This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

FDS after Init show ok,but always waitting for ready

Hi,

I  want to add FDS basedon  dimming_serve example ,However,after fds_init(); it  not jump to fds_evt_handler but stop wait .

The below is my code:

static void initialize(void)
{
    __LOG_INIT(LOG_SRC_APP | LOG_SRC_ACCESS | LOG_SRC_BEARER, LOG_LEVEL_INFO, LOG_CALLBACK_DEFAULT);
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "----- BLE Mesh Dimming Server Demo -----\n");

    ERROR_CHECK(app_timer_init());
    hal_leds_init();

    ble_stack_init();

#if MESH_FEATURE_GATT_ENABLED
    gap_params_init();
    conn_params_init();
#endif

    //mesh_init();

    uint32_t status = app_pwm_init(&PWM0, &m_pwm0_config, NULL);
    APP_ERROR_CHECK(status);
    m_pwm0_max = app_pwm_cycle_ticks_get(&PWM0);
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "PWM max ticks: %d\n", m_pwm0_max);

    #if 1
    //FDS
    /* Register first to receive an event when initialization is complete. */
    status=fds_register(fds_evt_handler);//(void) fds_register(fds_evt_handler);
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Status fds register is : %d\n",status);

    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Initializing fds...\n");

    status=fds_init();
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Status fds init is : %d\n",status);
    APP_ERROR_CHECK(status);

    /* Wait for fds to initialize. */
    wait_for_fds_ready();
    #if 0
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Available commands:\n");
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "- print all\t\tprint records\n");
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "- print config\tprint configuration\n");
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "- update\t\tupdate configuration\n");
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "- stat\t\tshow statistics\n");
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "- write\t\twrite a new record\n");
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "- delete\t\tdelete a record\n");
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "- delete_all\tdelete all records\n");
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "- gc\t\trun garbage collection\n");
    #endif

    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Reading flash usage statistics...\n");

    fds_stat_t stat = {0};

    status = fds_stat(&stat);
    APP_ERROR_CHECK(status);

    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Found %d valid records.\n", stat.valid_records);
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Found %d dirty records (ready to be garbage collected).\n", stat.dirty_records);

    fds_record_desc_t desc = {0};
    fds_find_token_t  tok  = {0};

    status = fds_record_find(CONFIG_FILE, CONFIG_REC_KEY, &desc, &tok);

    if (status == 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. */
        status = fds_record_open(&desc, &config);
        APP_ERROR_CHECK(status);

        /* Copy the configuration from flash into m_dummy_cfg. */
        memcpy(&m_dummy_cfg, config.p_data, sizeof(configuration_t));

        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Config file found, updating boot count to %d\n", m_dummy_cfg.boot_count);

        /* Update boot count. */
        m_dummy_cfg.boot_count++;

        /* Close the record when done reading. */
        status = fds_record_close(&desc);
        APP_ERROR_CHECK(status);

        /* Write the updated record to flash. */
        status = fds_record_update(&desc, &m_dummy_record);
        APP_ERROR_CHECK(status);
    }
    else
    {
        /* System config not found; write a new one. */
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Writing config file...\n");

        status = fds_record_write(&desc, &m_dummy_record);
        APP_ERROR_CHECK(status);
    }

   #endif
}

And The Bellow is Log:

<t: 0>, main.c, 558, ----- BLE Mesh Dimming Server Demo -----
<t: 17925>, ble_softdevice_support.c, 124, RAM Start is 0x20002DA0
<t: 17945>, main.c, 575, PWM max ticks: 1600
<t: 17948>, main.c, 581, Status fds register is : 0
<t: 17950>, main.c, 583, Initializing fds...

How To solve this ? TKS in anvance.

Best Regards

