Hi,
I have created 3 tasks and two queues.
Here is the initialization for tasks and queues. I am using STM32 microcontroller and eclipse IDE.
int main(void)
{
Queue01Handle = osMessageQueueNew(256, sizeof(uint8_t),&Queue01_attributes);
qGpsHandle = osMessageQueueNew(256, sizeof(uint8_t),&qGps_attributes);
if(Queue01Handle == NULL)
{
ConsolePrint("Queue01Handle Failed\r\n");
}
else
{
ConsolePrint("Queue01Handle Created\r\n");
}
if(qGpsHandle == NULL)
{
ConsolePrint("qGpsHandle Failed\r\n");
}
else
{
ConsolePrint("qGpsHandle Created\r\n");
}
/* creation of defaultTask_LED */
defaultTask_LEDHandle = osThreadNew(LED_Task_Default, NULL, &defaultTask_LED_attributes);
/* creation of Sender1 */
Sender1Handle = osThreadNew(UART3RxFrameProcess, NULL, &Sender1_attributes);
/* creation of Receiver1 */
Receiver1Handle = osThreadNew(UART2TxSend_Task, NULL, &Receiver1_attributes);
/* Start scheduler */
osKernelStart();
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
}
//Here is my ISR code. It receives a byte of data from uart peripheral and sends to UART3RxFrameProcess task. The UART3RxFrameProcess task receives the byte of data and keeps it in a buffer. The frame is correctly received in Queue01Handle.
When the frame is ready UART3RxFrameProcess task has to sent the buffer to another task UART2TxSend_Task using qGpsHandle . But UART2TxSend_Task is not receiving the data in qGpsHandle.
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
char GpsRxByte;
static portBASE_TYPE xHigherPriorityTaskWoken;
GpsRxByte = GpsUart.RxByte;
xHigherPriorityTaskWoken = pdFALSE;
xQueueSendFromISR(Queue01Handle, &GpsRxByte,&xHigherPriorityTaskWoken);
HAL_UART_Receive_IT(&huartGps, (uint8_t *)&GpsUart.RxByte, 1); //Restart receive interrupt
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
void UART2TxSend_Task(void *argument)
{
char *pGpsRxData=NULL;
for(;;)
{
if(pdTRUE == xQueueReceive(qGpsHandle, &pGpsRxData , 100))
{
ConsolePrint((char *)pGpsRxData);
}
}
osDelay(1);
}
void UART3RxFrameProcess(void *argument)
{
/* USER CODE BEGIN Sender1_Task Sender1Handle */
char GpsRxByte;
const GPS_MESSAGE *pGpsRxData = NULL;
/* Infinite loop */
for(;;)
{
/*Process the UART */
if(pdPASS == xQueueReceive(Queue01Handle, &GpsRxByte, 100))
{
if(GpsUart.RxCount >= 1024)//Overflow judgment
{
GpsUart.RxCount = 0;
memset(GpsUart.RxBuffer,0x00,sizeof(GpsUart.RxBuffer));
HAL_UART_Transmit(&huartSerial, (uint8_t *)&cAlmStr, sizeof(cAlmStr),0xFFFF);
}
else
{
switch(GpsUart.RxFrameState)
{
case UART_FRAME_IDLE :
if((GpsRxByte == GpsUart.RxStartByte1) || (GpsRxByte == GpsUart.RxStartByte2))
{
GpsUart.RxCount = 0;
GpsUart.RxBuffer[GpsUart.RxCount++] = GpsRxByte;
GpsUart.RxFrameState = UART_FRAME_START;
}
else
{
}
break;
case UART_FRAME_START :
if((GpsRxByte == GpsUart.RxEndByte1) || (GpsRxByte == GpsUart.RxEndByte2))
{
GpsUart.RxBuffer[GpsUart.RxCount++] = GpsRxByte;
GpsUart.RxFrameState = UART_FRAME_READY;
memset(GpsMsg.Data,0x00,sizeof(GpsMsg.Data));
strcpy(GpsMsg.Data, (char *)GpsUart.RxBuffer);
pGpsRxData = (GPS_MESSAGE *)&GpsMsg.Data;
ConsolePrint((char *)pGpsRxData);
xQueueSend(qGpsHandle, &pGpsRxData, 100);
memset(GpsUart.RxBuffer,0x00,sizeof(GpsUart.RxBuffer));
}
else
{
GpsUart.RxBuffer[GpsUart.RxCount++] = GpsRxByte;
}
break;
default :
GpsUart.RxFrameState = UART_FRAME_IDLE;
break;
}
}
}
}
osDelay(1);
}
Let me know any thing is required in UART2TxSend_Task.