[32] | 1 | #include "uart.h" |
---|
| 2 | |
---|
[36] | 3 | #define BASE_UART 0x800000FFF0C2C000 |
---|
| 4 | #define BAUD_UART 100000 |
---|
| 5 | //const long UART_BASE_ADR[1] = {0x800000FFF0C2C000}; |
---|
| 6 | //const int UART_BAUDS[1] = {0}; |
---|
[34] | 7 | const int BAUD_RATE =100000; |
---|
[32] | 8 | const int IN_CLK =50000000; |
---|
| 9 | |
---|
| 10 | #define REG8(add) *((volatile unsigned char *)(add)) |
---|
| 11 | |
---|
| 12 | #define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE) |
---|
| 13 | |
---|
| 14 | #define WAIT_FOR_XMITR(core) \ |
---|
| 15 | do { \ |
---|
[36] | 16 | lsr = REG8(BASE_UART + UART_LSR); \ |
---|
[32] | 17 | } while ((lsr & BOTH_EMPTY) != BOTH_EMPTY) |
---|
| 18 | |
---|
| 19 | #define WAIT_FOR_THRE(core) \ |
---|
| 20 | do { \ |
---|
[36] | 21 | lsr = REG8(BASE_UART + UART_LSR); \ |
---|
[32] | 22 | } while ((lsr & UART_LSR_THRE) != UART_LSR_THRE) |
---|
| 23 | |
---|
[36] | 24 | #define CHECK_FOR_CHAR(core) (REG8(BASE_UART + UART_LSR) & UART_LSR_DR) |
---|
[32] | 25 | |
---|
| 26 | #define WAIT_FOR_CHAR(core) \ |
---|
| 27 | do { \ |
---|
[36] | 28 | lsr = REG8(BASE_UART + UART_LSR); \ |
---|
[32] | 29 | } while ((lsr & UART_LSR_DR) != UART_LSR_DR) |
---|
| 30 | |
---|
| 31 | #define UART_TX_BUFF_LEN 32 |
---|
| 32 | #define UART_TX_BUFF_MASK (UART_TX_BUFF_LEN -1) |
---|
| 33 | |
---|
| 34 | char tx_buff[UART_TX_BUFF_LEN]; |
---|
| 35 | volatile int tx_level, rx_level; |
---|
| 36 | |
---|
[33] | 37 | void sal_main() __attribute__((noreturn)); |
---|
| 38 | void sal_main() |
---|
[32] | 39 | { |
---|
[33] | 40 | |
---|
| 41 | |
---|
| 42 | /* |
---|
| 43 | #define CONFIG_SYS_GBL_DATA_SIZE 128 / size in bytes reserved for initial data |
---|
| 44 | #define CONFIG_SYS_GBL_DATA_OFFSET (CONFIG_SYS_INIT_RAM_END - CONFIG_SYS_GBL_DATA_SIZE) |
---|
| 45 | #define CONFIG_SYS_INIT_SP_OFFSET CONFIG_SYS_GBL_DATA_OFFSET |
---|
| 46 | |
---|
| 47 | |
---|
| 48 | stackp: |
---|
| 49 | set CONFIG_SYS_INIT_SP_OFFSET, %fp |
---|
| 50 | andn %fp, 0x0f, %fp |
---|
| 51 | sub %fp, 64, %sp |
---|
| 52 | */ |
---|
[32] | 53 | uart_init(0); |
---|
[36] | 54 | |
---|
[32] | 55 | for(;;) { |
---|
| 56 | uart_puts(0,"XOpenSparc is alive \n"); |
---|
| 57 | } |
---|
| 58 | //return; |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | void uart_init(char core) |
---|
| 62 | { |
---|
| 63 | long allone=0xffffffffffffffff; |
---|
| 64 | int divisor; |
---|
[34] | 65 | //float float_divisor; |
---|
[32] | 66 | /* Reset receiver and transmiter */ |
---|
[36] | 67 | asm("nop \n"); |
---|
| 68 | asm("nop \n"); |
---|
| 69 | asm("nop \n"); |
---|
| 70 | asm("nop \n"); |
---|
| 71 | REG8( BASE_UART + UART_FCR ) = UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT | UART_FCR_TRIGGER_14; |
---|
| 72 | //REG8( UART_BASE_ADR[core] + UART_FCR ) = UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT | UART_FCR_TRIGGER_14; |
---|
| 73 | asm("nop \n"); |
---|
| 74 | asm("nop \n"); |
---|
| 75 | asm("nop \n"); |
---|
| 76 | asm("nop \n"); |
---|
| 77 | asm("nop \n"); |
---|
[33] | 78 | //asm("sethi %hi(8), %sp \n"); |
---|
| 79 | //asm("mov 0xfff, %sp \n"); |
---|
| 80 | |
---|
[32] | 81 | /* Disable all interrupts */ |
---|
[36] | 82 | REG8(BASE_UART + UART_IER) = 0x00; |
---|
| 83 | //REG8(UART_BASE_ADR[core] + UART_IER) = 0x00; |
---|
[32] | 84 | |
---|
| 85 | /* Set 8 bit char, 1 stop bit, no parity */ |
---|
[36] | 86 | REG8(BASE_UART + UART_LCR) = UART_LCR_WLEN8 & ~(UART_LCR_STOP | UART_LCR_PARITY); |
---|
[32] | 87 | |
---|
| 88 | /* Set baud rate */ |
---|
[34] | 89 | //float_divisor = (float) IN_CLK/(16 * UART_BAUDS[core]); |
---|
| 90 | //float_divisor += 0.50f; // Ensure round up |
---|
| 91 | //divisor = (int) float_divisor; |
---|
| 92 | divisor = BAUD_RATE; |
---|
| 93 | |
---|
[36] | 94 | REG8(BASE_UART + UART_LCR) |= UART_LCR_DLAB; |
---|
| 95 | REG8(BASE_UART + UART_DLL) = divisor & 0x000000ff; |
---|
| 96 | REG8(BASE_UART + UART_DLM) = (divisor >> 8) & 0x000000ff; |
---|
| 97 | REG8(BASE_UART + UART_LCR) &= ~(UART_LCR_DLAB); |
---|
[32] | 98 | |
---|
| 99 | return; |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | void uart_putc(char core, char c) |
---|
| 103 | { |
---|
| 104 | unsigned char lsr; |
---|
| 105 | |
---|
| 106 | WAIT_FOR_THRE(core); |
---|
[36] | 107 | REG8(BASE_UART + UART_TX) = c; |
---|
[32] | 108 | if(c == '\n') { |
---|
| 109 | WAIT_FOR_THRE(core); |
---|
[36] | 110 | REG8(BASE_UART + UART_TX) = '\r'; |
---|
[32] | 111 | } |
---|
| 112 | WAIT_FOR_XMITR(core); |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | void uart_puts (char core, char *s) { |
---|
| 116 | // loop until *s != NULL |
---|
| 117 | while (*s) { |
---|
| 118 | uart_putc(core,*s); |
---|
| 119 | s++; |
---|
| 120 | } |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | |
---|
| 124 | |
---|
| 125 | // Only used when we know THRE is empty, typically in interrupt |
---|
| 126 | /*void uart_putc_noblock(char core, char c) |
---|
| 127 | { |
---|
| 128 | REG8(UART_BASE_ADR[core] + UART_TX) = c; |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | |
---|
| 132 | char uart_getc(char core) |
---|
| 133 | { |
---|
| 134 | unsigned char lsr; |
---|
| 135 | char c; |
---|
| 136 | |
---|
| 137 | WAIT_FOR_CHAR(core); |
---|
| 138 | c = REG8(UART_BASE_ADR[core] + UART_RX); |
---|
| 139 | return c; |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | int uart_check_for_char(char core) |
---|
| 143 | { |
---|
| 144 | return CHECK_FOR_CHAR(core); |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | void uart_rxint_enable(char core) |
---|
| 148 | { |
---|
| 149 | REG8(UART_BASE_ADR[core] + UART_IER) |= UART_IER_RDI; |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | void uart_rxint_disable(char core) |
---|
| 153 | { |
---|
| 154 | REG8(UART_BASE_ADR[core] + UART_IER) &= ~(UART_IER_RDI); |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | void uart_txint_enable(char core) |
---|
| 158 | { |
---|
| 159 | REG8(UART_BASE_ADR[core] + UART_IER) |= UART_IER_THRI; |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | void uart_txint_disable(char core) |
---|
| 163 | { |
---|
| 164 | REG8(UART_BASE_ADR[core] + UART_IER) &= ~(UART_IER_THRI); |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | char uart_get_iir(char core) |
---|
| 168 | { |
---|
| 169 | return REG8(UART_BASE_ADR[core] + UART_IIR); |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | |
---|
| 173 | char uart_get_lsr(char core) |
---|
| 174 | { |
---|
| 175 | return REG8(UART_BASE_ADR[core] + UART_LSR); |
---|
| 176 | } |
---|
| 177 | |
---|
| 178 | |
---|
| 179 | char uart_get_msr(char core) |
---|
| 180 | { |
---|
| 181 | return REG8(UART_BASE_ADR[core] + UART_MSR); |
---|
| 182 | } |
---|
| 183 | */ |
---|
| 184 | |
---|
| 185 | |
---|