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.

SEM_post not working although not called within an hwi

Hello,

 

I have a problem with a semaphore post function.

I am working with tci6482 board and CCS 3.2.

I have a multitasking project where the tasks get created dynamically.

Inside one of these tasks I am calling the SEM_post function (the semaphores are also created dynamically) which normally should increase the semaphore value

but it doesn't.

What might be the reasons?  I already checked if the task has a stack overflow but everything is fine.

 

  • What version of bios are you using?

    Did you declare you sem_handles as globals? If you declare as locals you might have problems. Have you tried to move the SEM_create to main and see if it works?

  • Hi Mariana,

     

    I am using the bios version 5.21. The semaphore handles are global.

    I think I have found the reason for my problem.

    What happens if the semaphore value is 0 and you call sem_post and another task is waiting on this semaphore?

    Will the semaphore increased by 1 or will it still be 0? What is the right behaviour here?

    In my situation the semaphore is still 0, but the same semaphore can be increased at another point by another Tasks.

    Hope it is not too confusing.

  • It is a bit confusing. If you do a post, and a pend immediately follows, you might not even have time to see the the count increasing. If the SEM_pend is working, I guess this is the case.

  • Maybe this makes it easier. This is the situation where I want to call the sem_post for 0xe0010c5c. You can see that there is a task (mac (0XE0010D0C) )pending on that semaphore. I put a breakpoint at "SEM_post(*sem);" and did one step, but the semaphore didn't increased its value. Is it because of the pending task?

    int sem_post(sem_t *sem)
    {
        int i = SEM_count(*sem);
        t = TSK_self();
        SEM_post(*sem);
        if(i < SEM_count(*sem)){
            LOG_printf(&trace,"Sem_post succeeded Task: %s -> %x\n",t->name, *sem);
            return 0;
        }else{
            LOG_printf(&trace,"Sem_post failed Task: %s -> %x\n",t->name, *sem);
            return -1;
            }
    }

    Server Data Copy:

    DSP/BIOS
    Name, Count
    KNL, -
    Name, System Time, Start of Stack, Size of Stack, Stack Peak
    KNL, 11822, 0xe3440000, 0x7fff, 0xffffffff
    TSK, -
    Name, Handle, State, Priority, Timeout, Time Remaining, Blocked On, Start of Stack, Size of Stack, Stack Peak
    Ul_Sched_Worker, 0xe001414c, Ready, 3, 0, 0, , 0xe00141a0, 0x1000, 0x60
    Dl_Sched_Worker, 0xe0011f94, Running, 3, 0, 0, , 0xe0011fe8, 0x2000, 0x48c
    mac, 0xe0010d0c, Blocked, 3, 0, 0, SEM: 0xE0010C5C, 0xe0010d60, 0x1000, 0x81c
    LTE_TST, 0xe000b97c, Blocked, 5, 0, 0, SEM: 0xE000CA14, 0xe000b9d0, 0x1000, 0x6b4
    ConfigBoot, 0xe000a914, Terminated, 15, 0, 0, , 0xe000a968, 0x1000, 0x4b4
    0xE000A074, 0xe000a074, Blocked, 1, 0, 0, SEM: 0xE000A044, 0xe000a0c8, 0x400, 0xa8
    tskNdkStackTest, 0xe3455f78, Ready, 2, 0, 0, , 0x800000, 0x800, 0x558
    TSK_idle, 0xe3455f10, Ready, 0, 0, 0, , 0xe345b260, 0x400, 0x198
    SWI, -
    Name, Handle, State, Priority, Mailbox Value, Function, arg0, arg1, Function Address
    0xE345B8D4, 0xe345b8d4, Inactive, 1, 0, PRD_F_swi, 0x0, 0x0, 0xe3450880
    KNL_swi, 0xe345b8a8, Inactive, 0, 0, KNL_run, 0x0, 0x0, 0xe34516e0
    MBX, -
    SEM, -
    Name, Handle, Count, # Tasks Pending, Tasks Pending
    0xE0011DBC, 0xe0011dbc, 0x0, 0,
    0xE001411C, 0xe001411c, 0x1, 0,
    0xE0013FF4, 0xe0013ff4, 0x13, 0,
    0xE0010C14, 0xe0010c14, 0x1, 0,
    0xE0010BDC, 0xe0010bdc, 0x1, 0,
    0xE0010AB4, 0xe0010ab4, 0x14, 0,
    0xE0010A84, 0xe0010a84, 0x0, 0,
    0xE0010A54, 0xe0010a54, 0x0, 0,
    0xE0010CDC, 0xe0010cdc, 0x1, 0,
    0xE0010C8C, 0xe0010c8c, 0x1, 0,
    0xE0010C5C, 0xe0010c5c, 0x0, 1, mac (0XE0010D0C)
    0xE000CA14, 0xe000ca14, 0x0, 1, LTE_TST (0XE000B97C)
    0xE000C9E4, 0xe000c9e4, 0x1, 0,
    0xE000A8E4, 0xe000a8e4, 0x0, 0,
    0xE000A8B4, 0xe000a8b4, 0x1, 0,
    0xE000A884, 0xe000a884, 0x1a, 0,
    0xE000A74C, 0xe000a74c, 0x1, 0,
    0xE000A71C, 0xe000a71c, 0x1, 0,
    0xE000A6EC, 0xe000a6ec, 0x1, 0,
    0xE000A6BC, 0xe000a6bc, 0x1, 0,
    0xE000A68C, 0xe000a68c, 0x1, 0,
    0xE000A65C, 0xe000a65c, 0x1, 0,
    0xE000A62C, 0xe000a62c, 0x1, 0,
    0xE000A5FC, 0xe000a5fc, 0x1, 0,
    0xE000A5CC, 0xe000a5cc, 0x1, 0,
    0xE000A59C, 0xe000a59c, 0x1, 0,
    0xE000A56C, 0xe000a56c, 0x1, 0,
    0xE000A53C, 0xe000a53c, 0x1, 0,
    0xE000A50C, 0xe000a50c, 0x1, 0,
    0xE000A4DC, 0xe000a4dc, 0x1, 0,
    0xE000A044, 0xe000a044, 0x0, 1, 0xE000A074 (0XE000A074)
    0xE000A014, 0xe000a014, 0x1, 0,
    MEM, -
    Name, Largest Free Block, Free Mem, Used Mem, Total Size, Start Address, End Address, Mem Segment
    .data, 0x2ee8500, 0x2ee8648, 0x1179b8, 0x3000000, 0xe0000000, 0xe2ffffff, 0
    BUF, -
    SIO, -
    DEV, -

  • I'm assuming that the type sem_t you your program is equal to type SEM_Handle.

    If the other task id being called, in other words if SEM_pend is working, than it should be OK. If you post this there, and put just one SEM_pend in another task of higher priority, is SEM_pend serviced? 

  • If your sem_post() function is called from TaskA and a higher priority TaskB is pending on the semaphore that gets posted, then that TaskB will immediately come off its SEM_pend() call and start executing. This will result in the count be decremented back to 0, so TaskA would not see the count whenever it gets restarted (when TaskB pends or terminates or such).

    If you change the priorities of TaskA and TaskB so the pended TaskB is a lower priority task, then the SEM_post() call in sem_post() will return with a count of 1. Whenever TaskA gives up its execution thread, then TaskB would be able to finally come off its SEM_pend for this semaphore.

    Does this fit with what you see?

  • Yes, that's what happening.

    In my case TaskA and TaskB have the same priority. So that's the reason why I can't see the semaphore incrementing.

    Thanks for that!

    I have another question:

    Is there a possibility to debug on Task level?

    When I put a breakpoint to debug, are there still other tasks running at the background?

    Is there a possiblity to see at which code position the other tasks are waiting?

     

     

     

  • CCS v3 is generally used as a Stop Mode debugger. In this case, a breakpoint will cause all instruction execution to halt. Some peripherals may continue to run, like timers and EDMA, but no additional instructions until you tell it to Run again.

    Under Debug on the File menu, near the bottom is an option to use Real Time Mode. In this mode, hitting a breakpoint halts all non-interrupt code, but will allow interrupts to occur and ISRs to be executed. This is intended to keep a hard disk drive spinning and keep the armature from crashing when you hit a breakpoint, for example.

    But neither of these modes will allow other tasks to continue running. The only method for this is really the LOG_printf debugging you are probably doing already. Sorry.