Hi,
I am working on Queues. I am facing this problem with priority assignment of the tasks.
Problem statement
I have created two sender tasks (SenderTask1 and SenderTask2) and one receiver task. The code is working fine if the receiver task has higher priority and sendertask1 (normal priority) and sendertask2 has below normal priority.
This means I have assigned three different priorities for three tasks. This is all about working code and here is the code and its related output screen shot.
#include "main.h"
#include "cmsis_os.h"
UART_HandleTypeDef huart2;
osThreadId Sender1Handle;
osThreadId Sender2Handle;
osThreadId ReceiverHandle;
osMessageQId Queue1Handle;
int main(void)
{
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART2_UART_Init();
/* USER CODE BEGIN 2 */
printf("Application start\r\n");
/* Create the thread(s) */
/* definition and creation of Sender1 */
osThreadDef(Sender1, StartSender1, osPriorityBelowNormal, 0, 512);
Sender1Handle = osThreadCreate(osThread(Sender1), NULL);
/* definition and creation of Sender2 */
osThreadDef(Sender2, StartSender2, osPriorityNormal, 0, 512);
Sender2Handle = osThreadCreate(osThread(Sender2), NULL);
/* definition and creation of Receiver */
osThreadDef(Receiver, StartReceiver, osPriorityAboveNormal, 0, 512);
ReceiverHandle = osThreadCreate(osThread(Receiver), NULL);
/* Create the queue(s) */
/* definition and creation of Queue1 */
osMessageQDef(Queue1, 256, uint8_t);
Queue1Handle = osMessageCreate(osMessageQ(Queue1), NULL);
/* Start scheduler */
osKernelStart();
while(1)
{
}
}
For Not working code
The only difference is priorities and here are the three lines that are not working. When the sender task1 and sender task 2 is having same priority what is happening?
/* Create the thread(s) */
/* definition and creation of Sender1 */
osThreadDef(Sender1, StartSender1, osPriorityNormal, 0, 512);
Sender1Handle = osThreadCreate(osThread(Sender1), NULL);
/* definition and creation of Sender2 */
osThreadDef(Sender2, StartSender2, osPriorityNormal, 0, 512);
Sender2Handle = osThreadCreate(osThread(Sender2), NULL);
/* definition and creation of Receiver */
osThreadDef(Receiver, StartReceiver, osPriorityAboveNormal, 0, 512);
ReceiverHandle = osThreadCreate(osThread(Receiver), NULL);
Any one can discuss this problem and how to solve this issue. what is the problem with the priority. Can both sender tasks cannot have same priority and why the receiver task has to be highest priority than sender tasks.