]> git.sur5r.net Git - freertos/blob - Demo/HCS12_CodeWarrior_small/CODE/TickTimer.C
Prepare files for export (MicroBlaze project).
[freertos] / Demo / HCS12_CodeWarrior_small / CODE / TickTimer.C
1 /** ###################################################################\r
2 **     THIS BEAN MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.\r
3 **     Filename  : TickTimer.C\r
4 **     Project   : RTOSDemo\r
5 **     Processor : MC9S12C32CFU\r
6 **     Beantype  : TimerInt\r
7 **     Version   : Bean 02.063, Driver 01.05, CPU db: 2.87.276\r
8 **     Compiler  : Metrowerks HC12 C Compiler\r
9 **     Date/Time : 18/06/2005, 17:53\r
10 **     Abstract  :\r
11 **         This bean "TimerInt" implements a periodic interrupt.\r
12 **         When the bean and its events are enabled, the "OnInterrupt"\r
13 **         event is called periodically with the period that you specify.\r
14 **         TimerInt supports also changing the period in runtime.\r
15 **         The source of periodic interrupt can be timer compare or reload \r
16 **         register or timer-overflow interrupt (of free running counter).\r
17 **     Settings  :\r
18 **         Timer name                  : TIM (16-bit)\r
19 **         Compare name                : TC0\r
20 **         Counter shared              : No\r
21 **\r
22 **         High-speed CPU mode\r
23 **             Prescaler               : divide-by-4\r
24 **             Clock                   : 5999000 Hz\r
25 **           Initial period/frequency\r
26 **             Xtal ticks              : 16000\r
27 **             microseconds            : 1000\r
28 **             milliseconds            : 1\r
29 **             seconds (real)          : 0.0010000\r
30 **             Hz                      : 1000\r
31 **             kHz                     : 1\r
32 **\r
33 **         Runtime setting             : period/frequency interval (continual setting)\r
34 **             ticks                   : 16000 to 160000 ticks\r
35 **             microseconds            : 1000 to 10000 microseconds\r
36 **             milliseconds            : 1 to 10 milliseconds\r
37 **             seconds (real)          : 0.0010000 to 0.0100000 seconds\r
38 **             Hz                      : 100 to 1000 Hz\r
39 **\r
40 **         Initialization:\r
41 **              Timer                  : Disabled\r
42 **              Events                 : Enabled\r
43 **\r
44 **         Timer registers\r
45 **              Counter                : TCNT      [68]\r
46 **              Mode                   : TIOS      [64]\r
47 **              Run                    : TSCR1     [70]\r
48 **              Prescaler              : TSCR2     [77]\r
49 **\r
50 **         Compare registers\r
51 **              Compare                : TC0       [80]\r
52 **\r
53 **         Flip-flop registers\r
54 **              Mode                   : TCTL2     [73]\r
55 **     Contents  :\r
56 **         Enable    - byte TickTimer_Enable(void);\r
57 **         SetFreqHz - byte TickTimer_SetFreqHz(word Freq);\r
58 **\r
59 **     (c) Copyright UNIS, spol. s r.o. 1997-2002\r
60 **     UNIS, spol. s r.o.\r
61 **     Jundrovska 33\r
62 **     624 00 Brno\r
63 **     Czech Republic\r
64 **     http      : www.processorexpert.com\r
65 **     mail      : info@processorexpert.com\r
66 ** ###################################################################*/\r
67 \r
68 \r
69 /* MODULE TickTimer. */\r
70 \r
71 #include "Events.h"\r
72 #include "TickTimer.h"\r
73 \r
74 /* Definition of DATA and CODE segments for this bean. User can specify where\r
75    these segments will be located on "Build options" tab of the selected CPU bean. */\r
76 #pragma DATA_SEG TickTimer_DATA        /* Data section for this module. */\r
77 #pragma CODE_SEG TickTimer_CODE        /* Code section for this module. */\r
78 \r
79 static bool EnUser;                    /* Enable/Disable device by user */\r
80 static word CmpHighVal;                /* Compare register value for high speed CPU mode */\r
81 \r
82 \r
83 /*\r
84 ** ===================================================================\r
85 **     Method      :  SetCV (bean TimerInt)\r
86 **\r
87 **     Description :\r
88 **         This method is internal. It is used by Processor Expert\r
89 **         only.\r
90 ** ===================================================================\r
91 */\r
92 static void SetCV(word Val)\r
93 {\r
94   if (Val == 0)                        /* If the given value is zero */\r
95     Val = 65535;                       /* then change it to the maximal one */\r
96   TC0 = Val;                           /* Store given value to the compare register */\r
97   TC7 = Val;                           /* Store given value to the modulo register */\r
98 }\r
99 \r
100 /*\r
101 ** ===================================================================\r
102 **     Method      :  SetPV (bean TimerInt)\r
103 **\r
104 **     Description :\r
105 **         This method is internal. It is used by Processor Expert\r
106 **         only.\r
107 ** ===================================================================\r
108 */\r
109 static void SetPV(byte Val)\r
110 {\r
111   TSCR2_PR = Val;                      /* Store given value to the prescaler */\r
112 }\r
113 \r
114 /*\r
115 ** ===================================================================\r
116 **     Method      :  HWEnDi (bean TimerInt)\r
117 **\r
118 **     Description :\r
119 **         This method is internal. It is used by Processor Expert\r
120 **         only.\r
121 ** ===================================================================\r
122 */\r
123 static void HWEnDi(void)\r
124 {\r
125   if (EnUser) {                        /* Enable device? */\r
126     TFLG1 = 1;                         /* Reset interrupt request flag */\r
127     TIE_C0I = 1;                       /* Enable interrupt */\r
128   }\r
129   else {                               /* Disable device? */\r
130     TIE_C0I = 0;                       /* Disable interrupt */\r
131   }\r
132 }\r
133 \r
134 /*\r
135 ** ===================================================================\r
136 **     Method      :  TickTimer_Enable (bean TimerInt)\r
137 **\r
138 **     Description :\r
139 **         Enable the bean - it starts the timer. Events may be\r
140 **         generated ("DisableEvent"/"EnableEvent").\r
141 **     Parameters  : None\r
142 **     Returns     :\r
143 **         ---             - Error code, possible codes:\r
144 **                           ERR_OK - OK\r
145 **                           ERR_SPEED - This device does not work in\r
146 **                           the active speed mode\r
147 ** ===================================================================\r
148 */\r
149 byte TickTimer_Enable(void)\r
150 {\r
151   if (!EnUser) {                       /* Is the device disabled by user? */\r
152     EnUser = TRUE;                     /* If yes then set the flag "device enabled" */\r
153     HWEnDi();                          /* Enable the device */\r
154   }\r
155   return ERR_OK;                       /* OK */\r
156 }\r
157 \r
158 /*\r
159 ** ===================================================================\r
160 **     Method      :  TickTimer_SetFreqHz (bean TimerInt)\r
161 **\r
162 **     Description :\r
163 **         This method sets the new frequency of the generated\r
164 **         events. The frequency is expressed in Hz as a 16-bit\r
165 **         unsigned integer number.\r
166 **         This method is available only if runtime setting type\r
167 **         'from interval' is selected in the Timing dialog box in\r
168 **         Runtime setting area.\r
169 **     Parameters  :\r
170 **         NAME            - DESCRIPTION\r
171 **         Freq            - Frequency to set [in Hz]\r
172 **                      (100 to 1000 Hz)\r
173 **     Returns     :\r
174 **         ---             - Error code, possible codes:\r
175 **                           ERR_OK - OK\r
176 **                           ERR_SPEED - This device does not work in\r
177 **                           the active speed mode\r
178 **                           ERR_MATH - Overflow during evaluation\r
179 **                           ERR_RANGE - Parameter out of range\r
180 ** ===================================================================\r
181 */\r
182 byte TickTimer_SetFreqHz(word Freq)\r
183 {\r
184   dlong rtval;                         /* Result of two 32-bit numbers division */\r
185   word rtword;                         /* Result of 64-bit number division */\r
186 \r
187   if ((Freq > 1000) || (Freq < 100))   /* Is the given value out of range? */\r
188     return ERR_RANGE;                  /* If yes then error */\r
189   rtval[1] = 1535744000 / (dword)Freq; /* Divide high speed CPU mode coefficient by the given value */\r
190   rtval[0] = 0;                        /* Convert result to the type dlong */\r
191   if (PE_Timer_LngHi1(rtval[0],rtval[1],&rtword)) /* Is the result greater or equal than 65536 ? */\r
192     rtword = 65535;                    /* If yes then use maximal possible value */\r
193   CmpHighVal = rtword;                 /* Store result (compare register value for high speed CPU mode) to the variable CmpHighVal */\r
194   SetCV(CmpHighVal);                   /* Store appropriate value to the compare register according to the selected high speed CPU mode */\r
195   return ERR_OK;                       /* OK */\r
196 }\r
197 \r
198 /*\r
199 ** ===================================================================\r
200 **     Method      :  TickTimer_Init (bean TimerInt)\r
201 **\r
202 **     Description :\r
203 **         This method is internal. It is used by Processor Expert\r
204 **         only.\r
205 ** ===================================================================\r
206 */\r
207 void TickTimer_Init(void)\r
208 {\r
209   CmpHighVal = 5999;                   /* Compare register value for high speed CPU mode */\r
210   EnUser = FALSE;                      /* Disable device */\r
211   SetCV(CmpHighVal);                   /* Store appropriate value to the compare register according to the selected high speed CPU mode */\r
212   SetPV(2);                            /* Set prescaler register according to the selected high speed CPU mode */\r
213   HWEnDi();                            /* Enable/disable device according to status flags */\r
214 }\r
215 \r
216 /*\r
217 ** ===================================================================\r
218 **     Method      :  TickTimer_Interrupt (bean TimerInt)\r
219 **\r
220 **     Description :\r
221 **         This method is internal. It is used by Processor Expert\r
222 **         only.\r
223 ** ===================================================================\r
224 */\r
225 #pragma CODE_SEG __NEAR_SEG NON_BANKED /* Interrupt section for this module. Placement will be in NON_BANKED area. */\r
226 __interrupt void TickTimer_Interrupt(void)\r
227 {\r
228   TFLG1 = 1;                           /* Reset interrupt request flag */\r
229   vTaskTickInterrupt();                /* Invoke user event */\r
230 }\r
231 \r
232 #pragma CODE_SEG TickTimer_CODE        /* Code section for this module. */\r
233 \r
234 /* END TickTimer. */\r
235 \r
236 /*\r
237 ** ###################################################################\r
238 **\r
239 **     This file was created by UNIS Processor Expert 03.33 for \r
240 **     the Motorola HCS12 series of microcontrollers.\r
241 **\r
242 ** ###################################################################\r
243 */\r