1 | #include <arch/philips/lpc2114.h>
|
2 | #include "config.h" // Config-File with System Defines
|
3 | #include <string.h>
|
4 | #include <stdlib.h>
|
5 | #include "uart.h"
|
6 |
|
7 | char uart0_rx_buffer;
|
8 | char uart0_buf_len=0;
|
9 |
|
10 | void uart_init(int baud, char num){
|
11 | unsigned int UART_DIVISOR=0;
|
12 | if(num==0){
|
13 | UART0_IER = 0x00; // disable all interrupts
|
14 | UART0_IIR = 0x00; // clear interrupt ID register
|
15 | UART0_LSR = 0x00; // clear line status register
|
16 | //Setting the UART Divisor Latch
|
17 | UART0_LCR = (1<<7);
|
18 | UART_DIVISOR = (((FOSC*PLL_M/VPBDIV_VAL) / ((baud) * 16.0)) + 0.5);
|
19 | //Calculate UART Divisor Latch
|
20 | UART0_DLL = (char)UART_DIVISOR; // Setting lower Byte of the Latch
|
21 | Divisor
|
22 | UART0_DLM = (char)(UART_DIVISOR >> 8); // Setting upper Byte of the
|
23 | Latch Divisor
|
24 |
|
25 | UART0_LCR = (3<<0); // 8bit Char Length
|
26 | UART0_FCR = (1<<0) | (2<<6); // FIFO Enable (Bit0 = 1) + Trigger
|
27 | level 2 = 8 Characters (at Bit6 = 2 )
|
28 |
|
29 | UART0_IER = (1<<0); // Receive Data Available Interrupt enablen
|
30 | }else{
|
31 | UART1_IER = 0x00; // disable all interrupts
|
32 | UART1_IIR = 0x00; // clear interrupt ID register
|
33 | UART1_LSR = 0x00; // clear line status register
|
34 | //Setting the UART Divisor Latch
|
35 | UART1_LCR = (1<<7);
|
36 | UART_DIVISOR = (((FOSC*PLL_M/VPBDIV_VAL) / ((baud) * 16.0)) + 0.5);
|
37 | //Calculate UART Divisor Latch
|
38 | UART1_DLL = (char)UART_DIVISOR; // Setting lower Byte of the Latch
|
39 | Divisor
|
40 | UART1_DLM = (char)(UART_DIVISOR >> 8); // Setting upper Byte of the
|
41 | Latch Divisor
|
42 |
|
43 | UART1_LCR = (3<<0); // 8bit Char Length
|
44 | UART1_FCR = (1<<0) | (2<<6); // FIFO Enable (Bit0 = 1) + Trigger
|
45 | level 2 = 8 Characters (at Bit6 = 2 )
|
46 |
|
47 | UART1_IER = (1<<0); // Receive Data Available Interrupt enablen
|
48 | }
|
49 | }
|
50 | void uart_putc(char c,char num){
|
51 | char ULSR_THRE;
|
52 | ULSR_THRE=(1 << 5);
|
53 | while (!(UART0_LSR & ULSR_THRE)) // wait for TX buffer to
|
54 | empty
|
55 | continue; // also either WDOG() or
|
56 | swap()
|
57 |
|
58 | UART0_THR = c; // put char to Transmit Holding Register
|
59 | }
|
60 |
|
61 | void uart_puts(char *s,char num){
|
62 | while(*s){
|
63 | uart_putc(*s,num);
|
64 | s++;
|
65 | }
|
66 | }
|
67 |
|
68 | int uart_getcW(int num){
|
69 | char ULSR_RDR;
|
70 | ULSR_RDR=(1 << 0);
|
71 | while ( !(UART0_LSR & ULSR_RDR) ); // wait for character
|
72 | return UART0_RBR; // return character
|
73 | }
|