sgdk
16c550.h
00001 /************************************************************************/
00010 #ifndef _16C550_H_
00011 #define _16C550_H_
00012 
00013 #include "types.h"
00014 
00015 #if (MODULE_MEGAWIFI != 0)
00016 
00018 #define UART_BASE               0xA130C1
00019 
00021 #define UART_CLK                24000000LU
00022 
00025 #define UART_BR                 1500000LU
00026 //#define UART_BR                       500000LU
00027 //#define UART_BR                       750000LU
00028 //#define UART_BR                       115200
00029 
00031 #define UART_TX_FIFO_LEN                16
00032 
00034 #define DivWithRounding(dividend, divisor)      ((((dividend)*2/(divisor))+1)/2)
00035 
00036 #define UART_DLM_VAL    (DivWithRounding(UART_CLK, 16 * UART_BR)>>8)
00037 //#define UART_DLM_VAL  ((UART_CLK/16/UART_BR)>>8)
00039 #define UART_DLL_VAL    (DivWithRounding(UART_CLK, 16 * UART_BR) & 0xFF)
00040 //#define UART_DLL_VAL  ((UART_CLK/16/UART_BR)&0xFF)
00041 
00049 
00050 #define UART_RHR        (*((volatile uint8_t*)(UART_BASE +  0)))
00051 
00052 #define UART_THR        (*((volatile uint8_t*)(UART_BASE +  0)))
00053 
00054 #define UART_IER        (*((volatile uint8_t*)(UART_BASE +  2)))
00055 
00056 #define UART_FCR        (*((volatile uint8_t*)(UART_BASE +  4)))
00057 
00058 #define UART_ISR        (*((volatile uint8_t*)(UART_BASE +  4)))
00059 
00060 #define UART_LCR        (*((volatile uint8_t*)(UART_BASE +  6)))
00061 
00062 #define UART_MCR        (*((volatile uint8_t*)(UART_BASE +  8)))
00063 
00064 #define UART_LSR        (*((volatile uint8_t*)(UART_BASE + 10)))
00065 
00066 #define UART_MSR        (*((volatile uint8_t*)(UART_BASE + 12)))
00067 
00068 #define UART_SPR        (*((volatile uint8_t*)(UART_BASE + 14)))
00069 
00070 #define UART_DLL        (*((volatile uint8_t*)(UART_BASE +  0)))
00071 
00072 #define UART_DLM        (*((volatile uint8_t*)(UART_BASE +  2)))
00073 
00075 
00076 typedef struct {
00077         uint8_t IER;    
00078         uint8_t FCR;    
00079         uint8_t LCR;    
00080         uint8_t MCR;    
00081 } UartShadow;
00082 
00084 extern UartShadow sh;
00085 
00090 #define UART_MCR__DTR           0x01    ///< Data Terminal Ready.
00091 #define UART_MCR__RTS           0x02    ///< Request To Send.
00092 #define UART_MCR__OUT1          0x04    ///< GPIO pin 1.
00093 #define UART_MCR__OUT2          0x08    ///< GPIO pin 2.
00094 
00099 #define UART_MSR__DSR           0x20    ///< Data Set Ready
00100 
00102 /************************************************************************/
00107 void uart_init(void);
00108 
00109 /************************************************************************/
00115 #define uart_tx_ready() (UART_LSR & 0x20)
00116 
00117 /************************************************************************/
00122 #define uart_rx_ready() (UART_LSR & 0x01)
00123 
00124 /************************************************************************/
00130 #define uart_putc(c)            do{UART_RHR = (c);}while(0);
00131 
00132 /************************************************************************/
00138 #define uart_getc()             (UART_RHR)
00139 
00140 /************************************************************************/
00146 #define uart_set(reg, val)      do{sh.reg = (val);UART_##reg = (val);}while(0)
00147 
00148 /************************************************************************/
00154 #define uart_get(reg)           (sh.reg)
00155 
00156 /************************************************************************/
00162 #define uart_set_bits(reg, val) do{sh.reg |= (val);                     \
00163         UART_##reg = sh.reg;}while(0)
00164 
00165 /************************************************************************/
00171 #define uart_clr_bits(reg, val) do{sh.reg &= ~(val);                    \
00172         UART_##reg = sh.reg;}while(0)
00173 
00174 /************************************************************************/
00177 #define uart_reset_fifos()      uart_set_bits(FCR, 0x07)
00178 
00179 #endif // MODULE_MEGAWIFI
00180 
00181 #endif /*_16C550_H_*/
00182 
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines