Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
nix61
rt-thread
提交
fa6d14eb
R
rt-thread
项目概览
nix61
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
fa6d14eb
编写于
7月 04, 2015
作者:
H
heyuanjie87
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[CMSIS] 完善cmsis os接口
上级
19d6c41d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
174 addition
and
120 deletion
+174
-120
components/CMSIS/RTOS/cmsis_os.h
components/CMSIS/RTOS/cmsis_os.h
+11
-6
components/CMSIS/RTOS/cmsis_rtthread.c
components/CMSIS/RTOS/cmsis_rtthread.c
+163
-114
未找到文件。
components/CMSIS/RTOS/cmsis_os.h
浏览文件 @
fa6d14eb
...
...
@@ -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.
...
...
components/CMSIS/RTOS/cmsis_rtthread.c
浏览文件 @
fa6d14eb
...
...
@@ -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
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录