Panda

  • Hi Hung,

        A good news,I use SES Version  4.16a to rebuild the project,then erase and program  ,It does work OK now.I think this is where the problem exist.Thanks for your help all the time.

    Best Regards,

    Panda

  • Good to hear that it works now. I'm not sure why SES v3.12 didn't work, might be that it doesn't support Section or has the flash/section configuration slightly different. 

  • Hi Hung,

         I have met FDS (FDS_ERR_OPERATION_TIMEOUT) and even not working issues. I erase all and program.First few time it works well, however when after happening  DS_ERR_OPERATION_TIMEOUT, the FDS function not work . 

         The fllowing is

     //=====================    below: OK =============================//
    0> <t:    2287078>, access.c,  942, RX opcode =[FFFF8206]
     0> <t:    2287080>, access.c,  943, msg length =[0005]
     0> <t:    2287083>, access.c,  944, msg rx: : 0A00011414
     0> <t:    2287085>, access.c,  952, element index =[0]
     0> <t:    2287088>, access.c, 1015, In coming is OK ! 
     0> <t:    2287090>, generic_level_server.c,  101, Opcode Jumper to Level handl_set !
     0> <t:    2287093>, app_level.c,  498, Level SET: Level: 10  delay: 100  tt: 2000  req-delta: 10 
     0> <t:    2287098>, access.c,  284, appkey_handle is 65535 
     0> <t:    2287100>, access.c,  285, address_handle  is 0 
     0> <t:    2287103>, access.c,  402, Source address: 9 Target Address: 4
     0> <t:    2287106>, access.c,  407, sensor msg tx: : 00000A0014
     0> <t:    2287115>, access.c,  972, is_opcode_of_model true
     0> <t:    2287117>, access.c,  983, address_match false
     0> <t:    2287119>, access.c,  988, bitfield_get true
     0> <t:    2287121>, access.c,  995, ACCESS_INTERNAL_STATE_IS_ALLOCATED true
     0> <t:    2290375>, app_level.c,  280, Selecting interval for one step change
     0> <t:    2290378>, app_level.c,  284, timeout_rtc_ticks: 6554 ticks
     0> <t:    2296935>, app_level.c,  303, delta= 10
     0> <t:    2296937>, app_level.c,  313, One Level cb happen !
     0> <t:    2296939>, app_level.c,  314, Present Level: 0
     0> <t:    2296942>, app_level.c,  316, ELAPSED_TIME: 0 ,Transition Time: 0
     0> <t:    2296945>, main.c,  268, m_pwm0_present_level is:     0
     0> <t:    2296947>, main.c,  291, Pwm value:    0
     0> <t:    2303504>, app_level.c,  303, delta= 10
     0> <t:    2303506>, app_level.c,  313, One Level cb happen !
     0> <t:    2303508>, app_level.c,  314, Present Level: 1
     0> <t:    2303511>, app_level.c,  316, ELAPSED_TIME: 1 ,Transition Time: 200
     0> <t:    2303514>, main.c,  268, m_pwm0_present_level is:     1
     0> <t:    2303517>, main.c,  291, Pwm value:  100
     0> <t:    2310073>, app_level.c,  303, delta= 10
     0> <t:    2310075>, app_level.c,  313, One Level cb happen !
     0> <t:    2310077>, app_level.c,  314, Present Level: 2
     0> <t:    2310080>, app_level.c,  316, ELAPSED_TIME: 2 ,Transition Time: 400
     0> <t:    2310083>, main.c,  268, m_pwm0_present_level is:     2
     0> <t:    2310086>, main.c,  291, Pwm value:  200
     0> <t:    2316642>, app_level.c,  303, delta= 10
     0> <t:    2316644>, app_level.c,  313, One Level cb happen !
     0> <t:    2316646>, app_level.c,  314, Present Level: 3
     0> <t:    2316649>, app_level.c,  316, ELAPSED_TIME: 3 ,Transition Time: 601
     0> <t:    2316652>, main.c,  268, m_pwm0_present_level is:     3
     0> <t:    2316655>, main.c,  291, Pwm value:  300
     0> <t:    2323211>, app_level.c,  303, delta= 10
     0> <t:    2323214>, app_level.c,  313, One Level cb happen !
     0> <t:    2323216>, app_level.c,  314, Present Level: 4
     0> <t:    2323218>, app_level.c,  316, ELAPSED_TIME: 4 ,Transition Time: 801
     0> <t:    2323221>, main.c,  268, m_pwm0_present_level is:     4
     0> <t:    2323224>, main.c,  291, Pwm value:  400
     0> <t:    2329781>, app_level.c,  303, delta= 10
     0> <t:    2329783>, app_level.c,  313, One Level cb happen !
     0> <t:    2329785>, app_level.c,  314, Present Level: 5
     0> <t:    2329788>, app_level.c,  316, ELAPSED_TIME: 5 ,Transition Time: 1002
     0> <t:    2329791>, main.c,  268, m_pwm0_present_level is:     5
     0> <t:    2329794>, main.c,  291, Pwm value:  500
     0> <t:    2336350>, app_level.c,  303, delta= 10
     0> <t:    2336352>, app_level.c,  313, One Level cb happen !
     0> <t:    2336355>, app_level.c,  314, Present Level: 6
     0> <t:    2336357>, app_level.c,  316, ELAPSED_TIME: 6 ,Transition Time: 1202
     0> <t:    2336360>, main.c,  268, m_pwm0_present_level is:     6
     0> <t:    2336363>, main.c,  291, Pwm value:  600
     0> <t:    2342919>, app_level.c,  303, delta= 10
     0> <t:    2342921>, app_level.c,  313, One Level cb happen !
     0> <t:    2342923>, app_level.c,  314, Present Level: 7
     0> <t:    2342926>, app_level.c,  316, ELAPSED_TIME: 7 ,Transition Time: 1403
     0> <t:    2342929>, main.c,  268, m_pwm0_present_level is:     7
     0> <t:    2342932>, main.c,  291, Pwm value:  700
     0> <t:    2349488>, app_level.c,  303, delta= 10
     0> <t:    2349490>, app_level.c,  313, One Level cb happen !
     0> <t:    2349493>, app_level.c,  314, Present Level: 8
     0> <t:    2349495>, app_level.c,  316, ELAPSED_TIME: 8 ,Transition Time: 1603
     0> <t:    2349498>, main.c,  268, m_pwm0_present_level is:     8
     0> <t:    2349501>, main.c,  291, Pwm value:  800
     0> <t:    2356057>, app_level.c,  303, delta= 10
     0> <t:    2356059>, app_level.c,  313, One Level cb happen !
     0> <t:    2356061>, app_level.c,  314, Present Level: 9
     0> <t:    2356064>, app_level.c,  316, ELAPSED_TIME: 9 ,Transition Time: 1804
     0> <t:    2356067>, main.c,  268, m_pwm0_present_level is:     9
     0> <t:    2356070>, main.c,  291, Pwm value:  900
     0> <t:    2362626>, access.c,  284, appkey_handle is 65535 
     0> <t:    2362629>, access.c,  285, address_handle  is 0 
     0> <t:    2362631>, main.c,  268, m_pwm0_present_level is:    10
     0> <t:    2362634>, main.c,  291, Pwm value: 1000
     0> <t:    2362636>, app_level.c,  337, Level_transition_complete:    10
     0> <t:    2362639>, app_level.c,  340, pwm_value is 10 ,Flag is 1
     0> <t:    2362642>, user.c,  586, Is Coming to FDS!
     0> <t:    2362644>, user.c,  591, Element 0, value is 10!
     0> <t:    2362647>, user.c,  428, delete_next: 1,pending_flag:0.
     0> <t:    2362649>, user.c,  433, Deleting next record.
     0> <t:    2362654>, user.c,  613, FDS Data is Writting ...
     0> <t:    2365909>, user.c,  332, Event: FDS_EVT_DEL_RECORD received (FDS_SUCCESS)
     0> <t:    2365912>, user.c,  371, Record ID:	0x0011
     0> <t:    2365914>, user.c,  372, File ID:	0xF010
     0> <t:    2365916>, user.c,  373, Record key:	0x7010
     0> <t:    2366550>, user.c,  332, Event: FDS_EVT_WRITE received (FDS_SUCCESS)
     0> <t:    2366553>, user.c,  348, Record ID:	0x0012
     0> <t:    2366555>, user.c,  349, File ID:	0xF010
     0> <t:    2366557>, user.c,  350, Record key:	0x7010
    
    //================below:  (FDS_ERR_OPERATION_TIMEOUT)=================//
     0> <t:    5019568>, access.c,  942, RX opcode =[FFFF8206]
     0> <t:    5019570>, access.c,  943, msg length =[0005]
     0> <t:    5019573>, access.c,  944, msg rx: : 0000021414
     0> <t:    5019575>, access.c,  952, element index =[0]
     0> <t:    5019577>, access.c, 1015, In coming is OK ! 
     0> <t:    5019580>, generic_level_server.c,  101, Opcode Jumper to Level handl_set !
     0> <t:    5019583>, app_level.c,  498, Level SET: Level: 0  delay: 100  tt: 2000  req-delta: -10 
     0> <t:    5019588>, access.c,  284, appkey_handle is 65535 
     0> <t:    5019590>, access.c,  285, address_handle  is 0 
     0> <t:    5019593>, access.c,  402, Source address: 9 Target Address: 4
     0> <t:    5019596>, access.c,  407, sensor msg tx: : 0A00000014
     0> <t:    5019605>, access.c,  972, is_opcode_of_model true
     0> <t:    5019607>, access.c,  983, address_match false
     0> <t:    5019609>, access.c,  988, bitfield_get true
     0> <t:    5019611>, access.c,  995, ACCESS_INTERNAL_STATE_IS_ALLOCATED true
     0> <t:    5020808>, access.c,  284, appkey_handle is 65535 
     0> <t:    5020810>, access.c,  285, address_handle  is 65535 
     0> <t:    5022865>, app_level.c,  280, Selecting interval for one step change
     0> <t:    5022868>, app_level.c,  284, timeout_rtc_ticks: 6554 ticks
     0> <t:    5029425>, app_level.c,  303, delta= -10
     0> <t:    5029427>, app_level.c,  313, One Level cb happen !
     0> <t:    5029429>, app_level.c,  314, Present Level: 10
     0> <t:    5029432>, app_level.c,  316, ELAPSED_TIME: 10 ,Transition Time: 0
     0> <t:    5029435>, main.c,  268, m_pwm0_present_level is:    10
     0> <t:    5029437>, main.c,  291, Pwm value: 1000
     0> <t:    5035994>, app_level.c,  303, delta= -10
     0> <t:    5035996>, app_level.c,  313, One Level cb happen !
     0> <t:    5035999>, app_level.c,  314, Present Level: 9
     0> <t:    5036001>, app_level.c,  316, ELAPSED_TIME: 9 ,Transition Time: 200
     0> <t:    5036004>, main.c,  268, m_pwm0_present_level is:     9
     0> <t:    5036007>, main.c,  291, Pwm value:  900
     0> <t:    5042563>, app_level.c,  303, delta= -10
     0> <t:    5042565>, app_level.c,  313, One Level cb happen !
     0> <t:    5042568>, app_level.c,  314, Present Level: 8
     0> <t:    5042570>, app_level.c,  316, ELAPSED_TIME: 8 ,Transition Time: 400
     0> <t:    5042573>, main.c,  268, m_pwm0_present_level is:     8
     0> <t:    5042576>, main.c,  291, Pwm value:  800
     0> <t:    5049132>, app_level.c,  303, delta= -10
     0> <t:    5049134>, app_level.c,  313, One Level cb happen !
     0> <t:    5049136>, app_level.c,  314, Present Level: 7
     0> <t:    5049139>, app_level.c,  316, ELAPSED_TIME: 7 ,Transition Time: 601
     0> <t:    5049142>, main.c,  268, m_pwm0_present_level is:     7
     0> <t:    5049145>, main.c,  291, Pwm value:  700
     0> <t:    5055701>, app_level.c,  303, delta= -10
     0> <t:    5055703>, app_level.c,  313, One Level cb happen !
     0> <t:    5055705>, app_level.c,  314, Present Level: 6
     0> <t:    5055708>, app_level.c,  316, ELAPSED_TIME: 6 ,Transition Time: 801
     0> <t:    5055711>, main.c,  268, m_pwm0_present_level is:     6
     0> <t:    5055714>, main.c,  291, Pwm value:  600
     0> <t:    5062271>, app_level.c,  303, delta= -10
     0> <t:    5062273>, app_level.c,  313, One Level cb happen !
     0> <t:    5062276>, app_level.c,  314, Present Level: 5
     0> <t:    5062278>, app_level.c,  316, ELAPSED_TIME: 5 ,Transition Time: 1002
     0> <t:    5062281>, main.c,  268, m_pwm0_present_level is:     5
     0> <t:    5062284>, main.c,  291, Pwm value:  500
     0> <t:    5068840>, app_level.c,  303, delta= -10
     0> <t:    5068842>, app_level.c,  313, One Level cb happen !
     0> <t:    5068844>, app_level.c,  314, Present Level: 4
     0> <t:    5068847>, app_level.c,  316, ELAPSED_TIME: 4 ,Transition Time: 1202
     0> <t:    5068850>, main.c,  268, m_pwm0_present_level is:     4
     0> <t:    5068853>, main.c,  291, Pwm value:  400
     0> <t:    5075409>, app_level.c,  303, delta= -10
     0> <t:    5075411>, app_level.c,  313, One Level cb happen !
     0> <t:    5075414>, app_level.c,  314, Present Level: 3
     0> <t:    5075416>, app_level.c,  316, ELAPSED_TIME: 3 ,Transition Time: 1403
     0> <t:    5075419>, main.c,  268, m_pwm0_present_level is:     3
     0> <t:    5075422>, main.c,  291, Pwm value:  300
     0> <t:    5081978>, app_level.c,  303, delta= -10
     0> <t:    5081980>, app_level.c,  313, One Level cb happen !
     0> <t:    5081982>, app_level.c,  314, Present Level: 2
     0> <t:    5081985>, app_level.c,  316, ELAPSED_TIME: 2 ,Transition Time: 1603
     0> <t:    5081989>, main.c,  268, m_pwm0_present_level is:     2
     0> <t:    5081991>, main.c,  291, Pwm value:  200
     0> <t:    5088548>, app_level.c,  303, delta= -10
     0> <t:    5088550>, app_level.c,  313, One Level cb happen !
     0> <t:    5088553>, app_level.c,  314, Present Level: 1
     0> <t:    5088555>, app_level.c,  316, ELAPSED_TIME: 1 ,Transition Time: 1804
     0> <t:    5088558>, main.c,  268, m_pwm0_present_level is:     1
     0> <t:    5088561>, main.c,  291, Pwm value:  100
     0> <t:    5095117>, access.c,  284, appkey_handle is 65535 
     0> <t:    5095120>, access.c,  285, address_handle  is 0 
     0> <t:    5095122>, main.c,  268, m_pwm0_present_level is:     0
     0> <t:    5095125>, main.c,  291, Pwm value:    0
     0> <t:    5095127>, app_level.c,  337, Level_transition_complete:     0
     0> <t:    5095130>, app_level.c,  340, pwm_value is 0 ,Flag is 1
     0> <t:    5095133>, user.c,  586, Is Coming to FDS!
     0> <t:    5095135>, user.c,  591, Element 0, value is 0!
     0> <t:    5095138>, user.c,  428, delete_next: 1,pending_flag:0.
     0> <t:    5095141>, user.c,  433, Deleting next record.
     0> <t:    5095179>, user.c,  332, Event: FDS_EVT_DEL_RECORD received (FDS_ERR_OPERATION_TIMEOUT)
     0> <t:    5095220>, user.c,  332, Event: FDS_EVT_WRITE received (FDS_ERR_OPERATION_TIMEOUT)
     0> <t:    5095224>, user.c,  613, FDS Data is Writting ...
    //=================== bellow : No working================================//
     0> <t:    6268450>, access.c,  942, RX opcode =[FFFF8206]
     0> <t:    6268453>, access.c,  943, msg length =[0005]
     0> <t:    6268455>, access.c,  944, msg rx: : 0A00041414
     0> <t:    6268458>, access.c,  952, element index =[0]
     0> <t:    6268460>, access.c, 1015, In coming is OK ! 
     0> <t:    6268463>, generic_level_server.c,  101, Opcode Jumper to Level handl_set !
     0> <t:    6268466>, app_level.c,  498, Level SET: Level: 10  delay: 100  tt: 2000  req-delta: 10 
     0> <t:    6268471>, access.c,  284, appkey_handle is 65535 
     0> <t:    6268473>, access.c,  285, address_handle  is 0 
     0> <t:    6268476>, access.c,  402, Source address: 9 Target Address: 4
     0> <t:    6268479>, access.c,  407, sensor msg tx: : 00000A0014
     0> <t:    6268488>, access.c,  972, is_opcode_of_model true
     0> <t:    6268490>, access.c,  983, address_match false
     0> <t:    6268492>, access.c,  988, bitfield_get true
     0> <t:    6268494>, access.c,  995, ACCESS_INTERNAL_STATE_IS_ALLOCATED true
     0> <t:    6271747>, app_level.c,  280, Selecting interval for one step change
     0> <t:    6271750>, app_level.c,  284, timeout_rtc_ticks: 6554 ticks
     0> <t:    6278307>, app_level.c,  303, delta= 10
     0> <t:    6278309>, app_level.c,  313, One Level cb happen !
     0> <t:    6278312>, app_level.c,  314, Present Level: 0
     0> <t:    6278314>, app_level.c,  316, ELAPSED_TIME: 0 ,Transition Time: 0
     0> <t:    6278317>, main.c,  268, m_pwm0_present_level is:     0
     0> <t:    6278319>, main.c,  291, Pwm value:    0
     0> <t:    6284876>, app_level.c,  303, delta= 10
     0> <t:    6284878>, app_level.c,  313, One Level cb happen !
     0> <t:    6284881>, app_level.c,  314, Present Level: 1
     0> <t:    6284883>, app_level.c,  316, ELAPSED_TIME: 1 ,Transition Time: 200
     0> <t:    6284886>, main.c,  268, m_pwm0_present_level is:     1
     0> <t:    6284889>, main.c,  291, Pwm value:  100
     0> <t:    6291445>, app_level.c,  303, delta= 10
     0> <t:    6291447>, app_level.c,  313, One Level cb happen !
     0> <t:    6291450>, app_level.c,  314, Present Level: 2
     0> <t:    6291452>, app_level.c,  316, ELAPSED_TIME: 2 ,Transition Time: 400
     0> <t:    6291455>, main.c,  268, m_pwm0_present_level is:     2
     0> <t:    6291458>, main.c,  291, Pwm value:  200
     0> <t:    6298014>, app_level.c,  303, delta= 10
     0> <t:    6298016>, app_level.c,  313, One Level cb happen !
     0> <t:    6298019>, app_level.c,  314, Present Level: 3
     0> <t:    6298021>, app_level.c,  316, ELAPSED_TIME: 3 ,Transition Time: 601
     0> <t:    6298024>, main.c,  268, m_pwm0_present_level is:     3
     0> <t:    6298027>, main.c,  291, Pwm value:  300
     0> <t:    6304583>, app_level.c,  303, delta= 10
     0> <t:    6304585>, app_level.c,  313, One Level cb happen !
     0> <t:    6304588>, app_level.c,  314, Present Level: 4
     0> <t:    6304590>, app_level.c,  316, ELAPSED_TIME: 4 ,Transition Time: 801
     0> <t:    6304593>, main.c,  268, m_pwm0_present_level is:     4
     0> <t:    6304596>, main.c,  291, Pwm value:  400
     0> <t:    6311152>, app_level.c,  303, delta= 10
     0> <t:    6311154>, app_level.c,  313, One Level cb happen !
     0> <t:    6311157>, app_level.c,  314, Present Level: 5
     0> <t:    6311159>, app_level.c,  316, ELAPSED_TIME: 5 ,Transition Time: 1002
     0> <t:    6311162>, main.c,  268, m_pwm0_present_level is:     5
     0> <t:    6311165>, main.c,  291, Pwm value:  500
     0> <t:    6317721>, app_level.c,  303, delta= 10
     0> <t:    6317723>, app_level.c,  313, One Level cb happen !
     0> <t:    6317725>, app_level.c,  314, Present Level: 6
     0> <t:    6317728>, app_level.c,  316, ELAPSED_TIME: 6 ,Transition Time: 1202
     0> <t:    6317731>, main.c,  268, m_pwm0_present_level is:     6
     0> <t:    6317734>, main.c,  291, Pwm value:  600
     0> <t:    6324290>, app_level.c,  303, delta= 10
     0> <t:    6324292>, app_level.c,  313, One Level cb happen !
     0> <t:    6324295>, app_level.c,  314, Present Level: 7
     0> <t:    6324297>, app_level.c,  316, ELAPSED_TIME: 7 ,Transition Time: 1403
     0> <t:    6324300>, main.c,  268, m_pwm0_present_level is:     7
     0> <t:    6324303>, main.c,  291, Pwm value:  700
     0> <t:    6330860>, app_level.c,  303, delta= 10
     0> <t:    6330862>, app_level.c,  313, One Level cb happen !
     0> <t:    6330864>, app_level.c,  314, Present Level: 8
     0> <t:    6330867>, app_level.c,  316, ELAPSED_TIME: 8 ,Transition Time: 1603
     0> <t:    6330870>, main.c,  268, m_pwm0_present_level is:     8
     0> <t:    6330873>, main.c,  291, Pwm value:  800
     0> <t:    6331528>, access.c,  284, appkey_handle is 65535 
     0> <t:    6331531>, access.c,  285, address_handle  is 65535 
     0> <t:    6337429>, app_level.c,  303, delta= 10
     0> <t:    6337431>, app_level.c,  313, One Level cb happen !
     0> <t:    6337434>, app_level.c,  314, Present Level: 9
     0> <t:    6337436>, app_level.c,  316, ELAPSED_TIME: 9 ,Transition Time: 1804
     0> <t:    6337439>, main.c,  268, m_pwm0_present_level is:     9
     0> <t:    6337442>, main.c,  291, Pwm value:  900
     0> <t:    6343998>, access.c,  284, appkey_handle is 65535 
     0> <t:    6344001>, access.c,  285, address_handle  is 0 
     0> <t:    6344003>, main.c,  268, m_pwm0_present_level is:    10
     0> <t:    6344006>, main.c,  291, Pwm value: 1000
     0> <t:    6344008>, app_level.c,  337, Level_transition_complete:    10
     0> <t:    6344011>, app_level.c,  340, pwm_value is 10 ,Flag is 1
     0> <t:    6986888>, access.c,  284, appkey_handle is 65535 
     0> <t:    6986890>, access.c,  285, address_handle  is 65535 
    //=======================bellow  BUTTON RESET =======================//
    
     0> <t:       5335>, user.c,  491, ---FDS example started .---
     0> <t:       5337>, user.c,  496, Initializing fds...
     0> <t:       5340>, user.c,  332, Event: FDS_EVT_INIT received (FDS_SUCCESS)
     0> <t:       5343>, user.c,  509, Found 1 valid records.
     0> <t:       5345>, user.c,  510, Found 1 dirty records (ready to be garbage collected).
     0> <t:       5348>, user.c,  528, PWM Value is 10 and 40 
     0> <t:       5351>, user.c,  542, Config file found, updating boot count to 13.
    

        A part Code:

    static void initialize(void)
    {
    ...
    fds_test();
    }
    int main(void)
    {
      initialize();
      ...
      for (;;)
      {
            fds_data();
            (void)sd_app_evt_wait();
      }
    }
    void fds_data(void)
    {
        //app_level_server_t * p_server;
       // __LOG(LOG_SRC_APP, LOG_LEVEL_INFO,"Waking !\n");
        if(fds_flag==true)
        {
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO,"Is Coming to FDS!\n");
            fds_flag=false;
            if(element_number==0)
            {
                m_dummy_cfg.pwm_value[0]=pwm_value;//p_server->state.present_level;
              __LOG(LOG_SRC_APP, LOG_LEVEL_INFO,"Element 0, value is %d!\n",m_dummy_cfg.pwm_value[0]);
            }
            else if(element_number==1)
            {
                m_dummy_cfg.pwm_value[1]=pwm_value;//p_server->state.present_level;
                __LOG(LOG_SRC_APP, LOG_LEVEL_INFO,"Element 1, value is %d!\n",m_dummy_cfg.pwm_value[1]);
            }
        
            fds_record_desc_t desc = {0};  
            fds_find_token_t  tok  = {0};
            ret_code_t rc = fds_record_find(CONFIG_FILE, CONFIG_REC_KEY, &desc, &tok); 
            if (rc == FDS_SUCCESS)
            {
              m_fds_deleted=false;
              delete_all_begin();
              delete_all_process();
             // wait_for_fds_delete();
            }
            m_fds_write=false;
            rc = fds_record_write(&desc, &m_dummy_record);
            if(rc==FDS_SUCCESS)
            {
              __LOG(LOG_SRC_APP, LOG_LEVEL_INFO,"FDS Data is Writting ...\n");
            }
            APP_ERROR_CHECK(rc);
            wait_for_fds_write();
          
             (void) sd_app_evt_wait();
        }
    }
    void fds_test(void)   //int main(void)
    {
        ret_code_t rc;
    
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "---FDS example started .---\n");
        /* Register first to receive an event when initialization is complete. */
        (void) fds_register(fds_evt_handler);
    
        
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Initializing fds...\n");
    
        rc = fds_init();
        APP_ERROR_CHECK(rc);
    
        /* Wait for fds to initialize. */
        wait_for_fds_ready();
    
        fds_stat_t stat = {0};
    
        rc = fds_stat(&stat);
        APP_ERROR_CHECK(rc);
    
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO,"Found %d valid records.\n", stat.valid_records);
        __LOG(LOG_SRC_APP, LOG_LEVEL_INFO,"Found %d dirty records (ready to be garbage collected).\n", 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(&m_dummy_cfg, config.p_data, sizeof(configuration_t));
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "PWM Value is %d and %d \r\n", m_dummy_cfg.pwm_value[0], m_dummy_cfg.pwm_value[1]);
            //add 
            #if 0
    	uint32_t *data;
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO,"Data = ");
    	data = (uint32_t *)config.p_data;
    	for (uint16_t i=0;i<config.p_header->length_words;i++)
    	{
                    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO,"0x%8x ",data[i]);
    
            }
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO,"\r\n");
            #endif
    
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO,"Config file found, updating boot count to %d.\n", m_dummy_cfg.boot_count);
    
            /* Update boot count. */
            m_dummy_cfg.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);
            if(stat.dirty_records>=3)
            {
              m_fds_gc=false;
              rc=fds_gc();
              APP_ERROR_CHECK(rc);
               wait_for_fds_gc();
            }
        }
        else
        {
            /* System config not found; write a new one. */
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO,"Writing config file...\n");
    
            m_dummy_cfg.pwm_value[0]=50;
            m_dummy_cfg.pwm_value[1]=40;
            m_fds_write=false;
            rc = fds_record_write(&desc, &m_dummy_record);
            APP_ERROR_CHECK(rc);
            wait_for_fds_write();
        }
    }

       The include file is here: include.rar

        Could you give me some help to slove this issue?Thank you.

    Best Regards,

    Panda.

Related