UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

Adam Taylor’s MicroZed Chronicles Part 45: FreeRTOS—creating our own tasks

by Xilinx Employee on ‎08-18-2014 11:27 AM (34,246 Views)

 

By Adam Taylor

 

 

Having successfully got the FreeRTOS demo up and running on the Zynq-based MicroZed board in the last blog, we obviously want to be able to write our own application. So our first example will be simple. We’ll configure the Zynq SoC’s XADC and output results over a serial link. The application will also check the received value and if that value is above a predefined level, the code will light an LED as an alert. In future blogs, this example will enable us to look at how we can communicate this information between tasks and deliver a more complex application.

 

The first stage of code development is to create a function that can be called to initialize the XADC before we start the RTOS scheduler. This will allow us to use the XADC in one of the two tasks we will be using for this example. The function will be a standard one like those we have created many times before in this series.

 

This example will use two tasks. The first will read the XADC temperature and adds the obtained value to the queue. The second task reads the value from the queue and performs the temperature check. For this application, this second task will also output data over the serial link so that we can see what is occurring. These two tasks will demonstrate how we can communicate with hardware peripherals within the Zynq SoC, using one task to obtain values from the hardware and then using those obtained values in a second task. Inter-task communication is a key aspect of using an RTOS in an embedded system.

 

Rather helpfully the FreeRTOS demo code comes with two examples: the full demo and a much simpler blinking demo. The blinking LED demo is controlled by setting the pre-processor declaration within main.c:

 

 

#define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY     1

 

 

Setting this flag and rebuilding the application results in a simple example that blinks the MicroZed’s on-board LED. It does this by passing data between two tasks at a predefined rate using a queue. This code is almost exactly what we require for our purposes, so this simple demo code gives us a useful starting point for the application code we wish to develop.

 

As mentioned above the first thing we need to create is a configuration routine to initialize the Zynq SoC’s XADC for use. Remember to add the required include files and declarations needed to access the Zynq SoC’s XADC. We have done this several times over the course of this blog so it should be second nature to you now.

 

The next step is to modify the transmitting task to read the XADC temperature and to put the retrieved value on the queue to be read by the receiving process. The code to do that looks like this:

 

 

static void prvQueueSendTask( void *pvParameters )

{

TickType_t xNextWakeTime;

unsigned long ulValueToSend = 100UL;     

      ( void ) pvParameters;

      xNextWakeTime = xTaskGetTickCount();

      printf("task tx");

      for( ;; )

      {

            vTaskDelayUntil( &xNextWakeTime, mainQUEUE_SEND_FREQUENCY_MS );

            ulValueToSend = XAdcPs_GetAdcData(&XADCInst, XADCPS_CH_TEMP);

     

            xQueueSend( xQueue, &ulValueToSend, 0U );

      }

}

 

 

The receiving process takes this value from the queue. We can then compare the received value against the expected value and toggle the LED if the received value exceeds the expected value:

 

 

static void prvQueueReceiveTask( void *pvParameters )

{

unsigned long ulReceivedValue;

unsigned long ulExpectedValue = 43000;

      ( void ) pvParameters;

      printf("task rx");

      for( ;; )

      {

            xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY );

            printf("Raw Value = %lu", ulReceivedValue);

            if( ulReceivedValue == ulExpectedValue )

            {

                  vParTestToggleLED( mainTASK_LED );

                  ulReceivedValue = 0U;

            }

      }

}

 

 

As can be seen above this very simple approach will be able to light the LED should the temperature go above an alarm value. However, in many cases this will result in a chattering LED because a borderline temperature value will quickly vacillate above and below the threshold. We fix this problem by introducing hysteresis so that the LED only turns off once the temperature has dropped by a sufficient amount to stop oscillation.

 

 

 

 

Please see the previous entries in this MicroZed series by Adam Taylor:

 

 

Adam Taylor’s MicroZed Chronicles Part 44: MicroZed Operating Systems—FreeRTOS

 

Adam Taylor’s MicroZed Chronicles Part 43: XADC Alarms and Interrupts 

 

Adam Taylor’s MicroZed Chronicles MicroZed Part 42: MicroZed Operating Systems Part 4

 

Adam Taylor’s MicroZed Chronicles MicroZed Part 41: MicroZed Operating Systems Part 3

 

Adam Taylor’s MicroZed Chronicles MicroZed Part 40: MicroZed Operating Systems Part Two

 

Adam Taylor’s MicroZed Chronicles MicroZed Part 39: MicroZed Operating Systems Part One

 

Adam Taylor’s MicroZed Chronicles MicroZed Part 38 – Answering a question on Interrupts

 

Adam Taylor’s MicroZed Chronicles Part 37: Driving Adafruit RGB NeoPixel LED arrays with MicroZed Part 8

 

