前言
泰凌微BLE在建立连接后,需要周期性的来完成一个收发包事件(Brx Event),在SDK中该事件通过中断来触发。在部分应用中,如擦写片上flash(MSPI)禁用中断时间较长(100ms)可能会造成连接断开,需要通过时序保护来操作
如有异议,请评论指正
Conn stste Slave role时序保护
API接口
接口对外声明在ll_slave.h
头文件中
int bls_ll_requestConnBrxEventDisable(void);
- 请求申请关闭BrxEvent;
- 返回0表示解决申请,需要等待BrxEvent事件结束后重新申请,
- 返回非零,返回表示允许停止BrxEvent的时间(ms)
- 返回0xFFFF,表示不存在BrxEvent(当前未建立连接,AdvState IdelState),无需保护
- 当前为conn state且收到了update map或update connection parameter更新请求但还未更新时间点,返回时间为更新时间点减去当前时间
- 当前为Conn state没有收到master请求,返回为当前connection supervison timeout超时断开时间值的一半
void bls_ll_disableConnBrxEvent(void);
- 停止BrxEvent事件,在申请成功后调用
void bls_ll_restoreConnBrxEvent(void);
- 恢复BrxEvent事件,必须在申请时间段内调用
代码示例
8258片上的flash擦除需要消耗30~100ms的时间,可根据自己的应用来裁定;
bool flash_protect_erase(unsigned long addr)
{
uint32_t time_ms = bls_ll_requestConnBrxEventDisable();//请求禁用brxEvent
if(time_ms > 100)
{
bls_ll_disableConnBrxEvent();//禁用brxEvent
flash_erase_sector (addr);
bls_ll_restoreConnBrxEvent();//恢复brxEvent
return true;
}
return false;
}
总结
在建立连接后,需要考虑时序保护;
时序保护时,一定要评估临界代码的时间,不能超过请求保护的时间要求,如果时间确实较长,可以考虑修改最大连接超时时间或者拆解多个子任务执行