一 概念
fatfs文件系统在文件读写中不可或却。熟悉和深入理解是一个不可或缺的前提。
这里面需要先明确几个概念:文件open的属性,这个非常重要。可以并列使用。
二 源码解析
A 写入数据:
if((false == g_lora_state) && (Mybuffer.Data_Length( &My_ADS1299_buffer)>= ADS_DATA_SIZE)) { Mybuffer.Get( &My_ADS1299_buffer, TF_Buffer_ADS1299, ADS_DATA_SIZE); //memset(TF_Buffer_ADS1299,0x11,TF_Buffer_ADS1299_Size); //dump8(TF_Buffer_ADS1299,10); FRESULT res = f_write( &ADS1299_file, TF_Buffer_ADS1299 , TF_Buffer_ADS1299_Size, &bw); if(res == FR_OK) { ads_data_cnt++; //f_sync(&ADS1299_file); if(ads_data_cnt%1 == 0) { mprintf("date 4.10 ads data wirte success cnt:%d \n\r",ads_data_cnt); } } else { data_failed_cnt++; mprintf("ads task write data failed:%d failed cnt:%d \n\r",res,data_failed_cnt); } }
B 读取的文件打开
g_lora_state = true; f_close(&ADS1299_file); res=f_open(&ADS1299_file, ADS1299_filename, FA_READ); mprintf("file sd enter and open file state is:%d \n\r",res);
C 文件读取
FRESULT res = f_read( &ADS1299_file, TF_Buffer_ADS1299 , TF_Buffer_ADS1299_Size, &bw); mprintf("file read state is:%d \n\r",res); if(bw < 1) { mprintf("file read over \n\r"); g_lora_state = false; seq_num = 0; f_close(&ADS1299_file); res=f_open(&ADS1299_file, ADS1299_filename, FA_OPEN_ALWAYS | FA_WRITE); mprintf("file save and open file state is:%d \n\r",res); } else { dump8(TF_Buffer_ADS1299,20); }
作者:虚生 出处:https://www.cnblogs.com/dylancao/ 以音频和传感器算法为核心的智能可穿戴产品解决方案提供商 ,提供可穿戴智能软硬件解决方案的设计,开发和咨询服务。 勾搭热线:邮箱:1173496664@qq.com weixin:18019245820 市场技术对接群:347609188 |
![]() |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战