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.

  • Resolved

[FAQ] RTOS: How do I add Task hooks to a SYS/BIOS application?

Intellectual 940 points

Replies: 1

Views: 311

I have a SYS/BIOS project and I want to register certain functions as Task hooks.

  • SYS/BIOS allows users to add their own application specific task hooks to the system. These hooks will be called at key points during the thread life cycle (create, delete, switch, exit, etc.). See the SYS/BIOS User's Guide and the SYS/BIOS APIs for more info. This example shows how to add these hooks in the .cfg file along with C code for sample hook functions. Swi hooks and Hwi hooks are added similarly.

    Add this to your project's .cfg file:

    Task.addHookSet({
       registerFxn: '&myRegisterFxn',
       createFxn: '&myCreateFxn',
       deleteFxn: '&myDeleteFxn',
       switchFxn: '&mySwitchFxn'
    });

    Add these sample implementations to your application's .c file:

    #include <xdc/std.h>
     
    #include <xdc/runtime/Memory.h>
    #include <xdc/runtime/Error.h>
    #include <xdc/runtime/System.h>
     
    #include <ti/sysbios/knl/Task.h>
     
    /*
    * Task Hook Functions
    */
    #define TLSSIZE 32
     
    Int hookId;
     
    /*
    * ======== myRegisterFxn ========
    * This function is called at boot time.
    */
    Void myRegisterFxn(Int id)
    {
         hookId = id;
    }
     
    /*
    * ======== myCreateFxn ========
    */
    Void myCreateFxn(Task_Handle task, Error_Block *eb)
    {
       Ptr tls;
         System_printf("myCreateFxn: task = 0x%x\n", task);
         Error_init(eb);
         tls = Memory_alloc(NULL, TLSSIZE, 0, eb);
     
         Task_setHookContext(task, hookId, tls);
    }
     
    Void myDeleteFxn(Task_Handle task)
    {
       Ptr tls;
     
       System_printf("myDeleteFxn: task = 0x%x\n", task);
     
       tls = Task_getHookContext(task, hookId);
     
       Memory_free(NULL, tls, TLSSIZE);
    }
     
    Void mySwitchFxn(Task_Handle from, Task_Handle to)
    {
         // System_printf("mySwitchFxn: from = 0x%x, to = 0x%x", from, to);
    }

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.