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.c64p;
38
39 import xdc.rov.ViewInfo;
40
41 import xdc.runtime.Diags;
42 import xdc.runtime.Error;
43 import xdc.runtime.Log;
44
45 /*!
46 * ======== Hwi ========
47 * C64+ Hardware Interrupt Support Module.
48 *
49 * This Hwi module provides C64+ family-specific implementations of the
50 * APIs defined in {@link ti.sysbios.interfaces.IHwi IHwi}.
51 *
52 * Additional C64+ device-specific APIs are also provided.
53 *
54 * An example of creating a Hwi instance:
55 *
56 * @p(code)
57 *
58 * Int intNum;
59 * Hwi_Params params;
60 * Error_Block eb;
61 *
62 * // Initialize the error block
63 * Error_init(&eb);
64 *
65 * // Initialize the Hwi parameters
66 * Hwi_Params_init(¶ms);
67 *
68 * // Set the GEM event id in the params
69 * params.eventId = 78
70 *
71 * // Specify the interrupt vector number
72 * intNum = 8;
73 *
74 * // create the Hwi for the specified interrupt number and params
75 * Hwi_create(intNum, myIsr, ¶ms, &eb);
76 *
77 * @p
78 *
79 * @a(NOTE)
80 * In this Hwi module implementation, the instance config parameter value
81 * {@link #MaskingOption_LOWER} is equivalent to {@link #MaskingOption_SELF}.
82 * Statically configuring a Hwi object's {@link #Params.maskSetting} to
83 * {@link #MaskingOption_LOWER} will result in the generation of a benign
84 * build warning. Dynamic usages of {@link #MaskingOption_LOWER} will be
85 * silently converted to {@link #MaskingOption_SELF}.
86 *
87 * @p(html)
88 * <h3> Calling Context </h3>
89 * <table border="1" cellpadding="3">
90 * <colgroup span="1"></colgroup> <colgroup span="5" align="center"></colgroup>
91 *
92 * <tr><th> Function </th><th> Hwi </th><th> Swi </th><th> Task </th><th> Main </th><th> Startup </th></tr>
93 * <!-- -->
94 * <tr><td> {@link #clearInterrupt} </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td></tr>
95 * <tr><td> {@link #create} </td><td> N </td><td> N </td><td> Y </td><td> Y </td><td> N </td></tr>
96 * <tr><td> {@link #disable} </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td></tr>
97 * <tr><td> {@link #disableIER} </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td><td> N </td></tr>
98 * <tr><td> {@link #disableInterrupt} </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td><td> N </td></tr>
99 * <tr><td> {@link #enable} </td><td> Y </td><td> Y </td><td> Y </td><td> N </td><td> N </td></tr>
100 * <tr><td> {@link #enableIER} </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td><td> N </td></tr>
101 * <tr><td> {@link #enableInterrupt} </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td><td> N </td></tr>
102 * <tr><td> {@link #eventMap} </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td><td> N </td></tr>
103 * <tr><td> {@link #getEventId} </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td><td> N </td></tr>
104 * <tr><td> {@link #getHandle} </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td><td> N </td></tr>
105 * <tr><td> {@link #Params_init} </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td></tr>
106 * <tr><td> {@link #restore} </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td></tr>
107 * <tr><td> {@link #restoreIER} </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td><td> N </td></tr>
108 * <tr><td> {@link #restoreInterrupt} </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td></tr>
109 * <tr><td> {@link #construct} </td><td> N </td><td> N </td><td> Y </td><td> Y </td><td> N </td></tr>
110 * <tr><td> {@link #delete} </td><td> N </td><td> N </td><td> Y </td><td> Y </td><td> N </td></tr>
111 * <tr><td> {@link #destruct} </td><td> N </td><td> N </td><td> Y </td><td> Y </td><td> N </td></tr>
112 * <tr><td> {@link #getHookContext} </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td><td> N </td></tr>
113 * <tr><td> {@link #reconfig} </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td><td> N </td></tr>
114 * <tr><td> {@link #setFunc} </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td><td> N </td></tr>
115 * <tr><td> {@link #setHookContext} </td><td> Y </td><td> Y </td><td> Y </td><td> Y </td><td> N </td></tr>
116 * <tr><td colspan="6"> Definitions: <br />
117 * <ul>
118 * <li> <b>Hwi</b>: API is callable from a Hwi thread. </li>
119 * <li> <b>Swi</b>: API is callable from a Swi thread. </li>
120 * <li> <b>Task</b>: API is callable from a Task thread. </li>
121 * <li> <b>Main</b>: API is callable during any of these phases: </li>
122 * <ul>
123 * <li> In your module startup after this module is started (e.g. Hwi_Module_startupDone() returns TRUE). </li>
124 * <li> During xdc.runtime.Startup.lastFxns. </li>
125 * <li> During main().</li>
126 * <li> During BIOS.startupFxns.</li>
127 * </ul>
128 * <li> <b>Startup</b>: API is callable during any of these phases:</li>
129 * <ul>
130 * <li> During xdc.runtime.Startup.firstFxns.</li>
131 * <li> In your module startup before this module is started (e.g. Hwi_Module_startupDone() returns FALSE).</li>
132 * </ul>
133 * </ul>
134 * </td></tr>
135 *
136 * </table>
137 * @p
138 */
139
140 @Template("./Hwi.xdt")
141 @ModuleStartup
142 @InstanceInitStatic
143
144 module Hwi inherits ti.sysbios.interfaces.IHwi
145 {
146
147
148 /*! C64+ supports 16 interrupts. */
149 const Int NUM_INTERRUPTS = 16;
150
151
152
153 /*! @_nodoc Hwi plug function type definition. */
154 typedef Void (*PlugFuncPtr)(void);
155
156 /*!
157 * ======== BasicView ========
158 * @_nodoc
159 */
160 metaonly struct BasicView {
161 Ptr halHwiHandle;
162 String label;
163 UInt intNum;
164 String fxn;
165 UArg arg;
166 Ptr irp;
167 UInt eventId;
168 String disableMask;
169 String restoreMask;
170 };
171
172 /*!
173 * ======== ModuleView ========
174 * @_nodoc
175 */
176 metaonly struct ModuleView {
177 String options[4];
178 String hwiStackPeak;
179 SizeT hwiStackSize;
180 Ptr hwiStackBase;
181 };
182
183 /*!
184 * ======== rovViewInfo ========
185 * @_nodoc
186 */
187 @Facet
188 metaonly config ViewInfo.Instance rovViewInfo =
189 ViewInfo.create({
190 viewMap: [
191 ['Basic', {type: ViewInfo.INSTANCE, viewInitFxn: 'viewInitBasic', structName: 'BasicView'}],
192 ['Module', {type: ViewInfo.MODULE, viewInitFxn: 'viewInitModule', structName: 'ModuleView'}]
193 ]
194 });
195
196
197
198 /*!
199 * non-dispatched interrupt object.
200 * provided so that XGCONF users can easily plug non-dispatched interrupts
201 */
202 metaonly struct NonDispatchedInterrupt {
203 Int intNum;
204 PlugFuncPtr fxn; /*! "Hwi_plug'd" ISR function. */
205 Bool enableInt;
206 Int eventId;
207 };
208
209 /*!
210 * non-dispatched interrupt array.
211 * provided so that XGCONF users can easily plug non-dispatched interrupts
212 */
213 metaonly config NonDispatchedInterrupt nonDispatchedInterrupts[string];
214
215 /*!
216 * Alternate reset vector address. Default is undefined.
217 *
218 * if initialized by the user then an additional reset vector
219 * is created and placed in the ".resetVector" section.
220 * To place the .resetVector section into a specific memory section,
221 * add the following command to your config script:
222 * @p(code)
223 * Program.sectMap[".resetVector"] = YourMemorySection;
224 * @p
225 */
226 metaonly config Ptr resetVectorAddress;
227
228 /*!
229 * Error raised when Hwi is already defined
230 */
231 config Error.Id E_alreadyDefined = {
232 msg: "E_alreadyDefined: Hwi already defined: intr# %d"
233 };
234
235 /*!
236 * Error raised when Hwi handle referenced in Hwi_delete()
237 * is not found in the Hwi dispatch table
238 */
239 config Error.Id E_handleNotFound = {
240 msg: "E_handleNotFound: Hwi handle not found: 0x%x"
241 };
242
243 /*!
244 * Issued just prior to Hwi function invocation (with interrupts disabled)
245 */
246 config Log.Event LM_begin = {
247 mask: Diags.USER1 | Diags.USER2,
248 msg: "LM_begin: hwi: 0x%x, func: 0x%x, preThread: %d, intNum: %d, irp: 0x%x"
249 };
250
251 /*!
252 * Issued just after return from Hwi function (with interrupts disabled)
253 */
254 config Log.Event LD_end = {
255 mask: Diags.USER2,
256 msg: "LD_end: hwi: 0x%x"
257 };
258
259 /*!
260 * enable Exception module for exception processing.
261 */
262 config Bool enableException = true;
263
264
265
266 /*!
267 * ======== disable ========
268 */
269 @Macro
270 override UInt disable();
271
272 /*!
273 * ======== enable ========
274 */
275 @Macro
276 override UInt enable();
277
278 /*!
279 * ======== restore ========
280 */
281 @Macro
282 override Void restore(UInt key);
283
284 /*!
285 * ======== inUseMeta ========
286 * @_nodoc
287 * Check for Hwi already in use.
288 * For internal SYS/BIOS use only.
289 * Should be called prior to any internal Hwi.create().
290 *
291 * @param(intNum) interrupt number
292 */
293 metaonly Bool inUseMeta(UInt intNum);
294
295 /*!
296 * ======== eventMap ========
297 * Maps a GEM event to interrupt number
298 *
299 * Function maps a GEM event to an interrupt number so that the
300 * event is the interrupt source of the vector.
301 *
302 * @p(code)
303 * // Maps GEM event #65 as the interrupt source of int vector #7
304 * Hwi_eventMap(7, 65);
305 * @p
306 *
307 * @param(intNum) interrupt number
308 * @param(eventId) event ID
309 */
310 Void eventMap(Int intNum, Int eventId);
311
312 /*!
313 * ======== eventMapMeta ========
314 * Maps GEM Event to interrupt number statically
315 *
316 * Function maps a GEM event to an interrupt number so that the
317 * event is the interrupt source of the vector.
318 *
319 * @p(code)
320 * // Maps GEM event #65 as the interrupt source of int vector #7
321 * Hwi.eventMapMeta(7, 65);
322 * @p
323 *
324 * @param(intNum) interrupt number
325 * @param(eventId) event Id
326 */
327 metaonly Void eventMapMeta(Int intNum, Int eventId);
328
329 /*!
330 * ======== plug ========
331 * Plug an interrupt vector with an ISR address.
332 *
333 * Hwi_plug writes an Interrupt Service Fetch Packet (ISFP) into the
334 * Interrupt Service Table (IST), at the address corresponding to intNum
335 * The op-codes written in the ISFP create a branch to the function
336 * entry point specified by fxn:
337 *
338 * @p(code)
339 * stw b0, *SP--[1]
340 * mvk fxn, b0
341 * mvkh fxn, b0
342 * b b0
343 * ldw *++SP[1],b0
344 * nop 4
345 * @p
346 *
347 * Hwi_plug hooks up the specified function as the branch target of a
348 * hardware interrupt (fielded by the CPU) at the vector address
349 * specified in intNum. Hwi_plug does not enable the interrupt.
350 * Use Hwi_enableIER to enable specific interrupts.
351 *
352 * AN ISR PLUGGED WITH THIS API IS NOT SERVICED BY THE INTERRUPT
353 * DISPATCHER. CONSEQUENTLY, IT SHOULD NOT INVOKE ANY SYS/BIOS APIs
354 * (ie Semaphore_post())!!!
355 *
356 * @a(constraints)
357 * o interrupt function MUST NOT INTERACT WITH SYS/BIOS.
358 * (ie do not call Semaphore_post())
359 *
360 * o vecid must be a valid interrupt ID in the range of 0-15.
361 *
362 * @param(intNum) interrupt number
363 * @param(fxn) pointer to ISR function
364 */
365 Void plug(UInt intNum, PlugFuncPtr fxn);
366
367 /*!
368 * ======== plugMeta ========
369 * Statically plug an interrupt vector with an ISR address.
370 *
371 * @param(intNum) interrupt number
372 * @param(fxn) pointer to ISR function
373 */
374 metaonly Void plugMeta(UInt intNum, PlugFuncPtr fxn);
375
376 /*!
377 * ======== getEventId ========
378 * Returns event id associated with interrupt number
379 *
380 * If a bad interrupt number is passed in, it will return -1.
381 *
382 * @param(intNum) interrupt number
383 * @b(returns) event id associated with intNum
384 */
385 Int getEventId(UInt intNum);
386
387 /*!
388 * ======== getHandle ========
389 * Returns Hwi_handle associated with interrupt number
390 *
391 * @param(intNum) interrupt number
392 * @b(returns) handle associated with intNum
393 */
394 Handle getHandle(UInt intNum);
395
396 /*!
397 * ======== disableIER ========
398 * Disable certain maskable interrupts.
399 *
400 * Atomically disables specific interrupts by clearing the bits
401 * specified by mask in the Interrupt Enable Register (IER).
402 *
403 * The IER bits to be cleared should be set to 1 in the mask.
404 *
405 * @param(mask) bitmask of interrupts to disable
406 * @b(returns) previous IER settings bitmask
407 */
408 Bits16 disableIER(Bits16 mask);
409
410 /*!
411 * ======== enableIER ========
412 * Enable certain maskable interrupts.
413 *
414 * Atomically enables specific interrupts by setting the bits
415 * specified by mask in the Interrupt Enable Register (IER).
416 *
417 * The IER bits to be set should be set to 1 in the mask.
418 *
419 * @param(mask) bitmask of interrupts to enable
420 * @b(returns) previous IER settings bitmask
421 */
422 Bits16 enableIER(Bits16 mask);
423
424 /*!
425 * ======== restoreIER ========
426 * Restore maskable interrupts to the state they were in
427 * when either disableIER() or enableIER() was called.
428 *
429 * Atomically writes the given mask to the IER register. Typically used
430 * to restore the IER register to the state returned from a call to
431 * either {@link #disableIER()} or {@link #enableIER()}.
432 *
433 * @param(mask) bitmask of interrupts to restore
434 * @b(returns) previous IER settings bitmask
435 */
436 Bits16 restoreIER(Bits16 mask);
437
438 instance:
439
440 /*!
441 * Dispatcher auto-nesting interrupt disable mask.
442 *
443 * When the dispatcher's auto interrupt nesting support feature
444 * is enabled (see {@link #dispatcherAutoNestingSupport}),
445 * this mask defines which IER bits are disabled prior to invoking
446 * the user's ISR function with GIE = 1.
447 *
448 * disableMask bits set to 1 correspond to IER bits that will be cleared
449 * prior to invoking the ISR.
450 *
451 * The value of this mask is normally auto-calculated based on the
452 * value of the maskSetting. However, manual setting of this
453 * mask is enabled by setting the maskSetting to
454 * {@link #MaskingOption MaskingOption_BITMASK}.
455 *
456 * The default value is derived from the
457 * {@link #MaskingOption MaskingOption_SELF}
458 * maskSetting.
459 */
460 config Bits16 disableMask = 0;
461
462 /*!
463 * Dispatcher auto-nesting interrupt restore mask.
464 *
465 * When the dispatcher's auto interrupt nesting support feature
466 * is enabled (see {@link #dispatcherAutoNestingSupport}),
467 * this mask defines which IER bits are restored to their previous
468 * setting upon return from the user's ISR function.
469 *
470 * restoreMask bits set to 1 correspond to IER bits that will be restored.
471 *
472 * The value of this mask is normally auto-calculated based on the
473 * value of the maskSetting. However, manual setting of this
474 * mask is enabled by setting the maskSetting to
475 * {@link #MaskingOption MaskingOption_BITMASK}.
476 *
477 * The default value is derived from the
478 * {@link #MaskingOption MaskingOption_SELF}
479 * maskSetting.
480 */
481 config Bits16 restoreMask = 0;
482
483 /*!
484 * Interrupt priority. Not supported on this target.
485 */
486 override config Int priority = 0;
487
488 /*!
489 * ======== reconfig ========
490 * Reconfigures a dispatched interrupt.
491 *
492 * This function reconfigures the dispatched interrupt so the
493 * specified function is called with the specified parameters.
494 *
495 * @param(fxn) pointer to ISR function
496 * @param(params) pointer to Hwi parameter structure
497 */
498 Void reconfig(FuncPtr fxn, const Params *params);
499
500 internal:
501
502 503 504 505 506 507
508 config UInt (*swiDisable)();
509 config Void (*swiRestoreHwi)(UInt);
510 config UInt (*taskDisable)();
511 config Void (*taskRestoreHwi)(UInt);
512
513 514 515 516 517 518 519 520
521 Char *getIsrStackAddress();
522
523
524 Void dispatchC(Int intNum);
525
526
527 Void dispatchCore(Int intNum);
528
529
530 Void unPluggedInterrupt();
531
532
533 Void switchAndDispatch(Int intNum);
534
535 536 537
538 Int postInit(Object *hwi, Error.Block *eb);
539
540 /*!
541 * const array to hold all HookSet objects.
542 */
543 config HookSet hooks[length] = [];
544
545 /*! Meta World Only Hwi Configuration Object. */
546 metaonly struct InterruptObj {
547 String name;
548 Bool used;
549 Bool useDispatcher;
550 FuncPtr fxn;
551 PlugFuncPtr pfxn;
552 };
553
554 /*!
555 * Meta-only array of interrupt objects.
556 * This meta-only array of Hwi config objects is initialized
557 * in Hwi.xs:module$meta$init().
558 */
559 metaonly config InterruptObj interrupt[NUM_INTERRUPTS];
560
561 struct Instance_State {
562 Bits16 disableMask;
563 Bits16 restoreMask;
564 UArg arg;
565 FuncPtr fxn;
566 Irp irp;
567 Ptr hookEnv[];
568 };
569
570 struct Module_State {
571 Char intEvents[16];
572 Bits16 ierMask;
573 volatile Int intNum;
574 Char *taskSP;
575
576
577 Char *isrStack;
578 Ptr vectorTableBase;
579 Ptr bss;
580
581 Handle dispatchTable[NUM_INTERRUPTS];
582 };
583 }