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 import xdc.runtime.Error;
38
39
40 /*!
41 * ======== Hwi ========
42 * Hardware Interrupt Support Module.
43 *
44 * The IHwi interface specifies APIs for globally enabling, disabling, and
45 * restoring interrupts.
46 *
47 * Additionally, management of individual, device-specific hardware
48 * interrupts is provided.
49 *
50 * The user can statically or dynamically assign routines that run when
51 * specific hardware interrupts occur.
52 *
53 * Dynamic assignment of Hwi routines to interrupts at run-time is done
54 * using the Hwi_create function.
55 *
56 * Interrupt routines can be written completely in C, completely in
57 * assembly, or in a mix of C and assembly. In order to support interrupt
58 * routines
59 * written completely in C, an interrupt dispatcher is provided that performs
60 * the requisite prolog and epilog for an interrupt routine.
61 *
62 * Some routines are assigned to interrupts by the other SYS/BIOS
63 * modules. For example, the Clock module configures its own timer interrupt
64 * handler. See the Clock Module for more details.
65 *
66 * @a(Runtime Hwi Creation)
67 *
68 * Below is an example of configuring an interrupt at runtime.
69 * Usually this code would be placed in main().
70 *
71 * @p(code)
72 * #include <xdc/runtime/Error.h>
73 * #include <ti/sysbios/hal/Hwi.h>
74 *
75 * Hwi_Handle myHwi;
76 *
77 * Int main(Int argc, char* argv[])
78 * {
79 * Hwi_Params hwiParams;
80 * Error_Block eb;
81 *
82 * Hwi_Params_init(&hwiParams);
83 * Error_init(&eb);
84 *
85 * // set the argument you want passed to your ISR function
86 * hwiParams.arg = 1;
87 *
88 * // set the event id of the peripheral assigned to this interrupt
89 * hwiParams.eventId = 10;
90 *
91 * // don't allow this interrupt to nest itself
92 * hwiParams.maskSetting = Hwi_MaskingOption_SELF;
93 *
94 * //
95 * // Configure interrupt 5 to invoke "myIsr".
96 * // Automatically enables interrupt 5 by default
97 * // set params.enableInt = FALSE if you want to control
98 * // when the interrupt is enabled using Hwi_enableInterrupt()
99 * //
100 *
101 * myHwi = Hwi_create(5, myIsr, &hwiParams, &eb);
102 *
103 * if (Error_check(&eb)) {
104 * // handle the error
105 * }
106 * }
107 *
108 * Void myIsr(UArg arg)
109 * {
110 * // here when interrupt #5 goes off
111 * }
112 * @p
113 *
114 * @a(Hook Functions)
115 *
116 * Sets of hook functions can be specified for the Hwi module
117 * using the configuration tool. Each set contains these hook
118 * functions:
119 * @p(blist)
120 * -Register: A function called before any statically-created Hwis
121 * are initialized at runtime. The register hook is called at boot time
122 * before main() and before interrupts are enabled.
123 * -Create: A function that is called when a Hwi is created.
124 * This includes hwis that are created statically and those
125 * created dynamically using {@link #create Hwi_create}.
126 * -Begin: A function that is called just prior to running a Hwi.
127 * -End: A function that is called just after a Hwi finishes.
128 * -Delete: A function that is called when a Hwi is deleted at
129 * run-time with {@link #delete Hwi_delete}.
130 * @p
131 *
132 * Register Function
133 *
134 * The Register function is provided to allow a hook set to store its
135 * hookset ID. This id can be passed to
136 * {@link #setHookContext Hwi_setHookContext} and
137 * {@link #getHookContext Hwi_getHookContext} to set or get
138 * hookset-specific context. The
139 * Register function must be specified if the hook implementation
140 * needs to use {@link #setHookContext Hwi_setHookContext} or
141 * {@link #getHookContext Hwi_getHookContext}.
142 * The registerFxn hook function is called during system initialization
143 * before interrupts have been enabled.
144 *
145 * @p(code)
146 * Void myRegisterFxn(Int id);
147 * @p
148 *
149 * Create and Delete Functions
150 *
151 * The create and delete functions are called whenever a Hwi is created
152 * or deleted. They are called with interrupts enabled (unless called
153 * at boot time or from main()).
154 *
155 * @p(code)
156 * Void myCreateFxn(Hwi_Handle hwi, Error_Block *eb);
157 * @p
158 *
159 * @p(code)
160 * Void myDeleteFxn(Hwi_Handle hwi);
161 * @p
162 *
163 * Begin and End Functions
164 *
165 * The beginFxn and endFxn function hooks are called with interrupts
166 * globally disabled, therefore any hook processing function will contribute
167 * to the overall system interrupt response latency. In order to minimize
168 * this impact, carefully consider the processing time spent in an Hwi
169 * beginFxn or endFxn function hook.
170 *
171 * @p(code)
172 * Void myBeginFxn(Hwi_Handle hwi);
173 * @p
174 *
175 * @p(code)
176 * Void myEndFxn(Hwi_Handle hwi);
177 * @p
178 *
179 * Hook functions can only be configured statically.
180 */
181
182 @DirectCall
183 @InstanceFinalize
184 @InstanceInitError
185
186 interface IHwi {
187
188
189
190 /*! Hwi create function type definition. */
191 typedef Void (*FuncPtr)(UArg);
192
193 /*!
194 * Interrupt Return Pointer.
195 *
196 * This is the address of the interrupted instruction.
197 */
198 typedef UArg Irp;
199
200 /*!
201 * Hwi hook set type definition.
202 *
203 * The functions that make up a hookSet have certain restrictions. They
204 * cannot call any Hwi instance functions other than Hwi_getHookContext()
205 * and Hwi_setHookContext(). For all practical purposes, they should treat
206 * the Hwi_Handle passed to these functions as an opaque handle.
207 */
208 struct HookSet {
209 Void (*registerFxn)(Int);
210 Void (*createFxn)(Handle, Error.Block *);
211 Void (*beginFxn)(Handle);
212 Void (*endFxn)(Handle);
213 Void (*deleteFxn)(Handle);
214 };
215
216 /*!
217 * ======== MaskingOption ========
218 * Shorthand interrupt masking options
219 *
220 * @value(MaskingOption_NONE) No interrupts are disabled
221 *
222 * @value(MaskingOption_ALL) All interrupts are disabled
223 *
224 * @value(MaskingOption_SELF) Only this interrupt is disabled
225 *
226 * @value(MaskingOption_BITMASK) User supplies interrupt enable masks
227 *
228 * @value(MaskingOption_LOWER) All current and lower priority
229 * interrupts are disabled.
230 *
231 * Only a few targets/devices truly
232 * support this masking option. For those
233 * that don't, this setting is treated
234 * the same as MaskingOption_SELF.
235 */
236 enum MaskingOption {
237 MaskingOption_NONE,
238 MaskingOption_ALL,
239 MaskingOption_SELF,
240 MaskingOption_BITMASK,
241 MaskingOption_LOWER
242 };
243
244 /*!
245 * ======== StackInfo ========
246 * Structure contains Hwi stack usage info
247 *
248 * Used by getStackInfo() and viewGetStackInfo() functions
249 */
250 struct StackInfo {
251 SizeT hwiStackPeak;
252 SizeT hwiStackSize;
253 Ptr hwiStackBase;
254 };
255
256
257
258 /*!
259 * Include interrupt nesting logic in interrupt dispatcher?
260 *
261 * Default is true.
262 *
263 * This option provides the user with the ability to optimize
264 * interrupt dispatcher performance when support for interrupt
265 * nesting is not required.
266 *
267 * Setting this parameter to false will disable the logic in
268 * the interrupt dispatcher that manipulates interrupt mask
269 * registers and enables and disables interrupts before and
270 * after invoking the user's Hwi function.
271 *
272 * Set this parameter to false if you don't need interrupts
273 * enabled during the execution of your Hwi functions.
274 */
275 config Bool dispatcherAutoNestingSupport = true;
276
277 /*!
278 * Include Swi scheduling logic in interrupt dispatcher?
279 *
280 * Default is inherited from {@link ti.sysbios.BIOS#swiEnabled
281 * BIOS.swiEnabled}, which is true by default.
282 *
283 * This option provides the user with the ability to optimize
284 * interrupt dispatcher performance when it is known that Swis
285 * will not be posted from any of their Hwi threads.
286 *
287 * Setting this parameter to false will disable the logic in
288 * the interrupt dispatcher that invokes the Swi scheduler
289 * prior to returning from an interrupt.
290 */
291 config Bool dispatcherSwiSupport;
292
293 /*!
294 * Include Task scheduling logic in interrupt dispatcher?
295 *
296 * Default is inherited from {@link ti.sysbios.BIOS#taskEnabled
297 * BIOS.taskEnabled}, which is true by default.
298 *
299 * This option provides the user with the ability to optimize
300 * interrupt dispatcher performance when it is known that no
301 * Task scheduling APIs (ie {@link ti.sysbios.knl.Semaphore#post
302 * Semaphore_post()}) will be executed from any of their Hwi threads.
303 *
304 * Setting this parameter to false will disable the logic in
305 * the interrupt dispatcher that invokes the Task scheduler
306 * prior to returning from an interrupt.
307 */
308 config Bool dispatcherTaskSupport;
309
310 /*!
311 * Controls whether the
312 * dispatcher retains the interrupted thread's return address.
313 *
314 * This option is enabled by default.
315 *
316 * Setting this parameter to false will disable the logic in
317 * the interrupt dispatcher that keeps track of the interrupt's
318 * return address and provide a small savings in interrupt latency.
319 *
320 * The application can get an interrupt's most recent return
321 * address using the {@link #getIrp} API.
322 */
323 config Bool dispatcherIrpTrackingSupport = true;
324
325
326
327 /*!
328 * ======== addHookSet ========
329 * addHookSet is used in a config file to add a hook set (defined
330 * by struct HookSet).
331 *
332 * HookSet structure elements may be omitted, in which case those
333 * elements will not exist.
334 *
335 * @param(hook) structure of type HookSet
336 */
337 metaonly Void addHookSet(HookSet hook);
338
339 /*!
340 * ======== viewGetStackInfo ========
341 * @_nodoc
342 * Returns the Hwi stack usage info. Used at ROV time.
343 *
344 * @b(returns) Hwi stack base, size, peak
345 */
346 metaonly StackInfo viewGetStackInfo();
347
348 /*!
349 * ======== getStackInfo ========
350 * Get Hwi stack usage Info.
351 *
352 * getStackInfo returns the Hwi stack usage info to its calling
353 * function by filling stack base address, stack size and stack
354 * peak fields in the {@link #StackInfo} structure.
355 *
356 * getStackInfo accepts two arguments, a pointer to a structure
357 * of type {@link #StackInfo} and a boolean. If the boolean is set
358 * to true, the function computes the stack depth and fills the
359 * stack peak field in the StackInfo structure. If a stack overflow
360 * is detected, the stack depth is not computed. If the boolean is
361 * set to false, the function only checks for a stack overflow.
362 *
363 * The isr stack is always checked for an overflow and a boolean
364 * is returned to indicate whether an overflow occured.
365 *
366 * Below is an example of calling getStackInfo() API:
367 *
368 * @p(code)
369 * #include <ti/sysbios/BIOS.h>
370 * #include <ti/sysbios/hal/Hwi.h>
371 * #include <ti/sysbios/knl/Swi.h>
372 * #include <ti/sysbios/knl/Task.h>
373 *
374 * Swi_Handle swi0;
375 * volatile Bool swiStackOverflow = FALSE;
376 *
377 * Void swi0Fxn(UArg arg1, UArg arg2)
378 * {
379 * Hwi_StackInfo stkInfo;
380 *
381 * // Request stack depth
382 * swiStackOverflow = Hwi_getStackInfo(&stkInfo, TRUE);
383 *
384 * // Alternately, we can omit the request for stack depth and
385 * // request only the stack base and stack size (the check for
386 * // stack overflow is always performed):
387 * //
388 * // swiStackOverflow = Hwi_getStackInfo(&stkInfo, FALSE);
389 *
390 * if (swiStackOverflow) {
391 * // isr Stack Overflow detected
392 * }
393 * }
394 *
395 * Void idleTask()
396 * {
397 * Swi_post(swi0);
398 * }
399 *
400 * Int main(Int argc, char* argv[])
401 * {
402 * swi0 = Swi_create(swi0Fxn, NULL, NULL);
403 *
404 * BIOS_start();
405 * return (0);
406 * }
407 * @p
408 *
409 * @param(stkInfo) pointer to structure of type {@link #StackInfo}
410 * @param(computeStackDepth) decides whether to compute stack depth
411 *
412 * @b(returns) boolean to indicate a stack overflow
413 */
414 Bool getStackInfo(StackInfo *stkInfo, Bool computeStackDepth);
415
416 /*!
417 * ======== startup ========
418 * Initially enable interrupts
419 *
420 * Called within BIOS_start
421 */
422 Void startup();
423
424 /*!
425 * ======== disable ========
426 * Globally disable interrupts.
427 *
428 * Hwi_disable globally disables hardware interrupts and returns an
429 * opaque key indicating whether interrupts were globally enabled or
430 * disabled on entry to Hwi_disable().
431 * The actual value of the key is target/device specific and is meant
432 * to be passed to Hwi_restore().
433 *
434 * Call Hwi_disable before a portion of a function that needs
435 * to run without interruption. When critical processing is complete, call
436 * Hwi_restore or Hwi_enable to reenable hardware interrupts.
437 *
438 * Servicing of interrupts that occur while interrupts are disabled is
439 * postponed until interrupts are reenabled. However, if the same type
440 * of interrupt occurs several times while interrupts are disabled,
441 * the interrupt's function is executed only once when interrupts are
442 * reenabled.
443 *
444 * A context switch can occur when calling Hwi_enable or Hwi_restore if
445 * an enabled interrupt occurred while interrupts are disabled.
446 *
447 * Hwi_disable may be called from main(). However, since Hwi interrupts
448 * are already disabled in main(), such a call has no effect.
449 *
450 * @a(constraints)
451 * If a Task switching API such as
452 * {@link ti.sysbios.knl.Semaphore#pend Semaphore_pend()},
453 * {@link ti.sysbios.knl.Semaphore#post Semaphore_post()},
454 * {@link ti.sysbios.knl.Task#sleep Task_sleep()}, or
455 * {@link ti.sysbios.knl.Task#yield Task_yield()}
456 * is invoked which results in a context switch while
457 * interrupts are disabled, an embedded call to
458 * {@link #enable Hwi_enable} occurs
459 * on the way to the new thread context which unconditionally re-enables
460 * interrupts. Interrupts will remain enabled until a subsequent
461 * {@link #disable Hwi_disable}
462 * invocation.
463 *
464 * Swis always run with interrupts enabled.
465 * See {@link ti.sysbios.knl.Swi#post Swi_post()} for a discussion Swis and
466 * interrupts.
467 *
468 * @b(returns) opaque key for use by Hwi_restore()
469 */
470 UInt disable();
471
472 /*!
473 * ======== enable ========
474 * Globally enable interrupts.
475 *
476 * Hwi_enable globally enables hardware interrupts and returns an
477 * opaque key indicating whether interrupts were globally enabled or
478 * disabled on entry to Hwi_enable().
479 * The actual value of the key is target/device specific and is meant
480 * to be passed to Hwi_restore().
481 *
482 *
483 * This function is
484 * called as part of SYS/BIOS Startup_POST_APP_MAIN phase.
485 *
486 * Hardware interrupts are enabled unless a call to Hwi_disable disables
487 * them.
488 *
489 * Servicing of interrupts that occur while interrupts are disabled is
490 * postponed until interrupts are reenabled. However, if the same type
491 * of interrupt occurs several times while interrupts are disabled,
492 * the interrupt's function is executed only once when interrupts are
493 * reenabled.
494 *
495 * A context switch can occur when calling Hwi_enable or Hwi_restore if
496 * an enabled interrupt occurred while interrupts are disabled.
497 *
498 * Any call to Hwi_enable enables interrupts, even if Hwi_disable has
499 * been called several times.
500 *
501 * Hwi_enable must not be called from main().
502 *
503 * @b(returns) opaque key for use by Hwi_restore()
504 */
505 UInt enable();
506
507 /*!
508 * ======== restore ========
509 * Globally restore interrupts.
510 *
511 * Hwi_restore globally restores interrupts to the state determined
512 * by the key argument provided by a previous invocation of Hwi_disable.
513 *
514 * A context switch may occur when calling Hwi_restore if Hwi_restore
515 * reenables interrupts and another Hwi occurred while interrupts were
516 * disabled.
517 *
518 * Hwi_restore may be called from main(). However, since Hwi_enable
519 * cannot be called from main(), interrupts are always disabled in
520 * main(), and a call to Hwi_restore has no effect.
521 *
522 * @param(key) enable/disable state to restore
523 */
524 Void restore(UInt key);
525
526 /*!
527 * @_nodoc
528 * ======== switchFromBootStack ========
529 * Indicate that we are leaving the boot stack and
530 * are about to switch to a task stack.
531 * Used by Task_startup()
532 */
533 Void switchFromBootStack();
534
535 /*!
536 * ======== post ========
537 * Generate an interrupt for test purposes.
538 *
539 * @param(intNum) ID of interrupt to generate
540 */
541 Void post(UInt intNum);
542
543 /*!
544 * @_nodoc
545 * ======== getTaskSP ========
546 * retrieve interrupted task's SP
547 *
548 * Used for benchmarking the SYS/BIOS Hwi dispatcher's task
549 * stack utilization.
550 *
551 * @b(returns) interrupted task's SP
552 */
553 Char *getTaskSP();
554
555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572
573
574 575 576 577 578 579 580 581 582 583 584 585 586 587 588
589
590
591 592 593 594 595 596 597 598 599 600 601 602 603
604
605
606 607 608 609 610 611 612 613 614 615 616 617 618 619
620
621
622 /*!
623 * ======== disableInterrupt ========
624 * Disable a specific interrupt.
625 *
626 * Disable a specific interrupt identified by an interrupt number.
627 *
628 * @param(intNum) interrupt number to disable
629 * @b(returns) key to restore previous enable/disable state
630 */
631 UInt disableInterrupt(UInt intNum);
632
633 /*!
634 * ======== enableInterrupt ========
635 * Enable a specific interrupt.
636 *
637 * Enables a specific interrupt identified by an interrupt number.
638 *
639 * @param(intNum) interrupt number to enable
640 * @b(returns) key to restore previous enable/disable state
641 */
642 UInt enableInterrupt(UInt intNum);
643
644 /*!
645 * ======== restoreInterrupt ========
646 * Restore a specific interrupt's enabled/disabled state.
647 *
648 * Restores a specific interrupt identified by an interrupt number.
649 * restoreInterrupt is generally used to restore an interrupt to its state
650 * before {@link #disableInterrupt} or {@link #enableInterrupt} was
651 * invoked
652 *
653 * @param(intNum) interrupt number to restore
654 * @param(key) key returned from enableInt or disableInt
655 */
656 Void restoreInterrupt(UInt intNum, UInt key);
657
658 /*!
659 * ======== clearInterrupt ========
660 * Clear a specific interrupt.
661 *
662 * Clears a specific interrupt's pending status.
663 * The implementation is family-specific.
664 *
665 * @param(intNum) interrupt number to clear
666 */
667 Void clearInterrupt(UInt intNum);
668
669 instance:
670
671 /*!
672 * Create a dispatched interrupt.
673 *
674 * A Hwi dispatcher table entry is created and filled with the
675 * function specified by the fxn parameter and the attributes
676 * specified by the params parameter.
677 *
678 * If params is NULL, the Hwi's dispatcher properties are assigned a
679 * default set of values. Otherwise, the following properties
680 * are specified by a structure of type Hwi_Params.
681 *
682 * @p(blist)
683 * - The arg element is a generic argument that is passed to the plugged
684 * function as its only parameter. The default value is 0.
685 * - The enableInt element determines whether the interrupt should be
686 * enabled in the IER by create.
687 * - The maskSetting element defines the dispatcherAutoNestingSupport
688 * behavior of the interrupt.
689 * @p
690 *
691 * Hwi_create returns a pointer to the created Hwi object.
692 *
693 * @param(intNum) interrupt number
694 * @param(hwiFxn) pointer to ISR function
695 *
696 */
697 create(Int intNum, FuncPtr hwiFxn);
698
699 /*! maskSetting. Default is {@link #MaskingOption Hwi_MaskingOption_SELF} */
700 config MaskingOption maskSetting = MaskingOption_SELF;
701
702 /*! ISR function argument. Default is 0. */
703 config UArg arg = 0;
704
705 /*! Enable this interrupt when object is created? Default is true. */
706 config Bool enableInt = true;
707
708 /*!
709 * Interrupt event ID (Interrupt Selection Number)
710 *
711 * Default is -1.
712 * Not all targets/devices support this instance parameter.
713 * On those that don't, this parameter is ignored.
714 */
715 config Int eventId = -1;
716
717 /*!
718 * Interrupt priority.
719 *
720 * The default value of -1 is used as a flag to indicate
721 * the lowest (logical) device-specific priority value.
722 *
723 * Not all targets/devices support this instance parameter.
724 * On those that don't, this parameter is ignored.
725 */
726 config Int priority = -1;
727
728 /*!
729 * ======== getFunc ========
730 * Get Hwi function and arg
731 *
732 * @param(arg) pointer for returning hwi's ISR function argument
733 * @b(returns) hwi's ISR function
734 */
735 FuncPtr getFunc(UArg *arg);
736
737 /*!
738 * ======== setFunc ========
739 * Overwrite Hwi function and arg
740 *
741 * Replaces a Hwi object's hwiFxn function originally
742 * provided in {@link #create}.
743 *
744 * @param(fxn) pointer to ISR function
745 * @param(arg) argument to ISR function
746 */
747 Void setFunc(FuncPtr fxn, UArg arg);
748
749 /*!
750 * ======== getHookContext ========
751 * Get hook instance's context for a Hwi.
752 *
753 * @b(returns) hook instance's context for hwi
754 */
755 Ptr getHookContext(Int id);
756
757 /*!
758 * ======== setHookContext ========
759 * Set hook instance's context for a Hwi.
760 *
761 * @param(id) hook instance's ID
762 * @param(hookContext) value to write to context
763 */
764 Void setHookContext(Int id, Ptr hookContext);
765
766 /*!
767 * ======== getIrp ========
768 * Get address of interrupted instruction.
769 *
770 * @b(returns) most current IRP of a Hwi
771 */
772 Irp getIrp();
773 }