Fork me on GitHub

随笔 - 997  文章 - 5  评论 - 181  阅读 - 300万 

一 概念

   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);
        }
复制代码

 

posted on   虚生  阅读(98)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
点击右上角即可分享
微信分享提示