OSAL

Overview

Defines the structures and interfaces for the Operating System Abstraction Layer (OSAL) module.

The OSAL module harmonizes OS interface differences and provides unified OS interfaces externally, including the memory management, thread, mutex, spinlock, semaphore, timer, file, interrupt, time, atomic, firmware, and I/O operation modules.

Since:

1.0

Version:

1.0

Summary

Files

File Name

Description

osal_atomic.h

Declares atomic and bit operation interfaces.

osal_file.h

Declares the file structures and interfaces.

osal_firmware.h

Declares firmware structures and interfaces.

osal_io.h

Declares I/O interfaces.

osal_irq.h

Declares interrupt request (IRQ) interfaces and common IRQ trigger modes.

osal_mem.h

Declares the driver memory request and release interfaces.

osal_mutex.h

Declares mutex types and interfaces.

osal_sem.h

Declares semaphore structures and interfaces.

osal_spinlock.h

Declares spinlock types and interfaces.

osal_thread.h

Declares thread types and interfaces.

osal_time.h

Declares the time, sleep, and delay interfaces.

osal_timer.h

Declares timer types and interfaces.

Data Structures

Data Structure Name

Description

OsalAtomic

Describes an atomic.

OsalFile

Declares a file type.

OsalFirmware

Defines the data structure for operating a firmware file.

OsalFwBlock

Defines the data structure for reading a firmware file.

OsalMutex

Describes a mutex.

OsalSem

Describes a semaphore.

OsalSpinlock

Describes a spinlock.

OsalThreadParam

Describes thread parameters.

OsalThread

Describes a thread.

OsalTimespec

Defines time.

OsalTimer

Describes a timer.

Macros

Macro Name and Value

Description

OSAL_O_RD_ONLY    0

Opens a file in read-only mode.

OSAL_O_WR_ONLY    1

Opens a file in write-only mode.

OSAL_O_RDWR    2

Opens a file in read and write mode.

OSAL_S_IREAD    00400

Defines the read permission for the owner.

OSAL_S_IWRITE    00200

Defines the write permission for the owner.

OSAL_S_IEXEC    00100

Defines the execution permission for the owner.

OSAL_S_IRGRP    00040

Defines the read permission for the group.

OSAL_S_IWGRP    00020

Defines the write permission for the group.

OSAL_S_IXGRP    00010

Defines the execution permission for the group.

OSAL_S_IROTH    00004

Defines the read permission for others.

OSAL_S_IWOTH    00002

Defines the write permission for others.

OSAL_S_IXOTH    00001

Defines the execution permission for others.

OSAL_SEEK_SET    0

Defines the offset from the file header.

OSAL_SEEK_CUR    1

Defines the offset from the current position.

OSAL_SEEK_END    2

Defines the offset from the end of the file.

OSAL_WRITEB(value, address)   writeb(value, address)

Writes one byte of data into an I/O address space.

OSAL_WRITEW(value, address)   writew(value, address)

Writes a short integer into an I/O address space.

OSAL_WRITEL(value, address)   writel(value, address)

Writes an integer into an I/O address space.

OSAL_READB(address)   readb(address)

Reads one byte of data from an I/O address space.

OSAL_READW(address)   readw(address)

Reads a short integer from an I/O address space.

OSAL_READL(address)   readl(address)

Reads an integer from an I/O address space.

OSAL_DECLARE_MUTEX (mutex)   struct OsalMutex mutex

Defines a mutex.

OSAL_DECLARE_SEMAPHORE (sem)   struct OsalSem sem

Defines a semaphore.

OSAL_DECLARE_SPINLOCK (spinlock)   OsalSpinlock spinlock

Defines a spinlock.

OSAL_DECLARE_THREAD (thread)   struct OsalThread thread

Defines a thread macro.

OSAL_DECLARE_TIMER (timer)   OsalTimer timer

Defines a timer macro.

Typedefs

Typedef Name

Description

OsalIRQHandle ) (uint32_t irqId, void dev)

typedef uint32_t( 

Defines an IRQ type.

OsalThreadEntry ) (void )

typedef int( 

Defines a thread callback function type.

OsalTimerFunc ) (uintptr_t arg)

