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> /* BV() */
00056 
00057     typedef uint16_t serstatus_t;
00058 
00059     /* Software errors */
00060     #define SERRF_RXFIFOOVERRUN  BV(0)  
00061     #define SERRF_RXTIMEOUT      BV(1)  
00062     #define SERRF_TXTIMEOUT      BV(2)  
00064     /* Hardware errors */
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 
00122 struct SerialHardware;
00123 
00125 extern const char * const serial_errors[8];
00126 
00128 typedef struct Serial
00129 {
00131     KFile fd;
00132 
00134     unsigned int unit;
00135 
00136 #ifdef _DEBUG
00137     bool is_open;
00138 #endif
00139 
00147     FIFOBuffer txfifo;
00148     FIFOBuffer rxfifo;
00149     /* \} */
00150 
00151 #if CONFIG_SER_RXTIMEOUT != -1
00152     ticks_t rxtimeout;
00153 #endif
00154 #if CONFIG_SER_TXTIMEOUT != -1
00155     ticks_t txtimeout;
00156 #endif
00157 
00159     volatile serstatus_t status;
00160 
00162     struct SerialHardware* hw;
00163 } Serial;
00164 
00165 
00169 #define KFT_SERIAL MAKE_ID('S', 'E', 'R', 'L')
00170 
00171 
00172 INLINE Serial * SERIAL_CAST(KFile *fd)
00173 {
00174     ASSERT(fd->_type == KFT_SERIAL);
00175     return (Serial *)fd;
00176 }
00177 
00178 /* Function prototypes */
00179 //extern int ser_getchar_nowait(struct Serial *port);
00180 
00181 void ser_setbaudrate(struct Serial *fd, unsigned long rate);
00182 void ser_setparity(struct Serial *fd, int parity);
00183 void ser_settimeouts(struct Serial *fd, mtime_t rxtimeout, mtime_t txtimeout);
00184 void ser_resync(struct Serial *fd, mtime_t delay);
00185 int ser_getchar_nowait(struct Serial *fd);
00186 
00187 void ser_purgeRx(struct Serial *fd);
00188 void ser_purgeTx(struct Serial *fd);
00189 void ser_purge(struct Serial *fd);
00190 void ser_init(struct Serial *fds, unsigned int unit);
00191 void spimaster_init(Serial *fds, unsigned int unit);
00192 
00193 
00199 #define ser_getstatus(h)    ((h)->status)
00200 #define ser_setstatus(h, x) ((h)->status = (x))
00201 /* \} */
00202 
00203 #endif /* DRV_SER_H */