diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2009-09-25 07:35:57 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2009-09-25 07:35:57 +0000 |
commit | d107ffedee36864fc238e791bddb02320a7bb30e (patch) | |
tree | d7daf42355b380f6f1df298d0e2c96f10d30f8fc /os/io | |
parent | ac7438357d5c3fcc133c630608af742b4cea3c00 (diff) | |
download | ChibiOS-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')
-rw-r--r-- | os/io/mac.c | 47 | ||||
-rw-r--r-- | os/io/mac.h | 2 | ||||
-rw-r--r-- | os/io/templates/mac_lld.c | 1 | ||||
-rw-r--r-- | os/io/templates/mac_lld.h | 13 |
4 files changed, 47 insertions, 16 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);
}
/** @} */
diff --git a/os/io/mac.h b/os/io/mac.h index 7c8a137f9..b405f6814 100644 --- a/os/io/mac.h +++ b/os/io/mac.h @@ -52,7 +52,7 @@ extern "C" { void macSetAddress(uint8_t *p);
void macStart(void);
void macStop(void);
- MACTransmissionDescriptor *macWaitTransmitDescriptor(systime_t time);
+ MACTransmitDescriptor *macWaitTransmitDescriptor(systime_t time);
void macReleaseTransmitDescriptor(MACTransmitDescriptor *tdp);
void macAddTransmitData(MACTransmitDescriptor *tdp,
uint8_t *buf,
diff --git a/os/io/templates/mac_lld.c b/os/io/templates/mac_lld.c index 748ced9d5..98c6f0c1d 100644 --- a/os/io/templates/mac_lld.c +++ b/os/io/templates/mac_lld.c @@ -93,6 +93,7 @@ void mac_lld_release_transmit_descriptor(MACTransmitDescriptor *tdp) { */
uint8_t *mac_lld_get_transmit_buffer(MACTransmitDescriptor *tdp) {
+ return NULL;
}
/**
diff --git a/os/io/templates/mac_lld.h b/os/io/templates/mac_lld.h index c88c1bf99..92e23cc4e 100644 --- a/os/io/templates/mac_lld.h +++ b/os/io/templates/mac_lld.h @@ -34,7 +34,7 @@ /**
* @brief Number of available descriptors/buffers. */
-#ifndef MAC_TRANSMIT_DESCRIPTORS !! defined(__DOXYGEN__)
+#if !defined(MAC_TRANSMIT_DESCRIPTORS) || defined(__DOXYGEN__)
#define MAC_TRANSMIT_DESCRIPTORS 2
#endif
@@ -42,9 +42,13 @@ /* Driver data structures and types. */
/*===========================================================================*/
-typedef struct MACTransmitDescriptor {
+typedef struct {
-};
+} MACTransmitDescriptor;
+
+typedef struct {
+
+} MACReceiveDescriptor;
/*===========================================================================*/
/* External declarations. */
@@ -60,6 +64,9 @@ extern "C" { MACTransmitDescriptor *max_lld_get_transmit_descriptor(void);
void mac_lld_release_transmit_descriptor(MACTransmitDescriptor *tdp);
uint8_t *mac_lld_get_transmit_buffer(MACTransmitDescriptor *tdp);
+ MACReceiveDescriptor *max_lld_get_receive_descriptor(void);
+ void mac_lld_release_receive_descriptor(MACReceiveDescriptor *rdp);
+ uint8_t *mac_lld_get_receive_buffer(MACReceiveDescriptor *rdp);
#ifdef __cplusplus
}
#endif
|