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