X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=drv%2Fser.h;h=c0f7b8bb036007d9b441129bedbb713c30b04b9d;hb=2535cb94ec2183791128f8bbd109ca69a960cf78;hp=4f69a2af780c00c6d121ece2fc1647771bd790ee;hpb=1e6fd302fca27fb288343fc74b9f5e212078d5fe;p=bertos.git diff --git a/drv/ser.h b/drv/ser.h index 4f69a2af..c0f7b8bb 100644 --- a/drv/ser.h +++ b/drv/ser.h @@ -40,11 +40,37 @@ #ifndef DRV_SER_H #define DRV_SER_H - +#include #include #include -#include CPU_HEADER(ser) +#if OS_HOSTED + #include /* BV() */ + + typedef uint16_t serstatus_t; + + /* Software errors */ + #define SERRF_RXFIFOOVERRUN BV(0) /**< Rx FIFO buffer overrun */ + #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. */ + + enum + { + SER_UART0, + SER_UART1, + + SER_CNT /**< Number of serial ports */ + }; + +#else + #include CPU_HEADER(ser) +#endif #include @@ -126,31 +152,39 @@ typedef struct Serial struct SerialHardware* hw; } Serial; +typedef struct KFileSerial +{ + KFile fd; + Serial *ser; +} KFileSerial; -/* Function prototypes */ -extern int ser_putchar(int c, struct Serial *port); -extern int ser_getchar(struct Serial *port); -extern int ser_getchar_nowait(struct Serial *port); +/** + * ID for serial. + */ +#define KFT_SERIAL MAKE_ID('S', 'E', 'R', 'L') -extern int ser_write(struct Serial *port, const void *buf, size_t len); -extern int ser_read(struct Serial *port, void *buf, size_t size); -extern int ser_print(struct Serial *port, const char *s); -extern int ser_printf(struct Serial *port, const char *format, ...) FORMAT(__printf__, 2, 3); +INLINE KFileSerial * KFILESERIAL(KFile *fd) +{ + ASSERT(fd->_type == KFT_SERIAL); + return (KFileSerial *)fd; +} + +/* Function prototypes */ +//extern int ser_getchar_nowait(struct Serial *port); -extern int ser_gets(struct Serial *port, char *buf, int size); -extern int ser_gets_echo(struct Serial *port, char *buf, int size, bool echo); -extern void ser_clearstatus(struct Serial *port); +void ser_setbaudrate(struct KFileSerial *fd, unsigned long rate); +void ser_setparity(struct KFileSerial *fd, int parity); +void ser_settimeouts(struct KFileSerial *fd, mtime_t rxtimeout, mtime_t txtimeout); +void ser_resync(struct KFileSerial *fd, mtime_t delay); +int ser_getchar_nowait(struct KFileSerial *fd); -extern void ser_setbaudrate(struct Serial *port, unsigned long rate); -extern void ser_setparity(struct Serial *port, int parity); -extern void ser_settimeouts(struct Serial *port, mtime_t rxtimeout, mtime_t txtimeout); -extern void ser_resync(struct Serial *port, mtime_t delay); -extern void ser_purge(struct Serial *port); -extern void ser_drain(struct Serial *port); +void ser_purgeRx(struct KFileSerial *fd); +void ser_purgeTx(struct KFileSerial *fd); +void ser_purge(struct KFileSerial *fd); +void ser_init(struct KFileSerial *fds, unsigned int unit); +void spimaster_init(KFileSerial *fds, unsigned int unit); -extern struct Serial *ser_open(unsigned int unit); -extern void ser_close(struct Serial *port); /** * \name Additional functions implemented as macros