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

Subversion Repositories openrisc

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

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

powered by: WebSVN 2.1.0

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