armink / EasyFlash

Lightweight IoT device information storage solution: KV/IAP/LOG. | 轻量级物联网设备信息存储方案:参数存储、在线升级及日志存储 ,全新一代版本请移步至 https://github.com/armink/FlashDB
MIT License
1.99k stars 759 forks source link

请问Flash读写会不会有被中断打断的隐患 #141

Open heluozhijian opened 2 years ago

heluozhijian commented 2 years ago

当有RTOS的情况下,lock和unlock通过信号量实现,请问会不会存在“flash_write”的时候被中断打断的隐患?

/**
 * lock the ENV ram cache
 */
void ef_port_env_lock(void) {
    rt_sem_take(&env_cache_lock, RT_WAITING_FOREVER);
}

/**
 * unlock the ENV ram cache
 */
void ef_port_env_unlock(void) {
    rt_sem_release(&env_cache_lock);
}
armink commented 2 years ago

如果你写 flash 时候中断是开的,肯定有这个可能

heluozhijian commented 2 years ago

嗯,实际应用的时候一般都有中断,这里的信号量估计得用开关中断,或者进入临界区来保护

armink commented 2 years ago

为什么呢?你要在中断里使用 EasyFlash ?

heluozhijian commented 2 years ago

那倒不是,我的意思在普通的任务中使用EasyFlash,那么EasyFlash在写入数据的时候,会不会被串口接收中断、脉冲捕获中断之类的干扰了?不是在中断服务函数里使用EasyFlash。

heluozhijian commented 2 years ago

lock和unlock之间的代码会被别的中断打断吗

armink commented 2 years ago

lock 目的就是为了锁住上下文,如果你中断中不使用 EasyFlash 那就没事的

heluozhijian commented 2 years ago

好的,谢谢你的回复和工作成果。准备在GD32+FreeRTOS项目中使用EasyFlash。

armink commented 2 years ago

可以试试 RT-Thread + EasyFlash ,有现成的 demo https://github.com/armink/EasyFlash/tree/master/demo/env/stm32f4xx,还有软件包https://packages.rt-thread.org/detail.html?package=EasyFlash

heluozhijian commented 2 years ago

好的