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的数据保存

    经验再多也只能看作加法,而经过理论升华的经验,就可以看作乘法!
  • 相关阅读:
    Minimum configuration for openldap to proxy multiple AD into a single search base
    排列组合算法(PHP)
    Make Notepad++ auto close HTML/XML tags after the slash(the Dreamweaver way)
    PHP, LDAPS and Apache
    【day1】tensorflow版本问题及初步使用
    tflearn save模型异常
    布隆过滤器(Bloom Filter)
    初识Spark(Spark系列)
    Hadoop实践
    install postgis(2.0) on ubuntu(12.04)
  • 原文地址:https://www.cnblogs.com/TorryLong/p/13640188.html
Copyright © 2011-2022 走看看