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 calling Semaphore_pend() within a function called by a Task function

Other Parts Discussed in Thread: SYSBIOS

Hi,

I have a task function which does a Semaphore_pend() and a Clock Swi handler which does a Semaphore_post() as follows:

void clock_isr()
{
   Semaphore_post(sem);
}

void task_func()
{
   while(1) {
      Semaphore_pend(sem, BIOS_WAIT_FOREVER);
   }
}

This works fine. When I use the debugger, I see that Semaphore_post() and Semaphore_pend() are called alternatively.

Now, I change my code so that instead of having the Semaphore_pend() in the task function directly, I have it in some other function called by the task function as follows:

void clock_isr()
{
   Semaphore_post(sem);
}

void test()
{
   while(1) {
      Semaphore_pend(sem, BIOS_WAIT_FOREVER);
   }
}

void task_func()
{
   test();
}

In this case, I get the following data abort error:

ndle: 0x8001fb68.
Swi stack base: 0x8001d2c8.
Swi stack size: 0x2000.
R0 = 0x8001fb98 R8 = 0x8001d024
R1 = 0x00000000 R9 = 0x8001d238
R2 = 0x6000011f R10 = 0x00000006
R3 = 0x80019260 R11 = 0x8001d020
R4 = 0x00000000 R12 = 0x00000000
R5 = 0x00000000 SP(R13) = 0x8001f1c8
R6 = 0x00000001 LR(R14) = 0x8000b070
R7 = 0x8001fbb8 PC(R15) = 0x8000ab28
PSR = 0xa000019f
ti.sysbios.family.arm.exc.Exception: line 176: E_dataAbort: pc = 0x8000ab28, lr = 0x8000b070.
xdc.runtime.Error.raise: terminating execution

Can anyone point out why this is happening ? 

Thanks !

  • Hello,

    Can you tell me which software versions (CCS, BIOS, etc...) you are using?

    Nothing is jumping out at me about your code. Please take a look at the following wiki page for tips on decoding exception dumps

    http://processors.wiki.ti.com/index.php/SYS/BIOS_FAQs#ExceptionDumpDecodingAnchor

    Also, have you tried using the ROV tool in CCS? Going to the BIOS section and looking at the "Scan for errors..." might help. Check Clock, Semaphore, and Task too to make sure items you've created are all present and look fine.

    - Whitney

  • Hi Whitney,  I'm using CCS version 5.3.0.00090 and SYS/BIOS version 6.34.02.18.

    Maybe this other issue I'm facing may throw some light:

    I understand that Sempahore_pend(sem, BIOS_NO_WAIT) can be called from any thread (Hwi, Swi, main, etc..), while Semaphore_pend(sem, BIOS_WAIT_FOREVER) can only be called from a Task thread.

    The problem is: in my case, Sempahore_pend(sem, BIOS_NO_WAIT) is working if I call it from the test() function (which is called by a task thread), but Semaphore_pend(sem, BIOS_WAIT_FOREVER) in test() gives me the data abort error..

    Do you think it has anything to do with the MMU module configuration ?

    Thanks for your reply !

  • Hi Whitney, 

    As you suggested, I used the ROV tool  and saw the below messages in the 'Scan for errors' tab of the BIOS section after the program crashed:

    ,ti.sysbios.BIOS,Module,N/A,N/A,Caught exception in view init code: "C:/ti/xdctools_3_24_05_48/packages/xdc/rov/StructureDecoder.xs", line 544: java.lang.Exception: Target memory read failed at address: 0x0, length: 4This read is at an INVALID address according to the application's section map. The application is likely either uninitialized or corrupt.

    ,ti.sysbios.knl.Clock,Module,N/A,N/A,Caught exception in view init code: "C:/ti/xdctools_3_24_05_48/packages/xdc/rov/StructureDecoder.xs", line 517: java.lang.Exception: Target memory read failed at address: 0x2e636478, length: 8This read is at an INVALID address according to the application's section map. The application is likely either uninitialized or corrupt.

    Could you please explain on what they could mean ?

    Thanks !

  • Thanks for the additional info. I forgot to ask--what device are you using?

    It sounds like it might be a problem with your Clock instance judging by the facts that the exception happened in Swi context, the error in ROV refers to the Clock module, and the Semaphore_pend() doesn't fail without a timeout. Are you able to look at the Clock module in ROV? Did you try to decode the exception dump using the link I posted to find out where the exception may have occurred?

    How are you creating the Clock and Semaphore?

    Thanks,

    Whitney

  • I'm using a beaglebone with an ARM Cortex A8 processor.

    The clock module looks fine in the ROV:

    And here's the exception dump:

    I'm creating the Clock and Semaphore dynamically during run-time:

    Clock_Params clock_params;
    Error_Block eb;
    Error_init(&eb);
    Clock_Params_init(&clock_params);
    clock_params.period = 1000;
    clock_params.startFlag = FALSE;
    Clock_Handle clock = Clock_create(&clock_isr, 1000, &clock_params, &eb);

    Semaphore_Params sem_params;
    Semaphore_Params_init(&sem_params);
    sem_params.mode = Semaphore_Mode_BINARY;
    Semaphore_Handle sem = Semaphore_create(0, &sem_params, NULL);

  • Check the value of sem to make sure the create isn't returning NULL. Also, pass it &eb instead of NULL and see if that helps.

    Semaphore_Handle sem = Semaphore_create(0, &sem_params, &eb);

    if (sem == NULL) {

        System_printf("Semaphore_create() failed!");

    }

    Whitney

  • Hi Whitney,

    Passing in &eb in the create function solved the problem. Didn't think that would matter that much..

    Thanks for the help !