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 <struct/fifobuf.h>
00045 #include <cfg/compiler.h>
00046 
00047 #if OS_HOSTED
00048     #include <cfg/macros.h> /* BV() */
00049 
00050     typedef uint16_t serstatus_t;
00051 
00052     /* Software errors */
00053     #define SERRF_RXFIFOOVERRUN  BV(0)  
00054     #define SERRF_RXTIMEOUT      BV(1)  
00055     #define SERRF_TXTIMEOUT      BV(2)  
00057     /* Hardware errors */
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 "cfg/cfg_ser.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     KFile fd;
00125 
00127     unsigned int unit;
00128 
00129 #ifdef _DEBUG
00130     bool is_open;
00131 #endif
00132 
00140     FIFOBuffer txfifo;
00141     FIFOBuffer rxfifo;
00142     /* \} */
00143 
00144 #if CONFIG_SER_RXTIMEOUT != -1
00145     ticks_t rxtimeout;
00146 #endif
00147 #if CONFIG_SER_TXTIMEOUT != -1
00148     ticks_t txtimeout;
00149 #endif
00150 
00152     volatile serstatus_t status;
00153 
00155     struct SerialHardware* hw;
00156 } Serial;
00157 
00158 
00162 #define KFT_SERIAL MAKE_ID('S', 'E', 'R', 'L')
00163 
00164 
00165 INLINE Serial * SERIAL_CAST(KFile *fd)
00166 {
00167     ASSERT(fd->_type == KFT_SERIAL);
00168     return (Serial *)fd;
00169 }
00170 
00171 /* Function prototypes */
00172 //extern int ser_getchar_nowait(struct Serial *port);
00173 
00174 void ser_setbaudrate(struct Serial *fd, unsigned long rate);
00175 void ser_setparity(struct Serial *fd, int parity);
00176 void ser_settimeouts(struct Serial *fd, mtime_t rxtimeout, mtime_t txtimeout);
00177 void ser_resync(struct Serial *fd, mtime_t delay);
00178 int ser_getchar_nowait(struct Serial *fd);
00179 
00180 void ser_purgeRx(struct Serial *fd);
00181 void ser_purgeTx(struct Serial *fd);
00182 void ser_purge(struct Serial *fd);
00183 void ser_init(struct Serial *fds, unsigned int unit);
00184 void spimaster_init(Serial *fds, unsigned int unit);
00185 
00186 
00192 #define ser_getstatus(h)    ((h)->status)
00193 #define ser_setstatus(h, x) ((h)->status = (x))
00194 /* \} */
00195 
00196 #endif /* DRV_SER_H */