aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2012-06-18 16:22:34 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2012-06-18 16:22:34 +0000
commit9057c6c72be213bb7f07929e2ddd1ab1e942a1de (patch)
tree2e61c984622621c39207b1d63198ca50a2e99f6c
parent3626647d7b924ca07df4197f9cde4a7965b8cbdf (diff)
downloadChibiOS-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
-rw-r--r--os/hal/include/io_channel.h73
-rw-r--r--os/hal/src/serial.c18
-rw-r--r--os/hal/src/serial_usb.c10
-rw-r--r--os/kernel/include/chstreams.h45
-rw-r--r--os/various/chprintf.c15
-rw-r--r--os/various/shell.c13
-rw-r--r--readme.txt7
-rw-r--r--test/test.c15
-rw-r--r--todo.txt2
9 files changed, 71 insertions, 127 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;
}
}
diff --git a/readme.txt b/readme.txt
index 0dc65d935..01b04339b 100644
--- a/readme.txt
+++ b/readme.txt
@@ -168,7 +168,7 @@
- NEW: Modified the SDC driver to implement the new block devices abstract
interface.
- NEW: Added two new functions to the MMC_SPI driver: mmcSync() and
- mmc_Get_Info(). Also implemented the new block devices abstract
+ mmcGetInfo(). Also implemented the new block devices abstract
interface. Moved the configuration parameters from mmcObjectInit() to
the configuration structure saving some RAM space. Updated demos.
- NEW: Added an abstract interface for block devices in the HAL. This
@@ -219,8 +219,11 @@
lwIP demos (backported to 2.4.1).
- NEW: lwIP related code is not centralized into a single place, no need to
duplicate the code in each application or demo (backported to 2.4.1).
+- CHANGE: Added two new methods to the BaseSequentialStream interface:
+ chSequentialStreamPut() and chSequentialStreamGet().
- CHANGE: Removed the chioch.h header from the kernel, now channels interface
- is exported by the HAL.
+ is exported by the HAL. Removed functions chPutWouldBlock() and
+ chGetWouldBlock().
- CHANGE: chprintf() now takes a BaseSequentialStream as parameter instead
of a BaseChannel making it more generic.
- CHANGE: Now the shell requires a BaseSequentialStream instead of a
diff --git a/test/test.c b/test/test.c
index beb0bfd3b..e6ee8e0ce 100644
--- a/test/test.c
+++ b/test/test.c
@@ -87,11 +87,6 @@ void * ROMCONST wa[5] = {test.wa.T0, test.wa.T1, test.wa.T2,
*/
static BaseSequentialStream *chp;
-static void _putc(BaseSequentialStream *chp, char c) {
-
- chSequentialStreamWrite(chp, (const uint8_t *)&c, 1);
-}
-
/**
* @brief Prints a decimal unsigned number.
*
@@ -101,13 +96,13 @@ void test_printn(uint32_t n) {
char buf[16], *p;
if (!n)
- _putc(chp, '0');
+ chSequentialStreamPut(chp, '0');
else {
p = buf;
while (n)
*p++ = (n % 10) + '0', n /= 10;
while (p > buf)
- _putc(chp, *--p);
+ chSequentialStreamPut(chp, *--p);
}
}
@@ -119,7 +114,7 @@ void test_printn(uint32_t n) {
void test_print(const char *msgp) {
while (*msgp)
- _putc(chp, *msgp++);
+ chSequentialStreamPut(chp, *msgp++);
}
/**
@@ -145,7 +140,7 @@ static void print_tokens(void) {
char *cp = tokens_buffer;
while (cp < tokp)
- _putc(chp, *cp++);
+ chSequentialStreamPut(chp, *cp++);
}
/**
@@ -310,7 +305,7 @@ static void print_line(void) {
unsigned i;
for (i = 0; i < 76; i++)
- _putc(chp, '-');
+ chSequentialStreamPut(chp, '-');
chSequentialStreamWrite(chp, (const uint8_t *)"\r\n", 2);
}
diff --git a/todo.txt b/todo.txt
index ccddba301..73ad20999 100644
--- a/todo.txt
+++ b/todo.txt
@@ -7,7 +7,7 @@ N = Decided against.
Version 2.5.0
X Revision of the RTCv2 driver implementation.
-- USB driver model revision.
+X USB driver model revision.
X STM32 OTG USB cell support for CL, F2, F4 devices.
Within 2.5.x: