mirror of
https://github.com/Ai-Thinker-Open/Ai-Thinker-Open_RTL8710BX_ALIOS_SDK.git
synced 2026-07-11 20:55:39 +00:00
rel_1.6.0 init
This commit is contained in:
commit
27b3e2883d
19359 changed files with 8093121 additions and 0 deletions
919
Living_SDK/kernel/vcall/cmsis/cmsis_os.c
Normal file
919
Living_SDK/kernel/vcall/cmsis/cmsis_os.c
Normal file
|
|
@ -0,0 +1,919 @@
|
|||
/* ----------------------------------------------------------------------
|
||||
* $Date: 5. February 2013
|
||||
* $Revision: V1.02
|
||||
*
|
||||
* Project: CMSIS-RTOS API
|
||||
* Title: cmsis_os.c
|
||||
*
|
||||
* Version 0.02
|
||||
* Initial Proposal Phase
|
||||
* Version 0.03
|
||||
* osKernelStart added, optional feature: main started as thread
|
||||
* osSemaphores have standard behavior
|
||||
* osTimerCreate does not start the timer, added osTimerStart
|
||||
* osThreadPass is renamed to osThreadYield
|
||||
* Version 1.01
|
||||
* Support for C++ interface
|
||||
* - const attribute removed from the osXxxxDef_t typedef's
|
||||
* - const attribute added to the osXxxxDef macros
|
||||
* Added: osTimerDelete, osMutexDelete, osSemaphoreDelete
|
||||
* Added: osKernelInitialize
|
||||
* Version 1.02
|
||||
* Control functions for short timeouts in microsecond resolution:
|
||||
* Added: osKernelSysTick, osKernelSysTickFrequency, osKernelSysTickMicroSec
|
||||
* Removed: osSignalGet
|
||||
*
|
||||
*
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Portions Copyright <EFBFBD> 2016 STMicroelectronics International N.V. All rights reserved.
|
||||
* Portions Copyright (c) 2013 ARM LIMITED
|
||||
* All rights reserved.
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* - Neither the name of ARM nor the names of its contributors may be used
|
||||
* to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file cmsis_os.c
|
||||
* @author AliOS-Things Team
|
||||
* @date 16-Mar-2018
|
||||
* @brief CMSIS-RTOS API implementation for AliOS-Things
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <cmsis_os.h>
|
||||
|
||||
/*
|
||||
* ARM Compiler 4/5
|
||||
*/
|
||||
#if defined ( __CC_ARM )
|
||||
|
||||
#define __ASM __asm
|
||||
#define __INLINE __inline
|
||||
#define __STATIC_INLINE static __inline
|
||||
|
||||
#include "cmsis_armcc.h"
|
||||
|
||||
/*
|
||||
* GNU Compiler
|
||||
*/
|
||||
#elif defined ( __GNUC__ )
|
||||
|
||||
#define __ASM __asm /*!< asm keyword for GNU Compiler */
|
||||
#define __INLINE inline /*!< inline keyword for GNU Compiler */
|
||||
#define __STATIC_INLINE static inline
|
||||
|
||||
#include "cmsis_gcc.h"
|
||||
|
||||
/*
|
||||
* IAR Compiler
|
||||
*/
|
||||
#elif defined ( __ICCARM__ )
|
||||
|
||||
#ifndef __ASM
|
||||
#define __ASM __asm
|
||||
#endif
|
||||
#ifndef __INLINE
|
||||
#define __INLINE inline
|
||||
#endif
|
||||
#ifndef __STATIC_INLINE
|
||||
#define __STATIC_INLINE static inline
|
||||
#endif
|
||||
|
||||
#include <cmsis_iar.h>
|
||||
#endif
|
||||
|
||||
/* Convert from CMSIS type osPriority to Rhino priority number */
|
||||
static uint8_t makeRhinoPriority (osPriority priority)
|
||||
{
|
||||
uint8_t fpriority = RHINO_IDLE_PRI;
|
||||
|
||||
if (priority != osPriorityError)
|
||||
{
|
||||
fpriority -= (priority - osPriorityIdle);
|
||||
}
|
||||
|
||||
return fpriority;
|
||||
#if 0
|
||||
typedef enum {
|
||||
osPriorityIdle = -3, -> 62 - ((-3) - (-3))= 62 ///< priority: idle (lowest)
|
||||
osPriorityLow = -2, -> 62 - ((-2) - (-3))= 61 ///< priority: low
|
||||
osPriorityBelowNormal = -1, -> 62 - ((-1) - (-3))= 60 ///< priority: below normal
|
||||
osPriorityNormal = 0, -> 62 - (( 0) - (-3))= 59 ///< priority: normal (default)
|
||||
osPriorityAboveNormal = +1, -> 62 - ((+1) - (-3))= 58 ///< priority: above normal
|
||||
osPriorityHigh = +2, -> 62 - ((+2) - (-3))= 57 ///< priority: high
|
||||
osPriorityRealtime = +3, -> 62 - ((+3) - (-3))= 56 ///< priority: realtime (highest)
|
||||
osPriorityError = 0x84 ///< system cannot determine priority or thread has illegal priority
|
||||
} osPriority;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Convert from Rhino priority number to CMSIS type osPriority */
|
||||
static osPriority makeCmsisPriority (uint8_t fpriority)
|
||||
{
|
||||
osPriority priority = osPriorityError;
|
||||
|
||||
if ((RHINO_IDLE_PRI - fpriority) <= (osPriorityRealtime - osPriorityIdle))
|
||||
{
|
||||
priority = (osPriority)((int)osPriorityIdle + (int)(RHINO_IDLE_PRI - fpriority));
|
||||
}
|
||||
|
||||
return priority;
|
||||
}
|
||||
|
||||
|
||||
/*********************** Kernel Control Functions *****************************/
|
||||
/**
|
||||
* @brief Initialize the RTOS Kernel for creating objects.
|
||||
* @retval status code that indicates the execution status of the function.
|
||||
* @note MUST REMAIN UNCHANGED: \b osKernelInitialize shall be consistent in every CMSIS-RTOS.
|
||||
*/
|
||||
osStatus osKernelInitialize (void)
|
||||
{
|
||||
(void)krhino_init();
|
||||
|
||||
return osOK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Start the RTOS Kernel with executing the specified thread.
|
||||
* @param thread_def thread definition referenced with \ref osThread.
|
||||
* @param argument pointer that is passed to the thread function as start argument.
|
||||
* @retval status code that indicates the execution status of the function
|
||||
* @note MUST REMAIN UNCHANGED: \b osKernelStart shall be consistent in every CMSIS-RTOS.
|
||||
*/
|
||||
osStatus osKernelStart (void)
|
||||
{
|
||||
krhino_start();
|
||||
|
||||
return osOK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if the RTOS kernel is already started
|
||||
* @param None
|
||||
* @retval (0) RTOS is not started
|
||||
* (1) RTOS is started
|
||||
* (-1) if this feature is disabled
|
||||
* @note MUST REMAIN UNCHANGED: \b osKernelRunning shall be consistent in every CMSIS-RTOS.
|
||||
*/
|
||||
int32_t osKernelRunning(void)
|
||||
{
|
||||
if (g_sys_stat == RHINO_RUNNING)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if (defined (osFeature_SysTick) && (osFeature_SysTick != 0)) // System Timer available
|
||||
/**
|
||||
* @brief Get the value of the Kernel SysTick timer
|
||||
* @param None
|
||||
* @retval None
|
||||
* @note MUST REMAIN UNCHANGED: \b osKernelSysTick shall be consistent in every CMSIS-RTOS.
|
||||
*/
|
||||
uint32_t osKernelSysTick(void)
|
||||
{
|
||||
return (uint32_t)g_tick_count;
|
||||
}
|
||||
#endif // System Timer available
|
||||
|
||||
/*********************** Thread Management *****************************/
|
||||
/**
|
||||
* @brief Create a thread and add it to Active Threads and set it to state READY.
|
||||
* @param thread_def thread definition referenced with \ref osThread.
|
||||
* @param argument pointer that is passed to the thread function as start argument.
|
||||
* @retval thread ID for reference by other functions or NULL in case of error.
|
||||
* @note MUST REMAIN UNCHANGED: \b osThreadCreate shall be consistent in every CMSIS-RTOS.
|
||||
*/
|
||||
osThreadId osThreadCreate (const osThreadDef_t *thread_def, void *argument)
|
||||
{
|
||||
ktask_t* ptcb;
|
||||
|
||||
if (RHINO_SUCCESS != krhino_task_create(thread_def->ptcb, thread_def->name, argument,
|
||||
makeRhinoPriority(thread_def->tpriority),
|
||||
thread_def->ticks, thread_def->pstackspace,
|
||||
thread_def->stacksize,
|
||||
(task_entry_t)thread_def->pthread, 1))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
ptcb = thread_def->ptcb;
|
||||
}
|
||||
|
||||
return (osThreadId)ptcb;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the thread ID of the current running thread.
|
||||
* @retval thread ID for reference by other functions or NULL in case of error.
|
||||
* @note MUST REMAIN UNCHANGED: \b osThreadGetId shall be consistent in every CMSIS-RTOS.
|
||||
*/
|
||||
osThreadId osThreadGetId (void)
|
||||
{
|
||||
return (osThreadId)krhino_cur_task_get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Terminate execution of a thread and remove it from Active Threads.
|
||||
* @param thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
|
||||
* @retval status code that indicates the execution status of the function.
|
||||
* @note MUST REMAIN UNCHANGED: \b osThreadTerminate shall be consistent in every CMSIS-RTOS.
|
||||
*/
|
||||
osStatus osThreadTerminate (osThreadId thread_id)
|
||||
{
|
||||
#if (RHINO_CONFIG_TASK_DEL > 0)
|
||||
if (RHINO_SUCCESS == krhino_task_del((ktask_t*)thread_id))
|
||||
return osOK;
|
||||
else
|
||||
return osErrorOS;
|
||||
#else
|
||||
return osErrorOS;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Pass control to next thread that is in state \b READY.
|
||||
* @retval status code that indicates the execution status of the function.
|
||||
* @note MUST REMAIN UNCHANGED: \b osThreadYield shall be consistent in every CMSIS-RTOS.
|
||||
*/
|
||||
osStatus osThreadYield (void)
|
||||
{
|
||||
krhino_task_yield();
|
||||
|
||||
return osOK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Change priority of an active thread.
|
||||
* @param thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
|
||||
* @param priority new priority value for the thread function.
|
||||
* @retval status code that indicates the execution status of the function.
|
||||
* @note MUST REMAIN UNCHANGED: \b osThreadSetPriority shall be consistent in every CMSIS-RTOS.
|
||||
*/
|
||||
osStatus osThreadSetPriority (osThreadId thread_id, osPriority priority)
|
||||
{
|
||||
#if (RHINO_CONFIG_TASK_PRI_CHG > 0)
|
||||
if (RHINO_SUCCESS == task_pri_change((ktask_t*)thread_id, makeRhinoPriority(priority)))
|
||||
return osOK;
|
||||
else
|
||||
return osErrorOS;
|
||||
#else
|
||||
return osErrorOS;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get current priority of an active thread.
|
||||
* @param thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
|
||||
* @retval current priority value of the thread function.
|
||||
* @note MUST REMAIN UNCHANGED: \b osThreadGetPriority shall be consistent in every CMSIS-RTOS.
|
||||
*/
|
||||
osPriority osThreadGetPriority (osThreadId thread_id)
|
||||
{
|
||||
ktask_t * ptcb;
|
||||
|
||||
if (thread_id == NULL)
|
||||
return osPriorityError;
|
||||
|
||||
ptcb = (ktask_t *)thread_id;
|
||||
|
||||
return makeCmsisPriority(ptcb->prio);
|
||||
}
|
||||
|
||||
/*********************** Generic Wait Functions *******************************/
|
||||
/**
|
||||
* @brief Wait for Timeout (Time Delay)
|
||||
* @param millisec time delay value
|
||||
* @retval status code that indicates the execution status of the function.
|
||||
*/
|
||||
osStatus osDelay (uint32_t millisec)
|
||||
{
|
||||
tick_t ticks = millisec / (1000000/RHINO_CONFIG_TICKS_PER_SECOND);
|
||||
|
||||
krhino_task_sleep(ticks ? ticks : 1); /* Minimum delay = 1 tick */
|
||||
}
|
||||
|
||||
#if (defined (osFeature_Wait) && (osFeature_Wait != 0)) /* Generic Wait available */
|
||||
/**
|
||||
* @brief Wait for Signal, Message, Mail, or Timeout
|
||||
* @param millisec timeout value or 0 in case of no time-out
|
||||
* @retval event that contains signal, message, or mail information or error code.
|
||||
* @note MUST REMAIN UNCHANGED: \b osWait shall be consistent in every CMSIS-RTOS.
|
||||
*/
|
||||
osEvent osWait (uint32_t millisec);
|
||||
|
||||
#endif /* Generic Wait available */
|
||||
|
||||
/*********************** Timer Management Functions ***************************/
|
||||
/**
|
||||
* @brief Create a timer.
|
||||
* @param timer_def timer object referenced with \ref osTimer.
|
||||
* @param type osTimerOnce for one-shot or osTimerPeriodic for periodic behavior.
|
||||
* @param argument argument to the timer call back function.
|
||||
* @retval timer ID for reference by other functions or NULL in case of error.
|
||||
* @note MUST REMAIN UNCHANGED: \b osTimerCreate shall be consistent in every CMSIS-RTOS.
|
||||
*/
|
||||
osTimerId osTimerCreate (const osTimerDef_t *timer_def, os_timer_type type, void *argument)
|
||||
{
|
||||
sys_time_t first = 1;
|
||||
sys_time_t round;
|
||||
|
||||
/*
|
||||
* we use the round to save information for : one-shot or periodic,
|
||||
* when type == osTimerPeriodic, round is set to MAX_TIMER_TICKS - 1,
|
||||
* when type == osTimerOnce, round is set to 0.
|
||||
* osTimerStart() will set the right value for round again.
|
||||
*
|
||||
* also the parameter first will be set to 1 here for workround error
|
||||
* in krhino_timer_create(), osTimerStart() will set the right value.
|
||||
*/
|
||||
|
||||
if (type == osTimerPeriodic)
|
||||
round = MAX_TIMER_TICKS - 1;
|
||||
else
|
||||
round = 0;
|
||||
|
||||
if (RHINO_SUCCESS == krhino_timer_create(timer_def->timer,
|
||||
timer_def->name, (timer_cb_t)timer_def->cb,
|
||||
first, round, argument, 0))
|
||||
{
|
||||
return (osTimerId)timer_def->timer;
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
#if (RHINO_CONFIG_TIMER > 0)
|
||||
|
||||
/**
|
||||
* @brief Start or restart a timer.
|
||||
* @param timer_id timer ID obtained by \ref osTimerCreate.
|
||||
* @param millisec time delay value of the timer.
|
||||
* @retval status code that indicates the execution status of the function
|
||||
* @note MUST REMAIN UNCHANGED: \b osTimerStart shall be consistent in every CMSIS-RTOS.
|
||||
*/
|
||||
osStatus osTimerStart (osTimerId timer_id, uint32_t millisec)
|
||||
{
|
||||
osStatus result = osOK;
|
||||
ktimer_t * ptimer = (ktimer_t *)timer_id;
|
||||
tick_t ticks = millisec / (1000000/RHINO_CONFIG_TICKS_PER_SECOND);
|
||||
|
||||
if (ticks == 0)
|
||||
{
|
||||
ticks = 1;
|
||||
}
|
||||
|
||||
ptimer->init_count = ticks;
|
||||
|
||||
/* check the type of timer, osTimerPeriodic or osTimerOnce*/
|
||||
|
||||
if ((MAX_TIMER_TICKS - 1) == ptimer->round_ticks)
|
||||
{
|
||||
ptimer->round_ticks = ticks;
|
||||
}
|
||||
|
||||
if (RHINO_SUCCESS != krhino_timer_start(ptimer))
|
||||
{
|
||||
result = osErrorOS;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Stop a timer.
|
||||
* @param timer_id timer ID obtained by \ref osTimerCreate
|
||||
* @retval status code that indicates the execution status of the function.
|
||||
* @note MUST REMAIN UNCHANGED: \b osTimerStop shall be consistent in every CMSIS-RTOS.
|
||||
*/
|
||||
osStatus osTimerStop (osTimerId timer_id)
|
||||
{
|
||||
osStatus result = osOK;
|
||||
|
||||
if (RHINO_SUCCESS != krhino_timer_stop((ktimer_t *)timer_id))
|
||||
{
|
||||
result = osErrorOS;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Delete a timer.
|
||||
* @param timer_id timer ID obtained by \ref osTimerCreate
|
||||
* @retval status code that indicates the execution status of the function.
|
||||
* @note MUST REMAIN UNCHANGED: \b osTimerDelete shall be consistent in every CMSIS-RTOS.
|
||||
*/
|
||||
osStatus osTimerDelete (osTimerId timer_id)
|
||||
{
|
||||
osStatus result = osOK;
|
||||
|
||||
if (RHINO_SUCCESS != krhino_timer_del((ktimer_t *)timer_id))
|
||||
{
|
||||
result = osErrorOS;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif /* RHINO_CONFIG_TIMER */
|
||||
|
||||
#if (osFeature_Signals > 0)
|
||||
/*************************** Signal Management ********************************/
|
||||
/**
|
||||
* @brief Set the specified Signal Flags of an active thread.
|
||||
* @param thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
|
||||
* @param signals specifies the signal flags of the thread that should be set.
|
||||
* @retval previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters.
|
||||
* @note MUST REMAIN UNCHANGED: \b osSignalSet shall be consistent in every CMSIS-RTOS.
|
||||
*/
|
||||
int32_t osSignalSet (osThreadId thread_id, int32_t signal)
|
||||
{
|
||||
(void) thread_id;
|
||||
(void) signal;
|
||||
|
||||
return 0x80000000; /* Task Notification not supported */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Clear the specified Signal Flags of an active thread.
|
||||
* @param thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
|
||||
* @param signals specifies the signal flags of the thread that shall be cleared.
|
||||
* @retval previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters.
|
||||
* @note MUST REMAIN UNCHANGED: \b osSignalClear shall be consistent in every CMSIS-RTOS.
|
||||
*/
|
||||
int32_t osSignalClear (osThreadId thread_id, int32_t signal);
|
||||
|
||||
/**
|
||||
* @brief Wait for one or more Signal Flags to become signaled for the current \b RUNNING thread.
|
||||
* @param signals wait until all specified signal flags set or 0 for any single signal flag.
|
||||
* @param millisec timeout value or 0 in case of no time-out.
|
||||
* @retval event flag information or error code.
|
||||
* @note MUST REMAIN UNCHANGED: \b osSignalWait shall be consistent in every CMSIS-RTOS.
|
||||
*/
|
||||
osEvent osSignalWait (int32_t signals, uint32_t millisec)
|
||||
{
|
||||
osEvent ret;
|
||||
|
||||
(void) signals;
|
||||
(void) millisec;
|
||||
|
||||
ret.status = osErrorOS; /* Task Notification not supported */
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif /* osFeature_Signals > 0 */
|
||||
|
||||
/**************************** Mutex Management ********************************/
|
||||
/**
|
||||
* @brief Create and Initialize a Mutex object
|
||||
* @param mutex_def mutex definition referenced with \ref osMutex.
|
||||
* @retval mutex ID for reference by other functions or NULL in case of error.
|
||||
* @note MUST REMAIN UNCHANGED: \b osMutexCreate shall be consistent in every CMSIS-RTOS.
|
||||
*/
|
||||
osMutexId osMutexCreate (const osMutexDef_t *mutex_def)
|
||||
{
|
||||
if (RHINO_SUCCESS != krhino_mutex_create(mutex_def->mutex, mutex_def->name))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (osMutexId)mutex_def->mutex;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Wait until a Mutex becomes available
|
||||
* @param mutex_id mutex ID obtained by \ref osMutexCreate.
|
||||
* @param millisec timeout value or 0 in case of no time-out.
|
||||
* @retval status code that indicates the execution status of the function.
|
||||
* @note MUST REMAIN UNCHANGED: \b osMutexWait shall be consistent in every CMSIS-RTOS.
|
||||
*/
|
||||
osStatus osMutexWait (osMutexId mutex_id, uint32_t millisec)
|
||||
{
|
||||
tick_t ticks;
|
||||
|
||||
if (mutex_id == NULL)
|
||||
{
|
||||
return osErrorParameter;
|
||||
}
|
||||
|
||||
ticks = 0;
|
||||
if (millisec != 0)
|
||||
{
|
||||
ticks = millisec / (1000000/RHINO_CONFIG_TICKS_PER_SECOND);
|
||||
}
|
||||
|
||||
if (RHINO_SUCCESS != krhino_mutex_lock((kmutex_t*)mutex_id, ticks))
|
||||
{
|
||||
return osErrorOS;
|
||||
}
|
||||
|
||||
return osOK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Release a Mutex that was obtained by \ref osMutexWait
|
||||
* @param mutex_id mutex ID obtained by \ref osMutexCreate.
|
||||
* @retval status code that indicates the execution status of the function.
|
||||
* @note MUST REMAIN UNCHANGED: \b osMutexRelease shall be consistent in every CMSIS-RTOS.
|
||||
*/
|
||||
osStatus osMutexRelease (osMutexId mutex_id)
|
||||
{
|
||||
if (RHINO_SUCCESS == krhino_mutex_unlock((kmutex_t*)mutex_id))
|
||||
{
|
||||
return osOK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return osErrorOS;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Delete a Mutex
|
||||
* @param mutex_id mutex ID obtained by \ref osMutexCreate.
|
||||
* @retval status code that indicates the execution status of the function.
|
||||
* @note MUST REMAIN UNCHANGED: \b osMutexDelete shall be consistent in every CMSIS-RTOS.
|
||||
*/
|
||||
osStatus osMutexDelete (osMutexId mutex_id)
|
||||
{
|
||||
if (RHINO_SUCCESS == krhino_mutex_del((kmutex_t*)mutex_id))
|
||||
{
|
||||
return osOK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return osErrorOS;
|
||||
}
|
||||
}
|
||||
|
||||
/******************** Semaphore Management Functions **************************/
|
||||
|
||||
#if (RHINO_CONFIG_SEM > 0)
|
||||
|
||||
/**
|
||||
* @brief Create and Initialize a Semaphore object used for managing resources
|
||||
* @param semaphore_def semaphore definition referenced with \ref osSemaphore.
|
||||
* @param count number of available resources.
|
||||
* @retval semaphore ID for reference by other functions or NULL in case of error.
|
||||
* @note MUST REMAIN UNCHANGED: \b osSemaphoreCreate shall be consistent in every CMSIS-RTOS.
|
||||
*/
|
||||
osSemaphoreId osSemaphoreCreate (const osSemaphoreDef_t *semaphore_def, int32_t count)
|
||||
{
|
||||
if (RHINO_SUCCESS != krhino_sem_create(semaphore_def->sem,
|
||||
semaphore_def->name, (sem_count_t)count))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (osSemaphoreId)semaphore_def->sem;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Wait until a Semaphore token becomes available
|
||||
* @param semaphore_id semaphore object referenced with \ref osSemaphore.
|
||||
* @param millisec timeout value or 0 in case of no time-out.
|
||||
* @retval number of available tokens, or -1 in case of incorrect parameters.
|
||||
* @note MUST REMAIN UNCHANGED: \b osSemaphoreWait shall be consistent in every CMSIS-RTOS.
|
||||
*/
|
||||
int32_t osSemaphoreWait (osSemaphoreId semaphore_id, uint32_t millisec)
|
||||
{
|
||||
tick_t ticks;
|
||||
|
||||
if (semaphore_id == NULL)
|
||||
{
|
||||
return osErrorParameter;
|
||||
}
|
||||
|
||||
ticks = 0;
|
||||
if (millisec != 0)
|
||||
{
|
||||
ticks = millisec / (1000000/RHINO_CONFIG_TICKS_PER_SECOND);
|
||||
}
|
||||
|
||||
if (RHINO_SUCCESS != krhino_sem_take((ksem_t*)semaphore_id, ticks))
|
||||
{
|
||||
return osErrorOS;
|
||||
}
|
||||
|
||||
return osOK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Release a Semaphore token
|
||||
* @param semaphore_id semaphore object referenced with \ref osSemaphore.
|
||||
* @retval status code that indicates the execution status of the function.
|
||||
* @note MUST REMAIN UNCHANGED: \b osSemaphoreRelease shall be consistent in every CMSIS-RTOS.
|
||||
*/
|
||||
osStatus osSemaphoreRelease (osSemaphoreId semaphore_id)
|
||||
{
|
||||
if (RHINO_SUCCESS == krhino_sem_give((ksem_t*)semaphore_id))
|
||||
{
|
||||
return osOK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return osErrorOS;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Delete a Semaphore
|
||||
* @param semaphore_id semaphore object referenced with \ref osSemaphore.
|
||||
* @retval status code that indicates the execution status of the function.
|
||||
* @note MUST REMAIN UNCHANGED: \b osSemaphoreDelete shall be consistent in every CMSIS-RTOS.
|
||||
*/
|
||||
osStatus osSemaphoreDelete (osSemaphoreId semaphore_id)
|
||||
{
|
||||
if (RHINO_SUCCESS == krhino_sem_del((ksem_t*)semaphore_id))
|
||||
{
|
||||
return osOK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return osErrorOS;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* Use Semaphores */
|
||||
|
||||
/******************* Memory Pool Management Functions ***********************/
|
||||
|
||||
#if (defined (osFeature_Pool) && (osFeature_Pool != 0))
|
||||
|
||||
//TODO
|
||||
//This is a primitive and inefficient wrapper around the existing AliOS memory management.
|
||||
//A better implementation will have to modify heap_x.c!
|
||||
|
||||
|
||||
typedef struct os_pool_cb {
|
||||
void *pool;
|
||||
uint8_t *markers;
|
||||
uint32_t pool_sz;
|
||||
uint32_t item_sz;
|
||||
uint32_t currentIndex;
|
||||
} os_pool_cb_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Create and Initialize a memory pool
|
||||
* @param pool_def memory pool definition referenced with \ref osPool.
|
||||
* @retval memory pool ID for reference by other functions or NULL in case of error.
|
||||
* @note MUST REMAIN UNCHANGED: \b osPoolCreate shall be consistent in every CMSIS-RTOS.
|
||||
*/
|
||||
osPoolId osPoolCreate (const osPoolDef_t *pool_def)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Allocate a memory block from a memory pool
|
||||
* @param pool_id memory pool ID obtain referenced with \ref osPoolCreate.
|
||||
* @retval address of the allocated memory block or NULL in case of no memory available.
|
||||
* @note MUST REMAIN UNCHANGED: \b osPoolAlloc shall be consistent in every CMSIS-RTOS.
|
||||
*/
|
||||
void *osPoolAlloc (osPoolId pool_id)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Allocate a memory block from a memory pool and set memory block to zero
|
||||
* @param pool_id memory pool ID obtain referenced with \ref osPoolCreate.
|
||||
* @retval address of the allocated memory block or NULL in case of no memory available.
|
||||
* @note MUST REMAIN UNCHANGED: \b osPoolCAlloc shall be consistent in every CMSIS-RTOS.
|
||||
*/
|
||||
void *osPoolCAlloc (osPoolId pool_id)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return an allocated memory block back to a specific memory pool
|
||||
* @param pool_id memory pool ID obtain referenced with \ref osPoolCreate.
|
||||
* @param block address of the allocated memory block that is returned to the memory pool.
|
||||
* @retval status code that indicates the execution status of the function.
|
||||
* @note MUST REMAIN UNCHANGED: \b osPoolFree shall be consistent in every CMSIS-RTOS.
|
||||
*/
|
||||
osStatus osPoolFree (osPoolId pool_id, void *block)
|
||||
{
|
||||
return osOK;
|
||||
}
|
||||
|
||||
#endif /* Use Memory Pool Management */
|
||||
|
||||
/******************* Message Queue Management Functions *********************/
|
||||
|
||||
#if (defined (osFeature_MessageQ) && (osFeature_MessageQ != 0)) /* Use Message Queues */
|
||||
|
||||
/**
|
||||
* @brief Create and Initialize a Message Queue
|
||||
* @param queue_def queue definition referenced with \ref osMessageQ.
|
||||
* @param thread_id thread ID (obtained by \ref osThreadCreate or \ref osThreadGetId) or NULL.
|
||||
* @retval message queue ID for reference by other functions or NULL in case of error.
|
||||
* @note MUST REMAIN UNCHANGED: \b osMessageCreate shall be consistent in every CMSIS-RTOS.
|
||||
*/
|
||||
osMessageQId osMessageCreate (const osMessageQDef_t *queue_def, osThreadId thread_id)
|
||||
{
|
||||
(void) thread_id;
|
||||
|
||||
if (RHINO_SUCCESS == krhino_fix_buf_queue_create(queue_def->queue,
|
||||
queue_def->name, queue_def->pool,
|
||||
queue_def->item_sz, queue_def->queue_sz))
|
||||
{
|
||||
return (osMessageQId)queue_def->queue;
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Put a Message to a Queue.
|
||||
* @param queue_id message queue ID obtained with \ref osMessageCreate.
|
||||
* @param info message information.
|
||||
* @param millisec timeout value or 0 in case of no time-out.
|
||||
* @retval status code that indicates the execution status of the function.
|
||||
* @note MUST REMAIN UNCHANGED: \b osMessagePut shall be consistent in every CMSIS-RTOS.
|
||||
*/
|
||||
osStatus osMessagePut (osMessageQId queue_id, uint32_t info, uint32_t millisec)
|
||||
{
|
||||
(void)millisec;
|
||||
|
||||
if (RHINO_SUCCESS == krhino_buf_queue_send((kbuf_queue_t *)queue_id, &info, 4))
|
||||
{
|
||||
return osOK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return osErrorOS;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get a Message or Wait for a Message from a Queue.
|
||||
* @param queue_id message queue ID obtained with \ref osMessageCreate.
|
||||
* @param millisec timeout value or 0 in case of no time-out.
|
||||
* @retval event information that includes status code.
|
||||
* @note MUST REMAIN UNCHANGED: \b osMessageGet shall be consistent in every CMSIS-RTOS.
|
||||
*/
|
||||
osEvent osMessageGet (osMessageQId queue_id, uint32_t millisec)
|
||||
{
|
||||
osEvent event;
|
||||
tick_t ticks;
|
||||
size_t size;
|
||||
|
||||
ticks = 0;
|
||||
if (millisec == osWaitForever)
|
||||
{
|
||||
ticks = RHINO_WAIT_FOREVER;
|
||||
}
|
||||
else if (millisec != 0)
|
||||
{
|
||||
ticks = millisec / (1000000/RHINO_CONFIG_TICKS_PER_SECOND);
|
||||
if (ticks == 0)
|
||||
{
|
||||
ticks = 1;
|
||||
}
|
||||
}
|
||||
|
||||
event.def.message_id = queue_id;
|
||||
event.value.v = 0;
|
||||
|
||||
if (queue_id == NULL)
|
||||
{
|
||||
event.status = osErrorParameter;
|
||||
return event;
|
||||
}
|
||||
|
||||
if (RHINO_SUCCESS == krhino_buf_queue_recv((kbuf_queue_t *)queue_id,
|
||||
ticks, &event.value.v, &size))
|
||||
{
|
||||
event.status = osEventMessage;
|
||||
}
|
||||
else
|
||||
{
|
||||
event.status = (ticks == 0) ? osOK : osEventTimeout;
|
||||
}
|
||||
|
||||
return event;
|
||||
}
|
||||
|
||||
#endif /* Use Message Queues */
|
||||
|
||||
/******************** Mail Queue Management Functions ***********************/
|
||||
#if (defined (osFeature_MailQ) && (osFeature_MailQ != 0)) /* Use Mail Queues */
|
||||
|
||||
typedef struct os_mailQ_cb {
|
||||
const osMailQDef_t *queue_def;
|
||||
QueueHandle_t handle;
|
||||
osPoolId pool;
|
||||
} os_mailQ_cb_t;
|
||||
|
||||
/**
|
||||
* @brief Create and Initialize mail queue
|
||||
* @param queue_def reference to the mail queue definition obtain with \ref osMailQ
|
||||
* @param thread_id thread ID (obtained by \ref osThreadCreate or \ref osThreadGetId) or NULL.
|
||||
* @retval mail queue ID for reference by other functions or NULL in case of error.
|
||||
* @note MUST REMAIN UNCHANGED: \b osMailCreate shall be consistent in every CMSIS-RTOS.
|
||||
*/
|
||||
osMailQId osMailCreate (const osMailQDef_t *queue_def, osThreadId thread_id)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Allocate a memory block from a mail
|
||||
* @param queue_id mail queue ID obtained with \ref osMailCreate.
|
||||
* @param millisec timeout value or 0 in case of no time-out.
|
||||
* @retval pointer to memory block that can be filled with mail or NULL in case error.
|
||||
* @note MUST REMAIN UNCHANGED: \b osMailAlloc shall be consistent in every CMSIS-RTOS.
|
||||
*/
|
||||
void *osMailAlloc (osMailQId queue_id, uint32_t millisec)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Allocate a memory block from a mail and set memory block to zero
|
||||
* @param queue_id mail queue ID obtained with \ref osMailCreate.
|
||||
* @param millisec timeout value or 0 in case of no time-out.
|
||||
* @retval pointer to memory block that can be filled with mail or NULL in case error.
|
||||
* @note MUST REMAIN UNCHANGED: \b osMailCAlloc shall be consistent in every CMSIS-RTOS.
|
||||
*/
|
||||
void *osMailCAlloc (osMailQId queue_id, uint32_t millisec)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Put a mail to a queue
|
||||
* @param queue_id mail queue ID obtained with \ref osMailCreate.
|
||||
* @param mail memory block previously allocated with \ref osMailAlloc or \ref osMailCAlloc.
|
||||
* @retval status code that indicates the execution status of the function.
|
||||
* @note MUST REMAIN UNCHANGED: \b osMailPut shall be consistent in every CMSIS-RTOS.
|
||||
*/
|
||||
osStatus osMailPut (osMailQId queue_id, void *mail)
|
||||
{
|
||||
return osOK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get a mail from a queue
|
||||
* @param queue_id mail queue ID obtained with \ref osMailCreate.
|
||||
* @param millisec timeout value or 0 in case of no time-out
|
||||
* @retval event that contains mail information or error code.
|
||||
* @note MUST REMAIN UNCHANGED: \b osMailGet shall be consistent in every CMSIS-RTOS.
|
||||
*/
|
||||
osEvent osMailGet (osMailQId queue_id, uint32_t millisec)
|
||||
{
|
||||
osEvent event;
|
||||
return event;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Free a memory block from a mail
|
||||
* @param queue_id mail queue ID obtained with \ref osMailCreate.
|
||||
* @param mail pointer to the memory block that was obtained with \ref osMailGet.
|
||||
* @retval status code that indicates the execution status of the function.
|
||||
* @note MUST REMAIN UNCHANGED: \b osMailFree shall be consistent in every CMSIS-RTOS.
|
||||
*/
|
||||
osStatus osMailFree (osMailQId queue_id, void *mail)
|
||||
{
|
||||
return osOK;
|
||||
}
|
||||
#endif /* Use Mail Queues */
|
||||
|
||||
717
Living_SDK/kernel/vcall/cmsis/cmsis_os.h
Normal file
717
Living_SDK/kernel/vcall/cmsis/cmsis_os.h
Normal file
|
|
@ -0,0 +1,717 @@
|
|||
/* ----------------------------------------------------------------------
|
||||
* $Date: 5. February 2013
|
||||
* $Revision: V1.02
|
||||
*
|
||||
* Project: CMSIS-RTOS API
|
||||
* Title: cmsis_os.h template header file
|
||||
*
|
||||
* Version 0.02
|
||||
* Initial Proposal Phase
|
||||
* Version 0.03
|
||||
* osKernelStart added, optional feature: main started as thread
|
||||
* osSemaphores have standard behavior
|
||||
* osTimerCreate does not start the timer, added osTimerStart
|
||||
* osThreadPass is renamed to osThreadYield
|
||||
* Version 1.01
|
||||
* Support for C++ interface
|
||||
* - const attribute removed from the osXxxxDef_t typedef's
|
||||
* - const attribute added to the osXxxxDef macros
|
||||
* Added: osTimerDelete, osMutexDelete, osSemaphoreDelete
|
||||
* Added: osKernelInitialize
|
||||
* Version 1.02
|
||||
* Control functions for short timeouts in microsecond resolution:
|
||||
* Added: osKernelSysTick, osKernelSysTickFrequency, osKernelSysTickMicroSec
|
||||
* Removed: osSignalGet
|
||||
*----------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (c) 2013-2017 ARM LIMITED
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the License); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#ifndef _CMSIS_OS_H
|
||||
#define _CMSIS_OS_H
|
||||
|
||||
/// \note MUST REMAIN UNCHANGED: \b osCMSIS identifies the CMSIS-RTOS API version.
|
||||
#define osCMSIS 0x10002 ///< API version (main [31:16] .sub [15:0])
|
||||
|
||||
/// \note CAN BE CHANGED: \b osCMSIS_KERNEL identifies the underlying RTOS kernel and version number.
|
||||
#define osCMSIS_KERNEL 0x10000 ///< RTOS identification and version (main [31:16] .sub [15:0])
|
||||
|
||||
/// \note MUST REMAIN UNCHANGED: \b osKernelSystemId shall be consistent in every CMSIS-RTOS.
|
||||
#define osKernelSystemId "KERNEL V1.00" ///< RTOS identification string
|
||||
|
||||
/// \note MUST REMAIN UNCHANGED: \b osFeature_xxx shall be consistent in every CMSIS-RTOS.
|
||||
|
||||
/* Memory Pools, Mail Queues, Signal is not supported yet */
|
||||
|
||||
#define osFeature_MainThread 1 ///< main thread 1=main can be thread, 0=not available
|
||||
/*not support yet*/
|
||||
#define osFeature_Pool 0 ///< Memory Pools: 1=available, 0=not available
|
||||
/*not support yet*/
|
||||
#define osFeature_MailQ 0 ///< Mail Queues: 1=available, 0=not available
|
||||
#define osFeature_MessageQ 1 ///< Message Queues: 1=available, 0=not available
|
||||
/*not support yet*/
|
||||
#define osFeature_Signals 0 ///< maximum number of Signal Flags available per thread
|
||||
#define osFeature_Semaphore 30 ///< maximum count for \ref osSemaphoreCreate function
|
||||
#define osFeature_Wait 0 ///< osWait function: 1=available, 0=not available
|
||||
#define osFeature_SysTick 1 ///< osKernelSysTick functions: 1=available, 0=not available
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <k_api.h> /* for rhino */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
|
||||
// ==== Enumeration, structures, defines ====
|
||||
|
||||
/// Priority used for thread control.
|
||||
/// \note MUST REMAIN UNCHANGED: \b osPriority shall be consistent in every CMSIS-RTOS.
|
||||
typedef enum {
|
||||
osPriorityIdle = -3, ///< priority: idle (lowest)
|
||||
osPriorityLow = -2, ///< priority: low
|
||||
osPriorityBelowNormal = -1, ///< priority: below normal
|
||||
osPriorityNormal = 0, ///< priority: normal (default)
|
||||
osPriorityAboveNormal = +1, ///< priority: above normal
|
||||
osPriorityHigh = +2, ///< priority: high
|
||||
osPriorityRealtime = +3, ///< priority: realtime (highest)
|
||||
osPriorityError = 0x84 ///< system cannot determine priority or thread has illegal priority
|
||||
} osPriority;
|
||||
|
||||
/// Timeout value.
|
||||
/// \note MUST REMAIN UNCHANGED: \b osWaitForever shall be consistent in every CMSIS-RTOS.
|
||||
#define osWaitForever 0xFFFFFFFF ///< wait forever timeout value
|
||||
|
||||
/// Status code values returned by CMSIS-RTOS functions.
|
||||
/// \note MUST REMAIN UNCHANGED: \b osStatus shall be consistent in every CMSIS-RTOS.
|
||||
typedef enum {
|
||||
osOK = 0, ///< function completed; no error or event occurred.
|
||||
osEventSignal = 0x08, ///< function completed; signal event occurred.
|
||||
osEventMessage = 0x10, ///< function completed; message event occurred.
|
||||
osEventMail = 0x20, ///< function completed; mail event occurred.
|
||||
osEventTimeout = 0x40, ///< function completed; timeout occurred.
|
||||
osErrorParameter = 0x80, ///< parameter error: a mandatory parameter was missing or specified an incorrect object.
|
||||
osErrorResource = 0x81, ///< resource not available: a specified resource was not available.
|
||||
osErrorTimeoutResource = 0xC1, ///< resource not available within given time: a specified resource was not available within the timeout period.
|
||||
osErrorISR = 0x82, ///< not allowed in ISR context: the function cannot be called from interrupt service routines.
|
||||
osErrorISRRecursive = 0x83, ///< function called multiple times from ISR with same object.
|
||||
osErrorPriority = 0x84, ///< system cannot determine priority or thread has illegal priority.
|
||||
osErrorNoMemory = 0x85, ///< system is out of memory: it was impossible to allocate or reserve memory for the operation.
|
||||
osErrorValue = 0x86, ///< value of a parameter is out of range.
|
||||
osErrorOS = 0xFF, ///< unspecified RTOS error: run-time error but no other error message fits.
|
||||
os_status_reserved = 0x7FFFFFFF ///< prevent from enum down-size compiler optimization.
|
||||
} osStatus;
|
||||
|
||||
|
||||
/// Timer type value for the timer definition.
|
||||
/// \note MUST REMAIN UNCHANGED: \b os_timer_type shall be consistent in every CMSIS-RTOS.
|
||||
typedef enum {
|
||||
osTimerOnce = 0, ///< one-shot timer
|
||||
osTimerPeriodic = 1 ///< repeating timer
|
||||
} os_timer_type;
|
||||
|
||||
/// Entry point of a thread.
|
||||
/// \note MUST REMAIN UNCHANGED: \b os_pthread shall be consistent in every CMSIS-RTOS.
|
||||
typedef void (*os_pthread) (void const *argument);
|
||||
|
||||
/// Entry point of a timer call back function.
|
||||
/// \note MUST REMAIN UNCHANGED: \b os_ptimer shall be consistent in every CMSIS-RTOS.
|
||||
typedef void (*os_ptimer) (void const *argument);
|
||||
|
||||
// >>> the following data type definitions may shall adapted towards a specific RTOS
|
||||
|
||||
/// Thread ID identifies the thread (pointer to a thread control block).
|
||||
/// \note CAN BE CHANGED: \b os_thread_cb is implementation specific in every CMSIS-RTOS.
|
||||
typedef ktask_t *osThreadId;
|
||||
|
||||
/// Timer ID identifies the timer (pointer to a timer control block).
|
||||
/// \note CAN BE CHANGED: \b os_timer_cb is implementation specific in every CMSIS-RTOS.
|
||||
typedef ktimer_t *osTimerId;
|
||||
|
||||
/// Mutex ID identifies the mutex (pointer to a mutex control block).
|
||||
/// \note CAN BE CHANGED: \b os_mutex_cb is implementation specific in every CMSIS-RTOS.
|
||||
typedef kmutex_t *osMutexId;
|
||||
|
||||
/// Semaphore ID identifies the semaphore (pointer to a semaphore control block).
|
||||
/// \note CAN BE CHANGED: \b os_semaphore_cb is implementation specific in every CMSIS-RTOS.
|
||||
typedef ksem_t *osSemaphoreId;
|
||||
|
||||
/// Pool ID identifies the memory pool (pointer to a memory pool control block).
|
||||
/// \note CAN BE CHANGED: \b os_pool_cb is implementation specific in every CMSIS-RTOS.
|
||||
typedef void *osPoolId;
|
||||
|
||||
/// Message ID identifies the message queue (pointer to a message queue control block).
|
||||
/// \note CAN BE CHANGED: \b os_messageQ_cb is implementation specific in every CMSIS-RTOS.
|
||||
typedef kqueue_t *osMessageQId;
|
||||
|
||||
/// Mail ID identifies the mail queue (pointer to a mail queue control block).
|
||||
/// \note CAN BE CHANGED: \b os_mailQ_cb is implementation specific in every CMSIS-RTOS.
|
||||
typedef kqueue_t *osMailQId;
|
||||
|
||||
|
||||
/// Thread Definition structure contains startup information of a thread.
|
||||
/// \note CAN BE CHANGED: \b os_thread_def is implementation specific in every CMSIS-RTOS.
|
||||
typedef struct os_thread_def {
|
||||
char *name; ///< Thread name
|
||||
os_pthread pthread; ///< start address of thread function
|
||||
osPriority tpriority; ///< initial thread priority
|
||||
uint32_t instances; ///< maximum number of instances of that thread function
|
||||
uint32_t stacksize; ///< stack size requirements in bytes; 0 is default stack size
|
||||
tick_t ticks;
|
||||
ktask_t *ptcb;
|
||||
cpu_stack_t *pstackspace;
|
||||
} osThreadDef_t;
|
||||
|
||||
/// Timer Definition structure contains timer parameters.
|
||||
/// \note CAN BE CHANGED: \b os_timer_def is implementation specific in every CMSIS-RTOS.
|
||||
typedef struct os_timer_def {
|
||||
char * name;
|
||||
os_ptimer cb; ///< start address of a timer function
|
||||
ktimer_t * timer;
|
||||
} osTimerDef_t;
|
||||
|
||||
/// Mutex Definition structure contains setup information for a mutex.
|
||||
/// \note CAN BE CHANGED: \b os_mutex_def is implementation specific in every CMSIS-RTOS.
|
||||
typedef struct os_mutex_def {
|
||||
char * name;
|
||||
uint32_t dummy; ///< dummy value.
|
||||
kmutex_t * mutex;
|
||||
} osMutexDef_t;
|
||||
|
||||
/// Semaphore Definition structure contains setup information for a semaphore.
|
||||
/// \note CAN BE CHANGED: \b os_semaphore_def is implementation specific in every CMSIS-RTOS.
|
||||
typedef struct os_semaphore_def {
|
||||
char * name;
|
||||
uint32_t dummy; ///< dummy value.
|
||||
ksem_t * sem;
|
||||
} osSemaphoreDef_t;
|
||||
|
||||
/// Definition structure for memory block allocation.
|
||||
/// \note CAN BE CHANGED: \b os_pool_def is implementation specific in every CMSIS-RTOS.
|
||||
typedef struct os_pool_def {
|
||||
uint32_t pool_sz; ///< number of items (elements) in the pool
|
||||
uint32_t item_sz; ///< size of an item
|
||||
void *pool; ///< pointer to memory for pool
|
||||
} osPoolDef_t;
|
||||
|
||||
/// Definition structure for message queue.
|
||||
/// \note CAN BE CHANGED: \b os_messageQ_def is implementation specific in every CMSIS-RTOS.
|
||||
typedef struct os_messageQ_def {
|
||||
char *name;
|
||||
uint32_t queue_sz; ///< number of elements in the queue
|
||||
uint32_t item_sz; ///< size of an item
|
||||
void *pool; ///< memory array for messages
|
||||
kbuf_queue_t *queue;
|
||||
} osMessageQDef_t;
|
||||
|
||||
/// Definition structure for mail queue.
|
||||
/// \note CAN BE CHANGED: \b os_mailQ_def is implementation specific in every CMSIS-RTOS.
|
||||
typedef struct os_mailQ_def {
|
||||
uint32_t queue_sz; ///< number of elements in the queue
|
||||
uint32_t item_sz; ///< size of an item
|
||||
void *pool; ///< memory array for mail
|
||||
} osMailQDef_t;
|
||||
|
||||
/// Event structure contains detailed information about an event.
|
||||
/// \note MUST REMAIN UNCHANGED: \b os_event shall be consistent in every CMSIS-RTOS.
|
||||
/// However the struct may be extended at the end.
|
||||
typedef struct {
|
||||
osStatus status; ///< status code: event or error information
|
||||
union {
|
||||
uint32_t v; ///< message as 32-bit value
|
||||
void *p; ///< message or mail as void pointer
|
||||
int32_t signals; ///< signal flags
|
||||
} value; ///< event value
|
||||
union {
|
||||
osMailQId mail_id; ///< mail id obtained by \ref osMailCreate
|
||||
osMessageQId message_id; ///< message id obtained by \ref osMessageCreate
|
||||
} def; ///< event definition
|
||||
} osEvent;
|
||||
|
||||
|
||||
// ==== Kernel Control Functions ====
|
||||
|
||||
/// Initialize the RTOS Kernel for creating objects.
|
||||
/// \return status code that indicates the execution status of the function.
|
||||
/// \note MUST REMAIN UNCHANGED: \b osKernelInitialize shall be consistent in every CMSIS-RTOS.
|
||||
osStatus osKernelInitialize (void);
|
||||
|
||||
/// Start the RTOS Kernel.
|
||||
/// \return status code that indicates the execution status of the function.
|
||||
/// \note MUST REMAIN UNCHANGED: \b osKernelStart shall be consistent in every CMSIS-RTOS.
|
||||
osStatus osKernelStart (void);
|
||||
|
||||
/// Check if the RTOS kernel is already started.
|
||||
/// \note MUST REMAIN UNCHANGED: \b osKernelRunning shall be consistent in every CMSIS-RTOS.
|
||||
/// \return 0 RTOS is not started, 1 RTOS is started.
|
||||
int32_t osKernelRunning(void);
|
||||
|
||||
#if (defined (osFeature_SysTick) && (osFeature_SysTick != 0)) // System Timer available
|
||||
|
||||
/// Get the RTOS kernel system timer counter
|
||||
/// \note MUST REMAIN UNCHANGED: \b osKernelSysTick shall be consistent in every CMSIS-RTOS.
|
||||
/// \return RTOS kernel system timer as 32-bit value
|
||||
uint32_t osKernelSysTick (void);
|
||||
|
||||
/// The RTOS kernel system timer frequency in Hz
|
||||
/// \note Reflects the system timer setting and is typically defined in a configuration file.
|
||||
#define osKernelSysTickFrequency 100000000
|
||||
|
||||
/// Convert a microseconds value to a RTOS kernel system timer value.
|
||||
/// \param microsec time value in microseconds.
|
||||
/// \return time value normalized to the \ref osKernelSysTickFrequency
|
||||
#define osKernelSysTickMicroSec(microsec) (((uint64_t)microsec * (osKernelSysTickFrequency)) / 1000000)
|
||||
|
||||
#endif // System Timer available
|
||||
|
||||
// ==== Thread Management ====
|
||||
|
||||
/// Create a Thread Definition with function, priority, and stack requirements.
|
||||
/// \param name name of the thread function.
|
||||
/// \param priority initial priority of the thread function.
|
||||
/// \param instances number of possible thread instances.
|
||||
/// \param stacksz stack size (in bytes) requirements for the thread function.
|
||||
/// \note CAN BE CHANGED: The parameters to \b osThreadDef shall be consistent but the
|
||||
/// macro body is implementation specific in every CMSIS-RTOS.
|
||||
#if defined (osObjectsExternal) // object is external
|
||||
#define osThreadDef(name, priority, instances, stacksz) \
|
||||
extern const osThreadDef_t os_thread_def_##name
|
||||
#else // define the object
|
||||
#define osThreadDef(name, priority, instances, stacksz) \
|
||||
const osThreadDef_t os_thread_def_##name = \
|
||||
{ (name), (priority), (instances), (stacksz) }
|
||||
#endif
|
||||
|
||||
/// Access a Thread definition.
|
||||
/// \param name name of the thread definition object.
|
||||
/// \note CAN BE CHANGED: The parameter to \b osThread shall be consistent but the
|
||||
/// macro body is implementation specific in every CMSIS-RTOS.
|
||||
#define osThread(name) \
|
||||
&os_thread_def_##name
|
||||
|
||||
/// Create a thread and add it to Active Threads and set it to state READY.
|
||||
/// \param[in] thread_def thread definition referenced with \ref osThread.
|
||||
/// \param[in] argument pointer that is passed to the thread function as start argument.
|
||||
/// \return thread ID for reference by other functions or NULL in case of error.
|
||||
/// \note MUST REMAIN UNCHANGED: \b osThreadCreate shall be consistent in every CMSIS-RTOS.
|
||||
osThreadId osThreadCreate (const osThreadDef_t *thread_def, void *argument);
|
||||
|
||||
/// Return the thread ID of the current running thread.
|
||||
/// \return thread ID for reference by other functions or NULL in case of error.
|
||||
/// \note MUST REMAIN UNCHANGED: \b osThreadGetId shall be consistent in every CMSIS-RTOS.
|
||||
osThreadId osThreadGetId (void);
|
||||
|
||||
/// Terminate execution of a thread and remove it from Active Threads.
|
||||
/// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
|
||||
/// \return status code that indicates the execution status of the function.
|
||||
/// \note MUST REMAIN UNCHANGED: \b osThreadTerminate shall be consistent in every CMSIS-RTOS.
|
||||
osStatus osThreadTerminate (osThreadId thread_id);
|
||||
|
||||
/// Pass control to next thread that is in state \b READY.
|
||||
/// \return status code that indicates the execution status of the function.
|
||||
/// \note MUST REMAIN UNCHANGED: \b osThreadYield shall be consistent in every CMSIS-RTOS.
|
||||
osStatus osThreadYield (void);
|
||||
|
||||
/// Change priority of an active thread.
|
||||
/// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
|
||||
/// \param[in] priority new priority value for the thread function.
|
||||
/// \return status code that indicates the execution status of the function.
|
||||
/// \note MUST REMAIN UNCHANGED: \b osThreadSetPriority shall be consistent in every CMSIS-RTOS.
|
||||
osStatus osThreadSetPriority (osThreadId thread_id, osPriority priority);
|
||||
|
||||
/// Get current priority of an active thread.
|
||||
/// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
|
||||
/// \return current priority value of the thread function.
|
||||
/// \note MUST REMAIN UNCHANGED: \b osThreadGetPriority shall be consistent in every CMSIS-RTOS.
|
||||
osPriority osThreadGetPriority (osThreadId thread_id);
|
||||
|
||||
|
||||
// ==== Generic Wait Functions ====
|
||||
|
||||
/// Wait for Timeout (Time Delay).
|
||||
/// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue "time delay" value
|
||||
/// \return status code that indicates the execution status of the function.
|
||||
osStatus osDelay (uint32_t millisec);
|
||||
|
||||
#if (defined (osFeature_Wait) && (osFeature_Wait != 0)) // Generic Wait available
|
||||
|
||||
/// Wait for Signal, Message, Mail, or Timeout.
|
||||
/// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out
|
||||
/// \return event that contains signal, message, or mail information or error code.
|
||||
/// \note MUST REMAIN UNCHANGED: \b osWait shall be consistent in every CMSIS-RTOS.
|
||||
osEvent osWait (uint32_t millisec);
|
||||
|
||||
#endif // Generic Wait available
|
||||
|
||||
|
||||
// ==== Timer Management Functions ====
|
||||
/// Define a Timer object.
|
||||
/// \param name name of the timer object.
|
||||
/// \param function name of the timer call back function.
|
||||
/// \note CAN BE CHANGED: The parameter to \b osTimerDef shall be consistent but the
|
||||
/// macro body is implementation specific in every CMSIS-RTOS.
|
||||
#if defined (osObjectsExternal) // object is external
|
||||
#define osTimerDef(name, function) \
|
||||
extern const osTimerDef_t os_timer_def_##name
|
||||
#else // define the object
|
||||
#define osTimerDef(name, function) \
|
||||
const osTimerDef_t os_timer_def_##name = \
|
||||
{ (function) }
|
||||
#endif
|
||||
|
||||
/// Access a Timer definition.
|
||||
/// \param name name of the timer object.
|
||||
/// \note CAN BE CHANGED: The parameter to \b osTimer shall be consistent but the
|
||||
/// macro body is implementation specific in every CMSIS-RTOS.
|
||||
#define osTimer(name) \
|
||||
&os_timer_def_##name
|
||||
|
||||
/// Create a timer.
|
||||
/// \param[in] timer_def timer object referenced with \ref osTimer.
|
||||
/// \param[in] type osTimerOnce for one-shot or osTimerPeriodic for periodic behavior.
|
||||
/// \param[in] argument argument to the timer call back function.
|
||||
/// \return timer ID for reference by other functions or NULL in case of error.
|
||||
/// \note MUST REMAIN UNCHANGED: \b osTimerCreate shall be consistent in every CMSIS-RTOS.
|
||||
osTimerId osTimerCreate (const osTimerDef_t *timer_def, os_timer_type type, void *argument);
|
||||
|
||||
/// Start or restart a timer.
|
||||
/// \param[in] timer_id timer ID obtained by \ref osTimerCreate.
|
||||
/// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue "time delay" value of the timer.
|
||||
/// \return status code that indicates the execution status of the function.
|
||||
/// \note MUST REMAIN UNCHANGED: \b osTimerStart shall be consistent in every CMSIS-RTOS.
|
||||
osStatus osTimerStart (osTimerId timer_id, uint32_t millisec);
|
||||
|
||||
/// Stop the timer.
|
||||
/// \param[in] timer_id timer ID obtained by \ref osTimerCreate.
|
||||
/// \return status code that indicates the execution status of the function.
|
||||
/// \note MUST REMAIN UNCHANGED: \b osTimerStop shall be consistent in every CMSIS-RTOS.
|
||||
osStatus osTimerStop (osTimerId timer_id);
|
||||
|
||||
/// Delete a timer that was created by \ref osTimerCreate.
|
||||
/// \param[in] timer_id timer ID obtained by \ref osTimerCreate.
|
||||
/// \return status code that indicates the execution status of the function.
|
||||
/// \note MUST REMAIN UNCHANGED: \b osTimerDelete shall be consistent in every CMSIS-RTOS.
|
||||
osStatus osTimerDelete (osTimerId timer_id);
|
||||
|
||||
|
||||
// ==== Signal Management ==== not support yet
|
||||
|
||||
/// Set the specified Signal Flags of an active thread.
|
||||
/// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
|
||||
/// \param[in] signals specifies the signal flags of the thread that should be set.
|
||||
/// \return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters.
|
||||
/// \note MUST REMAIN UNCHANGED: \b osSignalSet shall be consistent in every CMSIS-RTOS.
|
||||
int32_t osSignalSet (osThreadId thread_id, int32_t signals);
|
||||
|
||||
/// Clear the specified Signal Flags of an active thread.
|
||||
/// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId.
|
||||
/// \param[in] signals specifies the signal flags of the thread that shall be cleared.
|
||||
/// \return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters or call from ISR.
|
||||
/// \note MUST REMAIN UNCHANGED: \b osSignalClear shall be consistent in every CMSIS-RTOS.
|
||||
int32_t osSignalClear (osThreadId thread_id, int32_t signals);
|
||||
|
||||
/// Wait for one or more Signal Flags to become signaled for the current \b RUNNING thread.
|
||||
/// \param[in] signals wait until all specified signal flags set or 0 for any single signal flag.
|
||||
/// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
|
||||
/// \return event flag information or error code.
|
||||
/// \note MUST REMAIN UNCHANGED: \b osSignalWait shall be consistent in every CMSIS-RTOS.
|
||||
osEvent osSignalWait (int32_t signals, uint32_t millisec);
|
||||
|
||||
|
||||
// ==== Mutex Management ====
|
||||
|
||||
/// Define a Mutex.
|
||||
/// \param name name of the mutex object.
|
||||
/// \note CAN BE CHANGED: The parameter to \b osMutexDef shall be consistent but the
|
||||
/// macro body is implementation specific in every CMSIS-RTOS.
|
||||
#if defined (osObjectsExternal) // object is external
|
||||
#define osMutexDef(name) \
|
||||
extern const osMutexDef_t os_mutex_def_##name
|
||||
#else // define the object
|
||||
#define osMutexDef(name) \
|
||||
const osMutexDef_t os_mutex_def_##name = { 0 }
|
||||
#endif
|
||||
|
||||
/// Access a Mutex definition.
|
||||
/// \param name name of the mutex object.
|
||||
/// \note CAN BE CHANGED: The parameter to \b osMutex shall be consistent but the
|
||||
/// macro body is implementation specific in every CMSIS-RTOS.
|
||||
#define osMutex(name) \
|
||||
&os_mutex_def_##name
|
||||
|
||||
/// Create and Initialize a Mutex object.
|
||||
/// \param[in] mutex_def mutex definition referenced with \ref osMutex.
|
||||
/// \return mutex ID for reference by other functions or NULL in case of error.
|
||||
/// \note MUST REMAIN UNCHANGED: \b osMutexCreate shall be consistent in every CMSIS-RTOS.
|
||||
osMutexId osMutexCreate (const osMutexDef_t *mutex_def);
|
||||
|
||||
/// Wait until a Mutex becomes available.
|
||||
/// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate.
|
||||
/// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
|
||||
/// \return status code that indicates the execution status of the function.
|
||||
/// \note MUST REMAIN UNCHANGED: \b osMutexWait shall be consistent in every CMSIS-RTOS.
|
||||
osStatus osMutexWait (osMutexId mutex_id, uint32_t millisec);
|
||||
|
||||
/// Release a Mutex that was obtained by \ref osMutexWait.
|
||||
/// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate.
|
||||
/// \return status code that indicates the execution status of the function.
|
||||
/// \note MUST REMAIN UNCHANGED: \b osMutexRelease shall be consistent in every CMSIS-RTOS.
|
||||
osStatus osMutexRelease (osMutexId mutex_id);
|
||||
|
||||
/// Delete a Mutex that was created by \ref osMutexCreate.
|
||||
/// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate.
|
||||
/// \return status code that indicates the execution status of the function.
|
||||
/// \note MUST REMAIN UNCHANGED: \b osMutexDelete shall be consistent in every CMSIS-RTOS.
|
||||
osStatus osMutexDelete (osMutexId mutex_id);
|
||||
|
||||
|
||||
// ==== Semaphore Management Functions ====
|
||||
|
||||
#if (defined (osFeature_Semaphore) && (osFeature_Semaphore != 0)) // Semaphore available
|
||||
|
||||
/// Define a Semaphore object.
|
||||
/// \param name name of the semaphore object.
|
||||
/// \note CAN BE CHANGED: The parameter to \b osSemaphoreDef shall be consistent but the
|
||||
/// macro body is implementation specific in every CMSIS-RTOS.
|
||||
#if defined (osObjectsExternal) // object is external
|
||||
#define osSemaphoreDef(name) \
|
||||
extern const osSemaphoreDef_t os_semaphore_def_##name
|
||||
#else // define the object
|
||||
#define osSemaphoreDef(name) \
|
||||
const osSemaphoreDef_t os_semaphore_def_##name = { 0 }
|
||||
#endif
|
||||
|
||||
/// Access a Semaphore definition.
|
||||
/// \param name name of the semaphore object.
|
||||
/// \note CAN BE CHANGED: The parameter to \b osSemaphore shall be consistent but the
|
||||
/// macro body is implementation specific in every CMSIS-RTOS.
|
||||
#define osSemaphore(name) \
|
||||
&os_semaphore_def_##name
|
||||
|
||||
/// Create and Initialize a Semaphore object used for managing resources.
|
||||
/// \param[in] semaphore_def semaphore definition referenced with \ref osSemaphore.
|
||||
/// \param[in] count number of available resources.
|
||||
/// \return semaphore ID for reference by other functions or NULL in case of error.
|
||||
/// \note MUST REMAIN UNCHANGED: \b osSemaphoreCreate shall be consistent in every CMSIS-RTOS.
|
||||
osSemaphoreId osSemaphoreCreate (const osSemaphoreDef_t *semaphore_def, int32_t count);
|
||||
|
||||
/// Wait until a Semaphore token becomes available.
|
||||
/// \param[in] semaphore_id semaphore object referenced with \ref osSemaphoreCreate.
|
||||
/// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
|
||||
/// \return number of available tokens, or -1 in case of incorrect parameters.
|
||||
/// \note MUST REMAIN UNCHANGED: \b osSemaphoreWait shall be consistent in every CMSIS-RTOS.
|
||||
int32_t osSemaphoreWait (osSemaphoreId semaphore_id, uint32_t millisec);
|
||||
|
||||
/// Release a Semaphore token.
|
||||
/// \param[in] semaphore_id semaphore object referenced with \ref osSemaphoreCreate.
|
||||
/// \return status code that indicates the execution status of the function.
|
||||
/// \note MUST REMAIN UNCHANGED: \b osSemaphoreRelease shall be consistent in every CMSIS-RTOS.
|
||||
osStatus osSemaphoreRelease (osSemaphoreId semaphore_id);
|
||||
|
||||
/// Delete a Semaphore that was created by \ref osSemaphoreCreate.
|
||||
/// \param[in] semaphore_id semaphore object referenced with \ref osSemaphoreCreate.
|
||||
/// \return status code that indicates the execution status of the function.
|
||||
/// \note MUST REMAIN UNCHANGED: \b osSemaphoreDelete shall be consistent in every CMSIS-RTOS.
|
||||
osStatus osSemaphoreDelete (osSemaphoreId semaphore_id);
|
||||
|
||||
#endif // Semaphore available
|
||||
|
||||
|
||||
// ==== Memory Pool Management Functions ==== not support yet
|
||||
|
||||
#if (defined (osFeature_Pool) && (osFeature_Pool != 0)) // Memory Pool Management available
|
||||
|
||||
/// \brief Define a Memory Pool.
|
||||
/// \param name name of the memory pool.
|
||||
/// \param no maximum number of blocks (objects) in the memory pool.
|
||||
/// \param type data type of a single block (object).
|
||||
/// \note CAN BE CHANGED: The parameter to \b osPoolDef shall be consistent but the
|
||||
/// macro body is implementation specific in every CMSIS-RTOS.
|
||||
#if defined (osObjectsExternal) // object is external
|
||||
#define osPoolDef(name, no, type) \
|
||||
extern const osPoolDef_t os_pool_def_##name
|
||||
#else // define the object
|
||||
#define osPoolDef(name, no, type) \
|
||||
const osPoolDef_t os_pool_def_##name = \
|
||||
{ (no), sizeof(type), NULL }
|
||||
#endif
|
||||
|
||||
/// \brief Access a Memory Pool definition.
|
||||
/// \param name name of the memory pool
|
||||
/// \note CAN BE CHANGED: The parameter to \b osPool shall be consistent but the
|
||||
/// macro body is implementation specific in every CMSIS-RTOS.
|
||||
#define osPool(name) \
|
||||
&os_pool_def_##name
|
||||
|
||||
/// Create and Initialize a memory pool.
|
||||
/// \param[in] pool_def memory pool definition referenced with \ref osPool.
|
||||
/// \return memory pool ID for reference by other functions or NULL in case of error.
|
||||
/// \note MUST REMAIN UNCHANGED: \b osPoolCreate shall be consistent in every CMSIS-RTOS.
|
||||
osPoolId osPoolCreate (const osPoolDef_t *pool_def);
|
||||
|
||||
/// Allocate a memory block from a memory pool.
|
||||
/// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate.
|
||||
/// \return address of the allocated memory block or NULL in case of no memory available.
|
||||
/// \note MUST REMAIN UNCHANGED: \b osPoolAlloc shall be consistent in every CMSIS-RTOS.
|
||||
void *osPoolAlloc (osPoolId pool_id);
|
||||
|
||||
/// Allocate a memory block from a memory pool and set memory block to zero.
|
||||
/// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate.
|
||||
/// \return address of the allocated memory block or NULL in case of no memory available.
|
||||
/// \note MUST REMAIN UNCHANGED: \b osPoolCAlloc shall be consistent in every CMSIS-RTOS.
|
||||
void *osPoolCAlloc (osPoolId pool_id);
|
||||
|
||||
/// Return an allocated memory block back to a specific memory pool.
|
||||
/// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate.
|
||||
/// \param[in] block address of the allocated memory block that is returned to the memory pool.
|
||||
/// \return status code that indicates the execution status of the function.
|
||||
/// \note MUST REMAIN UNCHANGED: \b osPoolFree shall be consistent in every CMSIS-RTOS.
|
||||
osStatus osPoolFree (osPoolId pool_id, void *block);
|
||||
|
||||
#endif // Memory Pool Management available
|
||||
|
||||
|
||||
// ==== Message Queue Management Functions ====
|
||||
|
||||
#if (defined (osFeature_MessageQ) && (osFeature_MessageQ != 0)) // Message Queues available
|
||||
|
||||
/// \brief Create a Message Queue Definition.
|
||||
/// \param name name of the queue.
|
||||
/// \param queue_sz maximum number of messages in the queue.
|
||||
/// \param type data type of a single message element (for debugger).
|
||||
/// \note CAN BE CHANGED: The parameter to \b osMessageQDef shall be consistent but the
|
||||
/// macro body is implementation specific in every CMSIS-RTOS.
|
||||
#if defined (osObjectsExternal) // object is external
|
||||
#define osMessageQDef(name, queue_sz, type) \
|
||||
extern const osMessageQDef_t os_messageQ_def_##name
|
||||
#else // define the object
|
||||
#define osMessageQDef(name, queue_sz, type) \
|
||||
const osMessageQDef_t os_messageQ_def_##name = \
|
||||
{ (queue_sz), sizeof (type) }
|
||||
#endif
|
||||
|
||||
/// \brief Access a Message Queue Definition.
|
||||
/// \param name name of the queue
|
||||
/// \note CAN BE CHANGED: The parameter to \b osMessageQ shall be consistent but the
|
||||
/// macro body is implementation specific in every CMSIS-RTOS.
|
||||
#define osMessageQ(name) \
|
||||
&os_messageQ_def_##name
|
||||
|
||||
/// Create and Initialize a Message Queue.
|
||||
/// \param[in] queue_def queue definition referenced with \ref osMessageQ.
|
||||
/// \param[in] thread_id thread ID (obtained by \ref osThreadCreate or \ref osThreadGetId) or NULL.
|
||||
/// \return message queue ID for reference by other functions or NULL in case of error.
|
||||
/// \note MUST REMAIN UNCHANGED: \b osMessageCreate shall be consistent in every CMSIS-RTOS.
|
||||
osMessageQId osMessageCreate (const osMessageQDef_t *queue_def, osThreadId thread_id);
|
||||
|
||||
/// Put a Message to a Queue.
|
||||
/// \param[in] queue_id message queue ID obtained with \ref osMessageCreate.
|
||||
/// \param[in] info message information.
|
||||
/// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
|
||||
/// \return status code that indicates the execution status of the function.
|
||||
/// \note MUST REMAIN UNCHANGED: \b osMessagePut shall be consistent in every CMSIS-RTOS.
|
||||
osStatus osMessagePut (osMessageQId queue_id, uint32_t info, uint32_t millisec);
|
||||
|
||||
/// Get a Message or Wait for a Message from a Queue.
|
||||
/// \param[in] queue_id message queue ID obtained with \ref osMessageCreate.
|
||||
/// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
|
||||
/// \return event information that includes status code.
|
||||
/// \note MUST REMAIN UNCHANGED: \b osMessageGet shall be consistent in every CMSIS-RTOS.
|
||||
osEvent osMessageGet (osMessageQId queue_id, uint32_t millisec);
|
||||
|
||||
#endif // Message Queues available
|
||||
|
||||
|
||||
// ==== Mail Queue Management Functions ==== not support yet
|
||||
|
||||
#if (defined (osFeature_MailQ) && (osFeature_MailQ != 0)) // Mail Queues available
|
||||
|
||||
/// \brief Create a Mail Queue Definition.
|
||||
/// \param name name of the queue
|
||||
/// \param queue_sz maximum number of messages in queue
|
||||
/// \param type data type of a single message element
|
||||
/// \note CAN BE CHANGED: The parameter to \b osMailQDef shall be consistent but the
|
||||
/// macro body is implementation specific in every CMSIS-RTOS.
|
||||
#if defined (osObjectsExternal) // object is external
|
||||
#define osMailQDef(name, queue_sz, type) \
|
||||
extern const osMailQDef_t os_mailQ_def_##name
|
||||
#else // define the object
|
||||
#define osMailQDef(name, queue_sz, type) \
|
||||
const osMailQDef_t os_mailQ_def_##name = \
|
||||
{ (queue_sz), sizeof (type) }
|
||||
#endif
|
||||
|
||||
/// \brief Access a Mail Queue Definition.
|
||||
/// \param name name of the queue
|
||||
/// \note CAN BE CHANGED: The parameter to \b osMailQ shall be consistent but the
|
||||
/// macro body is implementation specific in every CMSIS-RTOS.
|
||||
#define osMailQ(name) \
|
||||
&os_mailQ_def_##name
|
||||
|
||||
/// Create and Initialize mail queue.
|
||||
/// \param[in] queue_def reference to the mail queue definition obtain with \ref osMailQ
|
||||
/// \param[in] thread_id thread ID (obtained by \ref osThreadCreate or \ref osThreadGetId) or NULL.
|
||||
/// \return mail queue ID for reference by other functions or NULL in case of error.
|
||||
/// \note MUST REMAIN UNCHANGED: \b osMailCreate shall be consistent in every CMSIS-RTOS.
|
||||
osMailQId osMailCreate (const osMailQDef_t *queue_def, osThreadId thread_id);
|
||||
|
||||
/// Allocate a memory block from a mail.
|
||||
/// \param[in] queue_id mail queue ID obtained with \ref osMailCreate.
|
||||
/// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out
|
||||
/// \return pointer to memory block that can be filled with mail or NULL in case of error.
|
||||
/// \note MUST REMAIN UNCHANGED: \b osMailAlloc shall be consistent in every CMSIS-RTOS.
|
||||
void *osMailAlloc (osMailQId queue_id, uint32_t millisec);
|
||||
|
||||
/// Allocate a memory block from a mail and set memory block to zero.
|
||||
/// \param[in] queue_id mail queue ID obtained with \ref osMailCreate.
|
||||
/// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out
|
||||
/// \return pointer to memory block that can be filled with mail or NULL in case of error.
|
||||
/// \note MUST REMAIN UNCHANGED: \b osMailCAlloc shall be consistent in every CMSIS-RTOS.
|
||||
void *osMailCAlloc (osMailQId queue_id, uint32_t millisec);
|
||||
|
||||
/// Put a mail to a queue.
|
||||
/// \param[in] queue_id mail queue ID obtained with \ref osMailCreate.
|
||||
/// \param[in] mail memory block previously allocated with \ref osMailAlloc or \ref osMailCAlloc.
|
||||
/// \return status code that indicates the execution status of the function.
|
||||
/// \note MUST REMAIN UNCHANGED: \b osMailPut shall be consistent in every CMSIS-RTOS.
|
||||
osStatus osMailPut (osMailQId queue_id, void *mail);
|
||||
|
||||
/// Get a mail from a queue.
|
||||
/// \param[in] queue_id mail queue ID obtained with \ref osMailCreate.
|
||||
/// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out
|
||||
/// \return event that contains mail information or error code.
|
||||
/// \note MUST REMAIN UNCHANGED: \b osMailGet shall be consistent in every CMSIS-RTOS.
|
||||
osEvent osMailGet (osMailQId queue_id, uint32_t millisec);
|
||||
|
||||
/// Free a memory block from a mail.
|
||||
/// \param[in] queue_id mail queue ID obtained with \ref osMailCreate.
|
||||
/// \param[in] mail pointer to the memory block that was obtained with \ref osMailGet.
|
||||
/// \return status code that indicates the execution status of the function.
|
||||
/// \note MUST REMAIN UNCHANGED: \b osMailFree shall be consistent in every CMSIS-RTOS.
|
||||
osStatus osMailFree (osMailQId queue_id, void *mail);
|
||||
|
||||
#endif // Mail Queues available
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _CMSIS_OS_H
|
||||
54
Living_SDK/kernel/vcall/cmsis/test/init_test.c
Normal file
54
Living_SDK/kernel/vcall/cmsis/test/init_test.c
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <cmsis_os.h>
|
||||
|
||||
#define DEMO_TASK_STACKSIZE 256 //256*cpu_stack_t = 1024byte
|
||||
#define DEMO_TASK_PRIORITY 20
|
||||
|
||||
extern void stm32_soc_init(void);
|
||||
static ktask_t demo_task_obj;
|
||||
static cpu_stack_t demo_task_buf[DEMO_TASK_STACKSIZE];
|
||||
static osThreadDef_t thread;
|
||||
|
||||
static void demo_task(void *arg)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
stm32_soc_init();
|
||||
|
||||
printf("demo_task here!\n");
|
||||
printf("rhino memory is %d!\n", krhino_global_space_get());
|
||||
|
||||
while (1)
|
||||
{
|
||||
printf("hello world! count %d\n", count++);
|
||||
|
||||
//sleep 1 second
|
||||
|
||||
osDelay(RHINO_CONFIG_TICKS_PER_SECOND*10000);
|
||||
};
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
osKernelInitialize();
|
||||
|
||||
thread.name = "demo_task";
|
||||
thread.pthread = (os_pthread)demo_task;
|
||||
thread.tpriority = osPriorityNormal;
|
||||
thread.stacksize = DEMO_TASK_STACKSIZE;
|
||||
thread.ptcb = &demo_task_obj;
|
||||
thread.pstackspace = demo_task_buf;
|
||||
|
||||
osThreadCreate (&thread, NULL);
|
||||
|
||||
osKernelStart();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
108
Living_SDK/kernel/vcall/cmsis/test/msgqueue_test.c
Normal file
108
Living_SDK/kernel/vcall/cmsis/test/msgqueue_test.c
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <cmsis_os.h>
|
||||
|
||||
#define DEMO_TASK_STACKSIZE 256 //256*cpu_stack_t = 1024byte
|
||||
#define DEMO_TASK_PRIORITY 20
|
||||
|
||||
static ktask_t init_task_obj;
|
||||
static ktask_t demo_task_obj1;
|
||||
static ktask_t demo_task_obj2;
|
||||
static cpu_stack_t init_task_buf[DEMO_TASK_STACKSIZE];
|
||||
static cpu_stack_t demo_task_buf1[DEMO_TASK_STACKSIZE];
|
||||
static cpu_stack_t demo_task_buf2[DEMO_TASK_STACKSIZE];
|
||||
|
||||
static osThreadDef_t thread_init;
|
||||
static osThreadDef_t thread1;
|
||||
static osThreadDef_t thread2;
|
||||
|
||||
static kbuf_queue_t buf_queue;
|
||||
static osMessageQDef_t msg_queue_def;
|
||||
static osMessageQId p_msgqueue;
|
||||
static uint32_t msg_buf_space[32];
|
||||
|
||||
static void init_task(void *arg)
|
||||
{
|
||||
printf("init_task here!\n");
|
||||
|
||||
msg_queue_def.name = "buf_queue";
|
||||
msg_queue_def.queue = &buf_queue;
|
||||
msg_queue_def.queue_sz = 32;
|
||||
msg_queue_def.item_sz = 4;
|
||||
msg_queue_def.pool = msg_buf_space;
|
||||
|
||||
p_msgqueue = osMessageCreate (&msg_queue_def, (osThreadId)NULL);
|
||||
if (p_msgqueue == NULL)
|
||||
{
|
||||
printf("osMessageCreate failed\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("osMessageCreate ok\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void demo_task1(void *arg)
|
||||
{
|
||||
osEvent event;
|
||||
|
||||
while (1)
|
||||
{
|
||||
event = osMessageGet(p_msgqueue, osWaitForever);
|
||||
if (event.status == osEventMessage)
|
||||
{
|
||||
printf("demo_task1 get msg %d\n", event.value.v);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("demo_task1 get msg failed\n");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
static void demo_task2(void *arg)
|
||||
{
|
||||
uint32_t count = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
osMessagePut(p_msgqueue,count,0xffffffff);
|
||||
|
||||
printf("demo_task2 put msg %d\n", count++);
|
||||
osDelay(RHINO_CONFIG_TICKS_PER_SECOND*10000);
|
||||
};
|
||||
}
|
||||
|
||||
void cmsis_msgqueue_test(void)
|
||||
{
|
||||
thread_init.name = "init_task";
|
||||
thread_init.pthread = (os_pthread)init_task;
|
||||
thread_init.tpriority = osPriorityHigh;
|
||||
thread_init.stacksize = DEMO_TASK_STACKSIZE;
|
||||
thread_init.ptcb = &init_task_obj;
|
||||
thread_init.pstackspace = init_task_buf;
|
||||
|
||||
thread1.name = "demo_task1";
|
||||
thread1.pthread = (os_pthread)demo_task1;
|
||||
thread1.tpriority = osPriorityNormal;
|
||||
thread1.stacksize = DEMO_TASK_STACKSIZE;
|
||||
thread1.ptcb = &demo_task_obj1;
|
||||
thread1.pstackspace = demo_task_buf1;
|
||||
|
||||
thread2.name = "demo_task2";
|
||||
thread2.pthread = (os_pthread)demo_task2;
|
||||
thread2.tpriority = osPriorityNormal;
|
||||
thread2.stacksize = DEMO_TASK_STACKSIZE;
|
||||
thread2.ptcb = &demo_task_obj2;
|
||||
thread2.pstackspace = demo_task_buf2;
|
||||
|
||||
osThreadCreate (&thread_init, NULL);
|
||||
osThreadCreate (&thread1, NULL);
|
||||
osThreadCreate (&thread2, NULL);
|
||||
}
|
||||
|
||||
95
Living_SDK/kernel/vcall/cmsis/test/mutex_test.c
Normal file
95
Living_SDK/kernel/vcall/cmsis/test/mutex_test.c
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <cmsis_os.h>
|
||||
|
||||
#define DEMO_TASK_STACKSIZE 256 //256*cpu_stack_t = 1024byte
|
||||
#define DEMO_TASK_PRIORITY 20
|
||||
|
||||
static ktask_t init_task_obj;
|
||||
static ktask_t demo_task_obj1;
|
||||
static ktask_t demo_task_obj2;
|
||||
static cpu_stack_t init_task_buf[DEMO_TASK_STACKSIZE];
|
||||
static cpu_stack_t demo_task_buf1[DEMO_TASK_STACKSIZE];
|
||||
static cpu_stack_t demo_task_buf2[DEMO_TASK_STACKSIZE];
|
||||
|
||||
static osThreadDef_t thread_init;
|
||||
static osThreadDef_t thread1;
|
||||
static osThreadDef_t thread2;
|
||||
|
||||
static kmutex_t mutex;
|
||||
static osMutexDef_t mutex_def;
|
||||
static osMutexId pMutex;
|
||||
|
||||
static void init_task(void *arg)
|
||||
{
|
||||
mutex_def.name = "mutex";
|
||||
mutex_def.mutex = &mutex;
|
||||
|
||||
pMutex = osMutexCreate (&mutex_def);
|
||||
if (pMutex == NULL)
|
||||
{
|
||||
printf("osMutexCreate failed\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("osMutexCreate ok\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void demo_task1(void *arg)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
osMutexWait(pMutex, 0xffffffff);
|
||||
printf("demo_task1 get mutex %d\n", count++);
|
||||
};
|
||||
}
|
||||
|
||||
static void demo_task2(void *arg)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
osMutexRelease(pMutex);
|
||||
|
||||
printf("demo_task2 release mutex %d\n", count++);
|
||||
osDelay(RHINO_CONFIG_TICKS_PER_SECOND*10000);
|
||||
};
|
||||
}
|
||||
|
||||
void cmsis_mutex_test(void)
|
||||
{
|
||||
thread_init.name = "init_task";
|
||||
thread_init.pthread = (os_pthread)init_task;
|
||||
thread_init.tpriority= osPriorityHigh;
|
||||
thread_init.stacksize= DEMO_TASK_STACKSIZE;
|
||||
thread_init.ptcb = &init_task_obj;
|
||||
thread_init.pstackspace = init_task_buf;
|
||||
|
||||
thread1.name = "demo_task1";
|
||||
thread1.pthread = (os_pthread)demo_task1;
|
||||
thread1.tpriority= osPriorityNormal;
|
||||
thread1.stacksize= DEMO_TASK_STACKSIZE;
|
||||
thread1.ptcb = &demo_task_obj1;
|
||||
thread1.pstackspace = demo_task_buf1;
|
||||
|
||||
thread2.name = "demo_task2";
|
||||
thread2.pthread = (os_pthread)demo_task2;
|
||||
thread2.tpriority= osPriorityNormal;
|
||||
thread2.stacksize= DEMO_TASK_STACKSIZE;
|
||||
thread2.ptcb = &demo_task_obj2;
|
||||
thread2.pstackspace = demo_task_buf2;
|
||||
|
||||
osThreadCreate (&thread_init, NULL);
|
||||
osThreadCreate (&thread1, NULL);
|
||||
osThreadCreate (&thread2, NULL);
|
||||
}
|
||||
|
||||
95
Living_SDK/kernel/vcall/cmsis/test/sem_test.c
Normal file
95
Living_SDK/kernel/vcall/cmsis/test/sem_test.c
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <cmsis_os.h>
|
||||
|
||||
#define DEMO_TASK_STACKSIZE 256 //256*cpu_stack_t = 1024byte
|
||||
#define DEMO_TASK_PRIORITY 20
|
||||
|
||||
static ktask_t init_task_obj;
|
||||
static ktask_t demo_task_obj1;
|
||||
static ktask_t demo_task_obj2;
|
||||
static cpu_stack_t init_task_buf[DEMO_TASK_STACKSIZE];
|
||||
static cpu_stack_t demo_task_buf1[DEMO_TASK_STACKSIZE];
|
||||
static cpu_stack_t demo_task_buf2[DEMO_TASK_STACKSIZE];
|
||||
|
||||
static osThreadDef_t thread_init;
|
||||
static osThreadDef_t thread1;
|
||||
static osThreadDef_t thread2;
|
||||
|
||||
static ksem_t sem;
|
||||
static osSemaphoreDef_t sem_def;
|
||||
static osSemaphoreId pSem;
|
||||
|
||||
static void init_task(void *arg)
|
||||
{
|
||||
sem_def.name = "sem";
|
||||
sem_def.sem = &sem;
|
||||
|
||||
pSem = osSemaphoreCreate (&sem_def, 0);
|
||||
if (pSem == NULL)
|
||||
{
|
||||
printf("osSemaphoreCreate failed\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("osSemaphoreCreate ok\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void demo_task1(void *arg)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
osSemaphoreWait(pSem, 0xffffffff);
|
||||
printf("demo_task1 get sem %d\n", count++);
|
||||
};
|
||||
}
|
||||
|
||||
static void demo_task2(void *arg)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
osSemaphoreRelease(pSem);
|
||||
|
||||
printf("demo_task2 release sem %d\n", count++);
|
||||
osDelay(RHINO_CONFIG_TICKS_PER_SECOND*10000);
|
||||
};
|
||||
}
|
||||
|
||||
void cmsis_sem_test(void)
|
||||
{
|
||||
thread_init.name = "init_task";
|
||||
thread_init.pthread = (os_pthread)init_task;
|
||||
thread_init.tpriority = osPriorityHigh;
|
||||
thread_init.stacksize = DEMO_TASK_STACKSIZE;
|
||||
thread_init.ptcb = &init_task_obj;
|
||||
thread_init.pstackspace = init_task_buf;
|
||||
|
||||
thread1.name = "demo_task1";
|
||||
thread1.pthread = (os_pthread)demo_task1;
|
||||
thread1.tpriority = osPriorityNormal;
|
||||
thread1.stacksize = DEMO_TASK_STACKSIZE;
|
||||
thread1.ptcb = &demo_task_obj1;
|
||||
thread1.pstackspace = demo_task_buf1;
|
||||
|
||||
thread2.name = "demo_task2";
|
||||
thread2.pthread = (os_pthread)demo_task2;
|
||||
thread2.tpriority = osPriorityNormal;
|
||||
thread2.stacksize = DEMO_TASK_STACKSIZE;
|
||||
thread2.ptcb = &demo_task_obj2;
|
||||
thread2.pstackspace = demo_task_buf2;
|
||||
|
||||
osThreadCreate (&thread_init, NULL);
|
||||
osThreadCreate (&thread1, NULL);
|
||||
osThreadCreate (&thread2, NULL);
|
||||
}
|
||||
|
||||
75
Living_SDK/kernel/vcall/cmsis/test/timer_test.c
Normal file
75
Living_SDK/kernel/vcall/cmsis/test/timer_test.c
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <cmsis_os.h>
|
||||
|
||||
#define DEMO_TASK_STACKSIZE 256 //256*cpu_stack_t = 1024byte
|
||||
#define DEMO_TASK_PRIORITY 20
|
||||
|
||||
static ktask_t demo_task_obj;
|
||||
static cpu_stack_t demo_task_buf[DEMO_TASK_STACKSIZE];
|
||||
static osThreadDef_t thread;
|
||||
|
||||
static osTimerDef_t timer_def;
|
||||
static ktimer_t timer_space;
|
||||
|
||||
static int timer_cb_count = 0;
|
||||
static void timer_function(void)
|
||||
{
|
||||
timer_cb_count ++;
|
||||
printf("timer cb is called, timer_cb_count = %d\n");
|
||||
}
|
||||
|
||||
static void demo_task(void *arg)
|
||||
{
|
||||
int count = 0;
|
||||
osTimerId pTimerId = NULL;
|
||||
|
||||
timer_def.name = "testTimer";
|
||||
timer_def.cb = (os_ptimer)timer_function;
|
||||
timer_def.timer= &timer_space;
|
||||
|
||||
pTimerId = osTimerCreate (&timer_def, osTimerPeriodic, NULL);
|
||||
if (pTimerId == NULL)
|
||||
{
|
||||
printf("osTimerCreate failed, MAX_TIMER_TICKS = %d\n",MAX_TIMER_TICKS);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("osTimerCreate ok\n");
|
||||
}
|
||||
|
||||
osTimerStart (pTimerId, 1000000);
|
||||
|
||||
while (1)
|
||||
{
|
||||
printf("hello world! count %d\n", count++);
|
||||
|
||||
//sleep 1 second
|
||||
|
||||
osDelay(RHINO_CONFIG_TICKS_PER_SECOND*10000);
|
||||
|
||||
if (timer_cb_count > 10)
|
||||
{
|
||||
osTimerStop(pTimerId);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
void cmsis_timer_test(void)
|
||||
{
|
||||
thread.name = "demo_task";
|
||||
thread.pthread = (os_pthread)demo_task;
|
||||
thread.tpriority= osPriorityNormal;
|
||||
thread.stacksize= DEMO_TASK_STACKSIZE;
|
||||
thread.ptcb = &demo_task_obj;
|
||||
thread.pstackspace = demo_task_buf;
|
||||
|
||||
osThreadCreate (&thread, NULL);
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue