2019-05-18 02:49 AM
Hi guys
Can any one provide me how to use queue inside UART ISR receive interrupt....
I have tried it using some web search but I couldn't achieve it can any one provide me the working example. below, I have attached my code and the image where my code got struck any one help me to find out the solution to my problem Iam using keil ide with FreeRTOS and stm32f429igt6 controller
xQueueHandle xQueue;
void USART_Configuration(void);
uint8_t uart_getchar(void);
void USART1_IRQHandler(void)
{
uint8_t ch;
if (USART_GetITStatus(USART1, USART_IT_RXNE)) {
ch = USART1->DR;
rxbuf1[rxptrh1++] = ch;
}
if (USART_GetITStatus(USART1, USART_IT_TXE)) {
if (txlen1) {
txlen1--;
USART1->DR = *txptr1++;
}
if (!txlen1) {
USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
}
}
// taskYIELD();
}
void USART6_IRQHandler(void)
{
uint8_t ch;
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
if (USART_GetITStatus(USART6, USART_IT_RXNE)) {
ch = USART_ReceiveData(USART6);
rxbuf2[rxptrh2++] = ch;
if(ch == '\n')
{
xTaskResumeFromISR(receiver_task);
}
}
if (USART_GetITStatus(USART6, USART_IT_TXE)) {
if (txlen2) {
txlen2--;
USART6->DR = *txptr2++;
}
if (!txlen2) {
USART_ITConfig(USART6, USART_IT_TXE, DISABLE);
}
}
taskYIELD();
}
void uart_send2(uint8_t *buf, uint32_t len)
{
txptr2 = buf;
txlen2 = len;
USART_ITConfig(USART6, USART_IT_TXE, ENABLE);
}
void uart_send1(uint8_t *buf, uint32_t len)
{
txptr1 = buf;
txlen1 = len;
USART_ITConfig(USART1, USART_IT_TXE, ENABLE);
}
void publisher_task(void *pvParameter)
{
uint8_t* counter;
char data1[5];
for(;;)
{
if(xQueue != NULL){
xQueueReceive(xQueue,&counter,portMAX_DELAY);
uart_send2(counter,5);
TM_DelayMillis(500);
uart_send2("hai\r\n",5);
TM_DelayMillis(500);
}
else
{
uart_send2("Queue is not ready\n",25);
TM_DelayMillis(500);
}
}
}
void receiver_task(void *pvParameter){
while(1){
uart_send2("Inside queue\r\n",14);
TM_DelayMillis(500);
xQueueSend( xQueue, &rxbuf1, 10 );
vTaskSuspend(receiver_task);
}
}
int main(void)
{
SystemInit();
Gpio_init();
TM_Delay_Init();
USART_Configuration();
xQueue = xQueueCreate( 256,1);
if( xQueue != NULL )
{
uart_send2("Queue is created\n",20);
TM_DelayMillis(500);
xTaskCreate(publisher_task,"producer_task",600,NULL,2,NULL);
xTaskCreate(receiver_task,"Receiver_task",600,NULL,4,NULL);
vTaskStartScheduler();
}
else{
uart_send2("Queue creation failed\n",20);
TM_DelayMillis(500);
}
while (1)
{
}
}
2023-05-18 09:30 AM
@AChan.15 did you get this resolved eventually? I am facing a similar issue
2023-05-18 10:22 AM
Post your code, explain what you are TRYING to do, what steps you've taken to debug it and what is or isn't happening. The code from the original post is so horribly broken it isn't worth referencing.
And using an RTOS queue for incoming UART data SOUNDS like a good idea but isn't always the best approach.