FreeRTOS's application assignment

Source: Internet
Author: User
Tags semaphore

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.

  1. Create a producer task that takes 1 light sensor value every 1ms.
    • Collect the average of the readings.
    • Write average value every 100ms (avg. of samples) sensor queue to the.
    • Use medium the-this task
  2. Create a consumer task that pulls the data off thesensor queue
    • Use infinite timeout value during queue receive API
    • Open a file (Sensor.txt), and append the data to an output file on the SD card.
    • Save the data in this format:printf("%i, %i\n", time, light)"
    • Just leave the file in "open" mode, such that it'll flush the data after enough data is written rather than flushing it Upon each write, which would consume a lot of CPUs.
    • Use medium the-this task
  3. At the end of this 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 thexEventGroupSetBits()
    • Task 1 should set bit1, Task 2 should set bit2 etc.
  4. Create a  watchdog task  that monitors the operation of the tasks.
    • Use the 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.
    • use a timeout of 1 second, and wait for all the bits to set. If there is both tasks, wait for bit1, and Bit2 etc.
    • If you fail to detect the bits is set, that is means the other tasks do not reach the end of the loop.
    • in the event of failed to detect the bits, append a file (stuck.txt) with the information on which task May is "Stu CK "
    • Open the file, append the data, and close the (stuck.txt) file to flush the data immediately.
  5. Create a terminal command to "suspend" and "Resume" a task by name.
    • "Task suspend Task1" should suspend a task named "Task1"
    • "Task Resume Task2" should suspend a task named "Task2"
  6. Run the system, and under normal operation, you'll see a file being saved with sensor data values.
    • Plot the file data in Excel to demonstrate.
  7. Suspend the producer task. The watchdog task should display a message and save relevant info to the SD card.
  8. Let the system run for a while, and note the CPU usage in your text file.
  9. Change the ADC sensor implementation
    • Modify the source code "adc.h" of by is not using the ADC polling mode.
    • Instead of "Trigger ADC", "Wait for completion", and "read value", modify it to this:
      upon ADC Initializ ation, enable ADC interrupt, and create a binary semaphore.
      The ADC interrupt should "give" the semaphore upon completion of the ADC.
      Note: Need to read the ADC data register in order to clear the interrupt before you exit the ISR.
      after
      triggering the ADC, wait for ADC semaphore using xSemaphoreTake() , and then read the value.
  10. After changing the ADC behavior, let the system run for a while, and note the CPU usage again.

What's created is a "software watchdog". This means if a loop is stuck, or a task was frozen, you can save relevant information such so you can Debug at a later time.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.