diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2009-05-03 09:51:01 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2009-05-03 09:51:01 +0000 |
commit | 62a6638eb544f2c3d9022bcb34cae181aa8f7aae (patch) | |
tree | 2824331e6e59e511963608603d65010d70ebf140 /src | |
parent | a8df5dfb84dc37224222520ead47d4cef40ebd9f (diff) | |
download | ChibiOS-62a6638eb544f2c3d9022bcb34cae181aa8f7aae.tar.gz ChibiOS-62a6638eb544f2c3d9022bcb34cae181aa8f7aae.tar.bz2 ChibiOS-62a6638eb544f2c3d9022bcb34cae181aa8f7aae.zip |
Added I/O queue checks to the channels, added notes in the readme, improved the FullDuplexDriver.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@940 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'src')
-rw-r--r-- | src/chserial.c | 16 | ||||
-rw-r--r-- | src/include/channels.h | 34 | ||||
-rw-r--r-- | src/include/serial.h | 18 |
3 files changed, 67 insertions, 1 deletions
diff --git a/src/chserial.c b/src/chserial.c index 4dac892f8..65179689d 100644 --- a/src/chserial.c +++ b/src/chserial.c @@ -28,6 +28,20 @@ #if CH_USE_SERIAL_FULLDUPLEX
+/*
+ * Interface implementation, the following functions just invoke the equivalent
+ * queue-level function or macro. + */
+static bool_t putwouldblock(void *instance) {
+
+ return chOQIsFull(&((FullDuplexDriver *)instance)->d2.oqueue);
+}
+
+static bool_t getwouldblock(void *instance) {
+
+ return chIQIsEmpty(&((FullDuplexDriver *)instance)->d2.iqueue);
+}
+
static msg_t put(void *instance, uint8_t b, systime_t timeout) {
return chOQPutTimeout(&((FullDuplexDriver *)instance)->d2.oqueue, b, timeout);
@@ -49,7 +63,7 @@ static size_t read(void *instance, uint8_t *buffer, size_t n) { }
static const struct FullDuplexDriverVMT vmt = {
- {put, get},
+ {putwouldblock, getwouldblock, put, get},
{write, read},
{}
};
diff --git a/src/include/channels.h b/src/include/channels.h index d3d1f5d47..2ff20b1ad 100644 --- a/src/include/channels.h +++ b/src/include/channels.h @@ -32,6 +32,16 @@ */
struct _base_channel_methods {
/**
+ * @brief Channel output check.
+ * @see chIOPutWouldBlock()
+ */
+ bool_t (*putwouldblock)(void *instance);
+ /**
+ * @brief Channel input check.
+ * @see chIOGetWouldBlock()
+ */
+ bool_t (*getwouldblock)(void *instance);
+ /**
* @brief Channel put method with timeout specification.
* @see chIOPut()
*/
@@ -77,6 +87,30 @@ typedef struct { } BaseChannel;
/**
+ * @brief Channel output check.
+ * @details This function verifies if a subsequent @p chIOPut() would block.
+ *
+ * @param[in] ip pointer to a @p BaseChannel or derived class
+ * @return The output queue status:
+ * @retval FALSE if the output queue has space and would not block a write
+ * operation.
+ * @retval TRUE if the output queue is full and would block a write operation.
+ */
+#define chIOPutWouldBlock(ip) ((ip)->vmt->m0.putwouldblock(ip))
+
+/**
+ * @brief Channel input check.
+ * @details This function verifies if a subsequent @p chIOGett() would block.
+ *
+ * @param[in] ip pointer to a @p BaseChannel or derived class
+ * @return The input queue status:
+ * @retval FALSE if the input queue contains data and would not block a read
+ * operation.
+ * @retval TRUE if the input queue is empty and would block a read operation.
+ */
+#define chIOGetWouldBlock(ip) ((ip)->vmt->m0.getwouldblock(ip))
+
+/**
* @brief Channel blocking byte write.
* @details This function writes a byte value to a channel. If the channel
* is not ready to accept data then the calling thread is suspended.
diff --git a/src/include/serial.h b/src/include/serial.h index 9bb6c4f92..08ddf61fe 100644 --- a/src/include/serial.h +++ b/src/include/serial.h @@ -137,6 +137,24 @@ extern "C" { #endif
/**
+ * @brief Direct output check on a @p FullDuplexDriver. + * @details This function bypasses the indirect access to the channel and
+ * checks directly the output queue. This is faster but cannot
+ * be used to check different channels implementations.
+ * @see chIOPutWouldBlock()
+ */
+#define chFDDPutWouldBlock(sd) chOQIsFull(&(sd)->d2.oqueue)
+
+/**
+ * @brief Direct input check on a @p FullDuplexDriver.
+ * @details This function bypasses the indirect access to the channel and
+ * checks directly the input queue. This is faster but cannot
+ * be used to check different channels implementations.
+ * @see chIOGetWouldBlock()
+ */
+#define chFDDGetWouldBlock(sd) chIQIsEmpty(&(sd)->d2.iqueue)
+
+/**
* @brief Direct blocking write to a @p FullDuplexDriver.
* @details This function bypasses the indirect access to the channel and
* writes directly on the output queue. This is faster but cannot
|