ld scripts moved to arch subdirectory.
[LPC2xxx_and_RobotSpejbl.git] / app / arm / test_uart / uart_test.c
blob8b3785a4cc3407d81312aa82ec85774e173a3e0b
1 #include <LPC210x.h>
2 #include "uartx.h"
6 /**
7 * Function Name: lowInit()
9 * Description:
10 * This function starts up the PLL then sets up the GPIO pins before
11 * waiting for the PLL to lock. It finally engages the PLL and
12 * returns
14 * Calling Sequence:
15 * void
17 * Returns:
18 * void
21 static void lowInit(void)
23 // set PLL multiplier & divisor.
24 // values computed from config.h
25 PLLCFG = PLLCFG_MSEL | PLLCFG_PSEL;
27 // enable PLL
28 PLLCON = PLLCON_PLLE;
29 PLLFEED = 0xAA; // Make it happen. These two updates
30 PLLFEED = 0x55; // MUST occur in sequence.
32 // setup the parallel port pin
33 IOCLR = PIO_ZERO_BITS; // clear the ZEROs output
34 IOSET = PIO_ONE_BITS; // set the ONEs output
35 IODIR = PIO_OUTPUT_BITS; // set the output bit direction
37 // wait for PLL lock
38 while (!(PLLSTAT & PLLSTAT_LOCK))
39 continue;
41 // enable & connect PLL
42 PLLCON = PLLCON_PLLE | PLLCON_PLLC;
43 PLLFEED = 0xAA; // Make it happen. These two updates
44 PLLFEED = 0x55; // MUST occur in sequence.
46 // setup & enable the MAM
47 MAMTIM = MAMTIM_CYCLES;
48 MAMCR = MAMCR_FULL;
50 // set the peripheral bus speed
51 // value computed from config.h
52 VPBDIV = VPBDIV_VALUE; // set the peripheral bus clock speed
56 /**
57 * Function Name: sysInit()
59 * Description:
60 * This function is responsible for initializing the program
61 * specific hardware
63 * Calling Sequence:
64 * void
66 * Returns:
67 * void
70 static void sysInit(void)
72 lowInit(); // setup clocks and processor port pins
74 MEMMAP = 1; // map interrupt vectors space into FLASH
76 VICIntEnClear = 0xFFFFFFFF; // clear all interrupts
77 VICIntSelect = 0x00000000; // clear all FIQ selections
78 VICDefVectAddr = (uint32_t)reset; // point unvectored IRQs to reset()
84 /**
85 * Creates a delay
86 * @param d duration (unit not defined yet)
88 void
89 delay(int d)
91 volatile int x;
92 int i;
93 for (i = 0; i < 10; i++)
94 for(x = d; x; --x)
98 #define NUM_LEDS 4
99 static int leds[] = { 0x10000, 0x20000, 0x40000, 0x80000 };
101 /*////////////////////////////LEDS INITIALISATION///////////////////////*/
104 * Initializes leds.
106 static void ledInit()
108 IODIR |= 0x000F0000; /*leds connected to P0.16 17 18 & 19 should blink*/
109 IOSET = 0x00000000; /* all leds are switched off */
113 * Switches the leds off.
114 * @param led switched off led number. (integer)
116 static void ledOff(int led) /* Ioclr.i =1 => IOset.i cleared */
118 IOCLR = led;
122 * Switches the leds on.
123 * @param led switched on led number. (integer)
125 static void ledOn(int led) /* Ioset.i = 1 => P0.i = 1 */
127 IOSET = led;
134 * this program uses UART1 to print hello as a test word
135 * if everything is correct, leds 0 and 1 should be switched on
136 * then the program ask to type a word and print it continuously (led 0 blinks at each write)
137 * @param
138 * @return
140 int main(void)
142 int i = 0;
143 int written_int_word = -1;
144 char *testword = "hello";
146 sysInit();
148 ledInit();
149 ledOn(leds[0]);
152 uartInit(UART_SEL1, B9600 , UART_8N1, UART_FIFO_8);
155 ledOn(leds[1]);
157 uartPutch(UART_SEL1, '\n');
158 uartPuts( UART_SEL1, testword);
160 uartPuts( UART_SEL1, "\nPlease write one character:");
162 uartPutch(UART_SEL1, '\n');
163 while(written_int_word == -1)
164 written_int_word = uartGetch(UART_SEL1);
167 while(1)
169 if (i++ & 1) ledOn(leds[0]);
170 else ledOff(leds[0]);
171 uartPutch(UART_SEL1, written_int_word);
172 delay(200000);
176 return 0;