Real-Time Systems

Real-Time Systems

Real-Time Systems

CprE 458/558, Fall 2009

Iowa State University

Lab 2, Coover Hall - Open Hours

Total: 60 points

Introduction

In this lab, you are provided with some code for an MP3 player system, which is an excellent practical application of the producer-consumer problem. In the following we first present a quick overview of the system and then list the submissions required.

Instructions to Design the MP3 Player System

Download the Lab2_Files.zip from the course website, and unzip it. Open Workspace0.wsp from where you unzip the files. You should see two projects in this workspace, one called ‘mad_lib_module’ and one called ‘mp3_lab’. You will need to boot your board intoVxWorks and start a target server, as done in the previous lab. Once this is set up, build anddownload the ‘mad_lib_module’ project, followed by the ‘mp3_lab’ project. You will needto change the ‘#define MP3_FILE’ line to point to an MP3 file you brought tolab and copied to your Compact Flash card.

The following describes the components of the lab. The entire system consists of six major features:

  1. Libmad (Software)
  2. Circular Buffer (Software – You will be implementing this)
  3. AC97 Task (Software)
  4. Audio Interrupt Handler (Software)
  5. Onboard AC97 D/A Converter (Hardware)
  6. Onboard FIFO (Hardware)

The Libmad is the MP3 decoding library, which reads in the MP3 file you specified in the ‘#define MP3_FILE’ statement from the flash card. It periodically samples the input file at a predetermined rate and writes the digital samples into the circular buffer in the function ‘Output()’ given in the ‘System2.c’ file. The following figure depicts the system data flow.

The ‘AC97_Task()’ task reads out the data from circular buffer and feeds it to the sample buffer which is periodically read by the D/A converter using the audio interrupt handler. The audio interrupt handler is invoked when the hardware FIFO is half full. It writes samples from the buffer shared by the ‘AC97_Task()’ and the interrupt handler until either the hardware FIFO is full or there are no more samples. The D/A converter finally produces the output audio signal to the speaker. This completes the cycle.

In this part of the lab, we focus on the inter-task communication between the ‘Output()’ task and ‘AC97_Task()’. Right now, the communication is carried out using a circular buffer as shown in the figure. Our objective is to implement the circular buffer.

Semaphores are an excellent means to achieve mutual exclusion over shared variables and buffers. Read the VxWorks Programmers Guide available online to find out how to use priority semaphores. Use the given priority semaphore and circular buffer function prototypes to implement a circular buffer system that is shared between ‘Output()’ and ‘AC97_Task()’ by filling in the empty functions.

Once the circular buffer functions are implemented, start the Tornado shell, and call ‘play_mp3()’ tostart the system. Connect the audio in cable from your monitor to the Amp Out jack onyour board. You should start to hear some playback; you may call ‘kill_mp3()’ to stop playback (You may want to turn the volume down first).

You will need to do the following for the MP3 player component:

  1. Implement the circular buffer functions
  2. Capture Windview screenshots of the system while ‘play_mp3()’ is running

Instructions to Display and Fix Priority Inversion

The second part of this lab introduces a third task named ‘dummy_task()’ and examines the effects it has on the priority semaphore. The three tasks are set up so that ‘Output()’ has the low priority, ‘dummy_task()’ has the medium priority, and ‘AC97_Task()’ has the high priority. A priority inversion will occur when ‘AC97_Task() is attempting to lock the semaphore, while ‘Output()’ is locked and ‘dummy_task()’ is currently executing.

To enable the dummy task change the statement ‘#define DUMMY_MODE’ to 1 from it’s initial value of 0. Open up a TeraTerm window connected to the board, and call ‘play_mp3()’ from the shell. A ‘Priority Inversion!’ statement will appear in the TeraTerm window each time a priority inversion occurs on the resource.

After demonstrating that priority inheritance has occurred the code needs to be changed so priority inheritance does not occur. You can do this in any way you see fit. Note that the inclusion of ‘dummy_task()’ will cause skipping in the MP3 audio due to the amount of computation required to incur a priority inversion; it is safe to ignore this effect.

Hint: Look at the documentation for semMCreate(), specifically the flags passed to it.

You will need to do the following for the priority inversion component:

  1. Show and fix priority inversion
  2. Capture Windview screenshots of fixed/unfixed priority inversion

Be sure to turn in your source code with the rest of the deliverables!