Merge pull request #512 from heyuanjie87/ForPullRequest

[CMSIS] 完善cmsis os接口
This commit is contained in:
Bernard Xiong 2015-07-05 08:34:02 +08:00
commit 9f84e429ef
2 changed files with 174 additions and 120 deletions

View File

@ -215,7 +215,7 @@ typedef struct rt_mailbox *osMailQId;
/// \note CAN BE CHANGED: \b os_thread_def is implementation specific in every CMSIS-RTOS. /// \note CAN BE CHANGED: \b os_thread_def is implementation specific in every CMSIS-RTOS.
typedef const struct os_thread_def { typedef const struct os_thread_def {
const char *name; const char *name;
void (*entry)(void *parameter); os_pthread entry;
rt_uint32_t stack_size; rt_uint32_t stack_size;
rt_uint8_t priority; rt_uint8_t priority;
rt_uint32_t tick; 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. /// \note CAN BE CHANGED: \b os_timer_def is implementation specific in every CMSIS-RTOS.
typedef const struct os_timer_def { typedef const struct os_timer_def {
const char *name; const char *name;
void (*timeout)(void *parameter); os_ptimer timeout;
void *parameter; void *parameter;
rt_tick_t time; rt_tick_t time;
rt_uint8_t flag; 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. /// \note CAN BE CHANGED: \b os_messageQ_def is implementation specific in every CMSIS-RTOS.
typedef const struct os_messageQ_def { typedef const struct os_messageQ_def {
const char *name; const char *name;
rt_size_t msg_size;
rt_size_t max_msgs; rt_size_t max_msgs;
rt_size_t msg_size;
rt_uint8_t flag; rt_uint8_t flag;
} osMessageQDef_t; } osMessageQDef_t;
@ -294,7 +294,7 @@ typedef struct {
/// \param[in] argument pointer that is passed to the thread function as start argument. /// \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. /// \return status code that indicates the execution status of the function.
/// \note MUST REMAIN UNCHANGED: \b osKernelStart shall be consistent in every CMSIS-RTOS. /// \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. /// Check if the RTOS kernel is already started.
/// \note MUST REMAIN UNCHANGED: \b osKernelRunning shall be consistent in every CMSIS-RTOS. /// \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. /// \note MUST REMAIN UNCHANGED: \b osMutexRelease shall be consistent in every CMSIS-RTOS.
osStatus osMutexRelease (osMutexId mutex_id); 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 ==== // ==== Semaphore Management Functions ====
@ -560,7 +565,7 @@ extern osPoolDef_t os_pool_def_##name
#else // define the object #else // define the object
#define osPoolDef(name, no, type) \ #define osPoolDef(name, no, type) \
osPoolDef_t os_pool_def_##name = \ osPoolDef_t os_pool_def_##name = \
{ (no), sizeof(type), NULL } {"pool", (no), sizeof(type) }
#endif #endif
/// \brief Access a Memory Pool definition. /// \brief Access a Memory Pool definition.
@ -614,7 +619,7 @@ extern osMessageQDef_t os_messageQ_def_##name
#else // define the object #else // define the object
#define osMessageQDef(name, queue_sz, type) \ #define osMessageQDef(name, queue_sz, type) \
osMessageQDef_t os_messageQ_def_##name = \ osMessageQDef_t os_messageQ_def_##name = \
{ (queue_sz), sizeof (type) } {"msg", (queue_sz), 4 }
#endif #endif
/// \brief Access a Message Queue Definition. /// \brief Access a Message Queue Definition.

View File

@ -3,10 +3,8 @@
// Kernel Control Public API // Kernel Control Public API
/// Start the RTOS Kernel with executing the specified thread /// 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;
@ -24,8 +22,15 @@ int32_t osKernelRunning(void)
osThreadId osThreadCreate(osThreadDef_t *thread_def, void *argument) osThreadId osThreadCreate(osThreadDef_t *thread_def, void *argument)
{ {
osThreadId thread; osThreadId thread;
int size;
thread = rt_thread_create(thread_def->name, thread_def->entry, argument, thread_def->stack_size, thread_def->priority, thread_def->tick); 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) if (thread != RT_NULL)
rt_thread_startup(thread); rt_thread_startup(thread);
@ -87,9 +92,9 @@ osStatus osThreadSetPriority(osThreadId thread_id, osPriority priority)
osPriority osThreadGetPriority(osThreadId thread_id) osPriority osThreadGetPriority(osThreadId thread_id)
{ {
if (thread_id == RT_NULL) if (thread_id == RT_NULL)
return osErrorOS; return osPriorityError;
if (thread_id->current_priority < osPriorityIdle || thread_id->current_priority > osPriorityRealtime) if ((osPriority)thread_id->current_priority < osPriorityIdle || (osPriority)thread_id->current_priority > osPriorityRealtime)
return osPriorityError; return osPriorityError;
return thread_id->current_priority; return thread_id->current_priority;
@ -133,14 +138,24 @@ osEvent osWait(uint32_t millisec)
/// Create timer /// Create timer
osTimerId osTimerCreate(osTimerDef_t *timer_def, os_timer_type type, void *argument) 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 /// Start or restart timer
osStatus osTimerStart(osTimerId timer_id, uint32_t millisec) osStatus osTimerStart(osTimerId timer_id, uint32_t millisec)
{ {
rt_err_t result; 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); result = rt_timer_start(timer_id);
if (result == RT_EOK) if (result == RT_EOK)
return osOK; return osOK;
@ -196,6 +211,18 @@ osStatus osMutexRelease(osMutexId mutex_id)
return osErrorOS; 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 // Semaphore Public API
/// Create and Initialize a Semaphore object /// Create and Initialize a Semaphore object
@ -248,6 +275,7 @@ void *osPoolAlloc(osPoolId pool_id)
/// Allocate a memory block from a memory pool and set memory block to zero /// Allocate a memory block from a memory pool and set memory block to zero
void *osPoolCAlloc(osPoolId pool_id) void *osPoolCAlloc(osPoolId pool_id)
{ {
return RT_NULL;
} }
/// Return an allocated memory block back to a specific memory pool /// Return an allocated memory block back to a specific memory pool
@ -271,7 +299,7 @@ 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) if (result == RT_EOK)
return osOK; return osOK;
@ -282,7 +310,23 @@ osStatus osMessagePut(osMessageQId queue_id, uint32_t info, uint32_t millisec)
/// Get a Message or Wait for a Message from a Queue /// Get a Message or Wait for a Message from a Queue
osEvent osMessageGet(osMessageQId queue_id, uint32_t millisec) 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 // Mail Queue Management Public API
@ -290,26 +334,31 @@ osEvent osMessageGet(osMessageQId queue_id, uint32_t millisec)
/// Create and Initialize mail queue /// Create and Initialize mail queue
osMailQId osMailCreate(osMailQDef_t *queue_def, osThreadId thread_id) osMailQId osMailCreate(osMailQDef_t *queue_def, osThreadId thread_id)
{ {
return RT_NULL;
} }
/// Allocate a memory block from a mail /// Allocate a memory block from a mail
void *osMailAlloc(osMailQId queue_id, uint32_t millisec) void *osMailAlloc(osMailQId queue_id, uint32_t millisec)
{ {
return RT_NULL;
} }
/// Allocate a memory block from a mail and set memory block to zero /// Allocate a memory block from a mail and set memory block to zero
void *osMailCAlloc(osMailQId queue_id, uint32_t millisec) void *osMailCAlloc(osMailQId queue_id, uint32_t millisec)
{ {
return RT_NULL;
} }
/// Free a memory block from a mail /// Free a memory block from a mail
osStatus osMailFree(osMailQId queue_id, void *mail) osStatus osMailFree(osMailQId queue_id, void *mail)
{ {
return osErrorOS;
} }
/// Put a mail to a queue /// Put a mail to a queue
osStatus osMailPut(osMailQId queue_id, void *mail) osStatus osMailPut(osMailQId queue_id, void *mail)
{ {
return osErrorOS;
} }
/// Get a mail from a queue /// Get a mail from a queue