aboutsummaryrefslogtreecommitdiffstats
path: root/os
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2012-05-08 17:09:20 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2012-05-08 17:09:20 +0000
commitd0a2e55ed0cf97be924ebbdae2497fd77bfac5b6 (patch)
treea31ebbd42904206131ff4eb661b4341558ca8925 /os
parentba6519a2eaf35bc6d39188e10b6ea12ef553009d (diff)
downloadChibiOS-d0a2e55ed0cf97be924ebbdae2497fd77bfac5b6.tar.gz
ChibiOS-d0a2e55ed0cf97be924ebbdae2497fd77bfac5b6.tar.bz2
ChibiOS-d0a2e55ed0cf97be924ebbdae2497fd77bfac5b6.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4175 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os')
-rw-r--r--os/hal/include/io_channel.h46
-rw-r--r--os/hal/platforms/AT91SAM7/serial_lld.c6
-rw-r--r--os/hal/platforms/AVR/serial_lld.c4
-rw-r--r--os/hal/platforms/LPC11xx/serial_lld.c12
-rw-r--r--os/hal/platforms/LPC13xx/serial_lld.c12
-rw-r--r--os/hal/platforms/LPC214x/serial_lld.c12
-rw-r--r--os/hal/platforms/MSP430/serial_lld.c4
-rw-r--r--os/hal/platforms/Posix/serial_lld.c6
-rw-r--r--os/hal/platforms/SPC56x/serial_lld.c6
-rw-r--r--os/hal/platforms/STM32/serial_lld.c10
-rw-r--r--os/hal/platforms/STM8L/serial_lld.c4
-rw-r--r--os/hal/platforms/STM8S/serial_lld.c4
-rw-r--r--os/hal/platforms/Win32/serial_lld.c6
-rw-r--r--os/hal/src/serial.c12
-rw-r--r--os/hal/src/serial_usb.c12
-rw-r--r--os/kernel/include/ch.h1
-rw-r--r--os/kernel/include/chioch.h370
-rw-r--r--os/various/chprintf.c21
-rw-r--r--os/various/chprintf.h2
-rw-r--r--os/various/shell.c36
-rw-r--r--os/various/shell.h6
21 files changed, 133 insertions, 459 deletions
diff --git a/os/hal/include/io_channel.h b/os/hal/include/io_channel.h
index c6da6b89b..3357bf6bd 100644
--- a/os/hal/include/io_channel.h
+++ b/os/hal/include/io_channel.h
@@ -71,7 +71,7 @@
*
* @brief @p BaseChannel virtual methods table.
*/
-struct tmp_BaseChannelVMT {
+struct BaseChannelVMT {
_base_channel_methods
};
@@ -86,7 +86,7 @@ typedef struct {
/** @brief Virtual Methods Table.*/
const struct BaseChannelVMT *vmt;
_base_channel_data
-} tmp_BaseChannel;
+} BaseChannel;
/**
* @name Macro Functions (BaseChannel)
@@ -98,6 +98,7 @@ typedef struct {
* 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.
@@ -114,6 +115,7 @@ typedef struct {
* 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.
@@ -131,6 +133,7 @@ typedef struct {
*
* @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.
@@ -166,6 +169,7 @@ typedef struct {
* 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.
@@ -195,6 +199,21 @@ typedef struct {
#define chnGetTimeout(ip, time) ((ip)->vmt->get(ip, time))
/**
+ * @brief Channel blocking write.
+ * @details The function writes data from a buffer 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[out] bp pointer to the data buffer
+ * @param[in] n the maximum amount of data to be transferred
+ *
+ * @return The number of bytes transferred.
+ *
+ * @api
+ */
+#define chnWrite(ip, bp, n) chSequentialStreamWrite(ip, bp, n)
+
+/**
* @brief Channel blocking write with timeout.
* @details The function writes data from a buffer to a channel. If the channel
* is not ready to accept data then the calling thread is suspended.
@@ -214,6 +233,21 @@ typedef struct {
#define chnWriteTimeout(ip, bp, n, time) ((ip)->vmt->writet(ip, bp, n, time))
/**
+ * @brief Channel blocking read.
+ * @details The function reads data from a channel into a buffer. If the data
+ * is not available then the calling thread is suspended.
+ *
+ * @param[in] ip pointer to a @p BaseChannel or derived class
+ * @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.
+ *
+ * @api
+ */
+#define chnRead(ip, bp, n) chSequentialStreamRead(ip, bp, n)
+
+/**
* @brief Channel blocking read with timeout.
* @details The function reads data from a channel into a buffer. If the data
* is not available then the calling thread is suspended.
@@ -260,7 +294,7 @@ typedef uint_fast16_t chnflags_t;
/**
* @brief @p BaseAsynchronousChannel specific methods.
*/
-#define tmp__base_asynchronous_channel_methods \
+#define _base_asynchronous_channel_methods \
_base_channel_methods \
/* Channel read method with timeout specification.*/ \
chnflags_t (*getflags)(void *instance);
@@ -268,7 +302,7 @@ typedef uint_fast16_t chnflags_t;
/**
* @brief @p BaseAsynchronousChannel specific data.
*/
-#define tmp__base_asynchronous_channel_data \
+#define _base_asynchronous_channel_data \
_base_channel_data \
/* I/O condition event source.*/ \
EventSource event; \
@@ -280,7 +314,7 @@ typedef uint_fast16_t chnflags_t;
*
* @brief @p BaseAsynchronousChannel virtual methods table.
*/
-struct tmp_BaseAsynchronousChannelVMT {
+struct BaseAsynchronousChannelVMT {
_base_asynchronous_channel_methods
};
@@ -295,7 +329,7 @@ typedef struct {
/** @brief Virtual Methods Table.*/
const struct BaseAsynchronousChannelVMT *vmt;
_base_asynchronous_channel_data
-} tmp_BaseAsynchronousChannel;
+} BaseAsynchronousChannel;
/**
* @name Macro Functions (BaseAsynchronousChannel)
diff --git a/os/hal/platforms/AT91SAM7/serial_lld.c b/os/hal/platforms/AT91SAM7/serial_lld.c
index d23aa9b0e..0e6aa1178 100644
--- a/os/hal/platforms/AT91SAM7/serial_lld.c
+++ b/os/hal/platforms/AT91SAM7/serial_lld.c
@@ -139,7 +139,7 @@ static void usart_deinit(AT91PS_USART u) {
* @param[in] sdp communication channel associated to the USART
*/
static void set_error(SerialDriver *sdp, AT91_REG csr) {
- ioflags_t sts = 0;
+ chnflags_t sts = 0;
if (csr & AT91C_US_OVRE)
sts |= SD_OVERRUN_ERROR;
@@ -150,7 +150,7 @@ static void set_error(SerialDriver *sdp, AT91_REG csr) {
if (csr & AT91C_US_RXBRK)
sts |= SD_BREAK_DETECTED;
chSysLockFromIsr();
- chIOAddFlagsI(sdp, sts);
+ chnAddFlagsI(sdp, sts);
chSysUnlockFromIsr();
}
@@ -181,7 +181,7 @@ void sd_lld_serve_interrupt(SerialDriver *sdp) {
chSysLockFromIsr();
b = chOQGetI(&sdp->oqueue);
if (b < Q_OK) {
- chIOAddFlagsI(sdp, IO_OUTPUT_EMPTY);
+ chnAddFlagsI(sdp, CHN_OUTPUT_EMPTY);
u->US_IDR = AT91C_US_TXRDY;
}
else
diff --git a/os/hal/platforms/AVR/serial_lld.c b/os/hal/platforms/AVR/serial_lld.c
index 102fd9d45..e070d5448 100644
--- a/os/hal/platforms/AVR/serial_lld.c
+++ b/os/hal/platforms/AVR/serial_lld.c
@@ -70,7 +70,7 @@ static const SerialConfig default_config = {
/*===========================================================================*/
static void set_error(uint8_t sra, SerialDriver *sdp) {
- ioflags_t sts = 0;
+ chnflags_t sts = 0;
if (sra & (1 << DOR))
sts |= SD_OVERRUN_ERROR;
@@ -79,7 +79,7 @@ static void set_error(uint8_t sra, SerialDriver *sdp) {
if (sra & (1 << FE))
sts |= SD_FRAMING_ERROR;
chSysLockFromIsr();
- chIOAddFlagsI(sdp, sts);
+ chnAddFlagsI(sdp, sts);
chSysUnlockFromIsr();
}
diff --git a/os/hal/platforms/LPC11xx/serial_lld.c b/os/hal/platforms/LPC11xx/serial_lld.c
index 4b2b40b39..10f7817b7 100644
--- a/os/hal/platforms/LPC11xx/serial_lld.c
+++ b/os/hal/platforms/LPC11xx/serial_lld.c
@@ -101,7 +101,7 @@ static void uart_deinit(LPC_UART_TypeDef *u) {
* @param[in] err UART LSR register value
*/
static void set_error(SerialDriver *sdp, IOREG32 err) {
- ioflags_t sts = 0;
+ chnflags_t sts = 0;
if (err & LSR_OVERRUN)
sts |= SD_OVERRUN_ERROR;
@@ -112,7 +112,7 @@ static void set_error(SerialDriver *sdp, IOREG32 err) {
if (err & LSR_BREAK)
sts |= SD_BREAK_DETECTED;
chSysLockFromIsr();
- chIOAddFlagsI(sdp, sts);
+ chnAddFlagsI(sdp, sts);
chSysUnlockFromIsr();
}
@@ -139,12 +139,12 @@ static void serve_interrupt(SerialDriver *sdp) {
case IIR_SRC_RX:
chSysLockFromIsr();
if (chIQIsEmptyI(&sdp->iqueue))
- chIOAddFlagsI(sdp, IO_INPUT_AVAILABLE);
+ chnAddFlagsI(sdp, CHN_INPUT_AVAILABLE);
chSysUnlockFromIsr();
while (u->LSR & LSR_RBR_FULL) {
chSysLockFromIsr();
if (chIQPutI(&sdp->iqueue, u->RBR) < Q_OK)
- chIOAddFlagsI(sdp, SD_OVERRUN_ERROR);
+ chnAddFlagsI(sdp, SD_OVERRUN_ERROR);
chSysUnlockFromIsr();
}
break;
@@ -160,7 +160,7 @@ static void serve_interrupt(SerialDriver *sdp) {
if (b < Q_OK) {
u->IER &= ~IER_THRE;
chSysLockFromIsr();
- chIOAddFlagsI(sdp, IO_OUTPUT_EMPTY);
+ chnAddFlagsI(sdp, CHN_OUTPUT_EMPTY);
chSysUnlockFromIsr();
break;
}
@@ -186,7 +186,7 @@ static void preload(SerialDriver *sdp) {
do {
msg_t b = chOQGetI(&sdp->oqueue);
if (b < Q_OK) {
- chIOAddFlagsI(sdp, IO_OUTPUT_EMPTY);
+ chnAddFlagsI(sdp, CHN_OUTPUT_EMPTY);
return;
}
u->THR = b;
diff --git a/os/hal/platforms/LPC13xx/serial_lld.c b/os/hal/platforms/LPC13xx/serial_lld.c
index 2bf781a3d..f0c75d247 100644
--- a/os/hal/platforms/LPC13xx/serial_lld.c
+++ b/os/hal/platforms/LPC13xx/serial_lld.c
@@ -101,7 +101,7 @@ static void uart_deinit(LPC_UART_TypeDef *u) {
* @param[in] err UART LSR register value
*/
static void set_error(SerialDriver *sdp, IOREG32 err) {
- ioflags_t sts = 0;
+ chnflags_t sts = 0;
if (err & LSR_OVERRUN)
sts |= SD_OVERRUN_ERROR;
@@ -112,7 +112,7 @@ static void set_error(SerialDriver *sdp, IOREG32 err) {
if (err & LSR_BREAK)
sts |= SD_BREAK_DETECTED;
chSysLockFromIsr();
- chIOAddFlagsI(sdp, sts);
+ chnAddFlagsI(sdp, sts);
chSysUnlockFromIsr();
}
@@ -139,12 +139,12 @@ static void serve_interrupt(SerialDriver *sdp) {
case IIR_SRC_RX:
chSysLockFromIsr();
if (chIQIsEmptyI(&sdp->iqueue))
- chIOAddFlagsI(sdp, IO_INPUT_AVAILABLE);
+ chnAddFlagsI(sdp, CHN_INPUT_AVAILABLE);
chSysUnlockFromIsr();
while (u->LSR & LSR_RBR_FULL) {
chSysLockFromIsr();
if (chIQPutI(&sdp->iqueue, u->RBR) < Q_OK)
- chIOAddFlagsI(sdp, SD_OVERRUN_ERROR);
+ chnAddFlagsI(sdp, SD_OVERRUN_ERROR);
chSysUnlockFromIsr();
}
break;
@@ -160,7 +160,7 @@ static void serve_interrupt(SerialDriver *sdp) {
if (b < Q_OK) {
u->IER &= ~IER_THRE;
chSysLockFromIsr();
- chIOAddFlagsI(sdp, IO_OUTPUT_EMPTY);
+ chnAddFlagsI(sdp, CHN_OUTPUT_EMPTY);
chSysUnlockFromIsr();
break;
}
@@ -186,7 +186,7 @@ static void preload(SerialDriver *sdp) {
do {
msg_t b = chOQGetI(&sdp->oqueue);
if (b < Q_OK) {
- chIOAddFlagsI(sdp, IO_OUTPUT_EMPTY);
+ chnAddFlagsI(sdp, CHN_OUTPUT_EMPTY);
return;
}
u->THR = b;
diff --git a/os/hal/platforms/LPC214x/serial_lld.c b/os/hal/platforms/LPC214x/serial_lld.c
index 8b325f35e..ce207ff61 100644
--- a/os/hal/platforms/LPC214x/serial_lld.c
+++ b/os/hal/platforms/LPC214x/serial_lld.c
@@ -106,7 +106,7 @@ static void uart_deinit(UART *u) {
* @param[in] err UART LSR register value
*/
static void set_error(SerialDriver *sdp, IOREG32 err) {
- ioflags_t sts = 0;
+ chnflags_t sts = 0;
if (err & LSR_OVERRUN)
sts |= SD_OVERRUN_ERROR;
@@ -117,7 +117,7 @@ static void set_error(SerialDriver *sdp, IOREG32 err) {
if (err & LSR_BREAK)
sts |= SD_BREAK_DETECTED;
chSysLockFromIsr();
- chIOAddFlagsI(sdp, sts);
+ chnAddFlagsI(sdp, sts);
chSysUnlockFromIsr();
}
@@ -145,12 +145,12 @@ static void serve_interrupt(SerialDriver *sdp) {
case IIR_SRC_RX:
chSysLockFromIsr();
if (chIQIsEmptyI(&sdp->iqueue))
- chIOAddFlagsI(sdp, IO_INPUT_AVAILABLE);
+ chnAddFlagsI(sdp, CHN_INPUT_AVAILABLE);
chSysUnlockFromIsr();
while (u->UART_LSR & LSR_RBR_FULL) {
chSysLockFromIsr();
if (chIQPutI(&sdp->iqueue, u->UART_RBR) < Q_OK)
- chIOAddFlagsI(sdp, SD_OVERRUN_ERROR);
+ chnAddFlagsI(sdp, SD_OVERRUN_ERROR);
chSysUnlockFromIsr();
}
break;
@@ -166,7 +166,7 @@ static void serve_interrupt(SerialDriver *sdp) {
if (b < Q_OK) {
u->UART_IER &= ~IER_THRE;
chSysLockFromIsr();
- chIOAddFlagsI(sdp, IO_OUTPUT_EMPTY);
+ chnAddFlagsI(sdp, CHN_OUTPUT_EMPTY);
chSysUnlockFromIsr();
break;
}
@@ -192,7 +192,7 @@ static void preload(SerialDriver *sdp) {
do {
msg_t b = chOQGetI(&sdp->oqueue);
if (b < Q_OK) {
- chIOAddFlagsI(sdp, IO_OUTPUT_EMPTY);
+ chnAddFlagsI(sdp, CHN_OUTPUT_EMPTY);
return;
}
u->UART_THR = b;
diff --git a/os/hal/platforms/MSP430/serial_lld.c b/os/hal/platforms/MSP430/serial_lld.c
index b3a030bc6..bdc3c580d 100644
--- a/os/hal/platforms/MSP430/serial_lld.c
+++ b/os/hal/platforms/MSP430/serial_lld.c
@@ -60,7 +60,7 @@ static const SerialConfig default_config = {
/*===========================================================================*/
static void set_error(SerialDriver *sdp, uint8_t urctl) {
- ioflags_t sts = 0;
+ chnflags_t sts = 0;
if (urctl & OE)
sts |= SD_OVERRUN_ERROR;
@@ -71,7 +71,7 @@ static void set_error(SerialDriver *sdp, uint8_t urctl) {
if (urctl & BRK)
sts |= SD_BREAK_DETECTED;
chSysLockFromIsr();
- chIOAddFlagsI(sdp, sts);
+ chnAddFlagsI(sdp, sts);
chSysUnlockFromIsr();
}
diff --git a/os/hal/platforms/Posix/serial_lld.c b/os/hal/platforms/Posix/serial_lld.c
index 4eea349b6..d8c62a0d7 100644
--- a/os/hal/platforms/Posix/serial_lld.c
+++ b/os/hal/platforms/Posix/serial_lld.c
@@ -121,7 +121,7 @@ static bool_t connint(SerialDriver *sdp) {
goto abort;
}
chSysLockFromIsr();
- chIOAddFlagsI(sdp, IO_CONNECTED);
+ chnAddFlagsI(sdp, CHN_CONNECTED);
chSysUnlockFromIsr();
return TRUE;
}
@@ -149,7 +149,7 @@ static bool_t inint(SerialDriver *sdp) {
close(sdp->com_data);
sdp->com_data = INVALID_SOCKET;
chSysLockFromIsr();
- chIOAddFlagsI(sdp, IO_DISCONNECTED);
+ chnAddFlagsI(sdp, CHN_DISCONNECTED);
chSysUnlockFromIsr();
return FALSE;
case INVALID_SOCKET:
@@ -190,7 +190,7 @@ static bool_t outint(SerialDriver *sdp) {
close(sdp->com_data);
sdp->com_data = INVALID_SOCKET;
chSysLockFromIsr();
- chIOAddFlagsI(sdp, IO_DISCONNECTED);
+ chnAddFlagsI(sdp, CHN_DISCONNECTED);
chSysUnlockFromIsr();
return FALSE;
case INVALID_SOCKET:
diff --git a/os/hal/platforms/SPC56x/serial_lld.c b/os/hal/platforms/SPC56x/serial_lld.c
index 935ba6d8b..7effeeb60 100644
--- a/os/hal/platforms/SPC56x/serial_lld.c
+++ b/os/hal/platforms/SPC56x/serial_lld.c
@@ -117,7 +117,7 @@ static void esci_deinit(volatile struct ESCI_tag *escip) {
* @param[in] sr eSCI SR register value
*/
static void set_error(SerialDriver *sdp, uint32_t sr) {
- ioflags_t sts = 0;
+ chnflags_t sts = 0;
if (sr & 0x08000000)
sts |= SD_OVERRUN_ERROR;
@@ -130,7 +130,7 @@ static void set_error(SerialDriver *sdp, uint32_t sr) {
/* if (sr & 0x00000000)
sts |= SD_BREAK_DETECTED;*/
chSysLockFromIsr();
- chIOAddFlagsI(sdp, sts);
+ chnAddFlagsI(sdp, sts);
chSysUnlockFromIsr();
}
@@ -156,7 +156,7 @@ static void serve_interrupt(SerialDriver *sdp) {
chSysLockFromIsr();
b = chOQGetI(&sdp->oqueue);
if (b < Q_OK) {
- chIOAddFlagsI(sdp, IO_OUTPUT_EMPTY);
+ chnAddFlagsI(sdp, CHN_OUTPUT_EMPTY);
escip->CR1.B.TIE = 0;
}
else {
diff --git a/os/hal/platforms/STM32/serial_lld.c b/os/hal/platforms/STM32/serial_lld.c
index cc60bb850..a93d36523 100644
--- a/os/hal/platforms/STM32/serial_lld.c
+++ b/os/hal/platforms/STM32/serial_lld.c
@@ -140,7 +140,7 @@ static void usart_deinit(USART_TypeDef *u) {
* @param[in] sr USART SR register value
*/
static void set_error(SerialDriver *sdp, uint16_t sr) {
- ioflags_t sts = 0;
+ chnflags_t sts = 0;
if (sr & USART_SR_ORE)
sts |= SD_OVERRUN_ERROR;
@@ -151,7 +151,7 @@ static void set_error(SerialDriver *sdp, uint16_t sr) {
if (sr & USART_SR_NE)
sts |= SD_NOISE_ERROR;
chSysLockFromIsr();
- chIOAddFlagsI(sdp, sts);
+ chnAddFlagsI(sdp, sts);
chSysUnlockFromIsr();
}
@@ -172,7 +172,7 @@ static void serve_interrupt(SerialDriver *sdp) {
/* Special case, LIN break detection.*/
if (sr & USART_SR_LBD) {
chSysLockFromIsr();
- chIOAddFlagsI(sdp, SD_BREAK_DETECTED);
+ chnAddFlagsI(sdp, SD_BREAK_DETECTED);
chSysUnlockFromIsr();
u->SR &= ~USART_SR_LBD;
}
@@ -188,7 +188,7 @@ static void serve_interrupt(SerialDriver *sdp) {
chSysLockFromIsr();
b = chOQGetI(&sdp->oqueue);
if (b < Q_OK) {
- chIOAddFlagsI(sdp, IO_OUTPUT_EMPTY);
+ chnAddFlagsI(sdp, CHN_OUTPUT_EMPTY);
u->CR1 = (cr1 & ~USART_CR1_TXEIE) | USART_CR1_TCIE;
}
else
@@ -198,7 +198,7 @@ static void serve_interrupt(SerialDriver *sdp) {
/* Physical transmission end.*/
if (sr & USART_SR_TC) {
chSysLockFromIsr();
- chIOAddFlagsI(sdp, IO_TRANSMISSION_END);
+ chnAddFlagsI(sdp, CHN_TRANSMISSION_END);
chSysUnlockFromIsr();
u->CR1 = cr1 & ~USART_CR1_TCIE;
u->SR &= ~USART_SR_TC;
diff --git a/os/hal/platforms/STM8L/serial_lld.c b/os/hal/platforms/STM8L/serial_lld.c
index b5ee21f83..b91f44a21 100644
--- a/os/hal/platforms/STM8L/serial_lld.c
+++ b/os/hal/platforms/STM8L/serial_lld.c
@@ -115,7 +115,7 @@ static void notify3(GenericQueue *qp) {
* @notapi
*/
void sd_lld_set_error(SerialDriver *sdp, uint8_t sr) {
- ioflags_t sts = 0;
+ chnflags_t sts = 0;
if (sr & USART_SR_OR)
sts |= SD_OVERRUN_ERROR;
@@ -126,7 +126,7 @@ void sd_lld_set_error(SerialDriver *sdp, uint8_t sr) {
if (sr & USART_SR_PE)
sts |= SD_PARITY_ERROR;
chSysLockFromIsr();
- chIOAddFlagsI(sdp, sts);
+ chnAddFlagsI(sdp, sts);
chSysUnlockFromIsr();
}
diff --git a/os/hal/platforms/STM8S/serial_lld.c b/os/hal/platforms/STM8S/serial_lld.c
index fbc3baeaf..610591cdf 100644
--- a/os/hal/platforms/STM8S/serial_lld.c
+++ b/os/hal/platforms/STM8S/serial_lld.c
@@ -73,7 +73,7 @@ static ROMCONST SerialConfig default_config = {
/*===========================================================================*/
static void set_error(SerialDriver *sdp, uint8_t sr) {
- ioflags_t sts = 0;
+ chnflags_t sts = 0;
/* Note, SR register bit definitions are equal for all UARTs so using
the UART1 definitions is fine.*/
@@ -86,7 +86,7 @@ static void set_error(SerialDriver *sdp, uint8_t sr) {
if (sr & UART1_SR_PE)
sts |= SD_PARITY_ERROR;
chSysLockFromIsr();
- chIOAddFlagsI(sdp, sts);
+ chnAddFlagsI(sdp, sts);
chSysUnlockFromIsr();
}
diff --git a/os/hal/platforms/Win32/serial_lld.c b/os/hal/platforms/Win32/serial_lld.c
index a144b7f50..d383317bc 100644
--- a/os/hal/platforms/Win32/serial_lld.c
+++ b/os/hal/platforms/Win32/serial_lld.c
@@ -114,7 +114,7 @@ static bool_t connint(SerialDriver *sdp) {
goto abort;
}
chSysLockFromIsr();
- chIOAddFlagsI(sdp, IO_CONNECTED);
+ chnAddFlagsI(sdp, CHN_CONNECTED);
chSysUnlockFromIsr();
return TRUE;
}
@@ -143,7 +143,7 @@ static bool_t inint(SerialDriver *sdp) {
closesocket(sdp->com_data);
sdp->com_data = INVALID_SOCKET;
chSysLockFromIsr();
- chIOAddFlagsI(sdp, IO_DISCONNECTED);
+ chnAddFlagsI(sdp, CHN_DISCONNECTED);
chSysUnlockFromIsr();
return FALSE;
case SOCKET_ERROR:
@@ -184,7 +184,7 @@ static bool_t outint(SerialDriver *sdp) {
closesocket(sdp->com_data);
sdp->com_data = INVALID_SOCKET;
chSysLockFromIsr();
- chIOAddFlagsI(sdp, IO_DISCONNECTED);
+ chnAddFlagsI(sdp, CHN_DISCONNECTED);
chSysUnlockFromIsr();
return FALSE;
case SOCKET_ERROR:
diff --git a/os/hal/src/serial.c b/os/hal/src/serial.c
index d0ea89297..aaeb5e6ee 100644
--- a/os/hal/src/serial.c
+++ b/os/hal/src/serial.c
@@ -94,8 +94,8 @@ static size_t readt(void *ip, uint8_t *bp, size_t n, systime_t time) {
return chIQReadTimeout(&((SerialDriver *)ip)->iqueue, bp, n, time);
}
-static ioflags_t getflags(void *ip) {
- _ch_get_and_clear_flags_impl(ip);
+static chnflags_t getflags(void *ip) {
+ _chn_get_and_clear_flags_impl(ip);
}
static const struct SerialDriverVMT vmt = {
@@ -139,7 +139,7 @@ void sdObjectInit(SerialDriver *sdp, qnotify_t inotify, qnotify_t onotify) {
sdp->vmt = &vmt;
chEvtInit(&sdp->event);
- sdp->flags = IO_NO_ERROR;
+ sdp->flags = CHN_NO_ERROR;
sdp->state = SD_STOP;
chIQInit(&sdp->iqueue, sdp->ib, SERIAL_BUFFERS_SIZE, inotify);
chOQInit(&sdp->oqueue, sdp->ob, SERIAL_BUFFERS_SIZE, onotify);
@@ -215,9 +215,9 @@ void sdIncomingDataI(SerialDriver *sdp, uint8_t b) {
chDbgCheck(sdp != NULL, "sdIncomingDataI");
if (chIQIsEmptyI(&sdp->iqueue))
- chIOAddFlagsI(sdp, IO_INPUT_AVAILABLE);
+ chnAddFlagsI(sdp, CHN_INPUT_AVAILABLE);
if (chIQPutI(&sdp->iqueue, b) < Q_OK)
- chIOAddFlagsI(sdp, SD_OVERRUN_ERROR);
+ chnAddFlagsI(sdp, SD_OVERRUN_ERROR);
}
/**
@@ -243,7 +243,7 @@ msg_t sdRequestDataI(SerialDriver *sdp) {
b = chOQGetI(&sdp->oqueue);
if (b < Q_OK)
- chIOAddFlagsI(sdp, IO_OUTPUT_EMPTY);
+ chnAddFlagsI(sdp, CHN_OUTPUT_EMPTY);
return b;
}
diff --git a/os/hal/src/serial_usb.c b/os/hal/src/serial_usb.c
index f007e7bdd..52c57c800 100644
--- a/os/hal/src/serial_usb.c
+++ b/os/hal/src/serial_usb.c
@@ -103,7 +103,7 @@ static size_t readt(void *ip, uint8_t *bp, size_t n, systime_t time) {
return chIQReadTimeout(&((SerialUSBDriver *)ip)->iqueue, bp, n, time);
}
-static ioflags_t getflags(void *ip) {
+static chnflags_t getflags(void *ip) {
_ch_get_and_clear_flags_impl(ip);
}
@@ -133,7 +133,7 @@ static void inotify(GenericQueue *qp) {
chSysLock();
usbStartReceiveI(sdup->config->usbp, USB_CDC_DATA_AVAILABLE_EP);
- chIOAddFlagsI(sdup, IO_INPUT_AVAILABLE);
+ chnAddFlagsI(sdup, CHN_INPUT_AVAILABLE);
sdup->iqueue.q_rdptr = sdup->iqueue.q_buffer;
sdup->iqueue.q_counter = n;
while (notempty(&sdup->iqueue.q_waiting))
@@ -160,7 +160,7 @@ static void onotify(GenericQueue *qp) {
chSysLock();
usbStartTransmitI(sdup->config->usbp, USB_CDC_DATA_REQUEST_EP);
- chIOAddFlagsI(sdup, IO_OUTPUT_EMPTY);
+ chnAddFlagsI(sdup, CHN_OUTPUT_EMPTY);
sdup->oqueue.q_wrptr = sdup->oqueue.q_buffer;
sdup->oqueue.q_counter = chQSizeI(&sdup->oqueue);
while (notempty(&sdup->oqueue.q_waiting))
@@ -195,7 +195,7 @@ void sduObjectInit(SerialUSBDriver *sdup) {
sdup->vmt = &vmt;
chEvtInit(&sdup->event);
- sdup->flags = IO_NO_ERROR;
+ sdup->flags = CHN_NO_ERROR;
sdup->state = SDU_STOP;
chIQInit(&sdup->iqueue, sdup->ib, SERIAL_USB_BUFFERS_SIZE, inotify);
chOQInit(&sdup->oqueue, sdup->ob, SERIAL_USB_BUFFERS_SIZE, onotify);
@@ -312,7 +312,7 @@ void sduDataTransmitted(USBDriver *usbp, usbep_t ep) {
chSysLockFromIsr();
usbStartTransmitI(usbp, ep);
- chIOAddFlagsI(sdup, IO_OUTPUT_EMPTY);
+ chnAddFlagsI(sdup, CHN_OUTPUT_EMPTY);
sdup->oqueue.q_wrptr = sdup->oqueue.q_buffer;
sdup->oqueue.q_counter = chQSizeI(&sdup->oqueue);
while (notempty(&sdup->oqueue.q_waiting))
@@ -348,7 +348,7 @@ void sduDataReceived(USBDriver *usbp, usbep_t ep) {
chSysLockFromIsr();
usbStartReceiveI(usbp, ep);
- chIOAddFlagsI(sdup, IO_INPUT_AVAILABLE);
+ chnAddFlagsI(sdup, CHN_INPUT_AVAILABLE);
sdup->iqueue.q_rdptr = sdup->iqueue.q_buffer;
sdup->iqueue.q_counter = n;
while (notempty(&sdup->iqueue.q_waiting))
diff --git a/os/kernel/include/ch.h b/os/kernel/include/ch.h
index 3696f78b3..073ab2280 100644
--- a/os/kernel/include/ch.h
+++ b/os/kernel/include/ch.h
@@ -123,7 +123,6 @@
#include "chinline.h"
#include "chqueues.h"
#include "chstreams.h"
-#include "chioch.h"
#include "chfiles.h"
#include "chdebug.h"
diff --git a/os/kernel/include/chioch.h b/os/kernel/include/chioch.h
deleted file mode 100644
index d8e8771f6..000000000
--- a/os/kernel/include/chioch.h
+++ /dev/null
@@ -1,370 +0,0 @@
-/*
- ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
- 2011,2012 Giovanni Di Sirio.
-
- This file is part of ChibiOS/RT.
-
- ChibiOS/RT is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- ChibiOS/RT is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-/**
- * @file chioch.h
- * @brief I/O channels.
- * @details This header defines abstract interfaces useful to access generic
- * I/O resources in a standardized way.
- *
- * @addtogroup io_channels
- * @details This module defines an abstract interface for I/O channels by
- * extending the @p BaseSequentialStream interface. Note that no code
- * is present, I/O channels are just abstract interface like
- * structures, you should look at the systems as to a set of abstract
- * C++ classes (even if written in C). Specific device drivers can
- * use/extend the interface and implement them.<br>
- * This system has the advantage to make the access to channels
- * independent from the implementation logic.
- * @{
- */
-
-#ifndef _CHIOCH_H_
-#define _CHIOCH_H_
-
-/**
- * @brief @p BaseChannel specific methods.
- */
-#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); \
- /* Channel get method with timeout specification.*/ \
- msg_t (*get)(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); \
- /* Channel read method with timeout specification.*/ \
- size_t (*readt)(void *instance, uint8_t *bp, size_t n, systime_t time);
-
-/**
- * @brief @p BaseChannel specific data.
- * @note It is empty because @p BaseChannel is only an interface without
- * implementation.
- */
-#define _base_channel_data \
- _base_sequential_stream_data
-
-/**
- * @extends BaseSequentialStreamVMT
- *
- * @brief @p BaseChannel virtual methods table.
- */
-struct BaseChannelVMT {
- _base_channel_methods
-};
-
-/**
- * @extends BaseSequentialStream
- *
- * @brief Base channel class.
- * @details This class represents a generic, byte-wide, I/O channel. This class
- * introduces generic I/O primitives with timeout specification.
- */
-typedef struct {
- /** @brief Virtual Methods Table.*/
- const struct BaseChannelVMT *vmt;
- _base_channel_data
-} 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 chIOPutWouldBlock(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 chIOGetWouldBlock(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 chIOPut(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.
- *
- * @param[in] ip pointer to a @p BaseChannel or derived class
- * @param[in] b the byte value to be written to the channel
- * @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 The operation status.
- * @retval Q_OK if the operation succeeded.
- * @retval Q_TIMEOUT if the specified time expired.
- * @retval Q_RESET if the channel associated queue (if any) was reset.
- *
- * @api
- */
-#define chIOPutTimeout(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 chIOGet(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.
- *
- * @param[in] ip pointer to a @p BaseChannel or derived class
- * @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 byte value from the queue.
- * @retval Q_TIMEOUT if the specified time expired.
- * @retval Q_RESET if the channel associated queue (if any) has been
- * reset.
- *
- * @api
- */
-#define chIOGetTimeout(ip, time) ((ip)->vmt->get(ip, time))
-
-/**
- * @brief Channel blocking write with timeout.
- * @details The function writes data from a buffer 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[out] bp pointer to the data buffer
- * @param[in] n the maximum amount of data to be transferred
- * @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 The number of bytes transferred.
- *
- * @api
- */
-#define chIOWriteTimeout(ip, bp, n, time) \
- ((ip)->vmt->writet(ip, bp, n, time))
-
-/**
- * @brief Channel blocking read with timeout.
- * @details The function reads data from a channel into a buffer. If the data
- * is not available then the calling thread is suspended.
- *
- * @param[in] ip pointer to a @p BaseChannel or derived class
- * @param[in] bp pointer to the data buffer
- * @param[in] n the maximum amount of data to be transferred
- * @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 The number of bytes transferred.
- *
- * @api
- */
-#define chIOReadTimeout(ip, bp, n, time) \
- ((ip)->vmt->readt(ip, bp, n, time))
-/** @} */
-
-#if CH_USE_EVENTS || defined(__DOXYGEN__)
-/**
- * @name I/O status flags
- * @{
- */
-/** @brief No pending conditions.*/
-#define IO_NO_ERROR 0
-/** @brief Connection happened.*/
-#define IO_CONNECTED 1
-/** @brief Disconnection happened.*/
-#define IO_DISCONNECTED 2
-/** @brief Data available in the input queue.*/
-#define IO_INPUT_AVAILABLE 4
-/** @brief Output queue empty.*/
-#define IO_OUTPUT_EMPTY 8
-/** @brief Transmission end.*/
-#define IO_TRANSMISSION_END 16
-/** @} */
-
-/**
- * @brief Type of an I/O condition flags mask.
- */
-typedef uint_fast16_t ioflags_t;
-
-/**
- * @brief @p BaseAsynchronousChannel specific methods.
- */
-#define _base_asynchronous_channel_methods \
- _base_channel_methods \
- /* Channel read method with timeout specification.*/ \
- ioflags_t (*getflags)(void *instance);
-
-/**
- * @brief @p BaseAsynchronousChannel specific data.
- */
-#define _base_asynchronous_channel_data \
- _base_channel_data \
- /* I/O condition event source.*/ \
- EventSource event; \
- /* I/O condition flags.*/ \
- ioflags_t flags;
-
-/**
- * @extends BaseChannelVMT
- *
- * @brief @p BaseAsynchronousChannel virtual methods table.
- */
-struct BaseAsynchronousChannelVMT {
- _base_asynchronous_channel_methods
-};
-
-/**
- * @extends BaseChannel
- *
- * @brief Base asynchronous channel class.
- * @details This class extends @p BaseChannel by adding event sources fields
- * for asynchronous I/O for use in an event-driven environment.
- */
-typedef struct {
- /** @brief Virtual Methods Table.*/
- const struct BaseAsynchronousChannelVMT *vmt;
- _base_asynchronous_channel_data
-} BaseAsynchronousChannel;
-
-/**
- * @name Macro Functions (BaseAsynchronousChannel)
- * @{
- */
-/**
- * @brief Returns the I/O condition event source.
- * @details The event source is broadcasted when an I/O condition happens.
- *
- * @param[in] ip pointer to a @p BaseAsynchronousChannel or derived
- * class
- * @return A pointer to an @p EventSource object.
- *
- * @api
- */
-#define chIOGetEventSource(ip) (&((ip)->event))
-
-/**
- * @brief Adds status flags to the channel's mask.
- * @details This function is usually called from the I/O ISRs in order to
- * notify I/O conditions such as data events, errors, signal
- * changes etc.
- *
- * @param[in] ip pointer to a @p BaseAsynchronousChannel or derived
- * class
- * @param[in] mask condition flags to be added to the mask
- *
- * @iclass
- */
-#define chIOAddFlagsI(ip, mask) { \
- (ip)->flags |= (mask); \
- chEvtBroadcastI(&(ip)->event); \
-}
-
-/**
- * @brief Returns and clears the status flags associated to the channel.
- *
- * @param[in] ip pointer to a @p BaseAsynchronousChannel or derived
- * class
- * @return The condition flags modified since last time this
- * function was invoked.
- *
- * @api
- */
-#define chIOGetAndClearFlags(ip) ((ip)->vmt->getflags(ip))
-/** @} */
-
-/**
- * @brief Default implementation of the @p getflags virtual method.
- *
- * @param[in] ip pointer to a @p BaseAsynchronousChannel or derived
- * class
- * @return The condition flags modified since last time this
- * function was invoked.
- *
- * @notapi
- */
-#define _ch_get_and_clear_flags_impl(ip) \
- ioflags_t mask; \
- chSysLock(); \
- mask = ((BaseAsynchronousChannel *)(ip))->flags; \
- ((BaseAsynchronousChannel *)(ip))->flags = IO_NO_ERROR; \
- chSysUnlock(); \
- return mask
-
-#endif /* CH_USE_EVENTS */
-
-#endif /* _CHIOCH_H_ */
-
-/** @} */
diff --git a/os/various/chprintf.c b/os/various/chprintf.c
index 1b2c3329c..3cb66bf91 100644
--- a/os/various/chprintf.c
+++ b/os/various/chprintf.c
@@ -29,6 +29,11 @@
#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,
@@ -83,7 +88,7 @@ static char *ftoa(char *p, double num) {
/**
* @brief System formatted output function.
* @details This function implements a minimal @p printf() like functionality
- * with output on a @p BaseChannel.
+ * with output on a @p BaseSequentialStream.
* The general parameters format is: %[-][width|*][.precision|*][l|L]p.
* The following parameter types (p) are supported:
* - <b>x</b> hexadecimal integer.
@@ -98,10 +103,10 @@ static char *ftoa(char *p, double num) {
* - <b>s</b> string.
* .
*
- * @param[in] chp pointer to a @p BaseChannel implementing object
+ * @param[in] chp pointer to a @p BaseSequentialStream implementing object
* @param[in] fmt formatting string
*/
-void chprintf(BaseChannel *chp, const char *fmt, ...) {
+void chprintf(BaseSequentialStream *chp, const char *fmt, ...) {
va_list ap;
char tmpbuf[MAX_FILLER + 1];
char *p, *s, c, filler;
@@ -120,7 +125,7 @@ void chprintf(BaseChannel *chp, const char *fmt, ...) {
return;
}
if (c != '%') {
- chIOPut(chp, (uint8_t)c);
+ _putc(chp, (uint8_t)c);
continue;
}
p = tmpbuf;
@@ -235,18 +240,18 @@ unsigned_common:
width = -width;
if (width < 0) {
if (*s == '-' && filler == '0') {
- chIOPut(chp, (uint8_t)*s++);
+ _putc(chp, (uint8_t)*s++);
i--;
}
do
- chIOPut(chp, (uint8_t)filler);
+ _putc(chp, (uint8_t)filler);
while (++width != 0);
}
while (--i >= 0)
- chIOPut(chp, (uint8_t)*s++);
+ _putc(chp, (uint8_t)*s++);
while (width) {
- chIOPut(chp, (uint8_t)filler);
+ _putc(chp, (uint8_t)filler);
width--;
}
}
diff --git a/os/various/chprintf.h b/os/various/chprintf.h
index 866dfa067..039b23a6b 100644
--- a/os/various/chprintf.h
+++ b/os/various/chprintf.h
@@ -39,7 +39,7 @@
#ifdef __cplusplus
extern "C" {
#endif
- void chprintf(BaseChannel *chp, const char *fmt, ...);
+ void chprintf(BaseSequentialStream *chp, const char *fmt, ...);
#ifdef __cplusplus
}
#endif
diff --git a/os/various/shell.c b/os/various/shell.c
index bd0359052..fd9451f2e 100644
--- a/os/various/shell.c
+++ b/os/various/shell.c
@@ -38,6 +38,11 @@
*/
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)
@@ -55,12 +60,12 @@ static char *_strtok(char *str, const char *delim, char **saveptr) {
return *token ? token : NULL;
}
-static void usage(BaseChannel *chp, char *p) {
+static void usage(BaseSequentialStream *chp, char *p) {
chprintf(chp, "Usage: %s\r\n", p);
}
-static void list_commands(BaseChannel *chp, const ShellCommand *scp) {
+static void list_commands(BaseSequentialStream *chp, const ShellCommand *scp) {
while (scp->sc_name != NULL) {
chprintf(chp, "%s ", scp->sc_name);
@@ -68,7 +73,7 @@ static void list_commands(BaseChannel *chp, const ShellCommand *scp) {
}
}
-static void cmd_info(BaseChannel *chp, int argc, char *argv[]) {
+static void cmd_info(BaseSequentialStream *chp, int argc, char *argv[]) {
(void)argv;
if (argc > 0) {
@@ -100,7 +105,7 @@ static void cmd_info(BaseChannel *chp, int argc, char *argv[]) {
#endif
}
-static void cmd_systime(BaseChannel *chp, int argc, char *argv[]) {
+static void cmd_systime(BaseSequentialStream *chp, int argc, char *argv[]) {
(void)argv;
if (argc > 0) {
@@ -119,7 +124,7 @@ static ShellCommand local_commands[] = {
{NULL, NULL}
};
-static bool_t cmdexec(const ShellCommand *scp, BaseChannel *chp,
+static bool_t cmdexec(const ShellCommand *scp, BaseSequentialStream *chp,
char *name, int argc, char *argv[]) {
while (scp->sc_name != NULL) {
@@ -135,7 +140,7 @@ static bool_t cmdexec(const ShellCommand *scp, BaseChannel *chp,
/**
* @brief Shell thread function.
*
- * @param[in] p pointer to a @p BaseChannel object
+ * @param[in] p pointer to a @p BaseSequentialStream object
* @return Termination reason.
* @retval RDY_OK terminated by command.
* @retval RDY_RESET terminated by reset condition on the I/O channel.
@@ -143,7 +148,7 @@ static bool_t cmdexec(const ShellCommand *scp, BaseChannel *chp,
static msg_t shell_thread(void *p) {
int n;
msg_t msg = RDY_OK;
- BaseChannel *chp = ((ShellConfig *)p)->sc_channel;
+ BaseSequentialStream *chp = ((ShellConfig *)p)->sc_channel;
const ShellCommand *scp = ((ShellConfig *)p)->sc_commands;
char *lp, *cmd, *tokp, line[SHELL_MAX_LINE_LENGTH];
char *args[SHELL_MAX_ARGUMENTS + 1];
@@ -245,19 +250,20 @@ Thread *shellCreateStatic(const ShellConfig *scp, void *wsp,
/**
* @brief Reads a whole line from the input channel.
*
- * @param[in] chp pointer to a @p BaseChannel object
+ * @param[in] chp pointer to a @p BaseSequentialStream object
* @param[in] line pointer to the line buffer
* @param[in] size buffer maximum length
* @return The operation status.
* @retval TRUE the channel was reset or CTRL-D pressed.
* @retval FALSE operation successful.
*/
-bool_t shellGetLine(BaseChannel *chp, char *line, unsigned size) {
+bool_t shellGetLine(BaseSequentialStream *chp, char *line, unsigned size) {
char *p = line;
while (TRUE) {
- short c = (short)chIOGet(chp);
- if (c < 0)
+ char c;
+
+ if (chSequentialStreamRead(chp, (uint8_t *)&c, 1) == 0)
return TRUE;
if (c == 4) {
chprintf(chp, "^D");
@@ -265,9 +271,9 @@ bool_t shellGetLine(BaseChannel *chp, char *line, unsigned size) {
}
if (c == 8) {
if (p != line) {
- chIOPut(chp, (uint8_t)c);
- chIOPut(chp, 0x20);
- chIOPut(chp, (uint8_t)c);
+ _putc(chp, c);
+ _putc(chp, 0x20);
+ _putc(chp, c);
p--;
}
continue;
@@ -280,7 +286,7 @@ bool_t shellGetLine(BaseChannel *chp, char *line, unsigned size) {
if (c < 0x20)
continue;
if (p < line + size - 1) {
- chIOPut(chp, (uint8_t)c);
+ _putc(chp, c);
*p++ = (char)c;
}
}
diff --git a/os/various/shell.h b/os/various/shell.h
index 17c3609ab..6da791110 100644
--- a/os/various/shell.h
+++ b/os/various/shell.h
@@ -46,7 +46,7 @@
/**
* @brief Command handler function type.
*/
-typedef void (*shellcmd_t)(BaseChannel *chp, int argc, char *argv[]);
+typedef void (*shellcmd_t)(BaseSequentialStream *chp, int argc, char *argv[]);
/**
* @brief Custom command entry type.
@@ -60,7 +60,7 @@ typedef struct {
* @brief Shell descriptor type.
*/
typedef struct {
- BaseChannel *sc_channel; /**< @brief I/O channel associated
+ BaseSequentialStream *sc_channel; /**< @brief I/O channel associated
to the shell. */
const ShellCommand *sc_commands; /**< @brief Shell extra commands
table. */
@@ -77,7 +77,7 @@ extern "C" {
Thread *shellCreate(const ShellConfig *scp, size_t size, tprio_t prio);
Thread *shellCreateStatic(const ShellConfig *scp, void *wsp,
size_t size, tprio_t prio);
- bool_t shellGetLine(BaseChannel *chp, char *line, unsigned size);
+ bool_t shellGetLine(BaseSequentialStream *chp, char *line, unsigned size);
#ifdef __cplusplus
}
#endif