From 11215c3bcb0b0cbe5794cfc92d0c20de6c8696d9 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 22 Jan 2010 14:51:54 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1539 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/platforms/AT91SAM7/serial_lld.c | 30 ++++++------- os/hal/platforms/AT91SAM7/serial_lld.h | 63 +++++++++----------------- os/hal/platforms/AVR/serial_lld.c | 8 ++-- os/hal/platforms/AVR/serial_lld.h | 55 ++++++++--------------- os/hal/platforms/LPC214x/serial_lld.c | 42 ++++++++--------- os/hal/platforms/LPC214x/serial_lld.h | 63 +++++++++----------------- os/hal/platforms/Linux/serial_lld.c | 82 +++++++++++++++++----------------- os/hal/platforms/Linux/serial_lld.h | 75 +++++++++++-------------------- os/hal/platforms/MSP430/serial_lld.c | 8 ++-- os/hal/platforms/MSP430/serial_lld.h | 55 ++++++++--------------- os/hal/platforms/STM32/serial_lld.c | 36 +++++++-------- os/hal/platforms/STM32/serial_lld.h | 63 +++++++++----------------- os/hal/platforms/Win32/serial_lld.c | 82 +++++++++++++++++----------------- os/hal/platforms/Win32/serial_lld.h | 75 +++++++++++-------------------- 14 files changed, 293 insertions(+), 444 deletions(-) (limited to 'os/hal/platforms') diff --git a/os/hal/platforms/AT91SAM7/serial_lld.c b/os/hal/platforms/AT91SAM7/serial_lld.c index b781b2115..64acb809d 100644 --- a/os/hal/platforms/AT91SAM7/serial_lld.c +++ b/os/hal/platforms/AT91SAM7/serial_lld.c @@ -82,18 +82,18 @@ static const SerialConfig default_config = { * @param[in] sdp communication channel associated to the USART */ static void usart_init(SerialDriver *sdp) { - AT91PS_USART u = sdp->sd.usart; + AT91PS_USART u = sdp->usart; /* Disables IRQ sources and stop operations.*/ u->US_IDR = 0xFFFFFFFF; u->US_CR = AT91C_US_RSTRX | AT91C_US_RSTTX | AT91C_US_RSTSTA; /* New parameters setup.*/ - if (sdp->sd.config->sc_mr & AT91C_US_OVER) - u->US_BRGR = MCK / (sdp->sd.config->sc_speed * 8); + if (sdp->config->sc_mr & AT91C_US_OVER) + u->US_BRGR = MCK / (sdp->config->sc_speed * 8); else - u->US_BRGR = MCK / (sdp->sd.config->sc_speed * 16); - u->US_MR = sdp->sd.config->sc_mr; + u->US_BRGR = MCK / (sdp->config->sc_speed * 16); + u->US_MR = sdp->config->sc_mr; u->US_RTOR = 0; u->US_TTGR = 0; @@ -148,7 +148,7 @@ __attribute__((noinline)) */ static void serve_interrupt(SerialDriver *sdp) { uint32_t csr; - AT91PS_USART u = sdp->sd.usart; + AT91PS_USART u = sdp->usart; csr = u->US_CSR; if (csr & AT91C_US_RXRDY) { @@ -160,9 +160,9 @@ static void serve_interrupt(SerialDriver *sdp) { msg_t b; chSysLockFromIsr(); - b = chOQGetI(&sdp->sd.oqueue); + b = chOQGetI(&sdp->oqueue); if (b < Q_OK) { - chEvtBroadcastI(&sdp->bac.oevent); + chEvtBroadcastI(&sdp->oevent); u->US_IDR = AT91C_US_TXRDY; } else @@ -228,7 +228,7 @@ void sd_lld_init(void) { #if USE_SAM7_USART0 sdObjectInit(&SD1, NULL, notify1); - SD1.sd.usart = AT91C_BASE_US0; + SD1.usart = AT91C_BASE_US0; AT91C_BASE_PIOA->PIO_PDR = SAM7_USART0_RX | SAM7_USART0_TX; AT91C_BASE_PIOA->PIO_ASR = SAM7_USART0_RX | SAM7_USART0_TX; AT91C_BASE_PIOA->PIO_PPUDR = SAM7_USART0_RX | SAM7_USART0_TX; @@ -239,7 +239,7 @@ void sd_lld_init(void) { #if USE_SAM7_USART1 sdObjectInit(&SD2, NULL, notify2); - SD2.sd.usart = AT91C_BASE_US1; + SD2.usart = AT91C_BASE_US1; AT91C_BASE_PIOA->PIO_PDR = SAM7_USART1_RX | SAM7_USART1_TX; AT91C_BASE_PIOA->PIO_ASR = SAM7_USART1_RX | SAM7_USART1_TX; AT91C_BASE_PIOA->PIO_PPUDR = SAM7_USART1_RX | SAM7_USART1_TX; @@ -256,10 +256,10 @@ void sd_lld_init(void) { */ void sd_lld_start(SerialDriver *sdp) { - if (sdp->sd.config == NULL) - sdp->sd.config = &default_config; + if (sdp->config == NULL) + sdp->config = &default_config; - if (sdp->sd.state == SD_STOP) { + if (sdp->state == SD_STOP) { #if USE_SAM7_USART0 if (&SD1 == sdp) { /* Starts the clock and clears possible sources of immediate interrupts.*/ @@ -289,8 +289,8 @@ void sd_lld_start(SerialDriver *sdp) { */ void sd_lld_stop(SerialDriver *sdp) { - if (sdp->sd.state == SD_READY) { - usart_deinit(sdp->sd.usart); + if (sdp->state == SD_READY) { + usart_deinit(sdp->usart); #if USE_SAM7_USART0 if (&SD1 == sdp) { AT91C_BASE_PMC->PMC_PCDR = (1 << AT91C_ID_US0); diff --git a/os/hal/platforms/AT91SAM7/serial_lld.h b/os/hal/platforms/AT91SAM7/serial_lld.h index 3b7b009ab..a3030e246 100644 --- a/os/hal/platforms/AT91SAM7/serial_lld.h +++ b/os/hal/platforms/AT91SAM7/serial_lld.h @@ -101,48 +101,27 @@ typedef struct { /** * @brief @p SerialDriver specific data. */ -struct _serial_driver_data { - /** - * @brief Driver state. - */ - sdstate_t state; - /** - * @brief Current configuration data. - */ - const SerialConfig *config; - /** - * @brief Input queue, incoming data can be read from this input queue by - * using the queues APIs. - */ - InputQueue iqueue; - /** - * @brief Output queue, outgoing data can be written to this output queue by - * using the queues APIs. - */ - OutputQueue oqueue; - /** - * @brief Status Change @p EventSource. This event is generated when one or - * more condition flags change. - */ - EventSource sevent; - /** - * @brief I/O driver status flags. - */ - sdflags_t flags; - /** - * @brief Input circular buffer. - */ - uint8_t ib[SERIAL_BUFFERS_SIZE]; - /** - * @brief Output circular buffer. - */ - uint8_t ob[SERIAL_BUFFERS_SIZE]; - /* End of the mandatory fields.*/ - /** - * @brief Pointer to the USART registers block. - */ - AT91PS_USART usart; -}; +#define _serial_driver_data \ + _base_asynchronous_channel_data; \ + /* Driver state.*/ \ + sdstate_t state; \ + /* Current configuration data.*/ \ + const SerialConfig *config; \ + /* Input queue.*/ \ + 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.*/ \ + uint8_t ob[SERIAL_BUFFERS_SIZE]; \ + /* End of the mandatory fields.*/ \ + /* Pointer to the USART registers block.*/ \ + AT91PS_USART usart /*===========================================================================*/ /* Driver macros. */ diff --git a/os/hal/platforms/AVR/serial_lld.c b/os/hal/platforms/AVR/serial_lld.c index 53aec65d6..008b1176d 100644 --- a/os/hal/platforms/AVR/serial_lld.c +++ b/os/hal/platforms/AVR/serial_lld.c @@ -235,18 +235,18 @@ void sd_lld_init(void) { */ void sd_lld_start(SerialDriver *sdp) { - if (sdp->sd.config == NULL) - sdp->sd.config = &default_config; + if (sdp->config == NULL) + sdp->config = &default_config; #if USE_AVR_USART0 if (&SD1 == sdp) { - usart0_init(sdp->sd.config); + usart0_init(sdp->config); return; } #endif #if USE_AVR_USART1 if (&SD2 == sdp) { - usart1_init(sdp->sd.config); + usart1_init(sdp->config); return; } #endif diff --git a/os/hal/platforms/AVR/serial_lld.h b/os/hal/platforms/AVR/serial_lld.h index 1d06b6d79..4abadf018 100644 --- a/os/hal/platforms/AVR/serial_lld.h +++ b/os/hal/platforms/AVR/serial_lld.h @@ -87,44 +87,25 @@ typedef struct { /** * @brief @p SerialDriver specific data. */ -struct _serial_driver_data { - /** - * @brief Driver state. - */ - sdstate_t state; - /** - * @brief Current configuration data. - */ - const SerialConfig *config; - /** - * @brief Input queue, incoming data can be read from this input queue by - * using the queues APIs. - */ - InputQueue iqueue; - /** - * @brief Output queue, outgoing data can be written to this output queue by - * using the queues APIs. - */ - OutputQueue oqueue; - /** - * @brief Status Change @p EventSource. This event is generated when one or - * more condition flags change. - */ - EventSource sevent; - /** - * @brief I/O driver status flags. - */ - sdflags_t flags; - /** - * @brief Input circular buffer. - */ - uint8_t ib[SERIAL_BUFFERS_SIZE]; - /** - * @brief Output circular buffer. - */ - uint8_t ob[SERIAL_BUFFERS_SIZE]; +#define _serial_driver_data \ + _base_asynchronous_channel_data; \ + /* Driver state.*/ \ + sdstate_t state; \ + /* Current configuration data.*/ \ + const SerialConfig *config; \ + /* Input queue.*/ \ + 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.*/ \ + uint8_t ob[SERIAL_BUFFERS_SIZE]; \ /* End of the mandatory fields.*/ -}; /*===========================================================================*/ /* Driver macros. */ diff --git a/os/hal/platforms/LPC214x/serial_lld.c b/os/hal/platforms/LPC214x/serial_lld.c index 9c76d8e7f..b44e5eaf9 100644 --- a/os/hal/platforms/LPC214x/serial_lld.c +++ b/os/hal/platforms/LPC214x/serial_lld.c @@ -64,14 +64,14 @@ static const SerialConfig default_config = { * @param[in] sdp communication channel associated to the UART */ static void uart_init(SerialDriver *sdp) { - UART *u = sdp->sd.uart; + UART *u = sdp->uart; - uint32_t div = PCLK / (sdp->sd.config->sc_speed << 4); - u->UART_LCR = sdp->sd.config->sc_lcr | LCR_DLAB; + uint32_t div = PCLK / (sdp->config->sc_speed << 4); + u->UART_LCR = sdp->config->sc_lcr | LCR_DLAB; u->UART_DLL = div; u->UART_DLM = div >> 8; - u->UART_LCR = sdp->sd.config->sc_lcr; - u->UART_FCR = FCR_ENABLE | FCR_RXRESET | FCR_TXRESET | sdp->sd.config->sc_fcr; + u->UART_LCR = sdp->config->sc_lcr; + u->UART_FCR = FCR_ENABLE | FCR_RXRESET | FCR_TXRESET | sdp->config->sc_fcr; u->UART_ACR = 0; u->UART_FDR = 0x10; u->UART_TER = TER_ENABLE; @@ -128,7 +128,7 @@ __attribute__((noinline)) * go through the whole ISR and have another interrupt soon after. */ static void serve_interrupt(SerialDriver *sdp) { - UART *u = sdp->sd.uart; + UART *u = sdp->uart; while (TRUE) { switch (u->UART_IIR & IIR_SRC_MASK) { @@ -140,12 +140,12 @@ static void serve_interrupt(SerialDriver *sdp) { case IIR_SRC_TIMEOUT: case IIR_SRC_RX: chSysLockFromIsr(); - if (chIQIsEmpty(&sdp->sd.iqueue)) - chEvtBroadcastI(&sdp->bac.ievent); + if (chIQIsEmpty(&sdp->iqueue)) + chEvtBroadcastI(&sdp->ievent); chSysUnlockFromIsr(); while (u->UART_LSR & LSR_RBR_FULL) { chSysLockFromIsr(); - if (chIQPutI(&sdp->sd.iqueue, u->UART_RBR) < Q_OK) + if (chIQPutI(&sdp->iqueue, u->UART_RBR) < Q_OK) sdAddFlagsI(sdp, SD_OVERRUN_ERROR); chSysUnlockFromIsr(); } @@ -157,12 +157,12 @@ static void serve_interrupt(SerialDriver *sdp) { msg_t b; chSysLockFromIsr(); - b = chOQGetI(&sdp->sd.oqueue); + b = chOQGetI(&sdp->oqueue); chSysUnlockFromIsr(); if (b < Q_OK) { u->UART_IER &= ~IER_THRE; chSysLockFromIsr(); - chEvtBroadcastI(&sdp->bac.oevent); + chEvtBroadcastI(&sdp->oevent); chSysUnlockFromIsr(); break; } @@ -181,14 +181,14 @@ static void serve_interrupt(SerialDriver *sdp) { * @brief Attempts a TX FIFO preload. */ static void preload(SerialDriver *sdp) { - UART *u = sdp->sd.uart; + UART *u = sdp->uart; if (u->UART_LSR & LSR_THRE) { int i = LPC214x_UART_FIFO_PRELOAD; do { - msg_t b = chOQGetI(&sdp->sd.oqueue); + msg_t b = chOQGetI(&sdp->oqueue); if (b < Q_OK) { - chEvtBroadcastI(&sdp->bac.oevent); + chEvtBroadcastI(&sdp->oevent); return; } u->UART_THR = b; @@ -265,12 +265,12 @@ void sd_lld_init(void) { #if USE_LPC214x_UART0 sdObjectInit(&SD1, NULL, notify1); - SD1.sd.uart = U0Base; + SD1.uart = U0Base; SetVICVector(UART0IrqHandler, LPC214x_UART1_PRIORITY, SOURCE_UART0); #endif #if USE_LPC214x_UART1 sdObjectInit(&SD2, NULL, notify2); - SD2.sd.uart = U1Base; + SD2.uart = U1Base; SetVICVector(UART1IrqHandler, LPC214x_UART2_PRIORITY, SOURCE_UART1); #endif } @@ -282,10 +282,10 @@ void sd_lld_init(void) { */ void sd_lld_start(SerialDriver *sdp) { - if (sdp->sd.config == NULL) - sdp->sd.config = &default_config; + if (sdp->config == NULL) + sdp->config = &default_config; - if (sdp->sd.state == SD_STOP) { + if (sdp->state == SD_STOP) { #if USE_LPC214x_UART1 if (&SD1 == sdp) { PCONP = (PCONP & PCALL) | PCUART0; @@ -311,8 +311,8 @@ void sd_lld_start(SerialDriver *sdp) { */ void sd_lld_stop(SerialDriver *sdp) { - if (sdp->sd.state == SD_READY) { - uart_deinit(sdp->sd.uart); + if (sdp->state == SD_READY) { + uart_deinit(sdp->uart); #if USE_LPC214x_UART1 if (&SD1 == sdp) { PCONP = (PCONP & PCALL) & ~PCUART0; diff --git a/os/hal/platforms/LPC214x/serial_lld.h b/os/hal/platforms/LPC214x/serial_lld.h index 67e7e27d0..974a9849a 100644 --- a/os/hal/platforms/LPC214x/serial_lld.h +++ b/os/hal/platforms/LPC214x/serial_lld.h @@ -122,48 +122,27 @@ typedef struct { /** * @brief @p SerialDriver specific data. */ -struct _serial_driver_data { - /** - * @brief Driver state. - */ - sdstate_t state; - /** - * @brief Current configuration data. - */ - const SerialConfig *config; - /** - * @brief Input queue, incoming data can be read from this input queue by - * using the queues APIs. - */ - InputQueue iqueue; - /** - * @brief Output queue, outgoing data can be written to this output queue by - * using the queues APIs. - */ - OutputQueue oqueue; - /** - * @brief Status Change @p EventSource. This event is generated when one or - * more condition flags change. - */ - EventSource sevent; - /** - * @brief I/O driver status flags. - */ - sdflags_t flags; - /** - * @brief Input circular buffer. - */ - uint8_t ib[SERIAL_BUFFERS_SIZE]; - /** - * @brief Output circular buffer. - */ - uint8_t ob[SERIAL_BUFFERS_SIZE]; - /* End of the mandatory fields.*/ - /** - * @brief Pointer to the USART registers block. - */ - UART *uart; -}; +#define _serial_driver_data \ + _base_asynchronous_channel_data; \ + /* Driver state.*/ \ + sdstate_t state; \ + /* Current configuration data.*/ \ + const SerialConfig *config; \ + /* Input queue.*/ \ + 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.*/ \ + uint8_t ob[SERIAL_BUFFERS_SIZE]; \ + /* End of the mandatory fields.*/ \ + /* Pointer to the USART registers block.*/ \ + UART *uart /*===========================================================================*/ /* Driver macros. */ diff --git a/os/hal/platforms/Linux/serial_lld.c b/os/hal/platforms/Linux/serial_lld.c index a5cfe8a3d..c80c59d1b 100644 --- a/os/hal/platforms/Linux/serial_lld.c +++ b/os/hal/platforms/Linux/serial_lld.c @@ -68,18 +68,18 @@ static void init(SerialDriver *sdp, uint16_t port) { struct protoent *prtp; if ((prtp = getprotobyname("tcp")) == NULL) { - printf("%s: Error mapping protocol name to protocol number\n", sdp->sd.com_name); + printf("%s: Error mapping protocol name to protocol number\n", sdp->com_name); goto abort; } - sdp->sd.com_listen = socket(PF_INET, SOCK_STREAM, prtp->p_proto); - if (sdp->sd.com_listen == INVALID_SOCKET) { - printf("%s: Error creating simulator socket\n", sdp->sd.com_name); + sdp->com_listen = socket(PF_INET, SOCK_STREAM, prtp->p_proto); + if (sdp->com_listen == INVALID_SOCKET) { + printf("%s: Error creating simulator socket\n", sdp->com_name); goto abort; } - if (ioctl(sdp->sd.com_listen, FIONBIO, &nb) != 0) { - printf("%s: Unable to setup non blocking mode on socket\n", sdp->sd.com_name); + if (ioctl(sdp->com_listen, FIONBIO, &nb) != 0) { + printf("%s: Unable to setup non blocking mode on socket\n", sdp->com_name); goto abort; } @@ -87,35 +87,35 @@ static void init(SerialDriver *sdp, uint16_t port) { sad.sin_family = AF_INET; sad.sin_addr.s_addr = INADDR_ANY; sad.sin_port = htons(port); - if (bind(sdp->sd.com_listen, (struct sockaddr *)&sad, sizeof(sad))) { - printf("%s: Error binding socket\n", sdp->sd.com_name); + if (bind(sdp->com_listen, (struct sockaddr *)&sad, sizeof(sad))) { + printf("%s: Error binding socket\n", sdp->com_name); goto abort; } - if (listen(sdp->sd.com_listen, 1) != 0) { - printf("%s: Error listening socket\n", sdp->sd.com_name); + if (listen(sdp->com_listen, 1) != 0) { + printf("%s: Error listening socket\n", sdp->com_name); goto abort; } - printf("Full Duplex Channel %s listening on port %d\n", sdp->sd.com_name, port); + printf("Full Duplex Channel %s listening on port %d\n", sdp->com_name, port); return; abort: - if (sdp->sd.com_listen != INVALID_SOCKET) - close(sdp->sd.com_listen); + if (sdp->com_listen != INVALID_SOCKET) + close(sdp->com_listen); exit(1); } static bool_t connint(SerialDriver *sdp) { - if (sdp->sd.com_data == INVALID_SOCKET) { + if (sdp->com_data == INVALID_SOCKET) { struct sockaddr addr; socklen_t addrlen = sizeof(addr); - if ((sdp->sd.com_data = accept(sdp->sd.com_listen, &addr, &addrlen)) == INVALID_SOCKET) + if ((sdp->com_data = accept(sdp->com_listen, &addr, &addrlen)) == INVALID_SOCKET) return FALSE; - if (ioctl(sdp->sd.com_data, FIONBIO, &nb) != 0) { - printf("%s: Unable to setup non blocking mode on data socket\n", sdp->sd.com_name); + if (ioctl(sdp->com_data, FIONBIO, &nb) != 0) { + printf("%s: Unable to setup non blocking mode on data socket\n", sdp->com_name); goto abort; } sdAddFlagsI(sdp, SD_CONNECTED); @@ -123,34 +123,34 @@ static bool_t connint(SerialDriver *sdp) { } return FALSE; abort: - if (sdp->sd.com_listen != INVALID_SOCKET) - close(sdp->sd.com_listen); - if (sdp->sd.com_data != INVALID_SOCKET) - close(sdp->sd.com_data); + if (sdp->com_listen != INVALID_SOCKET) + close(sdp->com_listen); + if (sdp->com_data != INVALID_SOCKET) + close(sdp->com_data); exit(1); } static bool_t inint(SerialDriver *sdp) { - if (sdp->sd.com_data != INVALID_SOCKET) { + if (sdp->com_data != INVALID_SOCKET) { int i; uint8_t data[32]; /* * Input. */ - int n = recv(sdp->sd.com_data, data, sizeof(data), 0); + int n = recv(sdp->com_data, data, sizeof(data), 0); switch (n) { case 0: - close(sdp->sd.com_data); - sdp->sd.com_data = INVALID_SOCKET; + close(sdp->com_data); + sdp->com_data = INVALID_SOCKET; sdAddFlagsI(sdp, SD_DISCONNECTED); return FALSE; case INVALID_SOCKET: if (errno == EWOULDBLOCK) return FALSE; - close(sdp->sd.com_data); - sdp->sd.com_data = INVALID_SOCKET; + close(sdp->com_data); + sdp->com_data = INVALID_SOCKET; return FALSE; } for (i = 0; i < n; i++) @@ -162,7 +162,7 @@ static bool_t inint(SerialDriver *sdp) { static bool_t outint(SerialDriver *sdp) { - if (sdp->sd.com_data != INVALID_SOCKET) { + if (sdp->com_data != INVALID_SOCKET) { int n; uint8_t data[1]; @@ -173,18 +173,18 @@ static bool_t outint(SerialDriver *sdp) { if (n < 0) return FALSE; data[0] = (uint8_t)n; - n = send(sdp->sd.com_data, data, sizeof(data), 0); + n = send(sdp->com_data, data, sizeof(data), 0); switch (n) { case 0: - close(sdp->sd.com_data); - sdp->sd.com_data = INVALID_SOCKET; + close(sdp->com_data); + sdp->com_data = INVALID_SOCKET; sdAddFlagsI(sdp, SD_DISCONNECTED); return FALSE; case INVALID_SOCKET: if (errno == EWOULDBLOCK) return FALSE; - close(sdp->sd.com_data); - sdp->sd.com_data = INVALID_SOCKET; + close(sdp->com_data); + sdp->com_data = INVALID_SOCKET; return FALSE; } return TRUE; @@ -207,16 +207,16 @@ void sd_lld_init(void) { #if USE_SIM_SERIAL1 sdObjectInit(&SD1, NULL, NULL); - SD1.sd.com_listen = INVALID_SOCKET; - SD1.sd.com_data = INVALID_SOCKET; - SD1.sd.com_name = "SD1"; + SD1.com_listen = INVALID_SOCKET; + SD1.com_data = INVALID_SOCKET; + SD1.com_name = "SD1"; #endif #if USE_SIM_SERIAL2 sdObjectInit(&SD2, NULL, NULL); - SD2.sd.com_listen = INVALID_SOCKET; - SD2.sd.com_data = INVALID_SOCKET; - SD2.sd.com_name = "SD2"; + SD2.com_listen = INVALID_SOCKET; + SD2.com_data = INVALID_SOCKET; + SD2.com_name = "SD2"; #endif } @@ -227,8 +227,8 @@ void sd_lld_init(void) { */ void sd_lld_start(SerialDriver *sdp) { - if (sdp->sd.config == NULL) - sdp->sd.config = &default_config; + if (sdp->config == NULL) + sdp->config = &default_config; #if USE_SIM_SERIAL1 if (sdp == &SD1) diff --git a/os/hal/platforms/Linux/serial_lld.h b/os/hal/platforms/Linux/serial_lld.h index 5950472b4..1a246196f 100644 --- a/os/hal/platforms/Linux/serial_lld.h +++ b/os/hal/platforms/Linux/serial_lld.h @@ -106,56 +106,31 @@ typedef struct { /** * @brief @p SerialDriver specific data. */ -struct _serial_driver_data { - /** - * @brief Driver state. - */ - sdstate_t state; - /** - * @brief Current configuration data. - */ - const SerialConfig *config; - /** - * @brief Input queue, incoming data can be read from this input queue by - * using the queues APIs. - */ - InputQueue iqueue; - /** - * @brief Output queue, outgoing data can be written to this output queue by - * using the queues APIs. - */ - OutputQueue oqueue; - /** - * @brief Status Change @p EventSource. This event is generated when one or - * more condition flags change. - */ - EventSource sevent; - /** - * @brief I/O driver status flags. - */ - sdflags_t flags; - /** - * @brief Input circular buffer. - */ - uint8_t ib[SERIAL_BUFFERS_SIZE]; - /** - * @brief Output circular buffer. - */ - uint8_t ob[SERIAL_BUFFERS_SIZE]; - /* End of the mandatory fields.*/ - /** - * Listen socket for simulated serial port. - */ - SOCKET com_listen; - /** - * Data socket for simulated serial port. - */ - SOCKET com_data; - /** - * Port readable name. - */ - const char *com_name; -}; +#define _serial_driver_data \ + _base_asynchronous_channel_data; \ + /* Driver state.*/ \ + sdstate_t state; \ + /* Current configuration data.*/ \ + const SerialConfig *config; \ + /* Input queue.*/ \ + 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.*/ \ + uint8_t ob[SERIAL_BUFFERS_SIZE]; \ + /* End of the mandatory fields.*/ \ + /* Listen socket for simulated serial port.*/ \ + SOCKET com_listen; \ + /* Data socket for simulated serial port.*/ \ + SOCKET com_data; \ + /* Port readable name.*/ \ + const char *com_name /*===========================================================================*/ /* Driver macros. */ diff --git a/os/hal/platforms/MSP430/serial_lld.c b/os/hal/platforms/MSP430/serial_lld.c index acc8a8357..abb0086bf 100644 --- a/os/hal/platforms/MSP430/serial_lld.c +++ b/os/hal/platforms/MSP430/serial_lld.c @@ -260,18 +260,18 @@ void sd_lld_init(void) { */ void sd_lld_start(SerialDriver *sdp) { - if (sdp->sd.config == NULL) - sdp->sd.config = &default_config; + if (sdp->config == NULL) + sdp->config = &default_config; #if USE_MSP430_USART0 if (&SD1 == sdp) { - usart0_init(sdp->sd.config); + usart0_init(sdp->config); return; } #endif #if USE_MSP430_USART1 if (&SD2 == sdp) { - usart1_init(sdp->sd.config); + usart1_init(sdp->config); return; } #endif diff --git a/os/hal/platforms/MSP430/serial_lld.h b/os/hal/platforms/MSP430/serial_lld.h index 8b8f80d30..14542ce4a 100644 --- a/os/hal/platforms/MSP430/serial_lld.h +++ b/os/hal/platforms/MSP430/serial_lld.h @@ -91,44 +91,25 @@ typedef struct { /** * @brief @p SerialDriver specific data. */ -struct _serial_driver_data { - /** - * @brief Driver state. - */ - sdstate_t state; - /** - * @brief Current configuration data. - */ - const SerialConfig *config; - /** - * @brief Input queue, incoming data can be read from this input queue by - * using the queues APIs. - */ - InputQueue iqueue; - /** - * @brief Output queue, outgoing data can be written to this output queue by - * using the queues APIs. - */ - OutputQueue oqueue; - /** - * @brief Status Change @p EventSource. This event is generated when one or - * more condition flags change. - */ - EventSource sevent; - /** - * @brief I/O driver status flags. - */ - sdflags_t flags; - /** - * @brief Input circular buffer. - */ - uint8_t ib[SERIAL_BUFFERS_SIZE]; - /** - * @brief Output circular buffer. - */ - uint8_t ob[SERIAL_BUFFERS_SIZE]; +#define _serial_driver_data \ + _base_asynchronous_channel_data; \ + /* Driver state.*/ \ + sdstate_t state; \ + /* Current configuration data.*/ \ + const SerialConfig *config; \ + /* Input queue.*/ \ + 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.*/ \ + uint8_t ob[SERIAL_BUFFERS_SIZE]; \ /* End of the mandatory fields.*/ -}; /*===========================================================================*/ /* Driver macros. */ diff --git a/os/hal/platforms/STM32/serial_lld.c b/os/hal/platforms/STM32/serial_lld.c index 3c8fda8c0..8077aa3f3 100644 --- a/os/hal/platforms/STM32/serial_lld.c +++ b/os/hal/platforms/STM32/serial_lld.c @@ -72,24 +72,24 @@ static const SerialConfig default_config = * @param[in] sdp pointer to a @p SerialDriver object */ static void usart_init(SerialDriver *sdp) { - USART_TypeDef *u = sdp->sd.usart; + USART_TypeDef *u = sdp->usart; /* * Baud rate setting. */ - if (sdp->sd.usart == USART1) - u->BRR = APB2CLK / sdp->sd.config->sc_speed; + if (sdp->usart == USART1) + u->BRR = APB2CLK / sdp->config->sc_speed; else - u->BRR = APB1CLK / sdp->sd.config->sc_speed; + u->BRR = APB1CLK / sdp->config->sc_speed; /* * Note that some bits are enforced. */ - u->CR1 = sdp->sd.config->sc_cr1 | USART_CR1_UE | USART_CR1_PEIE | + u->CR1 = sdp->config->sc_cr1 | USART_CR1_UE | USART_CR1_PEIE | USART_CR1_RXNEIE | USART_CR1_TE | USART_CR1_RE; - u->CR2 = sdp->sd.config->sc_cr2 | USART_CR2_LBDIE; - u->CR3 = sdp->sd.config->sc_cr3 | USART_CR3_EIE; + u->CR2 = sdp->config->sc_cr2 | USART_CR2_LBDIE; + u->CR3 = sdp->config->sc_cr3 | USART_CR3_EIE; (void)u->SR; /* SR reset step 1.*/ (void)u->DR; /* SR reset step 2.*/ } @@ -137,7 +137,7 @@ static void set_error(SerialDriver *sdp, uint16_t sr) { * @param[in] sdp communication channel associated to the USART */ static void serve_interrupt(SerialDriver *sdp) { - USART_TypeDef *u = sdp->sd.usart; + USART_TypeDef *u = sdp->usart; uint16_t cr1 = u->CR1; uint16_t sr = u->SR; /* SR reset step 1.*/ uint16_t dr = u->DR; /* SR reset step 2.*/ @@ -155,9 +155,9 @@ static void serve_interrupt(SerialDriver *sdp) { if ((cr1 & USART_CR1_TXEIE) && (sr & USART_SR_TXE)) { msg_t b; chSysLockFromIsr(); - b = chOQGetI(&sdp->sd.oqueue); + b = chOQGetI(&sdp->oqueue); if (b < Q_OK) { - chEvtBroadcastI(&sdp->bac.oevent); + chEvtBroadcastI(&sdp->oevent); u->CR1 = cr1 & ~USART_CR1_TXEIE; } else @@ -235,17 +235,17 @@ void sd_lld_init(void) { #if USE_STM32_USART1 sdObjectInit(&SD1, NULL, notify1); - SD1.sd.usart = USART1; + SD1.usart = USART1; #endif #if USE_STM32_USART2 sdObjectInit(&SD2, NULL, notify2); - SD2.sd.usart = USART2; + SD2.usart = USART2; #endif #if USE_STM32_USART3 sdObjectInit(&SD3, NULL, notify3); - SD3.sd.usart = USART3; + SD3.usart = USART3; #endif } @@ -256,10 +256,10 @@ void sd_lld_init(void) { */ void sd_lld_start(SerialDriver *sdp) { - if (sdp->sd.config == NULL) - sdp->sd.config = &default_config; + if (sdp->config == NULL) + sdp->config = &default_config; - if (sdp->sd.state == SD_STOP) { + if (sdp->state == SD_STOP) { #if USE_STM32_USART1 if (&SD1 == sdp) { RCC->APB2ENR |= RCC_APB2ENR_USART1EN; @@ -291,8 +291,8 @@ void sd_lld_start(SerialDriver *sdp) { */ void sd_lld_stop(SerialDriver *sdp) { - if (sdp->sd.state == SD_READY) { - usart_deinit(sdp->sd.usart); + if (sdp->state == SD_READY) { + usart_deinit(sdp->usart); #if USE_STM32_USART1 if (&SD1 == sdp) { RCC->APB2ENR &= ~RCC_APB2ENR_USART1EN; diff --git a/os/hal/platforms/STM32/serial_lld.h b/os/hal/platforms/STM32/serial_lld.h index 97a56a332..e215dcef9 100644 --- a/os/hal/platforms/STM32/serial_lld.h +++ b/os/hal/platforms/STM32/serial_lld.h @@ -132,48 +132,27 @@ typedef struct { /** * @brief @p SerialDriver specific data. */ -struct _serial_driver_data { - /** - * @brief Driver state. - */ - sdstate_t state; - /** - * @brief Current configuration data. - */ - const SerialConfig *config; - /** - * @brief Input queue, incoming data can be read from this input queue by - * using the queues APIs. - */ - InputQueue iqueue; - /** - * @brief Output queue, outgoing data can be written to this output queue by - * using the queues APIs. - */ - OutputQueue oqueue; - /** - * @brief Status Change @p EventSource. This event is generated when one or - * more condition flags change. - */ - EventSource sevent; - /** - * @brief I/O driver status flags. - */ - sdflags_t flags; - /** - * @brief Input circular buffer. - */ - uint8_t ib[SERIAL_BUFFERS_SIZE]; - /** - * @brief Output circular buffer. - */ - uint8_t ob[SERIAL_BUFFERS_SIZE]; - /* End of the mandatory fields.*/ - /** - * @brief Pointer to the USART registers block. - */ - USART_TypeDef *usart; -}; +#define _serial_driver_data \ + _base_asynchronous_channel_data; \ + /* Driver state.*/ \ + sdstate_t state; \ + /* Current configuration data.*/ \ + const SerialConfig *config; \ + /* Input queue.*/ \ + 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.*/ \ + uint8_t ob[SERIAL_BUFFERS_SIZE]; \ + /* End of the mandatory fields.*/ \ + /* Pointer to the USART registers block.*/ \ + USART_TypeDef *usart /*===========================================================================*/ /* Driver macros. */ diff --git a/os/hal/platforms/Win32/serial_lld.c b/os/hal/platforms/Win32/serial_lld.c index e29b994de..b22dcbad3 100644 --- a/os/hal/platforms/Win32/serial_lld.c +++ b/os/hal/platforms/Win32/serial_lld.c @@ -61,18 +61,18 @@ static void init(SerialDriver *sdp, uint16_t port) { struct protoent *prtp; if ((prtp = getprotobyname("tcp")) == NULL) { - printf("%s: Error mapping protocol name to protocol number\n", sdp->sd.com_name); + printf("%s: Error mapping protocol name to protocol number\n", sdp->com_name); goto abort; } - sdp->sd.com_listen = socket(PF_INET, SOCK_STREAM, prtp->p_proto); - if (sdp->sd.com_listen == INVALID_SOCKET) { - printf("%s: Error creating simulator socket\n", sdp->sd.com_name); + sdp->com_listen = socket(PF_INET, SOCK_STREAM, prtp->p_proto); + if (sdp->com_listen == INVALID_SOCKET) { + printf("%s: Error creating simulator socket\n", sdp->com_name); goto abort; } - if (ioctlsocket(sdp->sd.com_listen, FIONBIO, &nb) != 0) { - printf("%s: Unable to setup non blocking mode on socket\n", sdp->sd.com_name); + if (ioctlsocket(sdp->com_listen, FIONBIO, &nb) != 0) { + printf("%s: Unable to setup non blocking mode on socket\n", sdp->com_name); goto abort; } @@ -80,36 +80,36 @@ static void init(SerialDriver *sdp, uint16_t port) { sad.sin_family = AF_INET; sad.sin_addr.s_addr = INADDR_ANY; sad.sin_port = htons(port); - if (bind(sdp->sd.com_listen, (struct sockaddr *)&sad, sizeof(sad))) { - printf("%s: Error binding socket\n", sdp->sd.com_name); + if (bind(sdp->com_listen, (struct sockaddr *)&sad, sizeof(sad))) { + printf("%s: Error binding socket\n", sdp->com_name); goto abort; } - if (listen(sdp->sd.com_listen, 1) != 0) { - printf("%s: Error listening socket\n", sdp->sd.com_name); + if (listen(sdp->com_listen, 1) != 0) { + printf("%s: Error listening socket\n", sdp->com_name); goto abort; } - printf("Full Duplex Channel %s listening on port %d\n", sdp->sd.com_name, port); + printf("Full Duplex Channel %s listening on port %d\n", sdp->com_name, port); return; abort: - if (sdp->sd.com_listen != INVALID_SOCKET) - closesocket(sdp->sd.com_listen); + if (sdp->com_listen != INVALID_SOCKET) + closesocket(sdp->com_listen); WSACleanup(); exit(1); } static bool_t connint(SerialDriver *sdp) { - if (sdp->sd.com_data == INVALID_SOCKET) { + if (sdp->com_data == INVALID_SOCKET) { struct sockaddr addr; int addrlen = sizeof(addr); - if ((sdp->sd.com_data = accept(sdp->sd.com_listen, &addr, &addrlen)) == INVALID_SOCKET) + if ((sdp->com_data = accept(sdp->com_listen, &addr, &addrlen)) == INVALID_SOCKET) return FALSE; - if (ioctlsocket(sdp->sd.com_data, FIONBIO, &nb) != 0) { - printf("%s: Unable to setup non blocking mode on data socket\n", sdp->sd.com_name); + if (ioctlsocket(sdp->com_data, FIONBIO, &nb) != 0) { + printf("%s: Unable to setup non blocking mode on data socket\n", sdp->com_name); goto abort; } sdAddFlagsI(sdp, SD_CONNECTED); @@ -117,35 +117,35 @@ static bool_t connint(SerialDriver *sdp) { } return FALSE; abort: - if (sdp->sd.com_listen != INVALID_SOCKET) - closesocket(sdp->sd.com_listen); - if (sdp->sd.com_data != INVALID_SOCKET) - closesocket(sdp->sd.com_data); + if (sdp->com_listen != INVALID_SOCKET) + closesocket(sdp->com_listen); + if (sdp->com_data != INVALID_SOCKET) + closesocket(sdp->com_data); WSACleanup(); exit(1); } static bool_t inint(SerialDriver *sdp) { - if (sdp->sd.com_data != INVALID_SOCKET) { + if (sdp->com_data != INVALID_SOCKET) { int i; uint8_t data[32]; /* * Input. */ - int n = recv(sdp->sd.com_data, data, sizeof(data), 0); + int n = recv(sdp->com_data, data, sizeof(data), 0); switch (n) { case 0: - closesocket(sdp->sd.com_data); - sdp->sd.com_data = INVALID_SOCKET; + closesocket(sdp->com_data); + sdp->com_data = INVALID_SOCKET; sdAddFlagsI(sdp, SD_DISCONNECTED); return FALSE; case SOCKET_ERROR: if (WSAGetLastError() == WSAEWOULDBLOCK) return FALSE; - closesocket(sdp->sd.com_data); - sdp->sd.com_data = INVALID_SOCKET; + closesocket(sdp->com_data); + sdp->com_data = INVALID_SOCKET; return FALSE; } for (i = 0; i < n; i++) @@ -157,7 +157,7 @@ static bool_t inint(SerialDriver *sdp) { static bool_t outint(SerialDriver *sdp) { - if (sdp->sd.com_data != INVALID_SOCKET) { + if (sdp->com_data != INVALID_SOCKET) { int n; uint8_t data[1]; @@ -168,18 +168,18 @@ static bool_t outint(SerialDriver *sdp) { if (n < 0) return FALSE; data[0] = (uint8_t)n; - n = send(sdp->sd.com_data, data, sizeof(data), 0); + n = send(sdp->com_data, data, sizeof(data), 0); switch (n) { case 0: - closesocket(sdp->sd.com_data); - sdp->sd.com_data = INVALID_SOCKET; + closesocket(sdp->com_data); + sdp->com_data = INVALID_SOCKET; sdAddFlagsI(sdp, SD_DISCONNECTED); return FALSE; case SOCKET_ERROR: if (WSAGetLastError() == WSAEWOULDBLOCK) return FALSE; - closesocket(sdp->sd.com_data); - sdp->sd.com_data = INVALID_SOCKET; + closesocket(sdp->com_data); + sdp->com_data = INVALID_SOCKET; return FALSE; } return TRUE; @@ -202,16 +202,16 @@ void sd_lld_init(void) { #if USE_WIN32_SERIAL1 sdObjectInit(&SD1, NULL, NULL); - SD1.sd.com_listen = INVALID_SOCKET; - SD1.sd.com_data = INVALID_SOCKET; - SD1.sd.com_name = "SD1"; + SD1.com_listen = INVALID_SOCKET; + SD1.com_data = INVALID_SOCKET; + SD1.com_name = "SD1"; #endif #if USE_WIN32_SERIAL1 sdObjectInit(&SD2, NULL, NULL); - SD2.sd.com_listen = INVALID_SOCKET; - SD2.sd.com_data = INVALID_SOCKET; - SD2.sd.com_name = "SD2"; + SD2.com_listen = INVALID_SOCKET; + SD2.com_data = INVALID_SOCKET; + SD2.com_name = "SD2"; #endif } @@ -222,8 +222,8 @@ void sd_lld_init(void) { */ void sd_lld_start(SerialDriver *sdp) { - if (sdp->sd.config == NULL) - sdp->sd.config = &default_config; + if (sdp->config == NULL) + sdp->config = &default_config; #if USE_WIN32_SERIAL1 if (sdp == &SD1) diff --git a/os/hal/platforms/Win32/serial_lld.h b/os/hal/platforms/Win32/serial_lld.h index ed70a880a..936ff2a7a 100644 --- a/os/hal/platforms/Win32/serial_lld.h +++ b/os/hal/platforms/Win32/serial_lld.h @@ -102,56 +102,31 @@ typedef struct { /** * @brief @p SerialDriver specific data. */ -struct _serial_driver_data { - /** - * @brief Driver state. - */ - sdstate_t state; - /** - * @brief Current configuration data. - */ - const SerialConfig *config; - /** - * @brief Input queue, incoming data can be read from this input queue by - * using the queues APIs. - */ - InputQueue iqueue; - /** - * @brief Output queue, outgoing data can be written to this output queue by - * using the queues APIs. - */ - OutputQueue oqueue; - /** - * @brief Status Change @p EventSource. This event is generated when one or - * more condition flags change. - */ - EventSource sevent; - /** - * @brief I/O driver status flags. - */ - sdflags_t flags; - /** - * @brief Input circular buffer. - */ - uint8_t ib[SERIAL_BUFFERS_SIZE]; - /** - * @brief Output circular buffer. - */ - uint8_t ob[SERIAL_BUFFERS_SIZE]; - /* End of the mandatory fields.*/ - /** - * Listen socket for simulated serial port. - */ - SOCKET com_listen; - /** - * Data socket for simulated serial port. - */ - SOCKET com_data; - /** - * Port readable name. - */ - const char *com_name; -}; +#define _serial_driver_data \ + _base_asynchronous_channel_data; \ + /* Driver state.*/ \ + sdstate_t state; \ + /* Current configuration data.*/ \ + const SerialConfig *config; \ + /* Input queue.*/ \ + 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.*/ \ + uint8_t ob[SERIAL_BUFFERS_SIZE]; \ + /* End of the mandatory fields.*/ \ + /* Listen socket for simulated serial port.*/ \ + SOCKET com_listen; \ + /* Data socket for simulated serial port.*/ \ + SOCKET com_data; \ + /* Port readable name.*/ \ + const char *com_name /*===========================================================================*/ /* External declarations. */ -- cgit v1.2.3