portability: cmsis: Run clang-format on CMSIS-RTOSv2

clang-format -i subsys/portability/cmsis_rtos_v2/*.h
clang-format -i subsys/portability/cmsis_rtos_v2/*.c

Signed-off-by: Utsav Munendra <utsavm@meta.com>
This commit is contained in:
Utsav Munendra 2025-02-13 10:33:21 +05:30 committed by Benjamin Cabé
commit 6d490e9cf0
10 changed files with 85 additions and 135 deletions

View file

@ -18,7 +18,7 @@ static const osEventFlagsAttr_t init_event_flags_attrs = {
.cb_size = 0,
};
#define DONT_CARE (0)
#define DONT_CARE (0)
/**
* @brief Create and Initialize an Event Flags object.
@ -35,21 +35,19 @@ 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) {
if (k_mem_slab_alloc(&cv2_event_flags_slab, (void **)&events, K_MSEC(100)) == 0) {
memset(events, 0, sizeof(struct cv2_event_flags));
} else {
return NULL;
}
k_poll_signal_init(&events->poll_signal);
k_poll_event_init(&events->poll_event, K_POLL_TYPE_SIGNAL,
K_POLL_MODE_NOTIFY_ONLY, &events->poll_signal);
k_poll_event_init(&events->poll_event, K_POLL_TYPE_SIGNAL, K_POLL_MODE_NOTIFY_ONLY,
&events->poll_signal);
events->signal_results = 0U;
if (attr->name == NULL) {
strncpy(events->name, init_event_flags_attrs.name,
sizeof(events->name) - 1);
strncpy(events->name, init_event_flags_attrs.name, sizeof(events->name) - 1);
} else {
strncpy(events->name, attr->name, sizeof(events->name) - 1);
}
@ -102,8 +100,8 @@ uint32_t osEventFlagsClear(osEventFlagsId_t ef_id, uint32_t flags)
/**
* @brief Wait for one or more Event Flags to become signaled.
*/
uint32_t osEventFlagsWait(osEventFlagsId_t ef_id, uint32_t flags,
uint32_t options, uint32_t timeout)
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;
int retval, key;
@ -173,12 +171,11 @@ uint32_t osEventFlagsWait(osEventFlagsId_t ef_id, uint32_t flags,
* adjust the timeout value accordingly based on
* the time that has already elapsed.
*/
ticks_elapsed =
(uint64_t)k_uptime_ticks() - time_stamp_start;
ticks_elapsed = (uint64_t)k_uptime_ticks() - time_stamp_start;
if (ticks_elapsed < (uint64_t)timeout) {
poll_timeout = Z_TIMEOUT_TICKS((k_ticks_t)(
timeout - (uint32_t)ticks_elapsed));
poll_timeout = Z_TIMEOUT_TICKS(
(k_ticks_t)(timeout - (uint32_t)ticks_elapsed));
} else {
return osFlagsErrorTimeout;
}
@ -198,8 +195,7 @@ uint32_t osEventFlagsWait(osEventFlagsId_t ef_id, uint32_t flags,
*/
__ASSERT(events->poll_event.state == K_POLL_STATE_SIGNALED,
"event state not signalled!");
__ASSERT(events->poll_event.signal->signaled == 1U,
"event signaled is not 1");
__ASSERT(events->poll_event.signal->signaled == 1U, "event signaled is not 1");
}
return sig;

View file

@ -24,8 +24,7 @@ osStatus_t osKernelGetInfo(osVersion_t *version, char *id_buf, uint32_t id_size)
}
if ((id_buf != NULL) && (version != NULL)) {
snprintf(id_buf, id_size,
"Zephyr V%2"PRIu32".%2"PRIu32".%2"PRIu32,
snprintf(id_buf, id_size, "Zephyr V%2" PRIu32 ".%2" PRIu32 ".%2" PRIu32,
SYS_KERNEL_VER_MAJOR(version->kernel),
SYS_KERNEL_VER_MINOR(version->kernel),
SYS_KERNEL_VER_PATCHLEVEL(version->kernel));
@ -78,9 +77,9 @@ int32_t osKernelRestoreLock(int32_t lock)
}
if (lock < 0) {
return 1; /* locked */
return 1; /* locked */
} else {
return 0; /* not locked */
return 0; /* not locked */
}
}

