Happy New Year! For the first blog of the year I thought we would combine the FreeRTOS and the XADC examples we had bbeen looking at previously.
This will enable me to show how we can do the following
- Configure the XADC
- Create a task to read from the XADC
- Create a second task to take action on the results from the first task
The intended functionality is the one task, once a second reads the XADC internal parameters and stores them within a array. This array is then communicated via a queue to the recieivng task which processes the results, for this example it just outputs them over the UART. If we wanted to this task could perform more detailed analysis or calcualtion on the results being provided to it.
We can easily modify the hello world example to perform this. If we wish to make it more complex and introduce more tasks which share resources, we must ensure they are properly managed and do not become deadlocked.
The first thing we need to do is include the proper header files such that we can use the API for the XADC we do this by including the “XSYSMON.H”.
Within the main function we are going to configure and initialise the XADC before we start the two tasks.
As we are going to be using the printf function and we are going to transfering data we need to ensure the stack size is correctly allocated. To prevent problems I decided to increase this to ensure there was sufficent for that requred for both tasks, when we create the tasks in the main() we are required to define the stack allocated to each task. For both tasks I decided to allocate 1000 bytes, I left the task pirorites as the receiving task being a higher priortiy than the transmitting task ensuring the data is transmitted as soon as it is received.
The next step was to create the queue, as I mentioned above due to the priorities of the RX and TX tasks there will only be one element in the queue, which will be the size of the size element XADC_Buf.
The final element is to start the scheduler and let the tasks run for ever well once we have written them.
We write each task as a we would any function in C, being careful to ensure we include the 1 second dealy within the transmitt task.
When I ran the code (which is available here) I got the following results.