changing circuitry to disable RTC, update initialization to match
[fw/openalt] / cpu / cpu.c
1 #include "FreeRTOS.h"
2 #include "cpu/cpu.h"
3
4 //
5 //  Olimex board specific.  LEDs are on P0.10, P0.11
6 //
7 #define partstFIRST_IO                    ((unsigned portLONG) 0x400)
8 #define partstNUM_LEDS                    (2)
9 #define partstALL_OUTPUTS_OFF   ((unsigned portLONG) 0xffffffff)
10
11 //
12 //
13 //
14 void cpuSetupHardware (void)
15 {
16 #ifdef RUN_FROM_RAM
17   //
18   //  Remap the interrupt vectors to RAM if we are are running from RAM
19   //
20   SCB_MEMMAP = SCB_MEMMAP_URM;
21 #endif
22
23   //
24   //  Configure the RS2332 pins.  All other pins remain at their default of 0
25   //
26   PCB_PINSEL0 |= (PCB_PINSEL0_P00_TXD0 | PCB_PINSEL0_P01_RXD0 | PCB_PINSEL0_P08_TXD1 | PCB_PINSEL0_P09_RXD1);
27
28   //
29   //  Set all GPIO to output other than the P0.14 (BSL), and the JTAG pins.  
30   //  The JTAG pins are left as input as I'm not sure what will happen if the 
31   //  Wiggler is connected after powerup - not that it would be a good idea to
32   //  do that anyway.
33   //
34   GPIO0_IODIR = ~(GPIO_IO_P14 | GPIO_IO_P15 | GPIO_IO_P15);
35   GPIO1_IODIR = ~GPIO_IO_JTAG;
36
37   //
38   //  Setup the PLL to multiply the 12Mhz XTAL input by 4, divide by 1
39   //
40   SCB_PLLCFG = (SCB_PLLCFG_MUL4 | SCB_PLLCFG_DIV1);
41
42   //
43   //  Activate the PLL by turning it on then feeding the correct sequence of bytes
44   //
45   SCB_PLLCON  = SCB_PLLCON_PLLE;
46   SCB_PLLFEED = SCB_PLLFEED_FEED1;
47   SCB_PLLFEED = SCB_PLLFEED_FEED2;
48
49   //
50   //  Wait for the PLL to lock...
51   //
52   while (!(SCB_PLLSTAT & SCB_PLLSTAT_PLOCK))
53     ;
54
55   //
56   //  ...before connecting it using the feed sequence again
57   //
58   SCB_PLLCON  = SCB_PLLCON_PLLC | SCB_PLLCON_PLLE;
59   SCB_PLLFEED = SCB_PLLFEED_FEED1;
60   SCB_PLLFEED = SCB_PLLFEED_FEED2;
61
62   //
63   //  Setup and turn on the MAM.  Three cycle access is used due to the fast
64   //  PLL used.  It is possible faster overall performance could be obtained by
65   //  tuning the MAM and PLL settings.
66   //
67   MAM_TIM = MAM_TIM_3;
68   MAM_CR = MAM_CR_FULL;
69
70   //
71   //  Setup the peripheral bus to be the same as the PLL output (48Mhz)
72   //
73   SCB_VPBDIV = SCB_VPBDIV_100;
74
75   //
76   //  Disable power to all modules
77   //
78   SCB_PCONP = 0x0000;
79
80   //
81   //
82   //
83   cpuGPIOInitialize ();
84 }
85
86 //
87 //
88 //
89 void cpuPLLDisable (void)
90 {
91   SCB_PLLCON  = 0;
92   SCB_PLLFEED = SCB_PLLFEED_FEED1;
93   SCB_PLLFEED = SCB_PLLFEED_FEED2;
94   SCB_PLLCFG =  0;
95 }
96
97 //
98 //
99 //
100 void cpuT1Disable (void)
101 {
102   T1_TCR = 0;
103   T1_PR = 0;
104   T1_MCR = 0;
105   T1_CCR = 0;
106   T1_EMR = 0;
107   T1_CTCR = 0;
108   T1_IR = 0;
109 }
110
111 //
112 //
113 //
114 void cpuGPIOInitialize (void)
115 {
116         GPIO0_IOSET = partstALL_OUTPUTS_OFF;
117 }
118
119 void cpuToggleLED (unsigned portBASE_TYPE uxLED)
120 {
121   unsigned portLONG ulLED = partstFIRST_IO;
122
123   if (uxLED < partstNUM_LEDS)
124   {
125     ulLED <<= (unsigned portLONG) uxLED;
126
127     if (GPIO0_IOPIN & ulLED)
128       GPIO0_IOCLR = ulLED;
129     else
130       GPIO0_IOSET = ulLED;                      
131   }     
132 }