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.

Hwi Hooks

Other Parts Discussed in Thread: SYSBIOS

Hello, Everyone!

I have a question about Hwi hook function:create.

When I read the pdf named "TI SYS/BIOS Real-time Operating System v6.x User’s Guide",I have a question about Hwi hook function.

I don't know where the system invokes the Hwi_create function. And I don't find that it invokes the Hwi.create in the configuration file.

So I want to know when the Hwi object is created and  who invokes this function.

I hope someone can give me the answer about it.

Thanks.

 

  • The create hooks are called prior to main() for all statically created Hwi objects, and are called within the Hwi_create() thread for dynamically created Hwi objects.

    Alan

  • Thank you for your reply, Alan.

    I know what you said.

    What I want to know is the accurate time the Hwi object is created by Hwi_create or by Hwi.create.

    And I want to know who invoke this hook to create.

    For example,in the pdf I mentioned there is a Hwi Hooks example.In this example,there are some C code as follows:

    /* ======== myCreate1 ========
    * invoked during Hwi module startup before main()
    * for statically created Hwis */
    Void myCreate1(Hwi_Handle hwi, Error_Block *eb)
    {
        Ptr pEnv;
        pEnv = Hwi_getHookContext(hwi, myHookSetId1);
        /* pEnv should be 0 at this point. If not, there's a bug. */
        System_printf("myCreate1: pEnv = 0x%x, time = %d\n", pEnv, Timestamp_get32());
        Hwi_setHookContext(hwi, myHookSetId1, (Ptr)0xdead1);
    }

    Meanwhile, In the C code and the XDCtools configuration script, it doesn't mention anything about Hwi_create and Hwi.create. In  the XDCtools configuration script, it only has some codes as follows:

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

    The main() is as follows:
    /* ======== main ======== */
    Int main(Int argc, Char* argv[])
    {
        System_printf("Starting HwiHookExample...\n");
        BIOS_start();
        return (0);
    }

    So when and who create ??

    Can you tell me??

  • I think I understand your question now.

    In this example, there are two Hwi objects being implicitly created.

    Both Hwi objects are associated with ti.sysbios.hal.Timer instances.

    The first timer instance is being created internally by the Clock module as a source of periodic interrupts to run the Clock tick.

    The second timer instance is being explicitly created by these lines in the configuration file:

    /* Create myTimer as source of Hwi */
    var Timer = xdc.useModule('ti.sysbios.hal.Timer');
    var timerParams = new Timer.Params();
    timerParams.startMode = Timer.StartMode_USER;
    timerParams.runMode = Timer.RunMode_ONESHOT;
    timerParams.period = 1000; // 1ms
    Program.global.myTimer = Timer.create(Timer.ANY, "&myTimerFunc", timerParams);

    The Timer module internally creates a Hwi object to handle the interrupt associated with each Timer instance.

    So in this example, there will be two invocations of the Hwi create hooks: one for the Hwi instance associated with the Timer used by the Clock module, and the other for the Hwi instance associated with the Timer being created by the application.

    Both of these Hwi instances are created statically. Consequently, as I mentioned in a previous post, both Hwi create hook invocations will occur before main().

    I hope I understood and answered your question.

    Alan

  • Thank you , Alan.

    Your answer is very clear. But I have another question.

    You said that "The first timer instance is being created internally by the Clock module as a source of periodic interrupts to run the Clock tick".

    Can you explain this sentence in detail??

    Especially this part: "as a source of periodic interrupts to run the Clock tick".

    And what's the relationship between this example and the Clock module??

     

    Meng

  • Meng,

    The Clock tick drives the timing within SYS/BIOS. If you call Task_sleep, for example, SYS/BIOS needs to be some way to determine time to sleep the task. It is the Clock tick that supplies this. Note that Task_sleep()'s parameter is number of ticks.

    Void Task_sleep(UInt nticks);

    The nticks corresponds to the number of SYS/BIOS Clock ticks that you want to wait. By default the Clock's period is 1ms (however this is configurable). So if you specific Task_sleep(1000) and the period is 1ms, the task will sleep for 1 second.

    There are other areas in SYS/BIOS where the Clock tick is used (e.g. Semaphore, Event). Users can add callback functions to the Clock module, instead of using a different timer. Please read about the Clock module for more details about this.

    Todd

  • Thank you , Todd.

    Your answer is very clear.

     

    Meng