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.

Semaphore in Piccolo F28035PN/CCS ver 5.1

Other Parts Discussed in Thread: SYSBIOS

 Dear support,
We work with Piccolo F28035PN card and build application with SYSBIOS(CCS ver 5.1). that use CAN peripherials. I have CAN bus HWI:

 void ECAN1Isr_prev (void) //interrupt#101
   {
          Semaphore_post(SEM_CAN_MSG_RECEIVED);
  }


and the task for receive CAN-data:
while (1)
 {  // Wait for a message to be recieved
    Semaphore_pend(SEM_CAN_MSG_RECEIVED, BIOS_WAIT_FOREVER);
   m_SemaphoreCounting++;
}

SEM_CAN_MSG_RECEIVED defined is configuration as:

var SEM_CAN_MSG_RECEIVEDParams = new Semaphore.Params();
SEM_CAN_MSG_RECEIVEDParams.instance.name = "SEM_CAN_MSG_RECEIVED";
SEM_CAN_MSG_RECEIVEDParams.mode = Semaphore.Mode_COUNTING;
Program.global.SEM_CAN_MSG_RECEIVED = Semaphore.create(0, SEM_CAN_MSG_RECEIVEDParams);

After 1-st CAN interrupt arrived  the program always increment m_SemaphoreCounting  without any relation to HWI interrupts.

What could be the reason of this strange behaviors.

Thanks,Sabina

 

  • Sabina,

    Are you saying the Semaphore_pend() is not actually pending there until the interrupt comes?

    Are you incrementing the semaphore count anywhere else?

    Judah

  • I perform POST in interrupt HWI only ( once ).
    I print semaphoreCount value in the HWI and in the task;

    HWI:
     void ECAN1Isr(void)
     {
       Semaphore_post(SEM_CAN_MSG_RECEIVED);
        int semaphoreCountVal = Semaphore_getCount(SEM_CAN_MSG_RECEIVED);
        Log_info2("ECAN1INTA_ISR start, miv = %d, semaphoreCountVal = %d", miv, semaphoreCountVal);
      }

    TASK:
    int loopCounting = 0;
    while (1)
     {
       bool semaphorePendReturnVal = Semaphore_pend(SEM_CAN_MSG_RECEIVED, BIOS_WAIT_FOREVER); 
      loopCounting++;
       int semaphoreCountVal = Semaphore_getCount(SEM_CAN_MSG_RECEIVED);
       Log_info3("loopCounting = %d, semaphorePendReturnVal = %d, semaphoreCountVal = %d", loopCounting, semaphorePendReturnVal, semaphoreCountVal);
    }

     output on the console after the 1st interrupt arrived (correct): 

    ECAN1INTA_ISR start,  semaphoreCountVal = 0
    loopCounting = 1, semaphorePendReturnVal = 1, semaphoreCountVal = 0"

    and output on the console after progtam running without additional HWI interrupts (problematic !!!!):
    loopCounting = 38761, semaphorePendReturnVal = 1, semaphoreCountVal = 0
    loopCounting = 38762, semaphorePendReturnVal = 1, semaphoreCountVal = 0

    It is not clear why Semaphore_pend(SEM_CAN_MSG_RECEIVED, BIOS_WAIT_FOREVER); return true always.

    And why semaphoreCountVal = 0 in the HWI?

    Thanks, Sabina

  • Sabina,

    When you create the Semaphore initially, does it have a value of 0?

    There's no logical explanation for your problem.  If Semaphore_pend() is not functioning properly, it needs to be determined why? It could be the Semaphore count is getting corrupted by something else.  Yes a value of 0 for the semaphore count in Hwi definitely points to some problem already because a post should have incremented the value.

    Judah

  • Hi Judah,

    Thanks for the reply. I found the source of the problem. I had two different interrupts with the same function that perform Semaphore_post().

    Thanks a lot, Sabina