git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4294 35acf78f-673a-0410-8e92-d51de3d6d3f4

master
gdisirio 2012-06-18 16:22:34 +00:00
parent 3626647d7b
commit 9057c6c72b
9 changed files with 71 additions and 127 deletions

View File

@ -44,14 +44,10 @@
*/ */
#define _base_channel_methods \ #define _base_channel_methods \
_base_sequential_stream_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.*/ \ /* 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.*/ \ /* 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.*/ \ /* Channel write method with timeout specification.*/ \
size_t (*writet)(void *instance, const uint8_t *bp, \ size_t (*writet)(void *instance, const uint8_t *bp, \
size_t n, systime_t time); \ size_t n, systime_t time); \
@ -92,56 +88,6 @@ typedef struct {
* @name Macro Functions (BaseChannel) * @name Macro Functions (BaseChannel)
* @{ * @{
*/ */
/**
* @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. * @brief Channel blocking byte write with timeout.
* @details This function writes a byte value to a channel. If the channel * @details This function writes a byte value to a channel. If the channel
@ -163,21 +109,6 @@ typedef struct {
*/ */
#define chnPutTimeout(ip, b, time) ((ip)->vmt->put(ip, b, time)) #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. * @brief Channel blocking byte read with timeout.
* @details This function reads a byte value from a channel. If the data * @details This function reads a byte value from a channel. If the data

View File

@ -64,22 +64,14 @@ static size_t reads(void *ip, uint8_t *bp, size_t n) {
n, TIME_INFINITE); n, TIME_INFINITE);
} }
static bool_t putwouldblock(void *ip) { static msg_t put(void *ip, uint8_t b) {
bool_t b;
chSysLock(); return chOQPutTimeout(&((SerialDriver *)ip)->oqueue, b, TIME_INFINITE);
b = chOQIsFullI(&((SerialDriver *)ip)->oqueue);
chSysUnlock();
return b;
} }
static bool_t getwouldblock(void *ip) { static msg_t get(void *ip) {
bool_t b;
chSysLock(); return chIQGetTimeout(&((SerialDriver *)ip)->iqueue, TIME_INFINITE);
b = chIQIsEmptyI(&((SerialDriver *)ip)->iqueue);
chSysUnlock();
return b;
} }
static msg_t putt(void *ip, uint8_t b, systime_t timeout) { 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 = { static const struct SerialDriverVMT vmt = {
writes, reads, putwouldblock, getwouldblock, writes, reads, put, get,
putt, gett, writet, readt, putt, gett, writet, readt,
getflags getflags
}; };

View File

@ -73,14 +73,14 @@ static size_t reads(void *ip, uint8_t *bp, size_t n) {
n, TIME_INFINITE); 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) { 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 = { static const struct SerialUSBDriverVMT vmt = {
writes, reads, putwouldblock, getwouldblock, writes, reads, put, get,
putt, gett, writet, readt, putt, gett, writet, readt,
getflags getflags
}; };

View File

@ -46,7 +46,11 @@
/* Stream write buffer method.*/ \ /* Stream write buffer method.*/ \
size_t (*write)(void *instance, const uint8_t *bp, size_t n); \ size_t (*write)(void *instance, const uint8_t *bp, size_t n); \
/* Stream read buffer method.*/ \ /* 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. * @brief @p BaseSequentialStream specific data.
@ -85,9 +89,8 @@ typedef struct {
* @param[in] bp pointer to the data buffer * @param[in] bp pointer to the data buffer
* @param[in] n the maximum amount of data to be transferred * @param[in] n the maximum amount of data to be transferred
* @return The number of bytes transferred. The return value can * @return The number of bytes transferred. The return value can
* be less than the specified number of bytes if the * be less than the specified number of bytes if an
* stream reaches a physical end of file and cannot be * end-of-file condition has been met.
* extended.
* *
* @api * @api
*/ */
@ -101,12 +104,42 @@ typedef struct {
* @param[out] bp pointer to the data buffer * @param[out] bp pointer to the data buffer
* @param[in] n the maximum amount of data to be transferred * @param[in] n the maximum amount of data to be transferred
* @return The number of bytes transferred. The return value can * @return The number of bytes transferred. The return value can
* be less than the specified number of bytes if the * be less than the specified number of bytes if an
* stream reaches the end of the available data. * end-of-file condition has been met.
* *
* @api * @api
*/ */
#define chSequentialStreamRead(ip, bp, n) ((ip)->vmt->read(ip, bp, n)) #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_ */ #endif /* _CHSTREAMS_H_ */

View File

@ -37,11 +37,6 @@
#define MAX_FILLER 11 #define MAX_FILLER 11
#define FLOAT_PRECISION 100000 #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, static char *long_to_string_with_divisor(char *p,
long num, long num,
unsigned radix, unsigned radix,
@ -133,7 +128,7 @@ void chprintf(BaseSequentialStream *chp, const char *fmt, ...) {
return; return;
} }
if (c != '%') { if (c != '%') {
_putc(chp, (uint8_t)c); chSequentialStreamPut(chp, (uint8_t)c);
continue; continue;
} }
p = tmpbuf; p = tmpbuf;
@ -248,18 +243,18 @@ unsigned_common:
width = -width; width = -width;
if (width < 0) { if (width < 0) {
if (*s == '-' && filler == '0') { if (*s == '-' && filler == '0') {
_putc(chp, (uint8_t)*s++); chSequentialStreamPut(chp, (uint8_t)*s++);
i--; i--;
} }
do do
_putc(chp, (uint8_t)filler); chSequentialStreamPut(chp, (uint8_t)filler);
while (++width != 0); while (++width != 0);
} }
while (--i >= 0) while (--i >= 0)
_putc(chp, (uint8_t)*s++); chSequentialStreamPut(chp, (uint8_t)*s++);
while (width) { while (width) {
_putc(chp, (uint8_t)filler); chSequentialStreamPut(chp, (uint8_t)filler);
width--; width--;
} }
} }

