brilliantdt wrote on Friday, May 01, 2015:
void ISR_Bp1(void)
{
static portBASE_TYPE xHigherPriorityTaskWoken1;
xHigherPriorityTaskWoken1 = pdFALSE;
portBASE_TYPE isr1 = xSemaphoreGiveFromISR( xBinarySemaphore1, &xHigherPriorityTaskWoken1 );
if(isr1==pdTRUE)
{
USART_Write(AT91C_BASE_US0, 0xe1, 0);
}
LED0_ON;
}
void ISR_Bp2(void)
{
static portBASE_TYPE xHigherPriorityTaskWoken2;
xHigherPriorityTaskWoken2 = pdFALSE;
portBASE_TYPE isr2 = xSemaphoreGiveFromISR( xBinarySemaphore2, &xHigherPriorityTaskWoken2 );
if(isr2==pdTRUE)
{
USART_Write(AT91C_BASE_US0, 0xf1, 0);
}
LED0_OFF;
}
static void vLED0Task( void *pvParameters )
{
while(1)
{
if( xSemaphoreTake(xBinarySemaphore1,portMAX_DELAY) == pdTRUE)
{
USART_Write(AT91C_BASE_US0, 0xee, 0);
}
}
}
static void vLED1Task( void *pvParameters )
{
while(1)
{
if( xSemaphoreTake(xBinarySemaphore2,portMAX_DELAY) == pdTRUE)
{
USART_Write(AT91C_BASE_US0, 0xff, 0);
}
}
}
int main(void)
{
ConfigureUsart0();
PIO_Configure(pins, PIO_LISTSIZE(pins));
USART_Write(AT91C_BASE_US0, 0x11, 0);
ConfigureButtons();
ConfigureLeds();
vSemaphoreCreateBinary( xBinarySemaphore1 );
vSemaphoreCreateBinary( xBinarySemaphore2 );
portBASE_TYPE flagLED0 = xTaskCreate( vLED0Task, ( signed portCHAR * )"LED0", configMINIMAL_STACK_SIZE, NULL, vLED0Task_PRIORITY, NULL );
if(flagLED0 == pdTRUE)
{
USART_Write(AT91C_BASE_US0, 0x22, 0);
}
USART_Write(AT91C_BASE_US0, 0x12, 0);
portBASE_TYPE flagLED1 = xTaskCreate( vLED1Task, ( signed portCHAR * )"LED1", configMINIMAL_STACK_SIZE, NULL, vLED1Task_PRIORITY, NULL );
if(flagLED1 == pdTRUE)
{
USART_Write(AT91C_BASE_US0, 0x23, 0);
}
USART_Write(AT91C_BASE_US0, 0x13, 0);
vTaskStartScheduler();
// Main loop
while (1) {
}
}
As you can see, after I create binary xBinarySemaphore1 and xBinarySemaphore2 in the main function, the two tasks can respectively take these two semaphores. However, after I give semaphores using xSemaphoreGiveFromISR() in the two ISR functions(I am sure that the interrupt handlers respond because LEDO is ON or OFF ,and different byte is transmitted with USART), the task vLED0Task and vLED1Task can not take the semaphores. What is wrong with my codes? Thanks a lot!