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 @InstanceFinalize
183 @InstanceInitError
184
185 interface IHwi {
186
187
188
189 /*! Hwi create function type definition. */
190 typedef Void (*FuncPtr)(UArg);
191
192 /*!
193 * Interrupt Return Pointer.
194 * This is the address of the interrupted instruction.
195 */
196 typedef UArg Irp;
197
198 /*!
199 * Hwi hook set type definition.
200 *
201 * The functions that make up a hookSet have certain restrictions. They
202 * cannot call any Hwi instance functions other than Hwi_getHookContext()
203 * and Hwi_setHookContext(). For all practical purposes, they should treat
204 * the Hwi_Handle passed to these functions as an opaque handle.
205 */
206 struct HookSet {
207 Void (*registerFxn)(Int);
208 Void (*createFxn)(Handle, Error.Block *);
209 Void (*beginFxn)(Handle);
210 Void (*endFxn)(Handle);
211 Void (*deleteFxn)(Handle);
212 };
213
214 /*! Shorthand interrupt masking options. */
215 enum MaskingOption {
216 MaskingOption_NONE, /*! No interrupts are disabled. */
217 MaskingOption_ALL, /*! All interrupts are disabled. */
218 MaskingOption_SELF, /*! Only this interrupt is disabled. */
219 MaskingOption_BITMASK, /*! User supplies IER masks. */
220 MaskingOption_LOWER /*! All current and lower priority
221 interrupts are disabled. Only a few
222 targets/devices truly support this
223 masking option. For those that don't,
224 this setting is treated the same as
225 MaskingOption_SELF */
226 };
227
228 /*!
229 * @_nodoc
230 * returned by viewGetStackInfo()
231 */
232 metaonly struct StackInfo {
233 SizeT hwiStackPeak;
234 SizeT hwiStackSize;
235 Ptr hwiStackBase;
236 };
237
238
239
240 /*!
241 * Include interrupt nesting logic in interrupt dispatcher?
242 *
243 * Default is true.
244 *
245 * This option provides the user with the ability to optimize
246 * interrupt dispatcher performance when support for interrupt
247 * nesting is not required.
248 *
249 * Setting this parameter to false will disable the logic in
250 * the interrupt dispatcher that manipulates interrupt mask
251 * registers and enables and disables interrupts before and
252 * after invoking the user's Hwi function.
253 *
254 * Set this parameter to false if you don't need interrupts
255 * enabled during the execution of your Hwi functions.
256 */
257 config Bool dispatcherAutoNestingSupport = true;
258
259 /*!
260 * Include Swi scheduling logic in interrupt dispatcher?
261 *
262 * Default is inherited from {@link ti.sysbios.BIOS#swiEnabled
263 * BIOS.swiEnabled}, which is true by default.
264 *
265 * This option provides the user with the ability to optimize
266 * interrupt dispatcher performance when it is known that Swis
267 * will not be posted from any of their Hwi threads.
268 *
269 * Setting this parameter to false will disable the logic in
270 * the interrupt dispatcher that invokes the Swi scheduler
271 * prior to returning from an interrupt.
272 */
273 config Bool dispatcherSwiSupport;
274
275 /*!
276 * Include Task scheduling logic in interrupt dispatcher?
277 *
278 * Default is inherited from {@link ti.sysbios.BIOS#taskEnabled
279 * BIOS.taskEnabled}, which is true by default.
280 *
281 * This option provides the user with the ability to optimize
282 * interrupt dispatcher performance when it is known that no
283 * Task scheduling APIs (ie {@link ti.sysbios.ipc.Semaphore#post
284 * Semaphore_post()}) will be executed from any of their Hwi threads.
285 *
286 * Setting this parameter to false will disable the logic in
287 * the interrupt dispatcher that invokes the Task scheduler
288 * prior to returning from an interrupt.
289 */
290 config Bool dispatcherTaskSupport;
291
292 /*!
293 * Controls whether the
294 * dispatcher retains the interrupted thread's return address.
295 *
296 * This option is enabled by default.
297 *
298 * Setting this parameter to false will disable the logic in
299 * the interrupt dispatcher that keeps track of the interrupt's
300 * return address and provide a small savings in interrupt latency.
301 *
302 * The application can get an interrupt's most recent return
303 * address using the {@link #getIrp} API.
304 */
305 config Bool dispatcherIrpTrackingSupport = true;
306
307
308
309 /*!
310 * ======== addHookSet ========
311 * addHookSet is used in a config file to add a hook set (defined
312 * by struct HookSet).
313 *
314 * HookSet structure elements may be omitted, in which case those
315 * elements will not exist.
316 *
317 * @param(hook) structure of type HookSet
318 */
319 metaonly Void addHookSet(HookSet hook);
320
321 /*!
322 * ======== viewGetStackInfo ========
323 * @_nodoc
324 * Returns the Hwi stack usage info. Used at ROV time.
325 *
326 * @b(returns) Hwi stack base, size, peak
327 */
328 metaonly StackInfo viewGetStackInfo();
329
330 /*!
331 * ======== startup ========
332 * Initially enable interrupts
333 *
334 * Called within BIOS_start
335 */
336 @DirectCall
337 Void startup();
338
339 /*!
340 * ======== disable ========
341 * Globally disable interrupts.
342 *
343 * Hwi_disable globally disables hardware interrupts and returns an
344 * opaque key indicating whether interrupts were globally enabled or
345 * disabled on entry to Hwi_disable().
346 * The actual value of the key is target/device specific and is meant
347 * to be passed to Hwi_restore().
348 *
349 * Call Hwi_disable before a portion of a function that needs
350 * to run without interruption. When critical processing is complete, call
351 * Hwi_restore or Hwi_enable to reenable hardware interrupts.
352 *
353 * Servicing of interrupts that occur while interrupts are disabled is
354 * postponed until interrupts are reenabled. However, if the same type
355 * of interrupt occurs several times while interrupts are disabled,
356 * the interrupt's function is executed only once when interrupts are
357 * reenabled.
358 *
359 * A context switch can occur when calling Hwi_enable or Hwi_restore if
360 * an enabled interrupt occurred while interrupts are disabled.
361 *
362 * Hwi_disable may be called from main(). However, since Hwi interrupts
363 * are already disabled in main(), such a call has no effect.
364 *
365 * @a(constraints)
366 * If a Task switching API such as
367 * {@link ti.sysbios.ipc.Semaphore#pend Semaphore_pend()},
368 * {@link ti.sysbios.ipc.Semaphore#post Semaphore_post()},
369 * {@link ti.sysbios.knl.Task#sleep Task_sleep()}, or
370 * {@link ti.sysbios.knl.Task#yield Task_yield()}
371 * is invoked which results in a context switch while
372 * interrupts are disabled, an embedded call to
373 * {@link #enable Hwi_enable} occurs
374 * on the way to the new thread context which unconditionally re-enables
375 * interrupts. Interrupts will remain enabled until a subsequent
376 * {@link #disable Hwi_disable}
377 * invocation.
378 *
379 * Swis always run with interrupts enabled.
380 * See {@link ti.sysbios.knl.Swi#post Swi_post()} for a discussion Swis and
381 * interrupts.
382 *
383 * @b(returns) opaque key for use by Hwi_restore()
384 */
385 UInt disable();
386
387 /*!
388 * ======== enable ========
389 * Globally enable interrupts.
390 *
391 * Hwi_enable globally enables hardware interrupts and returns an
392 * opaque key indicating whether interrupts were globally enabled or
393 * disabled on entry to Hwi_enable().
394 * The actual value of the key is target/device specific and is meant
395 * to be passed to Hwi_restore().
396 *
397 *
398 * This function is
399 * called as part of SYS/BIOS Startup_POST_APP_MAIN phase.
400 *
401 * Hardware interrupts are enabled unless a call to Hwi_disable disables
402 * them.
403 *
404 * Servicing of interrupts that occur while interrupts are disabled is
405 * postponed until interrupts are reenabled. However, if the same type
406 * of interrupt occurs several times while interrupts are disabled,
407 * the interrupt's function is executed only once when interrupts are
408 * reenabled.
409 *
410 * A context switch can occur when calling Hwi_enable or Hwi_restore if
411 * an enabled interrupt occurred while interrupts are disabled.
412 *
413 * Any call to Hwi_enable enables interrupts, even if Hwi_disable has
414 * been called several times.
415 *
416 * Hwi_enable must not be called from main().
417 *
418 * @b(returns) opaque key for use by Hwi_restore()
419 */
420 UInt enable();
421
422 /*!
423 * ======== restore ========
424 * Globally restore interrupts.
425 *
426 * Hwi_restore globally restores interrupts to the state determined
427 * by the key argument provided by a previous invocation of Hwi_disable.
428 *
429 * A context switch may occur when calling Hwi_restore if Hwi_restore
430 * reenables interrupts and another Hwi occurred while interrupts were
431 * disabled.
432 *
433 * Hwi_restore may be called from main(). However, since Hwi_enable
434 * cannot be called from main(), interrupts are always disabled in
435 * main(), and a call to Hwi_restore has no effect.
436 *
437 * @param(key) enable/disable state to restore
438 */
439 Void restore(UInt key);
440
441 /*!
442 * @_nodoc
443 * ======== switchFromBootStack ========
444 * Indicate that we are leaving the boot stack and
445 * are about to switch to a task stack.
446 * Used by Task_startup()
447 */
448 @DirectCall
449 Void switchFromBootStack();
450
451 /*!
452 * @_nodoc
453 * ======== post ========
454 * Generate an interrupt for test purposes.
455 *
456 * @param(intNum) ID of interrupt to generate
457 */
458 @DirectCall
459 Void post(UInt intNum);
460
461 /*!
462 * @_nodoc
463 * ======== getTaskSP ========
464 * retrieve interrupted task's SP
465 *
466 * Used for benchmarking the SYS/BIOS Hwi dispatcher's task
467 * stack utilization.
468 *
469 * @b(returns) interrupted task's SP
470 */
471 @DirectCall
472 Char *getTaskSP();
473
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491
492
493 494 495 496 497 498 499 500 501 502 503 504 505
506
507
508 509 510 511 512 513 514 515 516 517 518 519 520 521
522
523
524 /*!
525 * ======== disableInterrupt ========
526 * Disable a specific interrupt.
527 *
528 * Disable a specific interrupt identified by an interrupt number.
529 *
530 * @param(intNum) interrupt number to disable
531 * @b(returns) key to restore previous enable/disable state
532 */
533 @DirectCall
534 UInt disableInterrupt(UInt intNum);
535
536 /*!
537 * ======== enableInterrupt ========
538 * Enable a specific interrupt.
539 *
540 * Enables a specific interrupt identified by an interrupt number.
541 *
542 * @param(intNum) interrupt number to enable
543 * @b(returns) key to restore previous enable/disable state
544 */
545 @DirectCall
546 UInt enableInterrupt(UInt intNum);
547
548 /*!
549 * ======== restoreInterrupt ========
550 * Restore a specific interrupt's enabled/disabled state.
551 *
552 * Restores a specific interrupt identified by an interrupt number.
553 * restoreInterrupt is generally used to restore an interrupt to its state
554 * before {@link #disableInterrupt} or {@link #enableInterrupt} was
555 * invoked
556 *
557 * @param(intNum) interrupt number to restore
558 * @param(key) key returned from enableInt or disableInt
559 */
560 @DirectCall
561 Void restoreInterrupt(UInt intNum, UInt key);
562
563 /*!
564 * ======== clearInterrupt ========
565 * Clear a specific interrupt.
566 *
567 * Clears a specific interrupt's pending status.
568 * The implementation is family-specific.
569 *
570 * @param(intNum) interrupt number to clear
571 */
572 @DirectCall
573 Void clearInterrupt(UInt intNum);
574
575 instance:
576
577 /*!
578 * Create a dispatched interrupt.
579 *
580 * A Hwi dispatcher table entry is created and filled with the
581 * function specified by the fxn parameter and the attributes
582 * specified by the params parameter.
583 *
584 * If params is NULL, the Hwi's dispatcher properties are assigned a
585 * default set of values. Otherwise, the following properties
586 * are specified by a structure of type Hwi_Params.
587 *
588 * @p(blist)
589 * - The arg element is a generic argument that is passed to the plugged
590 * function as its only parameter. The default value is 0.
591 * - The enableInt element determines whether the interrupt should be
592 * enabled in the IER by create.
593 * - The maskSetting element defines the dispatcherAutoNestingSupport
594 * behavior of the interrupt.
595 * @p
596 *
597 * Hwi_create returns a pointer to the created Hwi object.
598 *
599 * @param(intNum) interrupt number
600 * @param(hwiFxn) pointer to ISR function
601 *
602 */
603 @DirectCall
604 create(Int intNum, FuncPtr hwiFxn);
605
606 /*! maskSetting. Default is {@link #MaskingOption Hwi_MaskingOption_SELF} */
607 config MaskingOption maskSetting = MaskingOption_SELF;
608
609 /*! ISR function argument. Default is 0. */
610 config UArg arg = 0;
611
612 /*! Enable this interrupt now? Default is true. */
613 config Bool enableInt = true;
614
615 /*!
616 * Interrupt event ID (Interrupt Selection Number)
617 * Default is -1.
618 * Not all targets/devices support this instance parameter.
619 * On those that don't, this parameter is ignored.
620 */
621 config Int eventId = -1;
622
623 /*!
624 * Interrupt priority.
625 * Default is -1.
626 * Not all targets/devices support this instance parameter.
627 * On those that don't, this parameter is ignored.
628 */
629 config Int priority = -1;
630
631 /*!
632 * ======== getFunc ========
633 * Get Hwi function and arg
634 *
635 * @param(arg) pointer for returning hwi's ISR function argument
636 * @b(returns) hwi's ISR function
637 */
638 @DirectCall
639 FuncPtr getFunc(UArg *arg);
640
641 /*!
642 * ======== setFunc ========
643 * Overwrite Hwi function and arg
644 *
645 * Replaces a Hwi object's hwiFxn function originally
646 * provided in {@link #create}.
647 *
648 * @param(fxn) pointer to ISR function
649 * @param(arg) argument to ISR function
650 */
651 @DirectCall
652 Void setFunc(FuncPtr fxn, UArg arg);
653
654 /*!
655 * ======== getHookContext ========
656 * Get hook instance's context for a Hwi.
657 *
658 * @b(returns) hook instance's context for hwi
659 */
660 @DirectCall
661 Ptr getHookContext(Int id);
662
663 /*!
664 * ======== setHookContext ========
665 * Set hook instance's context for a Hwi.
666 *
667 * @param(id) hook instance's ID
668 * @param(hookContext) value to write to context
669 */
670 @DirectCall
671 Void setHookContext(Int id, Ptr hookContext);
672
673 /*!
674 * ======== getIrp ========
675 * Get address of interrupted instruction.
676 *
677 * @b(returns) most current IRP of a Hwi
678 */
679 @DirectCall
680 Irp getIrp();
681 }
682 683 684 685
686