diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2010-01-02 18:52:30 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2010-01-02 18:52:30 +0000 |
commit | edfe4ce4411e0b4f8f78db5c19bc6d553ac82a4f (patch) | |
tree | f3e027681bae2a939e53b06962cc583e8e909e39 | |
parent | 6cb3190f38d34fd4d159c16e2c927f5aeb65c210 (diff) | |
download | ChibiOS-edfe4ce4411e0b4f8f78db5c19bc6d553ac82a4f.tar.gz ChibiOS-edfe4ce4411e0b4f8f78db5c19bc6d553ac82a4f.tar.bz2 ChibiOS-edfe4ce4411e0b4f8f78db5c19bc6d553ac82a4f.zip |
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1497 35acf78f-673a-0410-8e92-d51de3d6d3f4
-rw-r--r-- | demos/GNU-Linux-GCC/halconf.h | 2 | ||||
-rw-r--r-- | os/hal/platforms/Linux/serial_lld.c | 89 | ||||
-rw-r--r-- | os/hal/platforms/Linux/serial_lld.h | 73 |
3 files changed, 85 insertions, 79 deletions
diff --git a/demos/GNU-Linux-GCC/halconf.h b/demos/GNU-Linux-GCC/halconf.h index 58d49966f..f80ceafb0 100644 --- a/demos/GNU-Linux-GCC/halconf.h +++ b/demos/GNU-Linux-GCC/halconf.h @@ -38,7 +38,7 @@ * settings file. This file can be used to include platform specific
* header files or to override the low level drivers settings. */
-#include "mcuconf.h"
+/*#include "mcuconf.h"*/
/*===========================================================================*/
/* PAL driver related settings. */
diff --git a/os/hal/platforms/Linux/serial_lld.c b/os/hal/platforms/Linux/serial_lld.c index b94e95039..a5cfe8a3d 100644 --- a/os/hal/platforms/Linux/serial_lld.c +++ b/os/hal/platforms/Linux/serial_lld.c @@ -54,7 +54,7 @@ SerialDriver SD2; /*===========================================================================*/
/** @brief Driver default configuration.*/
-static const SerialDriverConfig default_config = {
+static const SerialConfig default_config = {
};
static u_long nb = 1;
@@ -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->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 (ioctl(sdp->d2.com_listen, FIONBIO, &nb) != 0) {
- printf("%s: Unable to setup non blocking mode on socket\n", sdp->d2.com_name);
+ if (ioctl(sdp->sd.com_listen, FIONBIO, &nb) != 0) {
+ printf("%s: Unable to setup non blocking mode on socket\n", sdp->sd.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->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)
- close(sdp->d2.com_listen);
+ if (sdp->sd.com_listen != INVALID_SOCKET)
+ close(sdp->sd.com_listen);
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;
socklen_t 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 (ioctl(sdp->d2.com_data, FIONBIO, &nb) != 0) {
- printf("%s: Unable to setup non blocking mode on data socket\n", sdp->d2.com_name);
+ 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);
goto abort;
}
sdAddFlagsI(sdp, SD_CONNECTED);
@@ -123,34 +123,34 @@ static bool_t connint(SerialDriver *sdp) { }
return FALSE;
abort:
- if (sdp->d2.com_listen != INVALID_SOCKET)
- close(sdp->d2.com_listen);
- if (sdp->d2.com_data != INVALID_SOCKET)
- close(sdp->d2.com_data);
+ if (sdp->sd.com_listen != INVALID_SOCKET)
+ close(sdp->sd.com_listen);
+ if (sdp->sd.com_data != INVALID_SOCKET)
+ close(sdp->sd.com_data);
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:
- close(sdp->d2.com_data);
- sdp->d2.com_data = INVALID_SOCKET;
+ close(sdp->sd.com_data);
+ sdp->sd.com_data = INVALID_SOCKET;
sdAddFlagsI(sdp, SD_DISCONNECTED);
return FALSE;
case INVALID_SOCKET:
if (errno == EWOULDBLOCK)
return FALSE;
- close(sdp->d2.com_data);
- sdp->d2.com_data = INVALID_SOCKET;
+ close(sdp->sd.com_data);
+ sdp->sd.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->d2.com_data != INVALID_SOCKET) {
+ if (sdp->sd.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->d2.com_data, data, sizeof(data), 0);
+ n = send(sdp->sd.com_data, data, sizeof(data), 0);
switch (n) {
case 0:
- close(sdp->d2.com_data);
- sdp->d2.com_data = INVALID_SOCKET;
+ close(sdp->sd.com_data);
+ sdp->sd.com_data = INVALID_SOCKET;
sdAddFlagsI(sdp, SD_DISCONNECTED);
return FALSE;
case INVALID_SOCKET:
if (errno == EWOULDBLOCK)
return FALSE;
- close(sdp->d2.com_data);
- sdp->d2.com_data = INVALID_SOCKET;
+ close(sdp->sd.com_data);
+ sdp->sd.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.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_SIM_SERIAL2
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
}
@@ -224,14 +224,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_SIM_SERIAL1
if (sdp == &SD1)
diff --git a/os/hal/platforms/Linux/serial_lld.h b/os/hal/platforms/Linux/serial_lld.h index a825ecc81..5950472b4 100644 --- a/os/hal/platforms/Linux/serial_lld.h +++ b/os/hal/platforms/Linux/serial_lld.h @@ -92,62 +92,71 @@ 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];
/**
- * Listen socket for simulated serial port. + * @brief Output circular buffer.
*/
- SOCKET com_listen;
+ 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;
+ 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;
-
/*===========================================================================*/
/* Driver macros. */
/*===========================================================================*/
@@ -168,7 +177,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
|