diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2009-09-25 14:56:57 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2009-09-25 14:56:57 +0000 |
commit | 7c2813c27119ed1f3c9c433dc37583cc919d5a3f (patch) | |
tree | 5f5cc8ea003f288e05a06c9d14ea9aaf5b8e11f3 /os/io/mac.c | |
parent | df471c97569f94d75efcdd00d19274bab243c981 (diff) | |
download | ChibiOS-7c2813c27119ed1f3c9c433dc37583cc919d5a3f.tar.gz ChibiOS-7c2813c27119ed1f3c9c433dc37583cc919d5a3f.tar.bz2 ChibiOS-7c2813c27119ed1f3c9c433dc37583cc919d5a3f.zip |
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1181 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/io/mac.c')
-rw-r--r-- | os/io/mac.c | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/os/io/mac.c b/os/io/mac.c index 823a1b4a7..e64f0bee0 100644 --- a/os/io/mac.c +++ b/os/io/mac.c @@ -28,11 +28,6 @@ #include <mac.h>
/**
- * @brief Interface status. - */
-static enum {ifStopped = 0, ifStarted} state;
-
-/**
* @brief Transmit descriptors counter semaphore. */
static Semaphore tdsem, rdsem;
@@ -42,13 +37,22 @@ static Semaphore tdsem, rdsem; */
void macInit(void) {
- chSemInit(&tdsem, MAC_TRANSMIT_DESCRIPTORS);
- chSemInit(&rdsem, 0);
- state = ifStopped;
mac_lld_init();
}
/**
+ * @brief Initialize the standard part of a @p MACDriver structure. + *
+ * @param[in] macp pointer to the @p MACDriver object
+ */
+void macObjectInit(MACDriver *macp) {
+
+ chSemInit(&macp->md_tdsem, MAC_TRANSMIT_DESCRIPTORS);
+ chSemInit(&macp->md_rdsem, 0);
+ macp->md_state = ifStopped;
+}
+
+/**
* @brief MAC address setup.
*
* @param[in] macp pointer to the @p MACDriver object @@ -61,7 +65,7 @@ void macInit(void) { */
void macSetAddress(MACDriver *macp, uint8_t *p) {
- if (state == ifStopped)
+ if (macp->md_state == ifStopped)
mac_lld_set_address(macp, p);
}
@@ -74,11 +78,11 @@ void macSetAddress(MACDriver *macp, uint8_t *p) { void macStart(MACDriver *macp) {
chSysLock();
- if (state == ifStarted) {
+ if (macp->md_state == ifStarted) {
chSysUnlock();
return;
}
- state = ifStarted;
+ macp->md_state = ifStarted;
chSysUnlock();
mac_lld_start(macp);
}
@@ -91,13 +95,13 @@ void macStart(MACDriver *macp) { void macStop(MACDriver *macp) {
chSysLock();
- if (state == ifStopped) {
+ if (macp->md_state == ifStopped) {
chSysUnlock();
return;
}
- state = ifStopped;
- chSemResetI(&tdsem, MAC_TRANSMIT_DESCRIPTORS);
- chSemResetI(&rdsem, 0);
+ macp->md_state = ifStopped;
+ chSemResetI(&macp->md_tdsem, MAC_TRANSMIT_DESCRIPTORS);
+ chSemResetI(&macp->md_rdsem, 0);
chSchRescheduleS();
chSysUnlock();
mac_lld_stop(macp);
@@ -124,7 +128,8 @@ MACTransmitDescriptor *macWaitTransmitDescriptor(MACDriver *macp, chSysLock();
- if ((state == ifStopped) || (chSemWaitTimeoutS(&tdsem, time) != RDY_OK))
+ if ((macp->md_state == ifStopped) ||
+ (chSemWaitTimeoutS(&tdsem, time) != RDY_OK))
tdp = NULL;
else
tdp = max_lld_get_transmit_descriptor(macp);
@@ -143,7 +148,7 @@ MACTransmitDescriptor *macWaitTransmitDescriptor(MACDriver *macp, void macReleaseTransmitDescriptor(MACDriver *macp,
MACTransmitDescriptor *tdp) {
- if (state == ifStarted)
+ if (macp->md_state == ifStarted)
mac_lld_release_transmit_descriptor(macp, tdp);
}
@@ -169,7 +174,8 @@ MACReceiveDescriptor *macWaitReceiveDescriptor(MACDriver *macp, chSysLock();
- if ((state == ifStopped) || (chSemWaitTimeoutS(&rdsem, time) != RDY_OK))
+ if ((macp->md_state == ifStopped) ||
+ (chSemWaitTimeoutS(&rdsem, time) != RDY_OK))
rdp = NULL;
else
rdp = max_lld_get_receive_descriptor(macp);
@@ -189,7 +195,7 @@ MACReceiveDescriptor *macWaitReceiveDescriptor(MACDriver *macp, void macReleaseReceiveDescriptor(MACDriver *macp,
MACReceiveDescriptor *rdp) {
- if (state == ifStarted)
+ if (macp->md_state == ifStarted)
mac_lld_release_receive_descriptor(macp, rdp);
}
|