samic45mit wrote on Friday, November 09, 2018:
I want to create BinarySemaphore for uart ISR. I create two task “handler_task1” , “perodic_task2”.
1.“handler_task1” is for uart ISR and it take BinarySemaphore for UART isr.
2.“perodic_task2” is run in 700 ms and it transmit “Periodic task running” form UART, it work well until any interrupt come on rx of uart. If even a single interrupt come them there is no response on hyper terminal. and even perodic_task2 also stop sending message on terminal and led blink is also stop (connected on port c).
Free rtos setting are same, as come in example code from freertos
So please help to solve this issue
/******************************* //Microcontroller-- atmega32 //Complier --WINAVR 20100110 ,AVR STDIO 7 //CRESTAL FREQ-11.0592Mhz //free rtos version-- FreeRTOS V9.0 //uart board rate-9600 //Memory uses, output window //Program Memory Usage : 5598 bytes 17.1 % Full //Data Memory Usage : 1665 bytes 81.3 % Full *******************************/ # include #include #include #include #include #include #include "uart.c" #include "uart.h" #include "FreeRTOS.h" #include "task.h" #include "queue.h" #include "list.h" #include "semphr.h" #define mainMY_TASK_PRIORITY (tskIDLE_PRIORITY + 3) /* The period between executions of the check task. */ #define mainCHECK_PERIOD (( portTickType ) 30 / portTICK_RATE_MS ) unsigned char blink=0x00; //variable for led blink connected on PORTC SemaphoreHandle_t xBinarySemaphore; //Semaphore variable //char reci,Temp; //not used ISR(USART_RX_vect) // ISR { //Temp=UDR; //reci = Temp; //UART_TxChar('R'); xSemaphoreGiveFromISR( xBinarySemaphore,NULL); //give semaphore to handler task "handler_task1" } #if (configUSE_IDLE_HOOK == 1) /* * The idle hook is used to scheduler co-routines. */ void vApplicationIdleHook(void); #endif static void handler_task1( void *pvParameters); //uart interrupt handler task, this take semaphore static void perodic_task2( void *pvParameters); //This print "Periodic task running" on hypertermical in every 700ms int main(void) { PORTC=0XFF; //for blinking led, connected on PORT C DDRC=0XFF; //Create binary semaphore vSemaphoreCreateBinary( xBinarySemaphore ); UART_init(); //Init UART,BOUD RATE 9600,rx interrupt enable sei(); //Enable interrupt if(xBinarySemaphore!=NULL) //If semaphore not created,don't start scheduler { xTaskCreate( handler_task1,(signed portCHAR * ) "handler_task1",configMINIMAL_STACK_SIZE, NULL,2, NULL ); //UART interrupt handler task, this take semaphore xTaskCreate( perodic_task2,(signed portCHAR * ) "perodic_task2",configMINIMAL_STACK_SIZE, NULL,1, NULL ); //periodic task, this run continuously in 700ms vTaskStartScheduler(); } while (1) { ; } } //This task never run, when a single character come form uart isr it stop perodic_task2 also static void handler_task1( void *pvParameters ) { //The parameters are not used. for( ;; ) { xSemaphoreTake( xBinarySemaphore,portMAX_DELAY); UART_TxChar('A'); //when interrupt come, print A,B on hyper terminal UART_TxChar('B'); } } //It run but when ever rx interrupt come it stop and nothing come on hyper terminal static void perodic_task2( void *pvParameters ) { /* The parameters are not used. */ (void) pvParameters; portTickType xLastWakeTime; xLastWakeTime = xTaskGetTickCount(); for( ;; ) { PORTC=blink; //blink led, connected on port c blink=~blink; send_string("Periodic task running"); //Send data on serial port UART_TxChar('\r'); UART_TxChar('\n'); vTaskDelayUntil( &xLastWakeTime, (700 / portTICK_RATE_MS ) ); //Here the task execute in 700ms } } #if (configUSE_IDLE_HOOK == 1) void vApplicationIdleHook( void ) { //vCoRoutineSchedule(); } #endif