Nios® V Processor Software Developer Handbook

ID 743810
Date 10/02/2023
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

9.3.3. Thread-Safe Drivers

To enable a driver to be ported between the HAL and MicroC/OS-II environments, Intel 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 a multithreaded uCOS/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-provided device driver code, and you can use them if you need to write a device driver with similar portability.

The path listed for the header file is relative to the <Intel Quartus installation directory>/nios2eds/components/micrium_uc_osii/UCOSII/inc directory.

Table 39.  OS-Independent Macros for Thread-Safe HAL Drivers
Macros MicroC/OS-II Implementation Single-Threaded HAL Implementation

Event Flag Macros

Defined in os/alt_flag.h and priv/alt_flag_ucosii.h.

ALT_FLAG_GRP(group) Create a flag group with the name group. Empty Statement
ALT_EXTERN_FLAG_GRP(group) Create an external reference to a flag group with name group.
ALT_STATIC_FLAG_GRP(group) Create a static flag group with the name group.
ALT_FLAG_CREATE(group, flags) Call OSFlagCreate() to initialize the flag group pointer, group, with the flag value flags. The error code is the return value of the macro. Return 0 (success)
ALT_FLAG_PEND(group, flags, wait_type, timeout) 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.
ALT_FLAG_POST(group, flags, opt) 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.

Semaphore Macros

Defined in os/alt_sem.h and priv/alt_sem_ucosii.h.

ALT_SEM(sem) Create an OS_Event pointer with the name sem. Empty Statement
ALT_EXTERN_SEM(sem) Create an external reference to an OS_Event pointer with the name sem.
ALT_STATIC_SEM(sem) Create a static OS_Eventpointer with the name sem.
ALT_STATIC_CREATE(sem, value) Call OSSemCreate()  with the argument value to initialize OS_Event pointer,  sem. The return value is zero on success, or negative otherwise. Return 0 (success)
ALT_SEM_PEND(sem, timeout) Call  OSSemPend() with the first two arguments set to sem  and  timeout respectively. The error code is the return value of the macro.
ALT_SEM_POST(sem) Call OSSemPost() with the input argument sem.
Table 40.  Arguments for Event Flags Macros
Argument Valid Inputs Defined in Header
wait_type
  • ALT_FLAG_WAIT_SET_ALL_WITH_CONSUME
  • ALT_FLAG_WAIT_SET_ALL_WO_CONSUME
  • ALT_FLAG_WAIT_SET_ANY_WITH_CONSUME
  • ALT_FLAG_WAIT_SET_ANY_WO_CONSUME
  • os/alt_flag.h
  • ucos_ii.h
timeout
  • ALT_FLAG_WAIT_MAX_TIMEOUT
opt
  • ALT_FLAG_SET
  • ALT_FLAG_CLEAR