OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [HCS12_CodeWarrior_banked/] [CODE/] [TickTimer.C] - Blame information for rev 607

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 588 jeremybenn
/** ###################################################################
2
**     THIS BEAN MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
3
**     Filename  : TickTimer.C
4
**     Project   : RTOSDemo
5
**     Processor : MC9S12DP256BCPV
6
**     Beantype  : TimerInt
7
**     Version   : Bean 02.063, Driver 01.05, CPU db: 2.87.283
8
**     Compiler  : Metrowerks HC12 C Compiler
9
**     Date/Time : 18/06/2005, 16:21
10
**     Abstract  :
11
**         This bean "TimerInt" implements a periodic interrupt.
12
**         When the bean and its events are enabled, the "OnInterrupt"
13
**         event is called periodically with the period that you specify.
14
**         TimerInt supports also changing the period in runtime.
15
**         The source of periodic interrupt can be timer compare or reload
16
**         register or timer-overflow interrupt (of free running counter).
17
**     Settings  :
18
**         Timer name                  : ECT (16-bit)
19
**         Compare name                : TC0
20
**         Counter shared              : No
21
**
22
**         High-speed CPU mode
23
**             Prescaler               : divide-by-8
24
**             Clock                   : 3124000 Hz
25
**           Initial period/frequency
26
**             Xtal ticks              : 16000
27
**             microseconds            : 1000
28
**             milliseconds            : 1
29
**             seconds (real)          : 0.0010000
30
**             Hz                      : 1000
31
**             kHz                     : 1
32
**
33
**         Runtime setting             : period/frequency interval (continual setting)
34
**             ticks                   : 16000 to 320000 ticks
35
**             microseconds            : 1000 to 20000 microseconds
36
**             milliseconds            : 1 to 20 milliseconds
37
**             seconds (real)          : 0.0010000 to 0.0200000 seconds
38
**             Hz                      : 50 to 1000 Hz
39
**
40
**         Initialization:
41
**              Timer                  : Enabled
42
**              Events                 : Enabled
43
**
44
**         Timer registers
45
**              Counter                : TCNT      [68]
46
**              Mode                   : TIOS      [64]
47
**              Run                    : TSCR1     [70]
48
**              Prescaler              : TSCR2     [77]
49
**
50
**         Compare registers
51
**              Compare                : TC0       [80]
52
**
53
**         Flip-flop registers
54
**              Mode                   : TCTL2     [73]
55
**     Contents  :
56
**         Enable           - byte TickTimer_Enable(void);
57
**         SetPeriodTicks16 - byte TickTimer_SetPeriodTicks16(word Ticks);
58
**         SetPeriodTicks32 - byte TickTimer_SetPeriodTicks32(dword Ticks);
59
**         SetPeriodUS      - byte TickTimer_SetPeriodUS(word Time);
60
**         SetPeriodMS      - byte TickTimer_SetPeriodMS(word Time);
61
**         SetFreqHz        - byte TickTimer_SetFreqHz(word Freq);
62
**
63
**     (c) Copyright UNIS, spol. s r.o. 1997-2002
64
**     UNIS, spol. s r.o.
65
**     Jundrovska 33
66
**     624 00 Brno
67
**     Czech Republic
68
**     http      : www.processorexpert.com
69
**     mail      : info@processorexpert.com
70
** ###################################################################*/
71
 
72
 
73
/* MODULE TickTimer. */
74
 
75
#include "Events.h"
76
#include "TickTimer.h"
77
 
78
/* Definition of DATA and CODE segments for this bean. User can specify where
79
   these segments will be located on "Build options" tab of the selected CPU bean. */
80
#pragma DATA_SEG TickTimer_DATA        /* Data section for this module. */
81
#pragma CODE_SEG TickTimer_CODE        /* Code section for this module. */
82
 
83
static word CmpHighVal;                /* Compare register value for high speed CPU mode */
84
 
85
 
86
/*
87
** ===================================================================
88
**     Method      :  SetCV (bean TimerInt)
89
**
90
**     Description :
91
**         This method is internal. It is used by Processor Expert
92
**         only.
93
** ===================================================================
94
*/
95
static void SetCV(word Val)
96
{
97
  if (Val == 0)                        /* If the given value is zero */
98
    Val = 65535;                       /* then change it to the maximal one */
99
  TC0 = Val;                           /* Store given value to the compare register */
100
  TC7 = Val;                           /* Store given value to the modulo register */
101
}
102
 
