summaryrefslogtreecommitdiff
path: root/components/CMSIS/RTOS
diff options
context:
space:
mode:
authorheyuanjie87 <[email protected]>2015-07-04 15:19:30 +0800
committerheyuanjie87 <[email protected]>2015-07-04 15:19:30 +0800
commitfa6d14ebf65a7b386f7605e80d9c6db513b7bbfe (patch)
treef0810f93d81cac9b9df5d447d027ae8973902df7 /components/CMSIS/RTOS
parent19d6c41db6804b21dab16316909ff542dec3635a (diff)
[CMSIS] 完善cmsis os接口
Diffstat (limited to 'components/CMSIS/RTOS')
-rw-r--r--components/CMSIS/RTOS/cmsis_os.h17
-rw-r--r--components/CMSIS/RTOS/cmsis_rtthread.c277
2 files changed, 174 insertions, 120 deletions
diff --git a/components/CMSIS/RTOS/cmsis_os.h b/components/CMSIS/RTOS/cmsis_os.h
index 84cd966063..d8f822847b 100644
--- a/components/CMSIS/RTOS/cmsis_os.h
+++ b/components/CMSIS/RTOS/cmsis_os.h
@@ -215,7 +215,7 @@ typedef struct rt_mailbox *osMailQId;
/// \note CAN BE CHANGED: \b os_thread_def is implementation specific in every CMSIS-RTOS.
typedef const struct os_thread_def {
const char *name;
- void (*entry)(void *parameter);
+ os_pthread entry;
rt_uint32_t stack_size;
rt_uint8_t priority;
rt_uint32_t tick;
@@ -225,7 +225,7 @@ typedef const struct os_thread_def {
/// \note CAN BE CHANGED: \b os_timer_def is implementation specific in every CMSIS-RTOS.
typedef const struct os_timer_def {
const char *name;
- void (*timeout)(void *parameter);
+ os_ptimer timeout;
void *parameter;
rt_tick_t time;
rt_uint8_t flag;
@@ -257,8 +257,8 @@ typedef const struct os_pool_def {
/// \note CAN BE CHANGED: \b os_messageQ_def is implementation specific in every CMSIS-RTOS.
typedef const struct os_messageQ_def {
const char *name;
- rt_size_t msg_size;
rt_size_t max_msgs;
+ rt_size_t msg_size;
rt_uint8_t flag;
} osMessageQDef_t;
@@ -294,7 +294,7 @@ typedef struct {
/// \param[in] argument pointer that is passed to the thread function as start argument.
/// \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 (osThreadDef_t *thread_def, void *argument);
+osStatus osKernelStart (void);
/// Check if the RTOS kernel is already started.
/// \note MUST REMAIN UNCHANGED: \b osKernelRunning shall be consistent in every CMSIS-RTOS.
@@ -498,6 +498,11 @@ osStatus osMutexWait (osMutexId mutex_id, uint32_t millisec);
/// \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 ====
@@ -560,7 +565,7 @@ extern osPoolDef_t os_pool_def_##name
#else // define the object
#define osPoolDef(name, no, type) \
osPoolDef_t os_pool_def_##name = \
-{ (no), sizeof(type), NULL }
+{"pool", (no), sizeof(type) }
#endif
/// \brief Access a Memory Pool definition.
@@ -614,7 +619,7 @@ extern osMessageQDef_t os_messageQ_def_##name
#else // define the object
#define osMessageQDef(name, queue_sz, type) \
osMessageQDef_t os_messageQ_def_##name = \
-{ (queue_sz), sizeof (type) }
+{"msg", (queue_sz), 4 }
#endif
/// \brief Access a Message Queue Definition.
diff --git a/components/CMSIS/RTOS/cmsis_rtthread.c b/components/CMSIS/RTOS/cmsis_rtthread.c
index 5789573297..d95480d892 100644
--- a/components/CMSIS/RTOS/cmsis_rtthread.c
+++ b/components/CMSIS/RTOS/cmsis_rtthread.c
@@ -3,19 +3,17 @@
// Kernel Control Public API
/// Start the RTOS Kernel with executing the specified thread
-osStatus osKernelStart(osThreadDef_t *thread_def, void *argument)
+osStatus osKernelStart(void)
{
- osThreadCreate(thread_def, argument);
+ rt_system_scheduler_start();
- rt_system_scheduler_start();
-
- return osOK;
+ return osOK;
}
/// Check if the RTOS kernel is already started
int32_t osKernelRunning(void)
{
- return (rt_thread_self() != RT_NULL) ? 1 : 0;
+ return (rt_thread_self() != RT_NULL) ? 1 : 0;
}
// Thread Public API
@@ -23,76 +21,83 @@ int32_t osKernelRunning(void)
/// Create a thread and add it to Active Threads and set it to state READY
osThreadId osThreadCreate(osThreadDef_t *thread_def, void *argument)
{
- osThreadId thread;
-
- thread = rt_thread_create(thread_def->name, thread_def->entry, argument, thread_def->stack_size, thread_def->priority, thread_def->tick);
- if (thread != RT_NULL)
- rt_thread_startup(thread);
+ osThreadId thread;
+ int size;
+
+ size = thread_def->stack_size;
+ if (size == 0)
+ {
+ size = 4096;
+ }
+
+ thread = rt_thread_create(thread_def->name, thread_def->entry, argument, size, thread_def->priority, thread_def->tick);
+ if (thread != RT_NULL)
+ rt_thread_startup(thread);
- return thread;
+ return thread;
}
/// Return the thread ID of the current running thread
osThreadId osThreadGetId(void)
{
- return rt_thread_self();
+ return rt_thread_self();
}
/// Terminate execution of a thread and remove it from ActiveThreads
osStatus osThreadTerminate(osThreadId thread_id)
{
- rt_err_t result;
+ rt_err_t result;
- result = rt_thread_delete(thread_id);
+ result = rt_thread_delete(thread_id);
- if (result == RT_EOK)
- return osOK;
- else
- return osErrorOS;
+ if (result == RT_EOK)
+ return osOK;
+ else
+ return osErrorOS;
}
/// Pass control to next thread that is in state READY
osStatus osThreadYield(void)
{
- rt_err_t result;
+ rt_err_t result;
- result = rt_thread_yield();
+ result = rt_thread_yield();
- if (result == RT_EOK)
- return osOK;
- else
- return osErrorOS;
+ if (result == RT_EOK)
+ return osOK;
+ else
+ return osErrorOS;
}
/// Change prority of an active thread
osStatus osThreadSetPriority(osThreadId thread_id, osPriority priority)
{
- rt_err_t result;
-
- if (thread_id == RT_NULL)
- return osErrorOS;
+ rt_err_t result;
+
+ if (thread_id == RT_NULL)
+ return osErrorOS;
+
+ if (priority < osPriorityIdle || priority > osPriorityRealtime)
+ return osErrorPriority;
- if (priority < osPriorityIdle || priority > osPriorityRealtime)
- return osErrorPriority;
+ result = rt_thread_control(thread_id, RT_THREAD_CTRL_CHANGE_PRIORITY, &priority);
- result = rt_thread_control(thread_id, RT_THREAD_CTRL_CHANGE_PRIORITY, &priority);
-
- if (result == RT_EOK)
- return osOK;
- else
- return osErrorOS;
+ if (result == RT_EOK)
+ return osOK;
+ else
+ return osErrorOS;
}
/// Get current prority of an active thread
osPriority osThreadGetPriority(osThreadId thread_id)
{
- if (thread_id == RT_NULL)
- return osErrorOS;
+ if (thread_id == RT_NULL)
+ return osPriorityError;
- if (thread_id->current_priority < osPriorityIdle || thread_id->current_priority > osPriorityRealtime)
- return osPriorityError;
-
- return thread_id->current_priority;
+ if ((osPriority)thread_id->current_priority < osPriorityIdle || (osPriority)thread_id->current_priority > osPriorityRealtime)
+ return osPriorityError;
+
+ return thread_id->current_priority;
}
// Generic Wait API
@@ -100,31 +105,31 @@ osPriority osThreadGetPriority(osThreadId thread_id)
/// Wait for Timeout (Time Delay)
osStatus osDelay(uint32_t millisec)
{
- rt_err_t result;
- rt_tick_t ticks;
+ rt_err_t result;
+ rt_tick_t ticks;
- ticks = rt_tick_from_millisecond(millisec);
- result = rt_thread_delay(ticks);
+ ticks = rt_tick_from_millisecond(millisec);
+ result = rt_thread_delay(ticks);
- if (result == RT_EOK)
- return osOK;
- else
- return osErrorOS;
+ if (result == RT_EOK)
+ return osOK;
+ else
+ return osErrorOS;
}
/// Wait for Signal, Message, Mail, or Timeout
osEvent osWait(uint32_t millisec)
{
- rt_err_t result;
- rt_tick_t ticks;
+ rt_err_t result;
+ rt_tick_t ticks;
- ticks = rt_tick_from_millisecond(millisec);
- result = rt_thread_delay(ticks);
+ ticks = rt_tick_from_millisecond(millisec);
+ result = rt_thread_delay(ticks);
/*
- if (result == RT_EOK)
- return osOK;
- else
- return osErrorOS;
+ if (result == RT_EOK)
+ return osOK;
+ else
+ return osErrorOS;
*/
}
@@ -133,31 +138,41 @@ osEvent osWait(uint32_t millisec)
/// Create timer
osTimerId osTimerCreate(osTimerDef_t *timer_def, os_timer_type type, void *argument)
{
- return rt_timer_create(timer_def->name, timer_def->timeout, timer_def->parameter, timer_def->time, timer_def->flag);
+ uint8_t flag = RT_TIMER_FLAG_SOFT_TIMER;
+
+ if (type == osTimerPeriodic)
+ {
+ flag |= RT_TIMER_FLAG_PERIODIC;
+ }
+
+ return rt_timer_create(timer_def->name, timer_def->timeout, argument, timer_def->time, flag);
}
/// Start or restart timer
osStatus osTimerStart(osTimerId timer_id, uint32_t millisec)
{
- rt_err_t result;
-
- result = rt_timer_start(timer_id);
- if (result == RT_EOK)
- return osOK;
- else
- return osErrorOS;
+ rt_err_t result;
+ rt_tick_t ticks;
+
+ ticks = rt_tick_from_millisecond(millisec);
+ rt_timer_control(timer_id, RT_TIMER_CTRL_SET_TIME, &ticks);
+ result = rt_timer_start(timer_id);
+ if (result == RT_EOK)
+ return osOK;
+ else
+ return osErrorOS;
}
/// Stop timer
osStatus osTimerStop(osTimerId timer_id)
{
- rt_err_t result;
-
- result = rt_timer_stop(timer_id);
- if (result == RT_EOK)
- return osOK;
- else
- return osErrorOS;
+ rt_err_t result;
+
+ result = rt_timer_stop(timer_id);
+ if (result == RT_EOK)
+ return osOK;
+ else
+ return osErrorOS;
}
// Mutex Public API
@@ -165,35 +180,47 @@ osStatus osTimerStop(osTimerId timer_id)
/// Create and Initialize a Mutex object
osMutexId osMutexCreate(osMutexDef_t *mutex_def)
{
- return rt_mutex_create(mutex_def->name, mutex_def->flag);
+ return rt_mutex_create(mutex_def->name, mutex_def->flag);
}
/// Wait until a Mutex becomes available
osStatus osMutexWait(osMutexId mutex_id, uint32_t millisec)
{
- rt_err_t result;
- rt_tick_t ticks;
+ rt_err_t result;
+ rt_tick_t ticks;
- ticks = rt_tick_from_millisecond(millisec);
- result = rt_mutex_take(mutex_id, ticks);
+ ticks = rt_tick_from_millisecond(millisec);
+ result = rt_mutex_take(mutex_id, ticks);
- if (result == RT_EOK)
- return osOK;
- else
- return osErrorOS;
+ if (result == RT_EOK)
+ return osOK;
+ else
+ return osErrorOS;
}
/// Release a Mutex that was obtained with osMutexWait
osStatus osMutexRelease(osMutexId mutex_id)
{
- rt_err_t result;
+ rt_err_t result;
- result = rt_mutex_release(mutex_id);
+ result = rt_mutex_release(mutex_id);
- if (result == RT_EOK)
- return osOK;
- else
- return osErrorOS;
+ if (result == RT_EOK)
+ return osOK;
+ else
+ return osErrorOS;
+}
+
+osStatus osMutexDelete (osMutexId mutex_id)
+{
+ rt_err_t result;
+
+ result = rt_mutex_delete(mutex_id);
+
+ if (result == RT_EOK)
+ return osOK;
+ else
+ return osErrorOS;
}
// Semaphore Public API
@@ -201,34 +228,34 @@ osStatus osMutexRelease(osMutexId mutex_id)
/// Create and Initialize a Semaphore object
osSemaphoreId osSemaphoreCreate(osSemaphoreDef_t *semaphore_def, int32_t count)
{
- return rt_sem_create(semaphore_def->name, count, semaphore_def->flag);
+ return rt_sem_create(semaphore_def->name, count, semaphore_def->flag);
}
/// Wait until a Semaphore becomes available
int32_t osSemaphoreWait(osSemaphoreId semaphore_id, uint32_t millisec)
{
- rt_tick_t ticks;
+ rt_tick_t ticks;
- if (semaphore_id == RT_NULL)
- return -1;
+ if (semaphore_id == RT_NULL)
+ return -1;
- ticks = rt_tick_from_millisecond(millisec);
- rt_sem_take(semaphore_id, ticks);
+ ticks = rt_tick_from_millisecond(millisec);
+ rt_sem_take(semaphore_id, ticks);
- return semaphore_id->value;
+ return semaphore_id->value;
}
/// Release a Semaphore
osStatus osSemaphoreRelease(osSemaphoreId semaphore_id)
{
- rt_err_t result;
+ rt_err_t result;
- result = rt_sem_release(semaphore_id);
+ result = rt_sem_release(semaphore_id);
- if (result == RT_EOK)
- return osOK;
- else
- return osErrorOS;
+ if (result == RT_EOK)
+ return osOK;
+ else
+ return osErrorOS;
}
// Memory Management Public API
@@ -236,26 +263,27 @@ osStatus osSemaphoreRelease(osSemaphoreId semaphore_id)
/// Create and Initialize memory pool
osPoolId osPoolCreate(osPoolDef_t *pool_def)
{
- return rt_mp_create(pool_def->name, pool_def->block_count, pool_def->block_size);
+ return rt_mp_create(pool_def->name, pool_def->block_count, pool_def->block_size);
}
/// Allocate a memory block from a memory pool
void *osPoolAlloc(osPoolId pool_id)
{
- return rt_mp_alloc(pool_id, 0);
+ return rt_mp_alloc(pool_id, 0);
}
/// Allocate a memory block from a memory pool and set memory block to zero
void *osPoolCAlloc(osPoolId pool_id)
{
+ return RT_NULL;
}
/// Return an allocated memory block back to a specific memory pool
osStatus osPoolFree(osPoolId pool_id, void *block)
{
- rt_mp_free(block);
+ rt_mp_free(block);
- return osOK;
+ return osOK;
}
// Message Queue Management Public API
@@ -263,26 +291,42 @@ osStatus osPoolFree(osPoolId pool_id, void *block)
/// Create and Initialize Message Queue
osMessageQId osMessageCreate(osMessageQDef_t *queue_def, osThreadId thread_id)
{
- return rt_mq_create(queue_def->name, queue_def->msg_size, queue_def->max_msgs, queue_def->flag);
+ return rt_mq_create(queue_def->name, queue_def->msg_size, queue_def->max_msgs, queue_def->flag);
}
/// Put a Message to a Queue
osStatus osMessagePut(osMessageQId queue_id, uint32_t info, uint32_t millisec)
{
- rt_err_t result;
+ rt_err_t result;
- result = rt_mq_send(queue_id, &info, 1);
+ result = rt_mq_send(queue_id, &info, 4);
- if (result == RT_EOK)
- return osOK;
- else
- return osErrorOS;
+ if (result == RT_EOK)
+ return osOK;
+ else
+ return osErrorOS;
}
/// Get a Message or Wait for a Message from a Queue
osEvent osMessageGet(osMessageQId queue_id, uint32_t millisec)
{
-
+ osEvent event;
+ rt_err_t result;
+ rt_tick_t ticks;
+
+ ticks = rt_tick_from_millisecond(millisec);
+ result = rt_mq_recv(queue_id, &event.value, 4, ticks);
+
+ if (result == RT_EOK)
+ {
+ event.status = osEventMessage;
+ }
+ else
+ {
+ event.status = osEventTimeout;
+ }
+
+ return event;
}
// Mail Queue Management Public API
@@ -290,26 +334,31 @@ osEvent osMessageGet(osMessageQId queue_id, uint32_t millisec)
/// Create and Initialize mail queue
osMailQId osMailCreate(osMailQDef_t *queue_def, osThreadId thread_id)
{
+ return RT_NULL;
}
/// Allocate a memory block from a mail
void *osMailAlloc(osMailQId queue_id, uint32_t millisec)
{
+ return RT_NULL;
}
/// Allocate a memory block from a mail and set memory block to zero
void *osMailCAlloc(osMailQId queue_id, uint32_t millisec)
{
+ return RT_NULL;
}
/// Free a memory block from a mail
osStatus osMailFree(osMailQId queue_id, void *mail)
{
+ return osErrorOS;
}
/// Put a mail to a queue
osStatus osMailPut(osMailQId queue_id, void *mail)
{
+ return osErrorOS;
}
/// Get a mail from a queue