aboutsummaryrefslogtreecommitdiffstats
path: root/os/io
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2009-09-24 18:43:09 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2009-09-24 18:43:09 +0000
commitac7438357d5c3fcc133c630608af742b4cea3c00 (patch)
tree690a96267595bfecd151b898d6414b181faed689 /os/io
parent1a62b448482d81f92e2fc7e7e9095ad7982947be (diff)
downloadChibiOS-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')
-rw-r--r--os/io/mac.c57
-rw-r--r--os/io/mac.h18
-rw-r--r--os/io/templates/mac_lld.c44
-rw-r--r--os/io/templates/mac_lld.h4
4 files changed, 96 insertions, 27 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);
}
/** @} */
diff --git a/os/io/mac.h b/os/io/mac.h
index 129c700d4..7c8a137f9 100644
--- a/os/io/mac.h
+++ b/os/io/mac.h
@@ -29,6 +29,22 @@
#include "mac_lld.h"
+/**
+ * @brief Returns the buffer associated to a @p MACTransmitDescriptor.
+ *
+ * @param[in] tdp the pointer to the @p MACTransmitDescriptor structure
+ * @return The pointer to the transmit buffer.
+ */
+#define macGetTransmitBuffer(tdp) mac_lld_get_transmit_buffer(tdp)
+
+/**
+ * @brief Returns the buffer associated to a @p MACReceiveDescriptor.
+ *
+ * @param[in] rdp the pointer to the @p MACReceiveDescriptor structure
+ * @return The pointer to the receive buffer.
+ */
+#define macGetReceiveBuffer(rdp) mac_lld_get_receive_buffer(rdp)
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -36,7 +52,7 @@ extern "C" {
void macSetAddress(uint8_t *p);
void macStart(void);
void macStop(void);
- MACTransmissionDescriptor *macGetTransmitDescriptor(systime_t time);
+ MACTransmissionDescriptor *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 b8e4e1614..748ced9d5 100644
--- a/os/io/templates/mac_lld.c
+++ b/os/io/templates/mac_lld.c
@@ -63,7 +63,7 @@ void mac_lld_stop(void) {
}
/**
- * @brief Allocates a transmission descriptor.
+ * @brief Returns a transmission descriptor.
* @details One of the available transmission descriptors is locked and
* returned.
*
@@ -86,15 +86,45 @@ void mac_lld_release_transmit_descriptor(MACTransmitDescriptor *tdp) {
}
/**
- * @brief Enqueues data to a @p MACTransmitDescriptor.
+ * @brief Returns the buffer associated 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
+ * @return The pointer to the transmit buffer.
*/
-void mac_lld_add_transmit_data(MACTransmitDescriptor *tdp,
- uint8_t *buf,
- size_t size) {
+uint8_t *mac_lld_get_transmit_buffer(MACTransmitDescriptor *tdp) {
+
+}
+
+/**
+ * @brief Returns a received frame.
+ *
+ * @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 *max_lld_get_receive_descriptor(void) {
+
+ return NULL;
+}
+
+/**
+ * @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 mac_lld_release_receive_descriptor(MACReceiveDescriptor *rdp) {
+
+}
+
+/**
+ * @brief Returns the buffer associated to a @p MACTransmitDescriptor.
+ *
+ * @param[in] tdp the pointer to the @p MACTransmitDescriptor structure
+ * @return The pointer to the transmit buffer.
+ */
+uint8_t *mac_lld_get_receive_buffer(MACReceiveDescriptor *rdp) {
}
diff --git a/os/io/templates/mac_lld.h b/os/io/templates/mac_lld.h
index f2eda28bd..c88c1bf99 100644
--- a/os/io/templates/mac_lld.h
+++ b/os/io/templates/mac_lld.h
@@ -59,9 +59,7 @@ extern "C" {
void mac_lld_stop(void);
MACTransmitDescriptor *max_lld_get_transmit_descriptor(void);
void mac_lld_release_transmit_descriptor(MACTransmitDescriptor *tdp);
- void mac_lld_add_transmit_data(MACTransmitDescriptor *tdp,
- uint8_t *buf,
- size_t size);
+ uint8_t *mac_lld_get_transmit_buffer(MACTransmitDescriptor *tdp);
#ifdef __cplusplus
}
#endif