1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
32 33 34 35 36
37
38 package ti.sysbios.family.arm.tms570;
39
40 import xdc.rov.ViewInfo;
41
42 import xdc.runtime.Error;
43 import xdc.runtime.Types;
44 import ti.sysbios.interfaces.ITimer;
45 /*!
46 * ======== Timer ========
47 * Timer Peripherals Manager for arm_tms570 family.
48 *
49 * @p(html)
50 * <h3> Calling Context </h3>
51 * <table border="1" cellpadding="3">
52 * <colgroup span="1"></colgroup> <colgroup span="5" align="center"></colgroup>
53 *
54 * <tr><th> Function </th><th> Hwi </th><th> Swi </th><th> Task </th><th> Main </th><th> Startup </th></tr>
55 * <!-- -->
56 * <tr><td> {@link #getNumTimers} </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td><td> N </td></tr>
57 * <tr><td> {@link #getStatus} </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td><td> N </td></tr>
58 * <tr><td> {@link #Params_init} </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td><td> N </td></tr>
59 * <tr><td> {@link #construct} </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td><td> N </td></tr>
60 * <tr><td> {@link #create} </td><td> N </td><td> N </td><td> Y </td><td> Y </td><td> N </td></tr>
61 * <tr><td> {@link #delete} </td><td> N </td><td> N </td><td> Y </td><td> Y </td><td> N </td></tr>
62 * <tr><td> {@link #destruct} </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td><td> N </td></tr>
63 * <tr><td> {@link #getCount} </td><td> Y </td><td> Y </td><td> Y </td><td> N </td><td> N </td></tr>
64 * <tr><td> {@link #getFreq} </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td><td> N </td></tr>
65 * <tr><td> {@link #getPeriod} </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td><td> N </td></tr>
66 * <tr><td> {@link #reconfig} </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td><td> N </td></tr>
67 * <tr><td> {@link #setPeriod} </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td><td> N </td></tr>
68 * <tr><td> {@link #setPeriodMicroSecs} </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td><td> N </td></tr>
69 * <tr><td> {@link #start} </td><td> Y </td><td> Y </td><td> Y </td><td> N </td><td> N </td></tr>
70 * <tr><td> {@link #stop} </td><td> Y </td><td> Y </td><td> Y </td><td> N </td><td> N </td></tr>
71 * <tr><td colspan="6"> Definitions: <br />
72 * <ul>
73 * <li> <b>Hwi</b>: API is callable from a Hwi thread. </li>
74 * <li> <b>Swi</b>: API is callable from a Swi thread. </li>
75 * <li> <b>Task</b>: API is callable from a Task thread. </li>
76 * <li> <b>Main</b>: API is callable during any of these phases: </li>
77 * <ul>
78 * <li> In your module startup after this module is started (e.g. Timer_Module_startupDone() returns TRUE). </li>
79 * <li> During xdc.runtime.Startup.lastFxns. </li>
80 * <li> During main().</li>
81 * <li> During BIOS.startupFxns.</li>
82 * </ul>
83 * <li> <b>Startup</b>: API is callable during any of these phases:</li>
84 * <ul>
85 * <li> During xdc.runtime.Startup.firstFxns.</li>
86 * <li> In your module startup before this module is started (e.g. Timer_Module_startupDone() returns FALSE).</li>
87 * </ul>
88 * </ul>
89 * </td></tr>
90 *
91 * </table>
92 * @p
93 *
94 */
95 @InstanceFinalize
96 @InstanceInitError
97 @ModuleStartup
98
99 module Timer inherits ti.sysbios.interfaces.ITimer
100 {
101 /*! Max value of Timer period for PeriodType_COUNTS*/
102 const UInt MAX_PERIOD = 0xffffffff;
103
104 /*! Number of timer peripherals on chip */
105 const Int NUM_TIMER_DEVICES = 2;
106
107 /*! @_nodoc
108 * Min instructions to use in trigger().
109 */
110 const Int MIN_SWEEP_PERIOD = 8;
111
112 /*! Timer Configuration struct.
113 *
114 * @field(cos) When true timer stops counting during emulation halt.
115 * When false timer continues to count during emulation
116 * halt.
117 */
118 struct Control {
119 Bool cos; /*! 0=stop in debug mode; 1=continue in debug mode */
120 };
121
122 /*! @_nodoc */
123 @XmlDtd
124 metaonly struct BasicView {
125 Ptr halTimerHandle;
126 String label;
127 UInt id;
128 String startMode;
129 String runMode;
130 UInt period;
131 String periodType;
132 UInt intNum;
133 String tickFxn[];
134 UArg arg;
135 String extFreq;
136 UInt32 accuTicks;
137 String hwiHandle;
138 };
139
140 /*! @_nodoc */
141 metaonly struct DeviceView {
142 UInt id;
143 String device;
144 String devAddr;
145 UInt intNum;
146 String runMode;
147 UInt period;
148 UInt currCount;
149 UInt remainingCount;
150 String state;
151 };
152
153 /*! @_nodoc */
154 metaonly struct ModuleView {
155 String availMask;
156 }
157
158 /*! @_nodoc */
159 @Facet
160 metaonly config ViewInfo.Instance rovViewInfo =
161 ViewInfo.create({
162 viewMap: [
163 [
164 'Basic',
165 {
166 type: ViewInfo.INSTANCE,
167 viewInitFxn: 'viewInitBasic',
168 structName: 'BasicView'
169 }
170 ],
171 [
172 'Device',
173 {
174 type: ViewInfo.INSTANCE,
175 viewInitFxn: 'viewInitDevice',
176 structName: 'DeviceView'
177 }
178 ],
179 [
180 'Module',
181 {
182 type: ViewInfo.MODULE,
183 viewInitFxn: 'viewInitModule',
184 structName: 'ModuleView'
185 }
186 ],
187 ]
188 });
189
190 /*!
191 * Error raised when timer id specified is not supported.
192 */
193 config Error.Id E_invalidTimer = {msg: "E_invalidTimer: Invalid Timer Id %d"};
194
195 /*!
196 * Error raised when timer requested is in use
197 */
198 config Error.Id E_notAvailable =
199 {msg: "E_notAvailable: Timer not available %d"};
200
201 /*!
202 * Error raised when Hwi Params has mask where self is turned on.
203 *
204 * This is not allowed because the timers on this platform do not
205 * support one-shot mode and a stub is used to stop it.
206 * Another timer interrupt cannot go off when the ISR is running.
207 */
208 config Error.Id E_invalidHwiMask =
209 {msg: "E_InvalidMask: Mask in hwiParams cannot enable self"};
210
211 /*!
212 * Error raised when period requested is not supported
213 */
214 config Error.Id E_cannotSupport =
215 {msg: "E_cannotSupport: Timer cannot support requested period %d"};
216
217 /*!
218 * ======== anyMask ========
219 * Available mask to be used when select = Timer_ANY
220 */
221 config UInt anyMask = 0x3;
222
223 /*!
224 * ======== oneShotStub ========
225 * @_nodoc
226 * RTI timer does not support one shot mode. This stub stops timer
227 * and disables its interrupt.
228 *
229 * @param(arg) Timer Handle.
230 */
231 Void oneShotStub(UArg arg);
232
233 /*!
234 * ======== periodicStub ========
235 * @_nodoc
236 * When accuTicks = true, this stub does the tick accumulation.
237 *
238 * @param(arg) Timer Handle.
239 */
240 Void periodicStub(UArg arg);
241
242 /*!
243 * ======== getHandle ========
244 * @_nodoc
245 * Used by TimestampProvider module to get hold of timer handle used by
246 * Clock.
247 *
248 * @param(id) timer Id.
249 */
250 Handle getHandle(UInt id);
251
252 instance:
253
254
255 /*! Control register configuration. Default cos=0. */
256 config Control controlRegInit = {cos: 0};
257
258 /*! Hwi Params for Hwi Object. Default is null.*/
259 config Hwi.Params *hwiParams = null;
260
261 /*! Hwi intNum to be used by Timer. */
262 config Int intNum = -1;
263
264 /*!
265 * ======== reconfig ========
266 * Used to modify static timer instances at runtime.
267 *
268 * @param(timerParams) timer Params
269 * @param(tickFxn) functions that runs when timer expires.
270 */
271 Void reconfig(FuncPtr tickFxn, const Params *timerParams, Error.Block *eb);
272
273 /*!
274 * ======== getAccuTicks ========
275 * @_nodoc
276 * returns accumulated ticks. Used by TimestampProvider.
277 *
278 * @b(returns) get accumulated ticks
279 */
280 UInt32 getAccuTicks();
281
282 /*!
283 * ======== ackInterrupt ========
284 * clear the current timer interrupt flag
285 */
286 Void ackInterrupt();
287
288 internal:
289
290 /*!
291 * ======== noStartupNeeded ========
292 * Flag used to prevent misc code from being brought in
293 * un-necessarily
294 */
295 config UInt startupNeeded = false;
296
297 struct Instance_State {
298 Bool staticInst;
299 Int id;
300 UInt controlRegInit;
301 ITimer.RunMode runMode;
302 ITimer.StartMode startMode;
303 UInt period;
304 ITimer.PeriodType periodType;
305 UInt intNum;
306 UArg arg;
307 Hwi.FuncPtr tickFxn;
308 Types.FreqHz extFreq;
309 volatile UInt32 accuTicks;
310 Hwi.Handle hwi;
311 }
312
313 struct Module_State {
314 UInt availMask;
315 Handle handles[NUM_TIMER_DEVICES];
316
317 }
318 }
319 320 321 322
323