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 package ti.sysbios.family.arm.ducati;
38
39 import xdc.rov.ViewInfo;
40
41 import xdc.runtime.Types;
42 import xdc.runtime.Error;
43
44 import ti.sysbios.interfaces.ITimer;
45 import ti.sysbios.family.arm.m3.Hwi;
46
47 /*!
48 * ======== Timer ========
49 * Ducati Cortex M3 Timer Peripherals Manager.
50 *
51 * The timers used in Ducati are the NVIC SysTick timer
52 * and the two CTM timers (0 and 1) that support interrupts.
53 * The CTM timers are shared between the two M3 cores.
54 * Core 0 uses CTM timer 0 and Core 1 uses timer 1.
55 * Each core then supports 2 timers.
56 * Timer 0 is the core's SysTick timer
57 * and Timer 1 is the core's CTM timer.
58 * Both timers are clocked at the CPU clock rate, nominally 200MHz.
59 * Timer 0 (the SysTick timer) has only 24 bits of period resolution
60 * (up to 83ms).
61 * Timer 1 (the CTM timer) supports a full 32 bit period
62 * (up to 21 seconds).
63 *
64 * @p(html)
65 * <h3> Calling Context </h3>
66 * <table border="1" cellpadding="3">
67 * <colgroup span="1"></colgroup> <colgroup span="5" align="center"></colgroup>
68 *
69 * <tr><th> Function </th><th> Hwi </th><th> Swi </th><th> Task </th><th> Main </th><th> Startup </th></tr>
70 * <!-- -->
71 * <tr><td> {@link #getNumTimers} </td><td> - </td><td> - </td><td> - </td><td> - </td><td> - </td></tr>
72 * <tr><td> {@link #getStatus} </td><td> - </td><td> - </td><td> - </td><td> - </td><td> - </td></tr>
73 * <tr><td> {@link #Params_init} </td><td> - </td><td> - </td><td> - </td><td> - </td><td> - </td></tr>
74 * <tr><td> {@link #construct} </td><td> - </td><td> - </td><td> - </td><td> - </td><td> - </td></tr>
75 * <tr><td> {@link #create} </td><td> - </td><td> - </td><td> - </td><td> - </td><td> - </td></tr>
76 * <tr><td> {@link #delete} </td><td> - </td><td> - </td><td> - </td><td> - </td><td> - </td></tr>
77 * <tr><td> {@link #destruct} </td><td> - </td><td> - </td><td> - </td><td> - </td><td> - </td></tr>
78 * <tr><td> {@link #getCount} </td><td> - </td><td> - </td><td> - </td><td> - </td><td> - </td></tr>
79 * <tr><td> {@link #getFreq} </td><td> - </td><td> - </td><td> - </td><td> - </td><td> - </td></tr>
80 * <tr><td> {@link #getPeriod} </td><td> - </td><td> - </td><td> - </td><td> - </td><td> - </td></tr>
81 * <tr><td> {@link #reconfig} </td><td> - </td><td> - </td><td> - </td><td> - </td><td> - </td></tr>
82 * <tr><td> {@link #setPeriod} </td><td> - </td><td> - </td><td> - </td><td> - </td><td> - </td></tr>
83 * <tr><td> {@link #setPeriodMicroSecs} </td><td> - </td><td> - </td><td> - </td><td> - </td><td> - </td></tr>
84 * <tr><td> {@link #start} </td><td> - </td><td> - </td><td> - </td><td> - </td><td> - </td></tr>
85 * <tr><td> {@link #stop} </td><td> - </td><td> - </td><td> - </td><td> - </td><td> - </td></tr>
86 * <tr><td colspan="6"> Definitions: <br />
87 * <ul>
88 * <li> <b>Hwi</b>: API is callable from a Hwi thread. </li>
89 * <li> <b>Swi</b>: API is callable from a Swi thread. </li>
90 * <li> <b>Task</b>: API is callable from a Task thread. </li>
91 * <li> <b>Main</b>: API is callable during any of these phases: </li>
92 * <ul>
93 * <li> In your module startup after this module is started (e.g. Cache_Module_startupDone() returns TRUE). </li>
94 * <li> During xdc.runtime.Startup.lastFxns. </li>
95 * <li> During main().</li>
96 * <li> During BIOS.startupFxns.</li>
97 * </ul>
98 * <li> <b>Startup</b>: API is callable during any of these phases:</li>
99 * <ul>
100 * <li> During xdc.runtime.Startup.firstFxns.</li>
101 * <li> In your module startup before this module is started (e.g. Cache_Module_startupDone() returns FALSE).</li>
102 * </ul>
103 * </ul>
104 * </td></tr>
105 *
106 * </table>
107 * @p
108 */
109 @InstanceFinalize
110 @InstanceInitError
111 @ModuleStartup
112
113 module Timer inherits ti.sysbios.interfaces.ITimer
114 {
115 /*! Max value of Timer period for PeriodType_COUNTS*/
116 const UInt MAX_PERIOD = 0xffffffff;
117
118 /*!
119 * Number of timer peripherals on chip
120 *
121 * Only 2 are available to each core.
122 */
123 const Int NUM_TIMER_DEVICES = 2;
124
125 /*! Timer clock divider wrt cpu clock */
126 const Int TIMER_CLOCK_DIVIDER = 1;
127
128 /*! @_nodoc
129 * Min instructions to use in trigger().
130 */
131 const Int MIN_SWEEP_PERIOD = 1;
132
133 /*! @_nodoc */
134 @XmlDtd
135 metaonly struct BasicView {
136 Ptr halTimerHandle;
137 String label;
138 UInt id;
139 String device;
140 String startMode;
141 String runMode;
142 UInt period;
143 String periodType;
144 UInt intNum;
145 String tickFxn[];
146 UArg arg;
147 String extFreq;
148 String hwiHandle;
149 };
150
151
152 /*! @_nodoc */
153 metaonly struct ModuleView {
154 String availMask;
155 }
156
157 /*! @_nodoc */
158 metaonly struct DeviceView {
159 UInt id;
160 String device;
161 String devAddr;
162 UInt intNum;
163 String runMode;
164 UInt period;
165 UInt currCount;
166 UInt remainingCount;
167 };
168
169 /*! @_nodoc */
170 @Facet
171 metaonly config ViewInfo.Instance rovViewInfo =
172 ViewInfo.create({
173 viewMap: [
174 [
175 'Basic',
176 {
177 type: ViewInfo.INSTANCE,
178 viewInitFxn: 'viewInitBasic',
179 structName: 'BasicView'
180 }
181 ],
182 [
183 'Device',
184 {
185 type: ViewInfo.INSTANCE,
186 viewInitFxn: 'viewInitDevice',
187 structName: 'DeviceView'
188 }
189 ],
190 [
191 'Module',
192 {
193 type: ViewInfo.MODULE,
194 viewInitFxn: 'viewInitModule',
195 structName: 'ModuleView'
196 }
197 ],
198 ]
199 });
200
201 /*!
202 * Error raised when timer id specified is not supported.
203 */
204 config Error.Id E_invalidTimer = {msg: "E_invalidTimer: Invalid Timer Id %d"};
205
206 /*!
207 * Error raised when timer requested is in use
208 */
209 config Error.Id E_notAvailable =
210 {msg: "E_notAvailable: Timer not available %d"};
211
212 /*!
213 * Error raised when period requested is not supported
214 */
215 config Error.Id E_cannotSupport =
216 {msg: "E_cannotSupport: Timer cannot support requested period %d"};
217
218 /*!
219 * ======== anyMask ========
220 * Available mask to be used when select = Timer_ANY
221 */
222 config UInt anyMask = 0x3;
223
224 /*!
225 * ======== getHandle ========
226 * Get Handle associated with a timer id.
227 *
228 * @param(id) timer Id.
229 * @b(returns) timer Handle
230 */
231 @DirectCall
232 Handle getHandle(UInt id);
233
234 /*!
235 * ======== oneShotStub ========
236 * @_nodoc
237 * SysTick timer does not support one shot mode. This stub stops timer
238 * and clears the pending timer interrupt.
239 *
240 * @param(arg) Timer object.
241 */
242 @DirectCall
243 Void oneShotStub(UArg arg);
244
245 /*!
246 * ======== periodicStub ========
247 * @_nodoc
248 * SysTick timer interrupt must be acknowledged. This stub acknowledges timer
249 *
250 * @param(arg) Timer object.
251 */
252 @DirectCall
253 Void periodicStub(UArg arg);
254
255 instance:
256
257 /*! Hwi Params for Hwi Object. Default is null. */
258 config Hwi.Params *hwiParams = null;
259
260 /*!
261 * ======== reconfig ========
262 * Used to modify static timer instances at runtime.
263 *
264 * @param(timerParams) timer Params
265 * @param(tickFxn) function that runs when timer expires
266 */
267 @DirectCall
268 Void reconfig(FuncPtr tickFxn, const Params *timerParams, Error.Block *eb);
269
270
271 internal:
272
273 /*!
274 * ======== noStartupNeeded ========
275 * Flag used to prevent misc code from being brought in
276 * un-necessarily
277 */
278 config UInt startupNeeded = false;
279
280 281 282 283
284 Void initDevice(Object *timer);
285
286 287 288 289
290 Int postInit(Object *timer, Error.Block *eb);
291
292 struct Instance_State {
293 Bool staticInst;
294 Int id;
295 Int ctmid;
296 RunMode runMode;
297 StartMode startMode;
298 UInt period;
299 PeriodType periodType;
300 UInt intNum;
301 UArg arg;
302 Hwi.FuncPtr tickFxn;
303 Types.FreqHz extFreq;
304 Hwi.Handle hwi;
305 }
306
307 struct Module_State {
308 UInt availMask;
309 Handle handles[NUM_TIMER_DEVICES];
310
311 }
312 }
313