sasikalaswathi wrote on Monday, November 11, 2019:
Attached the code for reference.
void vTaskFunction1(void);
void vTaskFunction2(void);
void vTaskFunction3(void);
BaseType_t xReturned,xReturned1,xReturned2;
SemaphoreHandle_t UARTAccess,UARTAccess1;
char rec_data;
int main(void)
{
UARTAccess=xSemaphoreCreateBinary();
if (UARTAccess!=NULL)
{
xReturned =xTaskCreate( vTaskFunction1, “Task 1”, 512,NULL, 1, NULL );
xReturned1=xTaskCreate( vTaskFunction2, “Task 2”, 512, NULL, 1, NULL );
xReturned2=xTaskCreate( vTaskFunction3, “Task 3”, 512, NULL, 2, NULL );
if(xReturned==1&& xReturned1==1 && xReturned2==1)
{
vTaskStartScheduler();
}
}
else
{
// created semaphore was null
// printf();
}
}
void vTaskFunction1( void)
{
for(;
{
if(xSemaphoreTake(UARTAccess,10))
{
// HAL_GPIO_WritePin(GPIOE,GPIO_PIN_10,1);
printf(“Task1-get\n”);
}
else
{
printf("Task1-not get\n");
}
}
}
void vTaskFunction2( void)
{
for(;
{
if(xSemaphoreTake(UARTAccess,10))
{
// HAL_GPIO_WritePin(GPIOE,GPIO_PIN_10,0);
printf(“Task2-get\n”);
}
else
{
printf("Task2-not get\n");
}
}
}
void vTaskFunction3( void)
{
BaseType_t give_result;
for(;;)
{
give_result=xSemaphoreGive( UARTAccess);
if( give_result != pdTRUE )
{
// printf(“semaphore not given:%ld\n”,give_result);
}
else
{
printf(“semaphore given:%ld\n”,give_result);
}
}
}