P0/P1/P2功能实现:接入业务组合根(按键/LED/过零/配网/OTA),联动、11B定时、运行记录、灯泡寿命(DP3/DP4/DP25)、CBR0 VM、512分包
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
/******************************************************************************
|
||||
* @file app_defer.c
|
||||
* @brief ISR→任务上下文的延后执行标志位实现
|
||||
* @author cyWu <1917507415@qq.com>
|
||||
* @date 2026.08.31
|
||||
* @version V1.0.0,首次发布
|
||||
******************************************************************************/
|
||||
|
||||
#include "system/includes.h"
|
||||
#include "app_defer.h"
|
||||
|
||||
/** 位掩码,volatile:request() 在中断上下文写,take()/is_pending()/cancel()
|
||||
* 在任务上下文读写,两侧都用 local_irq_disable/enable 包一下读改写,
|
||||
* 避免"任务侧正在清 A 位时中断侧设 B 位"这种读改写竞态把 B 位冲丢。 */
|
||||
static volatile uint8_t s_flags;
|
||||
|
||||
void app_defer_request(AppDeferBit_t bit)
|
||||
{
|
||||
if (bit >= APP_DEFER_MAX) {
|
||||
return;
|
||||
}
|
||||
local_irq_disable();
|
||||
s_flags |= (uint8_t)(1u << bit);
|
||||
local_irq_enable();
|
||||
}
|
||||
|
||||
uint8_t app_defer_take(AppDeferBit_t bit)
|
||||
{
|
||||
uint8_t was_set;
|
||||
|
||||
if (bit >= APP_DEFER_MAX) {
|
||||
return 0;
|
||||
}
|
||||
local_irq_disable();
|
||||
was_set = (s_flags & (uint8_t)(1u << bit)) ? 1 : 0;
|
||||
s_flags &= (uint8_t)~(1u << bit);
|
||||
local_irq_enable();
|
||||
return was_set;
|
||||
}
|
||||
|
||||
uint8_t app_defer_is_pending(AppDeferBit_t bit)
|
||||
{
|
||||
if (bit >= APP_DEFER_MAX) {
|
||||
return 0;
|
||||
}
|
||||
return (s_flags & (uint8_t)(1u << bit)) ? 1 : 0;
|
||||
}
|
||||
|
||||
void app_defer_cancel(AppDeferBit_t bit)
|
||||
{
|
||||
if (bit >= APP_DEFER_MAX) {
|
||||
return;
|
||||
}
|
||||
local_irq_disable();
|
||||
s_flags &= (uint8_t)~(1u << bit);
|
||||
local_irq_enable();
|
||||
}
|
||||
Reference in New Issue
Block a user