portability: cmsis: Rename cmsis wrapper types
Namespace this types with `cmsis_rtos` instead of `cv2` Signed-off-by: Utsav Munendra <utsavm@meta.com>
This commit is contained in:
parent
13ef44200e
commit
11eb0ce4db
9 changed files with 165 additions and 114 deletions
|
@ -10,57 +10,102 @@
|
|||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/portability/cmsis_os2.h>
|
||||
|
||||
struct cv2_thread {
|
||||
/** @brief Size for names of RTOS objects. */
|
||||
#define CMSIS_OBJ_NAME_MAX_LEN 16
|
||||
|
||||
/**
|
||||
* @brief Control block for a CMSIS-RTOSv2 thread.
|
||||
*
|
||||
* Application can use manual user-defined allocation for RTOS objects by supplying a pointer to
|
||||
* thread control block. Control block is initiazed within `osThreadNew()`.
|
||||
*/
|
||||
struct cmsis_rtos_thread_cb {
|
||||
sys_dnode_t node;
|
||||
struct k_thread z_thread;
|
||||
struct k_poll_signal poll_signal;
|
||||
struct k_poll_event poll_event;
|
||||
uint32_t signal_results;
|
||||
char name[16];
|
||||
char name[CMSIS_OBJ_NAME_MAX_LEN];
|
||||
uint32_t attr_bits;
|
||||
struct k_sem join_guard;
|
||||
char has_joined;
|
||||
};
|
||||
|
||||
struct cv2_timer {
|
||||
/**
|
||||
* @brief Control block for a CMSIS-RTOSv2 timer.
|
||||
*
|
||||
* Application can use manual user-defined allocation for RTOS objects by supplying a pointer to
|
||||
* timer control block. Control block is initiazed within `osTimerNew()`.
|
||||
*/
|
||||
struct cmsis_rtos_timer_cb {
|
||||
struct k_timer z_timer;
|
||||
osTimerType_t type;
|
||||
uint32_t status;
|
||||
char name[16];
|
||||
char name[CMSIS_OBJ_NAME_MAX_LEN];
|
||||
void (*callback_function)(void *argument);
|
||||
void *arg;
|
||||
};
|
||||
|
||||
struct cv2_mutex {
|
||||
/**
|
||||
* @brief Control block for a CMSIS-RTOSv2 mutex.
|
||||
*
|
||||
* Application can use manual user-defined allocation for RTOS objects by supplying a pointer to
|
||||
* mutex control block. Control block is initiazed within `osMutexNew()`.
|
||||
*/
|
||||
struct cmsis_rtos_mutex_cb {
|
||||
struct k_mutex z_mutex;
|
||||
char name[16];
|
||||
char name[CMSIS_OBJ_NAME_MAX_LEN];
|
||||
uint32_t state;
|
||||
};
|
||||
|
||||
struct cv2_sem {
|
||||
/**
|
||||
* @brief Control block for a CMSIS-RTOSv2 semaphore.
|
||||
*
|
||||
* Application can use manual user-defined allocation for RTOS objects by supplying a pointer to
|
||||
* semaphore control block. Control block is initiazed within `osSemaphoreNew()`.
|
||||
*/
|
||||
struct cmsis_rtos_semaphore_cb {
|
||||
struct k_sem z_semaphore;
|
||||
char name[16];
|
||||
char name[CMSIS_OBJ_NAME_MAX_LEN];
|
||||
};
|
||||
|
||||
struct cv2_mslab {
|
||||
/**
|
||||
* @brief Control block for a CMSIS-RTOSv2 memory pool.
|
||||
*
|
||||
* Application can use manual user-defined allocation for RTOS objects by supplying a pointer to
|
||||
* memory pool control block. Control block is initiazed within `osMemoryPoolNew()`.
|
||||
*/
|
||||
struct cmsis_rtos_mempool_cb {
|
||||
struct k_mem_slab z_mslab;
|
||||
void *pool;
|
||||
char is_dynamic_allocation;
|
||||
char name[16];
|
||||
char name[CMSIS_OBJ_NAME_MAX_LEN];
|
||||
};
|
||||
|
||||
struct cv2_msgq {
|
||||
/**
|
||||
* @brief Control block for a CMSIS-RTOSv2 message queue.
|
||||
*
|
||||
* Application can use manual user-defined allocation for RTOS objects by supplying a pointer to
|
||||
* message queue control block. Control block is initiazed within `osMessageQueueNew()`.
|
||||
*/
|
||||
struct cmsis_rtos_msgq_cb {
|
||||
struct k_msgq z_msgq;
|
||||
void *pool;
|
||||
char is_dynamic_allocation;
|
||||
char name[16];
|
||||
char name[CMSIS_OBJ_NAME_MAX_LEN];
|
||||
};
|
||||
|
||||
struct cv2_event_flags {
|
||||
/**
|
||||
* @brief Control block for a CMSIS-RTOSv2 event flag.
|
||||
*
|
||||
* Application can use manual user-defined allocation for RTOS objects by supplying a pointer to
|
||||
* event flag control block. Control block is initiazed within `osEventFlagsNew()`.
|
||||
*/
|
||||
struct cmsis_rtos_event_cb {
|
||||
struct k_poll_signal poll_signal;
|
||||
struct k_poll_event poll_event;
|
||||
uint32_t signal_results;
|
||||
char name[16];
|
||||
char name[CMSIS_OBJ_NAME_MAX_LEN];
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include <zephyr/portability/cmsis_types.h>
|
||||
#include <string.h>
|
||||
|
||||
K_MEM_SLAB_DEFINE(cv2_event_flags_slab, sizeof(struct cv2_event_flags),
|
||||
K_MEM_SLAB_DEFINE(cmsis_rtos_event_cb_slab, sizeof(struct cmsis_rtos_event_cb),
|
||||
CONFIG_CMSIS_V2_EVT_FLAGS_MAX_COUNT, 4);
|
||||
|
||||
static const osEventFlagsAttr_t init_event_flags_attrs = {
|
||||
|
@ -25,7 +25,7 @@ static const osEventFlagsAttr_t init_event_flags_attrs = {
|
|||
*/
|
||||
osEventFlagsId_t osEventFlagsNew(const osEventFlagsAttr_t *attr)
|
||||
{
|
||||
struct cv2_event_flags *events;
|
||||
struct cmsis_rtos_event_cb *events;
|
||||
|
||||
if (k_is_in_isr()) {
|
||||
return NULL;
|
||||
|
@ -35,8 +35,8 @@ osEventFlagsId_t osEventFlagsNew(const osEventFlagsAttr_t *attr)
|
|||
attr = &init_event_flags_attrs;
|
||||
}
|
||||
|
||||
if (k_mem_slab_alloc(&cv2_event_flags_slab, (void **)&events, K_MSEC(100)) == 0) {
|
||||
memset(events, 0, sizeof(struct cv2_event_flags));
|
||||
if (k_mem_slab_alloc(&cmsis_rtos_event_cb_slab, (void **)&events, K_MSEC(100)) == 0) {
|
||||
memset(events, 0, sizeof(struct cmsis_rtos_event_cb));
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ osEventFlagsId_t osEventFlagsNew(const osEventFlagsAttr_t *attr)
|
|||
*/
|
||||
uint32_t osEventFlagsSet(osEventFlagsId_t ef_id, uint32_t flags)
|
||||
{
|
||||
struct cv2_event_flags *events = (struct cv2_event_flags *)ef_id;
|
||||
struct cmsis_rtos_event_cb *events = (struct cmsis_rtos_event_cb *)ef_id;
|
||||
unsigned int key;
|
||||
|
||||
if ((ef_id == NULL) || (flags & osFlagsError)) {
|
||||
|
@ -81,7 +81,7 @@ uint32_t osEventFlagsSet(osEventFlagsId_t ef_id, uint32_t flags)
|
|||
*/
|
||||
uint32_t osEventFlagsClear(osEventFlagsId_t ef_id, uint32_t flags)
|
||||
{
|
||||
struct cv2_event_flags *events = (struct cv2_event_flags *)ef_id;
|
||||
struct cmsis_rtos_event_cb *events = (struct cmsis_rtos_event_cb *)ef_id;
|
||||
unsigned int key;
|
||||
uint32_t sig;
|
||||
|
||||
|
@ -103,7 +103,7 @@ uint32_t osEventFlagsClear(osEventFlagsId_t ef_id, uint32_t flags)
|
|||
uint32_t osEventFlagsWait(osEventFlagsId_t ef_id, uint32_t flags, uint32_t options,
|
||||
uint32_t timeout)
|
||||
{
|
||||
struct cv2_event_flags *events = (struct cv2_event_flags *)ef_id;
|
||||
struct cmsis_rtos_event_cb *events = (struct cmsis_rtos_event_cb *)ef_id;
|
||||
int retval, key;
|
||||
uint32_t sig;
|
||||
k_timeout_t poll_timeout;
|
||||
|
@ -206,7 +206,7 @@ uint32_t osEventFlagsWait(osEventFlagsId_t ef_id, uint32_t flags, uint32_t optio
|
|||
*/
|
||||
const char *osEventFlagsGetName(osEventFlagsId_t ef_id)
|
||||
{
|
||||
struct cv2_event_flags *events = (struct cv2_event_flags *)ef_id;
|
||||
struct cmsis_rtos_event_cb *events = (struct cmsis_rtos_event_cb *)ef_id;
|
||||
|
||||
if (!k_is_in_isr() && (ef_id != NULL)) {
|
||||
return events->name;
|
||||
|
@ -220,7 +220,7 @@ const char *osEventFlagsGetName(osEventFlagsId_t ef_id)
|
|||
*/
|
||||
uint32_t osEventFlagsGet(osEventFlagsId_t ef_id)
|
||||
{
|
||||
struct cv2_event_flags *events = (struct cv2_event_flags *)ef_id;
|
||||
struct cmsis_rtos_event_cb *events = (struct cmsis_rtos_event_cb *)ef_id;
|
||||
|
||||
if (ef_id == NULL) {
|
||||
return 0;
|
||||
|
@ -234,7 +234,7 @@ uint32_t osEventFlagsGet(osEventFlagsId_t ef_id)
|
|||
*/
|
||||
osStatus_t osEventFlagsDelete(osEventFlagsId_t ef_id)
|
||||
{
|
||||
struct cv2_event_flags *events = (struct cv2_event_flags *)ef_id;
|
||||
struct cmsis_rtos_event_cb *events = (struct cmsis_rtos_event_cb *)ef_id;
|
||||
|
||||
if (ef_id == NULL) {
|
||||
return osErrorResource;
|
||||
|
@ -248,7 +248,7 @@ osStatus_t osEventFlagsDelete(osEventFlagsId_t ef_id)
|
|||
* ef_id is incorrect) is not supported in Zephyr.
|
||||
*/
|
||||
|
||||
k_mem_slab_free(&cv2_event_flags_slab, (void *)events);
|
||||
k_mem_slab_free(&cmsis_rtos_event_cb_slab, (void *)events);
|
||||
|
||||
return osOK;
|
||||
}
|
||||
|
|
|
@ -11,7 +11,8 @@
|
|||
|
||||
#define TIME_OUT_TICKS 10
|
||||
|
||||
K_MEM_SLAB_DEFINE(cv2_mem_slab, sizeof(struct cv2_mslab), CONFIG_CMSIS_V2_MEM_SLAB_MAX_COUNT, 4);
|
||||
K_MEM_SLAB_DEFINE(cv2_mem_slab, sizeof(struct cmsis_rtos_mempool_cb),
|
||||
CONFIG_CMSIS_V2_MEM_SLAB_MAX_COUNT, 4);
|
||||
|
||||
static const osMemoryPoolAttr_t init_mslab_attrs = {
|
||||
.name = "ZephyrMemPool",
|
||||
|
@ -28,7 +29,7 @@ static const osMemoryPoolAttr_t init_mslab_attrs = {
|
|||
osMemoryPoolId_t osMemoryPoolNew(uint32_t block_count, uint32_t block_size,
|
||||
const osMemoryPoolAttr_t *attr)
|
||||
{
|
||||
struct cv2_mslab *mslab;
|
||||
struct cmsis_rtos_mempool_cb *mslab;
|
||||
|
||||
BUILD_ASSERT(K_HEAP_MEM_POOL_SIZE >= CONFIG_CMSIS_V2_MEM_SLAB_MAX_DYNAMIC_SIZE,
|
||||
"heap must be configured to be at least the max dynamic size");
|
||||
|
@ -46,7 +47,7 @@ osMemoryPoolId_t osMemoryPoolNew(uint32_t block_count, uint32_t block_size,
|
|||
}
|
||||
|
||||
if (k_mem_slab_alloc(&cv2_mem_slab, (void **)&mslab, K_MSEC(100)) == 0) {
|
||||
(void)memset(mslab, 0, sizeof(struct cv2_mslab));
|
||||
(void)memset(mslab, 0, sizeof(struct cmsis_rtos_mempool_cb));
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -90,7 +91,7 @@ osMemoryPoolId_t osMemoryPoolNew(uint32_t block_count, uint32_t block_size,
|
|||
*/
|
||||
void *osMemoryPoolAlloc(osMemoryPoolId_t mp_id, uint32_t timeout)
|
||||
{
|
||||
struct cv2_mslab *mslab = (struct cv2_mslab *)mp_id;
|
||||
struct cmsis_rtos_mempool_cb *mslab = (struct cmsis_rtos_mempool_cb *)mp_id;
|
||||
int retval;
|
||||
void *ptr;
|
||||
|
||||
|
@ -126,7 +127,7 @@ void *osMemoryPoolAlloc(osMemoryPoolId_t mp_id, uint32_t timeout)
|
|||
*/
|
||||
osStatus_t osMemoryPoolFree(osMemoryPoolId_t mp_id, void *block)
|
||||
{
|
||||
struct cv2_mslab *mslab = (struct cv2_mslab *)mp_id;
|
||||
struct cmsis_rtos_mempool_cb *mslab = (struct cmsis_rtos_mempool_cb *)mp_id;
|
||||
|
||||
if (mslab == NULL) {
|
||||
return osErrorParameter;
|
||||
|
@ -147,7 +148,7 @@ osStatus_t osMemoryPoolFree(osMemoryPoolId_t mp_id, void *block)
|
|||
*/
|
||||
const char *osMemoryPoolGetName(osMemoryPoolId_t mp_id)
|
||||
{
|
||||
struct cv2_mslab *mslab = (struct cv2_mslab *)mp_id;
|
||||
struct cmsis_rtos_mempool_cb *mslab = (struct cmsis_rtos_mempool_cb *)mp_id;
|
||||
|
||||
if (!k_is_in_isr() && (mslab != NULL)) {
|
||||
return mslab->name;
|
||||
|
@ -161,7 +162,7 @@ const char *osMemoryPoolGetName(osMemoryPoolId_t mp_id)
|
|||
*/
|
||||
uint32_t osMemoryPoolGetCapacity(osMemoryPoolId_t mp_id)
|
||||
{
|
||||
struct cv2_mslab *mslab = (struct cv2_mslab *)mp_id;
|
||||
struct cmsis_rtos_mempool_cb *mslab = (struct cmsis_rtos_mempool_cb *)mp_id;
|
||||
|
||||
if (mslab == NULL) {
|
||||
return 0;
|
||||
|
@ -175,7 +176,7 @@ uint32_t osMemoryPoolGetCapacity(osMemoryPoolId_t mp_id)
|
|||
*/
|
||||
uint32_t osMemoryPoolGetBlockSize(osMemoryPoolId_t mp_id)
|
||||
{
|
||||
struct cv2_mslab *mslab = (struct cv2_mslab *)mp_id;
|
||||
struct cmsis_rtos_mempool_cb *mslab = (struct cmsis_rtos_mempool_cb *)mp_id;
|
||||
|
||||
if (mslab == NULL) {
|
||||
return 0;
|
||||
|
@ -189,7 +190,7 @@ uint32_t osMemoryPoolGetBlockSize(osMemoryPoolId_t mp_id)
|
|||
*/
|
||||
uint32_t osMemoryPoolGetCount(osMemoryPoolId_t mp_id)
|
||||
{
|
||||
struct cv2_mslab *mslab = (struct cv2_mslab *)mp_id;
|
||||
struct cmsis_rtos_mempool_cb *mslab = (struct cmsis_rtos_mempool_cb *)mp_id;
|
||||
|
||||
if (mslab == NULL) {
|
||||
return 0;
|
||||
|
@ -203,7 +204,7 @@ uint32_t osMemoryPoolGetCount(osMemoryPoolId_t mp_id)
|
|||
*/
|
||||
uint32_t osMemoryPoolGetSpace(osMemoryPoolId_t mp_id)
|
||||
{
|
||||
struct cv2_mslab *mslab = (struct cv2_mslab *)mp_id;
|
||||
struct cmsis_rtos_mempool_cb *mslab = (struct cmsis_rtos_mempool_cb *)mp_id;
|
||||
|
||||
if (mslab == NULL) {
|
||||
return 0;
|
||||
|
@ -217,7 +218,7 @@ uint32_t osMemoryPoolGetSpace(osMemoryPoolId_t mp_id)
|
|||
*/
|
||||
osStatus_t osMemoryPoolDelete(osMemoryPoolId_t mp_id)
|
||||
{
|
||||
struct cv2_mslab *mslab = (struct cv2_mslab *)mp_id;
|
||||
struct cmsis_rtos_mempool_cb *mslab = (struct cmsis_rtos_mempool_cb *)mp_id;
|
||||
|
||||
if (mslab == NULL) {
|
||||
return osErrorParameter;
|
||||
|
|
|
@ -9,7 +9,8 @@
|
|||
#include <string.h>
|
||||
#include "wrapper.h"
|
||||
|
||||
K_MEM_SLAB_DEFINE(cv2_msgq_slab, sizeof(struct cv2_msgq), CONFIG_CMSIS_V2_MSGQ_MAX_COUNT, 4);
|
||||
K_MEM_SLAB_DEFINE(cmsis_rtos_msgq_cb_slab, sizeof(struct cmsis_rtos_msgq_cb),
|
||||
CONFIG_CMSIS_V2_MSGQ_MAX_COUNT, 4);
|
||||
|
||||
static const osMessageQueueAttr_t init_msgq_attrs = {
|
||||
.name = "ZephyrMsgQ",
|
||||
|
@ -26,7 +27,7 @@ static const osMessageQueueAttr_t init_msgq_attrs = {
|
|||
osMessageQueueId_t osMessageQueueNew(uint32_t msg_count, uint32_t msg_size,
|
||||
const osMessageQueueAttr_t *attr)
|
||||
{
|
||||
struct cv2_msgq *msgq;
|
||||
struct cmsis_rtos_msgq_cb *msgq;
|
||||
|
||||
BUILD_ASSERT(K_HEAP_MEM_POOL_SIZE >= CONFIG_CMSIS_V2_MSGQ_MAX_DYNAMIC_SIZE,
|
||||
"heap must be configured to be at least the max dynamic size");
|
||||
|
@ -43,8 +44,8 @@ osMessageQueueId_t osMessageQueueNew(uint32_t msg_count, uint32_t msg_size,
|
|||
attr = &init_msgq_attrs;
|
||||
}
|
||||
|
||||
if (k_mem_slab_alloc(&cv2_msgq_slab, (void **)&msgq, K_MSEC(100)) == 0) {
|
||||
(void)memset(msgq, 0, sizeof(struct cv2_msgq));
|
||||
if (k_mem_slab_alloc(&cmsis_rtos_msgq_cb_slab, (void **)&msgq, K_MSEC(100)) == 0) {
|
||||
(void)memset(msgq, 0, sizeof(struct cmsis_rtos_msgq_cb));
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -56,12 +57,12 @@ osMessageQueueId_t osMessageQueueNew(uint32_t msg_count, uint32_t msg_size,
|
|||
#if (K_HEAP_MEM_POOL_SIZE > 0)
|
||||
msgq->pool = k_calloc(msg_count, msg_size);
|
||||
if (msgq->pool == NULL) {
|
||||
k_mem_slab_free(&cv2_msgq_slab, (void *)msgq);
|
||||
k_mem_slab_free(&cmsis_rtos_msgq_cb_slab, (void *)msgq);
|
||||
return NULL;
|
||||
}
|
||||
msgq->is_dynamic_allocation = TRUE;
|
||||
#else
|
||||
k_mem_slab_free(&cv2_msgq_slab, (void *)msgq);
|
||||
k_mem_slab_free(&cmsis_rtos_msgq_cb_slab, (void *)msgq);
|
||||
return NULL;
|
||||
#endif
|
||||
} else {
|
||||
|
@ -86,7 +87,7 @@ osMessageQueueId_t osMessageQueueNew(uint32_t msg_count, uint32_t msg_size,
|
|||
osStatus_t osMessageQueuePut(osMessageQueueId_t msgq_id, const void *msg_ptr, uint8_t msg_prio,
|
||||
uint32_t timeout)
|
||||
{
|
||||
struct cv2_msgq *msgq = (struct cv2_msgq *)msgq_id;
|
||||
struct cmsis_rtos_msgq_cb *msgq = (struct cmsis_rtos_msgq_cb *)msgq_id;
|
||||
int retval;
|
||||
|
||||
ARG_UNUSED(msg_prio);
|
||||
|
@ -123,7 +124,7 @@ osStatus_t osMessageQueuePut(osMessageQueueId_t msgq_id, const void *msg_ptr, ui
|
|||
osStatus_t osMessageQueueGet(osMessageQueueId_t msgq_id, void *msg_ptr, uint8_t *msg_prio,
|
||||
uint32_t timeout)
|
||||
{
|
||||
struct cv2_msgq *msgq = (struct cv2_msgq *)msgq_id;
|
||||
struct cmsis_rtos_msgq_cb *msgq = (struct cmsis_rtos_msgq_cb *)msgq_id;
|
||||
int retval;
|
||||
|
||||
ARG_UNUSED(msg_prio);
|
||||
|
@ -161,7 +162,7 @@ osStatus_t osMessageQueueGet(osMessageQueueId_t msgq_id, void *msg_ptr, uint8_t
|
|||
*/
|
||||
uint32_t osMessageQueueGetCapacity(osMessageQueueId_t msgq_id)
|
||||
{
|
||||
struct cv2_msgq *msgq = (struct cv2_msgq *)msgq_id;
|
||||
struct cmsis_rtos_msgq_cb *msgq = (struct cmsis_rtos_msgq_cb *)msgq_id;
|
||||
|
||||
if (msgq == NULL) {
|
||||
return 0;
|
||||
|
@ -175,7 +176,7 @@ uint32_t osMessageQueueGetCapacity(osMessageQueueId_t msgq_id)
|
|||
*/
|
||||
uint32_t osMessageQueueGetMsgSize(osMessageQueueId_t msgq_id)
|
||||
{
|
||||
struct cv2_msgq *msgq = (struct cv2_msgq *)msgq_id;
|
||||
struct cmsis_rtos_msgq_cb *msgq = (struct cmsis_rtos_msgq_cb *)msgq_id;
|
||||
|
||||
if (msgq == NULL) {
|
||||
return 0;
|
||||
|
@ -189,7 +190,7 @@ uint32_t osMessageQueueGetMsgSize(osMessageQueueId_t msgq_id)
|
|||
*/
|
||||
uint32_t osMessageQueueGetCount(osMessageQueueId_t msgq_id)
|
||||
{
|
||||
struct cv2_msgq *msgq = (struct cv2_msgq *)msgq_id;
|
||||
struct cmsis_rtos_msgq_cb *msgq = (struct cmsis_rtos_msgq_cb *)msgq_id;
|
||||
|
||||
if (msgq == NULL) {
|
||||
return 0;
|
||||
|
@ -203,7 +204,7 @@ uint32_t osMessageQueueGetCount(osMessageQueueId_t msgq_id)
|
|||
*/
|
||||
uint32_t osMessageQueueGetSpace(osMessageQueueId_t msgq_id)
|
||||
{
|
||||
struct cv2_msgq *msgq = (struct cv2_msgq *)msgq_id;
|
||||
struct cmsis_rtos_msgq_cb *msgq = (struct cmsis_rtos_msgq_cb *)msgq_id;
|
||||
|
||||
if (msgq == NULL) {
|
||||
return 0;
|
||||
|
@ -217,7 +218,7 @@ uint32_t osMessageQueueGetSpace(osMessageQueueId_t msgq_id)
|
|||
*/
|
||||
const char *osMessageQueueGetName(osMessageQueueId_t msgq_id)
|
||||
{
|
||||
struct cv2_msgq *msgq = (struct cv2_msgq *)msgq_id;
|
||||
struct cmsis_rtos_msgq_cb *msgq = (struct cmsis_rtos_msgq_cb *)msgq_id;
|
||||
|
||||
if (!k_is_in_isr() && (msgq_id != NULL)) {
|
||||
return msgq->name;
|
||||
|
@ -231,7 +232,7 @@ const char *osMessageQueueGetName(osMessageQueueId_t msgq_id)
|
|||
*/
|
||||
osStatus_t osMessageQueueReset(osMessageQueueId_t msgq_id)
|
||||
{
|
||||
struct cv2_msgq *msgq = (struct cv2_msgq *)msgq_id;
|
||||
struct cmsis_rtos_msgq_cb *msgq = (struct cmsis_rtos_msgq_cb *)msgq_id;
|
||||
|
||||
if (msgq == NULL) {
|
||||
return osErrorParameter;
|
||||
|
@ -256,7 +257,7 @@ osStatus_t osMessageQueueReset(osMessageQueueId_t msgq_id)
|
|||
*/
|
||||
osStatus_t osMessageQueueDelete(osMessageQueueId_t msgq_id)
|
||||
{
|
||||
struct cv2_msgq *msgq = (struct cv2_msgq *)msgq_id;
|
||||
struct cmsis_rtos_msgq_cb *msgq = (struct cmsis_rtos_msgq_cb *)msgq_id;
|
||||
|
||||
if (msgq == NULL) {
|
||||
return osErrorParameter;
|
||||
|
@ -274,7 +275,7 @@ osStatus_t osMessageQueueDelete(osMessageQueueId_t msgq_id)
|
|||
if (msgq->is_dynamic_allocation) {
|
||||
k_free(msgq->pool);
|
||||
}
|
||||
k_mem_slab_free(&cv2_msgq_slab, (void *)msgq);
|
||||
k_mem_slab_free(&cmsis_rtos_msgq_cb_slab, (void *)msgq);
|
||||
|
||||
return osOK;
|
||||
}
|
||||
|
|
|
@ -9,7 +9,8 @@
|
|||
#include <string.h>
|
||||
#include "wrapper.h"
|
||||
|
||||
K_MEM_SLAB_DEFINE(cv2_mutex_slab, sizeof(struct cv2_mutex), CONFIG_CMSIS_V2_MUTEX_MAX_COUNT, 4);
|
||||
K_MEM_SLAB_DEFINE(cmsis_rtos_mutex_cb_slab, sizeof(struct cmsis_rtos_mutex_cb),
|
||||
CONFIG_CMSIS_V2_MUTEX_MAX_COUNT, 4);
|
||||
|
||||
static const osMutexAttr_t init_mutex_attrs = {
|
||||
.name = "ZephyrMutex",
|
||||
|
@ -23,7 +24,7 @@ static const osMutexAttr_t init_mutex_attrs = {
|
|||
*/
|
||||
osMutexId_t osMutexNew(const osMutexAttr_t *attr)
|
||||
{
|
||||
struct cv2_mutex *mutex;
|
||||
struct cmsis_rtos_mutex_cb *mutex;
|
||||
|
||||
if (k_is_in_isr()) {
|
||||
return NULL;
|
||||
|
@ -38,8 +39,8 @@ osMutexId_t osMutexNew(const osMutexAttr_t *attr)
|
|||
|
||||
__ASSERT(!(attr->attr_bits & osMutexRobust), "Zephyr does not support osMutexRobust.\n");
|
||||
|
||||
if (k_mem_slab_alloc(&cv2_mutex_slab, (void **)&mutex, K_MSEC(100)) == 0) {
|
||||
memset(mutex, 0, sizeof(struct cv2_mutex));
|
||||
if (k_mem_slab_alloc(&cmsis_rtos_mutex_cb_slab, (void **)&mutex, K_MSEC(100)) == 0) {
|
||||
memset(mutex, 0, sizeof(struct cmsis_rtos_mutex_cb));
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -61,7 +62,7 @@ osMutexId_t osMutexNew(const osMutexAttr_t *attr)
|
|||
*/
|
||||
osStatus_t osMutexAcquire(osMutexId_t mutex_id, uint32_t timeout)
|
||||
{
|
||||
struct cv2_mutex *mutex = (struct cv2_mutex *)mutex_id;
|
||||
struct cmsis_rtos_mutex_cb *mutex = (struct cmsis_rtos_mutex_cb *)mutex_id;
|
||||
int status;
|
||||
|
||||
if (mutex_id == NULL) {
|
||||
|
@ -94,7 +95,7 @@ osStatus_t osMutexAcquire(osMutexId_t mutex_id, uint32_t timeout)
|
|||
*/
|
||||
osStatus_t osMutexRelease(osMutexId_t mutex_id)
|
||||
{
|
||||
struct cv2_mutex *mutex = (struct cv2_mutex *)mutex_id;
|
||||
struct cmsis_rtos_mutex_cb *mutex = (struct cmsis_rtos_mutex_cb *)mutex_id;
|
||||
|
||||
if (mutex_id == NULL) {
|
||||
return osErrorParameter;
|
||||
|
@ -116,7 +117,7 @@ osStatus_t osMutexRelease(osMutexId_t mutex_id)
|
|||
*/
|
||||
osStatus_t osMutexDelete(osMutexId_t mutex_id)
|
||||
{
|
||||
struct cv2_mutex *mutex = (struct cv2_mutex *)mutex_id;
|
||||
struct cmsis_rtos_mutex_cb *mutex = (struct cmsis_rtos_mutex_cb *)mutex_id;
|
||||
|
||||
if (mutex_id == NULL) {
|
||||
return osErrorParameter;
|
||||
|
@ -130,14 +131,14 @@ osStatus_t osMutexDelete(osMutexId_t mutex_id)
|
|||
* mutex_id is in an invalid mutex state) is not supported in Zephyr.
|
||||
*/
|
||||
|
||||
k_mem_slab_free(&cv2_mutex_slab, (void *)mutex);
|
||||
k_mem_slab_free(&cmsis_rtos_mutex_cb_slab, (void *)mutex);
|
||||
|
||||
return osOK;
|
||||
}
|
||||
|
||||
osThreadId_t osMutexGetOwner(osMutexId_t mutex_id)
|
||||
{
|
||||
struct cv2_mutex *mutex = (struct cv2_mutex *)mutex_id;
|
||||
struct cmsis_rtos_mutex_cb *mutex = (struct cmsis_rtos_mutex_cb *)mutex_id;
|
||||
|
||||
if (k_is_in_isr() || (mutex == NULL)) {
|
||||
return NULL;
|
||||
|
@ -153,7 +154,7 @@ osThreadId_t osMutexGetOwner(osMutexId_t mutex_id)
|
|||
|
||||
const char *osMutexGetName(osMutexId_t mutex_id)
|
||||
{
|
||||
struct cv2_mutex *mutex = (struct cv2_mutex *)mutex_id;
|
||||
struct cmsis_rtos_mutex_cb *mutex = (struct cmsis_rtos_mutex_cb *)mutex_id;
|
||||
|
||||
if (k_is_in_isr() || (mutex == NULL)) {
|
||||
return NULL;
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
#include <zephyr/portability/cmsis_types.h>
|
||||
#include <string.h>
|
||||
|
||||
K_MEM_SLAB_DEFINE(cv2_semaphore_slab, sizeof(struct cv2_sem), CONFIG_CMSIS_V2_SEMAPHORE_MAX_COUNT,
|
||||
4);
|
||||
K_MEM_SLAB_DEFINE(cmsis_rtos_semaphore_cb_slab, sizeof(struct cmsis_rtos_semaphore_cb),
|
||||
CONFIG_CMSIS_V2_SEMAPHORE_MAX_COUNT, 4);
|
||||
|
||||
static const osSemaphoreAttr_t init_sema_attrs = {
|
||||
.name = "ZephyrSem",
|
||||
|
@ -24,7 +24,7 @@ static const osSemaphoreAttr_t init_sema_attrs = {
|
|||
osSemaphoreId_t osSemaphoreNew(uint32_t max_count, uint32_t initial_count,
|
||||
const osSemaphoreAttr_t *attr)
|
||||
{
|
||||
struct cv2_sem *semaphore;
|
||||
struct cmsis_rtos_semaphore_cb *semaphore;
|
||||
|
||||
if (k_is_in_isr()) {
|
||||
return NULL;
|
||||
|
@ -34,8 +34,9 @@ osSemaphoreId_t osSemaphoreNew(uint32_t max_count, uint32_t initial_count,
|
|||
attr = &init_sema_attrs;
|
||||
}
|
||||
|
||||
if (k_mem_slab_alloc(&cv2_semaphore_slab, (void **)&semaphore, K_MSEC(100)) == 0) {
|
||||
(void)memset(semaphore, 0, sizeof(struct cv2_sem));
|
||||
if (k_mem_slab_alloc(&cmsis_rtos_semaphore_cb_slab, (void **)&semaphore, K_MSEC(100)) ==
|
||||
0) {
|
||||
(void)memset(semaphore, 0, sizeof(struct cmsis_rtos_semaphore_cb));
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -56,7 +57,7 @@ osSemaphoreId_t osSemaphoreNew(uint32_t max_count, uint32_t initial_count,
|
|||
*/
|
||||
osStatus_t osSemaphoreAcquire(osSemaphoreId_t semaphore_id, uint32_t timeout)
|
||||
{
|
||||
struct cv2_sem *semaphore = (struct cv2_sem *)semaphore_id;
|
||||
struct cmsis_rtos_semaphore_cb *semaphore = (struct cmsis_rtos_semaphore_cb *)semaphore_id;
|
||||
int status;
|
||||
|
||||
if (semaphore_id == NULL) {
|
||||
|
@ -87,7 +88,7 @@ osStatus_t osSemaphoreAcquire(osSemaphoreId_t semaphore_id, uint32_t timeout)
|
|||
|
||||
uint32_t osSemaphoreGetCount(osSemaphoreId_t semaphore_id)
|
||||
{
|
||||
struct cv2_sem *semaphore = (struct cv2_sem *)semaphore_id;
|
||||
struct cmsis_rtos_semaphore_cb *semaphore = (struct cmsis_rtos_semaphore_cb *)semaphore_id;
|
||||
|
||||
if (semaphore_id == NULL) {
|
||||
return 0;
|
||||
|
@ -101,7 +102,7 @@ uint32_t osSemaphoreGetCount(osSemaphoreId_t semaphore_id)
|
|||
*/
|
||||
osStatus_t osSemaphoreRelease(osSemaphoreId_t semaphore_id)
|
||||
{
|
||||
struct cv2_sem *semaphore = (struct cv2_sem *)semaphore_id;
|
||||
struct cmsis_rtos_semaphore_cb *semaphore = (struct cmsis_rtos_semaphore_cb *)semaphore_id;
|
||||
|
||||
if (semaphore_id == NULL) {
|
||||
return osErrorParameter;
|
||||
|
@ -122,7 +123,7 @@ osStatus_t osSemaphoreRelease(osSemaphoreId_t semaphore_id)
|
|||
*/
|
||||
osStatus_t osSemaphoreDelete(osSemaphoreId_t semaphore_id)
|
||||
{
|
||||
struct cv2_sem *semaphore = (struct cv2_sem *)semaphore_id;
|
||||
struct cmsis_rtos_semaphore_cb *semaphore = (struct cmsis_rtos_semaphore_cb *)semaphore_id;
|
||||
|
||||
if (semaphore_id == NULL) {
|
||||
return osErrorParameter;
|
||||
|
@ -137,14 +138,14 @@ osStatus_t osSemaphoreDelete(osSemaphoreId_t semaphore_id)
|
|||
* supported in Zephyr.
|
||||
*/
|
||||
|
||||
k_mem_slab_free(&cv2_semaphore_slab, (void *)semaphore);
|
||||
k_mem_slab_free(&cmsis_rtos_semaphore_cb_slab, (void *)semaphore);
|
||||
|
||||
return osOK;
|
||||
}
|
||||
|
||||
const char *osSemaphoreGetName(osSemaphoreId_t semaphore_id)
|
||||
{
|
||||
struct cv2_sem *semaphore = (struct cv2_sem *)semaphore_id;
|
||||
struct cmsis_rtos_semaphore_cb *semaphore = (struct cmsis_rtos_semaphore_cb *)semaphore_id;
|
||||
|
||||
if (!k_is_in_isr() && (semaphore_id != NULL)) {
|
||||
return semaphore->name;
|
||||
|
|
|
@ -26,12 +26,13 @@ static const osThreadAttr_t init_thread_attrs = {
|
|||
};
|
||||
|
||||
static sys_dlist_t thread_list;
|
||||
static struct cv2_thread cv2_thread_pool[CONFIG_CMSIS_V2_THREAD_MAX_COUNT];
|
||||
static struct cmsis_rtos_thread_cb cmsis_rtos_thread_cb_pool[CONFIG_CMSIS_V2_THREAD_MAX_COUNT];
|
||||
static atomic_t thread_num;
|
||||
static atomic_t thread_num_dynamic;
|
||||
|
||||
#if CONFIG_CMSIS_V2_THREAD_DYNAMIC_MAX_COUNT != 0
|
||||
static K_THREAD_STACK_ARRAY_DEFINE(cv2_thread_stack_pool, CONFIG_CMSIS_V2_THREAD_DYNAMIC_MAX_COUNT,
|
||||
static K_THREAD_STACK_ARRAY_DEFINE(cmsis_rtos_thread_stack_pool,
|
||||
CONFIG_CMSIS_V2_THREAD_DYNAMIC_MAX_COUNT,
|
||||
CONFIG_CMSIS_V2_THREAD_DYNAMIC_STACK_SIZE);
|
||||
#endif
|
||||
|
||||
|
@ -54,7 +55,7 @@ static inline uint32_t cmsis_to_zephyr_priority(uint32_t c_prio)
|
|||
|
||||
static void zephyr_thread_wrapper(void *arg1, void *arg2, void *arg3)
|
||||
{
|
||||
struct cv2_thread *tid = arg2;
|
||||
struct cmsis_rtos_thread_cb *tid = arg2;
|
||||
void *(*fun_ptr)(void *) = arg3;
|
||||
|
||||
fun_ptr(arg1);
|
||||
|
@ -66,10 +67,10 @@ static void zephyr_thread_wrapper(void *arg1, void *arg2, void *arg3)
|
|||
void *is_cmsis_rtos_v2_thread(void *thread_id)
|
||||
{
|
||||
sys_dnode_t *pnode;
|
||||
struct cv2_thread *itr;
|
||||
struct cmsis_rtos_thread_cb *itr;
|
||||
|
||||
SYS_DLIST_FOR_EACH_NODE(&thread_list, pnode) {
|
||||
itr = CONTAINER_OF(pnode, struct cv2_thread, node);
|
||||
itr = CONTAINER_OF(pnode, struct cmsis_rtos_thread_cb, node);
|
||||
|
||||
if ((void *)itr == thread_id) {
|
||||
return itr;
|
||||
|
@ -82,11 +83,11 @@ void *is_cmsis_rtos_v2_thread(void *thread_id)
|
|||
osThreadId_t get_cmsis_thread_id(k_tid_t tid)
|
||||
{
|
||||
sys_dnode_t *pnode;
|
||||
struct cv2_thread *itr;
|
||||
struct cmsis_rtos_thread_cb *itr;
|
||||
|
||||
if (tid != NULL) {
|
||||
SYS_DLIST_FOR_EACH_NODE(&thread_list, pnode) {
|
||||
itr = CONTAINER_OF(pnode, struct cv2_thread, node);
|
||||
itr = CONTAINER_OF(pnode, struct cmsis_rtos_thread_cb, node);
|
||||
|
||||
if (&itr->z_thread == tid) {
|
||||
return (osThreadId_t)itr;
|
||||
|
@ -104,7 +105,7 @@ osThreadId_t osThreadNew(osThreadFunc_t threadfunc, void *arg, const osThreadAtt
|
|||
{
|
||||
int32_t prio;
|
||||
osPriority_t cv2_prio;
|
||||
struct cv2_thread *tid;
|
||||
struct cmsis_rtos_thread_cb *tid;
|
||||
static uint32_t one_time;
|
||||
void *stack;
|
||||
size_t stack_size;
|
||||
|
@ -157,7 +158,7 @@ osThreadId_t osThreadNew(osThreadFunc_t threadfunc, void *arg, const osThreadAtt
|
|||
|
||||
this_thread_num = atomic_inc((atomic_t *)&thread_num);
|
||||
|
||||
tid = &cv2_thread_pool[this_thread_num];
|
||||
tid = &cmsis_rtos_thread_cb_pool[this_thread_num];
|
||||
tid->attr_bits = attr->attr_bits;
|
||||
|
||||
#if CONFIG_CMSIS_V2_THREAD_DYNAMIC_MAX_COUNT != 0
|
||||
|
@ -167,7 +168,7 @@ osThreadId_t osThreadNew(osThreadFunc_t threadfunc, void *arg, const osThreadAtt
|
|||
"dynamic stack size must be configured to be non-zero\n");
|
||||
this_thread_num_dynamic = atomic_inc((atomic_t *)&thread_num_dynamic);
|
||||
stack_size = CONFIG_CMSIS_V2_THREAD_DYNAMIC_STACK_SIZE;
|
||||
stack = cv2_thread_stack_pool[this_thread_num_dynamic];
|
||||
stack = cmsis_rtos_thread_stack_pool[this_thread_num_dynamic];
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
|
@ -218,7 +219,7 @@ const char *osThreadGetName(osThreadId_t thread_id)
|
|||
if (is_cmsis_rtos_v2_thread(thread_id) == NULL) {
|
||||
name = NULL;
|
||||
} else {
|
||||
struct cv2_thread *tid = (struct cv2_thread *)thread_id;
|
||||
struct cmsis_rtos_thread_cb *tid = (struct cmsis_rtos_thread_cb *)thread_id;
|
||||
|
||||
name = k_thread_name_get(&tid->z_thread);
|
||||
}
|
||||
|
@ -242,7 +243,7 @@ osThreadId_t osThreadGetId(void)
|
|||
*/
|
||||
osPriority_t osThreadGetPriority(osThreadId_t thread_id)
|
||||
{
|
||||
struct cv2_thread *tid = (struct cv2_thread *)thread_id;
|
||||
struct cmsis_rtos_thread_cb *tid = (struct cmsis_rtos_thread_cb *)thread_id;
|
||||
uint32_t priority;
|
||||
|
||||
if (k_is_in_isr() || (tid == NULL) || (is_cmsis_rtos_v2_thread(tid) == NULL) ||
|
||||
|
@ -259,7 +260,7 @@ osPriority_t osThreadGetPriority(osThreadId_t thread_id)
|
|||
*/
|
||||
osStatus_t osThreadSetPriority(osThreadId_t thread_id, osPriority_t priority)
|
||||
{
|
||||
struct cv2_thread *tid = (struct cv2_thread *)thread_id;
|
||||
struct cmsis_rtos_thread_cb *tid = (struct cmsis_rtos_thread_cb *)thread_id;
|
||||
|
||||
if ((tid == NULL) || (is_cmsis_rtos_v2_thread(tid) == NULL) ||
|
||||
(priority <= osPriorityNone) || (priority > osPriorityISR)) {
|
||||
|
@ -284,7 +285,7 @@ osStatus_t osThreadSetPriority(osThreadId_t thread_id, osPriority_t priority)
|
|||
*/
|
||||
osThreadState_t osThreadGetState(osThreadId_t thread_id)
|
||||
{
|
||||
struct cv2_thread *tid = (struct cv2_thread *)thread_id;
|
||||
struct cmsis_rtos_thread_cb *tid = (struct cmsis_rtos_thread_cb *)thread_id;
|
||||
osThreadState_t state;
|
||||
|
||||
if (k_is_in_isr() || (tid == NULL) || (is_cmsis_rtos_v2_thread(tid) == NULL)) {
|
||||
|
@ -336,7 +337,7 @@ osStatus_t osThreadYield(void)
|
|||
*/
|
||||
uint32_t osThreadGetStackSize(osThreadId_t thread_id)
|
||||
{
|
||||
struct cv2_thread *tid = (struct cv2_thread *)thread_id;
|
||||
struct cmsis_rtos_thread_cb *tid = (struct cmsis_rtos_thread_cb *)thread_id;
|
||||
|
||||
__ASSERT(tid, "");
|
||||
__ASSERT(is_cmsis_rtos_v2_thread(tid), "");
|
||||
|
@ -351,7 +352,7 @@ uint32_t osThreadGetStackSize(osThreadId_t thread_id)
|
|||
*/
|
||||
uint32_t osThreadGetStackSpace(osThreadId_t thread_id)
|
||||
{
|
||||
struct cv2_thread *tid = (struct cv2_thread *)thread_id;
|
||||
struct cmsis_rtos_thread_cb *tid = (struct cmsis_rtos_thread_cb *)thread_id;
|
||||
size_t unused;
|
||||
int ret;
|
||||
|
||||
|
@ -372,7 +373,7 @@ uint32_t osThreadGetStackSpace(osThreadId_t thread_id)
|
|||
*/
|
||||
osStatus_t osThreadSuspend(osThreadId_t thread_id)
|
||||
{
|
||||
struct cv2_thread *tid = (struct cv2_thread *)thread_id;
|
||||
struct cmsis_rtos_thread_cb *tid = (struct cmsis_rtos_thread_cb *)thread_id;
|
||||
|
||||
if ((tid == NULL) || (is_cmsis_rtos_v2_thread(tid) == NULL)) {
|
||||
return osErrorParameter;
|
||||
|
@ -396,7 +397,7 @@ osStatus_t osThreadSuspend(osThreadId_t thread_id)
|
|||
*/
|
||||
osStatus_t osThreadResume(osThreadId_t thread_id)
|
||||
{
|
||||
struct cv2_thread *tid = (struct cv2_thread *)thread_id;
|
||||
struct cmsis_rtos_thread_cb *tid = (struct cmsis_rtos_thread_cb *)thread_id;
|
||||
|
||||
if ((tid == NULL) || (is_cmsis_rtos_v2_thread(tid) == NULL)) {
|
||||
return osErrorParameter;
|
||||
|
@ -421,7 +422,7 @@ osStatus_t osThreadResume(osThreadId_t thread_id)
|
|||
*/
|
||||
osStatus_t osThreadDetach(osThreadId_t thread_id)
|
||||
{
|
||||
struct cv2_thread *tid = (struct cv2_thread *)thread_id;
|
||||
struct cmsis_rtos_thread_cb *tid = (struct cmsis_rtos_thread_cb *)thread_id;
|
||||
|
||||
if ((tid == NULL) || (is_cmsis_rtos_v2_thread(tid) == NULL)) {
|
||||
return osErrorParameter;
|
||||
|
@ -450,7 +451,7 @@ osStatus_t osThreadDetach(osThreadId_t thread_id)
|
|||
*/
|
||||
osStatus_t osThreadJoin(osThreadId_t thread_id)
|
||||
{
|
||||
struct cv2_thread *tid = (struct cv2_thread *)thread_id;
|
||||
struct cmsis_rtos_thread_cb *tid = (struct cmsis_rtos_thread_cb *)thread_id;
|
||||
osStatus_t status = osError;
|
||||
|
||||
if ((tid == NULL) || (is_cmsis_rtos_v2_thread(tid) == NULL)) {
|
||||
|
@ -491,7 +492,7 @@ osStatus_t osThreadJoin(osThreadId_t thread_id)
|
|||
*/
|
||||
__NO_RETURN void osThreadExit(void)
|
||||
{
|
||||
struct cv2_thread *tid;
|
||||
struct cmsis_rtos_thread_cb *tid;
|
||||
|
||||
__ASSERT(!k_is_in_isr(), "");
|
||||
tid = osThreadGetId();
|
||||
|
@ -508,7 +509,7 @@ __NO_RETURN void osThreadExit(void)
|
|||
*/
|
||||
osStatus_t osThreadTerminate(osThreadId_t thread_id)
|
||||
{
|
||||
struct cv2_thread *tid = (struct cv2_thread *)thread_id;
|
||||
struct cmsis_rtos_thread_cb *tid = (struct cmsis_rtos_thread_cb *)thread_id;
|
||||
|
||||
if ((tid == NULL) || (is_cmsis_rtos_v2_thread(tid) == NULL)) {
|
||||
return osErrorParameter;
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
uint32_t osThreadFlagsSet(osThreadId_t thread_id, uint32_t flags)
|
||||
{
|
||||
unsigned int key;
|
||||
struct cv2_thread *tid = (struct cv2_thread *)thread_id;
|
||||
struct cmsis_rtos_thread_cb *tid = (struct cmsis_rtos_thread_cb *)thread_id;
|
||||
|
||||
if ((thread_id == NULL) || (is_cmsis_rtos_v2_thread(thread_id) == NULL) ||
|
||||
(flags & 0x80000000)) {
|
||||
|
@ -37,13 +37,13 @@ uint32_t osThreadFlagsSet(osThreadId_t thread_id, uint32_t flags)
|
|||
*/
|
||||
uint32_t osThreadFlagsGet(void)
|
||||
{
|
||||
struct cv2_thread *tid;
|
||||
struct cmsis_rtos_thread_cb *tid;
|
||||
|
||||
if (k_is_in_isr()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
tid = (struct cv2_thread *)osThreadGetId();
|
||||
tid = (struct cmsis_rtos_thread_cb *)osThreadGetId();
|
||||
if (tid == NULL) {
|
||||
return 0;
|
||||
} else {
|
||||
|
@ -56,7 +56,7 @@ uint32_t osThreadFlagsGet(void)
|
|||
*/
|
||||
uint32_t osThreadFlagsClear(uint32_t flags)
|
||||
{
|
||||
struct cv2_thread *tid;
|
||||
struct cmsis_rtos_thread_cb *tid;
|
||||
int sig, key;
|
||||
|
||||
if (k_is_in_isr()) {
|
||||
|
@ -67,7 +67,7 @@ uint32_t osThreadFlagsClear(uint32_t flags)
|
|||
return osFlagsErrorParameter;
|
||||
}
|
||||
|
||||
tid = (struct cv2_thread *)osThreadGetId();
|
||||
tid = (struct cmsis_rtos_thread_cb *)osThreadGetId();
|
||||
if (tid == NULL) {
|
||||
return osFlagsErrorUnknown;
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ uint32_t osThreadFlagsClear(uint32_t flags)
|
|||
*/
|
||||
uint32_t osThreadFlagsWait(uint32_t flags, uint32_t options, uint32_t timeout)
|
||||
{
|
||||
struct cv2_thread *tid;
|
||||
struct cmsis_rtos_thread_cb *tid;
|
||||
int retval, key;
|
||||
uint32_t sig;
|
||||
uint32_t time_delta_ms, timeout_ms = k_ticks_to_ms_floor64(timeout);
|
||||
|
@ -100,7 +100,7 @@ uint32_t osThreadFlagsWait(uint32_t flags, uint32_t options, uint32_t timeout)
|
|||
return osFlagsErrorParameter;
|
||||
}
|
||||
|
||||
tid = (struct cv2_thread *)osThreadGetId();
|
||||
tid = (struct cmsis_rtos_thread_cb *)osThreadGetId();
|
||||
if (tid == NULL) {
|
||||
return osFlagsErrorUnknown;
|
||||
}
|
||||
|
|
|
@ -13,7 +13,8 @@
|
|||
|
||||
static void zephyr_timer_wrapper(struct k_timer *timer);
|
||||
|
||||
K_MEM_SLAB_DEFINE(cv2_timer_slab, sizeof(struct cv2_timer), CONFIG_CMSIS_V2_TIMER_MAX_COUNT, 4);
|
||||
K_MEM_SLAB_DEFINE(cmsis_rtos_timer_cb_slab, sizeof(struct cmsis_rtos_timer_cb),
|
||||
CONFIG_CMSIS_V2_TIMER_MAX_COUNT, 4);
|
||||
|
||||
static const osTimerAttr_t init_timer_attrs = {
|
||||
.name = "ZephyrTimer",
|
||||
|
@ -24,9 +25,9 @@ static const osTimerAttr_t init_timer_attrs = {
|
|||
|
||||
static void zephyr_timer_wrapper(struct k_timer *timer)
|
||||
{
|
||||
struct cv2_timer *cm_timer;
|
||||
struct cmsis_rtos_timer_cb *cm_timer;
|
||||
|
||||
cm_timer = CONTAINER_OF(timer, struct cv2_timer, z_timer);
|
||||
cm_timer = CONTAINER_OF(timer, struct cmsis_rtos_timer_cb, z_timer);
|
||||
(cm_timer->callback_function)(cm_timer->arg);
|
||||
}
|
||||
|
||||
|
@ -36,7 +37,7 @@ static void zephyr_timer_wrapper(struct k_timer *timer)
|
|||
osTimerId_t osTimerNew(osTimerFunc_t func, osTimerType_t type, void *argument,
|
||||
const osTimerAttr_t *attr)
|
||||
{
|
||||
struct cv2_timer *timer;
|
||||
struct cmsis_rtos_timer_cb *timer;
|
||||
|
||||
if (type != osTimerOnce && type != osTimerPeriodic) {
|
||||
return NULL;
|
||||
|
@ -50,8 +51,8 @@ osTimerId_t osTimerNew(osTimerFunc_t func, osTimerType_t type, void *argument,
|
|||
attr = &init_timer_attrs;
|
||||
}
|
||||
|
||||
if (k_mem_slab_alloc(&cv2_timer_slab, (void **)&timer, K_MSEC(100)) == 0) {
|
||||
(void)memset(timer, 0, sizeof(struct cv2_timer));
|
||||
if (k_mem_slab_alloc(&cmsis_rtos_timer_cb_slab, (void **)&timer, K_MSEC(100)) == 0) {
|
||||
(void)memset(timer, 0, sizeof(struct cmsis_rtos_timer_cb));
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -77,7 +78,7 @@ osTimerId_t osTimerNew(osTimerFunc_t func, osTimerType_t type, void *argument,
|
|||
*/
|
||||
osStatus_t osTimerStart(osTimerId_t timer_id, uint32_t ticks)
|
||||
{
|
||||
struct cv2_timer *timer = (struct cv2_timer *)timer_id;
|
||||
struct cmsis_rtos_timer_cb *timer = (struct cmsis_rtos_timer_cb *)timer_id;
|
||||
|
||||
if (timer == NULL) {
|
||||
return osErrorParameter;
|
||||
|
@ -102,7 +103,7 @@ osStatus_t osTimerStart(osTimerId_t timer_id, uint32_t ticks)
|
|||
*/
|
||||
osStatus_t osTimerStop(osTimerId_t timer_id)
|
||||
{
|
||||
struct cv2_timer *timer = (struct cv2_timer *)timer_id;
|
||||
struct cmsis_rtos_timer_cb *timer = (struct cmsis_rtos_timer_cb *)timer_id;
|
||||
|
||||
if (timer == NULL) {
|
||||
return osErrorParameter;
|
||||
|
@ -126,7 +127,7 @@ osStatus_t osTimerStop(osTimerId_t timer_id)
|
|||
*/
|
||||
osStatus_t osTimerDelete(osTimerId_t timer_id)
|
||||
{
|
||||
struct cv2_timer *timer = (struct cv2_timer *)timer_id;
|
||||
struct cmsis_rtos_timer_cb *timer = (struct cmsis_rtos_timer_cb *)timer_id;
|
||||
|
||||
if (timer == NULL) {
|
||||
return osErrorParameter;
|
||||
|
@ -141,7 +142,7 @@ osStatus_t osTimerDelete(osTimerId_t timer_id)
|
|||
timer->status = NOT_ACTIVE;
|
||||
}
|
||||
|
||||
k_mem_slab_free(&cv2_timer_slab, (void *)timer);
|
||||
k_mem_slab_free(&cmsis_rtos_timer_cb_slab, (void *)timer);
|
||||
return osOK;
|
||||
}
|
||||
|
||||
|
@ -150,7 +151,7 @@ osStatus_t osTimerDelete(osTimerId_t timer_id)
|
|||
*/
|
||||
const char *osTimerGetName(osTimerId_t timer_id)
|
||||
{
|
||||
struct cv2_timer *timer = (struct cv2_timer *)timer_id;
|
||||
struct cmsis_rtos_timer_cb *timer = (struct cmsis_rtos_timer_cb *)timer_id;
|
||||
|
||||
if (k_is_in_isr() || (timer == NULL)) {
|
||||
return NULL;
|
||||
|
@ -164,7 +165,7 @@ const char *osTimerGetName(osTimerId_t timer_id)
|
|||
*/
|
||||
uint32_t osTimerIsRunning(osTimerId_t timer_id)
|
||||
{
|
||||
struct cv2_timer *timer = (struct cv2_timer *)timer_id;
|
||||
struct cmsis_rtos_timer_cb *timer = (struct cmsis_rtos_timer_cb *)timer_id;
|
||||
|
||||
if (k_is_in_isr() || (timer == NULL)) {
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue