Guidance regarding Task and it's priorities

Hi Everyone,
I am new in RTOS, I am currently working on a project in which I use freeRTOS. In the project there is 2 SPI (in which 1 is used for EEPROM and 1 is used for DISPLAY); 4 UARTS (in which 3 work on MODBUS protocol); 7 channels of ADC; PWM; Timmer Interrupts; 1 Keypad; watchdog; RTC; and GPIO’s included. I interface these with Nuvoton M453 mcu.

Can anyone guide me on some points that I listed below

  1. For these how many numbers of tasks can I created which runs the code smoothly.
  2. How can I set the priority as I check the MAX_SIZE is only 4.
  3. How can I give size for each task that created.
  4. Is there any instructions or recommendations where these all describes.
  5. Can I run some part in main while loop or rest in tasks created while loop.
  6. Which is better to use (mutex, semaphore and task notify)
  7. Can I start or stop tasks from interrupt
  8. How can I manage these all with RTOS.
  9. Can anyone share me some reference or example code that can I prefer and code easily.

Thanks, in advanced, Kindly help me as I am new and gets confused.

That depends a lot on your application design. You may consider one task per peripheral.

What is MAX_SIZE? The maximum number of task priorities are configured using configMAX_PRIORITIES.

Remaining of your questions are about basic understanding of FreeRTOS. I’d recommend going through the following resources:

Hi aggarg,

#define configMAX_PRIORITIES ( 4 )
#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 4
#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 0xf

priority is set on the behalf of hardware interrupt and here in config.h here is the parameters.

configMAX_PRIORITIES is for task priorities and it does not depend on the hardware interrupt priorities. You can change it to a higher number if you need more task priorities.

okay, after defining numbers of priorities, I can create as many tasks as I want to run each peripheral, is there any size dependencies for each task.

As I create 12 tasks, but the code is not working but if I comment 2 or 3 tasks then code working fine.

Probably you‘re running of (heap) memory.
Did you define configASSERT properly and even more important do you check the return values of the FreeRTOS-API calls like xTaskCreate ?
It’s also good habit to also define configCHECK_FOR_STACK_OVERFLOW and maybe configUSE_MALLOC_FAILED_HOOK, too.
See e.g. Customization - FreeRTOS™
for further details.

Also, make it a habit to check the return value of EVERY FreeRTOS API call.

Hi,

yes, I define configASSERT as per the example provided by freeRTOS and also return values of the freeRTOS-API calls but how can I know it’s out of heap memory.

E.g. xTaskCreate - FreeRTOS™ doc tells:
Returns:

  • If the task was created successfully then pdPASS is returned.
  • Otherwise errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY is returned.

(The malloc failed hook would also be invoked if configured as mentioned.)