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
master
gdisirio 2012-09-16 09:08:43 +00:00
parent dfb876b3a1
commit f90a0f3790
17 changed files with 38 additions and 87 deletions

View File

@ -149,16 +149,18 @@ static void termination_handler(eventid_t id) {
} }
} }
static EventListener sd1fel, sd2fel;
/** /**
* @brief SD1 status change handler. * @brief SD1 status change handler.
* *
* @param[in] id event id. * @param[in] id event id.
*/ */
static void sd1_handler(eventid_t id) { static void sd1_handler(eventid_t id) {
chnflags_t flags; flagsmask_t flags;
(void)id; (void)id;
flags = chnGetAndClearFlags(&SD1); flags = chEvtGetAndClearFlags(&sd1fel);
if ((flags & CHN_CONNECTED) && (shelltp1 == NULL)) { if ((flags & CHN_CONNECTED) && (shelltp1 == NULL)) {
cputs("Init: connection on SD1"); cputs("Init: connection on SD1");
shelltp1 = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO + 1); 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. * @param[in] id event id.
*/ */
static void sd2_handler(eventid_t id) { static void sd2_handler(eventid_t id) {
chnflags_t flags; flagsmask_t flags;
(void)id; (void)id;
flags = chnGetAndClearFlags(&SD2); flags = chEvtGetAndClearFlags(&sd2fel);
if ((flags & CHN_CONNECTED) && (shelltp2 == NULL)) { if ((flags & CHN_CONNECTED) && (shelltp2 == NULL)) {
cputs("Init: connection on SD2"); cputs("Init: connection on SD2");
shelltp2 = shellCreate(&shell_cfg2, SHELL_WA_SIZE, NORMALPRIO + 10); shelltp2 = shellCreate(&shell_cfg2, SHELL_WA_SIZE, NORMALPRIO + 10);
@ -238,10 +240,8 @@ int main(void) {
*/ */
cputs("Shell service started on SD1, SD2"); cputs("Shell service started on SD1, SD2");
cputs(" - Listening for connections on SD1"); cputs(" - Listening for connections on SD1");
(void) chnGetAndClearFlags(&SD1);
chEvtRegister(chnGetEventSource(&SD1), &sd1fel, 1); chEvtRegister(chnGetEventSource(&SD1), &sd1fel, 1);
cputs(" - Listening for connections on SD2"); cputs(" - Listening for connections on SD2");
(void) chnGetAndClearFlags(&SD2);
chEvtRegister(chnGetEventSource(&SD2), &sd2fel, 2); chEvtRegister(chnGetEventSource(&SD2), &sd2fel, 2);
/* /*

View File

@ -147,16 +147,18 @@ static void termination_handler(eventid_t id) {
} }
} }
static EventListener sd1fel, sd2fel;
/** /**
* @brief SD1 status change handler. * @brief SD1 status change handler.
* *
* @param[in] id event id. * @param[in] id event id.
*/ */
static void sd1_handler(eventid_t id) { static void sd1_handler(eventid_t id) {
chnflags_t flags; flagsmask_t flags;
(void)id; (void)id;
flags = chnGetAndClearFlags(&SD1); flags = chEvtGetAndClearFlags(&sd1fel);
if ((flags & CHN_CONNECTED) && (shelltp1 == NULL)) { if ((flags & CHN_CONNECTED) && (shelltp1 == NULL)) {
cputs("Init: connection on SD1"); cputs("Init: connection on SD1");
shelltp1 = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO + 1); 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. * @param[in] id event id.
*/ */
static void sd2_handler(eventid_t id) { static void sd2_handler(eventid_t id) {
chnflags_t flags; flagsmask_t flags;
(void)id; (void)id;
flags = chnGetAndClearFlags(&SD2); flags = chEvtGetAndClearFlags(&sd2fel);
if ((flags & CHN_CONNECTED) && (shelltp2 == NULL)) { if ((flags & CHN_CONNECTED) && (shelltp2 == NULL)) {
cputs("Init: connection on SD2"); cputs("Init: connection on SD2");
shelltp2 = shellCreate(&shell_cfg2, SHELL_WA_SIZE, NORMALPRIO + 10); shelltp2 = shellCreate(&shell_cfg2, SHELL_WA_SIZE, NORMALPRIO + 10);
@ -201,7 +203,7 @@ static evhandler_t fhandlers[] = {
* Simulator main. * * Simulator main. *
*------------------------------------------------------------------------*/ *------------------------------------------------------------------------*/
int main(void) { int main(void) {
EventListener sd1fel, sd2fel, tel; EventListener tel;
/* /*
* System initializations. * System initializations.
@ -236,10 +238,8 @@ int main(void) {
*/ */
cputs("Shell service started on SD1, SD2"); cputs("Shell service started on SD1, SD2");
cputs(" - Listening for connections on SD1"); cputs(" - Listening for connections on SD1");
(void) chnGetAndClearFlags(&SD1);
chEvtRegister(chnGetEventSource(&SD1), &sd1fel, 1); chEvtRegister(chnGetEventSource(&SD1), &sd1fel, 1);
cputs(" - Listening for connections on SD2"); cputs(" - Listening for connections on SD2");
(void) chnGetAndClearFlags(&SD2);
chEvtRegister(chnGetEventSource(&SD2), &sd2fel, 2); chEvtRegister(chnGetEventSource(&SD2), &sd2fel, 2);
/* /*

View File

@ -200,7 +200,7 @@ typedef struct {
#if CH_USE_EVENTS || defined(__DOXYGEN__) #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.*/ /** @brief No pending conditions.*/
@ -217,18 +217,11 @@ typedef struct {
#define CHN_TRANSMISSION_END 16 #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. * @brief @p BaseAsynchronousChannel specific methods.
*/ */
#define _base_asynchronous_channel_methods \ #define _base_asynchronous_channel_methods \
_base_channel_methods \ _base_channel_methods \
/* Channel read method with timeout specification.*/ \
chnflags_t (*getflags)(void *instance);
/** /**
* @brief @p BaseAsynchronousChannel specific data. * @brief @p BaseAsynchronousChannel specific data.
@ -236,9 +229,7 @@ typedef uint_fast16_t chnflags_t;
#define _base_asynchronous_channel_data \ #define _base_asynchronous_channel_data \
_base_channel_data \ _base_channel_data \
/* I/O condition event source.*/ \ /* I/O condition event source.*/ \
EventSource event; \ EventSource event;
/* I/O condition flags.*/ \
chnflags_t flags;
/** /**
* @extends BaseChannelVMT * @extends BaseChannelVMT
@ -279,53 +270,22 @@ typedef struct {
#define chnGetEventSource(ip) (&((ip)->event)) #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 * @details This function is usually called from the I/O ISRs in order to
* notify I/O conditions such as data events, errors, signal * notify I/O conditions such as data events, errors, signal
* changes etc. * changes etc.
* *
* @param[in] ip pointer to a @p BaseAsynchronousChannel or derived * @param[in] ip pointer to a @p BaseAsynchronousChannel or derived
* class * 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 * @iclass
*/ */
#define chnAddFlagsI(ip, mask) { \ #define chnAddFlagsI(ip, flags) { \
(ip)->flags |= (mask); \ chEvtBroadcastFlagsI(&(ip)->event, flags); \
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 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 /* CH_USE_EVENTS */
#endif /* _IO_CHANNEL_H_ */ #endif /* _IO_CHANNEL_H_ */

View File

@ -139,7 +139,7 @@ static void usart_deinit(AT91PS_USART u) {
* @param[in] sdp communication channel associated to the USART * @param[in] sdp communication channel associated to the USART
*/ */
static void set_error(SerialDriver *sdp, AT91_REG csr) { static void set_error(SerialDriver *sdp, AT91_REG csr) {
chnflags_t sts = 0; flagsmask_t sts = 0;
if (csr & AT91C_US_OVRE) if (csr & AT91C_US_OVRE)
sts |= SD_OVERRUN_ERROR; sts |= SD_OVERRUN_ERROR;

View File

@ -70,7 +70,7 @@ static const SerialConfig default_config = {
/*===========================================================================*/ /*===========================================================================*/
static void set_error(uint8_t sra, SerialDriver *sdp) { static void set_error(uint8_t sra, SerialDriver *sdp) {
chnflags_t sts = 0; flagsmask_t sts = 0;
uint8_t dor = 0; uint8_t dor = 0;
uint8_t upe = 0; uint8_t upe = 0;
uint8_t fe = 0; uint8_t fe = 0;

View File

@ -101,7 +101,7 @@ static void uart_deinit(LPC_USART_Type *u) {
* @param[in] err UART LSR register value * @param[in] err UART LSR register value
*/ */
static void set_error(SerialDriver *sdp, IOREG32 err) { static void set_error(SerialDriver *sdp, IOREG32 err) {
chnflags_t sts = 0; flagsmask_t sts = 0;
if (err & LSR_OVERRUN) if (err & LSR_OVERRUN)
sts |= SD_OVERRUN_ERROR; sts |= SD_OVERRUN_ERROR;

View File

@ -101,7 +101,7 @@ static void uart_deinit(LPC_UART_TypeDef *u) {
* @param[in] err UART LSR register value * @param[in] err UART LSR register value
*/ */
static void set_error(SerialDriver *sdp, IOREG32 err) { static void set_error(SerialDriver *sdp, IOREG32 err) {
chnflags_t sts = 0; flagsmask_t sts = 0;
if (err & LSR_OVERRUN) if (err & LSR_OVERRUN)
sts |= SD_OVERRUN_ERROR; sts |= SD_OVERRUN_ERROR;

View File

@ -101,7 +101,7 @@ static void uart_deinit(LPC_UART_TypeDef *u) {
* @param[in] err UART LSR register value * @param[in] err UART LSR register value
*/ */
static void set_error(SerialDriver *sdp, IOREG32 err) { static void set_error(SerialDriver *sdp, IOREG32 err) {
chnflags_t sts = 0; flagsmask_t sts = 0;
if (err & LSR_OVERRUN) if (err & LSR_OVERRUN)
sts |= SD_OVERRUN_ERROR; sts |= SD_OVERRUN_ERROR;

View File

@ -106,7 +106,7 @@ static void uart_deinit(UART *u) {
* @param[in] err UART LSR register value * @param[in] err UART LSR register value
*/ */
static void set_error(SerialDriver *sdp, IOREG32 err) { static void set_error(SerialDriver *sdp, IOREG32 err) {
chnflags_t sts = 0; flagsmask_t sts = 0;
if (err & LSR_OVERRUN) if (err & LSR_OVERRUN)
sts |= SD_OVERRUN_ERROR; sts |= SD_OVERRUN_ERROR;

View File

@ -60,7 +60,7 @@ static const SerialConfig default_config = {
/*===========================================================================*/ /*===========================================================================*/
static void set_error(SerialDriver *sdp, uint8_t urctl) { static void set_error(SerialDriver *sdp, uint8_t urctl) {
chnflags_t sts = 0; flagsmask_t sts = 0;
if (urctl & OE) if (urctl & OE)
sts |= SD_OVERRUN_ERROR; sts |= SD_OVERRUN_ERROR;

View File

@ -117,7 +117,7 @@ static void esci_deinit(volatile struct ESCI_tag *escip) {
* @param[in] sr eSCI SR register value * @param[in] sr eSCI SR register value
*/ */
static void set_error(SerialDriver *sdp, uint32_t sr) { static void set_error(SerialDriver *sdp, uint32_t sr) {
chnflags_t sts = 0; flagsmask_t sts = 0;
if (sr & 0x08000000) if (sr & 0x08000000)
sts |= SD_OVERRUN_ERROR; sts |= SD_OVERRUN_ERROR;

View File

@ -133,7 +133,7 @@ static void usart_deinit(USART_TypeDef *u) {
* @param[in] isr USART ISR register value * @param[in] isr USART ISR register value
*/ */
static void set_error(SerialDriver *sdp, uint16_t isr) { static void set_error(SerialDriver *sdp, uint16_t isr) {
chnflags_t sts = 0; flagsmask_t sts = 0;
if (isr & USART_ISR_ORE) if (isr & USART_ISR_ORE)
sts |= SD_OVERRUN_ERROR; sts |= SD_OVERRUN_ERROR;
@ -252,7 +252,7 @@ static void usart_deinit(USART_TypeDef *u) {
* @param[in] sr USART SR register value * @param[in] sr USART SR register value
*/ */
static void set_error(SerialDriver *sdp, uint16_t sr) { static void set_error(SerialDriver *sdp, uint16_t sr) {
chnflags_t sts = 0; flagsmask_t sts = 0;
if (sr & USART_SR_ORE) if (sr & USART_SR_ORE)
sts |= SD_OVERRUN_ERROR; sts |= SD_OVERRUN_ERROR;

View File

@ -115,7 +115,7 @@ static void notify3(GenericQueue *qp) {
* @notapi * @notapi
*/ */
void sd_lld_set_error(SerialDriver *sdp, uint8_t sr) { void sd_lld_set_error(SerialDriver *sdp, uint8_t sr) {
chnflags_t sts = 0; flagsmask_t sts = 0;
if (sr & USART_SR_OR) if (sr & USART_SR_OR)
sts |= SD_OVERRUN_ERROR; sts |= SD_OVERRUN_ERROR;

View File

@ -73,7 +73,7 @@ static ROMCONST SerialConfig default_config = {
/*===========================================================================*/ /*===========================================================================*/
static void set_error(SerialDriver *sdp, uint8_t sr) { 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 /* Note, SR register bit definitions are equal for all UARTs so using
the UART1 definitions is fine.*/ the UART1 definitions is fine.*/

View File

@ -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); 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 = { static const struct SerialDriverVMT vmt = {
write, read, put, get, write, read, put, get,
putt, gett, writet, readt, putt, gett, writet, readt
getflags
}; };
/*===========================================================================*/ /*===========================================================================*/
@ -139,7 +134,6 @@ void sdObjectInit(SerialDriver *sdp, qnotify_t inotify, qnotify_t onotify) {
sdp->vmt = &vmt; sdp->vmt = &vmt;
chEvtInit(&sdp->event); chEvtInit(&sdp->event);
sdp->flags = CHN_NO_ERROR;
sdp->state = SD_STOP; sdp->state = SD_STOP;
chIQInit(&sdp->iqueue, sdp->ib, SERIAL_BUFFERS_SIZE, inotify, sdp); chIQInit(&sdp->iqueue, sdp->ib, SERIAL_BUFFERS_SIZE, inotify, sdp);
chOQInit(&sdp->oqueue, sdp->ob, SERIAL_BUFFERS_SIZE, onotify, sdp); chOQInit(&sdp->oqueue, sdp->ob, SERIAL_BUFFERS_SIZE, onotify, sdp);

View File

@ -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); 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 = { static const struct SerialUSBDriverVMT vmt = {
write, read, put, get, write, read, put, get,
putt, gett, writet, readt, putt, gett, writet, readt
getflags
}; };
/** /**
@ -197,7 +192,6 @@ void sduObjectInit(SerialUSBDriver *sdup) {
sdup->vmt = &vmt; sdup->vmt = &vmt;
chEvtInit(&sdup->event); chEvtInit(&sdup->event);
sdup->flags = CHN_NO_ERROR;
sdup->state = SDU_STOP; sdup->state = SDU_STOP;
chIQInit(&sdup->iqueue, sdup->ib, SERIAL_USB_BUFFERS_SIZE, inotify, sdup); chIQInit(&sdup->iqueue, sdup->ib, SERIAL_USB_BUFFERS_SIZE, inotify, sdup);
chOQInit(&sdup->oqueue, sdup->ob, SERIAL_USB_BUFFERS_SIZE, onotify, sdup); chOQInit(&sdup->oqueue, sdup->ob, SERIAL_USB_BUFFERS_SIZE, onotify, sdup);
@ -256,7 +250,6 @@ void sduStop(SerialUSBDriver *sdup) {
void sduConfigureHookI(USBDriver *usbp) { void sduConfigureHookI(USBDriver *usbp) {
SerialUSBDriver *sdup = usbp->param; SerialUSBDriver *sdup = usbp->param;
sdup->flags = CHN_NO_ERROR;
chIQResetI(&sdup->iqueue); chIQResetI(&sdup->iqueue);
chOQResetI(&sdup->oqueue); chOQResetI(&sdup->oqueue);
chnAddFlagsI(sdup, CHN_CONNECTED); chnAddFlagsI(sdup, CHN_CONNECTED);

View File

@ -85,14 +85,18 @@
*** 2.5.1 *** *** 2.5.1 ***
- FIX: Fixed Data available event not generated in serial_usb driver (bug - FIX: Fixed Data available event not generated in serial_usb driver (bug
3567992). 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 - NEW: Improved the kernel events subsystem, now event sources can associate
source-specific flags to the listener, the flags can then be retrieved source-specific flags to the listener, the flags can then be retrieved
using the new APIs chEvtGetAndClearFlags() and chEvtGetAndClearFlagsI(). 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: Added VLE support to the Power Architecture GCC port.
- NEW: Reorganized the Power Architecture GCC port along the lines of the - NEW: Reorganized the Power Architecture GCC port along the lines of the
ARMCMx port, now it can support multiple core types. ARMCMx port, now it can support multiple core types.
- NEW: Updated the Power Architecture rules.mk file to put object and listing - 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 *** *** 2.5.0 ***
- FIX: Fixed anomaly in USB enumeration (bug 3565325)(backported to 2.4.3). - FIX: Fixed anomaly in USB enumeration (bug 3565325)(backported to 2.4.3).