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