This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

What are hooks?



hello, i have seen various examples with hooks. 

I cannot find much information about them, but would like to learn more. does anyone have any good resources.  

this is what i mean by a hook: "

Hwi, Swi, and Task threads optionally provide points in a thread's life cycle to insert user code for
instrumentation, monitoring, or statistics gathering purposes. Each of these code points is called a "hook"
and the user function provided for the hook is called a "hook function".

"

  • Hi Daniel,

    Key concept of a hook is very simple. A hook function is a user supplied C function with a well-defined signature that gets called back by the module when the particular 'hook event' gets triggered.

    SYS/BIOS allows user of Hwi, Swi and Task threads to register "hook functions" with certain events. The associated hook function gets called when the event it is registered with is triggered.  The type of events and the signature of the hook functions that can be registered are specified in the "Module-wide constants and types" section of the specific module. The hookable events in Hwi, Swi and Task modules are:

    Hwi: Register, Create, Begin, End & Delete

    Swi: Register, Create, Ready, Begin, End & Delete

    Task: Register, Create, Ready, Switch, Exit, and Delete

    When using these SYS/BIOS modules, inside a configuration script you can add a set of hook-functions to register with these module events using the Module.addHookSet() API. For example the following .cfg snippet:

    var Hwi = xdc.useModule('ti.sysbios.hal.Hwi');
    /* Hook Set 1 */
    Hwi.addHookSet({
        registerFxn: '&myRegister1',
        createFxn: '&myCreate1',
    });

    will hook the Hwi module's Create and Register events with these user supplied C functions:

    Void myCreate1(Hwi_Handle hwi, Error_Block *eb)
    {
        . . .
    }

    Void myRegisterFxn(Int id)
    {
    }

    Inside a hook function you can use Module supplied '<MOD>_getHookContext' and '<MOD>_setHookContext' functions to manage user state.

    A last detail is that you can have multiple hooks associated with a module's events, via multiple addHookSet() config calls. All hook functions will get called in sequence when the associated event is triggered.

    Hope this helps, if you have more specific questions let me know,

    Murat