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.

RTOS/TMS570LS3137: Can't "take" a semaphore in freeRTOS

Part Number: TMS570LS3137
Other Parts Discussed in Thread: HALCOGEN

Tool/software: TI-RTOS

I have been playing with tasks in freeRTOS, experimenting with notification events and event groups - I got both of those to work (notification works if I bracket the calls to make them privileged) - I found that event groups appear to be faster than notifications, which surprised me.  I've subsequently been trying to use binary semaphores without any success.  Specifically, it seems I cannot "take" the semaphore - I see that they are actually implemented as queues.   I've boiled it down to this simple sample program, which gets stuck with the "sender task" trying to take the semaphore:

/** @file sys_main.c 
*   @brief Application main file
*   @date 02-Mar-2016
*   @version 04.05.02
*
*   This file contains an empty main function,
*   which can be used for the application.
*/

/* 
* Copyright (C) 2009-2016 Texas Instruments Incorporated - www.ti.com 
* 
* .
* .
* .
*
*/


/* USER CODE BEGIN (0) */

/* USER CODE END */

/* Include Files */

#include "sys_common.h"

/* USER CODE BEGIN (1) */
#include <stdio.h>
#include <freeRTOS.h>
#include "os_task.h"
#include "os_semphr.h"

/* USER CODE END */


/* USER CODE BEGIN (2) */


int receiver_task_can_run = 0;

SemaphoreHandle_t start_semaphore = 0;
SemaphoreHandle_t stop_semaphore = 0;

void sender_task(void *p)
{

bool semaphore_take_return = pdFALSE;

semaphore_take_return = pdFALSE;
while (semaphore_take_return == pdFALSE) {
semaphore_take_return = xSemaphoreTake(start_semaphore,200);
if (pdFALSE == semaphore_take_return) printf("sender thread can't get start semaphore\n");
else printf("sender TOOK start_semaphore\n");
};

receiver_task_can_run = 1;

while(1) {};
}


void receiver_task(void *p)
{
int keepGoing = 1;
bool semaphore_take_return = pdFALSE;

vTaskDelay(2000); // let's not get ahead of the sender

while (0 == receiver_task_can_run) {
vTaskDelay(10);
}

while(1 == keepGoing){
//
BaseType_t xRunningPrivileged = prvRaisePrivilege();
semaphore_take_return = pdFALSE;
while (semaphore_take_return == pdFALSE) {
semaphore_take_return = xSemaphoreTake(start_semaphore,2000);
if (pdFALSE == semaphore_take_return) printf("receiver thread can't get start semaphore\n");
else printf("receiver thread TOOK start semaphore\n");
};

}

}



/* USER CODE END */

void main(void)
{
/* USER CODE BEGIN (3) */
BaseType_t xReturned;

puts("this is a test\n\r");

    start_semaphore = xSemaphoreCreateBinary();
    stop_semaphore = xSemaphoreCreateBinary();

xReturned = xTaskCreate(sender_task, (const char*)"sender_task", 350, NULL, 1, NULL);
printf("sender xReturned: 0x%x\n",xReturned);

xReturned = xTaskCreate(receiver_task, (const char*)"receiver_task", 300, NULL, 1, NULL);
printf("receiver xReturned: 0x%x\n",xReturned);


vTaskStartScheduler();

/* USER CODE END */
}

/* USER CODE BEGIN (4) */
/* USER CODE END */

This is not super-critical to me since I have event groups and notifications working, but I would like to know why this doesn't work.  I am using Halcogen 04.05.02 and CCS 6.2.0.00048