From bedb87c1e7cc9741c57c299d81d6e24c5e9c59c5 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 2 Jan 2010 13:35:55 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1495 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/platforms/Win32/serial_lld.c | 89 ++++++++++++++++++------------------- os/hal/platforms/Win32/serial_lld.h | 71 ++++++++++++++++------------- 2 files changed, 83 insertions(+), 77 deletions(-) (limited to 'os/hal/platforms/Win32') diff --git a/os/hal/platforms/Win32/serial_lld.c b/os/hal/platforms/Win32/serial_lld.c index 68decfc01..e29b994de 100644 --- a/os/hal/platforms/Win32/serial_lld.c +++ b/os/hal/platforms/Win32/serial_lld.c @@ -47,7 +47,7 @@ SerialDriver SD2; /*===========================================================================*/ /** @brief Driver default configuration.*/ -static const SerialDriverConfig default_config = { +static const SerialConfig default_config = { }; static u_long nb = 1; @@ -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->d2.com_name); + printf("%s: Error mapping protocol name to protocol number\n", sdp->sd.com_name); goto abort; } - sdp->d2.com_listen = socket(PF_INET, SOCK_STREAM, prtp->p_proto); - if (sdp->d2.com_listen == INVALID_SOCKET) { - printf("%s: Error creating simulator socket\n", sdp->d2.com_name); + 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); goto abort; } - if (ioctlsocket(sdp->d2.com_listen, FIONBIO, &nb) != 0) { - printf("%s: Unable to setup non blocking mode on socket\n", sdp->d2.com_name); + if (ioctlsocket(sdp->sd.com_listen, FIONBIO, &nb) != 0) { + printf("%s: Unable to setup non blocking mode on socket\n", sdp->sd.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->d2.com_listen, (struct sockaddr *)&sad, sizeof(sad))) { - printf("%s: Error binding socket\n", sdp->d2.com_name); + if (bind(sdp->sd.com_listen, (struct sockaddr *)&sad, sizeof(sad))) { + printf("%s: Error binding socket\n", sdp->sd.com_name); goto abort; } - if (listen(sdp->d2.com_listen, 1) != 0) { - printf("%s: Error listening socket\n", sdp->d2.com_name); + if (listen(sdp->sd.com_listen, 1) != 0) { + printf("%s: Error listening socket\n", sdp->sd.com_name); goto abort; } - printf("Full Duplex Channel %s listening on port %d\n", sdp->d2.com_name, port); + printf("Full Duplex Channel %s listening on port %d\n", sdp->sd.com_name, port); return; abort: - if (sdp->d2.com_listen != INVALID_SOCKET) - closesocket(sdp->d2.com_listen); + if (sdp->sd.com_listen != INVALID_SOCKET) + closesocket(sdp->sd.com_listen); WSACleanup(); exit(1); } static bool_t connint(SerialDriver *sdp) { - if (sdp->d2.com_data == INVALID_SOCKET) { + if (sdp->sd.com_data == INVALID_SOCKET) { struct sockaddr addr; int addrlen = sizeof(addr); - if ((sdp->d2.com_data = accept(sdp->d2.com_listen, &addr, &addrlen)) == INVALID_SOCKET) + if ((sdp->sd.com_data = accept(sdp->sd.com_listen, &addr, &addrlen)) == INVALID_SOCKET) return FALSE; - if (ioctlsocket(sdp->d2.com_data, FIONBIO, &nb) != 0) { - printf("%s: Unable to setup non blocking mode on data socket\n", sdp->d2.com_name); + 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); goto abort; } sdAddFlagsI(sdp, SD_CONNECTED); @@ -117,35 +117,35 @@ static bool_t connint(SerialDriver *sdp) { } return FALSE; abort: - if (sdp->d2.com_listen != INVALID_SOCKET) - closesocket(sdp->d2.com_listen); - if (sdp->d2.com_data != INVALID_SOCKET) - closesocket(sdp->d2.com_data); + if (sdp->sd.com_listen != INVALID_SOCKET) + closesocket(sdp->sd.com_listen); + if (sdp->sd.com_data != INVALID_SOCKET) + closesocket(sdp->sd.com_data); WSACleanup(); exit(1); } static bool_t inint(SerialDriver *sdp) { - if (sdp->d2.com_data != INVALID_SOCKET) { + if (sdp->sd.com_data != INVALID_SOCKET) { int i; uint8_t data[32]; /* * Input. */ - int n = recv(sdp->d2.com_data, data, sizeof(data), 0); + int n = recv(sdp->sd.com_data, data, sizeof(data), 0); switch (n) { case 0: - closesocket(sdp->d2.com_data); - sdp->d2.com_data = INVALID_SOCKET; + closesocket(sdp->sd.com_data); + sdp->sd.com_data = INVALID_SOCKET; sdAddFlagsI(sdp, SD_DISCONNECTED); return FALSE; case SOCKET_ERROR: if (WSAGetLastError() == WSAEWOULDBLOCK) return FALSE; - closesocket(sdp->d2.com_data); - sdp->d2.com_data = INVALID_SOCKET; + closesocket(sdp->sd.com_data); + sdp->sd.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->d2.com_data != INVALID_SOCKET) { + if (sdp->sd.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->d2.com_data, data, sizeof(data), 0); + n = send(sdp->sd.com_data, data, sizeof(data), 0); switch (n) { case 0: - closesocket(sdp->d2.com_data); - sdp->d2.com_data = INVALID_SOCKET; + closesocket(sdp->sd.com_data); + sdp->sd.com_data = INVALID_SOCKET; sdAddFlagsI(sdp, SD_DISCONNECTED); return FALSE; case SOCKET_ERROR: if (WSAGetLastError() == WSAEWOULDBLOCK) return FALSE; - closesocket(sdp->d2.com_data); - sdp->d2.com_data = INVALID_SOCKET; + closesocket(sdp->sd.com_data); + sdp->sd.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.d2.com_listen = INVALID_SOCKET; - SD1.d2.com_data = INVALID_SOCKET; - SD1.d2.com_name = "SD1"; + SD1.sd.com_listen = INVALID_SOCKET; + SD1.sd.com_data = INVALID_SOCKET; + SD1.sd.com_name = "SD1"; #endif #if USE_WIN32_SERIAL1 sdObjectInit(&SD2, NULL, NULL); - SD2.d2.com_listen = INVALID_SOCKET; - SD2.d2.com_data = INVALID_SOCKET; - SD2.d2.com_name = "SD2"; + SD2.sd.com_listen = INVALID_SOCKET; + SD2.sd.com_data = INVALID_SOCKET; + SD2.sd.com_name = "SD2"; #endif } @@ -219,14 +219,11 @@ void sd_lld_init(void) { * @brief Low level serial driver configuration and (re)start. * * @param[in] sdp pointer to a @p SerialDriver object - * @param[in] config the architecture-dependent serial driver configuration. - * If this parameter is set to @p NULL then a default - * configuration is used. */ -void sd_lld_start(SerialDriver *sdp, const SerialDriverConfig *config) { +void sd_lld_start(SerialDriver *sdp) { - if (config == NULL) - config = &default_config; + if (sdp->sd.config == NULL) + sdp->sd.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 4690fcb60..ed70a880a 100644 --- a/os/hal/platforms/Win32/serial_lld.h +++ b/os/hal/platforms/Win32/serial_lld.h @@ -87,63 +87,72 @@ */ typedef uint32_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. + * + * @note This structure content is architecture dependent, each driver + * implementation defines its own version and the custom static + * initializers. + */ +typedef struct { +} SerialConfig; + /** * @brief @p SerialDriver specific data. */ struct _serial_driver_data { /** - * Input queue, incoming data can be read from this input queue by - * using the queues APIs. + * @brief Driver state. + */ + sdstate_t state; + /** + * @brief Current configuration data. */ - InputQueue iqueue; + const SerialConfig *config; /** - * Output queue, outgoing data can be written to this output queue by - * using the queues APIs. + * @brief Input queue, incoming data can be read from this input queue by + * using the queues APIs. */ - OutputQueue oqueue; + InputQueue iqueue; /** - * Status Change @p EventSource. This event is generated when one or more - * condition flags change. + * @brief Output queue, outgoing data can be written to this output queue by + * using the queues APIs. */ - EventSource sevent; + OutputQueue oqueue; /** - * I/O driver status flags. + * @brief Status Change @p EventSource. This event is generated when one or + * more condition flags change. */ - sdflags_t flags; + EventSource sevent; /** - * Input circular buffer. + * @brief I/O driver status flags. */ - uint8_t ib[SERIAL_BUFFERS_SIZE]; + sdflags_t flags; /** - * Output circular buffer. + * @brief Input circular buffer. */ - uint8_t ob[SERIAL_BUFFERS_SIZE]; + 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; + SOCKET com_listen; /** * Data socket for simulated serial port. */ - SOCKET com_data; + SOCKET com_data; /** * Port readable name. */ - const char *com_name; + const char *com_name; }; -/** - * @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. - * - * @note This structure content is architecture dependent, each driver - * implementation defines its own version and the custom static - * initializers. - */ -typedef struct { -} SerialDriverConfig; - /*===========================================================================*/ /* External declarations. */ /*===========================================================================*/ @@ -160,7 +169,7 @@ extern SerialDriver SD2; extern "C" { #endif void sd_lld_init(void); - void sd_lld_start(SerialDriver *sdp, const SerialDriverConfig *config); + void sd_lld_start(SerialDriver *sdp); void sd_lld_stop(SerialDriver *sdp); bool_t sd_lld_interrupt_pending(void); #ifdef __cplusplus -- cgit v1.2.3