element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Personal Blogs
  • Community Hub
  • More
Personal Blogs
Legacy Personal Blogs Hercules LaunchPad and freeRTOS: Tasks, Messages & Queues
  • Blog
  • Documents
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 21 Sep 2015 7:21 PM Date Created
  • Views 1090 views
  • Likes 3 likes
  • Comments 1 comment
  • hercules_launchpad
  • rtos
  • texas_instruments
  • freertos
  • feature_tutorial
Related
Recommended

Hercules LaunchPad and freeRTOS: Tasks, Messages & Queues

Jan Cumps
Jan Cumps
21 Sep 2015

I'm playing around with RTOS these days. I've set up a small project on a Texas Instruments Hercules LaunchPad to try out tasks and messaging.

 

Don't expect anything complex. This is a minimal setup that allows me to exchange info between RTOS tasks. The simplicity of the example makes it easy to see what's happening.

 

This video is unavailable.
You don't have permission to edit metadata of this video.

 

The Project

 

 

We'll have an RTOS message queue, and 3 RTOS tasks that communicate via that queue.

image

2 tasks will write info to the queue, each at its own tempo.

1 task will poll the queue constantly, consume every message from that queue and do something with it.

Of course, that something is 'Blink a LED' image.

 

 

Porting freeRTOS to the Hercules microcontroller family

 

That's easy. The HALCoGen configuration application can generate a ready-to-compile ported freeRTOS version for you.

When you create a new project, you have the choice to make that a generic project, or a freeRTOS one.
When you select the latter, the RTOS code is generated together with any peripheral driver that you configure in HALCoGen.

 

The Firmware

 

We have to include some header files for RTOS tasks and queues. And we'll define task and queue handler variables.

 

/* Include FreeRTOS scheduler files */
#include "FreeRTOS.h"
#include "os_task.h"
#include "os_queue.h"

// ...

/* Define Task Handles */
xTaskHandle xTask1Handle;
xTaskHandle xTask2Handle;
xTaskHandle xTask3Handle;
// Global Queue Handle
QueueHandle_t qh = 0;

 

 

We also define what each of these tasks do, and what their execution frequency is. You'll see that the two sending tasks #1 and #2 are almost identical

 

/* Task1 */
void vTask1(void *pvParameters)
{
    for(;;)
    {
    xQueueSend(qh, "LED1", 50);
        vTaskDelay(100);
    }
}
/* Task2 */
void vTask2(void *pvParameters)
{
    for(;;)
    {
    xQueueSend(qh, "LED2", 50);
        vTaskDelay(200);
    }
}

/* Task3 */
void vTask3(void *pvParameters)
{
    char led[5];
    for(;;)
    {
        if(xQueueReceive(qh, &led[0], 1000)) { // we don't need to use a vTaskDelay here - we'll sleep 1000 ms if queue is empty

            if (!strcmp(led, "LED1")) {
                gioSetBit(gioPORTB, 6, gioGetBit(gioPORTB, 6) ^ 1);
            }
            if (!strcmp(led, "LED2")) {
                gioSetBit(gioPORTB, 7, gioGetBit(gioPORTB, 7) ^ 1);
            }
       }
    }
}

 

In the main function, we initialise our queue, register the tasks and kick off the RTOS scheduler. That's it. All the rest is magic.

Tasks 1 and 2 will start filling the queue with their messages. Task 3 will poll that queue, and execute its actions every time a value is available on that queue.

 

void main(void)
{
  // ...
  qh = xQueueCreate(5, 5);

    /* Create Task 1 */
    if (xTaskCreate(vTask1,"Task1", configMINIMAL_STACK_SIZE, NULL, 1, &xTask1Handle) != pdTRUE)
    {
        /* Task could not be created */
        while(1);
    }

    /* Create Task 2 */
    if (xTaskCreate(vTask2,"Task2", configMINIMAL_STACK_SIZE, NULL, 1, &xTask2Handle) != pdTRUE)
    {
        /* Task could not be created */
        while(1);
    }

    /* Create Task 3 */
    if (xTaskCreate(vTask3,"Task3", configMINIMAL_STACK_SIZE, NULL, 1, &xTask3Handle) != pdTRUE)
    {
        /* Task could not be created */
        while(1);
    }

    /* Start Scheduler */
    vTaskStartScheduler();

    /* Run forever */
    while(1);
  // ...
}

 

 

The result,as can be seen in the video at the top of this blog, is that the two LEDs flash. Each at its own pace. The LED1 will flash twice as fast as LED2, because Task2 asks to be woken up after a twice as long pause as Task1.

Of course, that's not a scenario where you would involve an RTOS. But an example of how the pieces integrate. You can see and understand how tasks, a scheduler and a queue cooperate.

 

reference and thank you: http://www.socialledge.com/sjsu/index.php?title=FreeRTOS_Tutorial

  • Sign in to reply
Parents
  • DAB
    DAB over 9 years ago

    Nice update.

     

    The code for RTOS looks fairly simple.

     

    I definitely need to find some time to get familiar with the it for my TI boards.

     

    DAB

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • DAB
    DAB over 9 years ago

    Nice update.

     

    The code for RTOS looks fairly simple.

     

    I definitely need to find some time to get familiar with the it for my TI boards.

     

    DAB

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube