Adam Taylor plays MicroZed: FreeRTOS

After successfully demonstrating FreeRTOS in a previous blog and running it on a Zynq-based MicroZed board, obviously we want to be able to write our own application. Therefore, we will first give a simple example. We will configure the Xynq SoC's XADC and output the results on a serial link. The application checks the received value, and if the value exceeds the preset value, the code will light the LED as an alarm.

The first step in code development is to create a function that is used to initialize the XADC before we start the RTOS scheduler. This will allow us to use XADC in one of the two tasks that run in this example. This function will be a standard function, just as we have created many times before in this series.

This example uses two tasks. The first task is to read the XADC temperature and add the obtained values ​​to the queue. The second task is to read the values ​​from the queue and perform a temperature check. In this application, the second task will also output data on the serial link so that we can see what happens. These two tasks show how we can communicate between hardware peripherals in the Zynq SoC, use a task to get values ​​from the hardware, and then use those values ​​in the second task. Inter-task communication is an important aspect of using RTOS in embedded systems.

The two examples of the FreeRTOS demo code that are very helpful are: a full demo and a simpler flashing demo. The flashing LED demo is controlled by setting the preprocessor declaration in main.c:
#define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 1

Set this flag and rebuild the application to get a simple example - the MicroZed onboard LED flashes. Pass data by pre-defined rates between two tasks and using queues. This code just happens to be what we need, so this simple demo brings us useful inspiration for the application code we want to develop.

As mentioned above, the first thing we want to create is a configuration routine that initializes the XADC of the Zynq SoC to make it available. Remember to add the required include files and the necessary declarations to access the Xynq SoC's XADC. We have done this many times in this blog, so this is very accustomed to you.

The next step is to modify the transfer task, read the XADC temperature, and place the resulting value in a queue for the receiving process to read. The code to achieve this is as follows:
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 then compare the received value with the expected value and switch the LED when the received value is greater than 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 from the above code, this simple application is when the temperature exceeds the warning value, the LED lights up. However, in many cases the LED will continue to flicker because the boundary temperature value will quickly swing between above and below the threshold. We solve this problem by introducing hysteresis so that the LED will only go out when the temperature drops sufficiently and stops fluctuating.

Optical Fibre Amplifier

China Fiber Optic Temperature Sensor,Fiber Sensing manufacturer, choose the high quality Fiber Optic Pressure Sensor,Fiber Optic Current Sensor, etc. SUENW always puts customer needs first and insists on factory self-management. Look forward to your cooperation!

Fiber Optic Temperature Sensor,Fiber Sensing,Fiber Optic Pressure Sensor,Fiber Optic Current Sensor

Shenzhen ShenWu Sensor Co.Ltd. , https://www.szsuenw.com