From: bernie Date: Fri, 17 Feb 2006 22:23:06 +0000 (+0000) Subject: Update POSIX serial emulator. X-Git-Tag: 1.0.0~721 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=cd8628e611877d99fc33609a2a3d4401b69222a4;p=bertos.git Update POSIX serial emulator. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@520 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/drv/ser.c b/drv/ser.c index 29719d4c..03c6db81 100755 --- a/drv/ser.c +++ b/drv/ser.c @@ -28,6 +28,9 @@ /*#* *#* $Log$ + *#* Revision 1.28 2006/02/17 22:23:06 bernie + *#* Update POSIX serial emulator. + *#* *#* Revision 1.27 2005/11/27 23:33:40 bernie *#* Use appconfig.h instead of cfg/config.h. *#* @@ -112,7 +115,7 @@ #include "ser_p.h" #include #include -#include +//#include #include /* diff --git a/drv/ser.h b/drv/ser.h index fd640b00..34498df7 100755 --- a/drv/ser.h +++ b/drv/ser.h @@ -14,6 +14,9 @@ /*#* *#* $Log$ + *#* Revision 1.24 2006/02/17 22:23:06 bernie + *#* Update POSIX serial emulator. + *#* *#* Revision 1.23 2005/11/27 23:33:40 bernie *#* Use appconfig.h instead of cfg/config.h. *#* @@ -87,6 +90,7 @@ #include #include #include /* BV() */ +#include /* ARCH_EMUL */ #include /*! \name Serial Error/status flags. */ @@ -123,7 +127,7 @@ #define SERRF_FRAMEERROR BV(9) /*!< Stop bit missing */ #define SERRF_NOISEERROR BV(10) /*!< Noise error */ #define SERRF_RXSROVERRUN BV(11) /*!< Rx shift register overrun */ -#elif defined(_EMUL) +#elif ARCH & ARCH_EMUL typedef uint16_t serstatus_t; /* Software errors */ @@ -131,13 +135,18 @@ #define SERRF_RXTIMEOUT BV(1) /*!< Receive timeout */ #define SERRF_TXTIMEOUT BV(2) /*!< Transmit timeout */ + /* Hardware errors */ + #define SERRF_RXSROVERRUN 0 /*!< Unsupported in emulated serial port. */ + #define SERRF_FRAMEERROR 0 /*!< Unsupported in emulated serial port. */ + #define SERRF_PARITYERROR 0 /*!< Unsupported in emulated serial port. */ + #define SERRF_NOISEERROR 0 /*!< Unsupported in emulated serial port. */ + #else #error unknown architecture #endif /*\}*/ -/*! \name Masks to group TX/RX errors. */ -/*\{*/ +/** Mask to group all RX errors. */ #define SERRF_RX \ ( SERRF_RXFIFOOVERRUN \ | SERRF_RXTIMEOUT \ @@ -145,8 +154,9 @@ | SERRF_PARITYERROR \ | SERRF_FRAMEERROR \ | SERRF_NOISEERROR) + +/** Mask to group all TX errors. */ #define SERRF_TX (SERRF_TXTIMEOUT) -/*\}*/ /*! @@ -181,11 +191,9 @@ enum SER_UART0, SER_PUNTALI, SER_BARCODE, -#elif defined(_EMUL) +#elif ARCH & ARCH_EMUL SER_UART0, - #if CONFIG_EMUL_UART1 - SER_UART1, - #endif + SER_UART1, #else #error unknown architecture #endif diff --git a/drv/ser_avr.c b/drv/ser_avr.c index 90d81fc4..5e0dc4d8 100755 --- a/drv/ser_avr.c +++ b/drv/ser_avr.c @@ -38,6 +38,9 @@ /*#* *#* $Log$ + *#* Revision 1.30 2006/02/17 22:23:06 bernie + *#* Update POSIX serial emulator. + *#* *#* Revision 1.29 2005/11/27 23:31:48 bernie *#* Support avr-libc 1.4. *#* @@ -664,7 +667,7 @@ static struct AvrSerial UARTDescs[SER_CNT] = } }; -struct SerialHardware* ser_hw_getdesc(int unit) +struct SerialHardware *ser_hw_getdesc(int unit) { ASSERT(unit < SER_CNT); return &UARTDescs[unit].hw; diff --git a/drv/ser_emul.c b/drv/ser_emul.c index a4b74101..9a6df21f 100755 --- a/drv/ser_emul.c +++ b/drv/ser_emul.c @@ -13,6 +13,9 @@ /*#* *#* $Log$ + *#* Revision 1.4 2006/02/17 22:23:06 bernie + *#* Update POSIX serial emulator. + *#* *#* Revision 1.3 2005/11/04 16:20:02 bernie *#* Fix reference to README.devlib in header. *#* @@ -26,11 +29,13 @@ #include "ser.h" #include "ser_p.h" -#include #include +#include #include +#include + #include #include #include /* open() */ @@ -43,10 +48,8 @@ extern struct Serial ser_handles[SER_CNT]; /* TX and RX buffers */ static unsigned char uart0_txbuffer[CONFIG_UART0_TXBUFSIZE]; static unsigned char uart0_rxbuffer[CONFIG_UART0_RXBUFSIZE]; -#if CONFIG_EMUL_UART1 - static unsigned char uart1_txbuffer[CONFIG_UART1_TXBUFSIZE]; - static unsigned char uart1_rxbuffer[CONFIG_UART1_RXBUFSIZE]; -#endif +static unsigned char uart1_txbuffer[CONFIG_UART1_TXBUFSIZE]; +static unsigned char uart1_rxbuffer[CONFIG_UART1_RXBUFSIZE]; /*! @@ -79,30 +82,36 @@ static void uart_cleanup(UNUSED_ARG(struct SerialHardware *, _hw)) hw->fd = -1; } -static void uart_enabletxirq(struct SerialHardware * _hw) +static void uart_txStart(struct SerialHardware * _hw) { struct EmulSerial *hw = (struct EmulSerial *)_hw; while(!fifo_isempty(&hw->ser->txfifo)) { - fputc(fifo_pop(&hw->ser->txfifo), hw->fd); + char c = fifo_pop(&hw->ser->txfifo); + write(hw->fd, &c, 1); } } -static void uart_setbaudrate(UNUSED_ARG(struct SerialHardware *, _hw), unsigned long rate) +static bool uart_txSending(UNUSED_ARG(struct SerialHardware *, _hw)) +{ + return false; +} + + +static void uart_setBaudrate(UNUSED_ARG(struct SerialHardware *, _hw), unsigned long rate) { TRACEMSG("rate=%lu", rate); // TODO } -static void uart_setparity(UNUSED_ARG(struct SerialHardware *, _hw), int parity) +static void uart_setParity(UNUSED_ARG(struct SerialHardware *, _hw), int parity) { TRACEMSG("parity=%d", parity); // TODO } - // FIXME: move into compiler.h? Ditch? #if COMPILER_C99 #define C99INIT(name,val) .name = val @@ -114,55 +123,45 @@ static void uart_setparity(UNUSED_ARG(struct SerialHardware *, _hw), int parity) #endif /* - * High-level interface data structures + * High-level interface data structures. */ -static const struct SerialHardwareVT UART0_VT = +static const struct SerialHardwareVT uart_vtable = { C99INIT(init, uart_init), C99INIT(cleanup, uart_cleanup), - C99INIT(setbaudrate, uart_setbaudrate), - C99INIT(setparity, uart_setparity), - C99INIT(enabletxirq, uart_enabletxirq), + C99INIT(setBaudrate, uart_setBaudrate), + C99INIT(setParity, uart_setParity), + C99INIT(txStart, uart_txStart), + C99INIT(txSending, uart_txSending), }; -#if CONFIG_EMUL_UART1 -static const struct SerialHardwareVT UART1_VT = -{ - C99INIT(init, uart_init), - C99INIT(cleanup, uart_cleanup), - C99INIT(setbaudrate, uart_setbaudrate), - C99INIT(setparity, uart_setparity), - C99INIT(enabletxirq, uart_enabletxirq), -}; -#endif // CONFIG_EMUL_UART1 - static struct EmulSerial UARTDescs[SER_CNT] = { { C99INIT(hw, /**/) { - C99INIT(table, &UART0_VT), + C99INIT(table, &uart_vtable), C99INIT(txbuffer, uart0_txbuffer), C99INIT(rxbuffer, uart0_rxbuffer), C99INIT(txbuffer_size, sizeof(uart0_txbuffer)), C99INIT(rxbuffer_size, sizeof(uart0_rxbuffer)), }, + C99INIT(ser, NULL), C99INIT(fd, -1), }, -#if CONFIG_EMUL_UART1 { C99INIT(hw, /**/) { - C99INIT(table, &UART1_VT), + C99INIT(table, &uart_vtable), C99INIT(txbuffer, uart1_txbuffer), C99INIT(rxbuffer, uart1_rxbuffer), C99INIT(txbuffer_size, sizeof(uart1_txbuffer)), C99INIT(rxbuffer_size, sizeof(uart1_rxbuffer)), }, + C99INIT(ser, NULL), C99INIT(fd, -1), }, -#endif }; -struct SerialHardware* ser_hw_getdesc(int unit) +struct SerialHardware *ser_hw_getdesc(int unit) { ASSERT(unit < SER_CNT); return &UARTDescs[unit].hw; diff --git a/drv/ser_p.h b/drv/ser_p.h index 25c6f7a5..ef58b261 100755 --- a/drv/ser_p.h +++ b/drv/ser_p.h @@ -15,6 +15,9 @@ /*#* *#* $Log$ + *#* Revision 1.9 2006/02/17 22:23:06 bernie + *#* Update POSIX serial emulator. + *#* *#* Revision 1.8 2005/11/04 16:20:02 bernie *#* Fix reference to README.devlib in header. *#* @@ -41,6 +44,8 @@ #ifndef DRV_SER_P_H #define DRV_SER_P_H +#include /* size_t */ + struct SerialHardware; struct Serial;