diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2009-09-24 18:43:09 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2009-09-24 18:43:09 +0000 |
commit | ac7438357d5c3fcc133c630608af742b4cea3c00 (patch) | |
tree | 690a96267595bfecd151b898d6414b181faed689 /os/io/mac.c | |
parent | 1a62b448482d81f92e2fc7e7e9095ad7982947be (diff) | |
download | ChibiOS-ac7438357d5c3fcc133c630608af742b4cea3c00.tar.gz ChibiOS-ac7438357d5c3fcc133c630608af742b4cea3c00.tar.bz2 ChibiOS-ac7438357d5c3fcc133c630608af742b4cea3c00.zip |
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1178 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/io/mac.c')
-rw-r--r-- | os/io/mac.c | 57 |
1 files changed, 41 insertions, 16 deletions
diff --git a/os/io/mac.c b/os/io/mac.c index c6c5f0168..2d90afb70 100644 --- a/os/io/mac.c +++ b/os/io/mac.c @@ -30,7 +30,7 @@ /**
* @brief Transmit descriptors counter semaphore. */
-static Semaphore tdsem;
+static Semaphore tdsem, rdsem;
/**
* @brief MAC Driver initialization. @@ -38,6 +38,7 @@ static Semaphore tdsem; void macInit(void) {
chSemInit(&tdsem, MAC_TRANSMIT_DESCRIPTORS);
+ chSemInit(&rdsem, 0);
mac_lld_init();
}
@@ -71,6 +72,7 @@ void macStop(void) { max_lld_stop();
chSemReset(&tdsem, MAC_TRANSMIT_DESCRIPTORS);
+ chSemReset(&rdsem, 0);
}
/**
@@ -80,14 +82,14 @@ void macStop(void) { * invoking thread is queued until one is freed.
* * @param[in] time the number of ticks before the operation timeouts,
- * the following special values are allowed:
- * - @a TIME_IMMEDIATE immediate timeout.
- * - @a TIME_INFINITE no timeout.
- * .
+ * the following special values are allowed:
+ * - @a TIME_IMMEDIATE immediate timeout.
+ * - @a TIME_INFINITE no timeout.
+ * .
* @return A pointer to a @p MACTransmitDescriptor structure or @p NULL if
* the operation timed out or the driver went in stop mode. */
-MACTransmitDescriptor *macGetTransmitDescriptor(systime_t time) {
+MACTransmitDescriptor *macWaitTransmitDescriptor(systime_t time) {
MACTransmitDescriptor *tdp;
chSysLock();
@@ -109,25 +111,48 @@ MACTransmitDescriptor *macGetTransmitDescriptor(systime_t time) { */
void macReleaseTransmitDescriptor(MACTransmitDescriptor *tdp) {
+ mac_lld_release_transmit_descriptor(tdp);
+}
+
+/**
+ * @brief Waits for a received frame.
+ * @details Stops until a frame is received and buffered. If a frame is
+ * not immediately available then the invoking thread is queued
+ * until one is received.
+ *
+ * @param[in] time the number of ticks before the operation timeouts,
+ * the following special values are allowed:
+ * - @a TIME_IMMEDIATE immediate timeout.
+ * - @a TIME_INFINITE no timeout.
+ * .
+ * @return A pointer to a @p MACReceiveDescriptor structure or @p NULL if
+ * the operation timed out, the driver went in stop mode or some
+ * transient error happened.
+ */
+MACReceiveDescriptor *macWaitReceiveDescriptor(systime_t time) {
+ MACReceiveDescriptor *rdp;
+
chSysLock();
- mac_lld_release_transmit_descriptor(tdp);
+ if (chSemWaitTimeoutS(&rdsem, time) == RDY_OK)
+ rdp = max_lld_get_receive_descriptor();
+ else
+ rdp = NULL;
chSysUnlock();
+ return rdp;
}
/**
- * @brief Enqueues data to a @p MACTransmitDescriptor.
- * - * @param[in] tdp the pointer to the @p MACTransmitDescriptor structure
- * @param buf pointer to the data buffer - * @param size size of the data to be enqueued + * @brief Releases a receive descriptor.
+ * @details The descriptor and its buffer is made available for more incoming
+ * frames.
+ *
+ * @param[in] rdp the pointer to the @p MACReceiveDescriptor structure
*/
-void macAddTransmitData(MACTransmitDescriptor *tdp,
- uint8_t *buf,
- size_t size) {
+void macReleaseTransmitDescriptor(MACReceiveDescriptor *rdp) {
- mac_lld_add_transmit_data(tdp, buf, size);
+ mac_lld_release_receive_descriptor(rdp);
}
/** @} */
|