Nios® II Software Developer Handbook

ID 683525
Date 8/28/2023
Public
Document Table of Contents

11.3.3. Thread-Safe HAL Drivers

To enable a driver to be ported between the HAL and MicroC/OS-II environments, Intel FPGA defines a set of operating system-independent macros that provide access to operating system facilities. These macros implement functionality that is only relevant to a multi-threaded environment. When compiled for a MicroC/OS-II project, the macros expand to MicroC/OS-II API calls. When compiled for a single-threaded HAL project, the macros expand to benign empty implementations. These macros are used in Intel FPGA-provided device driver code, and you can use them if you need to write a device driver with similar portability.

For more information about the functionality in the MicroC/OS-II environment, refer to MicroC/OS-II: The Real-Time Kernel.

The path listed for the header file is relative to the <Nios II EDS install path>/components/micrium_uc_osii/UCOSII/inc directory.

Table 47.  OS-Independent Macros for Thread-Safe HAL Drivers
Macro Defined in Header MicroC/OS-II Implementation Single-Threaded HAL Implementation
ALT_FLAG_GRP(group) os/alt_flag.h Create a pointer to a flag group with the name group. Empty statement
ALT_EXTERN_FLAG_GRP(group) os/alt_flag.h Create an external reference to a pointer to a flag group with name group. Empty statement
ALT_STATIC_FLAG_GRP(group) os/alt_flag.h Create a static pointer to a flag group with the name group. Empty statement
ALT_FLAG_CREATE(group, flags) os/alt_flag.h Call OSFlagCreate() to initialize the flag group pointer, group, with the flags value flags. The error code is the return value of the macro. Return 0 (success)
ALT_FLAG_PEND(group, flags, wait_type, timeout) os/alt_flag.h Call OSFlagPend() with the first four input arguments set to group, flags, wait_type, and timeout respectively. The error code is the return value of the macro. Return 0 (success)
ALT_FLAG_POST(group, flags, opt) os/alt_flag.h Call OSFlagPost() with the first three input arguments set to group, flags, and opt respectively. The error code is the return value of the macro. Return 0 (success)
ALT_SEM(sem) os/alt_sem.h Create an OS_EVENT pointer with the name sem. Empty statement
ALT_EXTERN_SEM(sem) os/alt_sem.h Create an external reference to an OS_EVENT pointer with the name sem. Empty statement
ALT_STATIC_SEM(sem) os/alt_sem.h Create a static OS_EVENT pointer with the name sem. Empty statement
ALT_SEM_CREATE(sem, value) os/alt_sem.h Call OSSemCreate() with the argument value to initialize the OS_EVENT pointer sem. The return value is zero on success, or negative otherwise. Return 0 (success)
ALT_SEM_PEND(sem, timeout) os/alt_sem.h Call OSSemPend() with the first two argument set to sem and timeout respectively. The error code is the return value of the macro. Return 0 (success)
ALT_SEM_POST(sem) os/alt_sem.h Call OSSemPost() with the input argument sem. Return 0 (success)