From f90a0f37906a9363a6e702d8ac1c4c8257370efa Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 16 Sep 2012 09:08:43 +0000 Subject: [PATCH] Removed flags handling in BaseAsynchronousChannel. Modified serial drivers to use the new event flags. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4671 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- demos/Posix-GCC/main.c | 12 +++--- demos/Win32-MinGW/main.c | 14 +++---- os/hal/include/io_channel.h | 52 +++----------------------- os/hal/platforms/AT91SAM7/serial_lld.c | 2 +- os/hal/platforms/AVR/serial_lld.c | 2 +- os/hal/platforms/LPC11Uxx/serial_lld.c | 2 +- os/hal/platforms/LPC11xx/serial_lld.c | 2 +- os/hal/platforms/LPC13xx/serial_lld.c | 2 +- os/hal/platforms/LPC214x/serial_lld.c | 2 +- os/hal/platforms/MSP430/serial_lld.c | 2 +- os/hal/platforms/SPC56x/serial_lld.c | 2 +- os/hal/platforms/STM32/serial_lld.c | 4 +- os/hal/platforms/STM8L/serial_lld.c | 2 +- os/hal/platforms/STM8S/serial_lld.c | 2 +- os/hal/src/serial.c | 8 +--- os/hal/src/serial_usb.c | 9 +---- readme.txt | 6 ++- 17 files changed, 38 insertions(+), 87 deletions(-) diff --git a/demos/Posix-GCC/main.c b/demos/Posix-GCC/main.c index afab51319..bcdc6636b 100644 --- a/demos/Posix-GCC/main.c +++ b/demos/Posix-GCC/main.c @@ -149,16 +149,18 @@ static void termination_handler(eventid_t id) { } } +static EventListener sd1fel, sd2fel; + /** * @brief SD1 status change handler. * * @param[in] id event id. */ static void sd1_handler(eventid_t id) { - chnflags_t flags; + flagsmask_t flags; (void)id; - flags = chnGetAndClearFlags(&SD1); + flags = chEvtGetAndClearFlags(&sd1fel); if ((flags & CHN_CONNECTED) && (shelltp1 == NULL)) { cputs("Init: connection on SD1"); shelltp1 = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO + 1); @@ -177,10 +179,10 @@ static void sd1_handler(eventid_t id) { * @param[in] id event id. */ static void sd2_handler(eventid_t id) { - chnflags_t flags; + flagsmask_t flags; (void)id; - flags = chnGetAndClearFlags(&SD2); + flags = chEvtGetAndClearFlags(&sd2fel); if ((flags & CHN_CONNECTED) && (shelltp2 == NULL)) { cputs("Init: connection on SD2"); shelltp2 = shellCreate(&shell_cfg2, SHELL_WA_SIZE, NORMALPRIO + 10); @@ -238,10 +240,8 @@ int main(void) { */ cputs("Shell service started on SD1, SD2"); cputs(" - Listening for connections on SD1"); - (void) chnGetAndClearFlags(&SD1); chEvtRegister(chnGetEventSource(&SD1), &sd1fel, 1); cputs(" - Listening for connections on SD2"); - (void) chnGetAndClearFlags(&SD2); chEvtRegister(chnGetEventSource(&SD2), &sd2fel, 2); /* diff --git a/demos/Win32-MinGW/main.c b/demos/Win32-MinGW/main.c index dc6e3685a..7514faebf 100644 --- a/demos/Win32-MinGW/main.c +++ b/demos/Win32-MinGW/main.c @@ -147,16 +147,18 @@ static void termination_handler(eventid_t id) { } } +static EventListener sd1fel, sd2fel; + /** * @brief SD1 status change handler. * * @param[in] id event id. */ static void sd1_handler(eventid_t id) { - chnflags_t flags; + flagsmask_t flags; (void)id; - flags = chnGetAndClearFlags(&SD1); + flags = chEvtGetAndClearFlags(&sd1fel); if ((flags & CHN_CONNECTED) && (shelltp1 == NULL)) { cputs("Init: connection on SD1"); shelltp1 = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO + 1); @@ -175,10 +177,10 @@ static void sd1_handler(eventid_t id) { * @param[in] id event id. */ static void sd2_handler(eventid_t id) { - chnflags_t flags; + flagsmask_t flags; (void)id; - flags = chnGetAndClearFlags(&SD2); + flags = chEvtGetAndClearFlags(&sd2fel); if ((flags & CHN_CONNECTED) && (shelltp2 == NULL)) { cputs("Init: connection on SD2"); shelltp2 = shellCreate(&shell_cfg2, SHELL_WA_SIZE, NORMALPRIO + 10); @@ -201,7 +203,7 @@ static evhandler_t fhandlers[] = { * Simulator main. * *------------------------------------------------------------------------*/ int main(void) { - EventListener sd1fel, sd2fel, tel; + EventListener tel; /* * System initializations. @@ -236,10 +238,8 @@ int main(void) { */ cputs("Shell service started on SD1, SD2"); cputs(" - Listening for connections on SD1"); - (void) chnGetAndClearFlags(&SD1); chEvtRegister(chnGetEventSource(&SD1), &sd1fel, 1); cputs(" - Listening for connections on SD2"); - (void) chnGetAndClearFlags(&SD2); chEvtRegister(chnGetEventSource(&SD2), &sd2fel, 2); /* diff --git a/os/hal/include/io_channel.h b/os/hal/include/io_channel.h index 726a2040a..02e3fb2be 100644 --- a/os/hal/include/io_channel.h +++ b/os/hal/include/io_channel.h @@ -200,7 +200,7 @@ typedef struct { #if CH_USE_EVENTS || defined(__DOXYGEN__) /** - * @name I/O status flags + * @name I/O status flags added to the event listener * @{ */ /** @brief No pending conditions.*/ @@ -217,18 +217,11 @@ typedef struct { #define CHN_TRANSMISSION_END 16 /** @} */ -/** - * @brief Type of an I/O condition flags mask. - */ -typedef uint_fast16_t chnflags_t; - /** * @brief @p BaseAsynchronousChannel specific methods. */ #define _base_asynchronous_channel_methods \ _base_channel_methods \ - /* Channel read method with timeout specification.*/ \ - chnflags_t (*getflags)(void *instance); /** * @brief @p BaseAsynchronousChannel specific data. @@ -236,9 +229,7 @@ typedef uint_fast16_t chnflags_t; #define _base_asynchronous_channel_data \ _base_channel_data \ /* I/O condition event source.*/ \ - EventSource event; \ - /* I/O condition flags.*/ \ - chnflags_t flags; + EventSource event; /** * @extends BaseChannelVMT @@ -279,53 +270,22 @@ typedef struct { #define chnGetEventSource(ip) (&((ip)->event)) /** - * @brief Adds status flags to the channel's mask. + * @brief Adds status flags to the listeners's flags 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 + * @param[in] flags condition flags to be added to the listener flags mask * * @iclass */ -#define chnAddFlagsI(ip, mask) { \ - (ip)->flags |= (mask); \ - chEvtBroadcastI(&(ip)->event); \ +#define chnAddFlagsI(ip, flags) { \ + chEvtBroadcastFlagsI(&(ip)->event, flags); \ } - -/** - * @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 chnGetAndClearFlags(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 _chn_get_and_clear_flags_impl(ip) \ - chnflags_t mask; \ - chSysLock(); \ - mask = ((BaseAsynchronousChannel *)(ip))->flags; \ - ((BaseAsynchronousChannel *)(ip))->flags = CHN_NO_ERROR; \ - chSysUnlock(); \ - return mask - #endif /* CH_USE_EVENTS */ #endif /* _IO_CHANNEL_H_ */ diff --git a/os/hal/platforms/AT91SAM7/serial_lld.c b/os/hal/platforms/AT91SAM7/serial_lld.c index 0e6aa1178..33917b38f 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) { - chnflags_t sts = 0; + flagsmask_t sts = 0; if (csr & AT91C_US_OVRE) sts |= SD_OVERRUN_ERROR; diff --git a/os/hal/platforms/AVR/serial_lld.c b/os/hal/platforms/AVR/serial_lld.c index c35cdca4b..ce7a928f0 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) { - chnflags_t sts = 0; + flagsmask_t sts = 0; uint8_t dor = 0; uint8_t upe = 0; uint8_t fe = 0; diff --git a/os/hal/platforms/LPC11Uxx/serial_lld.c b/os/hal/platforms/LPC11Uxx/serial_lld.c index 03bc9bbf9..d3faa7572 100644 --- a/os/hal/platforms/LPC11Uxx/serial_lld.c +++ b/os/hal/platforms/LPC11Uxx/serial_lld.c @@ -101,7 +101,7 @@ static void uart_deinit(LPC_USART_Type *u) { * @param[in] err UART LSR register value */ static void set_error(SerialDriver *sdp, IOREG32 err) { - chnflags_t sts = 0; + flagsmask_t sts = 0; if (err & LSR_OVERRUN) sts |= SD_OVERRUN_ERROR; diff --git a/os/hal/platforms/LPC11xx/serial_lld.c b/os/hal/platforms/LPC11xx/serial_lld.c index 10f7817b7..f0c5a9c1a 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) { - chnflags_t sts = 0; + flagsmask_t sts = 0; if (err & LSR_OVERRUN) sts |= SD_OVERRUN_ERROR; diff --git a/os/hal/platforms/LPC13xx/serial_lld.c b/os/hal/platforms/LPC13xx/serial_lld.c index f0c75d247..d5849cfd2 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) { - chnflags_t sts = 0; + flagsmask_t sts = 0; if (err & LSR_OVERRUN) sts |= SD_OVERRUN_ERROR; diff --git a/os/hal/platforms/LPC214x/serial_lld.c b/os/hal/platforms/LPC214x/serial_lld.c index ce207ff61..a25c9ebcc 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) { - chnflags_t sts = 0; + flagsmask_t sts = 0; if (err & LSR_OVERRUN) sts |= SD_OVERRUN_ERROR; diff --git a/os/hal/platforms/MSP430/serial_lld.c b/os/hal/platforms/MSP430/serial_lld.c index bdc3c580d..800243421 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) { - chnflags_t sts = 0; + flagsmask_t sts = 0; if (urctl & OE) sts |= SD_OVERRUN_ERROR; diff --git a/os/hal/platforms/SPC56x/serial_lld.c b/os/hal/platforms/SPC56x/serial_lld.c index 7effeeb60..e562b6c2d 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) { - chnflags_t sts = 0; + flagsmask_t sts = 0; if (sr & 0x08000000) sts |= SD_OVERRUN_ERROR; diff --git a/os/hal/platforms/STM32/serial_lld.c b/os/hal/platforms/STM32/serial_lld.c index eeabcae15..841b9b386 100644 --- a/os/hal/platforms/STM32/serial_lld.c +++ b/os/hal/platforms/STM32/serial_lld.c @@ -133,7 +133,7 @@ static void usart_deinit(USART_TypeDef *u) { * @param[in] isr USART ISR register value */ static void set_error(SerialDriver *sdp, uint16_t isr) { - chnflags_t sts = 0; + flagsmask_t sts = 0; if (isr & USART_ISR_ORE) sts |= SD_OVERRUN_ERROR; @@ -252,7 +252,7 @@ static void usart_deinit(USART_TypeDef *u) { * @param[in] sr USART SR register value */ static void set_error(SerialDriver *sdp, uint16_t sr) { - chnflags_t sts = 0; + flagsmask_t sts = 0; if (sr & USART_SR_ORE) sts |= SD_OVERRUN_ERROR; diff --git a/os/hal/platforms/STM8L/serial_lld.c b/os/hal/platforms/STM8L/serial_lld.c index b91f44a21..4392ee94c 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) { - chnflags_t sts = 0; + flagsmask_t sts = 0; if (sr & USART_SR_OR) sts |= SD_OVERRUN_ERROR; diff --git a/os/hal/platforms/STM8S/serial_lld.c b/os/hal/platforms/STM8S/serial_lld.c index 610591cdf..6904ac6ab 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) { - chnflags_t sts = 0; + flagsmask_t sts = 0; /* Note, SR register bit definitions are equal for all UARTs so using the UART1 definitions is fine.*/ diff --git a/os/hal/src/serial.c b/os/hal/src/serial.c index 2bf7f396b..999f4d6f9 100644 --- a/os/hal/src/serial.c +++ b/os/hal/src/serial.c @@ -94,14 +94,9 @@ static size_t readt(void *ip, uint8_t *bp, size_t n, systime_t time) { return chIQReadTimeout(&((SerialDriver *)ip)->iqueue, bp, n, time); } -static chnflags_t getflags(void *ip) { - _chn_get_and_clear_flags_impl(ip); -} - static const struct SerialDriverVMT vmt = { write, read, put, get, - putt, gett, writet, readt, - getflags + putt, gett, writet, readt }; /*===========================================================================*/ @@ -139,7 +134,6 @@ void sdObjectInit(SerialDriver *sdp, qnotify_t inotify, qnotify_t onotify) { sdp->vmt = &vmt; chEvtInit(&sdp->event); - sdp->flags = CHN_NO_ERROR; sdp->state = SD_STOP; chIQInit(&sdp->iqueue, sdp->ib, SERIAL_BUFFERS_SIZE, inotify, sdp); chOQInit(&sdp->oqueue, sdp->ob, SERIAL_BUFFERS_SIZE, onotify, sdp); diff --git a/os/hal/src/serial_usb.c b/os/hal/src/serial_usb.c index 9cef45524..05cb60c3f 100644 --- a/os/hal/src/serial_usb.c +++ b/os/hal/src/serial_usb.c @@ -103,14 +103,9 @@ static size_t readt(void *ip, uint8_t *bp, size_t n, systime_t time) { return chIQReadTimeout(&((SerialUSBDriver *)ip)->iqueue, bp, n, time); } -static chnflags_t getflags(void *ip) { - _chn_get_and_clear_flags_impl(ip); -} - static const struct SerialUSBDriverVMT vmt = { write, read, put, get, - putt, gett, writet, readt, - getflags + putt, gett, writet, readt }; /** @@ -197,7 +192,6 @@ void sduObjectInit(SerialUSBDriver *sdup) { sdup->vmt = &vmt; chEvtInit(&sdup->event); - sdup->flags = CHN_NO_ERROR; sdup->state = SDU_STOP; chIQInit(&sdup->iqueue, sdup->ib, SERIAL_USB_BUFFERS_SIZE, inotify, sdup); chOQInit(&sdup->oqueue, sdup->ob, SERIAL_USB_BUFFERS_SIZE, onotify, sdup); @@ -256,7 +250,6 @@ void sduStop(SerialUSBDriver *sdup) { void sduConfigureHookI(USBDriver *usbp) { SerialUSBDriver *sdup = usbp->param; - sdup->flags = CHN_NO_ERROR; chIQResetI(&sdup->iqueue); chOQResetI(&sdup->oqueue); chnAddFlagsI(sdup, CHN_CONNECTED); diff --git a/readme.txt b/readme.txt index f508a8e61..dbebc04b6 100644 --- a/readme.txt +++ b/readme.txt @@ -85,14 +85,18 @@ *** 2.5.1 *** - FIX: Fixed Data available event not generated in serial_usb driver (bug 3567992). +- NEW: Modified serial and serial_usb drivers to use the new event flags + mechanism, the previous flags handling in BaseAsynchronousChannel has + been removed. - NEW: Improved the kernel events subsystem, now event sources can associate source-specific flags to the listener, the flags can then be retrieved using the new APIs chEvtGetAndClearFlags() and chEvtGetAndClearFlagsI(). + Some old APIs have been renamed to increase consistency of the module. - NEW: Added VLE support to the Power Architecture GCC port. - NEW: Reorganized the Power Architecture GCC port along the lines of the ARMCMx port, now it can support multiple core types. - NEW: Updated the Power Architecture rules.mk file to put object and listing - files into a ./build directory like ARM ports alread do. + files into a ./build directory like ARM ports already do. *** 2.5.0 *** - FIX: Fixed anomaly in USB enumeration (bug 3565325)(backported to 2.4.3).