aboutsummaryrefslogtreecommitdiffstats
path: root/os/io/mac.c
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2009-09-25 07:35:57 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2009-09-25 07:35:57 +0000
commitd107ffedee36864fc238e791bddb02320a7bb30e (patch)
treed7daf42355b380f6f1df298d0e2c96f10d30f8fc /os/io/mac.c
parentac7438357d5c3fcc133c630608af742b4cea3c00 (diff)
downloadChibiOS-d107ffedee36864fc238e791bddb02320a7bb30e.tar.gz
ChibiOS-d107ffedee36864fc238e791bddb02320a7bb30e.tar.bz2
ChibiOS-d107ffedee36864fc238e791bddb02320a7bb30e.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1179 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/io/mac.c')
-rw-r--r--os/io/mac.c47
1 files changed, 35 insertions, 12 deletions
diff --git a/os/io/mac.c b/os/io/mac.c
index 2d90afb70..16c55d644 100644
--- a/os/io/mac.c
+++ b/os/io/mac.c
@@ -28,6 +28,11 @@
#include <mac.h>
/**
+ * @brief Interface status.
+ */
+static enum {ifStopped = 0, ifStarted} state;
+
+/**
* @brief Transmit descriptors counter semaphore.
*/
static Semaphore tdsem, rdsem;
@@ -39,6 +44,7 @@ void macInit(void) {
chSemInit(&tdsem, MAC_TRANSMIT_DESCRIPTORS);
chSemInit(&rdsem, 0);
+ state = ifStopped;
mac_lld_init();
}
@@ -62,6 +68,13 @@ void macSetAddress(uint8_t *p) {
*/
void macStart(void) {
+ chSysLock();
+ if (state == ifStarted) {
+ chSysUnlock();
+ return;
+ }
+ state = ifStarted;
+ chSysUnlock();
mac_lld_start();
}
@@ -70,9 +83,17 @@ void macStart(void) {
*/
void macStop(void) {
- max_lld_stop();
- chSemReset(&tdsem, MAC_TRANSMIT_DESCRIPTORS);
- chSemReset(&rdsem, 0);
+ chSysLock();
+ if (state == ifStopped) {
+ chSysUnlock();
+ return;
+ }
+ state = ifStopped;
+ chSemResetI(&tdsem, MAC_TRANSMIT_DESCRIPTORS);
+ chSemResetI(&rdsem, 0);
+ chSchRescheduleS();
+ chSysUnlock();
+ mac_lld_stop();
}
/**
@@ -94,10 +115,10 @@ MACTransmitDescriptor *macWaitTransmitDescriptor(systime_t time) {
chSysLock();
- if (chSemWaitTimeoutS(&tdsem, time) == RDY_OK)
- tdp = max_lld_get_transmit_descriptor();
- else
+ if ((state == ifStopped) || (chSemWaitTimeoutS(&tdsem, time) != RDY_OK))
tdp = NULL;
+ else
+ tdp = max_lld_get_transmit_descriptor();
chSysUnlock();
return tdp;
@@ -111,7 +132,8 @@ MACTransmitDescriptor *macWaitTransmitDescriptor(systime_t time) {
*/
void macReleaseTransmitDescriptor(MACTransmitDescriptor *tdp) {
- mac_lld_release_transmit_descriptor(tdp);
+ if (state == ifStarted)
+ mac_lld_release_transmit_descriptor(tdp);
}
/**
@@ -134,10 +156,10 @@ MACReceiveDescriptor *macWaitReceiveDescriptor(systime_t time) {
chSysLock();
- if (chSemWaitTimeoutS(&rdsem, time) == RDY_OK)
- rdp = max_lld_get_receive_descriptor();
- else
+ if ((state == ifStopped) || (chSemWaitTimeoutS(&rdsem, time) != RDY_OK))
rdp = NULL;
+ else
+ rdp = max_lld_get_receive_descriptor();
chSysUnlock();
return rdp;
@@ -150,9 +172,10 @@ MACReceiveDescriptor *macWaitReceiveDescriptor(systime_t time) {
*
* @param[in] rdp the pointer to the @p MACReceiveDescriptor structure
*/
-void macReleaseTransmitDescriptor(MACReceiveDescriptor *rdp) {
+void macReleaseReceiveDescriptor(MACReceiveDescriptor *rdp) {
- mac_lld_release_receive_descriptor(rdp);
+ if (state == ifStarted)
+ mac_lld_release_receive_descriptor(rdp);
}
/** @} */