/*******************************************************************************
* @file rsi_os.h
* @brief
*******************************************************************************
* # License
* <b>Copyright 2020 Silicon Laboratories Inc. www.silabs.com</b>
*******************************************************************************
*
* The licensor of this software is Silicon Laboratories Inc. Your use of this
* software is governed by the terms of Silicon Labs Master Software License
* Agreement (MSLA) available at
* www.silabs.com/about-us/legal/master-software-license-agreement. This
* software is distributed to you in Source Code format and is governed by the
* sections of the MSLA applicable to Source Code.
*
******************************************************************************/
#ifndef RSI_OS_H
#define RSI_OS_H
#include "rsi_error.h"
#include "rsi_data_types.h"
/******************************************************
* * Macros
* ******************************************************/
// Macro to increment a value
#define RSI_ATOMIC_INCREMENT(value) \
{ \
(value)++; \
}
// Macro to decrement a value
#define RSI_ATOMIC_DECREMENT(value) \
{ \
(value)--; \
}
// Error none (success)
#define RSI_ERR_NONE (0)
// Error returned when invalid arguments are given
#define RSI_ERR_INVALID_ARGS (1)
// Error returned when timeout error occurs
#define RSI_ERR_TIMEOUT (3)
// Mutex unlock value
#define RSI_NO_OS_MUTEX_UNLOCKED (0)
// Mutex lock value
#define RSI_NO_OS_MUTEX_LOCKED (1)
// Macro to set the mutex lock
#define RSI_NO_OS_ATOMIC_MUTEX_SET(mutex, value) (mutex) = value
// Macro for checking whether mutex is locked or not
#define RSI_NO_OS_ATOMIC_MUTEX_CHECK(mutex, value) (((mutex) == value) ? 1 : 0)
/******************************************************
* * Constants
* ******************************************************/
/******************************************************
* * Enumerations
* ******************************************************/
/******************************************************
* * Type Definitions
* ******************************************************/
typedef uint32_t rsi_reg_flags_t;
// Handle to manage Semaphores.
typedef uint32_t rsi_semaphore_handle_t;
// Handle to manage Mutex.
typedef uint32_t rsi_mutex_handle_t;
// Task handler
typedef void *rsi_task_handle_t;
typedef long rsi_base_type_t;
// Task function
typedef void (*rsi_task_function_t)(void *function);
/******************************************************
* * Structures
* ******************************************************/
/******************************************************
* * Global Variables
* ******************************************************/
/******************************************************
* * Function Declarations
* ******************************************************/
/* --------- CRITICAL SECTION FUNCTIONS --------- */
rsi_reg_flags_t rsi_critical_section_entry(void);
void rsi_critical_section_exit(rsi_reg_flags_t flags);
/* -------------- MUTEX FUNCTIONS -------------- */
rsi_error_t rsi_mutex_create(rsi_mutex_handle_t *p_mutex);
rsi_error_t rsi_mutex_lock(volatile rsi_mutex_handle_t *p_mutex);
void rsi_mutex_lock_from_isr(volatile rsi_mutex_handle_t *mutex);
rsi_error_t rsi_mutex_unlock(volatile rsi_mutex_handle_t *p_mutex);
void rsi_mutex_unlock_from_isr(volatile rsi_mutex_handle_t *mutex);
rsi_error_t rsi_mutex_destroy(rsi_mutex_handle_t *p_mutex);
/* ------------- SEMAPHORE FUNCTIONS ----------- */
rsi_error_t rsi_semaphore_create(rsi_semaphore_handle_t *p_sem, uint32_t cnt);
rsi_error_t rsi_semaphore_destroy(rsi_semaphore_handle_t *p_sem);
rsi_error_t rsi_semaphore_check_and_destroy(rsi_semaphore_handle_t *p_sem);
rsi_error_t rsi_semaphore_wait(rsi_semaphore_handle_t *p_sem, uint32_t timeout);
rsi_error_t rsi_semaphore_post(rsi_semaphore_handle_t *p_sem);
rsi_error_t rsi_semaphore_post_from_isr(rsi_semaphore_handle_t *semaphore);
rsi_error_t rsi_semaphore_reset(rsi_semaphore_handle_t *p_sem);
/* ------------- TASK FUNCTIONS ----------- */
rsi_error_t rsi_task_create(rsi_task_function_t task_function,
uint8_t *task_name,
uint32_t stack_size,
void *parameters,
uint32_t task_priority,
rsi_task_handle_t *task_handle);
void rsi_task_destroy(rsi_task_handle_t *task_handle);
void rsi_task_delete(rsi_task_handle_t *task_handle);
void rsi_os_task_delay(uint32_t timeout_ms);
void rsi_task_suspend(rsi_task_handle_t *task_handle);
void rsi_start_os_scheduler(void);
void rsi_wireless_driver_task_create(void);
uint32_t rsi_ms_to_tick(uint32_t timeout_ms);
/* ---------- OS MEMORY MAPPING FUNCTIONS -------- */
void *rsi_virtual_to_physical_address(void *x);
void *rsi_physical_to_virtual_address(void *x);
void *rsi_malloc(uint32_t size);
void rsi_free(void *p);
void rsi_vport_enter_critical(void);
void rsi_vport_exit_critical(void);
int32_t rsi_get_error(int32_t sockID);
void rsi_set_os_errno(int32_t error);
#endif
Typedefs#
Functions#
Enter critical section.
Exit critical section by restoring interrupts.
Create and initialize the mutex.
Lock the mutex.
Lock the mutex from ISR context.
Unlock the mutex.
Unlock the mutex from ISR context.
Destroy the mutex.
Create and initialize the semaphore instance.
Destroy the semaphore instance.
Checks whether the semaphore is created and destroys the semaphore instance, if its created.
Wait for semaphore.
Release semaphore, which is acquired.
Release semaphore, which is acquired from ISR context.
Create OS task/thread.
Destroy the task created.
Induce required delay in milli seconds.
Exit critical section.
Schedule the tasks created.
Map virtual address to physical address.
Map physical address to virtual address.
Allocate memory from the buffer which is maintained by freeRTOS.
Free the memory pointed by 'ptr'.
Enter into critical section.
Enter exit section.
Get WLAN status.
Sets the OS error .
Typedef Documentation#
Function Documentation#
rsi_critical_section_entry#
rsi_reg_flags_t rsi_critical_section_entry (void )
Enter critical section.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | [in] |
Returns
Interrupt status before entering critical section
rsi_critical_section_exit#
void rsi_critical_section_exit (rsi_reg_flags_t xflags)
Exit critical section by restoring interrupts.
Type | Direction | Argument Name | Description |
---|---|---|---|
rsi_reg_flags_t | [in] | xflags | - Interrupt status to restore interrupt on exit from critical section |
Returns
Void
rsi_mutex_create#
rsi_error_t rsi_mutex_create (rsi_mutex_handle_t * mutex)
Create and initialize the mutex.
Type | Direction | Argument Name | Description |
---|---|---|---|
rsi_mutex_handle_t * | [in] | mutex | - Mutex handle pointer |
Returns
0 - Success
Negative Value - Failure
rsi_mutex_lock#
rsi_error_t rsi_mutex_lock (volatile rsi_mutex_handle_t * mutex)
Lock the mutex.
Type | Direction | Argument Name | Description |
---|---|---|---|
volatile rsi_mutex_handle_t * | [in] | mutex | - Mutex handle pointer |
Returns
0 - Success
Negative Value - Failure
rsi_mutex_lock_from_isr#
void rsi_mutex_lock_from_isr (volatile rsi_mutex_handle_t * mutex)
Lock the mutex from ISR context.
Type | Direction | Argument Name | Description |
---|---|---|---|
volatile rsi_mutex_handle_t * | [in] | mutex | - Mutex handle pointer |
Returns
0 - Success
Negative Value - Failure
rsi_mutex_unlock#
rsi_error_t rsi_mutex_unlock (volatile rsi_mutex_handle_t * mutex)
Unlock the mutex.
Type | Direction | Argument Name | Description |
---|---|---|---|
volatile rsi_mutex_handle_t * | [in] | mutex | - Mutex handle pointer |
Returns
0 - Success
Negative Value - Failure
rsi_mutex_unlock_from_isr#
void rsi_mutex_unlock_from_isr (volatile rsi_mutex_handle_t * mutex)
Unlock the mutex from ISR context.
Type | Direction | Argument Name | Description |
---|---|---|---|
volatile rsi_mutex_handle_t * | [in] | mutex | - Mutex handle pointer |
Returns
None
rsi_mutex_destroy#
rsi_error_t rsi_mutex_destroy (rsi_mutex_handle_t * mutex)
Destroy the mutex.
Type | Direction | Argument Name | Description |
---|---|---|---|
rsi_mutex_handle_t * | [in] | mutex | - Mutex handle pointer |
Returns
0 - Success
Negative Value - Failure
rsi_semaphore_create#
rsi_error_t rsi_semaphore_create (rsi_semaphore_handle_t * semaphore, uint32_t count)
Create and initialize the semaphore instance.
Type | Direction | Argument Name | Description |
---|---|---|---|
rsi_semaphore_handle_t * | [in] | semaphore | - Semaphore handle pointer |
uint32_t | [in] | count | - Resource count |
Returns
0 - Success
Negative Value - Failure
rsi_semaphore_destroy#
rsi_error_t rsi_semaphore_destroy (rsi_semaphore_handle_t * semaphore)
Destroy the semaphore instance.
Type | Direction | Argument Name | Description |
---|---|---|---|
rsi_semaphore_handle_t * | [in] | semaphore | - Semaphore handle pointer |
Returns
0 - Success
Negative Value - Failure
rsi_semaphore_check_and_destroy#
rsi_error_t rsi_semaphore_check_and_destroy (rsi_semaphore_handle_t * semaphore)
Checks whether the semaphore is created and destroys the semaphore instance, if its created.
Type | Direction | Argument Name | Description |
---|---|---|---|
rsi_semaphore_handle_t * | [in] | semaphore | - Semaphore handle pointer |
Check whether the semaphore is created and destroy, if created.
Returns
0 - Success
Negative Value - Failure
Returns
0 - Success
Negative Value - Failure
rsi_semaphore_wait#
rsi_error_t rsi_semaphore_wait (rsi_semaphore_handle_t * semaphore, uint32_t timeout_ms)
Wait for semaphore.
Type | Direction | Argument Name | Description |
---|---|---|---|
rsi_semaphore_handle_t * | [in] | semaphore | - Semaphore handle pointer |
uint32_t | [in] | timeout_ms | - Maximum time to wait to acquire semaphore. If timeout_ms is 0 then wait till semaphore is acquired. |
Returns
0 - Success
Negative Value - Failure
rsi_semaphore_post#
rsi_error_t rsi_semaphore_post (rsi_semaphore_handle_t * semaphore)
Release semaphore, which is acquired.
Type | Direction | Argument Name | Description |
---|---|---|---|
rsi_semaphore_handle_t * | [in] | semaphore | - Semaphore handle pointer |
Returns
0 - Success
Negative Value - Failure
rsi_semaphore_post_from_isr#
rsi_error_t rsi_semaphore_post_from_isr (rsi_semaphore_handle_t * semaphore)
Release semaphore, which is acquired from ISR context.
Type | Direction | Argument Name | Description |
---|---|---|---|
rsi_semaphore_handle_t * | [in] | semaphore | - Semaphore handle pointer |
Returns
0 - Success
Negative Value - Failure
rsi_semaphore_reset#
rsi_error_t rsi_semaphore_reset (rsi_semaphore_handle_t * p_sem)
Type | Direction | Argument Name | Description |
---|---|---|---|
rsi_semaphore_handle_t * | N/A | p_sem |
rsi_task_create#
rsi_error_t rsi_task_create (rsi_task_function_t task_function, uint8_t * task_name, uint32_t stack_size, void * parameters, uint32_t task_priority, rsi_task_handle_t * task_handle)
Create OS task/thread.
Type | Direction | Argument Name | Description |
---|---|---|---|
rsi_task_function_t | [in] | task_function | - Pointer to function to be executed by created thread. |
uint8_t * | [in] | task_name | - Name of the created task |
uint32_t | [in] | stack_size | - Stack size given to the created task |
void * | [in] | parameters | - Pointer to the parameters to be passed to task function |
uint32_t | [in] | task_priority | - Task priority |
rsi_task_handle_t * | [in] | task_handle | - Task handle/instance created |
Returns
0 - Success
Negative Value - Failure
rsi_task_destroy#
void rsi_task_destroy (rsi_task_handle_t * task_handle)
Destroy the task created.
Type | Direction | Argument Name | Description |
---|---|---|---|
rsi_task_handle_t * | [in] | task_handle | - Task handle/instance to be deleted |
Returns
Void
rsi_task_delete#
void rsi_task_delete (rsi_task_handle_t * task_handle)
Type | Direction | Argument Name | Description |
---|---|---|---|
rsi_task_handle_t * | N/A | task_handle |
rsi_os_task_delay#
void rsi_os_task_delay (uint32_t timeout_ms)
Induce required delay in milli seconds.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint32_t | [in] | timeout_ms | - Expected delay in milli seconds |
Returns
Void
rsi_task_suspend#
void rsi_task_suspend (rsi_task_handle_t * task_handle)
Exit critical section.
Type | Direction | Argument Name | Description |
---|---|---|---|
rsi_task_handle_t * | [in] | task_handle | - Task handle to be suspended |
Returns
Void
rsi_start_os_scheduler#
void rsi_start_os_scheduler (void )
Schedule the tasks created.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | [in] |
Returns
Void
rsi_wireless_driver_task_create#
void rsi_wireless_driver_task_create (void )
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
rsi_ms_to_tick#
uint32_t rsi_ms_to_tick (uint32_t timeout_ms)
Type | Direction | Argument Name | Description |
---|---|---|---|
uint32_t | N/A | timeout_ms |
rsi_virtual_to_physical_address#
void * rsi_virtual_to_physical_address (void * virtual_address)
Map virtual address to physical address.
Type | Direction | Argument Name | Description |
---|---|---|---|
void * | [in] | virtual_address | - pointer to virtual address |
Returns
void
rsi_physical_to_virtual_address#
void * rsi_physical_to_virtual_address (void * physical_address)
Map physical address to virtual address.
Type | Direction | Argument Name | Description |
---|---|---|---|
void * | [in] | physical_address | - pointer to physical_address |
Returns
void
rsi_malloc#
void * rsi_malloc (uint32_t size)
Allocate memory from the buffer which is maintained by freeRTOS.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint32_t | [in] | size | - Required bytes in size |
Returns
Void
rsi_free#
void rsi_free (void * ptr)
Free the memory pointed by 'ptr'.
Type | Direction | Argument Name | Description |
---|---|---|---|
void * | [in] | ptr | - starting address of the memory to be freed |
Returns
Void
rsi_vport_enter_critical#
void rsi_vport_enter_critical (void )
Enter into critical section.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | [in] |
Returns
Void
rsi_vport_exit_critical#
void rsi_vport_exit_critical (void )
Enter exit section.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | [in] |
Returns
Void
rsi_get_error#
int32_t rsi_get_error (int32_t sockID)
Get WLAN status.
Type | Direction | Argument Name | Description |
---|---|---|---|
int32_t | [in] | sockID | - Socket ID |
Returns
WLAN status
rsi_set_os_errno#
void rsi_set_os_errno (int32_t error)
Sets the OS error .
Type | Direction | Argument Name | Description |
---|---|---|---|
int32_t | [in] | error | - Error |
Returns
Void