Guidelines for Developing a Nios II HAL Device Driver

ID 683146
Date 6/12/2015
Public
Document Table of Contents

1.10. Understanding HAL Mutual Exclusion Resources

Software device drivers can use mutual exclusion resources to control access to any data structure or peripheral register. Event flags and semaphores provide synchronization and mutual exclusion services. These resources allow only one task to access a shared piece of data at a time in a multi-threaded environment.

If the MicroC/OS-II operating system is present, its resources are used. Otherwise, the HAL provides its own set of event flags and semaphores. The HAL event flags and semaphores support device driver source code portability. The event flags and semaphores do nothing in this example.

The my_uart_driver device driver creates two semaphores and one event flag. The two semaphores are called read_lock and write_lock. my_uart_driver uses them to control access to the transmit and receive circular buffers. The event flag, called events, indicates to the software device driver when data is ready to be transmitted or received.