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