103
/*
104
** ===================================================================
105
**     Method      :  SetPV (bean TimerInt)
106
**
107
**     Description :
108
**         This method is internal. It is used by Processor Expert
109
**         only.
110
** ===================================================================
111
*/
112
static void SetPV(byte Val)
113
{
114
  TSCR2_PR = Val;                      /* Store given value to the prescaler */
115
}
116
 
117
/*
118
** ===================================================================
119
**     Method      :  HWEnDi (bean TimerInt)
120
**
121
**     Description :
122
**         This method is internal. It is used by Processor Expert
123
**         only.
124
** ===================================================================
125
*/
126
static void HWEnDi(void)
127
{
128
    TFLG1 = 1;                         /* Reset interrupt request flag */
129
    TIE_C0I = 1;                       /* Enable interrupt */
130
}
131
 
132
/*
133
** ===================================================================
134
**     Method      :  TickTimer_Enable (bean TimerInt)
135
**
136
**     Description :
137
**         Enable the bean - it starts the timer. Events may be
138
**         generated ("DisableEvent"/"EnableEvent").
139
**     Parameters  : None
140
**     Returns     :
141
**         ---             - Error code, possible codes:
142
**                           ERR_OK - OK
143
**                           ERR_SPEED - This device does not work in
144
**                           the active speed mode
145
** ===================================================================
146
*/
147
byte TickTimer_Enable(void)
148
{
149
  HWEnDi();                            /* Enable the device */
150
  return ERR_OK;                       /* OK */
151
}
152
 
153
/*
154
** ===================================================================
155
**     Method      :  TickTimer_SetPeriodTicks16 (bean TimerInt)
156
**
157
**     Description :
158
**         This method sets the new period of the generated events.
159
**         The period is expressed in Xtal ticks as a 16-bit unsigned
160
**         integer number.
161
**         This method is available only if runtime setting type
162
**         'from interval' is selected in the Timing dialog box in
163
**         Runtime setting area.
164
**     Parameters  :
165
**         NAME            - DESCRIPTION
166
**         Ticks           - Period to set [in Xtal ticks]
167
**                      (16000 to 65535 ticks)
168
**     Returns     :
169
**         ---             - Error code, possible codes:
170
**                           ERR_OK - OK
171
**                           ERR_SPEED - This device does not work in
172
**                           the active speed mode
173
**                           ERR_MATH - Overflow during evaluation
174
**                           ERR_RANGE - Parameter out of range
175
** ===================================================================
176
*/
177
byte TickTimer_SetPeriodTicks16(word Ticks)
178
{
179
  dlong rtval;                         /* Result of two 32-bit numbers multiplication */
180
  word rtword;                         /* Result of 64-bit number division */
181
 
182
  if (Ticks < 16000)                   /* Is the given value out of range? */
183
    return ERR_RANGE;                  /* If yes then error */
184
  PE_Timer_LngMul((dword)Ticks,838592365,&rtval); /* Multiply given value and high speed CPU mode coefficient */
185
  if (PE_Timer_LngHi4(rtval[0],rtval[1],&rtword)) /* Is the result greater or equal than 65536 ? */
186
    rtword = 65535;                    /* If yes then use maximal possible value */
187
  CmpHighVal = rtword;                 /* Store result (compare register value for high speed CPU mode) to the variable CmpHighVal */
188
  SetCV(CmpHighVal);                   /* Store appropriate value to the compare register according to the selected high speed CPU mode */
189
  return ERR_OK;                       /* OK */
190
}
191
 
