#ifndef __uart_h__ #define __uart_h__ #include "type.h" #include "io.h" struct Uart { typedef Io Accesseur; Accesseur regs[0]; // bank x Relative lcr; Relative bsr; // bank 0 Relative txd; Relative rxd; Relative ier; Relative eir; Relative fcr; Relative mcr; Relative lsr; Relative reserved; Relative spr; Relative ascr; // bank 1 Relative lbgdl; Relative lbgdh; // bank 2 Relative bgdl; Relative bgdh; Relative excr1; Relative excr2; Relative txflv; Relative rxflv; // bank 3 Relative mrid; Relative shLcr; Relative shFcr; void init(); inline void sendChar(U8 b) { while(!(lsr&0x20)) ; txd=b; } inline void flush() { while(!(lsr&0x40)) ; } inline U32 gotChar() { return lsr&0x01; } inline U32 getChar() { if(!(lsr&0x01)) return ~0; return rxd; } inline U32 waitChar() { while(!(lsr&0x01)) ; return rxd; } Uart& sendString(const U8 *string,U32 len); Uart& sendString(const U8 *string); inline Uart& sendString(const S8 *string) { return sendString((const U8 *)string); } void sendU32(U32 v,int size=8); inline void sendU16(U32 v) {sendU32((U32)v,4);} inline void sendU8 (U8 v) {sendU32((U32)v,2);} #ifndef _bur #endif void sendInt(int v); void sendHex(U8 v); void sendPrintable(U8 v); void dump(U8* buf,U32 len,U32 address=0,U32 increment=1); U32 yload(U8 *address); inline Uart& operator <<(const U8 *s) { sendString(s);return *this; } inline Uart& operator <<(const S8 *s) { sendString(s);return *this; } #ifndef _bur inline Uart& operator <<(int v) { sendInt(v);return *this; } #endif inline Uart& operator <<(S8 v) { sendChar(v);return *this; } inline Uart& operator <<(U8 v) { sendU8(v);return *this; } inline Uart& operator <<(U16 v) { sendU16(v);return *this; } inline Uart& operator <<(U32 v) { sendU32(v);return *this; } }; #define com1 (*(Uart*)0x3f8) #define com2 (*(Uart*)0x378) #endif /* __uart_h__ */