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.

events_pend tirtos cc26xx

Other Parts Discussed in Thread: SYSBIOS
Hello, i wanna use event in my project and its doesnt work
help me please



#include <xdc/std.h> #include <xdc/runtime/System.h> /* BIOS Header files */ #include <ti/sysbios/BIOS.h> #include <ti/sysbios/knl/Clock.h> #include <ti/sysbios/knl/Task.h> #include <ti/sysbios/knl/Event.h> #include <xdc/cfg/global.h> #include <xdc/runtime/Error.h> #include "Board.h" #define TASKSTACKSIZE 768 Task_Struct task0Struct; Char task0Stack[TASKSTACKSIZE]; Task_Handle firstTask; Event_Handle myEvent; Void firstFxn(UArg a0, UArg a1){ uint32_t i = 0; while(1){ i++; System_flush(); System_printf(" %d", i); if(i==5){ Event_post(myEvent, Event_Id_00); } Task_sleep(1000000 / Clock_tickPeriod); } } void secondFxn(void){ UInt evt; while(1){ evt = Event_pend(myEvent, Event_Id_NONE, Event_Id_00, BIOS_NO_WAIT); System_printf("Timeout expired for Event_pend()\n"); if (evt == 0) { System_flush(); System_printf(" 111111111"); break; } if (evt & Event_Id_00) { System_flush(); System_printf(" 22222222222"); } } } int main(void) { Error_Block eb; Error_init(&eb); myEvent = Event_create(NULL, &eb); Task_Params taskParams; Board_initGeneral(); Task_Params_init(&taskParams); taskParams.stackSize = TASKSTACKSIZE; taskParams.stack = &task0Stack; taskParams.priority = 1; taskParams.instance->name = "firstFxn"; Task_construct(&task0Struct, (Task_FuncPtr)firstFxn, &taskParams, NULL); firstTask = Task_handle(&task0Struct); BIOS_start(); return (0); }

  • What exactly is not working? Does it build? Note: you need to add the following into the .cfg file.
    var Event = xdc.useModule('ti.sysbios.knl.Event');

    Also, I don't see where you are calling the secondFxn. If it is being called somewhere else, why are you using BIOS_NO_WAIT. This is basically just polling. Part of the advantage of the Event module is the ability to block on multiple things instead of polling.

    Todd
  • 1) - i have no cfg file
    2) i dont wanna calling secondFxn, i want starting it when i post myEvent
    3) i using NO_WAIT because i want 2 tasks at the same time working
  • Actually, you want the secondFxn running and pending (waiting for an event to occur).

    Here's the sequence of events that need to occur for your code to work:

    1. Your firstFxn and secondFxn will start when you create them.
    2. Your secondFxn will stop at Event_pend because no events have been recorded yet (control will be given to firstFxn)
    3. firstFxn will eventually execute Event_post (at this time, secondFxn will go into Ready State)
    4. Depending on the priorities of your task, firstFxn will either release control to secondFxn or continue to Task_sleep. No matter what happens, firstFxn will eventually give up control.
    5. SecondFxn will regain control and exit the Event_pend (since the event it was watiing on occurred). The code below the Event_pend will execute once and stop again when it returns to the same Event_pend.
    6. firstFxn will wake up when the Task_sleep delay has expired.
    7. Go back to step 3

    So you need to create both tasks. And you have to use BIOS_WAIT_FOREVER if you want your secondFxn task to wait until the event occurs. Any other delay parameter that you pass to Event_pend (or any other blocking module with a delay) is normally used for error handling in case your program hangs. If a timeout occurs before the event was triggered, the Event_pend function will return False and

    You can actually use this to check which event caused the Event_pend to exit (the awaited event was posted or timeout)

    if (Event_pend(... insert parameters and timeout here ... )
    {
      // Event occurred
      // Do your stuff here
    }
    else
    {
     // handle timeout here (optional)
    }

  • I've marked Michel's response as "Verify Answer". If you feel this did not answer your question, please reject it and post a follow-up reply.

    Todd