/*******************************************************************************
* @file rsi_os_none.c
* @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.
*
******************************************************************************/
#include <rsi_driver.h>
#ifndef RSI_WITH_OS
/*
Include files
*/
/*==============================================*/
rsi_reg_flags_t rsi_critical_section_entry(void)
{
rsi_reg_flags_t xflags;
// hold interrupt status before entering critical section
// disable interrupts
#ifdef RSI_M4_INTERFACE
xflags = NVIC_GetIRQEnable((IRQn_Type)M4_ISR_IRQ);
NVIC_DisableIRQ((IRQn_Type)M4_ISR_IRQ);
#else
xflags = rsi_hal_critical_section_entry();
#endif
// return stored interrupt status
return (xflags);
}
/*==============================================*/
void rsi_critical_section_exit(rsi_reg_flags_t xflags)
{
// restore interrupts while exiting critical section
if (xflags != 0) {
#ifdef RSI_M4_INTERFACE
// restore interrupts while exiting critical section
NVIC_EnableIRQ((IRQn_Type)M4_ISR_IRQ);
#else
rsi_hal_critical_section_exit();
#endif
}
}
/*==============================================*/
void *rsi_virtual_to_physical_address(void *virtual_address)
{
return (virtual_address);
}
/*==============================================*/
void *rsi_physical_to_virtual_address(void *physical_address)
{
return (physical_address);
}
/*==============================================*/
rsi_error_t rsi_mutex_create(rsi_mutex_handle_t *mutex)
{
/* Create dummy mutxe pointer because OS not present */
RSI_NO_OS_ATOMIC_MUTEX_SET(*mutex, RSI_NO_OS_MUTEX_UNLOCKED);
return (RSI_ERROR_NONE);
}
/*==============================================*/
rsi_error_t rsi_mutex_lock(volatile rsi_mutex_handle_t *mutex)
{
while (RSI_NO_OS_ATOMIC_MUTEX_CHECK(*mutex, RSI_NO_OS_MUTEX_LOCKED))
;
RSI_NO_OS_ATOMIC_MUTEX_SET(*mutex, RSI_NO_OS_MUTEX_LOCKED);
return (RSI_ERROR_NONE);
}
/*==============================================*/
rsi_error_t rsi_mutex_unlock(volatile rsi_mutex_handle_t *mutex)
{
RSI_NO_OS_ATOMIC_MUTEX_SET(*mutex, RSI_NO_OS_MUTEX_UNLOCKED);
return (RSI_ERROR_NONE);
}
/*==============================================*/
rsi_error_t rsi_mutex_destroy(rsi_mutex_handle_t *mutex)
{
UNUSED_PARAMETER(mutex); //This statement is added only to resolve compilation warning, value is unchanged
return (RSI_ERROR_NONE);
}
/*==============================================*/
rsi_error_t rsi_semaphore_create(rsi_semaphore_handle_t *semaphore, uint32_t count)
{
*semaphore = count;
return (RSI_ERROR_NONE);
}
/*==============================================*/
rsi_error_t rsi_semaphore_destroy(rsi_semaphore_handle_t *semaphore)
{
*semaphore = 0;
return (RSI_ERROR_NONE);
}
/*==============================================*/
rsi_error_t rsi_semaphore_check_and_destroy(rsi_semaphore_handle_t *semaphore)
{
if (rsi_semaphore_destroy(semaphore) != RSI_ERROR_NONE) {
return RSI_ERROR_SEMAPHORE_DESTROY_FAILED;
}
return (RSI_ERROR_NONE);
}
/*==============================================*/
rsi_error_t rsi_semaphore_wait(rsi_semaphore_handle_t *semaphore, uint32_t timeout_ms)
{
volatile uint32_t *event;
rsi_timer_instance_t timer_instance;
rsi_driver_cb_t *rsi_driver_cb = global_cb_p->rsi_driver_cb;
event = (uint32_t *)semaphore;
if (0UL != *event) {
RSI_ATOMIC_DECREMENT(*event);
return (RSI_ERROR_NONE);
}
if (0UL == timeout_ms) {
while (0UL == *event) {
// if any events pending
// call rsi schedular
rsi_scheduler(&rsi_driver_cb->scheduler_cb);
}
RSI_ATOMIC_DECREMENT(*event);
return (RSI_ERROR_NONE);
}
rsi_init_timer(&timer_instance, timeout_ms);
while ((0UL != timeout_ms) && (0UL == *event)) {
// if any events pending
// call rsi schedular
rsi_scheduler(&rsi_driver_cb->scheduler_cb);
if (rsi_timer_expired(&timer_instance)) {
break;
}
}
if (0UL == *event || (0UL == timeout_ms)) {
return (RSI_ERROR_TIMEOUT);
} else {
RSI_ATOMIC_DECREMENT(*event);
}
return (RSI_ERROR_NONE);
}
/*==============================================*/
rsi_error_t rsi_semaphore_post_from_isr(rsi_semaphore_handle_t *semaphore)
{
volatile uint32_t *event;
event = (uint32_t *)semaphore;
RSI_ATOMIC_INCREMENT(*event);
return (RSI_ERROR_NONE);
}
/*==============================================*/
rsi_error_t rsi_semaphore_post(rsi_semaphore_handle_t *semaphore)
{
volatile uint32_t *event;
event = (uint32_t *)semaphore;
RSI_ATOMIC_INCREMENT(*event);
return (RSI_ERROR_NONE);
}
/*==============================================*/
rsi_error_t rsi_semaphore_reset(rsi_semaphore_handle_t *semaphore)
{
volatile uint32_t *event;
event = (uint32_t *)semaphore;
*event = 0;
return (RSI_ERROR_NONE);
}
#endif
Functions#
Disable interrupt to enter crtical section.
Exit critical section by restoring interrupts.
Map virtual address to physical address.
Map physical address to virtual address.
Create and initialize the mutex.
Take the mutex.
Give the mutex.
Destroye the mutex.
Create and initialize the semaphore instance.
Destroy the semaphore instance.
Check whether semaphore is created or not, It destroys the semaphore instance,if its created, otherwise should return Success.
Wireless library to acquire or wait for semaphore.
Wireless library to release semaphore, which was acquired.
Wireless library to release semaphore, which was acquired.
Used by Wireless Library to reset the semaphore.
Function Documentation#
rsi_critical_section_entry#
rsi_reg_flags_t rsi_critical_section_entry (void )
Disable interrupt to enter crtical section.
[in] |
Returns
flags - interrupt status before entering critical section
31
of file driver/rsi_os_none.c
rsi_critical_section_exit#
rsi_critical_section_exit (rsi_reg_flags_t xflags)
Exit critical section by restoring interrupts.
[in] | xflags | - interrupt status to restore interrupt on exit from critical section |
Returns
Void
52
of file driver/rsi_os_none.c
rsi_virtual_to_physical_address#
void * rsi_virtual_to_physical_address (void * virtual_address)
Map virtual address to physical address.
[in] | virtual_address | - pointer to virtual address |
Returns
void
72
of file driver/rsi_os_none.c
rsi_physical_to_virtual_address#
void * rsi_physical_to_virtual_address (void * physical_address)
Map physical address to virtual address.
[in] | physical_address | - pointer to physical_address |
Returns
void
85
of file driver/rsi_os_none.c
rsi_mutex_create#
rsi_error_t rsi_mutex_create (rsi_mutex_handle_t * mutex)
Create and initialize the mutex.
[in] | mutex | - Mutex handle pointer |
Returns
0 - Success Negative Value - Failure
96
of file driver/rsi_os_none.c
rsi_mutex_lock#
rsi_error_t rsi_mutex_lock (volatile rsi_mutex_handle_t * mutex)
Take the mutex.
[in] | mutex | - Mutex handle pointer |
Returns
0 - Success Negative Value - Failure
108
of file driver/rsi_os_none.c
rsi_mutex_unlock#
rsi_error_t rsi_mutex_unlock (volatile rsi_mutex_handle_t * mutex)
Give the mutex.
[in] | mutex | - Mutex handle pointer |
Returns
0 - Success Negative Value - Failure
120
of file driver/rsi_os_none.c
rsi_mutex_destroy#
rsi_error_t rsi_mutex_destroy (rsi_mutex_handle_t * mutex)
Destroye the mutex.
[in] | mutex | - Mutex handle pointer |
Returns
0 - Success Negative Value - Failure
131
of file driver/rsi_os_none.c
rsi_semaphore_create#
rsi_error_t rsi_semaphore_create (rsi_semaphore_handle_t * semaphore, uint32_t count)
Create and initialize the semaphore instance.
[in] | semaphore | - Semaphore handle pointer |
[in] | count | - Resource count |
Returns
0 - Success Negative Value - Failure
142
of file driver/rsi_os_none.c
rsi_semaphore_destroy#
rsi_error_t rsi_semaphore_destroy (rsi_semaphore_handle_t * semaphore)
Destroy the semaphore instance.
[in] | semaphore | - Semaphore handle pointer |
Returns
0 - Success Negative Value - Failure
154
of file driver/rsi_os_none.c
rsi_semaphore_check_and_destroy#
rsi_error_t rsi_semaphore_check_and_destroy (rsi_semaphore_handle_t * semaphore)
Check whether semaphore is created or not, It destroys the semaphore instance,if its created, otherwise should return Success.
[in] | semaphore | - Semaphore handle pointer |
Returns
0 - Success Negative Value - Failure
169
of file driver/rsi_os_none.c
rsi_semaphore_wait#
rsi_error_t rsi_semaphore_wait (rsi_semaphore_handle_t * semaphore, uint32_t timeout_ms)
Wireless library to acquire or wait for semaphore.
[in] | semaphore | - Semaphore handle pointer |
[in] | timeout_ms | - Maximum time to wait to acquire semaphore. If timeout_ms is 0 then wait till acquire semaphore. |
Returns
0 - Success Negative Value - Failure
183
of file driver/rsi_os_none.c
rsi_semaphore_post_from_isr#
rsi_error_t rsi_semaphore_post_from_isr (rsi_semaphore_handle_t * semaphore)
Wireless library to release semaphore, which was acquired.
[in] | semaphore | - Semaphore handle pointer |
Returns
0 - Success Negative Value - Failure
224
of file driver/rsi_os_none.c
rsi_semaphore_post#
rsi_error_t rsi_semaphore_post (rsi_semaphore_handle_t * semaphore)
Wireless library to release semaphore, which was acquired.
[in] | semaphore | - Semaphore handle pointer |
Returns
0 - Success Negative Value - Failure
238
of file driver/rsi_os_none.c
rsi_semaphore_reset#
rsi_error_t rsi_semaphore_reset (rsi_semaphore_handle_t * semaphore)
Used by Wireless Library to reset the semaphore.
[in] | semaphore | - Semaphore handle pointer |
Returns
0 - Success Negative Value - Failure
252
of file driver/rsi_os_none.c