Software Architecture- Handling System state machine task with other event tasks

Like to discuss on Software Architecture for an Embedded system based on FreeRTOS. I like to know how to handle main system states along with the other system tasks like key task, uart task and gui task.
For Example: I have created different tasks like,

  1. State machine task - shared task, 1st high priority task, with Queue
  2. Key task - 2nd high priority task. Once key pressed, get the correct key pressed and send message to state machine task to change system state which in turn send message to Gui task to display
  3. Uart receive task - medium priority task. Once message received in uart rx buffer, send message to state machine task to change system state which in turn send message to gui task to display
  4. GUI Task - shared task, low priority task with queue

Now, lets consider a scenario where UART medium priority task has sent 3 messages to state machine task queue. Before processing all 3 messages, now a high priority key task is sending message to queue. Now only after all 3 msgs of uart is handled, then key task message will be handled by state machine task.
Is this the right mechanism in handling system states and task events or there any efficient design pattern for this scenario. Please clarify.

Depends on what your design goals are. If user responsiveness is higher on your must list than data processing throughput, that looks acceptable.

The big question is does a single ‘State Machine Task’ fill the needs of your system.

That it has different ‘priority’ messages seems to imply that it is doing a number of things that might make more sense as separate operations.