/*#*
*#* $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.
*#*
#include <mware/fifobuf.h>
#include <cfg/compiler.h>
#include <cfg/macros.h> /* BV() */
+#include <cfg/arch_config.h> /* ARCH_EMUL */
#include <appconfig.h>
/*! \name Serial Error/status flags. */
#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 */
#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 \
| SERRF_PARITYERROR \
| SERRF_FRAMEERROR \
| SERRF_NOISEERROR)
+
+/** Mask to group all TX errors. */
#define SERRF_TX (SERRF_TXTIMEOUT)
-/*\}*/
/*!
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
/*#*
*#* $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.
*#*
#include "ser.h"
#include "ser_p.h"
-#include <cfg/config.h>
#include <cfg/debug.h>
+#include <cfg/compiler.h>
#include <mware/fifobuf.h>
+#include <appconfig.h>
+
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h> /* open() */
/* 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];
/*!
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
#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;