View File

@ -38,11 +38,6 @@
*/ */
EventSource shell_terminated; 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) { static char *_strtok(char *str, const char *delim, char **saveptr) {
char *token; char *token;
if (str) if (str)
@ -271,9 +266,9 @@ bool_t shellGetLine(BaseSequentialStream *chp, char *line, unsigned size) {
} }
if (c == 8) { if (c == 8) {
if (p != line) { if (p != line) {
_putc(chp, c); chSequentialStreamPut(chp, c);
_putc(chp, 0x20); chSequentialStreamPut(chp, 0x20);
_putc(chp, c); chSequentialStreamPut(chp, c);
p--; p--;
} }
continue; continue;
@ -286,7 +281,7 @@ bool_t shellGetLine(BaseSequentialStream *chp, char *line, unsigned size) {
if (c < 0x20) if (c < 0x20)
continue; continue;
if (p < line + size - 1) { if (p < line + size - 1) {
_putc(chp, c); chSequentialStreamPut(chp, c);
*p++ = (char)c; *p++ = (char)c;
} }
} }

View File

@ -168,7 +168,7 @@
- NEW: Modified the SDC driver to implement the new block devices abstract - NEW: Modified the SDC driver to implement the new block devices abstract
interface. interface.
- NEW: Added two new functions to the MMC_SPI driver: mmcSync() and - 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 interface. Moved the configuration parameters from mmcObjectInit() to
the configuration structure saving some RAM space. Updated demos. the configuration structure saving some RAM space. Updated demos.
- NEW: Added an abstract interface for block devices in the HAL. This - NEW: Added an abstract interface for block devices in the HAL. This
@ -219,8 +219,11 @@
lwIP demos (backported to 2.4.1). lwIP demos (backported to 2.4.1).
- NEW: lwIP related code is not centralized into a single place, no need to - 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). 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 - 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 - CHANGE: chprintf() now takes a BaseSequentialStream as parameter instead
of a BaseChannel making it more generic. of a BaseChannel making it more generic.
- CHANGE: Now the shell requires a BaseSequentialStream instead of a - CHANGE: Now the shell requires a BaseSequentialStream instead of a

View File

@ -87,11 +87,6 @@ void * ROMCONST wa[5] = {test.wa.T0, test.wa.T1, test.wa.T2,
*/ */
static BaseSequentialStream *chp; static BaseSequentialStream *chp;
static void _putc(BaseSequentialStream *chp, char c) {
chSequentialStreamWrite(chp, (const uint8_t *)&c, 1);
}
/** /**
* @brief Prints a decimal unsigned number. * @brief Prints a decimal unsigned number.
* *
@ -101,13 +96,13 @@ void test_printn(uint32_t n) {
char buf[16], *p; char buf[16], *p;
if (!n) if (!n)
_putc(chp, '0'); chSequentialStreamPut(chp, '0');
else { else {
p = buf; p = buf;
while (n) while (n)
*p++ = (n % 10) + '0', n /= 10; *p++ = (n % 10) + '0', n /= 10;
while (p > buf) 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) { void test_print(const char *msgp) {
while (*msgp) while (*msgp)
_putc(chp, *msgp++); chSequentialStreamPut(chp, *msgp++);
} }
/** /**
@ -145,7 +140,7 @@ static void print_tokens(void) {
char *cp = tokens_buffer; char *cp = tokens_buffer;
while (cp < tokp) while (cp < tokp)
_putc(chp, *cp++); chSequentialStreamPut(chp, *cp++);
} }
/** /**
@ -310,7 +305,7 @@ static void print_line(void) {
unsigned i; unsigned i;
for (i = 0; i < 76; i++) for (i = 0; i < 76; i++)
_putc(chp, '-'); chSequentialStreamPut(chp, '-');
chSequentialStreamWrite(chp, (const uint8_t *)"\r\n", 2); chSequentialStreamWrite(chp, (const uint8_t *)"\r\n", 2);
} }

View File

@ -7,7 +7,7 @@ N = Decided against.
Version 2.5.0 Version 2.5.0
X Revision of the RTCv2 driver implementation. 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. X STM32 OTG USB cell support for CL, F2, F4 devices.
Within 2.5.x: Within 2.5.x: