]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/HCS12_CodeWarrior_small/CODE/Cpu.C
Add FreeRTOS-Plus directory.
[freertos] / FreeRTOS / Demo / HCS12_CodeWarrior_small / CODE / Cpu.C
1 /** ###################################################################\r
2 **     THIS BEAN MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.\r
3 **     Filename  : Cpu.C\r
4 **     Project   : RTOSDemo\r
5 **     Processor : MC9S12C32CFU\r
6 **     Beantype  : MC9S12C32_80\r
7 **     Version   : Bean 01.002, Driver 01.09, CPU db: 2.87.276\r
8 **     Compiler  : Metrowerks HC12 C Compiler\r
9 **     Date/Time : 18/06/2005, 18:00\r
10 **     Abstract  :\r
11 **         This bean "MC9S12C32_80" implements properties, methods,\r
12 **         and events of the CPU.\r
13 **     Settings  :\r
14 **\r
15 **     Contents  :\r
16 **         EnableInt   - void Cpu_EnableInt(void);\r
17 **         DisableInt  - void Cpu_DisableInt(void);\r
18 **         SetWaitMode - void Cpu_SetWaitMode(void);\r
19 **         SetStopMode - void Cpu_SetStopMode(void);\r
20 **\r
21 **     (c) Copyright UNIS, spol. s r.o. 1997-2002\r
22 **     UNIS, spol. s r.o.\r
23 **     Jundrovska 33\r
24 **     624 00 Brno\r
25 **     Czech Republic\r
26 **     http      : www.processorexpert.com\r
27 **     mail      : info@processorexpert.com\r
28 ** ###################################################################*/\r
29 \r
30 /* MODULE Cpu. */\r
31 \r
32 #include "Byte1.h"\r
33 #include "TickTimer.h"\r
34 #include "ButtonInterrupt.h"\r
35 #include "PE_Types.h"\r
36 #include "PE_Error.h"\r
37 #include "PE_Const.h"\r
38 #include "IO_Map.h"\r
39 #include "PE_Timer.h"\r
40 #include "Events.h"\r
41 #include "Cpu.h"\r
42 \r
43 #define CGM_DELAY  3071UL\r
44 \r
45 \r
46 /* Global variables */\r
47 volatile byte CCR_reg;                 /* Current CCR reegister */\r
48 byte CpuMode = HIGH_SPEED;             /* Current speed mode */\r
49 \r
50 \r
51 /*\r
52 ** ===================================================================\r
53 **     Method      :  Cpu_Interrupt (bean MC9S12C32_80)\r
54 **\r
55 **     Description :\r
56 **         This method is internal. It is used by Processor Expert\r
57 **         only.\r
58 ** ===================================================================\r
59 */\r
60 #pragma CODE_SEG __NEAR_SEG NON_BANKED /* Interrupt section for this module. Placement will be in NON_BANKED area. */\r
61 \r
62 __interrupt void Cpu_Interrupt(void)\r
63 {\r
64 }\r
65 \r
66 #pragma CODE_SEG DEFAULT               /* Change code section to DEFAULT. */\r
67 \r
68 /*\r
69 ** ===================================================================\r
70 **     Method      :  Cpu_DisableInt (bean MC9S12C32_80)\r
71 **\r
72 **     Description :\r
73 **         Disable maskable interrupts\r
74 **     Parameters  : None\r
75 **     Returns     : Nothing\r
76 ** ===================================================================\r
77 */\r
78 /*\r
79 void Cpu_DisableInt(void)\r
80 \r
81 **      This method is implemented as macro in the header module. **\r
82 */\r
83 \r
84 /*\r
85 ** ===================================================================\r
86 **     Method      :  Cpu_EnableInt (bean MC9S12C32_80)\r
87 **\r
88 **     Description :\r
89 **         Enable maskable interrupts\r
90 **     Parameters  : None\r
91 **     Returns     : Nothing\r
92 ** ===================================================================\r
93 */\r
94 /*\r
95 void Cpu_EnableInt(void)\r
96 \r
97 **      This method is implemented as macro in the header module. **\r
98 */\r
99 \r
100 /*\r
101 ** ===================================================================\r
102 **     Method      :  Cpu_SetStopMode (bean MC9S12C32_80)\r
103 **\r
104 **     Description :\r
105 **         Set low power mode - Stop mode. For more information\r
106 **         about the stop mode see documentation of this CPU.\r
107 **     Parameters  : None\r
108 **     Returns     : Nothing\r
109 ** ===================================================================\r
110 */\r
111 /*\r
112 void Cpu_SetStopMode(void)\r
113 \r
114 **      This method is implemented as macro in the header module. **\r
115 */\r
116 \r
117 /*\r
118 ** ===================================================================\r
119 **     Method      :  Cpu_SetWaitMode (bean MC9S12C32_80)\r
120 **\r
121 **     Description :\r
122 **         Set low power mode - Wait mode. For more information\r
123 **         about the wait mode see documentation of this CPU.\r
124 **         Release from Watch mode: Reset or interrupt\r
125 **     Parameters  : None\r
126 **     Returns     : Nothing\r
127 ** ===================================================================\r
128 */\r
129 /*\r
130 void Cpu_SetWaitMode(void)\r
131 \r
132 **      This method is implemented as macro in the header module. **\r
133 */\r
134 \r
135 /*\r
136 ** ===================================================================\r
137 **     Method      :  _EntryPoint (bean MC9S12C32_80)\r
138 **\r
139 **     Description :\r
140 **         This method is internal. It is used by Processor Expert\r
141 **         only.\r
142 ** ===================================================================\r
143 */\r
144 extern void _Startup(void);            /* Forward declaration of external startup function declared in file Start12.c */\r
145 #define INITRG_ADR  0x0011             /* Register map position register */\r
146 #pragma NO_FRAME\r
147 #pragma NO_EXIT\r
148 void _EntryPoint(void)\r
149 {\r
150   /*** ### MC9S12C32_80 "Cpu" init code ... ***/\r
151   /*** PE initialization code after reset ***/\r
152   /* Initialization of the registers INITRG, INITRM, INITEE is done to protect them to be written accidentally later by the application */\r
153   *(byte*)INITRG_ADR = 0;              /* Set the register map position */\r
154   asm nop;                             /* nop instruction */\r
155   INITRM=8;                            /* Set the RAM map position */\r
156   /* MISC: ??=0,??=0,??=0,??=0,EXSTR1=0,EXSTR0=0,ROMHM=0,ROMON=1 */\r
157   MISC=1;\r
158   /* System clock initialization */\r
159   CLKSEL=0;\r
160   CLKSEL_PLLSEL = 0;                   /* Select clock source from XTAL */\r
161   PLLCTL_PLLON = 0;                    /* Disable the PLL */\r
162   SYNR = 23;                           /* Set the multiplier register */\r
163   REFDV = 15;                          /* Set the divider register */\r
164   PLLCTL = 192;\r
165   PLLCTL_PLLON = 1;                    /* Enable the PLL */\r
166   while(!CRGFLG_LOCK);                 /* Wait */\r
167   CLKSEL_PLLSEL = 1;                   /* Select clock source from PLL */\r
168   /*** End of PE initialization code after reset ***/\r
169 \r
170   __asm   jmp _Startup;                /* Jump to C startup code */\r
171 }\r
172 \r
173 /*\r
174 ** ===================================================================\r
175 **     Method      :  PE_low_level_init (bean MC9S12C32_80)\r
176 **\r
177 **     Description :\r
178 **         This method is internal. It is used by Processor Expert\r
179 **         only.\r
180 ** ===================================================================\r
181 */\r
182 void PE_low_level_init(void)\r
183 {\r
184   /* Common initialization of the CPU registers */\r
185 /* TSCR1: TEN=0,TSWAI=0,TSFRZ=1 */\r
186   output( TSCR1, input( TSCR1 ) & ~192 | 32 );\r
187 /* TCTL2: OM0=0,OL0=0 */\r
188   output( TCTL2, input( TCTL2 ) & ~3 );\r
189 /* TCTL1: OM7=0,OL7=0 */\r
190   output( TCTL1, input( TCTL1 ) & ~192 );\r
191 /* TIE: C0I=0 */\r
192   output( TIE, input( TIE ) & ~1 );\r
193 /* TTOV: TOV0=0 */\r
194   output( TTOV, input( TTOV ) & ~1 );\r
195 /* TSCR2: TOI=0,TCRE=1 */\r
196   output( TSCR2, input( TSCR2 ) & ~128 | 8 );\r
197 /* TIOS: IOS7=1,IOS0=1 */\r
198   output( TIOS, input( TIOS ) | 129 );\r
199 /* PPSP: PPSP0=0 */\r
200   output( PPSP, input( PPSP ) & ~1 );\r
201 /* PERP: PERP0=1 */\r
202   output( PERP, input( PERP ) | 1 );\r
203 /* DDRP: DDRP0=0 */\r
204   output( DDRP, input( DDRP ) & ~1 );\r
205 /* PWMCTL: PSWAI=0,PFRZ=0 */\r
206   output( PWMCTL, input( PWMCTL ) & ~12 );\r
207 /* PWMSDN: PWMIF=0,PWMIE=0,PWMRSTRT=0,PWMLVL=0,??=0,PWM7IN=0,PWM7INL=0,PWM7ENA=0 */\r
208   output( PWMSDN, 0 );\r
209   /* ### MC9S12C32_80 "Cpu" init code ... */\r
210   /* ### ByteIO "Byte1" init code ... */\r
211   PORTB = 0;                           /* Prepare value for output */\r
212   DDRB = 255;                          /* Set direction to output */\r
213   /* ### TimerInt "TickTimer" init code ... */\r
214   TickTimer_Init();\r
215   /* ### External interrupt "ButtonInterrupt" init code ... */\r
216   PIEP_PIEP0 = 0;                      /* Disable interrupt */\r
217  /* Common peripheral initialization - ENABLE */\r
218 /* TSCR1: TEN=1 */\r
219   output( TSCR1, input( TSCR1 ) | 128 );\r
220   INTCR_IRQEN = 0;                     /* Disable the IRQ interrupt. IRQ interrupt is enabled after CPU reset by default. */\r
221   __DI();                              /* Disable interrupts */\r
222 }\r
223 \r
224 /* END Cpu. */\r
225 \r
226 /*\r
227 ** ###################################################################\r
228 **\r
229 **     This file was created by UNIS Processor Expert 03.33 for \r
230 **     the Motorola HCS12 series of microcontrollers.\r
231 **\r
232 ** ###################################################################\r
233 */\r