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

11.2.3. Thread-Safe HAL Drivers

To enable a driver to be ported between the HAL and FreeRTOS 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. You can use the macro in Intel-provided device driver code, and if you need to write a device driver with similar portability.
  • When you compile for a multithreaded FreeRTOS project, the macros expand to FreeRTOS API calls.
  • When you compile for a single-threaded HAL project, the macros expand to benign empty implementations.

The path listed for the header file is relative to the /ip/altera/soft_processor /aws_freertos/FREERTOS/inc directory.

Table 42.  OS-Independent Macros for Thread-Safe HAL Drivers
Macros FreeRTOS Implementation Single-Threaded HAL Implementation

Event Flag Macros

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

ALT_FLAG_GRP(group) Creates a flag group with the name group. Empty Statement
ALT_EXTERN_FLAG_GRP(group) Creates an external reference to a flag group with name group.
ALT_STATIC_FLAG_GRP(group) Creates a static flag group with the name group.
ALT_FLAG_CREATE(group, flags)
  • Calls xEventGroupCreate() 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)
  • Calls xEventGroupWaitBits() 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)
  • Calls xEventGroup[Set|Clear]Bits() or xEventGroup[Set|Clear]BitsFromISR() 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_freertos.h.

ALT_SEM(sem) Creates an SemaphoreHandle_t with the name sem. Empty Statement
ALT_EXTERN_SEM(sem) Creates an external reference to an SemaphoreHandle_t with the name sem.
ALT_STATIC_SEM(sem) Creates a static SemaphoreHandle_t with the name sem.
ALT_STATIC_CREATE(sem, value)
  • Calls xSemaphoreCreateCounting() with the argument value to initialize initialize SemaphoreHandle_t ,  sem.
  • The return value is zero on success, or negative otherwise.
Return 0

(success)

ALT_SEM_PEND(sem, timeout)
  • Calls xSemaphoreTake() 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) Calls xSemaphoreGive() with the input argument sem.
Table 43.  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
timeout
  • ALT_FLAG_WAIT_MAX_TIMEOUT
opt
  • ALT_FLAG_SET
  • ALT_FLAG_CLEAR