aboutsummaryrefslogtreecommitdiffstats
path: root/os
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2011-01-09 10:10:39 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2011-01-09 10:10:39 +0000
commitff333430f1317247299863b592293faa7799e0a4 (patch)
treee7fbb1acfc6125c96b83b1f1097517d6f6f4ec9d /os
parentab5dc4cae1ee3d7ab47afb58ee9f52056c507d3a (diff)
downloadChibiOS-ff333430f1317247299863b592293faa7799e0a4.tar.gz
ChibiOS-ff333430f1317247299863b592293faa7799e0a4.tar.bz2
ChibiOS-ff333430f1317247299863b592293faa7799e0a4.zip
Serial driver changes, bug 3153550 fixed.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2625 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os')
-rw-r--r--os/hal/include/serial.h18
-rw-r--r--os/hal/platforms/AT91SAM7/serial_lld.c6
-rw-r--r--os/hal/platforms/AT91SAM7/serial_lld.h9
-rw-r--r--os/hal/platforms/AVR/serial_lld.c4
-rw-r--r--os/hal/platforms/AVR/serial_lld.h9
-rw-r--r--os/hal/platforms/LPC11xx/serial_lld.c12
-rw-r--r--os/hal/platforms/LPC11xx/serial_lld.h9
-rw-r--r--os/hal/platforms/LPC13xx/serial_lld.c12
-rw-r--r--os/hal/platforms/LPC13xx/serial_lld.h9
-rw-r--r--os/hal/platforms/LPC214x/serial_lld.c12
-rw-r--r--os/hal/platforms/LPC214x/serial_lld.h4
-rw-r--r--os/hal/platforms/MSP430/serial_lld.c4
-rw-r--r--os/hal/platforms/MSP430/serial_lld.h9
-rw-r--r--os/hal/platforms/SPC56x/serial_lld.c6
-rw-r--r--os/hal/platforms/SPC56x/serial_lld.h9
-rw-r--r--os/hal/platforms/STM32/serial_lld.c6
-rw-r--r--os/hal/platforms/STM32/serial_lld.h9
-rw-r--r--os/hal/platforms/STM8L/serial_lld.c4
-rw-r--r--os/hal/platforms/STM8L/serial_lld.h9
-rw-r--r--os/hal/platforms/STM8S/serial_lld.c4
-rw-r--r--os/hal/platforms/STM8S/serial_lld.h9
-rw-r--r--os/hal/platforms/Win32/serial_lld.c6
-rw-r--r--os/hal/platforms/Win32/serial_lld.h4
-rw-r--r--os/hal/src/serial.c59
-rw-r--r--os/hal/templates/serial_lld.h4
-rw-r--r--os/kernel/include/chioch.h82
26 files changed, 121 insertions, 207 deletions
diff --git a/os/hal/include/serial.h b/os/hal/include/serial.h
index bbbd9eda5..d67c3079a 100644
--- a/os/hal/include/serial.h
+++ b/os/hal/include/serial.h
@@ -34,22 +34,16 @@
/* Driver constants. */
/*===========================================================================*/
-/** @brief No pending conditions.*/
-#define SD_NO_ERROR 0
-/** @brief Connection happened.*/
-#define SD_CONNECTED 1
-/** @brief Disconnection happened.*/
-#define SD_DISCONNECTED 2
/** @brief Parity error happened.*/
-#define SD_PARITY_ERROR 4
+#define SD_PARITY_ERROR 16
/** @brief Framing error happened.*/
-#define SD_FRAMING_ERROR 8
+#define SD_FRAMING_ERROR 32
/** @brief Overflow happened.*/
-#define SD_OVERRUN_ERROR 16
+#define SD_OVERRUN_ERROR 64
/** @brief Noise on the line.*/
-#define SD_NOISE_ERROR 32
+#define SD_NOISE_ERROR 128
/** @brief Break detected.*/
-#define SD_BREAK_DETECTED 64
+#define SD_BREAK_DETECTED 256
/*===========================================================================*/
/* Driver pre-compile time settings. */
@@ -311,8 +305,6 @@ extern "C" {
void sdStop(SerialDriver *sdp);
void sdIncomingDataI(SerialDriver *sdp, uint8_t b);
msg_t sdRequestDataI(SerialDriver *sdp);
- void sdAddFlagsI(SerialDriver *sdp, sdflags_t mask);
- sdflags_t sdGetAndClearFlags(SerialDriver *sdp);
#ifdef __cplusplus
}
#endif
diff --git a/os/hal/platforms/AT91SAM7/serial_lld.c b/os/hal/platforms/AT91SAM7/serial_lld.c
index 04e72a795..f34f2b6d8 100644
--- a/os/hal/platforms/AT91SAM7/serial_lld.c
+++ b/os/hal/platforms/AT91SAM7/serial_lld.c
@@ -136,7 +136,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) {
- sdflags_t sts = 0;
+ ioflags_t sts = 0;
if (csr & AT91C_US_OVRE)
sts |= SD_OVERRUN_ERROR;
@@ -147,7 +147,7 @@ static void set_error(SerialDriver *sdp, AT91_REG csr) {
if (csr & AT91C_US_RXBRK)
sts |= SD_BREAK_DETECTED;
chSysLockFromIsr();
- sdAddFlagsI(sdp, sts);
+ chIOAddFlagsI(sdp, sts);
chSysUnlockFromIsr();
}
@@ -178,7 +178,7 @@ void sd_lld_serve_interrupt(SerialDriver *sdp) {
chSysLockFromIsr();
b = chOQGetI(&sdp->oqueue);
if (b < Q_OK) {
- chEvtBroadcastI(&sdp->oevent);
+ chIOAddFlagsI(sdp, IO_OUTPUT_EMPTY);
u->US_IDR = AT91C_US_TXRDY;
}
else
diff --git a/os/hal/platforms/AT91SAM7/serial_lld.h b/os/hal/platforms/AT91SAM7/serial_lld.h
index 027cf90cd..94aca128b 100644
--- a/os/hal/platforms/AT91SAM7/serial_lld.h
+++ b/os/hal/platforms/AT91SAM7/serial_lld.h
@@ -95,11 +95,6 @@
/*===========================================================================*/
/**
- * @brief Serial Driver condition flags type.
- */
-typedef uint32_t sdflags_t;
-
-/**
* @brief AT91SAM7 Serial Driver configuration structure.
* @details An instance of this structure must be passed to @p sdStart()
* in order to configure and start a serial driver operations.
@@ -128,10 +123,6 @@ typedef struct {
InputQueue iqueue; \
/* Output queue.*/ \
OutputQueue oqueue; \
- /* Status Change @p EventSource.*/ \
- EventSource sevent; \
- /* I/O driver status flags.*/ \
- sdflags_t flags; \
/* Input circular buffer.*/ \
uint8_t ib[SERIAL_BUFFERS_SIZE]; \
/* Output circular buffer.*/ \
diff --git a/os/hal/platforms/AVR/serial_lld.c b/os/hal/platforms/AVR/serial_lld.c
index a21e0e625..f78abac18 100644
--- a/os/hal/platforms/AVR/serial_lld.c
+++ b/os/hal/platforms/AVR/serial_lld.c
@@ -69,7 +69,7 @@ static const SerialConfig default_config = {
/*===========================================================================*/
static void set_error(uint8_t sra, SerialDriver *sdp) {
- sdflags_t sts = 0;
+ ioflags_t sts = 0;
if (sra & (1 << DOR))
sts |= SD_OVERRUN_ERROR;
@@ -78,7 +78,7 @@ static void set_error(uint8_t sra, SerialDriver *sdp) {
if (sra & (1 << FE))
sts |= SD_FRAMING_ERROR;
chSysLockFromIsr();
- sdAddFlagsI(sdp, sts);
+ chIOAddFlagsI(sdp, sts);
chSysUnlockFromIsr();
}
diff --git a/os/hal/platforms/AVR/serial_lld.h b/os/hal/platforms/AVR/serial_lld.h
index 15d3352b1..4a2ff843a 100644
--- a/os/hal/platforms/AVR/serial_lld.h
+++ b/os/hal/platforms/AVR/serial_lld.h
@@ -65,11 +65,6 @@
/*===========================================================================*/
/**
- * @brief Serial Driver condition flags type.
- */
-typedef uint8_t sdflags_t;
-
-/**
* @brief AVR Serial Driver configuration structure.
* @details An instance of this structure must be passed to @p sdStart()
* in order to configure and start a serial driver operations.
@@ -96,10 +91,6 @@ typedef struct {
InputQueue iqueue; \
/* Output queue.*/ \
OutputQueue oqueue; \
- /* Status Change @p EventSource.*/ \
- EventSource sevent; \
- /* I/O driver status flags.*/ \
- sdflags_t flags; \
/* Input circular buffer.*/ \
uint8_t ib[SERIAL_BUFFERS_SIZE]; \
/* Output circular buffer.*/ \
diff --git a/os/hal/platforms/LPC11xx/serial_lld.c b/os/hal/platforms/LPC11xx/serial_lld.c
index 8c0853315..ecd080eaf 100644
--- a/os/hal/platforms/LPC11xx/serial_lld.c
+++ b/os/hal/platforms/LPC11xx/serial_lld.c
@@ -100,7 +100,7 @@ static void uart_deinit(LPC_UART_TypeDef *u) {
* @param[in] err UART LSR register value
*/
static void set_error(SerialDriver *sdp, IOREG32 err) {
- sdflags_t sts = 0;
+ ioflags_t sts = 0;
if (err & LSR_OVERRUN)
sts |= SD_OVERRUN_ERROR;
@@ -111,7 +111,7 @@ static void set_error(SerialDriver *sdp, IOREG32 err) {
if (err & LSR_BREAK)
sts |= SD_BREAK_DETECTED;
chSysLockFromIsr();
- sdAddFlagsI(sdp, sts);
+ chIOAddFlagsI(sdp, sts);
chSysUnlockFromIsr();
}
@@ -138,12 +138,12 @@ static void serve_interrupt(SerialDriver *sdp) {
case IIR_SRC_RX:
chSysLockFromIsr();
if (chIQIsEmptyI(&sdp->iqueue))
- chEvtBroadcastI(&sdp->ievent);
+ chIOAddFlagsI(sdp, IO_INPUT_AVAILABLE);
chSysUnlockFromIsr();
while (u->LSR & LSR_RBR_FULL) {
chSysLockFromIsr();
if (chIQPutI(&sdp->iqueue, u->RBR) < Q_OK)
- sdAddFlagsI(sdp, SD_OVERRUN_ERROR);
+ chIOAddFlagsI(sdp, SD_OVERRUN_ERROR);
chSysUnlockFromIsr();
}
break;
@@ -159,7 +159,7 @@ static void serve_interrupt(SerialDriver *sdp) {
if (b < Q_OK) {
u->IER &= ~IER_THRE;
chSysLockFromIsr();
- chEvtBroadcastI(&sdp->oevent);
+ chIOAddFlagsI(sdp, IO_OUTPUT_EMPTY);
chSysUnlockFromIsr();
break;
}
@@ -185,7 +185,7 @@ static void preload(SerialDriver *sdp) {
do {
msg_t b = chOQGetI(&sdp->oqueue);
if (b < Q_OK) {
- chEvtBroadcastI(&sdp->oevent);
+ chIOAddFlagsI(sdp, IO_OUTPUT_EMPTY);
return;
}
u->THR = b;
diff --git a/os/hal/platforms/LPC11xx/serial_lld.h b/os/hal/platforms/LPC11xx/serial_lld.h
index 37c2afbb7..a2e8acc4b 100644
--- a/os/hal/platforms/LPC11xx/serial_lld.h
+++ b/os/hal/platforms/LPC11xx/serial_lld.h
@@ -142,11 +142,6 @@
/*===========================================================================*/
/**
- * @brief Serial Driver condition flags type.
- */
-typedef uint32_t sdflags_t;
-
-/**
* @brief LPC11xx Serial Driver configuration structure.
* @details An instance of this structure must be passed to @p sdStart()
* in order to configure and start a serial driver operations.
@@ -177,10 +172,6 @@ typedef struct {
InputQueue iqueue; \
/* Output queue.*/ \
OutputQueue oqueue; \
- /* Status Change @p EventSource.*/ \
- EventSource sevent; \
- /* I/O driver status flags.*/ \
- sdflags_t flags; \
/* Input circular buffer.*/ \
uint8_t ib[SERIAL_BUFFERS_SIZE]; \
/* Output circular buffer.*/ \
diff --git a/os/hal/platforms/LPC13xx/serial_lld.c b/os/hal/platforms/LPC13xx/serial_lld.c
index 5dc014d5c..b0f53d97a 100644
--- a/os/hal/platforms/LPC13xx/serial_lld.c
+++ b/os/hal/platforms/LPC13xx/serial_lld.c
@@ -100,7 +100,7 @@ static void uart_deinit(LPC_UART_TypeDef *u) {
* @param[in] err UART LSR register value
*/
static void set_error(SerialDriver *sdp, IOREG32 err) {
- sdflags_t sts = 0;
+ ioflags_t sts = 0;
if (err & LSR_OVERRUN)
sts |= SD_OVERRUN_ERROR;
@@ -111,7 +111,7 @@ static void set_error(SerialDriver *sdp, IOREG32 err) {
if (err & LSR_BREAK)
sts |= SD_BREAK_DETECTED;
chSysLockFromIsr();
- sdAddFlagsI(sdp, sts);
+ chIOAddFlagsI(sdp, sts);
chSysUnlockFromIsr();
}
@@ -138,12 +138,12 @@ static void serve_interrupt(SerialDriver *sdp) {
case IIR_SRC_RX:
chSysLockFromIsr();
if (chIQIsEmptyI(&sdp->iqueue))
- chEvtBroadcastI(&sdp->ievent);
+ chIOAddFlagsI(sdp, IO_INPUT_AVAILABLE);
chSysUnlockFromIsr();
while (u->LSR & LSR_RBR_FULL) {
chSysLockFromIsr();
if (chIQPutI(&sdp->iqueue, u->RBR) < Q_OK)
- sdAddFlagsI(sdp, SD_OVERRUN_ERROR);
+ chIOAddFlagsI(sdp, SD_OVERRUN_ERROR);
chSysUnlockFromIsr();
}
break;
@@ -159,7 +159,7 @@ static void serve_interrupt(SerialDriver *sdp) {
if (b < Q_OK) {
u->IER &= ~IER_THRE;
chSysLockFromIsr();
- chEvtBroadcastI(&sdp->oevent);
+ chIOAddFlagsI(sdp, IO_OUTPUT_EMPTY);
chSysUnlockFromIsr();
break;
}
@@ -185,7 +185,7 @@ static void preload(SerialDriver *sdp) {
do {
msg_t b = chOQGetI(&sdp->oqueue);
if (b < Q_OK) {
- chEvtBroadcastI(&sdp->oevent);
+ chIOAddFlagsI(sdp, IO_OUTPUT_EMPTY);
return;
}
u->THR = b;
diff --git a/os/hal/platforms/LPC13xx/serial_lld.h b/os/hal/platforms/LPC13xx/serial_lld.h
index 7a7f88c54..3636f224a 100644
--- a/os/hal/platforms/LPC13xx/serial_lld.h
+++ b/os/hal/platforms/LPC13xx/serial_lld.h
@@ -142,11 +142,6 @@
/*===========================================================================*/
/**
- * @brief Serial Driver condition flags type.
- */
-typedef uint32_t sdflags_t;
-
-/**
* @brief LPC13xx Serial Driver configuration structure.
* @details An instance of this structure must be passed to @p sdStart()
* in order to configure and start a serial driver operations.
@@ -177,10 +172,6 @@ typedef struct {
InputQueue iqueue; \
/* Output queue.*/ \
OutputQueue oqueue; \
- /* Status Change @p EventSource.*/ \
- EventSource sevent; \
- /* I/O driver status flags.*/ \
- sdflags_t flags; \
/* Input circular buffer.*/ \
uint8_t ib[SERIAL_BUFFERS_SIZE]; \
/* Output circular buffer.*/ \
diff --git a/os/hal/platforms/LPC214x/serial_lld.c b/os/hal/platforms/LPC214x/serial_lld.c
index c28cd42c1..cc6280d79 100644
--- a/os/hal/platforms/LPC214x/serial_lld.c
+++ b/os/hal/platforms/LPC214x/serial_lld.c
@@ -105,7 +105,7 @@ static void uart_deinit(UART *u) {
* @param[in] err UART LSR register value
*/
static void set_error(SerialDriver *sdp, IOREG32 err) {
- sdflags_t sts = 0;
+ ioflags_t sts = 0;
if (err & LSR_OVERRUN)
sts |= SD_OVERRUN_ERROR;
@@ -116,7 +116,7 @@ static void set_error(SerialDriver *sdp, IOREG32 err) {
if (err & LSR_BREAK)
sts |= SD_BREAK_DETECTED;
chSysLockFromIsr();
- sdAddFlagsI(sdp, sts);
+ chIOAddFlagsI(sdp, sts);
chSysUnlockFromIsr();
}
@@ -144,12 +144,12 @@ static void serve_interrupt(SerialDriver *sdp) {
case IIR_SRC_RX:
chSysLockFromIsr();
if (chIQIsEmptyI(&sdp->iqueue))
- chEvtBroadcastI(&sdp->ievent);
+ chIOAddFlagsI(sdp, IO_INPUT_AVAILABLE);
chSysUnlockFromIsr();
while (u->UART_LSR & LSR_RBR_FULL) {
chSysLockFromIsr();
if (chIQPutI(&sdp->iqueue, u->UART_RBR) < Q_OK)
- sdAddFlagsI(sdp, SD_OVERRUN_ERROR);
+ chIOAddFlagsI(sdp, SD_OVERRUN_ERROR);
chSysUnlockFromIsr();
}
break;
@@ -165,7 +165,7 @@ static void serve_interrupt(SerialDriver *sdp) {
if (b < Q_OK) {
u->UART_IER &= ~IER_THRE;
chSysLockFromIsr();
- chEvtBroadcastI(&sdp->oevent);
+ chIOAddFlagsI(sdp, IO_OUTPUT_EMPTY);
chSysUnlockFromIsr();
break;
}
@@ -191,7 +191,7 @@ static void preload(SerialDriver *sdp) {
do {
msg_t b = chOQGetI(&sdp->oqueue);
if (b < Q_OK) {
- chEvtBroadcastI(&sdp->oevent);
+ chIOAddFlagsI(sdp, IO_OUTPUT_EMPTY);
return;
}
u->UART_THR = b;
diff --git a/os/hal/platforms/LPC214x/serial_lld.h b/os/hal/platforms/LPC214x/serial_lld.h
index 6398e9483..f14b9524b 100644
--- a/os/hal/platforms/LPC214x/serial_lld.h
+++ b/os/hal/platforms/LPC214x/serial_lld.h
@@ -131,10 +131,6 @@ typedef struct {
InputQueue iqueue; \
/* Output queue.*/ \
OutputQueue oqueue; \
- /* Status Change @p EventSource.*/ \
- EventSource sevent; \
- /* I/O driver status flags.*/ \
- sdflags_t flags; \
/* Input circular buffer.*/ \
uint8_t ib[SERIAL_BUFFERS_SIZE]; \
/* Output circular buffer.*/ \
diff --git a/os/hal/platforms/MSP430/serial_lld.c b/os/hal/platforms/MSP430/serial_lld.c
index 633107412..c6000d7a8 100644
--- a/os/hal/platforms/MSP430/serial_lld.c
+++ b/os/hal/platforms/MSP430/serial_lld.c
@@ -61,7 +61,7 @@ static const SerialConfig default_config = {
/*===========================================================================*/
static void set_error(SerialDriver *sdp, uint8_t urctl) {
- sdflags_t sts = 0;
+ ioflags_t sts = 0;
if (urctl & OE)
sts |= SD_OVERRUN_ERROR;
@@ -72,7 +72,7 @@ static void set_error(SerialDriver *sdp, uint8_t urctl) {
if (urctl & BRK)
sts |= SD_BREAK_DETECTED;
chSysLockFromIsr();
- sdAddFlagsI(sdp, sts);
+ chIOAddFlagsI(sdp, sts);
chSysUnlockFromIsr();
}
diff --git a/os/hal/platforms/MSP430/serial_lld.h b/os/hal/platforms/MSP430/serial_lld.h
index 4803ace6e..42788abcf 100644
--- a/os/hal/platforms/MSP430/serial_lld.h
+++ b/os/hal/platforms/MSP430/serial_lld.h
@@ -65,11 +65,6 @@
/*===========================================================================*/
/**
- * @brief Serial Driver condition flags type.
- */
-typedef uint8_t sdflags_t;
-
-/**
* @brief MSP430 Serial Driver configuration structure.
* @details An instance of this structure must be passed to @p sdStart()
* in order to configure and start a serial driver operations.
@@ -100,10 +95,6 @@ typedef struct {
InputQueue iqueue; \
/* Output queue.*/ \
OutputQueue oqueue; \
- /* Status Change @p EventSource.*/ \
- EventSource sevent; \
- /* I/O driver status flags.*/ \
- sdflags_t flags; \
/* Input circular buffer.*/ \
uint8_t ib[SERIAL_BUFFERS_SIZE]; \
/* Output circular buffer.*/ \
diff --git a/os/hal/platforms/SPC56x/serial_lld.c b/os/hal/platforms/SPC56x/serial_lld.c
index 8da5e4fcf..afb23086a 100644
--- a/os/hal/platforms/SPC56x/serial_lld.c
+++ b/os/hal/platforms/SPC56x/serial_lld.c
@@ -116,7 +116,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) {
- sdflags_t sts = 0;
+ ioflags_t sts = 0;
if (sr & 0x08000000)
sts |= SD_OVERRUN_ERROR;
@@ -129,7 +129,7 @@ static void set_error(SerialDriver *sdp, uint32_t sr) {
/* if (sr & 0x00000000)
sts |= SD_BREAK_DETECTED;*/
chSysLockFromIsr();
- sdAddFlagsI(sdp, sts);
+ chIOAddFlagsI(sdp, sts);
chSysUnlockFromIsr();
}
@@ -155,7 +155,7 @@ static void serve_interrupt(SerialDriver *sdp) {
chSysLockFromIsr();
b = chOQGetI(&sdp->oqueue);
if (b < Q_OK) {
- chEvtBroadcastI(&sdp->oevent);
+ chIOAddFlagsI(sdp, IO_OUTPUT_EMPTY);
escip->CR1.B.TIE = 0;
}
else {
diff --git a/os/hal/platforms/SPC56x/serial_lld.h b/os/hal/platforms/SPC56x/serial_lld.h
index fdfe37c49..510e3298e 100644
--- a/os/hal/platforms/SPC56x/serial_lld.h
+++ b/os/hal/platforms/SPC56x/serial_lld.h
@@ -87,11 +87,6 @@
/*===========================================================================*/
/**
- * @brief Serial Driver condition flags type.
- */
-typedef uint8_t sdflags_t;
-
-/**
* @brief Generic Serial Driver configuration structure.
* @details An instance of this structure must be passed to @p sdStart()
* in order to configure and start a serial driver operations.
@@ -121,10 +116,6 @@ typedef struct {
InputQueue iqueue; \
/* Output queue.*/ \
OutputQueue oqueue; \
- /* Status Change @p EventSource.*/ \
- EventSource sevent; \
- /* I/O driver status flags.*/ \
- sdflags_t flags; \
/* Input circular buffer.*/ \
uint8_t ib[SERIAL_BUFFERS_SIZE]; \
/* Output circular buffer.*/ \
diff --git a/os/hal/platforms/STM32/serial_lld.c b/os/hal/platforms/STM32/serial_lld.c
index f68d54d50..84e42f44d 100644
--- a/os/hal/platforms/STM32/serial_lld.c
+++ b/os/hal/platforms/STM32/serial_lld.c
@@ -129,7 +129,7 @@ static void usart_deinit(USART_TypeDef *u) {
* @param[in] sr USART SR register value
*/
static void set_error(SerialDriver *sdp, uint16_t sr) {
- sdflags_t sts = 0;
+ ioflags_t sts = 0;
if (sr & USART_SR_ORE)
sts |= SD_OVERRUN_ERROR;
@@ -142,7 +142,7 @@ static void set_error(SerialDriver *sdp, uint16_t sr) {
if (sr & USART_SR_LBD)
sts |= SD_BREAK_DETECTED;
chSysLockFromIsr();
- sdAddFlagsI(sdp, sts);
+ chIOAddFlagsI(sdp, sts);
chSysUnlockFromIsr();
}
@@ -172,7 +172,7 @@ static void serve_interrupt(SerialDriver *sdp) {
chSysLockFromIsr();
b = chOQGetI(&sdp->oqueue);
if (b < Q_OK) {
- chEvtBroadcastI(&sdp->oevent);
+ chIOAddFlagsI(sdp, IO_OUTPUT_EMPTY);
u->CR1 = cr1 & ~USART_CR1_TXEIE;
}
else
diff --git a/os/hal/platforms/STM32/serial_lld.h b/os/hal/platforms/STM32/serial_lld.h
index 5d7d80c11..d16e1923d 100644
--- a/os/hal/platforms/STM32/serial_lld.h
+++ b/os/hal/platforms/STM32/serial_lld.h
@@ -153,11 +153,6 @@
/*===========================================================================*/
/**
- * @brief Serial Driver condition flags type.
- */
-typedef uint32_t sdflags_t;
-
-/**
* @brief STM32 Serial Driver configuration structure.
* @details An instance of this structure must be passed to @p sdStart()
* in order to configure and start a serial driver operations.
@@ -195,10 +190,6 @@ typedef struct {
InputQueue iqueue; \
/* Output queue.*/ \
OutputQueue oqueue; \
- /* Status Change @p EventSource.*/ \
- EventSource sevent; \
- /* I/O driver status flags.*/ \
- sdflags_t flags; \
/* Input circular buffer.*/ \
uint8_t ib[SERIAL_BUFFERS_SIZE]; \
/* Output circular buffer.*/ \
diff --git a/os/hal/platforms/STM8L/serial_lld.c b/os/hal/platforms/STM8L/serial_lld.c
index d5c102cfe..887dd4967 100644
--- a/os/hal/platforms/STM8L/serial_lld.c
+++ b/os/hal/platforms/STM8L/serial_lld.c
@@ -114,7 +114,7 @@ static void notify3(GenericQueue *qp) {
* @notapi
*/
void sd_lld_set_error(SerialDriver *sdp, uint8_t sr) {
- sdflags_t sts = 0;
+ ioflags_t sts = 0;
if (sr & USART_SR_OR)
sts |= SD_OVERRUN_ERROR;
@@ -125,7 +125,7 @@ void sd_lld_set_error(SerialDriver *sdp, uint8_t sr) {
if (sr & USART_SR_PE)
sts |= SD_PARITY_ERROR;
chSysLockFromIsr();
- sdAddFlagsI(sdp, sts);
+ chIOAddFlagsI(sdp, sts);
chSysUnlockFromIsr();
}
diff --git a/os/hal/platforms/STM8L/serial_lld.h b/os/hal/platforms/STM8L/serial_lld.h
index d9fd75bf1..c4943433a 100644
--- a/os/hal/platforms/STM8L/serial_lld.h
+++ b/os/hal/platforms/STM8L/serial_lld.h
@@ -96,11 +96,6 @@
/*===========================================================================*/
/**
- * @brief Serial Driver condition flags type.
- */
-typedef uint8_t sdflags_t;
-
-/**
* @brief Generic Serial Driver configuration structure.
* @details An instance of this structure must be passed to @p sdStart()
* in order to configure and start a serial driver operations.
@@ -130,10 +125,6 @@ typedef struct {
InputQueue iqueue; \
/* Output queue.*/ \
OutputQueue oqueue; \
- /* Status Change @p EventSource.*/ \
- EventSource sevent; \
- /* I/O driver status flags.*/ \
- sdflags_t flags; \
/* Input circular buffer.*/ \
uint8_t ib[SERIAL_BUFFERS_SIZE]; \
/* Output circular buffer.*/ \
diff --git a/os/hal/platforms/STM8S/serial_lld.c b/os/hal/platforms/STM8S/serial_lld.c
index a152e81d3..d5bdb96f0 100644
--- a/os/hal/platforms/STM8S/serial_lld.c
+++ b/os/hal/platforms/STM8S/serial_lld.c
@@ -72,7 +72,7 @@ static ROMCONST SerialConfig default_config = {
/*===========================================================================*/
static void set_error(SerialDriver *sdp, uint8_t sr) {
- sdflags_t sts = 0;
+ ioflags_t sts = 0;
/* Note, SR register bit definitions are equal for all UARTs so using
the UART1 definitions is fine.*/
@@ -85,7 +85,7 @@ static void set_error(SerialDriver *sdp, uint8_t sr) {
if (sr & UART1_SR_PE)
sts |= SD_PARITY_ERROR;
chSysLockFromIsr();
- sdAddFlagsI(sdp, sts);
+ chIOAddFlagsI(sdp, sts);
chSysUnlockFromIsr();
}
diff --git a/os/hal/platforms/STM8S/serial_lld.h b/os/hal/platforms/STM8S/serial_lld.h
index 29b44bfbc..96ac08896 100644
--- a/os/hal/platforms/STM8S/serial_lld.h
+++ b/os/hal/platforms/STM8S/serial_lld.h
@@ -88,11 +88,6 @@
/*===========================================================================*/
/**
- * @brief Serial Driver condition flags type.
- */
-typedef uint8_t sdflags_t;
-
-/**
* @brief Generic Serial Driver configuration structure.
* @details An instance of this structure must be passed to @p sdStart()
* in order to configure and start a serial driver operations.
@@ -122,10 +117,6 @@ typedef struct {
InputQueue iqueue; \
/* Output queue.*/ \
OutputQueue oqueue; \
- /* Status Change @p EventSource.*/ \
- EventSource sevent; \
- /* I/O driver status flags.*/ \
- sdflags_t flags; \
/* Input circular buffer.*/ \
uint8_t ib[SERIAL_BUFFERS_SIZE]; \
/* Output circular buffer.*/ \
diff --git a/os/hal/platforms/Win32/serial_lld.c b/os/hal/platforms/Win32/serial_lld.c
index 30e479055..bbfae160f 100644
--- a/os/hal/platforms/Win32/serial_lld.c
+++ b/os/hal/platforms/Win32/serial_lld.c
@@ -112,7 +112,7 @@ static bool_t connint(SerialDriver *sdp) {
printf("%s: Unable to setup non blocking mode on data socket\n", sdp->com_name);
goto abort;
}
- sdAddFlagsI(sdp, SD_CONNECTED);
+ chIOAddFlagsI(sdp, IO_CONNECTED);
return TRUE;
}
return FALSE;
@@ -139,7 +139,7 @@ static bool_t inint(SerialDriver *sdp) {
case 0:
closesocket(sdp->com_data);
sdp->com_data = INVALID_SOCKET;
- sdAddFlagsI(sdp, SD_DISCONNECTED);
+ chIOAddFlagsI(sdp, IO_DISCONNECTED);
return FALSE;
case SOCKET_ERROR:
if (WSAGetLastError() == WSAEWOULDBLOCK)
@@ -173,7 +173,7 @@ static bool_t outint(SerialDriver *sdp) {
case 0:
closesocket(sdp->com_data);
sdp->com_data = INVALID_SOCKET;
- sdAddFlagsI(sdp, SD_DISCONNECTED);
+ chIOAddFlagsI(sdp, IO_DISCONNECTED);
return FALSE;
case SOCKET_ERROR:
if (WSAGetLastError() == WSAEWOULDBLOCK)
diff --git a/os/hal/platforms/Win32/serial_lld.h b/os/hal/platforms/Win32/serial_lld.h
index 79a5994f2..5adf63998 100644
--- a/os/hal/platforms/Win32/serial_lld.h
+++ b/os/hal/platforms/Win32/serial_lld.h
@@ -110,10 +110,6 @@ typedef struct {
InputQueue iqueue; \
/* Output queue.*/ \
OutputQueue oqueue; \
- /* Status Change @p EventSource.*/ \
- EventSource sevent; \
- /* I/O driver status flags.*/ \
- sdflags_t flags; \
/* Input circular buffer.*/ \
uint8_t ib[SERIAL_BUFFERS_SIZE]; \
/* Output circular buffer.*/ \
diff --git a/os/hal/src/serial.c b/os/hal/src/serial.c
index c769061bb..aafedcc6b 100644
--- a/os/hal/src/serial.c
+++ b/os/hal/src/serial.c
@@ -89,8 +89,14 @@ 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 const struct SerialDriverVMT vmt = {
- writes, reads, putwouldblock, getwouldblock, putt, gett, writet, readt
+ writes, reads, putwouldblock, getwouldblock,
+ putt, gett, writet, readt,
+ getflags
};
/*===========================================================================*/
@@ -127,11 +133,9 @@ void sdInit(void) {
void sdObjectInit(SerialDriver *sdp, qnotify_t inotify, qnotify_t onotify) {
sdp->vmt = &vmt;
- chEvtInit(&sdp->ievent);
- chEvtInit(&sdp->oevent);
- chEvtInit(&sdp->sevent);
+ chEvtInit(&sdp->event);
+ sdp->flags = IO_NO_ERROR;
sdp->state = SD_STOP;
- sdp->flags = SD_NO_ERROR;
chIQInit(&sdp->iqueue, sdp->ib, SERIAL_BUFFERS_SIZE, inotify);
chOQInit(&sdp->oqueue, sdp->ob, SERIAL_BUFFERS_SIZE, onotify);
}
@@ -205,9 +209,9 @@ void sdIncomingDataI(SerialDriver *sdp, uint8_t b) {
chDbgCheck(sdp != NULL, "sdIncomingDataI");
if (chIQIsEmptyI(&sdp->iqueue))
- chEvtBroadcastI(&sdp->ievent);
+ chIOAddFlagsI(sdp, IO_INPUT_AVAILABLE);
if (chIQPutI(&sdp->iqueue, b) < Q_OK)
- sdAddFlagsI(sdp, SD_OVERRUN_ERROR);
+ chIOAddFlagsI(sdp, SD_OVERRUN_ERROR);
}
/**
@@ -232,49 +236,10 @@ msg_t sdRequestDataI(SerialDriver *sdp) {
b = chOQGetI(&sdp->oqueue);
if (b < Q_OK)
- chEvtBroadcastI(&sdp->oevent);
+ chIOAddFlagsI(sdp, IO_OUTPUT_EMPTY);
return b;
}
-/**
- * @brief Handles communication events/errors.
- * @details Must be called from the I/O interrupt service routine in order to
- * notify I/O conditions as errors, signals change etc.
- *
- * @param[in] sdp pointer to a @p SerialDriver structure
- * @param[in] mask condition flags to be added to the mask
- *
- * @iclass
- */
-void sdAddFlagsI(SerialDriver *sdp, sdflags_t mask) {
-
- chDbgCheck(sdp != NULL, "sdAddFlagsI");
-
- sdp->flags |= mask;
- chEvtBroadcastI(&sdp->sevent);
-}
-
-/**
- * @brief Returns and clears the errors mask associated to the driver.
- *
- * @param[in] sdp pointer to a @p SerialDriver structure
- * @return The condition flags modified since last time this
- * function was invoked.
- *
- * @api
- */
-sdflags_t sdGetAndClearFlags(SerialDriver *sdp) {
- sdflags_t mask;
-
- chDbgCheck(sdp != NULL, "sdGetAndClearFlags");
-
- chSysLock();
- mask = sdp->flags;
- sdp->flags = SD_NO_ERROR;
- chSysUnlock();
- return mask;
-}
-
#endif /* HAL_USE_SERIAL */
/** @} */
diff --git a/os/hal/templates/serial_lld.h b/os/hal/templates/serial_lld.h
index f33c2062b..252f15fe5 100644
--- a/os/hal/templates/serial_lld.h
+++ b/os/hal/templates/serial_lld.h
@@ -73,10 +73,6 @@ typedef struct {
InputQueue iqueue; \
/* Output queue.*/ \
OutputQueue oqueue; \
- /* Status Change @p EventSource.*/ \
- EventSource sevent; \
- /* I/O driver status flags.*/ \
- sdflags_t flags; \
/* Input circular buffer.*/ \
uint8_t ib[SERIAL_BUFFERS_SIZE]; \
/* Output circular buffer.*/ \
diff --git a/os/kernel/include/chioch.h b/os/kernel/include/chioch.h
index 3fff4b626..05a185a4d 100644
--- a/os/kernel/include/chioch.h
+++ b/os/kernel/include/chioch.h
@@ -228,21 +228,40 @@ typedef struct {
((ip)->vmt->readt(ip, bp, n, time))
#if CH_USE_EVENTS
+
+/** @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 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
+ _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 \
- /* Data Available EventSource.*/ \
- EventSource ievent; \
- /* Data Transmitted EventSource.*/ \
- EventSource oevent;
+ /* I/O condition event source.*/ \
+ EventSource event; \
+ /* I/O condition flags.*/ \
+ ioflags_t flags;
/**
* @brief @p BaseAsynchronousChannel virtual methods table.
@@ -265,10 +284,8 @@ typedef struct {
} BaseAsynchronousChannel;
/**
- * @brief Returns the write event source.
- * @details The write event source is broadcasted when the channel is ready
- * for write operations. This usually happens when the internal
- * output queue becomes empty.
+ * @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
@@ -276,21 +293,54 @@ typedef struct {
*
* @api
*/
-#define chIOGetWriteEventSource(ip) (&((ip)->vmt->oevent))
+#define chIOGetEventSource(ip) (&((ip)->event))
/**
- * @brief Returns the read event source.
- * @details The read event source is broadcasted when the channel is ready
- * for read operations. This usually happens when the internal
- * input queue becomes non-empty.
+ * @brief Adds condition flags to the channel's mask.
+ * @details This function is usually called from the I/O ISTs 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
- * @return A pointer to an @p EventSource object.
+ * @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 errors mask 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 chIOGetReadEventSource(ip) (&((ip)->vmt->ievent))
+#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 */