1 | /* Constants to setup and access the UART. */
|
2 | #define serDLAB ( ( unsigned char ) 0x80 )
|
3 | #define serENABLE_INTERRUPTS ( ( unsigned char ) 0x03 )
|
4 | #define serNO_PARITY ( ( unsigned char ) 0x00 )
|
5 | #define ser1_STOP_BIT ( ( unsigned char ) 0x00 )
|
6 | #define ser8_BIT_CHARS ( ( unsigned char ) 0x03 )
|
7 | #define serFIFO_ON ( ( unsigned char ) 0x01 )
|
8 | #define serCLEAR_FIFO ( ( unsigned char ) 0x06 )
|
9 | #define serWANTED_CLOCK_SCALING ( ( unsigned long ) 16 )
|
10 |
|
11 | /* Constants to setup and access the VIC. */
|
12 | #define serUART0_VIC_CHANNEL ( ( unsigned long ) 0x0006 )
|
13 | #define serUART0_VIC_CHANNEL_BIT ( ( unsigned long ) 0x0040 )
|
14 | #define serUART0_VIC_ENABLE ( ( unsigned long ) 0x0020 )
|
15 |
|
16 | void init()
|
17 | {
|
18 | .............
|
19 | /* Setup the baud rate: Calculate the divisor value. */
|
20 | ulWantedClock = ulWantedBaud * serWANTED_CLOCK_SCALING * 4; // * 4 because of PCLK_UART0
|
21 | ulDivisor = configCPU_CLOCK_HZ / ulWantedClock;
|
22 |
|
23 | /* Set the DLAB bit so we can access the divisor. */
|
24 | U0LCR |= serDLAB;
|
25 |
|
26 | /* Setup the divisor. */
|
27 | U0DLL = ( unsigned char ) ( ulDivisor & ( unsigned long ) 0xff );
|
28 | ulDivisor >>= 8;
|
29 | U0DLM = ( unsigned char ) ( ulDivisor & ( unsigned long ) 0xff );
|
30 |
|
31 | /* Turn on the FIFO's and clear the buffers. */
|
32 | U0FCR = ( serFIFO_ON | serCLEAR_FIFO );
|
33 |
|
34 | /* Setup transmission format. */
|
35 | U0LCR = serNO_PARITY | ser1_STOP_BIT | ser8_BIT_CHARS;
|
36 |
|
37 | /* Enable UART0 interrupts. */
|
38 | U0IER = serENABLE_INTERRUPTS; //RBR and THR IRQ
|
39 |
|
40 | /* initialize VIC */
|
41 | VICIntEnClr = 0xffffffff;
|
42 | VICVectAddr = 0x00000000;
|
43 | VICIntSelect = 0x00000000; /* all IRQ */
|
44 |
|
45 | /* Setup the VIC for the UART. */
|
46 | VICIntSelect &= ~( serUART0_VIC_CHANNEL_BIT ); //IRQ, not FIQ
|
47 | VICIntEnClr = serUART0_VIC_CHANNEL_BIT;
|
48 | VICVectAddr6 = ( long ) vUART_ISR_Handler;
|
49 | VICVectCntl6 = 0xF; //Prio
|
50 | VICIntEnable |= serUART0_VIC_CHANNEL_BIT;
|
51 |
|
52 | ..........
|
53 | }
|