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.

RTOS/LAUNCHXL-F28379D: Swi issue, bad context error.

Part Number: LAUNCHXL-F28379D

Tool/software: TI-RTOS

Hello,

I am trying to add very simple Swi in RTSC project. I added idle function and swi in *.cfg file. Here is my code:

/*
 *  ======== main.c ========
 */
#include <xdc/cfg/global.h>
#include <xdc/std.h>

#include <xdc/runtime/Error.h>
#include <xdc/runtime/System.h>

#include <ti/sysbios/BIOS.h>

#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Swi.h>


Void swiFxn(UArg a0, UArg a1)
{
    System_printf("enter swiFxn()\n");

    System_printf("exit swiFxn()\n");

    System_flush(); /* force SysMin output to console */
}

Void idleFxn()
{
    Swi_post(swi0);
    //Task_sleep(1000);
}

/*
 *  ======== main ========
 */
Int main()
{ 
    System_printf("enter main()\n");

    BIOS_start();    /* does not return */
    return(0);
}

And here is log from a Console:

[C28xx_CPU1] enter main()
enter swiFxn()
exit swiFxn()
ti.sysbios.gates.GateMutex: line 99: assertion failure: A_badContext: bad calling context. See GateMutex API doc for details.
xdc.runtime.Error.raise: terminating execution

I have no idea why it doesn't work.

Any help appreciated.

BR,

Dawid.

  • Hi Dawid,

    What system provider are you using in the .cfg? For example

    System.SupportProxy = SysMin;

    I'm going to assume you are using SysMin....

    When System_flush is called and SysMin is the underlying proxy, the characters that were written to the internal SysMin buffer are flushed to the CCS console. The API to do this is HOSTwrite in the compiler's RTS library. Since TI-RTOS kernel uses the compiler's RTS, it plugs in a locking mechanism for thread-safety. By default we plug in a GateMutex. The HOSTwrite uses this lock. Since you are calling the System_flush from a Swi (not a task), you are getting the assert.

    If you are using SysStd, the problem happens in the System_printf since HOSTwrite is called then.

    So the short answer is not call System_flush from a Hwi or Swi...only from main() or a Task.

    Todd
  • Hello,

    you were right. I used SysMin. When I use flush in idle it's working.