Adam Taylor’s MicroZed Chronicles Part 36: Driving Adafruit RGB NeoPixel LED arrays with MicroZed Part 7

 

Adam Taylor’s MicroZed Chronicles Part 35: Driving Adafruit RGB NeoPixel LED arrays with MicroZed Part 6

 

Adam Taylor’s MicroZed Chronicles Part 34: Driving Adafruit RGB NeoPixel LED arrays with MicroZed Part 5

 

Adam Taylor’s MicroZed Chronicles Part 33: Driving Adafruit RGB NeoPixel LED arrays with the Zynq SoC

 

Adam Taylor’s MicroZed Chronicles Part 32: Driving Adafruit RGB NeoPixel LED arrays

 

Adam Taylor’s MicroZed Chronicles Part 31: Systems of Modules, Driving RGB NeoPixel LED arrays

 

 Adam Taylor’s MicroZed Chronicles Part 30: The MicroZed I/O Carrier Card

 

Zynq DMA Part Two – Adam Taylor’s MicroZed Chronicles Part 29

 

The Zynq PS/PL, Part Eight: Zynq DMA – Adam Taylor’s MicroZed Chronicles Part 28  

 

The Zynq PS/PL, Part Seven: Adam Taylor’s MicroZed Chronicles Part 27

 

The Zynq PS/PL, Part Six: Adam Taylor’s MicroZed Chronicles Part 26

 

The Zynq PS/PL, Part Five: Adam Taylor’s MicroZed Chronicles Part 25

 

The Zynq PS/PL, Part Four: Adam Taylor’s MicroZed Chronicles Part 24

 

The Zynq PS/PL, Part Three: Adam Taylor’s MicroZed Chronicles Part 23

 

The Zynq PS/PL, Part Two: Adam Taylor’s MicroZed Chronicles Part 22

 

The Zynq PS/PL, Part One: Adam Taylor’s MicroZed Chronicles Part 21

 

Introduction to the Zynq Triple Timer Counter Part Four: Adam Taylor’s MicroZed Chronicles Part 20

 

Introduction to the Zynq Triple Timer Counter Part Three: Adam Taylor’s MicroZed Chronicles Part 19

 

Introduction to the Zynq Triple Timer Counter Part Two: Adam Taylor’s MicroZed Chronicles Part 18

 

Introduction to the Zynq Triple Timer Counter Part One: Adam Taylor’s MicroZed Chronicles Part 17

 

The Zynq SoC’s Private Watchdog: Adam Taylor’s MicroZed Chronicles Part 16

 

Implementing the Zynq SoC’s Private Timer: Adam Taylor’s MicroZed Chronicles Part 15

 

MicroZed Timers, Clocks and Watchdogs: Adam Taylor’s MicroZed Chronicles Part 14

 

More About MicroZed Interrupts: Adam Taylor’s MicroZed Chronicles Part 13

 

MicroZed Interrupts: Adam Taylor’s MicroZed Chronicles Part 12

 

Using the MicroZed Button for Input: Adam Taylor’s MicroZed Chronicles Part 11

 

Driving the Zynq SoC's GPIO: Adam Taylor’s MicroZed Chronicles Part 10

 

Meet the Zynq MIO: Adam Taylor’s MicroZed Chronicles Part 9

 

MicroZed XADC Software: Adam Taylor’s MicroZed Chronicles Part 8

 

Getting the XADC Running on the MicroZed: Adam Taylor’s MicroZed Chronicles Part 7

 

A Boot Loader for MicroZed. Adam Taylor’s MicroZed Chronicles, Part 6 

 

Figuring out the MicroZed Boot Loader – Adam Taylor’s MicroZed Chronicles, Part 5

 

Running your programs on the MicroZed – Adam Taylor’s MicroZed Chronicles, Part 4

 

Zynq and MicroZed say “Hello World”-- Adam Taylor’s MicroZed Chronicles, Part 3

 

Adam Taylor’s MicroZed Chronicles: Setting the SW Scene

 

Bringing up the Avnet MicroZed with Vivado

 

Comments
by Explorer
on ‎08-18-2014 11:58 AM

hi

 

nice blog, but we can make the some example with standalone application; so we still save the light of execution on processor, because FreeRTOS will occupate resource, but not for this application.

 

Adam, are you use 1 CPU for this example ?

 

 

thank you 

Labels
About the Author
  • Be sure to join the Xilinx LinkedIn group to get an update for every new Xcell Daily post! ******************** Steve Leibson is the Director of Strategic Marketing and Business Planning at Xilinx. He started as a system design engineer at HP in the early days of desktop computing, then switched to EDA at Cadnetix, and subsequently became a technical editor for EDN Magazine. He's served as Editor in Chief of EDN Magazine, Embedded Developers Journal, and Microprocessor Report. He has extensive experience in computing, microprocessors, microcontrollers, embedded systems design, design IP, EDA, and programmable logic.