View file

@ -8,10 +8,9 @@
#include <string.h>
#include "wrapper.h"
#define TIME_OUT_TICKS 10
#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 cv2_mslab), CONFIG_CMSIS_V2_MEM_SLAB_MAX_COUNT, 4);
static const osMemoryPoolAttr_t init_mslab_attrs = {
.name = "ZephyrMemPool",
@ -30,8 +29,7 @@ osMemoryPoolId_t osMemoryPoolNew(uint32_t block_count, uint32_t block_size,
{
struct cv2_mslab *mslab;
BUILD_ASSERT(K_HEAP_MEM_POOL_SIZE >=
CONFIG_CMSIS_V2_MEM_SLAB_MAX_DYNAMIC_SIZE,
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");
if (k_is_in_isr()) {
@ -53,8 +51,7 @@ osMemoryPoolId_t osMemoryPoolNew(uint32_t block_count, uint32_t block_size,
}
if (attr->mp_mem == NULL) {
__ASSERT((block_count * block_size) <=
CONFIG_CMSIS_V2_MEM_SLAB_MAX_DYNAMIC_SIZE,
__ASSERT((block_count * block_size) <= CONFIG_CMSIS_V2_MEM_SLAB_MAX_DYNAMIC_SIZE,
"memory slab/pool size exceeds dynamic maximum");
mslab->pool = k_calloc(block_count, block_size);
@ -79,8 +76,7 @@ osMemoryPoolId_t osMemoryPoolNew(uint32_t block_count, uint32_t block_size,
}
if (attr->name == NULL) {
strncpy(mslab->name, init_mslab_attrs.name,
sizeof(mslab->name) - 1);
strncpy(mslab->name, init_mslab_attrs.name, sizeof(mslab->name) - 1);
} else {
strncpy(mslab->name, attr->name, sizeof(mslab->name) - 1);
}
@ -107,17 +103,14 @@ void *osMemoryPoolAlloc(osMemoryPoolId_t mp_id, uint32_t timeout)
}
if (timeout == 0U) {
retval = k_mem_slab_alloc(
(struct k_mem_slab *)(&mslab->z_mslab),
(void **)&ptr, K_NO_WAIT);
retval = k_mem_slab_alloc((struct k_mem_slab *)(&mslab->z_mslab), (void **)&ptr,
K_NO_WAIT);
} else if (timeout == osWaitForever) {
retval = k_mem_slab_alloc(
(struct k_mem_slab *)(&mslab->z_mslab),
(void **)&ptr, K_FOREVER);
retval = k_mem_slab_alloc((struct k_mem_slab *)(&mslab->z_mslab), (void **)&ptr,
K_FOREVER);
} else {
retval = k_mem_slab_alloc(
(struct k_mem_slab *)(&mslab->z_mslab),
(void **)&ptr, K_TICKS(timeout));
retval = k_mem_slab_alloc((struct k_mem_slab *)(&mslab->z_mslab), (void **)&ptr,
K_TICKS(timeout));
}
if (retval == 0) {

View file

@ -8,8 +8,7 @@
#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(cv2_msgq_slab, sizeof(struct cv2_msgq), CONFIG_CMSIS_V2_MSGQ_MAX_COUNT, 4);
static const osMessageQueueAttr_t init_msgq_attrs = {
.name = "ZephyrMsgQ",
@ -28,8 +27,7 @@ osMessageQueueId_t osMessageQueueNew(uint32_t msg_count, uint32_t msg_size,
{
struct cv2_msgq *msgq;
BUILD_ASSERT(K_HEAP_MEM_POOL_SIZE >=
CONFIG_CMSIS_V2_MSGQ_MAX_DYNAMIC_SIZE,
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");
if (k_is_in_isr()) {
@ -51,8 +49,7 @@ osMessageQueueId_t osMessageQueueNew(uint32_t msg_count, uint32_t msg_size,
}
if (attr->mq_mem == NULL) {
__ASSERT((msg_count * msg_size) <=
CONFIG_CMSIS_V2_MSGQ_MAX_DYNAMIC_SIZE,
__ASSERT((msg_count * msg_size) <= CONFIG_CMSIS_V2_MSGQ_MAX_DYNAMIC_SIZE,
"message queue size exceeds dynamic maximum");
#if (K_HEAP_MEM_POOL_SIZE > 0)
@ -74,8 +71,7 @@ osMessageQueueId_t osMessageQueueNew(uint32_t msg_count, uint32_t msg_size,
k_msgq_init(&msgq->z_msgq, msgq->pool, msg_size, msg_count);
if (attr->name == NULL) {
strncpy(msgq->name, init_msgq_attrs.name,
sizeof(msgq->name) - 1);
strncpy(msgq->name, init_msgq_attrs.name, sizeof(msgq->name) - 1);
} else {
strncpy(msgq->name, attr->name, sizeof(msgq->name) - 1);
}
@ -86,8 +82,8 @@ osMessageQueueId_t osMessageQueueNew(uint32_t msg_count, uint32_t msg_size,
/**
* @brief Put a message to a Queue.
*/
osStatus_t osMessageQueuePut(osMessageQueueId_t msgq_id, const void *msg_ptr,
uint8_t msg_prio, uint32_t timeout)
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;
int retval;
@ -108,8 +104,7 @@ osStatus_t osMessageQueuePut(osMessageQueueId_t msgq_id, const void *msg_ptr,
} else if (timeout == osWaitForever) {
retval = k_msgq_put(&msgq->z_msgq, (void *)msg_ptr, K_FOREVER);
} else {
retval = k_msgq_put(&msgq->z_msgq, (void *)msg_ptr,
K_TICKS(timeout));
retval = k_msgq_put(&msgq->z_msgq, (void *)msg_ptr, K_TICKS(timeout));
}
if (retval == 0) {
@ -124,8 +119,8 @@ osStatus_t osMessageQueuePut(osMessageQueueId_t msgq_id, const void *msg_ptr,
/**
* @brief Get a message or Wait for a Message from a Queue.
*/
osStatus_t osMessageQueueGet(osMessageQueueId_t msgq_id, void *msg_ptr,
uint8_t *msg_prio, uint32_t timeout)
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;
int retval;
@ -146,8 +141,7 @@ osStatus_t osMessageQueueGet(osMessageQueueId_t msgq_id, void *msg_ptr,
} else if (timeout == osWaitForever) {
retval = k_msgq_get(&msgq->z_msgq, msg_ptr, K_FOREVER);
} else {
retval = k_msgq_get(&msgq->z_msgq, msg_ptr,
K_TICKS(timeout));
retval = k_msgq_get(&msgq->z_msgq, msg_ptr, K_TICKS(timeout));
}
if (retval == 0) {

View file

@ -8,8 +8,7 @@
#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(cv2_mutex_slab, sizeof(struct cv2_mutex), CONFIG_CMSIS_V2_MUTEX_MAX_COUNT, 4);
static const osMutexAttr_t init_mutex_attrs = {
.name = "ZephyrMutex",
@ -36,8 +35,7 @@ osMutexId_t osMutexNew(const osMutexAttr_t *attr)
__ASSERT(attr->attr_bits & osMutexPrioInherit,
"Zephyr supports osMutexPrioInherit by default. Do not unselect it\n");
__ASSERT(!(attr->attr_bits & osMutexRobust),
"Zephyr does not support osMutexRobust.\n");
__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));
@ -49,8 +47,7 @@ osMutexId_t osMutexNew(const osMutexAttr_t *attr)
mutex->state = attr->attr_bits;
if (attr->name == NULL) {
strncpy(mutex->name, init_mutex_attrs.name,
sizeof(mutex->name) - 1);
strncpy(mutex->name, init_mutex_attrs.name, sizeof(mutex->name) - 1);
} else {
strncpy(mutex->name, attr->name, sizeof(mutex->name) - 1);
}
@ -63,7 +60,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 cv2_mutex *mutex = (struct cv2_mutex *)mutex_id;
int status;
if (mutex_id == NULL) {
@ -79,8 +76,7 @@ osStatus_t osMutexAcquire(osMutexId_t mutex_id, uint32_t timeout)
} else if (timeout == 0U) {
status = k_mutex_lock(&mutex->z_mutex, K_NO_WAIT);
} else {
status = k_mutex_lock(&mutex->z_mutex,
K_TICKS(timeout));
status = k_mutex_lock(&mutex->z_mutex, K_TICKS(timeout));
}
if (timeout != 0 && (status == -EAGAIN || status == -EBUSY)) {
@ -97,7 +93,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 cv2_mutex *mutex = (struct cv2_mutex *)mutex_id;
if (mutex_id == NULL) {
return osErrorParameter;
@ -138,7 +134,6 @@ osStatus_t osMutexDelete(osMutexId_t mutex_id)
return osOK;
}
osThreadId_t osMutexGetOwner(osMutexId_t mutex_id)
{
struct cv2_mutex *mutex = (struct cv2_mutex *)mutex_id;

View file

@ -8,8 +8,8 @@
#include <string.h>
#include "wrapper.h"
K_MEM_SLAB_DEFINE(cv2_semaphore_slab, sizeof(struct cv2_sem),
CONFIG_CMSIS_V2_SEMAPHORE_MAX_COUNT, 4);
K_MEM_SLAB_DEFINE(cv2_semaphore_slab, sizeof(struct cv2_sem), CONFIG_CMSIS_V2_SEMAPHORE_MAX_COUNT,
4);
static const osSemaphoreAttr_t init_sema_attrs = {
.name = "ZephyrSem",
@ -34,8 +34,7 @@ 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) {
if (k_mem_slab_alloc(&cv2_semaphore_slab, (void **)&semaphore, K_MSEC(100)) == 0) {
(void)memset(semaphore, 0, sizeof(struct cv2_sem));
} else {
return NULL;
@ -44,11 +43,9 @@ osSemaphoreId_t osSemaphoreNew(uint32_t max_count, uint32_t initial_count,
k_sem_init(&semaphore->z_semaphore, initial_count, max_count);
if (attr->name == NULL) {
strncpy(semaphore->name, init_sema_attrs.name,
sizeof(semaphore->name) - 1);
strncpy(semaphore->name, init_sema_attrs.name, sizeof(semaphore->name) - 1);
} else {
strncpy(semaphore->name, attr->name,
sizeof(semaphore->name) - 1);
strncpy(semaphore->name, attr->name, sizeof(semaphore->name) - 1);
}
return (osSemaphoreId_t)semaphore;
@ -59,7 +56,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 cv2_sem *semaphore = (struct cv2_sem *)semaphore_id;
int status;
if (semaphore_id == NULL) {
@ -76,8 +73,7 @@ osStatus_t osSemaphoreAcquire(osSemaphoreId_t semaphore_id, uint32_t timeout)
} else if (timeout == 0U) {
status = k_sem_take(&semaphore->z_semaphore, K_NO_WAIT);
} else {
status = k_sem_take(&semaphore->z_semaphore,
K_TICKS(timeout));
status = k_sem_take(&semaphore->z_semaphore, K_TICKS(timeout));
}
if (status == -EBUSY) {
@ -105,15 +101,14 @@ uint32_t osSemaphoreGetCount(osSemaphoreId_t semaphore_id)
*/
osStatus_t osSemaphoreRelease(osSemaphoreId_t semaphore_id)
{
struct cv2_sem *semaphore = (struct cv2_sem *) semaphore_id;
struct cv2_sem *semaphore = (struct cv2_sem *)semaphore_id;
if (semaphore_id == NULL) {
return osErrorParameter;
}
/* All tokens have already been released */
if (k_sem_count_get(&semaphore->z_semaphore) ==
semaphore->z_semaphore.limit) {
if (k_sem_count_get(&semaphore->z_semaphore) == semaphore->z_semaphore.limit) {
return osErrorResource;
}

View file

@ -30,8 +30,7 @@ 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(cv2_thread_stack_pool, CONFIG_CMSIS_V2_THREAD_DYNAMIC_MAX_COUNT,
CONFIG_CMSIS_V2_THREAD_DYNAMIC_STACK_SIZE);
#endif
@ -55,7 +54,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;
void * (*fun_ptr)(void *) = arg3;
void *(*fun_ptr)(void *) = arg3;
fun_ptr(arg1);
@ -100,8 +99,7 @@ osThreadId_t get_cmsis_thread_id(k_tid_t tid)
/**
* @brief Create a thread and add it to Active Threads.
*/
osThreadId_t osThreadNew(osThreadFunc_t threadfunc, void *arg,
const osThreadAttr_t *attr)
osThreadId_t osThreadNew(osThreadFunc_t threadfunc, void *arg, const osThreadAttr_t *attr)
{
int32_t prio;
osPriority_t cv2_prio;
@ -129,27 +127,24 @@ osThreadId_t osThreadNew(osThreadFunc_t threadfunc, void *arg,
cv2_prio = attr->priority;
}
if ((attr->stack_mem == NULL) && (thread_num_dynamic >=
CONFIG_CMSIS_V2_THREAD_DYNAMIC_MAX_COUNT)) {
if ((attr->stack_mem == NULL) &&
(thread_num_dynamic >= CONFIG_CMSIS_V2_THREAD_DYNAMIC_MAX_COUNT)) {
return NULL;
}
BUILD_ASSERT(osPriorityISR <= CONFIG_NUM_PREEMPT_PRIORITIES,
"Configure NUM_PREEMPT_PRIORITIES to at least osPriorityISR");
BUILD_ASSERT(CONFIG_CMSIS_V2_THREAD_DYNAMIC_MAX_COUNT <=
CONFIG_CMSIS_V2_THREAD_MAX_COUNT,
BUILD_ASSERT(CONFIG_CMSIS_V2_THREAD_DYNAMIC_MAX_COUNT <= CONFIG_CMSIS_V2_THREAD_MAX_COUNT,
"Number of dynamic threads cannot exceed max number of threads.");
BUILD_ASSERT(CONFIG_CMSIS_V2_THREAD_DYNAMIC_STACK_SIZE <=
CONFIG_CMSIS_V2_THREAD_MAX_STACK_SIZE,
CONFIG_CMSIS_V2_THREAD_MAX_STACK_SIZE,
"Default dynamic thread stack size cannot exceed max stack size");
__ASSERT(attr->stack_size <= CONFIG_CMSIS_V2_THREAD_MAX_STACK_SIZE,
"invalid stack size\n");
__ASSERT(attr->stack_size <= CONFIG_CMSIS_V2_THREAD_MAX_STACK_SIZE, "invalid stack size\n");
__ASSERT((cv2_prio >= osPriorityIdle) && (cv2_prio <= osPriorityISR),
"invalid priority\n");
__ASSERT((cv2_prio >= osPriorityIdle) && (cv2_prio <= osPriorityISR), "invalid priority\n");
if (attr->stack_mem != NULL) {
if (attr->stack_size == 0) {
@ -169,8 +164,7 @@ osThreadId_t osThreadNew(osThreadFunc_t threadfunc, void *arg,
uint32_t this_thread_num_dynamic;
__ASSERT(CONFIG_CMSIS_V2_THREAD_DYNAMIC_STACK_SIZE > 0,
"dynamic stack size must be configured to be non-zero\n");
this_thread_num_dynamic =
atomic_inc((atomic_t *)&thread_num_dynamic);
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];
} else
@ -181,8 +175,8 @@ osThreadId_t osThreadNew(osThreadFunc_t threadfunc, void *arg,
}
k_poll_signal_init(&tid->poll_signal);
k_poll_event_init(&tid->poll_event, K_POLL_TYPE_SIGNAL,
K_POLL_MODE_NOTIFY_ONLY, &tid->poll_signal);
k_poll_event_init(&tid->poll_event, K_POLL_TYPE_SIGNAL, K_POLL_MODE_NOTIFY_ONLY,
&tid->poll_signal);
tid->signal_results = 0U;
/* TODO: Do this somewhere only once */
@ -196,15 +190,11 @@ osThreadId_t osThreadNew(osThreadFunc_t threadfunc, void *arg,
k_sem_init(&tid->join_guard, 0, 1);
tid->has_joined = FALSE;
(void)k_thread_create(&tid->z_thread,
stack, stack_size,
zephyr_thread_wrapper,
(void *)arg, tid, threadfunc,
prio, 0, K_NO_WAIT);
(void)k_thread_create(&tid->z_thread, stack, stack_size, zephyr_thread_wrapper, (void *)arg,
tid, threadfunc, prio, 0, K_NO_WAIT);
if (attr->name == NULL) {
strncpy(tid->name, init_thread_attrs.name,
sizeof(tid->name) - 1);
strncpy(tid->name, init_thread_attrs.name, sizeof(tid->name) - 1);
} else {
strncpy(tid->name, attr->name, sizeof(tid->name) - 1);
}
@ -227,8 +217,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 cv2_thread *tid = (struct cv2_thread *)thread_id;
name = k_thread_name_get(&tid->z_thread);
}
@ -255,8 +244,7 @@ osPriority_t osThreadGetPriority(osThreadId_t thread_id)
struct cv2_thread *tid = (struct cv2_thread *)thread_id;
uint32_t priority;
if (k_is_in_isr() || (tid == NULL) ||
(is_cmsis_rtos_v2_thread(tid) == NULL) ||
if (k_is_in_isr() || (tid == NULL) || (is_cmsis_rtos_v2_thread(tid) == NULL) ||
(_is_thread_cmsis_inactive(&tid->z_thread))) {
return osPriorityError;
}
@ -285,8 +273,7 @@ osStatus_t osThreadSetPriority(osThreadId_t thread_id, osPriority_t priority)
return osErrorResource;
}
k_thread_priority_set((k_tid_t)&tid->z_thread,
cmsis_to_zephyr_priority(priority));
k_thread_priority_set((k_tid_t)&tid->z_thread, cmsis_to_zephyr_priority(priority));
return osOK;
}
@ -299,8 +286,7 @@ osThreadState_t osThreadGetState(osThreadId_t thread_id)
struct cv2_thread *tid = (struct cv2_thread *)thread_id;
osThreadState_t state;
if (k_is_in_isr() || (tid == NULL) ||
(is_cmsis_rtos_v2_thread(tid) == NULL)) {
if (k_is_in_isr() || (tid == NULL) || (is_cmsis_rtos_v2_thread(tid) == NULL)) {
return osThreadError;
}
@ -541,7 +527,6 @@ osStatus_t osThreadTerminate(osThreadId_t thread_id)
return osOK;
}
/**
* @brief Get number of active threads.
*/

View file

@ -7,7 +7,7 @@
#include <zephyr/kernel_structs.h>
#include "wrapper.h"
#define DONT_CARE (0)
#define DONT_CARE (0)
/**
* @brief Set the specified Thread Flags of a thread.
@ -17,8 +17,8 @@ uint32_t osThreadFlagsSet(osThreadId_t thread_id, uint32_t flags)
unsigned int key;
struct cv2_thread *tid = (struct cv2_thread *)thread_id;
if ((thread_id == NULL) || (is_cmsis_rtos_v2_thread(thread_id) == NULL)
|| (flags & 0x80000000)) {
if ((thread_id == NULL) || (is_cmsis_rtos_v2_thread(thread_id) == NULL) ||
(flags & 0x80000000)) {
return osFlagsErrorParameter;
}
@ -116,8 +116,7 @@ uint32_t osThreadFlagsWait(uint32_t flags, uint32_t options, uint32_t timeout)
retval = k_poll(&tid->poll_event, 1, K_FOREVER);
break;
default:
retval = k_poll(&tid->poll_event, 1,
K_MSEC(timeout_ms));
retval = k_poll(&tid->poll_event, 1, K_MSEC(timeout_ms));
break;
}
@ -132,8 +131,7 @@ uint32_t osThreadFlagsWait(uint32_t flags, uint32_t options, uint32_t timeout)
__ASSERT(tid->poll_event.state == K_POLL_STATE_SIGNALED,
"event state not signalled!");
__ASSERT(tid->poll_event.signal->signaled == 1U,
"event signaled is not 1");
__ASSERT(tid->poll_event.signal->signaled == 1U, "event signaled is not 1");
/* Reset the states to facilitate the next trigger */
tid->poll_event.signal->signaled = 0U;
@ -151,11 +149,9 @@ uint32_t osThreadFlagsWait(uint32_t flags, uint32_t options, uint32_t timeout)
* adjust the timeout value accordingly based on
* the time that has already elapsed.
*/
hwclk_cycles_delta =
(uint64_t)k_cycle_get_32() - time_stamp_start;
hwclk_cycles_delta = (uint64_t)k_cycle_get_32() - time_stamp_start;
time_delta_ns =
(uint32_t)k_cyc_to_ns_floor64(hwclk_cycles_delta);
time_delta_ns = (uint32_t)k_cyc_to_ns_floor64(hwclk_cycles_delta);
time_delta_ms = (uint32_t)time_delta_ns / NSEC_PER_MSEC;

View file

@ -8,13 +8,12 @@
#include <string.h>
#include "wrapper.h"
#define ACTIVE 1
#define ACTIVE 1
#define NOT_ACTIVE 0
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(cv2_timer_slab, sizeof(struct cv2_timer), CONFIG_CMSIS_V2_TIMER_MAX_COUNT, 4);
static const osTimerAttr_t init_timer_attrs = {
.name = "ZephyrTimer",
@ -34,8 +33,8 @@ static void zephyr_timer_wrapper(struct k_timer *timer)
/**
* @brief Create a Timer
*/
osTimerId_t osTimerNew(osTimerFunc_t func, osTimerType_t type,
void *argument, const osTimerAttr_t *attr)
osTimerId_t osTimerNew(osTimerFunc_t func, osTimerType_t type, void *argument,
const osTimerAttr_t *attr)
{
struct cv2_timer *timer;
@ -65,8 +64,7 @@ osTimerId_t osTimerNew(osTimerFunc_t func, osTimerType_t type,
k_timer_init(&timer->z_timer, zephyr_timer_wrapper, NULL);
if (attr->name == NULL) {
strncpy(timer->name, init_timer_attrs.name,
sizeof(timer->name) - 1);
strncpy(timer->name, init_timer_attrs.name, sizeof(timer->name) - 1);
} else {
strncpy(timer->name, attr->name, sizeof(timer->name) - 1);
}
@ -92,8 +90,7 @@ osStatus_t osTimerStart(osTimerId_t timer_id, uint32_t ticks)
if (timer->type == osTimerOnce) {
k_timer_start(&timer->z_timer, K_TICKS(ticks), K_NO_WAIT);
} else if (timer->type == osTimerPeriodic) {
k_timer_start(&timer->z_timer,
K_TICKS(ticks), K_TICKS(ticks));
k_timer_start(&timer->z_timer, K_TICKS(ticks), K_TICKS(ticks));
}
timer->status = ACTIVE;
@ -129,7 +126,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 cv2_timer *timer = (struct cv2_timer *)timer_id;
if (timer == NULL) {
return osErrorParameter;

View file

@ -11,10 +11,10 @@
#include <cmsis_os2.h>
#ifndef TRUE
#define TRUE 1
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#define FALSE 0
#endif
struct cv2_thread {