192
/*
193
** ===================================================================
194
**     Method      :  TickTimer_SetPeriodTicks32 (bean TimerInt)
195
**
196
**     Description :
197
**         This method sets the new period of the generated events.
198
**         The period is expressed in Xtal ticks as a 32-bit unsigned
199
**         integer number.
200
**         This method is available only if runtime setting type
201
**         'from interval' is selected in the Timing dialog box in
202
**         Runtime setting area.
203
**     Parameters  :
204
**         NAME            - DESCRIPTION
205
**         Ticks           - Period to set [in Xtal ticks]
206
**                      (16000 to 320000 ticks)
207
**     Returns     :
208
**         ---             - Error code, possible codes:
209
**                           ERR_OK - OK
210
**                           ERR_SPEED - This device does not work in
211
**                           the active speed mode
212
**                           ERR_MATH - Overflow during evaluation
213
**                           ERR_RANGE - Parameter out of range
214
** ===================================================================
215
*/
216
byte TickTimer_SetPeriodTicks32(dword Ticks)
217
{
218
  dlong rtval;                         /* Result of two 32-bit numbers multiplication */
219
  word rtword;                         /* Result of 64-bit number division */
220
 
221
  if ((Ticks > 320000) || (Ticks < 16000)) /* Is the given value out of range? */
222
    return ERR_RANGE;                  /* Range error */
223
  PE_Timer_LngMul(Ticks,838592365,&rtval); /* Multiply given value and high speed CPU mode coefficient */
224
  if (PE_Timer_LngHi4(rtval[0],rtval[1],&rtword)) /* Is the result greater or equal than 65536 ? */
225
    rtword = 65535;                    /* If yes then use maximal possible value */
226
  CmpHighVal = rtword;                 /* Store result (compare register value for high speed CPU mode) to the variable CmpHighVal */
227
  SetCV(CmpHighVal);                   /* Store appropriate value to the compare register according to the selected high speed CPU mode */
228
  return ERR_OK;                       /* OK */
229
}
230
 
231
/*
232
** ===================================================================
233
**     Method      :  TickTimer_SetPeriodUS (bean TimerInt)
234
**
235
**     Description :
236
**         This method sets the new period of the generated events.
237
**         The period is expressed in microseconds as a 16-bit
238
**         unsigned integer number.
239
**         This method is available only if runtime setting type
240
**         'from interval' is selected in the Timing dialog box in
241
**         Runtime setting area.
242
**     Parameters  :
243
**         NAME            - DESCRIPTION
244
**         Time            - Period to set [in microseconds]
245
**                      (1000 to 20000 microseconds)
246
**     Returns     :
247
**         ---             - Error code, possible codes:
248
**                           ERR_OK - OK
249
**                           ERR_SPEED - This device does not work in
250
**                           the active speed mode
251
**                           ERR_MATH - Overflow during evaluation
252
**                           ERR_RANGE - Parameter out of range
253
** ===================================================================
254
*/
255
byte TickTimer_SetPeriodUS(word Time)
256
{
257
  dlong rtval;                         /* Result of two 32-bit numbers multiplication */
258
  word rtword;                         /* Result of 64-bit number division */
259
 
260
  if ((Time > 20000) || (Time < 1000)) /* Is the given value out of range? */
261
    return ERR_RANGE;                  /* If yes then error */
262
  PE_Timer_LngMul((dword)Time,52412023,&rtval); /* Multiply given value and high speed CPU mode coefficient */
263
  if (PE_Timer_LngHi3(rtval[0],rtval[1],&rtword)) /* Is the result greater or equal than 65536 ? */
264
    rtword = 65535;                    /* If yes then use maximal possible value */
265
  CmpHighVal = rtword;                 /* Store result (compare register value for high speed CPU mode) to the variable CmpHighVal */
266
  SetCV(CmpHighVal);                   /* Store appropriate value to the compare register according to the selected high speed CPU mode */
267
  return ERR_OK;                       /* OK */
268
}
269
 
270
/*
271
** ===================================================================
272
**     Method      :  TickTimer_SetPeriodMS (bean TimerInt)
273
**
274
**     Description :
275
**         This method sets the new period of the generated events.
276
**         The period is expressed in miliseconds as a 16-bit
277
**         unsigned integer number.
278
**         This method is available only if runtime setting type
279
**         'from interval' is selected in the Timing dialog box in
280
**         Runtime setting area.
281
**     Parameters  :
282
**         NAME            - DESCRIPTION
283
**         Time            - Period to set [in miliseconds]
284
**                      (1 to 20 milliseconds)
285
**     Returns     :
286
**         ---             - Error code, possible codes:
287
**                           ERR_OK - OK
288
**                           ERR_SPEED - This device does not work in
289
**                           the active speed mode
290
**                           ERR_MATH - Overflow during evaluation
291
**                           ERR_RANGE - Parameter out of range
292
** ===================================================================
293
*/
294
byte TickTimer_SetPeriodMS(word Time)
295
{
296
  dlong rtval;                         /* Result of two 32-bit numbers multiplication */
297
  word rtword;                         /* Result of 64-bit number division */
298
 
299
  if ((Time > 20) || (Time < 1))       /* Is the given value out of range? */
300
    return ERR_RANGE;                  /* If yes then error */
301
  PE_Timer_LngMul((dword)Time,204734464,&rtval); /* Multiply given value and high speed CPU mode coefficient */
302
  if (PE_Timer_LngHi2(rtval[0],rtval[1],&rtword)) /* Is the result greater or equal than 65536 ? */
303
    rtword = 65535;                    /* If yes then use maximal possible value */
304
  CmpHighVal = rtword;                 /* Store result (compare register value for high speed CPU mode) to the variable CmpHighVal */
305
  SetCV(CmpHighVal);                   /* Store appropriate value to the compare register according to the selected high speed CPU mode */
306
  return ERR_OK;                       /* OK */
307
}
308
 
