layout | title | license |
---|---|---|
default |
uC/OS-II - semaphores |
This lab requires you to make use of semaphores in uC/OS-II to solve a variety of synchronisation problems.
-
Make sure that you are up to date with the exercises so far. When you are ready to check your work, you can import the repositories and checkout the solution branches. Build, run, and observe the solution programs. Study the code carefully to make sure that you understand it. Ask your lab tutor for help with anything that you don't understand.
$ cd ~/kf6010 $ mbed import https://github.com/davidkendall/blinky-mbed-tt $ cd blinky-mbed-tt $ git checkout P03
and
$ cd ~/kf6010 $ mbed import https://github.com/davidkendall/blinky-mbed-ucos-ii $ git checkout P03
-
Now import the repository that is the starting point for your use of semaphores with uC/OS-II.
$ cd ~/kf6010 $ mbed import https://github.com/davidkendall/semaphore-mbed-ucos-ii $ cd semaphore-mbed-ucos-ii
Build and run the program. Observe its behaviour carefully. Notice that the values of the
count1
andcount2
variables are shown on the LCD display. The LED on the FRDM-K64F board is green and is not flashing (you can ignore the RGB LED on the application board for the moment). -
Look carefully at the code in
src/app/main.cpp
. Notice the use of semaphores inappTaskCount1
andappTaskCount2
. Now comment out the lines in these tasks that pend and post thelcdSem
. You should comment out 4 lines in total. Build and run the program again. Ignore the warnings about unused variables. Observe its behaviour. What happens and why? -
Restore the lines that make use of the
lcdSem
. Build and run the program again. Observe its behaviour once more. Notice that the value of thecount1
variable is incrementing much more quickly than the value of thecount2
variable. How can that be happening? It is possible to replace thelcdSem
with a pair of semaphores,lcdSem1
andlcdSem2
, that can be used byappTaskCount1
andappTaskCount2
to preserve mutual exclusion and to ensure that both tasks make progress at the same rate. TheappTaskCount1
task should pend onlcdSem1
and postlcdSem2
. TheapptaskCount2
task should pend onlcdSem2
and postlcdSem1
. Create these semaphores (how should they be initialised to preserve mutual exclusion and avoid deadlock?) and implement the functionality described above. Build and run the program again. Both counts should now increment at the same rate. -
Study the initialisation of the semaphores in the previous exercise methodically. Try the following combinations of initialisation values:
lcdSem1 lcdSem2 ------------------ 0 0 0 1 1 0 1 1
In each case, build and run the program. Observe its behaviour and explain the results.
Now add a 1 ms delay at the beginning of
appTaskCount1
, just immediately before thewhile
loop. Try all of the combinations of initialisation value again. Build and run the program each time. Observe its behaviour and explain the results again. -
Do the task priorities of this system conform to the requirements of the rate monotonic (RM) scheduling method for fixed priority allocation? If so, explain why. If not, rewrite the program to comply with RM requirements. Build and run your new program.
You'll need to spend about 5 or 6 hours per week, outside of scheduled classroom time, working on the exercises and doing further reading. The most important part of this will be the time that you spend programming. You can configure your own computer to enable you to do any of the work that you would normally do in the lab. If your own computer has a Linux OS installed, then you can simply follow the instructions for installing the GNU Arm Embedded Toolchain and pyOCD. If you have a Windows or Mac machine, then you should install Virtualbox and create an Ubuntu 16.04 Desktop guest OS to run on your machine. See [Using Virtualbox]({{ url }}{{ baseurl }}kf4005/L01.html#using-virtualbox) for guidance. You can then install the tools, as explained earlier.