/******************************* //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
BinarySemaphore is not working form UART ISR of atmega32
I want to create BinarySemaphore for uart ISR. I create two task “handlertask1″ , “perodictask2″.
1.”handler_task1″ is for uart ISR and it take BinarySemaphore for UART isr.
2.”perodictask2″ 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 perodictask2 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
BinarySemaphore is not working form UART ISR of atmega32
The vSemaphoreCreateBinary() macro has been deprecated in favor of the xSemaphoreCreateBinary() function (https://www.freertos.org/xSemaphoreCreateBinary.html) – however in this case a direct to task notification would be a lighter weight alternative https://www.freertos.org/RTOS-task-notifications.html .
Does your interrupt work without the semaphore give, or indeed without using FreeRTOS (that is, do we know this is actually a FreeRTOS issue?). After a quick look and compare to https://sourceforge.net/p/freertos/code/HEAD/tree/trunk/FreeRTOS/Demo/AVRATMega323WinAVR/serial/serial.c my first guess would be that you are not clearing the interrupt, probably by reading the character from the UART, so you may just be re-entering the interrupt continuoulsy and in so doing preventing any other code from running. If you pause the debugge, what is executing?
Have you checked you have enough stack space, etc.?
BinarySemaphore is not working form UART ISR of atmega32
I try to replase vSemaphoreCreateBinary with xSemaphoreCreateBinary but I get complier error “SemaphoreCreateBinary undecleared”
I also get a warning– Warning pointer targets in passing argument 2 of ‘xTaskGenericCreate’ differ in signedness”
And yes interrupt lib is working fine without freertos. so this not interrupt re entering probleum. And I am not using any debugger so it is not possible to see the stack size.
the probleum come when any single character is recivied on UART and interrupt come.
BinarySemaphore is not working form UART ISR of atmega32
I try to replase vSemaphoreCreateBinary with xSemaphoreCreateBinary butThis won’t make any different to the issue – it’s just the newer function.
I get complier error “SemaphoreCreateBinary undecleared”Spelling mistake?
I also get a warning– Warning pointer targets in passing argument 2 of ‘xTaskGenericCreate’ differ in signedness”That is because the prototype is different, one is a macro and the other a function – take a look at the API docs on the website or in the code.
And yes interrupt lib is working fine without freertos. so this not interrupt re entering probleum. And I am not using any debugger so it is not possible to see the stack size. the probleum come when any single character is recivied on UART and interrupt come.Did you try my suggestion of stopping the debugger after the issue occurs to see what code is executing? As before, it might just be that you are not clearing the interrupt, as the code you posed does not seem to read the character.
BinarySemaphore is not working form UART ISR of atmega32
Thank’s for replay and giving your time
I try counting semafore and it work. but as you say it is comming again and again and told my lib is working fine without rtos. So please tell how to solve this.
Did you try my suggestion of stopping the debugger after the issue
occurs to see what code is executing? As before, it might just be that
you are not clearing the interrupt, as the code you posed does not seem
to read the character.—-
at presently I am not reading any character but just genrating interrupt when character come.and I don’t have any debugger so I con’t tell what is happing when this probleum ocure.
BinarySemaphore is not working form UART ISR of atmega32
at presently I am not reading any character but just genrating interrupt when character come.Which is what I said could be the source of your problem.
and I don’t have any debugger so I con’t tell what is happing when this probleum ocure.You are best placed to know what is going on on your hardware, and your work will be much faster and efficient if you have the necessary tools – a debugger being the minimum necessary tool.