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.

SWI argument runtime modification in SYS/BIOS

hello everybody,

i am trying to invoke a Swi function many times, every time with a different argument. I created my SWI statically in the cfg file.

How can i change the argument in the runtime code ? i tried mySWI.arg0 = ....; and mySwiParams.arg0 = .....; but in vain ( i included global.h to get globals from cfg file).

If possible can you give me further explanation about args in SYS/BIOS, i can't understand their concept yet. can we pass variable names to the arg parameter in the cfg file?

thanks

  • Hi Mohammed,

    When a Swi is created, you specify two arguments that will be passed to the Swi function (which you also specify) when it runs. Those args (like the function) cannot be changed after the create. For example, if you create a Swi instance and arg0 = 3, arg1 = 0x8f000000 and the function is mySwi.

    Void mySwi(UArg arg0, UArg arg1)
    {
    ...
    }

    When this Swi instance runs, arg0 will always 3 and arg1 will always be 0x8f000000.

    In my example above, I specified a pointer. You are free to change the contents of the memory that the pointer is pointing to. For example, let's say the pointer is actually a variable (e.g. mySwiStruct1) that is pointing to the structure below.

    typedef struct MySwiStruct {
        UInt cmd;
        Ptr buffer;
        SizeT size;
    } MySwiStruct;
    MySwiStruct mySwiStruct1;

     main()
    {
         ...      
         Swi_Params swiParams; 
       
         Swi_Params_init(&swiParams); 
         swiParams.arg0 = &mySwiStruct1;  
         swi1 = Swi_create(swi1Fxn, &swiParams, NULL);

    You could do the following before you posted the Swi

         mySwiStruct1.cmd    = SOME_ENUM;
         mySwiStruct1.buffer = someBuffer;
         mySwiStruct1.size   = SOME_SIZE;
         Swi_post(swi1);

    Now when the function runs, I can cast the arg0 to a MySwiStruct pointer and act on the cmd, buffer, size as needed. Note: you need to make the reading and writing of the mySwiStruct1 thread safe. You could disable interrupts or Swi's while reading and writing.

    Also note, you can create another Swi instance with the same function, but different args. This allows you to have 1 function that behaves differently based on the args.

         Swi_Params swiParams; 
       
         Swi_Params_init(&swiParams); 
         swiParams.arg0 = SCALE1;  
         swi1 = Swi_create(mySwi, &swiParams, NULL); 
         swiParams.arg0 = SCALE2;  
         swi2 = Swi_create(mySwi, &swiParams, NULL);

    Void mySwi(UArg arg0, UArg arg1)
    {
        ...
        output = arg0 * something_interesting;   
    }

    I hope that helps,
    Todd

  • I asked this question a few months ago (http://e2e.ti.com/support/embedded/f/355/p/94340/328848.aspx).

     

    The supported method is to recreate the SWI with the new arguments:

    pswi    = Swi_getFunc (pHandle->hSwi [ii], NULL, NULL);

    Swi_Params_init (&params);

    params.priority    = Swi_getPri (pHandle->hSwi [ii]);
    params.arg0        = arg0;
    params.arg1        = arg1;

    Swi_construct (Swi_struct (pHandle->hSwi [ii]), pswi, &params, NULL);

    If you're feeling adventurous, you can #define a symbol before including the header file:

    #define     ti_sysbios_knl_Swi__internalaccess
    #include    <ti/sysbios/knl/Swi.h>
    

    and then directly access the argument members:

    swi->arg0 = newarg0;

    swi->arg1 = newarg1;

     

    Peter