Difference between revisions of "Embedded System Tutorial File I/O"

From Embedded Systems Learning Academy
Jump to: navigation, search
(Assignment)
 
(10 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
Socialledge is moving to two portals. 
 +
*  The Wiki will remain here for general references about the SJ-One board, and to document student reports.
 +
*  The bookstack will now be used for SJSU assignments
 +
 +
[http://books.socialledge.com/books/embedded-drivers-real-time-operating-systems/chapter/lesson-watch-dogs This article has been moved here]
 +
 +
<!--
 +
 
In this project, we will attempt to "combine" all the FreeRTOS knowledge into a single assignment.
 
In this project, we will attempt to "combine" all the FreeRTOS knowledge into a single assignment.
 +
 +
 +
After completing the assignment, you will get a sense of how the CPU is utilized, and how to use a new FreeRTOS event group API.  All together, you should achieve a better sense of designing your tasks and using the File I/O for debugging purposes.
 +
  
 
== Assignment ==
 
== Assignment ==
 
Please follow the steps precisely in order to complete the objectives of the assignment.  If you use the C++ FreeRTOS framework, it should make the assignment significantly easy.
 
Please follow the steps precisely in order to complete the objectives of the assignment.  If you use the C++ FreeRTOS framework, it should make the assignment significantly easy.
 +
  
 
#  Create a '''<code>producer task</code>''' that takes 1 light sensor value every 1ms.
 
#  Create a '''<code>producer task</code>''' that takes 1 light sensor value every 1ms.
#*  Collect the average of the 100 readings.
+
#*  After collecting 100 samples (after 100ms), compute the average.
#*  Write average value of 100ms (100 samples) to the '''<code>sensor queue</code>'''.
+
#*  Write average value every 100ms (avg. of 100 samples) to the '''<code>sensor queue</code>'''.
 
#*  Use medium priority for this task
 
#*  Use medium priority for this task
 
#  Create a '''<code>consumer task</code>''' that pulls the data off the '''<code>sensor queue</code>'''  
 
#  Create a '''<code>consumer task</code>''' that pulls the data off the '''<code>sensor queue</code>'''  
Line 12: Line 25:
 
#*  Open a file (sensor.txt), and append the data to an output file on the SD card.
 
#*  Open a file (sensor.txt), and append the data to an output file on the SD card.
 
#*  Save the data in this format: '''<code>printf("%i, %i\n", time, light)"</code>'''
 
#*  Save the data in this format: '''<code>printf("%i, %i\n", time, light)"</code>'''
#*  Just leave the file in "open" mode, such that it will flush the data after enough data is written rather than flushing it upon each write, which will consume a lot of CPU.
+
#*  Note that if you write and close a file every 100ms, it may be very inefficient, so try to come up with a better method such that the file is only written once a second or so...
 
#*  Use medium priority for this task
 
#*  Use medium priority for this task
 +
#  At the end of the loop of each task, set a bit using FreeRTOS event group API.
 +
#*  At the end of each loop of the tasks, set a bit using the '''<code>xEventGroupSetBits()</code>'''
 +
#*  Task 1 should set bit1, Task 2 should set bit2 etc.
 
#  Create a '''<code>watchdog task</code>''' that monitors the operation of the two tasks.
 
#  Create a '''<code>watchdog task</code>''' that monitors the operation of the two tasks.
 
#*  Use high priority for this task.
 
#*  Use high priority for this task.
#*  Every sixty seconds, save the CPU usage info to a file named "cpu.txt".  See terminal command "infoHandler" for reference.  Open the file, write the file, and close it immediately so the data is immediately flushed.
 
#*  Towards the end of the other tasks, set a bit using the '''<code>xEventGroupSetBits()</code>'''
 
#*  Task 1 should set bit1, Task 2 should set bit2 etc.
 
 
#*  Use a timeout of 1 second, and wait for all the bits to set.  If there are two tasks, wait for bit1, and bit2 etc.
 
#*  Use a timeout of 1 second, and wait for all the bits to set.  If there are two tasks, wait for bit1, and bit2 etc.
 
#*  If you fail to detect the bits are set, that means that the other tasks did not reach the end of the loop.
 
#*  If you fail to detect the bits are set, that means that the other tasks did not reach the end of the loop.
 
#*  In the event of failed to detect the bits, append a file (stuck.txt) with the information about which task may be "stuck"
 
#*  In the event of failed to detect the bits, append a file (stuck.txt) with the information about which task may be "stuck"
 
#*  Open the file, append the data, and close the (stuck.txt) file to flush out the data immediately.
 
#*  Open the file, append the data, and close the (stuck.txt) file to flush out the data immediately.
 +
#*  Extra Credit: Every sixty seconds, save the CPU usage info to a file named "cpu.txt".  See terminal command "infoHandler" for reference.  Open the file, write the file, and close it immediately so the data is immediately flushed.
 
#  Create a terminal command to "suspend" and "resume" a task by name.
 
#  Create a terminal command to "suspend" and "resume" a task by name.
 
#*  "task suspend task1" should suspend a task named "task1"
 
#*  "task suspend task1" should suspend a task named "task1"
Line 30: Line 44:
 
#  Suspend the producer task.  The watchdog task should display a message and save relevant info to the SD card.
 
#  Suspend the producer task.  The watchdog task should display a message and save relevant info to the SD card.
 
#  Let the system run for a while, and note down the CPU usage in your text file.
 
#  Let the system run for a while, and note down the CPU usage in your text file.
#  Change the ADC sensor implementation
 
#*  Modify the source code of how the light sensor class obtains the ADC value by not using ADC polling mode.
 
#*  Instead of "trigger ADC", "wait for completion", and "read value", modify it to this:
 
#*:  Upon ADC initialization, enable ADC interrupt, which should "give" a semaphore.
 
#*:  After triggering the ADC, wait for ADC semaphore to be given, and then read the value.
 
#  After changing the ADC behavior, let the system run for a while, and note down the CPU usage again.
 
  
 
What you created is a "software watchdog".  This means that in an event when a loop is stuck, or a task is frozen, you can save relevant information such that you can debug at a later time.
 
What you created is a "software watchdog".  This means that in an event when a loop is stuck, or a task is frozen, you can save relevant information such that you can debug at a later time.
 
+
-->
After completing the assignment, you will get a sensor of how the CPU is utilized, and how to use a new FreeRTOS event group API.  All together, you should acheive a better sensor of designing your tasks and using the File I/O for debugging purposes.
 

Latest revision as of 20:10, 25 January 2019

Socialledge is moving to two portals.

  • The Wiki will remain here for general references about the SJ-One board, and to document student reports.
  • The bookstack will now be used for SJSU assignments

This article has been moved here