ser.h
Go to the documentation of this file.00001
00040 #ifndef DRV_SER_H
00041 #define DRV_SER_H
00042
00043 #include <kern/kfile.h>
00044 #include <mware/fifobuf.h>
00045 #include <cfg/compiler.h>
00046
00047 #if OS_HOSTED
00048 #include <cfg/macros.h>
00049
00050 typedef uint16_t serstatus_t;
00051
00052
00053 #define SERRF_RXFIFOOVERRUN BV(0)
00054 #define SERRF_RXTIMEOUT BV(1)
00055 #define SERRF_TXTIMEOUT BV(2)
00057
00058 #define SERRF_RXSROVERRUN 0
00059 #define SERRF_FRAMEERROR 0
00060 #define SERRF_PARITYERROR 0
00061 #define SERRF_NOISEERROR 0
00063 enum
00064 {
00065 SER_UART0,
00066 SER_UART1,
00067
00068 SER_CNT
00069 };
00070
00071 #else
00072 #include CPU_HEADER(ser)
00073 #endif
00074
00075 #include <appconfig.h>
00076
00077
00078
00083 #define SERRF_RX \
00084 ( SERRF_RXFIFOOVERRUN \
00085 | SERRF_RXTIMEOUT \
00086 | SERRF_RXSROVERRUN \
00087 | SERRF_PARITYERROR \
00088 | SERRF_FRAMEERROR \
00089 | SERRF_NOISEERROR)
00090 #define SERRF_TX (SERRF_TXTIMEOUT)
00091
00092
00097 #define SER_MSB_FIRST 0
00098 #define SER_LSB_FIRST 1
00099
00100
00109 #define SER_PARITY_NONE 0
00110 #define SER_PARITY_EVEN 2
00111 #define SER_PARITY_ODD 3
00112
00113
00114
00115 struct SerialHardware;
00116
00118 extern const char * const serial_errors[8];
00119
00121 typedef struct Serial
00122 {
00124 unsigned int unit;
00125
00126 #ifdef _DEBUG
00127 bool is_open;
00128 #endif
00129
00137 FIFOBuffer txfifo;
00138 FIFOBuffer rxfifo;
00139
00140
00141 #if CONFIG_SER_RXTIMEOUT != -1
00142 ticks_t rxtimeout;
00143 #endif
00144 #if CONFIG_SER_TXTIMEOUT != -1
00145 ticks_t txtimeout;
00146 #endif
00147
00149 volatile serstatus_t status;
00150
00152 struct SerialHardware* hw;
00153 } Serial;
00154
00155 typedef struct KFileSerial
00156 {
00157 KFile fd;
00158 Serial *ser;
00159 } KFileSerial;
00160
00164 #define KFT_SERIAL MAKE_ID('S', 'E', 'R', 'L')
00165
00166
00167 INLINE KFileSerial * KFILESERIAL(KFile *fd)
00168 {
00169 ASSERT(fd->_type == KFT_SERIAL);
00170 return (KFileSerial *)fd;
00171 }
00172
00173
00174
00175
00176 void ser_setbaudrate(struct KFileSerial *fd, unsigned long rate);
00177 void ser_setparity(struct KFileSerial *fd, int parity);
00178 void ser_settimeouts(struct KFileSerial *fd, mtime_t rxtimeout, mtime_t txtimeout);
00179 void ser_resync(struct KFileSerial *fd, mtime_t delay);
00180 int ser_getchar_nowait(struct KFileSerial *fd);
00181
00182 void ser_purgeRx(struct KFileSerial *fd);
00183 void ser_purgeTx(struct KFileSerial *fd);
00184 void ser_purge(struct KFileSerial *fd);
00185 void ser_init(struct KFileSerial *fds, unsigned int unit);
00186 void spimaster_init(KFileSerial *fds, unsigned int unit);
00187
00188
00194 #define ser_getstatus(h) ((h)->status)
00195 #define ser_setstatus(h, x) ((h)->status = (x))
00196
00197
00198 #endif