309
/*
310
** ===================================================================
311
**     Method      :  TickTimer_SetFreqHz (bean TimerInt)
312
**
313
**     Description :
314
**         This method sets the new frequency of the generated
315
**         events. The frequency is expressed in Hz as a 16-bit
316
**         unsigned integer number.
317
**         This method is available only if runtime setting type
318
**         'from interval' is selected in the Timing dialog box in
319
**         Runtime setting area.
320
**     Parameters  :
321
**         NAME            - DESCRIPTION
322
**         Freq            - Frequency to set [in Hz]
323
**                      (50 to 1000 Hz)
324
**     Returns     :
325
**         ---             - Error code, possible codes:
326
**                           ERR_OK - OK
327
**                           ERR_SPEED - This device does not work in
328
**                           the active speed mode
329
**                           ERR_MATH - Overflow during evaluation
330
**                           ERR_RANGE - Parameter out of range
331
** ===================================================================
332
*/
333
byte TickTimer_SetFreqHz(word Freq)
334
{
335
  dlong rtval;                         /* Result of two 32-bit numbers division */
336
  word rtword;                         /* Result of 64-bit number division */
337
 
338
  if ((Freq > 1000) || (Freq < 50))    /* Is the given value out of range? */
339
    return ERR_RANGE;                  /* If yes then error */
340
  rtval[1] = 799744000 / (dword)Freq;  /* Divide high speed CPU mode coefficient by the given value */
341
  rtval[0] = 0;                        /* Convert result to the type dlong */
342
  if (PE_Timer_LngHi1(rtval[0],rtval[1],&rtword)) /* Is the result greater or equal than 65536 ? */
343
    rtword = 65535;                    /* If yes then use maximal possible value */
344
  CmpHighVal = rtword;                 /* Store result (compare register value for high speed CPU mode) to the variable CmpHighVal */
345
  SetCV(CmpHighVal);                   /* Store appropriate value to the compare register according to the selected high speed CPU mode */
346
  return ERR_OK;                       /* OK */
347
}
348
 
349
/*
350
** ===================================================================
351
**     Method      :  TickTimer_Init (bean TimerInt)
352
**
353
**     Description :
354
**         This method is internal. It is used by Processor Expert
355
**         only.
356
** ===================================================================
357
*/
358
void TickTimer_Init(void)
359
{
360
  CmpHighVal = 3124;                   /* Compare register value for high speed CPU mode */
361
  SetCV(CmpHighVal);                   /* Store appropriate value to the compare register according to the selected high speed CPU mode */
362
  SetPV(3);                            /* Set prescaler register according to the selected high speed CPU mode */
363
  HWEnDi();                            /* Enable/disable device according to status flags */
364
}
365
 
366
/*
367
** ===================================================================
368
**     Method      :  TickTimer_Interrupt (bean TimerInt)
369
**
370
**     Description :
371
**         This method is internal. It is used by Processor Expert
372
**         only.
373
** ===================================================================
374
*/
375
#pragma CODE_SEG __NEAR_SEG NON_BANKED /* Interrupt section for this module. Placement will be in NON_BANKED area. */
376
__interrupt void TickTimer_Interrupt(void)
377
{
378
  TFLG1 = 1;                           /* Reset interrupt request flag */
379
  TickTimer_OnInterrupt();             /* Invoke user event */
380
}
381
 
382
#pragma CODE_SEG TickTimer_CODE        /* Code section for this module. */
383
 
384
/* END TickTimer. */
385
 
386
/*
387
** ###################################################################
388
**
389
**     This file was created by UNIS Processor Expert 03.33 for
390
**     the Motorola HCS12 series of microcontrollers.
391
**
392
** ###################################################################
393
*/

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.