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.

SYSBIOS EVENT

Other Parts Discussed in Thread: SYSBIOS

SysBios 6.33.04.39

Im trying to use Event_post(EventHandle, Event_Id_00) inside an HWI to triger a task doing Event_pend(EventHandle, Event_Id_00, Event_Id_00, BIOS_WAIT_FOREVER) and it doesnt seem to be working correctly.

Are we able to use Event_post() inside a HWI? if yes, is there anything we are doing wrong?

Here is some of the code:

 

 

void interrupt CANRX_INTERRUPT()

{

//VARIABLES

unsigned long CanStat;

//GET STATUS OF CAN

CanStat = (HWREG(CAN0_BASE + CAN_O_MSG1INT) & CAN_MSG1INT_INTPND_M);

CanStat |= (HWREG(CAN0_BASE + CAN_O_MSG2INT) << 16);

//IF THERE IS A MESSAGE IN CAN, POST AN EVENT

if((CanStat & 1) == 1)

{

//POST EVENT

Event_post(EventHandle, Event_Id_00);

//CLEAR INTERUPT

CANIntClear();

}

}

 

 

void MESSAGE_READ_TASK(UArg args1, UArg args2)

{

while(1)

{

//WAIT FOR EVENT

Event_pend(EventHandle, Event_Id_00, Event_Id_00, 1000000);

//READ DATA

CANMessageGet(CAN0_BASE, 1, &ObjectRx, 1);

}

}

  • Carlos,

    Are you registering CANRX_INTERRUPT() as a SYS/BIOS Hwi?  If yes, how are you doing this?   And if yes, you’ll need to remove the “interrupt” keyword from the function.  Otherwise the compiler will generate a “return from interrupt” for this function, which will cause problems during unwind of the interrupt.

    If you are *not* registering this function as a SYS/BIOS Hwi (but are plugging this ISR function directly) then you cannot call Event_post().  Event_post() will “ready” the task to run, and without internal protections from the Hwi module, the SYS/BIOS scheduler may immediately preempt the ISR to run the task.

    Scott

     

  • Hi Scott,

    Scott Gary said:
    you’ll need to remove the “interrupt” keyword from the function.

    After removing the "interrupt" keyword the results were the same.

     

    Scott Gary said:
    Are you registering CANRX_INTERRUPT() as a SYS/BIOS Hwi?  If yes, how are you doing this?

    Im not very sure of how many ways there are to register an Interrupt function but this is how I am registering my CANTX_INTERRUPT:

     

    //CAN INTERRUPT

    Hwi_Params_init(&HwiParams);

    HwiParams.priority = 1;

    Hwi_create(INT_CAN0, CANRX_INTERRUPT, &HwiParams, NULL);

     

    Scott Gary said:
    the SYS/BIOS scheduler may immediately preempt the ISR to run the task

    The scheduler is preempting the ISR function and cant return to the ISR function, having an error:

    ti.sysbios.knl.Task: line 345: E_spOutOfBounds: Task 0x20002cd4 stack error, SP = 0x2000322c.

    xdc.runtime.Error.raise: terminating execution

     

    Any Ideas?

     

     

  • Carlos,

    Can you post the contents of your application configuration file?  It has a .cfg extension.  If you can’t post the whole thing, can you post any configuration for BIOS or Hwi?  Something like this:

    var BIOS = xdc.useModule('ti.sysbios.BIOS');
    BIOS.swiEnabled = true;
    BIOS.taskEnabled = true;

    I’m wondering if the task “hold off” logic in the interrupt dispatcher is being disabled.  By default the task preemption should be prevented, but it is possible to optimize the application configuration and disable this if it is not needed.  I'm wondering if that is what has happened...

    Scott

  • var Defaults = xdc.useModule('xdc.runtime.Defaults');

    var Diags = xdc.useModule('xdc.runtime.Diags');

    var Error = xdc.useModule('xdc.runtime.Error');

    var Log = xdc.useModule('xdc.runtime.Log');

    var LoggerBuf = xdc.useModule('xdc.runtime.LoggerBuf');

    var Main = xdc.useModule('xdc.runtime.Main');

    var SysMin = xdc.useModule('xdc.runtime.SysMin');

    var System = xdc.useModule('xdc.runtime.System');

    var Text = xdc.useModule('xdc.runtime.Text');

     

    var BIOS = xdc.useModule('ti.sysbios.BIOS');

    var Clock = xdc.useModule('ti.sysbios.knl.Clock');

    var Idle = xdc.useModule('ti.sysbios.knl.Idle');

    var Timer = xdc.useModule('ti.sysbios.hal.Timer');

    var Boot = xdc.useModule('ti.catalog.arm.cortexm3.lm3init.Boot');

    var Task = xdc.useModule('ti.sysbios.knl.Task');

    var Event = xdc.useModule('ti.sysbios.knl.Event');

    var Hwi = xdc.useModule('ti.sysbios.family.arm.m3.Hwi');

    var ti_sysbios_hal_Hwi = xdc.useModule('ti.sysbios.hal.Hwi');

     

     

    Program.argSize = 0x0;

    System.maxAtexitHandlers = 4;  

    BIOS.heapSize = 4096;

    Program.stack = 1024;

    SysMin.bufSize = 0x200;

     

     

    var loggerBufParams = new LoggerBuf.Params();

    loggerBufParams.numEntries = 16;

    var logger0 = LoggerBuf.create(loggerBufParams);

    Defaults.common$.logger = logger0;

    Main.common$.diags_INFO = Diags.ALWAYS_ON;

     

    System.SupportProxy = SysMin;

    Boot.sysClockDiv = Boot.SYSDIV_10;

    BIOS.cpuFreq.lo = 20000000;

    Boot.pllBypass = false;

    Boot.pllOutEnable = true;

    Task.deleteTerminatedTasks = true;

    Task.checkStackFlag = true;

    Task.numPriorities = 32;

    Task.defaultStackSize = 1024;

    Task.idleTaskStackSize = 1024;

    BIOS.libType = BIOS.LibType_Debug;

    BIOS.swiEnabled = true;

    BIOS.taskEnabled = true;

     

    var task1Params = new Task.Params();

    task1Params.instance.name = "task1";

    task1Params.priority = 1;

    Program.global.task1 = Task.create("&MESSAGE_READ_TASK", task1Params);

     

    var hwi0Params = new Hwi.Params();

    hwi0Params.instance.name = "hwi0";

    hwi0Params.priority = 1;

    Program.global.hwi0 = Hwi.create(55, "&CANRX_INTERRUPT", hwi0Params);

  • Thanks for posting the contents.  I don’t see anything obvious here.  But, there are two different useModules for Hwi: one at the hal level and one at the family-specific level.  I don’t think this alone should cause a problem, but since we’re talking about a Hwi preemption issue, can you please delete this redundant line:

    var ti_sysbios_hal_Hwi = xdc.useModule('ti.sysbios.hal.Hwi');

    This probably won’t make a difference, but it is worth a try.

    I’ve not seen examples of ISRs calling Event_post(), but have seen several where Event_post() is called from a Swi context, which requires a similar hold off of the Task scheduler.

    What M3 device are you running on?

    Scott

  • Carlos,

    A TI engineer on vacation just sent me a hint for this one…  Are you running on a Stellaris device?  If so, only 8 Hwi priority levels are supported.  The valid priority values are: 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0.  Priority settings of 0-1f are all considered to be the same (because only bits 5-7 are valid).  There is some description here: http://processors.wiki.ti.com/index.php/SYS/BIOS_for_Stellaris_Devices#Supported_Priority_Values

    So, setting the Hwi priority to “1” results in the Hwi being treated as a zero-latency interrupt, which will *not* be handled by the Hwi dispatcher.  So with this priority, the ISR cannot call a SYS/BIOS API like Event_post().  If you change the Hwi priority to one of the valid priorities listed above then it should work, and there should be no preemption of the Hwi to execute the Task.

    Hope this is it…

    Scott

  • Scott, That last post worked like a charm.

    Thanks for all the help.

    BEST REGARDS!