portability: cmsis: Avoid copying objects names into control block
Instead, just store the pointer to the string provided as part of the RTOS object init attributes. Signed-off-by: Utsav Munendra <utsavm@meta.com>
This commit is contained in:
parent
e676bf3d35
commit
fd8abcff37
7 changed files with 34 additions and 55 deletions
|
@ -11,9 +11,6 @@
|
|||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/portability/cmsis_os2.h>
|
||||
|
||||
/** @brief Size for names of RTOS objects. */
|
||||
#define CMSIS_OBJ_NAME_MAX_LEN 16
|
||||
|
||||
/**
|
||||
* @brief Control block for a CMSIS-RTOSv2 thread.
|
||||
*
|
||||
|
@ -40,7 +37,7 @@ struct cmsis_rtos_timer_cb {
|
|||
osTimerType_t type;
|
||||
uint32_t status;
|
||||
bool is_cb_dynamic_allocation;
|
||||
char name[CMSIS_OBJ_NAME_MAX_LEN];
|
||||
const char *name;
|
||||
void (*callback_function)(void *argument);
|
||||
void *arg;
|
||||
};
|
||||
|
@ -54,7 +51,7 @@ struct cmsis_rtos_timer_cb {
|
|||
struct cmsis_rtos_mutex_cb {
|
||||
struct k_mutex z_mutex;
|
||||
bool is_cb_dynamic_allocation;
|
||||
char name[CMSIS_OBJ_NAME_MAX_LEN];
|
||||
const char *name;
|
||||
uint32_t state;
|
||||
};
|
||||
|
||||
|
@ -67,7 +64,7 @@ struct cmsis_rtos_mutex_cb {
|
|||
struct cmsis_rtos_semaphore_cb {
|
||||
struct k_sem z_semaphore;
|
||||
bool is_cb_dynamic_allocation;
|
||||
char name[CMSIS_OBJ_NAME_MAX_LEN];
|
||||
const char *name;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -81,7 +78,7 @@ struct cmsis_rtos_mempool_cb {
|
|||
void *pool;
|
||||
char is_dynamic_allocation;
|
||||
bool is_cb_dynamic_allocation;
|
||||
char name[CMSIS_OBJ_NAME_MAX_LEN];
|
||||
const char *name;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -95,7 +92,7 @@ struct cmsis_rtos_msgq_cb {
|
|||
void *pool;
|
||||
char is_dynamic_allocation;
|
||||
bool is_cb_dynamic_allocation;
|
||||
char name[CMSIS_OBJ_NAME_MAX_LEN];
|
||||
const char *name;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -109,7 +106,7 @@ struct cmsis_rtos_event_cb {
|
|||
struct k_poll_event poll_event;
|
||||
uint32_t signal_results;
|
||||
bool is_cb_dynamic_allocation;
|
||||
char name[CMSIS_OBJ_NAME_MAX_LEN];
|
||||
const char *name;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -50,11 +50,7 @@ osEventFlagsId_t osEventFlagsNew(const osEventFlagsAttr_t *attr)
|
|||
&events->poll_signal);
|
||||
events->signal_results = 0U;
|
||||
|
||||
if (attr->name == NULL) {
|
||||
strncpy(events->name, init_event_flags_attrs.name, sizeof(events->name) - 1);
|
||||
} else {
|
||||
strncpy(events->name, attr->name, sizeof(events->name) - 1);
|
||||
}
|
||||
events->name = (attr->name == NULL) ? init_event_flags_attrs.name : attr->name;
|
||||
|
||||
return (osEventFlagsId_t)events;
|
||||
}
|
||||
|
@ -207,16 +203,16 @@ uint32_t osEventFlagsWait(osEventFlagsId_t ef_id, uint32_t flags, uint32_t optio
|
|||
|
||||
/**
|
||||
* @brief Get name of an Event Flags object.
|
||||
* This function may be called from Interrupt Service Routines.
|
||||
*/
|
||||
const char *osEventFlagsGetName(osEventFlagsId_t 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;
|
||||
} else {
|
||||
if (events == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return events->name;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -84,11 +84,7 @@ osMemoryPoolId_t osMemoryPoolNew(uint32_t block_count, uint32_t block_size,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (attr->name == NULL) {
|
||||
strncpy(mslab->name, init_mslab_attrs.name, sizeof(mslab->name) - 1);
|
||||
} else {
|
||||
strncpy(mslab->name, attr->name, sizeof(mslab->name) - 1);
|
||||
}
|
||||
mslab->name = (attr->name == NULL) ? init_mslab_attrs.name : attr->name;
|
||||
|
||||
return (osMemoryPoolId_t)mslab;
|
||||
}
|
||||
|
@ -152,16 +148,16 @@ osStatus_t osMemoryPoolFree(osMemoryPoolId_t mp_id, void *block)
|
|||
|
||||
/**
|
||||
* @brief Get name of a Memory Pool object.
|
||||
* This function may be called from Interrupt Service Routines.
|
||||
*/
|
||||
const char *osMemoryPoolGetName(osMemoryPoolId_t 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;
|
||||
} else {
|
||||
if (mslab == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return mslab->name;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -79,11 +79,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);
|
||||
} else {
|
||||
strncpy(msgq->name, attr->name, sizeof(msgq->name) - 1);
|
||||
}
|
||||
msgq->name = (attr->name == NULL) ? init_msgq_attrs.name : attr->name;
|
||||
|
||||
return (osMessageQueueId_t)(msgq);
|
||||
}
|
||||
|
@ -222,16 +218,16 @@ uint32_t osMessageQueueGetSpace(osMessageQueueId_t msgq_id)
|
|||
|
||||
/**
|
||||
* @brief Get name of a Message Queue object.
|
||||
* This function may be called from Interrupt Service Routines.
|
||||
*/
|
||||
const char *osMessageQueueGetName(osMessageQueueId_t 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;
|
||||
} else {
|
||||
if (msgq == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return msgq->name;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -51,11 +51,7 @@ osMutexId_t osMutexNew(const osMutexAttr_t *attr)
|
|||
k_mutex_init(&mutex->z_mutex);
|
||||
mutex->state = attr->attr_bits;
|
||||
|
||||
if (attr->name == NULL) {
|
||||
strncpy(mutex->name, init_mutex_attrs.name, sizeof(mutex->name) - 1);
|
||||
} else {
|
||||
strncpy(mutex->name, attr->name, sizeof(mutex->name) - 1);
|
||||
}
|
||||
mutex->name = (attr->name == NULL) ? init_mutex_attrs.name : attr->name;
|
||||
|
||||
return (osMutexId_t)mutex;
|
||||
}
|
||||
|
@ -156,13 +152,16 @@ osThreadId_t osMutexGetOwner(osMutexId_t mutex_id)
|
|||
return get_cmsis_thread_id(mutex->z_mutex.owner);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get name of a mutex.
|
||||
* This function may be called from Interrupt Service Routines.
|
||||
*/
|
||||
const char *osMutexGetName(osMutexId_t mutex_id)
|
||||
{
|
||||
struct cmsis_rtos_mutex_cb *mutex = (struct cmsis_rtos_mutex_cb *)mutex_id;
|
||||
|
||||
if (k_is_in_isr() || (mutex == NULL)) {
|
||||
if (mutex == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return mutex->name;
|
||||
}
|
||||
|
|
|
@ -47,11 +47,7 @@ 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);
|
||||
} else {
|
||||
strncpy(semaphore->name, attr->name, sizeof(semaphore->name) - 1);
|
||||
}
|
||||
semaphore->name = (attr->name == NULL) ? init_sema_attrs.name : attr->name;
|
||||
|
||||
return (osSemaphoreId_t)semaphore;
|
||||
}
|
||||
|
@ -148,13 +144,16 @@ osStatus_t osSemaphoreDelete(osSemaphoreId_t semaphore_id)
|
|||
return osOK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get name of a semaphore.
|
||||
* This function may be called from Interrupt Service Routines.
|
||||
*/
|
||||
const char *osSemaphoreGetName(osSemaphoreId_t 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;
|
||||
} else {
|
||||
if (semaphore == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return semaphore->name;
|
||||
}
|
||||
|
|
|
@ -67,11 +67,7 @@ osTimerId_t osTimerNew(osTimerFunc_t func, osTimerType_t type, void *argument,
|
|||
|
||||
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);
|
||||
} else {
|
||||
strncpy(timer->name, attr->name, sizeof(timer->name) - 1);
|
||||
}
|
||||
timer->name = (attr->name == NULL) ? init_timer_attrs.name : attr->name;
|
||||
|
||||
return (osTimerId_t)timer;
|
||||
}
|
||||
|
@ -153,15 +149,15 @@ osStatus_t osTimerDelete(osTimerId_t timer_id)
|
|||
|
||||
/**
|
||||
* @brief Get name of a timer.
|
||||
* This function may be called from Interrupt Service Routines.
|
||||
*/
|
||||
const char *osTimerGetName(osTimerId_t timer_id)
|
||||
{
|
||||
struct cmsis_rtos_timer_cb *timer = (struct cmsis_rtos_timer_cb *)timer_id;
|
||||
|
||||
if (k_is_in_isr() || (timer == NULL)) {
|
||||
if (timer == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return timer->name;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue