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.

multiple semaphore

Hi,
I am new to SYS/BIOS and i have few question. I am using CCS 5.3.0.00090,
bios_6_33_06_50,mcsdk_2_01_02_06 , xdctools_3_23_04_60 and C6678 custom board.

I have created two tasks with different priority. I want to use two semaphores(sem0 and sem1) which will use two different  clock ticks(myClk0 and myClk1) for Semaphore_post(sem0 and sem1). It does not works.

The problem are as follows:

1. Semaphore 'count' doesnot seem to increment at all. Can you please let me know what's wrong am i doing here ?
2. can I use multiple semaphores for multiple tasks?

The source code is as follows :
/***********Cfg file**************************/
/*Two Semaphores are being created */
var semaphore1Params = new Semaphore.Params();
semaphore1Params.instance.name = "sem1";
Program.global.sem1 = Semaphore.create(null, semaphore1Params);
var semaphore0Params = new Semaphore.Params();
semaphore0Params.instance.name = "sem0";
Program.global.sem0 = Semaphore.create(null, semaphore0Params);

/*the stack size is also being increased*/
BIOS.heapSize = 0x2000;
/* System stack size (used by ISRs and Swis) */
Program.stack = 0x2000;
/* Circular buffer size for System_printf() */
SysMin.bufSize = 4096;

/*******************************************/

/**********  main.c  ****************/

void hardware_init(void); //customer hardware configuration
void ledTogglegreen (void); //Aplication code
void ledToggleOrange (void); //Aplication code
void hiPriTask (UArg arg0, UArg agr1);
void task (UArg arg0, UArg agr1);
Void clockHandler(UArg arg);
Void clockHandler1(UArg arg);
Clock_Params clockParams;
Clock_Params clock1Params;
Clock_Handle myClk0,  myClk1;

/**myIdleFunc**/

Void myIdleFunc()
{
 System_printf("Entering myIdleFunc(). \n");
 System_exit(0);

}

/*===========main =========*/
Void main()
{
 Task_Params taskParams;
 Task_Handle myTsk0, myTsk1;
 Error_Block eb;

 System_printf("Led Blink example Started\n");
 Error_init(&eb);

 /*Create 1 task with priority 15*/
 Task_Params_init(&taskParams);
 taskParams.stackSize = 1000;
 taskParams.priority = 15;   //high priority
 myTsk0 = Task_create ((Task_FuncPtr)hiPriTask, &taskParams, &eb);
 if (myTsk0 == NULL){
  System_abort("hiPriTask create failed");
 }

 /*create Low priority tasks with priority 1*/
 Task_Params_init(&taskParams);
 taskParams.priority =1;  // low priority task
 myTsk1 = Task_create ((Task_FuncPtr)task, &taskParams, &eb);
 if (myTsk1 == NULL){
  System_abort("LoPriTask create failed");
 }
 /*Clock tick is being introduced*/
 Clock_Params_init(&clockParams);
 clockParams.startFlag = TRUE;
 clockParams.period = 1000;
 myClk0 = Clock_create((Clock_FuncPtr)clockHandler, 1000, &clockParams, &eb);
 if(myClk0 == NULL){
   System_abort ("Clock create failed");
  }
 /*Clock tick is being introduced*/
 Clock_Params_init(&clock1Params);
 clock1Params.startFlag = TRUE;
 clock1Params.period = 500;
 myClk1 = Clock_create((Clock_FuncPtr)clockHandler1, 500, &clock1Params, &eb);
 if(myClk1 == NULL){
   System_abort ("Clock2 create failed");
  }
  /*Initializing customer hardware*/
  hardware_init();                   //customer hardware
 

   BIOS_start();
}

/*======Clock handler1 ======*/
static void clockHandler1 (UArg arg){
 Semaphore_post(sem1);
}

/*======Clock handler ======*/
static void clockHandler (UArg arg){
 Semaphore_post(sem0);
}

/*Low priority task*/
Void task(UArg argo, UArg arg1)
{
 while(1)
  {
   /*Semaphore_pend for sem1*/  
   Semaphore_pend (sem1, BIOS_WAIT_FOREVER);

  /*Toggle Led Orange*/
  ledToggleOrange(); //application code
  }
}

/*High priority task*/
Void hiPriTask(UArg arg0, UArg arg1) 
{
 while(1)
 {
  /*Semaphore_pend for Sem0*/
 Semaphore_pend (sem0, BIOS_WAIT_FOREVER);

  /*Toggle Led Green*/
  ledTogglegreen(); //application code

 }
}

  • Hi Nitish,

    Nitish Gautam said:
    1. Semaphore 'count' doesnot seem to increment at all. Can you please let me know what's wrong am i doing here ?

    Do you see your LEDs toggling? In your setup, the count won't increment. A Semaphore_pend() will block when count == 0.

    See this wiki page: http://processors.wiki.ti.com/index.php/SYS/BIOS_Training:_Semaphores

    Nitish Gautam said:
    2. can I use multiple semaphores for multiple tasks?

    Yes.

  • Hi Tom,

    Thanks for your quick response.

    Tom Kopriva said:
      Do you see your LEDs toggling? In your setup, the count won't increment. A Semaphore_pend() will block when count == 0

    As per the previous approach ; No, Led did not toggle and dsp crashes.

    But as per your suggestion i increased the semaphore count to 1 for both sem0 and sem1 as shown below: 

    /**************cfg file**********/
    
    var semaphore1Params = new Semaphore.Params();
    semaphore1Params.instance.name = "sem1";
    Program.global.sem1 = Semaphore.create(1, semaphore1Params);                   //change to 1
    var semaphore0Params = new Semaphore.Params();
    semaphore0Params.instance.name = "sem0";
    Program.global.sem0 = Semaphore.create(1, semaphore0Params);                  //change to 1

    I can see DSP led toggle two times and then it stops(i can see semaphores values changing and the moment it comes to 0 it stops).

    I have few questions regarding the above approach: 

    1. If I changed "Semaphore.create(1, semaphore0Params);"  value from 1 to any other value say (2 or 3). what will be the implication of using any other values. Can you please explain.

    2.

    2. can I use multiple semaphores for multiple tasks?

    Yes.

    can you please provide any example code where  multiple semaphores are being used.

    Thanks

    Nitish

     

     

     

  • Nitsch,

    see section 4.1 in the SYS/BIOS User's Guide. and the "Bigtime" SYS/BIOS example.