]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/HCS12_CodeWarrior_banked/CODE/Cpu.C
commit 9f316c246baafa15c542a5aea81a94f26e3d6507
[freertos] / FreeRTOS / Demo / HCS12_CodeWarrior_banked / 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 : MC9S12DP256BCPV\r
6 **     Beantype  : MC9S12DP256_112\r
7 **     Version   : Bean 01.148, Driver 01.09, CPU db: 2.87.283\r
8 **     Compiler  : Metrowerks HC12 C Compiler\r
9 **     Date/Time : 18/06/2005, 16:21\r
10 **     Abstract  :\r
11 **         This bean "MC9S12DP256_112" 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 **\r
19 **     (c) Copyright UNIS, spol. s r.o. 1997-2002\r
20 **     UNIS, spol. s r.o.\r
21 **     Jundrovska 33\r
22 **     624 00 Brno\r
23 **     Czech Republic\r
24 **     http      : www.processorexpert.com\r
25 **     mail      : info@processorexpert.com\r
26 ** ###################################################################*/\r
27 \r
28 /* MODULE Cpu. */\r
29 \r
30 #include "TickTimer.h"\r
31 #include "Byte1.h"\r
32 #include "COM0.h"\r
33 #include "PE_Types.h"\r
34 #include "PE_Error.h"\r
35 #include "PE_Const.h"\r
36 #include "IO_Map.h"\r
37 #include "PE_Timer.h"\r
38 #include "Events.h"\r
39 #include "Cpu.h"\r
40 \r
41 #define CGM_DELAY  3071UL\r
42 \r
43 \r
44 /* Global variables */\r
45 volatile byte CCR_reg;                 /* Current CCR reegister */\r
46 byte CpuMode = HIGH_SPEED;             /* Current speed mode */\r
47 \r
48 \r
49 /*\r
50 ** ===================================================================\r
51 **     Method      :  Cpu_Interrupt (bean MC9S12DP256_112)\r
52 **\r
53 **     Description :\r
54 **         This method is internal. It is used by Processor Expert\r
55 **         only.\r
56 ** ===================================================================\r
57 */\r
58 #pragma CODE_SEG __NEAR_SEG NON_BANKED /* Interrupt section for this module. Placement will be in NON_BANKED area. */\r
59 \r
60 __interrupt void Cpu_Interrupt(void)\r
61 {\r
62 }\r
63 \r
64 #pragma CODE_SEG DEFAULT               /* Change code section to DEFAULT. */\r
65 \r
66 /*\r
67 ** ===================================================================\r
68 **     Method      :  Cpu_DisableInt (bean MC9S12DP256_112)\r
69 **\r
70 **     Description :\r
71 **         Disable maskable interrupts\r
72 **     Parameters  : None\r
73 **     Returns     : Nothing\r
74 ** ===================================================================\r
75 */\r
76 /*\r
77 void Cpu_DisableInt(void)\r
78 \r
79 **      This method is implemented as macro in the header module. **\r
80 */\r
81 \r
82 /*\r
83 ** ===================================================================\r
84 **     Method      :  Cpu_EnableInt (bean MC9S12DP256_112)\r
85 **\r
86 **     Description :\r
87 **         Enable maskable interrupts\r
88 **     Parameters  : None\r
89 **     Returns     : Nothing\r
90 ** ===================================================================\r
91 */\r
92 /*\r
93 void Cpu_EnableInt(void)\r
94 \r
95 **      This method is implemented as macro in the header module. **\r
96 */\r
97 \r
98 /*\r
99 ** ===================================================================\r
100 **     Method      :  _EntryPoint (bean MC9S12DP256_112)\r
101 **\r
102 **     Description :\r
103 **         This method is internal. It is used by Processor Expert\r
104 **         only.\r
105 ** ===================================================================\r
106 */\r
107 extern void _Startup(void);            /* Forward declaration of external startup function declared in file Start12.c */\r
108 #define INITRG_ADR  0x0011             /* Register map position register */\r
109 #pragma NO_FRAME\r
110 #pragma NO_EXIT\r
111 void _EntryPoint(void)\r
112 {\r
113   /*** ### MC9S12DP256_112 "Cpu" init code ... ***/\r
114   /*** PE initialization code after reset ***/\r
115   /* Initialization of the registers INITRG, INITRM, INITEE is done to protect them to be written accidentally later by the application */\r
116   *(byte*)INITRG_ADR = 0;              /* Set the register map position */\r
117   asm nop;                             /* nop instruction */\r
118   INITRM=1;                            /* Set the RAM map position */\r
119   INITEE=1;                            /* Set the EEPROM map position */\r
120   /* MISC: ??=0,??=0,??=0,??=0,EXSTR1=0,EXSTR0=0,ROMHM=0,ROMON=1 */\r
121   MISC=1;\r
122   /* System clock initialization */\r
123   CLKSEL=0;\r
124   CLKSEL_PLLSEL = 0;                   /* Select clock source from XTAL */\r
125   PLLCTL_PLLON = 0;                    /* Disable the PLL */\r
126   SYNR = 24;                           /* Set the multiplier register */\r
127   REFDV = 15;                          /* Set the divider register */\r
128   PLLCTL = 192;\r
129   PLLCTL_PLLON = 1;                    /* Enable the PLL */\r
130   while(!CRGFLG_LOCK);                 /* Wait */\r
131   CLKSEL_PLLSEL = 1;                   /* Select clock source from PLL */\r
132   /*** End of PE initialization code after reset ***/\r
133 \r
134   __asm   jmp _Startup;                /* Jump to C startup code */\r
135 }\r
136 \r
137 /*\r
138 ** ===================================================================\r
139 **     Method      :  PE_low_level_init (bean MC9S12DP256_112)\r
140 **\r
141 **     Description :\r
142 **         This method is internal. It is used by Processor Expert\r
143 **         only.\r
144 ** ===================================================================\r
145 */\r
146 void PE_low_level_init(void)\r
147 {\r
148   /* Common initialization of the CPU registers */\r
149 /* TSCR1: TEN=0,TSWAI=0,TSFRZ=1 */\r
150   output( TSCR1, input( TSCR1 ) & ~192 | 32 );\r
151 /* TCTL2: OM0=0,OL0=0 */\r
152   output( TCTL2, input( TCTL2 ) & ~3 );\r
153 /* TCTL1: OM7=0,OL7=0 */\r
154   output( TCTL1, input( TCTL1 ) & ~192 );\r
155 /* TIE: C0I=0 */\r
156   output( TIE, input( TIE ) & ~1 );\r
157 /* TTOV: TOV0=0 */\r
158   output( TTOV, input( TTOV ) & ~1 );\r
159 /* TSCR2: TOI=0,TCRE=1 */\r
160   output( TSCR2, input( TSCR2 ) & ~128 | 8 );\r
161 /* TIOS: IOS7=1,IOS0=1 */\r
162   output( TIOS, input( TIOS ) | 129 );\r
163 /* PWMCTL: PSWAI=0,PFRZ=0 */\r
164   output( PWMCTL, input( PWMCTL ) & ~12 );\r
165 /* PWMSDN: PWMIF=0,PWMIE=0,PWMRSTRT=0,PWMLVL=0,??=0,PWM7IN=0,PWM7INL=0,PWM7ENA=0 */\r
166   output( PWMSDN, 0 );\r
167 /* ICSYS: SH37=0,SH26=0,SH15=0,SH04=0,TFMOD=0,PACMX=0,BUFEN=0,LATQ=0 */\r
168   output( ICSYS, 0 );\r
169 /* MCCTL: MODMC=1 */\r
170   output( MCCTL, input( MCCTL ) | 64 );\r
171   /* ### MC9S12DP256_112 "Cpu" init code ... */\r
172   /* ### TimerInt "TickTimer" init code ... */\r
173   TickTimer_Init();\r
174   /* ### ByteIO "Byte1" init code ... */\r
175   PORTB = 255;                         /* Prepare value for output */\r
176   DDRB = 255;                          /* Set direction to output */\r
177   /* ### Asynchro serial "COM0" init code ... */\r
178   DDRS &= ~1;\r
179   PTS |= 2;\r
180   DDRS |= 2;\r
181   COM0_Init();\r
182  /* Common peripheral initialization - ENABLE */\r
183 /* TSCR1: TEN=1 */\r
184   output( TSCR1, input( TSCR1 ) | 128 );\r
185   INTCR_IRQEN = 0;                     /* Disable the IRQ interrupt. IRQ interrupt is enabled after CPU reset by default. */\r
186   __DI();                              /* Disable interrupts */\r
187 }\r
188 \r
189 /* END Cpu. */\r
190 \r
191 /*\r
192 ** ###################################################################\r
193 **\r
194 **     This file was created by UNIS Processor Expert 03.33 for \r
195 **     the Motorola HCS12 series of microcontrollers.\r
196 **\r
197 ** ###################################################################\r
198 */\r