Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
tools-mirror
Micropython
提交
aa18ab7d
M
Micropython
项目概览
tools-mirror
/
Micropython
12 个月 前同步成功
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
Micropython
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
aa18ab7d
编写于
8月 14, 2020
作者:
J
Jim Mussared
提交者:
Damien George
9月 08, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
extmod/nimble: Implement NimBLE mutex.
上级
f3f31ac9
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
46 addition
and
4 deletion
+46
-4
extmod/nimble/nimble/nimble_npl_os.c
extmod/nimble/nimble/nimble_npl_os.c
+45
-4
extmod/nimble/nimble/nimble_npl_os.h
extmod/nimble/nimble/nimble_npl_os.h
+1
-0
未找到文件。
extmod/nimble/nimble/nimble_npl_os.c
浏览文件 @
aa18ab7d
...
...
@@ -249,21 +249,62 @@ void ble_npl_event_set_arg(struct ble_npl_event *ev, void *arg) {
/******************************************************************************/
// MUTEX
// This is what MICROPY_BEGIN_ATOMIC_SECTION returns on Unix (i.e. we don't
// need to preserve the atomic state to unlock).
#define ATOMIC_STATE_MUTEX_NOT_HELD 0xffffffff
ble_npl_error_t
ble_npl_mutex_init
(
struct
ble_npl_mutex
*
mu
)
{
DEBUG_MUTEX_printf
(
"ble_npl_mutex_init(%p)
\n
"
,
mu
);
mu
->
locked
=
0
;
mu
->
atomic_state
=
ATOMIC_STATE_MUTEX_NOT_HELD
;
return
BLE_NPL_OK
;
}
ble_npl_error_t
ble_npl_mutex_pend
(
struct
ble_npl_mutex
*
mu
,
ble_npl_time_t
timeout
)
{
DEBUG_MUTEX_printf
(
"ble_npl_mutex_pend(%p, %u) locked=%u
\n
"
,
mu
,
(
uint
)
timeout
,
(
uint
)
mu
->
locked
);
mu
->
locked
=
1
;
DEBUG_MUTEX_printf
(
"ble_npl_mutex_pend(%p, %u) locked=%u irq=%d
\n
"
,
mu
,
(
uint
)
timeout
,
(
uint
)
mu
->
locked
);
// This is a recursive mutex which we implement on top of the IRQ priority
// scheme. Unfortunately we have a single piece of global storage, where
// enter/exit critical needs an "atomic state".
// There are two different acquirers, either running in a VM thread (i.e.
// a direct Python call into NimBLE), or in the NimBLE task (i.e. polling
// or UART RX).
// On STM32 the NimBLE task runs in PENDSV, so cannot be interrupted by a VM thread.
// Therefore we only need to ensure that a VM thread that acquires a currently-unlocked mutex
// now raises the priority (thus preventing context switches to other VM threads and
// the PENDSV irq). If the mutex is already locked, then it must have been acquired
// by us.
// On Unix, the critical section is completely recursive and doesn't require us to manage
// state so we just acquire and release every time.
// TODO: The "volatile" on locked/atomic_state isn't enough to protect against memory re-ordering.
// First acquirer of this mutex always enters the critical section, unless
// we're on Unix where it happens every time.
if
(
mu
->
atomic_state
==
ATOMIC_STATE_MUTEX_NOT_HELD
)
{
mu
->
atomic_state
=
mp_bluetooth_nimble_hci_uart_enter_critical
();
}
++
mu
->
locked
;
return
BLE_NPL_OK
;
}
ble_npl_error_t
ble_npl_mutex_release
(
struct
ble_npl_mutex
*
mu
)
{
DEBUG_MUTEX_printf
(
"ble_npl_mutex_release(%p) locked=%u
\n
"
,
mu
,
(
uint
)
mu
->
locked
);
mu
->
locked
=
0
;
DEBUG_MUTEX_printf
(
"ble_npl_mutex_release(%p) locked=%u irq=%d
\n
"
,
mu
,
(
uint
)
mu
->
locked
);
assert
(
mu
->
locked
>
0
);
--
mu
->
locked
;
// Only exit the critical section for the final release, unless we're on Unix.
if
(
mu
->
locked
==
0
||
mu
->
atomic_state
==
ATOMIC_STATE_MUTEX_NOT_HELD
)
{
mp_bluetooth_nimble_hci_uart_exit_critical
(
mu
->
atomic_state
);
mu
->
atomic_state
=
ATOMIC_STATE_MUTEX_NOT_HELD
;
}
return
BLE_NPL_OK
;
}
...
...
extmod/nimble/nimble/nimble_npl_os.h
浏览文件 @
aa18ab7d
...
...
@@ -61,6 +61,7 @@ struct ble_npl_callout {
struct
ble_npl_mutex
{
volatile
uint8_t
locked
;
volatile
uint32_t
atomic_state
;
};
struct
ble_npl_sem
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录