Pular para o conteúdo principal
Knowledgebase
Home
Renesas Brasil - Knowledgebase

Running Threaded Blinky on the Synergy Platform

Latest Updated:10/04/2016

Overview

Use the section below to provide a short description of the how-to article. The section is also used by other pages to provide an abstract of this page. The lead sentence should tell the reader enough about the how-to article to help them decide whether to read on or not.

This self paced learning exercise show you how to create a Blinky design (Blink an LED on your Synergy board) using a simple thread implementation. This exercise uses brief descriptions of several common actions within the tool flow. This assumes you are somewhat familiar with the various operations within e2 studio. Feel free to 'pop out' of this guide and refresh your understanding of e2 studio operations by referring to the non-threaded example designs that illustrate each step in full step-by-step detail.

Goal

Use the section below to describe the goal of the how-to. You might want to offer prerequisites that must be met before the user begins the task, such as previous how-to's, configuration or product setting requirements.

After completing this how-to you will have created a simple threaded design from scratch and can move on to more complex implementations.

Use each step section to describe the instructions needed to achieve the goal.

Initial Set-Up

You must first have the Synergy software tool flow installed and a target Synergy board available to see Blinky work in hardware. If you don't, follow the below link to the Getting Started How in the Synergy Knowledge Base.

<Getting Started with the Synergy Platform>

Create Your Project

If you followed the previous step you should have the Synergy Platform tool flow working and you should have exercised your target board, most likely with the non-threaded version of Blinky. Now you are ready for a threaded version.

  1. Open e2 studio and create a new Synergy Project (refer back to the above How To if you need a reminder).
  2. Target your board and select the BSP with Thread-X option.
  3. You should now have familiar a starting point for adding Blinky code.

Add Threaded Blinky Code

In this step you will add the code for implementing the Threaded version of Blinky.

  1. Open the Threads Tab in the Configuration Window.
  2. Click on New to bring up a New Thread.
  3. Press the Generate Project Content button.
  4. You should now have a file called new_thread_entry.c
  5. Open new_thread_entry.c and replace all the code below the first line comment with the following code:

#include <stdio.h>
#include "new_thread.h"
#include "r_ioport.h"
bsp_leds_t Leds;
void new_thread_entry(void) {
    /* Get LED information for this board */
    R_BSP_LedsGet(&Leds);
    /* If this board has no LEDs then trap here */
    if (!Leds.led_count)
    {
        while(1);    // There are no LEDs on this board
    }
    ioport_level_t level = IOPORT_LEVEL_HIGH;
    while (1) {
        /* Toggle the LED */
        level = !level;
        g_ioport_on_ioport.pinWrite(Leds.p_leds[0], level);
        /* Wait one second */
        tx_thread_sleep(100);
    }
}

  1. Save the changes to the file and build the debug configuration of your project. It may take a minute or two (or perhaps more) so be patient. Also- it may stay 'stuck' on Build Project (55%) for a while and then finish up all at once. Don;t worry if something like that happens on your design.
  2. The design should build without errors. If not, look carefully at your added code.You may have missed or added some characters. When your code builds without errors, you are ready to run threaded blinky on your target board.

Run Threaded Blinky on Your Board

  1. Connect your board as you did when running your previous example design.
  2. Initialize the Debugger and select your new project build configuration.
  3. Click the Debug button to bring up the debug perspective.
  4. The debug session will halt at the beginning of the design, so you need to press the Resume button twice to get it to begin execution on your board.
  5. Your LED should now be blinking on and off. It should stay on for 1 second and then go off for 1 second until you pause or stop the debug session.
  6. You have completed your first threaded design with Synergy!

How Threaded Blinky Works

Threaded Blinky begins operation in the thread instead of in hal_entry as you may have noticed in previous examples (such as Hal Blinky). The Blinky thread is the only one in this design, so thats were the design starts. If multipe threads existed, each would have their own starting point.

The first part of threaded Blinky code should look similar to Hal Blinky. The code determines the location of an LED on the board, and if there is an LED it starts by setting it high. The code then enters a loop that will toggle the output level 

Threaded Blinky uses the tx_thread_sleep command to wait for 1 second. The parameter passes to tx_thread_sleep is in 'ticks' which are  10ms each, thus 100 is equal to 1 sec.

What's Next

Use the section below to describe additional considerations that were omitted for brevity and to guide the reader to further how-to's.

Now that you have completed this example design here are some suggestions for building on this exercise to extend your knowledge and skills with the Synergy Platform.

  • Try the Running Blinky with a Semaphore design to learn more about threaded implementations.
  • Read more about threaded operations in the <ThreadX for the Synergy Platform> PDF book.
  • Try and modify the threaded blinky design to blink every 10 seconds. Can you make the LED stay on for 1 second out of every 10?

Please leave feedback on this article by using the feedback buttons below.