typedef void(* 

Describes a timer execution function type.

Enumerations

Enumeration Name

Description

OSAL_IRQ_TRIGGER_MODE {   OSAL_IRQF_TRIGGER_NONE = 0, OSAL_IRQF_TRIGGER_RISING = 1, OSAL_IRQF_TRIGGER_FALLING = 2, OSAL_IRQF_TRIGGER_HIGH = 4,   OSAL_IRQF_TRIGGER_LOW = 8 }

Enumerates interrupt trigger modes.

OSAL_THREAD_PRIORITY { OSAL_THREAD_PRI_LOW, OSAL_THREAD_PRI_DEFAULT, OSAL_THREAD_PRI_HIGH, OSAL_THREAD_PRI_HIGHEST }

Enumerates thread priorities.

Functions

Function Name

Description

OsalAtomicRead (const OsalAtomicv)

int32_t 

Reads the counter of an atomic.

OsalAtomicSet (OsalAtomic v, int32_t counter)

void 

Sets the counter for an atomic.

OsalAtomicInc (OsalAtomicv)

void 

Increments the counter of an atomic by 1.

OsalAtomicDec (OsalAtomic v)

void 

Decrements the counter of an atomic by 1.

OsalTestBit (unsigned long nr, const volatile unsigned long addr)

int32_t 

Tests the value of a specified bit of a variable.

OsalTestSetBit (unsigned long nr, volatile unsigned long addr)

int32_t 

Sets the value of a specified bit of the variable and returns the bit value before the setting.

OsalTestClearBit (unsigned long nr, volatile unsigned long addr)

int32_t 

Clears the value of a specified bit of the variable and returns the bit value before clearing.

OsalClearBit (unsigned long nr, volatile unsigned long addr)

void 

Clears the value of a specified bit of the variable.

OsalFileOpen (OsalFilefile, const char path, int flags, uint32_t rights)

int32_t 

Opens a file.

OsalFileWrite (OsalFilefile, const void string, uint32_t length)

ssize_t 

Writes a file.

OsalFileClose (OsalFilefile)

void 

Closes a file.

OsalFileRead (OsalFile file, void buf, uint32_t length)

ssize_t 

Reads a file.

OsalFileLseek (OsalFile file, off_t offset, int32_t whence)

off_t 

Sets the file read/write offset.

OsalRequestFirmware (struct OsalFirmwarefw, const char fwName, void device)

int32_t 

Requests a firmware file based on its name and device information.

OsalSeekFirmware (struct OsalFirmware fw, uint32_t offset)

int32_t 

Reads a firmware file.

OsalReadFirmware (struct OsalFirmwarefw, struct OsalFwBlockblock)

int32_t 

Releases a firmware file.

OsalReleaseFirmware (struct OsalFirmwarefw)

int32_t 

OsalIoRemap (unsigned long phys_addr, unsigned long size)

static void  

Remaps an I/O physical address to its virtual address.

OsalIoUnmap (void addr)

static void 

Unmaps an I/O virtual address associated with the physical address.

OsalRegisterIrq (uint32_t irqId, uint32_t config, OsalIRQHandle handle, const char name, void dev)

int32_t 

Registers an IRQ.

OsalUnregisterIrq (uint32_t irqId)

int32_t 

Unregisters an IRQ.

OsalEnableIrq (uint32_t irqId)

int32_t 

Enables an IRQ.

OsalDisableIrq (uint32_t irqId)

int32_t 

Disables an IRQ.

OsalMemAlloc (size_t size)

void  

Allocates memory of a specified size.

OsalMemCalloc (size_t size)

void  

Allocates memory of a specified size, and clears the allocated memory.

OsalMemAllocAlign (size_t alignment, size_t size)

void  

Allocates memory of a specified size, and aligns the memory address on a given boundary.

OsalMemFree (void mem)

void 

Releases memory.

OsalMutexInit (struct OsalMutex mutex)

int32_t 

Initializes a mutex.

OsalMutexDestroy (struct OsalMutexmutex)

int32_t 

Destroys a mutex.

OsalMutexLock (struct OsalMutex mutex)

int32_t 

Locks a mutex.

OsalMutexTimedLock (struct OsalMutexmutex, uint32_t ms)

int32_t 

Locks a mutex with a specified timeout duration.

OsalMutexUnlock (struct OsalMutex mutex)

int32_t 

Unlocks a mutex.

OsalSemInit (struct OsalSemsem, uint32_t value)

int32_t 

Initializes a semaphore.

OsalSemWait (struct OsalSem sem, uint32_t ms)

int32_t 

Waits for a semaphore.

OsalSemPost (struct OsalSemsem)

int32_t 

Releases a semaphore.

OsalSemDestroy (struct OsalSem sem)

int32_t 

Destroys a semaphore.

OsalSpinInit (OsalSpinlockspinlock)

int32_t 

Initializes a spinlock.

OsalSpinDestroy (OsalSpinlock spinlock)

int32_t 

Destroys a spinlock.

OsalSpinLock (OsalSpinlockspinlock)

int32_t 

Obtains a spinlock.

OsalSpinUnlock (OsalSpinlock spinlock)

int32_t 

Releases a spinlock.

OsalSpinLockIrq (OsalSpinlockspinlock)

int32_t 

Obtains a spinlock and disables the IRQ.

OsalSpinUnlockIrq (OsalSpinlock spinlock)

int32_t 

Releases a spinlock and enables the IRQ.

OsalSpinLockIrqSave (OsalSpinlockspinlock, uint32_t flags)

int32_t 

Obtains a spinlock, disables the IRQ, and saves its status.

OsalSpinUnlockIrqRestore (OsalSpinlockspinlock, uint32_t flags)

int32_t 

Releases a spinlock, enables the IRQ, and restores the saved IRQ status.

OsalThreadCreate (struct OsalThreadthread, OsalThreadEntry threadEntry, void entryPara)

int32_t 

Creates a thread.

OsalThreadStart (struct OsalThreadthread, const struct OsalThreadParamparam)

int32_t 

Starts a thread.

OsalThreadDestroy (struct OsalThreadthread)

int32_t 

Destroys a thread.

OsalThreadSuspend (struct OsalThread thread)

int32_t 

Suspends a thread.

OsalThreadResume (struct OsalThreadthread)

int32_t 

Resumes a thread.

OsalSleep (uint32_t sec)

void 

Describes thread sleep, in seconds.

OsalMSleep (uint32_t ms)

void 

Describes thread sleep, in milliseconds.

OsalGetTime (OsalTimespectime)

int32_t 

Obtains the second and microsecond time.

OsalDiffTime (const OsalTimespecstart, const OsalTimespecend, OsalTimespecdiff)

int32_t 

Obtains time difference.

OsalGetSysTimeMs (void)

uint64_t 

Obtains the system time.

OsalMDelay (uint32_t ms)

void 

Describes thread delay, in milliseconds.

OsalUDelay (uint32_t us)

void 

Describes thread delay, in microseconds.

OsalTimerCreate (OsalTimer timer, uint32_t interval, OsalTimerFunc func, uintptr_t arg)

int32_t 

Creates a timer.

OsalTimerDelete (OsalTimertimer)

int32_t 

Deletes a timer.

OsalTimerStartOnce (OsalTimer timer)

int32_t 

Starts a timer.

OsalTimerStartLoop (OsalTimertimer)

int32_t 

Starts a periodic timer.

OsalTimerSetTimeout (OsalTimer timer, uint32_t interval)

int32_t 

Sets the interval of a timer.

Details

Macro Definition Documentation

OSAL_READB

  1. #define OSAL_READB( address) readb(address)

Description:

Reads one byte of data from an I/O address space.

Parameters:

Name

Description

addressIndicates the address to read.

Returns:

Returns the byte.

OSAL_READL

  1. #define OSAL_READL( address) readl(address)

Description:

Reads an integer from an I/O address space.

Parameters:

Name

Description

addressIndicates the address to read.

Returns:

Returns the integer.

OSAL_READW

  1. #define OSAL_READW( address) readw(address)

Description:

Reads a short integer from an I/O address space.

Parameters:

Name

Description

addressIndicates the address to read.

Returns:

Returns the short integer.

OSAL_WRITEB

  1. #define OSAL_WRITEB( value, address ) writeb(value, address)

Description:

Writes one byte of data into an I/O address space.

Parameters:

Name

Description

valueIndicates the data to write.
addressIndicates the address to write.

OSAL_WRITEL

  1. #define OSAL_WRITEL( value, address ) writel(value, address)

Description:

Writes an integer into an I/O address space.

Parameters:

Name

Description

valueIndicates the data to write.
addressIndicates the address to write.

OSAL_WRITEW

  1. #define OSAL_WRITEW( value, address ) writew(value, address)

Description:

Writes a short integer into an I/O address space.

Parameters:

Name

Description

valueIndicates the data to write.
addressIndicates the address to write.

Enumeration Type Documentation

OSAL_IRQ_TRIGGER_MODE

  1. enum[OSAL_IRQ_TRIGGER_MODE]($api-api-SmartVision-Devices-OSAL.md#ga78cd126b10424753db6f39f9b72ea124)

Description:

Enumerates interrupt trigger modes.

Enumerator

Description

OSAL_IRQF_TRIGGER_NONE 

Edge-triggered is not set

OSAL_IRQF_TRIGGER_RISING 

Rising edge triggered

OSAL_IRQF_TRIGGER_FALLING 

Failing edge triggered

OSAL_IRQF_TRIGGER_HIGH 

High-level triggered

OSAL_IRQF_TRIGGER_LOW 

Low-level triggered

OSAL_THREAD_PRIORITY

  1. enum[OSAL_THREAD_PRIORITY]($api-api-SmartVision-Devices-OSAL.md#gab8c099a9c39fdde73c74b3f7367be5d0)

Description:

Enumerates thread priorities.

Enumerator

Description

OSAL_THREAD_PRI_LOW 

Low priority

OSAL_THREAD_PRI_DEFAULT 

Default priority

OSAL_THREAD_PRI_HIGH 

High priority

OSAL_THREAD_PRI_HIGHEST 

Highest priority

Function Documentation

OsalAtomicDec()

  1. voidOsalAtomicDec([OsalAtomic]($api-api-SmartVision-Devices-OsalAtomic.md)* v)

Description:

Decrements the counter of an atomic by 1.

Parameters:

Name

Description

vIndicates the pointer to the atomic OsalAtomic.

OsalAtomicInc()

  1. voidOsalAtomicInc([OsalAtomic]($api-api-SmartVision-Devices-OsalAtomic.md)* v)

Description:

Increments the counter of an atomic by 1.

Parameters:

Name

Description

vIndicates the pointer to the atomic OsalAtomic.

OsalAtomicRead()

  1. int32_tOsalAtomicRead(const[OsalAtomic]($api-api-SmartVision-Devices-OsalAtomic.md)* v)

Description:

Reads the counter of an atomic.

Parameters:

Name

Description

vIndicates the pointer to the atomic OsalAtomic.

Returns:

Returns the counter.

OsalAtomicSet()

  1. voidOsalAtomicSet([OsalAtomic]($api-api-SmartVision-Devices-OsalAtomic.md)* v,int32_t counter )

Description:

Sets the counter for an atomic.

Parameters:

Name

Description

vIndicates the pointer to the atomic OsalAtomic.
counterIndicates the counter to set.

OsalClearBit()

  1. voidOsalClearBit(unsignedlong nr,volatileunsignedlong* addr )

Description:

Clears the value of a specified bit of the variable.

Parameters:

Name

Description

nrIndicates the bit of the variable. The value ranges from 0 to 31.
addrIndicates the pointer to the variable.

OsalDiffTime()

  1. int32_tOsalDiffTime(const[OsalTimespec]($api-api-SmartVision-Devices-OsalTimespec.md)* start,const[OsalTimespec]($api-api-SmartVision-Devices-OsalTimespec.md)*end,[OsalTimespec]($api-api-SmartVision-Devices-OsalTimespec.md)* diff )

Description:

Obtains time difference.

Parameters:

Name

Description

startIndicates the pointer to the start time OsalTimespec.
endIndicates the pointer to the end time OsalTimespec.
diffIndicates the pointer to the time difference OsalTimespec.

Returns:

Returns a value listed below:

HDF_STATUS

Description

HDF_SUCCESS

The operation is successful.

HDF_ERR_INVALID_PARAM

Invalid parameter.

OsalDisableIrq()

  1. int32_tOsalDisableIrq(uint32_t irqId)

Description:

Disables an IRQ.

Parameters:

Name

Description

irqIdIndicates the IRQ ID.

Returns:

Returns a value listed below:

HDF_STATUS

Description

HDF_SUCCESS

The operation is successful.

HDF_ERR_INVALID_PARAM

Invalid parameter.

OsalEnableIrq()

  1. int32_tOsalEnableIrq(uint32_t irqId)

Description:

Enables an IRQ.

Parameters:

Name

Description

irqIdIndicates the IRQ ID.

Returns:

Returns a value listed below:

HDF_STATUS

Description

HDF_SUCCESS

The operation is successful.

HDF_ERR_INVALID_PARAM

Invalid parameter.

OsalFileClose()

  1. voidOsalFileClose([OsalFile]($api-api-SmartVision-Devices-OsalFile.md)* file)

Description:

Closes a file.

Parameters:

Name

Description

fileIndicates the pointer to the file type OsalFile.

OsalFileLseek()

  1. off_tOsalFileLseek([OsalFile]($api-api-SmartVision-Devices-OsalFile.md)* file,off_t offset,int32_t whence )

Description:

Sets the file read/write offset.

Parameters:

Name

Description

fileIndicates the pointer to the file type OsalFile.
offsetIndicates the offset to set.
whenceIndicates the position from which the offset is to set. For details, see OSAL_SEEK_SET.

OsalFileOpen()

  1. int32_tOsalFileOpen([OsalFile]($api-api-SmartVision-Devices-OsalFile.md)* file,constchar* path,int flags,uint32_t rights )

Description:

Opens a file.

Parameters:

Name

Description

fileIndicates the pointer to the file type OsalFile.
pathIndicates the pointer to the name of the file to open.
flagsIndicates the mode of opening the file. For details, see OSAL_O_RD_ONLY.
rightsIndicates the permissions required for opening the file. For details, see OSAL_S_IREAD.

Returns:

Returns a value listed below:

HDF_STATUS

Description

HDF_SUCCESS

The operation is successful.

HDF_FAILURE

Failed to invoke the system function to open the file.

HDF_ERR_INVALID_PARAM

Invalid parameter.

OsalFileRead()

  1. ssize_tOsalFileRead([OsalFile]($api-api-SmartVision-Devices-OsalFile.md)* file,void* buf,uint32_t length )

Description:

Reads a file.

Parameters:

Name

Description

fileIndicates the pointer to the file type OsalFile.
bufIndicates the pointer to the buffer for storing the content to read.
lengthIndicates the length of the content to read.

Returns:

Returns a value listed below:

ssize_t

Description

Greater than 0

The length of the file content is successfully read.

HDF_FAILURE HDF_STATUS

Failed to invoke the system function to read the file.

HDF_ERR_INVALID_PARAM HDF_STATUS

Invalid parameter.

OsalFileWrite()

  1. ssize_tOsalFileWrite([OsalFile]($api-api-SmartVision-Devices-OsalFile.md)* file,constvoid*string,uint32_t length )

Description:

Writes a file.

Parameters:

Name

Description

fileIndicates the pointer to the file type OsalFile.
stringIndicates the pointer to the content to write.
lengthIndicates the length of the content to write.

Returns:

Returns a value listed below:

ssize_t

Description

Greater than 0

The length of the file content is successfully written.

HDF_FAILURE HDF_STATUS

Failed to invoke the system function to write the file.

HDF_ERR_INVALID_PARAM HDF_STATUS

Invalid parameter.

OsalGetSysTimeMs()

  1. uint64_tOsalGetSysTimeMs(void)

Description:

Obtains the system time.

Returns:

Returns the system time, in milliseconds.

OsalGetTime()

  1. int32_tOsalGetTime([OsalTimespec]($api-api-SmartVision-Devices-OsalTimespec.md)* time)

Description:

Obtains the second and microsecond time.

Parameters:

Name

Description

timeIndicates the pointer to the time structure OsalTimespec.

Returns:

Returns a value listed below:

HDF_STATUS

Description

HDF_SUCCESS

The operation is successful.

HDF_FAILURE

Failed to invoke the system function to obtain time.

HDF_ERR_INVALID_PARAM

Invalid parameter.

OsalIoRemap()

  1. staticvoid*OsalIoRemap(unsignedlong phys_addr,unsignedlong size )

Description:

Remaps an I/O physical address to its virtual address.

Parameters:

Name

Description

phys_addrIndicates the I/O physical address.
sizeIndicates the size of the physical address to remap.

Returns:

Returns the virtual address.

OsalIoUnmap()

  1. staticvoidOsalIoUnmap(void* addr)

Description:

Unmaps an I/O virtual address associated with the physical address.

The virtual address is the one returned by calling OsalIoRemap.

Parameters:

Name

Description

addrIndicates the pointer to the virtual address to unmap.

OsalMDelay()

  1. voidOsalMDelay(uint32_t ms)

Description:

Describes thread delay, in milliseconds.

When a thread invokes this function, the CPU is not released. This function returns after waiting for milliseconds.

Parameters:

Name

Description

msIndicates the delay time, in milliseconds.

OsalMemAlloc()

  1. void*OsalMemAlloc(size_t size)

Description:

Allocates memory of a specified size.

Parameters:

Name

Description

sizeIndicates the size of memory to allocate.

Returns:

Returns the pointer to the allocated memory if the operation is successful; returns NULL otherwise.

OsalMemAllocAlign()

  1. void*OsalMemAllocAlign(size_t alignment,size_t size )

Description:

Allocates memory of a specified size, and aligns the memory address on a given boundary.

Parameters:

Name

Description

alignmentIndicates the memory boundary alignment. The value must be a power of 2.
sizeIndicates the size of memory to allocate.

Returns:

Returns the pointer to the allocated memory if the operation is successful; returns NULL otherwise.

OsalMemCalloc()

  1. void*OsalMemCalloc(size_t size)

Description:

Allocates memory of a specified size, and clears the allocated memory.

Parameters:

Name

Description

sizeIndicates the size of memory to allocate.

Returns:

Returns the pointer to the allocated memory if the operation is successful; returns NULL otherwise.

OsalMemFree()

  1. voidOsalMemFree(void* mem)

Description:

Releases memory.

Parameters:

Name

Description

memIndicates the pointer to the memory to release.

OsalMSleep()

  1. voidOsalMSleep(uint32_t ms)

Description:

Describes thread sleep, in milliseconds.

When a thread invokes this function, the CPU is released and the thread enters the sleep state.

Parameters:

Name

Description

msIndicates the sleep time, in milliseconds.

OsalMutexDestroy()

  1. int32_tOsalMutexDestroy(struct[OsalMutex]($api-api-SmartVision-Devices-OsalMutex.md)* mutex)

Description:

Destroys a mutex.

Parameters:

Name

Description

mutexIndicates the pointer to the mutex OsalMutex.

Returns:

Returns a value listed below:

HDF_STATUS

Description

HDF_SUCCESS

The operation is successful.

HDF_FAILURE

Failed to invoke the system function to destroy the mutex.

HDF_ERR_INVALID_PARAM

Invalid parameter.

OsalMutexInit()

  1. int32_tOsalMutexInit(struct[OsalMutex]($api-api-SmartVision-Devices-OsalMutex.md)* mutex)

Description:

Initializes a mutex.

Parameters:

Name

Description

mutexIndicates the pointer to the mutex OsalMutex.

Returns:

Returns a value listed below:

HDF_STATUS

Description

HDF_SUCCESS

The operation is successful.

HDF_FAILURE

Failed to invoke the system function to initialize the mutex.

HDF_ERR_INVALID_PARAM

Invalid parameter.

OsalMutexLock()

  1. int32_tOsalMutexLock(struct[OsalMutex]($api-api-SmartVision-Devices-OsalMutex.md)* mutex)

Description:

Locks a mutex.

Parameters:

Name

Description

mutexIndicates the pointer to the mutex OsalMutex.

Returns:

Returns a value listed below:

HDF_STATUS

Description

HDF_SUCCESS

The operation is successful.

HDF_FAILURE

Failed to invoke the system function to lock the mutex.

HDF_ERR_INVALID_PARAM

Invalid parameter.

OsalMutexTimedLock()

  1. int32_tOsalMutexTimedLock(struct[OsalMutex]($api-api-SmartVision-Devices-OsalMutex.md)* mutex,uint32_t ms )

Description:

Locks a mutex with a specified timeout duration.

Parameters:

Name

Description

mutexIndicates the pointer to the mutex OsalMutex.
msIndicates the timeout duration, in milliseconds.

Returns:

Returns a value listed below:

HDF_STATUS

Description

HDF_SUCCESS

The operation is successful.

HDF_FAILURE

Failed to invoke the system function to lock the mutex.

HDF_ERR_INVALID_PARAM

Invalid parameter.

HDF_ERR_TIMEOUT

Timeout occurs.

OsalMutexUnlock()

  1. int32_tOsalMutexUnlock(struct[OsalMutex]($api-api-SmartVision-Devices-OsalMutex.md)* mutex)

Description:

Unlocks a mutex.

Parameters:

Name

Description

mutexIndicates the pointer to the mutex OsalMutex.

Returns:

Returns a value listed below:

HDF_STATUS

Description

HDF_SUCCESS

The operation is successful.

HDF_FAILURE

Failed to invoke the system function to unlock the mutex.

HDF_ERR_INVALID_PARAM

Invalid parameter.

OsalReadFirmware()

  1. int32_tOsalReadFirmware(struct[OsalFirmware]($api-api-SmartVision-Devices-OsalFirmware.md)* fw,struct[OsalFwBlock]($api-api-SmartVision-Devices-OsalFwBlock.md)* block )

Description:

Releases a firmware file.

After the firmware file is read, this function is called to release the firmware file.

Parameters:

Name

Description

fwIndicates the pointer to the firmware file OsalFirmware.

Returns:

Returns a value listed below:

HDF_STATUS

Description

HDF_SUCCESS

The operation is successful.

HDF_FAILURE

Failed to invoke the system function.

HDF_ERR_INVALID_PARAM

Invalid parameter.

OsalRegisterIrq()

  1. int32_tOsalRegisterIrq(uint32_t irqId,uint32_t config,[OsalIRQHandle]($api-api-SmartVision-Devices-OSAL.md#gab671a9e177f622a98af9ca1bd93198eb) handle, const char * name, void * dev )

Description:

Registers an IRQ.

Parameters:

Name

Description

irqIdIndicates the IRQ ID.
configIndicates the interrupt trigger mode. For details, see OSAL_IRQ_TRIGGER_MODE.
handleIndicates the interrupt processing function.
nameIndicates the pointer to the device name for registering an IRQ.
devIndicates the pointer to the parameter passed to the interrupt processing function.

Returns:

Returns a value listed below:

HDF_STATUS

Description

HDF_SUCCESS

The operation is successful.

HDF_FAILURE

Failed to invoke the system function to register the IRQ.

HDF_ERR_INVALID_PARAM

Invalid parameter.

OsalReleaseFirmware()

  1. int32_tOsalReleaseFirmware(struct[OsalFirmware]($api-api-SmartVision-Devices-OsalFirmware.md)* fw)

Description:

Release firmware resource

Parameters:

Name

Description

 fw Firmware parameter, see detail in OsalFirmware block Firmware data block, see detail in hdf_FWBlock

Returns:

: true or false

OsalRequestFirmware()

  1. int32_tOsalRequestFirmware(struct[OsalFirmware]($api-api-SmartVision-Devices-OsalFirmware.md)* fw,constchar* fwName,void* device )

Description:

Requests a firmware file based on its name and device information.

Parameters:

Name

Description

fwIndicates the pointer to the firmware file OsalFirmware, which cannot be empty.
fwNameIndicates the pointer to the firmware file name, which cannot be empty.
deviceIndicates the pointer to the information about the device that requests the firmware file.

Returns:

Returns a value listed below:

HDF_STATUS

Description

HDF_SUCCESS

The operation is successful.

HDF_FAILURE

Failed to invoke the system function.

HDF_ERR_INVALID_PARAM

Invalid parameter.

HDF_ERR_MALLOC_FAIL

Memory allocation fails.

OsalSeekFirmware()

  1. int32_tOsalSeekFirmware(struct[OsalFirmware]($api-api-SmartVision-Devices-OsalFirmware.md)* fw,uint32_t offset )

Description:

Reads a firmware file.

Parameters:

Name

Description

fwIndicates the pointer to the firmware file OsalFirmware.
blockIndicates the pointer to the firmware block to read. For details, see OsalFwBlock.

Returns:

Returns a value listed below:

HDF_STATUS

Description

HDF_SUCCESS

The operation is successful.

HDF_FAILURE

Failed to invoke the system function.

HDF_ERR_INVALID_PARAM

Invalid parameter.

OsalSemDestroy()

  1. int32_tOsalSemDestroy(struct[OsalSem]($api-api-SmartVision-Devices-OsalSem.md)* sem)

Description:

Destroys a semaphore.

Parameters:

Name

Description

semIndicates the pointer to the semaphore OsalSem.

Returns:

Returns a value listed below:

HDF_STATUS

Description

HDF_SUCCESS

The operation is successful.

HDF_FAILURE

Failed to invoke the system function to destroy the semaphore.

HDF_ERR_INVALID_PARAM

Invalid parameter.

OsalSemInit()

  1. int32_tOsalSemInit(struct[OsalSem]($api-api-SmartVision-Devices-OsalSem.md)* sem,uint32_t value )

Description:

Initializes a semaphore.

Parameters:

Name

Description

semIndicates the pointer to the semaphore OsalSem.
valueIndicates the initial value of the semaphore.

Returns:

Returns a value listed below:

HDF_STATUS

Description

HDF_SUCCESS

The operation is successful.

HDF_FAILURE

Failed to invoke the system function to initialize the semaphore.

HDF_ERR_INVALID_PARAM

Invalid parameter.

OsalSemPost()

  1. int32_tOsalSemPost(struct[OsalSem]($api-api-SmartVision-Devices-OsalSem.md)* sem)

Description:

Releases a semaphore.

Parameters:

Name

Description

semIndicates the pointer to the semaphore OsalSem.

Returns:

Returns a value listed below:

HDF_STATUS

Description

HDF_SUCCESS

The operation is successful.

HDF_FAILURE

Failed to invoke the system function to release the semaphore.

HDF_ERR_INVALID_PARAM

Invalid parameter.

OsalSemWait()

  1. int32_tOsalSemWait(struct[OsalSem]($api-api-SmartVision-Devices-OsalSem.md)* sem,uint32_t ms )

Description:

Waits for a semaphore.

Parameters:

Name

Description

semIndicates the pointer to the semaphore OsalSem.
msIndicates the timeout interval.

Returns:

Returns a value listed below:

HDF_STATUS

Description

HDF_SUCCESS

The operation is successful.

HDF_FAILURE

Failed to invoke the system function to wait for the semaphore.

HDF_ERR_INVALID_PARAM

Invalid parameter.

HDF_ERR_TIMEOUT

Timeout occurs.

OsalSleep()

  1. voidOsalSleep(uint32_t sec)

Description:

Describes thread sleep, in seconds.

When a thread invokes this function, the CPU is released and the thread enters the sleep state.

Parameters:

Name

Description

secIndicates the sleep time, in seconds.

OsalSpinDestroy()

  1. int32_tOsalSpinDestroy([OsalSpinlock]($api-api-SmartVision-Devices-OsalSpinlock.md)* spinlock)

Description:

Destroys a spinlock.

Parameters:

Name

Description

spinlockIndicates the pointer to the spinlock OsalSpinlock.

Returns:

Returns a value listed below:

HDF_STATUS

Description

HDF_SUCCESS

The operation is successful.

HDF_FAILURE

Failed to invoke the system function to destroy the spinlock.

HDF_ERR_INVALID_PARAM

Invalid parameter.

OsalSpinInit()

  1. int32_tOsalSpinInit([OsalSpinlock]($api-api-SmartVision-Devices-OsalSpinlock.md)* spinlock)

Description:

Initializes a spinlock.

Parameters:

Name

Description

spinlockIndicates the pointer to the spinlock OsalSpinlock.

Returns:

Returns a value listed below:

HDF_STATUS

Description

HDF_SUCCESS

The operation is successful.

HDF_FAILURE

Failed to invoke the system function to initialize the spinlock.

HDF_ERR_INVALID_PARAM

Invalid parameter.

HDF_ERR_MALLOC_FAIL

Memory allocation fails.

OsalSpinLock()

  1. int32_tOsalSpinLock([OsalSpinlock]($api-api-SmartVision-Devices-OsalSpinlock.md)* spinlock)

Description:

Obtains a spinlock.

Parameters:

Name

Description

spinlockIndicates the pointer to the spinlock OsalSpinlock.

Returns:

Returns a value listed below:

HDF_STATUS

Description

HDF_SUCCESS

The operation is successful.

HDF_FAILURE

Failed to invoke the system function to obtain the spinlock.

HDF_ERR_INVALID_PARAM

Invalid parameter.

OsalSpinLockIrq()

  1. int32_tOsalSpinLockIrq([OsalSpinlock]($api-api-SmartVision-Devices-OsalSpinlock.md)* spinlock)

Description:

Obtains a spinlock and disables the IRQ.

Parameters:

Name

Description

spinlockIndicates the pointer to the spinlock OsalSpinlock.

Returns:

Returns a value listed below:

HDF_STATUS

Description

HDF_SUCCESS

The operation is successful.

HDF_FAILURE

Failed to invoke the system function to obtain the spinlock.

HDF_ERR_INVALID_PARAM

Invalid parameter.

OsalSpinLockIrqSave()

  1. int32_tOsalSpinLockIrqSave([OsalSpinlock]($api-api-SmartVision-Devices-OsalSpinlock.md)* spinlock,uint32_t* flags )

Description:

Obtains a spinlock, disables the IRQ, and saves its status.

Parameters:

Name

Description

spinlockIndicates the pointer to the spinlock OsalSpinlock.
flagsIndicates the pointer to the status of the IRQ register.

Returns:

Returns a value listed below:

HDF_STATUS

Description

HDF_SUCCESS

The operation is successful.

HDF_FAILURE

Failed to invoke the system function to obtain the spinlock.

HDF_ERR_INVALID_PARAM

Invalid parameter.

OsalSpinUnlock()

  1. int32_tOsalSpinUnlock([OsalSpinlock]($api-api-SmartVision-Devices-OsalSpinlock.md)* spinlock)

Description:

Releases a spinlock.

Parameters:

Name

Description

spinlockIndicates the pointer to the spinlock OsalSpinlock.

Returns:

Returns a value listed below:

HDF_STATUS

Description

HDF_SUCCESS

The operation is successful.

HDF_FAILURE

Failed to invoke the system function to release the spinlock.

HDF_ERR_INVALID_PARAM

Invalid parameter.

OsalSpinUnlockIrq()

  1. int32_tOsalSpinUnlockIrq([OsalSpinlock]($api-api-SmartVision-Devices-OsalSpinlock.md)* spinlock)

Description:

Releases a spinlock and enables the IRQ.

Parameters:

Name

Description

spinlockIndicates the pointer to the spinlock OsalSpinlock.

Returns:

Returns a value listed below:

HDF_STATUS

Description

HDF_SUCCESS

The operation is successful.

HDF_FAILURE

Failed to invoke the system function to release the spinlock.

HDF_ERR_INVALID_PARAM

Invalid parameter.

OsalSpinUnlockIrqRestore()

  1. int32_tOsalSpinUnlockIrqRestore([OsalSpinlock]($api-api-SmartVision-Devices-OsalSpinlock.md)* spinlock,uint32_t* flags )

Description:

Releases a spinlock, enables the IRQ, and restores the saved IRQ status.

Parameters:

Name

Description

spinlockIndicates the pointer to the spinlock OsalSpinlock.
flagsIndicates the pointer to the value used to restore the IRQ register.

Returns:

Returns a value listed below:

HDF_STATUS

Description

HDF_SUCCESS

The operation is successful.

HDF_FAILURE

Failed to invoke the system function to release the spinlock.

HDF_ERR_INVALID_PARAM

Invalid parameter.

OsalTestBit()

  1. int32_tOsalTestBit(unsignedlong nr,constvolatileunsignedlong* addr )

Description:

Tests the value of a specified bit of a variable.

Parameters:

Name

Description

nrIndicates the bit of the variable. The value ranges from 0 to 31.
addrIndicates the pointer to the variable.

Returns:

Returns the bit value.

OsalTestClearBit()

  1. int32_tOsalTestClearBit(unsignedlong nr,volatileunsignedlong* addr )

Description:

Clears the value of a specified bit of the variable and returns the bit value before clearing.

Parameters:

Name

Description

nrIndicates the bit of the variable. The value ranges from 0 to 31.
addrIndicates the pointer to the variable.

Returns:

Returns the bit value before the bit is cleared.

OsalTestSetBit()

  1. int32_tOsalTestSetBit(unsignedlong nr,volatileunsignedlong* addr )

Description:

Sets the value of a specified bit of the variable and returns the bit value before the setting.

Parameters:

Name

Description

nrIndicates the bit of the variable. The value ranges from 0 to 31.
addrIndicates the pointer to the variable.

Returns:

Returns the bit value before the setting.

OsalThreadCreate()

  1. int32_tOsalThreadCreate(struct[OsalThread]($api-api-SmartVision-Devices-OsalThread.md)* thread,[OsalThreadEntry]($api-api-SmartVision-Devices-OSAL.md#ga21ea0f87d53e65ec86a424c532d688d8) threadEntry, void * entryPara )

Description:

Creates a thread.

Parameters:

Name

Description

threadIndicates the pointer to the thread OsalThread.
threadEntryIndicates the thread callback function OsalThreadEntry.
entryParaIndicates the pointer to the parameter passed to the thread callback function.

Returns:

Returns a value listed below:

HDF_STATUS

Description

HDF_SUCCESS

The operation is successful.

HDF_ERR_INVALID_PARAM

Invalid parameter.

HDF_ERR_MALLOC_FAIL

Memory allocation fails.

OsalThreadDestroy()

  1. int32_tOsalThreadDestroy(struct[OsalThread]($api-api-SmartVision-Devices-OsalThread.md)* thread)

Description:

Destroys a thread.

Parameters:

Name

Description

threadIndicates the pointer to the thread OsalThread.

Returns:

Returns a value listed below:

HDF_STATUS

Description

HDF_SUCCESS

The operation is successful.

HDF_FAILURE

Failed to invoke the system function to destroy the thread.

HDF_ERR_INVALID_PARAM

Invalid parameter.

OsalThreadResume()

  1. int32_tOsalThreadResume(struct[OsalThread]($api-api-SmartVision-Devices-OsalThread.md)* thread)

Description:

Resumes a thread.

Parameters:

Name

Description

threadIndicates the pointer to the thread OsalThread.

Returns:

Returns a value listed below:

HDF_STATUS

Description

HDF_SUCCESS

The operation is successful.

HDF_FAILURE

Failed to invoke the system function to resume the thread.

HDF_ERR_INVALID_PARAM

Invalid parameter.

OsalThreadStart()

  1. int32_tOsalThreadStart(struct[OsalThread]($api-api-SmartVision-Devices-OsalThread.md)* thread,conststruct[OsalThreadParam]($api-api-SmartVision-Devices-OsalThreadParam.md)* param )

Description:

Starts a thread.

Parameters:

Name

Description

threadIndicates the pointer to the thread OsalThread.
paramIndicates the pointer to the parameter used to start a thread. For details, see OsalThreadParam.

Returns:

Returns a value listed below:

HDF_STATUS

Description

HDF_SUCCESS

The operation is successful.

HDF_FAILURE

Failed to invoke the system function to start the thread.

HDF_ERR_INVALID_PARAM

Invalid parameter.

OsalThreadSuspend()

  1. int32_tOsalThreadSuspend(struct[OsalThread]($api-api-SmartVision-Devices-OsalThread.md)* thread)

Description:

Suspends a thread.

Parameters:

Name

Description

threadIndicates the pointer to the thread OsalThread.

Returns:

Returns a value listed below:

HDF_STATUS

Description

HDF_SUCCESS

The operation is successful.

HDF_FAILURE

Failed to invoke the system function to suspend the thread.

HDF_ERR_INVALID_PARAM

Invalid parameter.

OsalTimerCreate()

  1. int32_tOsalTimerCreate([OsalTimer]($api-api-SmartVision-Devices-OsalTimer.md)* timer,uint32_t interval,[OsalTimerFunc]($api-api-SmartVision-Devices-OSAL.md#gaf3e7a12075b25df5971049d8cd77c25c) func, uintptr_t arg )

Description:

Creates a timer.

Parameters:

Name

Description

timerIndicates the pointer to the timer OsalTimer.
intervalIndicates the timer interval.
funcIndicates the timer execution function OsalTimerFunc.
argIndicates the argument passed to the timer execution function.

Returns:

Returns a value listed below:

HDF_STATUS

Description

HDF_SUCCESS

The operation is successful.

HDF_FAILURE

Failed to invoke the system function.

HDF_ERR_INVALID_PARAM

Invalid parameter.

HDF_ERR_MALLOC_FAIL

Memory allocation fails.

OsalTimerDelete()

  1. int32_tOsalTimerDelete([OsalTimer]($api-api-SmartVision-Devices-OsalTimer.md)* timer)

Description:

Deletes a timer.

Parameters:

Name

Description

timerIndicates the pointer to the timer OsalTimer.

Returns:

Returns a value listed below:

HDF_STATUS

Description

HDF_SUCCESS

The operation is successful.

HDF_FAILURE

Failed to invoke the system function to delete the timer.

HDF_ERR_INVALID_PARAM

Invalid parameter.

OsalTimerSetTimeout()

  1. int32_tOsalTimerSetTimeout([OsalTimer]($api-api-SmartVision-Devices-OsalTimer.md)* timer,uint32_t interval )

Description:

Sets the interval of a timer.

Parameters:

Name

Description

timerIndicates the pointer to the timer OsalTimer.
intervalIndicates the timer interval, in milliseconds.

Returns:

Returns a value listed below:

HDF_STATUS

Description

HDF_SUCCESS

The operation is successful.

HDF_FAILURE

Failed to invoke the system function.

HDF_ERR_INVALID_PARAM

Invalid parameter.

OsalTimerStartLoop()

  1. int32_tOsalTimerStartLoop([OsalTimer]($api-api-SmartVision-Devices-OsalTimer.md)* timer)

Description:

Starts a periodic timer.

Parameters:

Name

Description

timerIndicates the pointer to the timer OsalTimer.
intervalIndicates the timer interval, in milliseconds.

Returns:

Returns a value listed below:

HDF_STATUS

Description

HDF_SUCCESS

The operation is successful.

HDF_FAILURE

Failed to invoke the system function to start the timer.

HDF_ERR_INVALID_PARAM

Invalid parameter.

OsalTimerStartOnce()

  1. int32_tOsalTimerStartOnce([OsalTimer]($api-api-SmartVision-Devices-OsalTimer.md)* timer)

Description:

Starts a timer.

Parameters:

Name

Description

timerIndicates the pointer to the timer OsalTimer.

Returns:

Returns a value listed below:

HDF_STATUS

Description

HDF_SUCCESS

The operation is successful.

HDF_FAILURE

Failed to invoke the system function to start the timer.

HDF_ERR_INVALID_PARAM

Invalid parameter.

OsalUDelay()

  1. voidOsalUDelay(uint32_t us)

Description:

Describes thread delay, in microseconds.

When a thread invokes this function, the CPU is not released. This function returns after waiting for microseconds.

Parameters:

Name

Description

usIndicates the delay time, in microseconds.

OsalUnregisterIrq()

  1. int32_tOsalUnregisterIrq(uint32_t irqId)

Description:

Unregisters an IRQ.

Parameters:

Name

Description

irqIdIndicates the IRQ ID.

Returns:

Returns a value listed below:

HDF_STATUS

Description

HDF_SUCCESS

The operation is successful.

HDF_FAILURE

Failed to invoke the system function to unregister the IRQ.

HDF_ERR_INVALID_PARAM

Invalid parameter.