Microchip | The Embedded Control Solutions Company Register Login
Browse All
Microchip Technology
 305 Code Snippets

FreeRTOS for PIC32MM family.

Microchip Technology

The attached code consists of FreeRTOS v9.0.0 ported to PIC32MM family along with a demo. This demo has tasks to blink LEDs at different rates, task to display on LCD , Mutex tasks, Semaphore tasks and Generic queue tasks.


About this Code Example

The demo application MPLAB X and MPLAB XC32 are the preferred IDE and compiler respectively with which to build the FreeRTOS demos. This demo supports the following device:

  • A PIC32MM0256GPM064 PIM on the Exp16/32 board.

The Demo Application

Demo application hardware setup - Explorer 16/32

All the Explorer 16/32 jumpers can remain in their default positions - in particular, JP2 should be fitted to ensure correct operation of the LEDs.

Functionality

The demo application can be configured to provide very simply 'blinky' style functionality, or a full and comprehensive test and demonstration of a subset of RTOS features. The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY constant, which is #define(d) at the top of main.c, is used to switch between the two. Demo application tasks are split between standard demo tasks, and demo specific tasks. Standard demo tasks are used by all FreeRTOS port demo applications. They have no purpose other than to demonstrate the FreeRTOS API, and test a port.

When mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1
When mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1 main() calls main_blinky(). main_blinky() creates a very simple example that uses two tasks, one queue, and one software timer.

  • The Blinky Software Timer:

This demonstrates an auto-reload software timer. The timer callback function does nothing but toggle an LED.

  • The Queue Send Task:

The queue send task is implemented by the prvQueueSendTask() function. prvQueueSendTask() just sits in a loop, sending the value 100 to the queue every 200 milliseconds.

  • The Queue Receive Task:

The queue receive task is implemented by the prvQueueReceiveTask() function. prvQueueReceiveTask() sits in a loop blocking on attempts to read from the queue (no CPU cycles are consumed while it is blocked), toggling an LED each time a value is received. The queue send task writes to the queue very 200 milliseconds, so the queue receive task will unblock and toggle the LED every 200 milliseconds.

When mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0
When mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0 main() calls main_full(). main_full() creates a very comprehensive test and demo application that creates numerous RTOS tasks and software timers. The description below is correct when the demo is executed on the Explorer 16.

  • LEDs marked D3 to D5 are under control of the 'flash' software timers. Each will flash at a constant frequency, with LED D3 being the fastest and LED D5 being the slowest.
  • Most of the tasks do not update an LED so have no visible indication that they are operating correctly. Therefore a 'Check' software timer is created to monitor all the other tasks. The check software timer callback monitors the system operation every 3 seconds, then writes a PASS or FAIL message to the LCD (via the LCD task). Any failures are latched, and the message displayed indicates in which task the failure was detected .If no errors exist a PASS message is displayed that includes a count value originating from a high frequency timer. The check software timer callback also toggles LED D10. The toggle frequency will increase if an error has been detected.
  • The application also demonstrates the use of a 'gatekeeper' task, in this case an LCD gatekeeper. The LCD task is the only task that is permitted to access the LCD directly. Other tasks wishing to write a message to the LCD send the message on a queue to the LCD task instead of accessing the LCD themselves. The LCD task just blocks on the queue (so it does not consume any CPU cycles) waiting for messages - automatically unblocking and displaying the messages as they arrive.

Categories

Release History

  • Jul 25, 2017

    Version: 1.0.0

    Initial Release

Download Contact the Developer

*Required Fields

  • Current Version:1.0.0
  • Created:Jul 25, 2017
  • Updated:Aug 6, 2017
  • Downloads:4325
  • MPLAB Version:3.60
  • C Compiler:MPLAB XC16
  • Development Tools:Explorer 16/32
  • Supported Devices:PIC32MM family

Corporate News

Resources

Stay Connected

Stay up to date with the latest news from Microchip Technology.