ser.h
Go to the documentation of this file.00001
00045 #ifndef DRV_SER_H
00046 #define DRV_SER_H
00047
00048 #include <io/kfile.h>
00049 #include <struct/fifobuf.h>
00050 #include <cfg/compiler.h>
00051
00052 #if OS_HOSTED
00053 #include <cfg/macros.h>
00054
00055 typedef uint16_t serstatus_t;
00056
00057
00058 #define SERRF_RXFIFOOVERRUN BV(0)
00059 #define SERRF_RXTIMEOUT BV(1)
00060 #define SERRF_TXTIMEOUT BV(2)
00062
00063 #define SERRF_RXSROVERRUN 0
00064 #define SERRF_FRAMEERROR 0
00065 #define SERRF_PARITYERROR 0
00066 #define SERRF_NOISEERROR 0
00068 enum
00069 {
00070 SER_UART0,
00071 SER_UART1,
00072
00073 SER_CNT
00074 };
00075
00076 #else
00077 #include CPU_HEADER(ser)
00078 #endif
00079
00080 #include "cfg/cfg_ser.h"
00081
00082
00083
00088 #define SERRF_RX \
00089 ( SERRF_RXFIFOOVERRUN \
00090 | SERRF_RXTIMEOUT \
00091 | SERRF_RXSROVERRUN \
00092 | SERRF_PARITYERROR \
00093 | SERRF_FRAMEERROR \
00094 | SERRF_NOISEERROR)
00095 #define SERRF_TX (SERRF_TXTIMEOUT)
00096
00097
00103 #define SER_MSB_FIRST 0
00104 #define SER_LSB_FIRST 1
00105
00114 #define SER_PARITY_NONE 0
00115 #define SER_PARITY_EVEN 2
00116 #define SER_PARITY_ODD 3
00117
00118
00119
00130 #if !defined(CONFIG_SER_STROBE) || !CONFIG_SER_STROBE
00131 #define SER_STROBE_ON do {} while(0)
00132 #define SER_STROBE_OFF do {} while(0)
00133 #define SER_STROBE_INIT do {} while(0)
00134 #endif
00135
00136 struct SerialHardware;
00137
00139 extern const char * const serial_errors[8];
00140
00142 typedef struct Serial
00143 {
00145 KFile fd;
00146
00148 unsigned int unit;
00149
00150 #ifdef _DEBUG
00151 bool is_open;
00152 #endif
00153
00161 FIFOBuffer txfifo;
00162 FIFOBuffer rxfifo;
00163
00164
00165 #if CONFIG_SER_RXTIMEOUT != -1
00166 ticks_t rxtimeout;
00167 #endif
00168 #if CONFIG_SER_TXTIMEOUT != -1
00169 ticks_t txtimeout;
00170 #endif
00171
00173 volatile serstatus_t status;
00174
00176 struct SerialHardware* hw;
00177 } Serial;
00178
00179
00183 #define KFT_SERIAL MAKE_ID('S', 'E', 'R', 'L')
00184
00185
00186 INLINE Serial * SERIAL_CAST(KFile *fd)
00187 {
00188 ASSERT(fd->_type == KFT_SERIAL);
00189 return (Serial *)fd;
00190 }
00191
00192
00193
00194
00195 void ser_setbaudrate(struct Serial *fd, unsigned long rate);
00196 void ser_setparity(struct Serial *fd, int parity);
00197 void ser_settimeouts(struct Serial *fd, mtime_t rxtimeout, mtime_t txtimeout);
00198 void ser_resync(struct Serial *fd, mtime_t delay);
00199 int ser_getchar_nowait(struct Serial *fd);
00200
00201 void ser_purgeRx(struct Serial *fd);
00202 void ser_purgeTx(struct Serial *fd);
00203 void ser_purge(struct Serial *fd);
00204 void ser_init(struct Serial *fds, unsigned int unit);
00205 void spimaster_init(Serial *fds, unsigned int unit);
00206
00207
00213 #define ser_getstatus(serial) ((serial)->status)
00214 #define ser_setstatus(serial, new_status) ((serial)->status = (new_status))
00215
00216
00217 #endif