Lab 2: Multi-task calculations

Contents

Contents. 2

Setup. 2

Description. 2

Hints for using the AXI Timer to measure time. 2

Hints for calculation with tasks. 2

General remarks. 2

Results required to complete the exercise. 2

Change history. 2

Setup

For this lab, you will need a Xilinx Zybo Z7-20 FPGA Board and a USB cable. Connect the USB cable to the PC and the Zybo Z7-20 board to connector PROG/UART. With this cable, the programming of the FPGA will be done, as well as serial communication between the board and PC.

Description

In this lab you will perform the following calculation:

for M=1000000 and q=π/2.

You have to compare the calculation speed using the following software approach:

1.      No RTOS operation system, simple main() function.

2.      RTOS and calculations distributed between N tasks (N=1…5).

Write a SINGLE function, which can be run from main() or from tasks. This function should read the argument (for example a structure), where the start and the end of calculation index i is given, as well as the address where to store the result.

First perform calculation without freeRTOS and measure the time of the calculation. Then run the same calculation under freeRTOS with N=1…5 number of tasks. Distribute equally the calculations between the tasks. Write the software in such a way, so changing a single #define will result in running 0...N tasks, for example:

#define NO_OF_TASKS    0 // calculation without FreeRTOS

#define NO_OF_TASKS    1 // calculation with one task under FreeRTOS

#define NO_OF_TASKS    2 //calculation with two concurrently running tasks under FreeRTOS

...

#define NO_OF_TASKS    5 //calculation with five concurrently running tasks under FreeRTOS

You should measure the time using the hardware AXI timer, that you have added during building the system. Time measurment should include the time of creating worker tasks, as well as distrubuing calculations among tasks and summing the result 

Always check the result of the calculation with the expected result. The expected result for M®µ is S(q)=.

Hints for using the AXI Timer to measure time

To use the timer, the following description can be very helpful (the functions are not complete):

·      Include the header with timer’s driver functions:

#include "xtmrctr.h"

·      Declare global variable representing the hardware timer instance:

XTmrCtr globTimerInstance;

·      Initialize the variable and connect it with the hardware timer:

XTmrCtr_Initialize(…)

Do not forget to check the result of this function (success/failure).

·      Configure the timer to auto-reload (macro XTC_AUTO_RELOAD_OPTION), using the function:

XTmrCtr_SetOptions(…)

·      Finally reset and start the hardware timer:

XTmrCtr_SetResetValue()
XTmrCtr_Reset()
XTmrCtr_Start()

·      Then you can capture the current state of the timer using the function:

u32 t1 = XTmrCtr_GetValue(&globTimerInstance, …);

·      The ticks can be converted to seconds using the information about the tick frequency from macro XPAR_TMRCTR_0_CLOCK_FREQ_HZ.

Hints for calculation with tasks

·      Create main task, then in this task create N worker tasks that will perform their part of the calculation

·      Create the array of structures, each structure should contain the data for a single worker task. Fill this array with appropriate start and end index for each task. Pass the structures to the worker tasks, as the parameter of the task. Use the same structure for collecting the results from the workers.

·      Use the functions ulTaskNotifyTake() and xTaskNotifyGive() for inter-task communication:

·      First delcare the global variable:

TaskHandle_t globTaskToNotify;

·      In the main task, assign to this variable the handle of the main task:

globTaskToNotify = xTaskGetCurrentTaskHandle();

·      Each worker task, after finishing its calculations, should communicate this to the main task using function:

xTaskNotifyGive(globTaskToNotify);

·      The main task should wait for the signals from worker tasks using the function:

ulTaskNotifyTake( pdFALSE, portMAX_DELAY );

·      Remeber, to read the information regarding floating point operations and printing on the console.

·      To measure the time, run the same calculations several time (3-5 times) and use the average time as calculation time.

Results required to complete the exercise

1.      Present the operation of your software for calculation without freeRTOS and with freeRTOS.

2.      Prove, that the obtained result is correct.

3.      Measure the calculation times for each calculation setup (N=0,1,2,3,4,5 tasks) and present the graph showing the calculation time in percentage. In this way you will see how much overhead is required by freeRTOS.

Change history

Adaptation to version Vivado 2018.3: M. Wójcikowski (08/2020).