zoukankan      html  css  js  c++  java
  • NRF52832的FDS程序,参考非蓝牙例程修改而来(需要增加DFU的基础上只要增加如下程序即可解决)

    /* Dummy configuration data. */
    static configuration_t m_dummy_cfg =
    {
        .config1_on  = false,
        .config2_on  = true,
        .boot_count  = 0x0,
        .device_name = "dummy",
    };
    
    /* A record containing dummy configuration data. */
    static fds_record_t const m_dummy_record =
    {
        .file_id           = CONFIG_FILE,
        .key               = CONFIG_REC_KEY,
        .data.p_data       = &ucheck_v,//&m_dummy_cfg,
        /* The length of a record is always expressed in 4-byte units (words). */
        .data.length_words = (sizeof(ucheck_v) + 3) / sizeof(uint32_t),
    };
    
    /* Keep track of the progress of a delete_all operation. */
    //static struct
    //{
    //    bool delete_next;   //!< Delete next record.
    //    bool pending;       //!< Waiting for an fds FDS_EVT_DEL_RECORD event, to delete the next record.
    //} m_delete_all;
    
    void user_data_update(void)
    {
        ret_code_t rc;
    
    //    NRF_LOG_INFO("Reading flash usage statistics...");
    
        fds_stat_t stat = {0};
    
        rc = fds_stat(&stat);
        APP_ERROR_CHECK(rc);
    
        NRF_LOG_INFO("Found %d valid records.", stat.valid_records);
        NRF_LOG_INFO("Found %d dirty records (ready to be garbage collected).", stat.dirty_records);
    
        fds_record_desc_t desc = {0};
        fds_find_token_t  tok    = {0};
    
        rc = fds_record_find(CONFIG_FILE, CONFIG_REC_KEY, &desc, &tok);
    
        if (rc == FDS_SUCCESS)
        {
        /* A config file is in flash. Let's update it. */
            fds_flash_record_t config = {0};
    
            /* Open the record and read its contents. */
            rc = fds_record_open(&desc, &config);
            APP_ERROR_CHECK(rc);
    
            /* Copy the configuration from flash into m_dummy_cfg. */
            //memcpy(&ucheck_v, config.p_data, sizeof(check_V));//这里是更新数据,所以不能把旧数据复制过来了
    
            NRF_LOG_INFO("Config file found, updating boot count to %d.", ucheck_v.boot_count);
    
            /* Update boot count. */
            ucheck_v.boot_count++;
    
            /* Close the record when done reading. */
            rc = fds_record_close(&desc);
            APP_ERROR_CHECK(rc);
    
            /* Write the updated record to flash. */
            rc = fds_record_update(&desc, &m_dummy_record);
            APP_ERROR_CHECK(rc);
        }
        else
        {
        /* System config not found; write a new one. */
            NRF_LOG_INFO("Writing config file...");
    
            rc = fds_record_write(&desc, &m_dummy_record);
            APP_ERROR_CHECK(rc);
        }
    
        //cli_start();
    }
    void user_init_data_flash(void)
    {
        ret_code_t rc;
        fds_record_desc_t desc = {0};
        fds_find_token_t  tok    = {0};
    
        rc = fds_record_find(CONFIG_FILE, CONFIG_REC_KEY, &desc, &tok);
    
        if (rc == FDS_SUCCESS)
        {
        /* A config file is in flash. Let's update it. */
            fds_flash_record_t config = {0};
    
            /* Open the record and read its contents. */
            rc = fds_record_open(&desc, &config);
            APP_ERROR_CHECK(rc);
    
            /* Copy the configuration from flash into m_dummy_cfg. */
            memcpy(&ucheck_v, config.p_data, sizeof(check_V));
    
            NRF_LOG_INFO("Config file found, updating boot count to %d.", ucheck_v.boot_count);
    
            /* Update boot count. */
            ucheck_v.boot_count++;
    
            /* Close the record when done reading. */
            rc = fds_record_close(&desc);
            APP_ERROR_CHECK(rc);
    
            /* Write the updated record to flash. */
            rc = fds_record_update(&desc, &m_dummy_record);
            APP_ERROR_CHECK(rc);
        }
    
    }

    在增加了DFU之后的52832程序,只要增加如下程序就可以完成FDS的数据保存

    经验再多也只能看作加法,而经过理论升华的经验,就可以看作乘法!
  • 相关阅读:
    Vue监听器、过滤器
    Vue生命周期、计算属性
    数组去重
    ES6总结
    学习笔记--html篇(1)
    学习整理--flex布局(1)
    对块作用域与变量函数提升再添新认识
    了解使用web workers
    js中的事件循环模型与特殊的定时器
    操作系统、浏览器与js之间的一些概念与联系
  • 原文地址:https://www.cnblogs.com/TorryLong/p/13640188.html
Copyright © 2011-2022 走看看