MicroC/OS-II Mutex Example

Recommended for:

  • Device: Stratix® II

  • Device: Cyclone® II

author-image

By

The MicroC/OS-II Mutex design example demonstrates the use of MicroC/OS-II mutual exclusion semaphores (mutex). It also serves as a good starting point for designs using MicroC/OS-II with Nios® II processors. MicroC/OS-II Mutexes are very similar to semaphores and are generally used to protect shared resources and/or facilitate task synchronization. The main difference between a mutex and a regular semaphore is that a mutex has the concept of raising the priority of a task that owns the mutex.

In this MicroC/OS-II Mutex design example, two different tasks are accessing a shared resource, which, in this case, is an LCD display.

The task called task1() prints out the status of the Joint Task Action Group (JTAG) UART connection on the top line of the LCD. A "1" signifies that the JTAG UART detects a valid connection to the nios2-terminal program. A "0" signifies that the JTAG UART no longer has a connection with the nios2-terminal program. Upon start-up with STDOUT set to the JTAG UART, a valid connection is detected. If the nios2-terminal program is stopped, or the JTAG cable is disconnected, the state of the connection will change a few seconds later. The task called task2() prints out how long the system has been running on the bottom line of the LCD.

Using This Design Example

Ensure that you have installed a Nios II development kit. Download the MicroC/OS-II Mutex design example and unzip the files into a directory under <Nios II kit path>/examples/software (for example, <Nios II kit path>/examples/software/ucosII_mutex). If installed in this directory, the design example will be available as a Nios II integrated development environment (IDE) project template. The MicroC/OS-II Mutex design example includes the project settings required to run this design example on the supported target hardware configuration. To use the MicroC/OS-II Mutex design example, simply create a new C/C++ application project in the IDE, and choose the desired project template.

The use of this design is governed by, and subject to, the terms and conditions of the Intel® Design Example License Agreement.

Hardware Requirements

The MicroC/OS-II design example requires the following devices to be present in the target hardware design:

  • LCD character display
  • JTAG UART
  • Timer

You can run this design example on the following Nios® II hardware design examples:

  • Stratix® II design examples
    • Standard
    • Full Featured
  • Cyclone® II design examples
    • Standard
    • Full Featured