diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2012-06-18 16:22:34 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2012-06-18 16:22:34 +0000 |
commit | 9057c6c72be213bb7f07929e2ddd1ab1e942a1de (patch) | |
tree | 2e61c984622621c39207b1d63198ca50a2e99f6c /os | |
parent | 3626647d7b924ca07df4197f9cde4a7965b8cbdf (diff) | |
download | ChibiOS-9057c6c72be213bb7f07929e2ddd1ab1e942a1de.tar.gz ChibiOS-9057c6c72be213bb7f07929e2ddd1ab1e942a1de.tar.bz2 ChibiOS-9057c6c72be213bb7f07929e2ddd1ab1e942a1de.zip |
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4294 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os')
-rw-r--r-- | os/hal/include/io_channel.h | 73 | ||||
-rw-r--r-- | os/hal/src/serial.c | 18 | ||||
-rw-r--r-- | os/hal/src/serial_usb.c | 10 | ||||
-rw-r--r-- | os/kernel/include/chstreams.h | 45 | ||||
-rw-r--r-- | os/various/chprintf.c | 15 | ||||
-rw-r--r-- | os/various/shell.c | 13 |
6 files changed, 60 insertions, 114 deletions
diff --git a/os/hal/include/io_channel.h b/os/hal/include/io_channel.h index 2f2809bf8..5573184f5 100644 --- a/os/hal/include/io_channel.h +++ b/os/hal/include/io_channel.h @@ -44,14 +44,10 @@ */
#define _base_channel_methods \
_base_sequential_stream_methods \
- /* Channel output check.*/ \
- bool_t (*putwouldblock)(void *instance); \
- /* Channel input check.*/ \
- bool_t (*getwouldblock)(void *instance); \
/* Channel put method with timeout specification.*/ \
- msg_t (*put)(void *instance, uint8_t b, systime_t time); \
+ msg_t (*putt)(void *instance, uint8_t b, systime_t time); \
/* Channel get method with timeout specification.*/ \
- msg_t (*get)(void *instance, systime_t time); \
+ msg_t (*gett)(void *instance, systime_t time); \
/* Channel write method with timeout specification.*/ \
size_t (*writet)(void *instance, const uint8_t *bp, \
size_t n, systime_t time); \
@@ -93,56 +89,6 @@ typedef struct { * @{
*/
/**
- * @brief Channel output check.
- * @details This function verifies if a subsequent put/write operation 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.
- *
- * @api
- */
-#define chnPutWouldBlock(ip) ((ip)->vmt->putwouldblock(ip))
-
-/**
- * @brief Channel input check.
- * @details This function verifies if a subsequent get/read operation 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.
- *
- * @api
- */
-#define chnGetWouldBlock(ip) ((ip)->vmt->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.
- *
- * @param[in] ip pointer to a @p BaseChannel or derived class
- * @param[in] b the byte value to be written to the channel
- *
- * @return The operation status.
- * @retval Q_OK if the operation succeeded.
- * @retval Q_RESET if the channel associated queue (if any) was reset.
- *
- * @api
- */
-#define chnPut(ip, b) ((ip)->vmt->put(ip, b, TIME_INFINITE))
-
-/**
* @brief Channel blocking byte write with timeout.
* @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.
@@ -164,21 +110,6 @@ typedef struct { #define chnPutTimeout(ip, b, time) ((ip)->vmt->put(ip, b, time))
/**
- * @brief Channel blocking byte read.
- * @details This function reads a byte value from a channel. If the data
- * is not available then the calling thread is suspended.
- *
- * @param[in] ip pointer to a @p BaseChannel or derived class
- *
- * @return A byte value from the queue.
- * @retval Q_RESET if the channel associated queue (if any) has been
- * reset.
- *
- * @api
- */
-#define chnGet(ip) ((ip)->vmt->get(ip, TIME_INFINITE))
-
-/**
* @brief Channel blocking byte read with timeout.
* @details This function reads a byte value from a channel. If the data
* is not available then the calling thread is suspended.
diff --git a/os/hal/src/serial.c b/os/hal/src/serial.c index 5b883e16a..8b0d7c8cf 100644 --- a/os/hal/src/serial.c +++ b/os/hal/src/serial.c @@ -64,22 +64,14 @@ static size_t reads(void *ip, uint8_t *bp, size_t n) { n, TIME_INFINITE);
}
-static bool_t putwouldblock(void *ip) {
- bool_t b;
+static msg_t put(void *ip, uint8_t b) {
- chSysLock();
- b = chOQIsFullI(&((SerialDriver *)ip)->oqueue);
- chSysUnlock();
- return b;
+ return chOQPutTimeout(&((SerialDriver *)ip)->oqueue, b, TIME_INFINITE);
}
-static bool_t getwouldblock(void *ip) {
- bool_t b;
+static msg_t get(void *ip) {
- chSysLock();
- b = chIQIsEmptyI(&((SerialDriver *)ip)->iqueue);
- chSysUnlock();
- return b;
+ return chIQGetTimeout(&((SerialDriver *)ip)->iqueue, TIME_INFINITE);
}
static msg_t putt(void *ip, uint8_t b, systime_t timeout) {
@@ -107,7 +99,7 @@ static chnflags_t getflags(void *ip) { }
static const struct SerialDriverVMT vmt = {
- writes, reads, putwouldblock, getwouldblock,
+ writes, reads, put, get,
putt, gett, writet, readt,
getflags
};
diff --git a/os/hal/src/serial_usb.c b/os/hal/src/serial_usb.c index 2b02ae02f..466b65b0a 100644 --- a/os/hal/src/serial_usb.c +++ b/os/hal/src/serial_usb.c @@ -73,14 +73,14 @@ static size_t reads(void *ip, uint8_t *bp, size_t n) { n, TIME_INFINITE);
}
-static bool_t putwouldblock(void *ip) {
+static msg_t put(void *ip, uint8_t b) {
- return chOQIsFullI(&((SerialUSBDriver *)ip)->oqueue);
+ return chOQPutTimeout(&((SerialUSBDriver *)ip)->oqueue, b, TIME_INFINITE);
}
-static bool_t getwouldblock(void *ip) {
+static msg_t get(void *ip) {
- return chIQIsEmptyI(&((SerialUSBDriver *)ip)->iqueue);
+ return chIQGetTimeout(&((SerialUSBDriver *)ip)->iqueue, TIME_INFINITE);
}
static msg_t putt(void *ip, uint8_t b, systime_t timeout) {
@@ -108,7 +108,7 @@ static chnflags_t getflags(void *ip) { }
static const struct SerialUSBDriverVMT vmt = {
- writes, reads, putwouldblock, getwouldblock,
+ writes, reads, put, get,
putt, gett, writet, readt,
getflags
};
diff --git a/os/kernel/include/chstreams.h b/os/kernel/include/chstreams.h index f12c662cd..e55aa53c7 100644 --- a/os/kernel/include/chstreams.h +++ b/os/kernel/include/chstreams.h @@ -46,7 +46,11 @@ /* Stream write buffer method.*/ \
size_t (*write)(void *instance, const uint8_t *bp, size_t n); \
/* Stream read buffer method.*/ \
- size_t (*read)(void *instance, uint8_t *bp, size_t n);
+ size_t (*read)(void *instance, uint8_t *bp, size_t n); \
+ /* Channel put method, blocking.*/ \
+ msg_t (*put)(void *instance, uint8_t b); \
+ /* Channel get method, blocking.*/ \
+ msg_t (*get)(void *instance); \
/**
* @brief @p BaseSequentialStream specific data.
@@ -85,9 +89,8 @@ typedef struct { * @param[in] bp pointer to the data buffer
* @param[in] n the maximum amount of data to be transferred
* @return The number of bytes transferred. The return value can
- * be less than the specified number of bytes if the
- * stream reaches a physical end of file and cannot be
- * extended.
+ * be less than the specified number of bytes if an
+ * end-of-file condition has been met.
*
* @api
*/
@@ -101,12 +104,42 @@ typedef struct { * @param[out] bp pointer to the data buffer
* @param[in] n the maximum amount of data to be transferred
* @return The number of bytes transferred. The return value can
- * be less than the specified number of bytes if the
- * stream reaches the end of the available data.
+ * be less than the specified number of bytes if an
+ * end-of-file condition has been met.
*
* @api
*/
#define chSequentialStreamRead(ip, bp, n) ((ip)->vmt->read(ip, bp, n))
+
+/**
+ * @brief Sequential Stream 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.
+ *
+ * @param[in] ip pointer to a @p BaseChannel or derived class
+ * @param[in] b the byte value to be written to the channel
+ *
+ * @return The operation status.
+ * @retval Q_OK if the operation succeeded.
+ * @retval Q_RESET if an end-of-file condition has been met.
+ *
+ * @api
+ */
+#define chSequentialStreamPut(ip, b) ((ip)->vmt->put(ip, b))
+
+/**
+ * @brief Sequential Stream blocking byte read.
+ * @details This function reads a byte value from a channel. If the data
+ * is not available then the calling thread is suspended.
+ *
+ * @param[in] ip pointer to a @p BaseChannel or derived class
+ *
+ * @return A byte value from the queue.
+ * @retval Q_RESET if an end-of-file condition has been met.
+ *
+ * @api
+ */
+#define chSequentialStreamGet(ip) ((ip)->vmt->get(ip))
/** @} */
#endif /* _CHSTREAMS_H_ */
diff --git a/os/various/chprintf.c b/os/various/chprintf.c index 78a4a8ac1..2e03fe9c2 100644 --- a/os/various/chprintf.c +++ b/os/various/chprintf.c @@ -37,11 +37,6 @@ #define MAX_FILLER 11
#define FLOAT_PRECISION 100000
-static void _putc(BaseSequentialStream *chp, char c) {
-
- chSequentialStreamWrite(chp, (const uint8_t *)&c, 1);
-}
-
static char *long_to_string_with_divisor(char *p,
long num,
unsigned radix,
@@ -133,7 +128,7 @@ void chprintf(BaseSequentialStream *chp, const char *fmt, ...) { return;
}
if (c != '%') {
- _putc(chp, (uint8_t)c);
+ chSequentialStreamPut(chp, (uint8_t)c);
continue;
}
p = tmpbuf;
@@ -248,18 +243,18 @@ unsigned_common: width = -width;
if (width < 0) {
if (*s == '-' && filler == '0') {
- _putc(chp, (uint8_t)*s++);
+ chSequentialStreamPut(chp, (uint8_t)*s++);
i--;
}
do
- _putc(chp, (uint8_t)filler);
+ chSequentialStreamPut(chp, (uint8_t)filler);
while (++width != 0);
}
while (--i >= 0)
- _putc(chp, (uint8_t)*s++);
+ chSequentialStreamPut(chp, (uint8_t)*s++);
while (width) {
- _putc(chp, (uint8_t)filler);
+ chSequentialStreamPut(chp, (uint8_t)filler);
width--;
}
}
diff --git a/os/various/shell.c b/os/various/shell.c index fd9451f2e..611da6de0 100644 --- a/os/various/shell.c +++ b/os/various/shell.c @@ -38,11 +38,6 @@ */
EventSource shell_terminated;
-static void _putc(BaseSequentialStream *chp, char c) {
-
- chSequentialStreamWrite(chp, (const uint8_t *)&c, 1);
-}
-
static char *_strtok(char *str, const char *delim, char **saveptr) {
char *token;
if (str)
@@ -271,9 +266,9 @@ bool_t shellGetLine(BaseSequentialStream *chp, char *line, unsigned size) { }
if (c == 8) {
if (p != line) {
- _putc(chp, c);
- _putc(chp, 0x20);
- _putc(chp, c);
+ chSequentialStreamPut(chp, c);
+ chSequentialStreamPut(chp, 0x20);
+ chSequentialStreamPut(chp, c);
p--;
}
continue;
@@ -286,7 +281,7 @@ bool_t shellGetLine(BaseSequentialStream *chp, char *line, unsigned size) { if (c < 0x20)
continue;
if (p < line + size - 1) {
- _putc(chp, c);
+ chSequentialStreamPut(chp, c);
*p++ = (char)c;
}
}
|