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.

problem of create SWI in code

Other Parts Discussed in Thread: CCSTUDIO

Hi,

I have some trouble in my project about creating SWI in my code rather than insert  SWI in dsp/bios tcf .

Description:

in the swi.h , there have define some structs like:

typedef struct SWI_Obj {
    Int         lock;
    Ptr         ready;
    Uns         mask;
    Ptr         link;
    Uns         initkey;
    Uns         mailbox;
    FXN_Obj     fxnobj;
    Int         stslock;
    STS_Obj     *sts;           /* pointer to STS_Obj */
} SWI_Obj;

typedef struct SWI_Obj *SWI_Handle;

typedef struct SWI_Attrs {
    SWI_Fxn     fxn;
    Arg         arg0;
    Arg         arg1;
    Int         priority;
    Uns         mailbox;
} SWI_Attrs;

Now, here is my code:

#include<stdio.h>

#include<log.h>
#include<swi.h>
#include<sys.h>
#include "switestcfg.h"

void swiFxn3(void);

 SWI_Handle swi;
 SWI_Attrs *attrs;

void main()

{ SWI_Attrs nmm = {(SWI_Fxn)swiFxn3,0,0,3,0};
 attrs = &nmm;
 swi=SWI_create(attrs);
 SWI_post(swi);

}

void swiFxn3()
{
 LOG_printf(&trace,"it's my interrupt\n");
}

I find that  it doesn't go to the LOG_printf(); in the other word, the swi may not be create successful .

please help me ,and tell me how to do for this. and if something I  neglect ?

  • Hi zhengwen,

    Please take a look at the file:

    C:\CCStudio_v3.3\bios_5_33_06\packages\ti\bios\examples\advanced\msgq_swi2swi\msgq_swi2swi.c

    It creates a SWI from main as you did, and it can help find the issue.

  • Hello,

     

    I run your code, and:

    First of all, the interrupt does happen, if you put a breakpoint in it you will see. But this is in my project.

    Second, the LOGprintf is not working, and I dont think it suppose to. That is, I think, because (let the TI support guys correct me on this one if I am wrong) You are using it in main, that is before the DSP BIOS was initialized. The LOGprintf is a function of DSP BIOS, and when I think of it the SWI module is also belongs to DSP BIOS.

    So, open a task, write a function in it, and I think it will work this way.

     

    Regards

    Arye

     

  • Arye,

    Arye Lerner said:
    That is, I think, because (let the TI support guys correct me on this one if I am wrong) You are using it in main, that is before the DSP BIOS was initialized. The LOGprintf is a function of DSP BIOS, and when I think of it the SWI module is also belongs to DSP BIOS.

    The LOG_printf might not work on main, but the LOG_printf is not really in main, but inside the SWI. And the SWI will only be called after main. The LOG_printf inside the SWI function should work.

    zhengwen,

    Try putting a break point as Arye suggested to see if is the SWI that is not being called or the LOG_printf that is not working.

    http://tiexpressdsp.com/wiki/index.php?title=DSP_BIOS_FAQ#Q:_How_can_I_convert_printf.28.29_statements_to_LOG_printf.28.29.3F

     

     

     

  • Hi,

    I have a try as you suggested to putting a break point , then I find that it doesn't work. the swiFxn3() is not called .

    Is there something wrong?

  • Hello

    Do You have software interrupts enabled? this is SWI_enable() function.

    Can You open a task, that will be executed first thing after main? I want to see if you are getting there. If you do, please try to call an SWI from there. I know that support guys told us that this should work anyway, I am just think that maybe you have some problem in DSP BIOS initialization.

    I am having a problem in recreating your problem. I tried to activate your code and it is worked, then I put a " while(1); " loop at the end of the main, and it didnt. That is because I didnt get out of main, and DSPBIOS is not initialized yet.

    If the CPU stop executing code after exit from main, initiates the DSP/BIOS and then proceeds with code execution, this problem should not happen. But if your software interrupt pops in the middle of DSP BIOS execution, that is, i think, maybe what causes the problem. I am guessing this, since I dont know how it really works.

    Anyway, I would suggest that you include the next modules when using DSP BIOS:

    #include <clk.h>
    #include <log.h>
    #include <hwi.h>
    #include <swi.h>
    #include <tsk.h>
    #include <std.h>

    I always include them, since it costs nothing, and it is recommended to include them in example projects.

     

    Regards

    Arye

     

     

  • Can You open a task, that will be executed first thing after main? I want to see if you are getting there. If you do, please try to call an SWI from there. I know that support guys told us that this should work anyway, I am just think that maybe you have some problem in DSP BIOS initialization.

    Yes, I have followed  your suggestion. I open a task ,and it can be executed after main, then i call an swi from there.but, i found that it didn't  enter to my function "void swiFxn3" as I  call swi in main, not to mention executeing "LOG_printf()" in the swiFxn3. If I insert swi in dsp/bios tcf, it can work well.

    So, now I am sure the problem is in creating swi in code .BUT ,but I cann't find where is wrong?

    Do You have software interrupts enabled? this is SWI_enable() function.

    in my opinion, it doesn't need to call swi_enable(), because when I insert swi in dsp/bios tcf, then insert  "swi_post(&**)" ,it can work well without using swi_enable().

    At last, thanks to your patience!!

    Regards

    zhengwen.zhang

  • I think your issue is due to the lack of a correct heap configuration for BIOS.  If you look at the return value of SWI_create, I assume it's not being created correctly.

    I just wrote this wiki page to give the proper steps for configuring BIOS to allow dynamic creation of threads/objects:

    http://wiki.davincidsp.com/index.php/Creating_Dynamic_Objects_and_Threads_in_BIOS

  • Brad Griffis

    Thank you very very very much! I figure out the problem followed your suggestion.

    regards

    zhengwen.zhang