7 * Function Name: lowInit()
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
21 static void lowInit(void)
23 // set PLL multiplier & divisor.
24 // values computed from config.h
25 PLLCFG
= PLLCFG_MSEL
| PLLCFG_PSEL
;
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
38 while (!(PLLSTAT
& PLLSTAT_LOCK
))
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
;
50 // set the peripheral bus speed
51 // value computed from config.h
52 VPBDIV
= VPBDIV_VALUE
; // set the peripheral bus clock speed
57 * Function Name: sysInit()
60 * This function is responsible for initializing the program
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()
86 * @param d duration (unit not defined yet)
93 for (i
= 0; i
< 10; i
++)
99 static int leds
[] = { 0x10000, 0x20000, 0x40000, 0x80000 };
101 /*////////////////////////////LEDS INITIALISATION///////////////////////*/
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 */
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 */
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)
143 int written_int_word
= -1;
144 char *testword
= "hello";
152 uartInit(UART_SEL1
, B9600
, UART_8N1
, UART_FIFO_8
);
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
);
169 if (i
++ & 1) ledOn(leds
[0]);
170 else ledOff(leds
[0]);
171 uartPutch(UART_SEL1
, written_int_word
);