Lab 4
Code for ECE 474 lab4
lab4rt3.ino File Reference

Code for Task RT-3+4. More...

#include <arduinoFFT.h>
#include <Arduino_FreeRTOS.h>
#include "queue.h"

Macros

#define RAND_SIZE   128
 Size of the random array size. More...
 
#define TIME_SIZE   5
 Size of the size of the time array. More...
 
#define STACK_SMALL   128
 Size of the stack size 1. More...
 
#define RAND_MIN   -32000
 Minimum number for creating a random number. More...
 
#define RAND_MAX   32000
 Maximum number for creating a random number. More...
 

Functions

void RT3p0 (void *pvParameters)
 Function to run task RT3p0. More...
 
void RT3p1 (void *pvParameters)
 Function to run task RT3p1. More...
 
void RT4 (void *pvParameters)
 Function to run task RT-4. More...
 
void setup ()
 Funciton to setup RtOS tasks. More...
 
void loop ()
 

Variables

arduinoFFT FFT = arduinoFFT()
 Create FFT object. More...
 
const double signalFrequency = 1000
 frequency (Hz) of the FFT signal More...
 
const double samplingFrequency = 5000
 frequency (Hz) of the FFT sample More...
 
const uint8_t amplitude = 100
 amplitude of the FFT signal More...
 
const uint16_t samples = RAND_SIZE
 numbers of samples for the FFT More...
 
double vReal [samples]
 sample arrays real part More...
 
double vImag [samples]
 sample arrays imaginary part More...
 
double rand_array [RAND_SIZE]
 random array RT-3 sent to More...
 
double store_rand [RAND_SIZE]
 random array RT-4 received from More...
 
unsigned long time_array [TIME_SIZE]
 time array that each FFT takes to compute that RT-4 will sent back More...
 
unsigned long store_time [TIME_SIZE]
 time array that each FFT takes to compute that RT-3 will receive once RT-4 sent back More...
 
unsigned long start_time
 time indicator that the FFTs started to compute More...
 
unsigned long end_time
 time indicator that the FFTs completed to compute More...
 
unsigned long duration
 time indicator that each FFT takes to compute More...
 
QueueHandle_t xQueue1
 FreeRTOS Queue for RT3p0. More...
 
QueueHandle_t xQueue2
 FreeRTOS Queue shared between RT-3 and 4. More...
 

Detailed Description

Code for Task RT-3+4.

Author
Fusco Li, Eric Yu
Date
10-June-2022

The program to use FreeRTOS library to generates an array of N pseudo-random 16-bit ints doubles and initializes a FreeRTOS Queue. The it will have the queue to sent and recive data between task RT-3 and 4, which does the following invovlving FFT :

  1. Has a loop so that it can run this 5 times
  2. send/recieve data between RT-3 and RT-4 using FreeRTOS
  3. Block and wait for the FFT to complete. Using the 2nd, RT-4 should signal back when it is done with the FFT
  4. compute FFT
  5. Report back on terminal using serial communication on how much total time to sent/recive and compute the FFT of the random buffer

Macro Definition Documentation

◆ RAND_MAX

#define RAND_MAX   32000

Maximum number for creating a random number.

◆ RAND_MIN

#define RAND_MIN   -32000

Minimum number for creating a random number.

◆ RAND_SIZE

#define RAND_SIZE   128

Size of the random array size.

◆ STACK_SMALL

#define STACK_SMALL   128

Size of the stack size 1.

◆ TIME_SIZE

#define TIME_SIZE   5

Size of the size of the time array.

Function Documentation

◆ loop()

void loop ( )

◆ RT3p0()

void RT3p0 ( void *  pvParameters)

Function to run task RT3p0.

This task would create a RAND_SIZE number random array in rand_array. Then it will use FreeRTOS xQueueCreate function. to create a queue on xQueue1. It then uses FreeRTOS's xTaskCreate() function to create task RT3p1 's function and then stop itself using vTaskSuspend

Parameters
pvParametersparameters that FreeRTOS can pass in

◆ RT3p1()

void RT3p1 ( void *  pvParameters)

Function to run task RT3p1.

This task would sent back rand_array pointer to the data into xQueue1 using the FreeRTOS xQueueSendToBack() function. in a loop that repeats TIME_SIZE times then it will use xQueueReceive() to receive store_time pointer with portMAX_DELAY delay to back and wait. Then it use serial to print out the the time to compute FFT in another loop that repeats TIME_SIZE times

Parameters
pvParametersparameters that FreeRTOS can pass in
See also
RT4

◆ RT4()

void RT4 ( void *  pvParameters)

Function to run task RT-4.

This task first stores the time it started each loop in start_time . It will recieve the store_rand pointer from xQueue1 using the xQueueReceive() function. It then loop samples of times to fill the vReal and vImag part of the FFT and compute the ramdom buffer. It recorde another time mark end_time and using the difference between start_time and end_time to compute amount of time it took to compute th FFT and store this value into duration . It put each of such variable into time_array and report its pointer back to xQueue2 using xQueueSendToBack()

Parameters
pvParametersparameters that FreeRTOS can pass in
See also
RT3p1
https://raw.githubusercontent.com/kosme/arduinoFFT/master/Examples/FFT_01/FFT_01.ino

◆ setup()

void setup ( )

Funciton to setup RtOS tasks.

Setup serial communication method and creat RTOS tasks. Set the priority of each task as well as its size.

Variable Documentation

◆ amplitude

const uint8_t amplitude = 100

amplitude of the FFT signal

◆ duration

unsigned long duration

time indicator that each FFT takes to compute

◆ end_time

unsigned long end_time

time indicator that the FFTs completed to compute

◆ FFT

arduinoFFT FFT = arduinoFFT()

Create FFT object.

◆ rand_array

double rand_array[RAND_SIZE]

random array RT-3 sent to

◆ samples

const uint16_t samples = RAND_SIZE

numbers of samples for the FFT

◆ samplingFrequency

const double samplingFrequency = 5000

frequency (Hz) of the FFT sample

◆ signalFrequency

const double signalFrequency = 1000

frequency (Hz) of the FFT signal

◆ start_time

unsigned long start_time

time indicator that the FFTs started to compute

◆ store_rand

double store_rand[RAND_SIZE]

random array RT-4 received from

◆ store_time

unsigned long store_time[TIME_SIZE]

time array that each FFT takes to compute that RT-3 will receive once RT-4 sent back

◆ time_array

unsigned long time_array[TIME_SIZE]

time array that each FFT takes to compute that RT-4 will sent back

◆ vImag

double vImag[samples]

sample arrays imaginary part

◆ vReal

double vReal[samples]

sample arrays real part

◆ xQueue1

QueueHandle_t xQueue1

FreeRTOS Queue for RT3p0.

◆ xQueue2

QueueHandle_t xQueue2

FreeRTOS Queue shared between RT-3 and 4.