//#include "hal_minifds.h"

//#include "nrf_sdh_soc.h"

//void minifds_sys_evt_handler(uint32_t sys_evt, void *p_context)
//{
//    //    UNUSED_PARAMETER(p_context);
//    MINIFDS_PRINT(" NRF_EVT_FLASH_OPERATION_SUCCESS,");
//    if ((sys_evt != NRF_EVT_FLASH_OPERATION_SUCCESS) && (sys_evt != NRF_EVT_FLASH_OPERATION_ERROR))
//    {
//        /* Ignore any non-flash events. */
//        return;
//    }
//    switch (sys_evt)
//    {
//    case NRF_EVT_FLASH_OPERATION_SUCCESS:
//        MINIFDS_PRINT(" NRF_EVT_FLASH_OPERATION_SUCCESS,");
//        break;
//    case NRF_EVT_FLASH_OPERATION_ERROR:
//        break;
//    }
//}
///* Define a nrf_sdh_soc event observer to receive SoftDevice system events. */
//NRF_SDH_SOC_OBSERVER(m_sys_obs, 0, minifds_sys_evt_handler, NULL);


//DEFINE_MINIINF(minifds, 0x00074000UL, 0x00078000UL, sdflash_write, sdflash_page_erase);

//unsigned char reckd[256];
//void add_pcs(cli_t *p_cli, unsigned short argc, char **argv)
//{
//    char recalue = 0;
//    static unsigned char key = 1;
//    for (int i = 0; i < sizeof(reckd); i++)
//    {
//        reckd[i] = 0x11;
//    }
//    reckd[sizeof(reckd) - 1] = 0x0B;
//    recalue = minfds_record_add(&minifds, key++, reckd, 100);
//    cli_printf(p_cli, "  %d  =minfds_record_add(&minifds,2,reckd,sizeof(reckd))", recalue);
//}
//CLI_CMD_REGISTER(add, "Cli cmd history", add_pcs);

//void update_pcs(cli_t *p_cli, unsigned short argc, char **argv)
//{
//    char recalue = 0;
//    for (int i = 0; i < sizeof(reckd); i++)
//    {
//        reckd[i] = 0x11;
//    }
//    reckd[sizeof(reckd) - 1] = 0x0B;
//    recalue = minfds_record_update(&minifds, 2, reckd, sizeof(reckd));
//    cli_printf(p_cli, "  %d  =minfds_record_update(&minifds,2,reckd,sizeof(reckd))", recalue);
//}
//CLI_CMD_REGISTER(update, "Cli cmd history", update_pcs);

//void del_pcs(cli_t *p_cli, unsigned short argc, char **argv)
//{
//    char recalue = 0;
//    unsigned char reckd[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
//    recalue = minfds_record_delete(&minifds, 2);
//    cli_printf(p_cli, "  %d  =minfds_record_delete(&minifds,2,reckd,sizeof(reckd))", recalue);
//}
//CLI_CMD_REGISTER(del, "Cli cmd history", del_pcs);

//void da_pcs(cli_t *p_cli, unsigned short argc, char **argv)
//{
//    char recalue = 0;
//    unsigned char reckd[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
//    recalue = minfds_record_delete_all(&minifds);
//    cli_printf(p_cli, "  %d  =minfds_record_delete(&minifds,2,reckd,sizeof(reckd))", recalue);
//}
//CLI_CMD_REGISTER(da, "Cli cmd history", da_pcs);

//void find_pcs(cli_t *p_cli, unsigned short argc, char **argv)
//{
//    char recalue = 0;
//    unsigned char reckd[64] = {0};
//    length_t length = 0;
//    recalue = minfds_record_find(&minifds, 2, reckd, &length);
//    cli_printf(p_cli, "  %d  = minfds_record_find", recalue);
//    for (unsigned int i = 0; i < length; i++)
//    {
//        MINIFDS_PRINT("0x%2x ", reckd[i]);
//    }
//    MINIFDS_PRINT("\r\n");
//}
//CLI_CMD_REGISTER(find, "Cli cmd history", find_pcs);

//void gc_pcs(cli_t *p_cli, unsigned short argc, char **argv)
//{
//    minfds_gc(&minifds);
//}
//CLI_CMD_REGISTER(gc, "Cli cmd history", gc_pcs);

//void cb_pcs(cli_t *p_cli, unsigned short argc, char **argv)
//{
//    printctb(&minifds);
//}
//CLI_CMD_REGISTER(cb, "Cli cmd history", cb_pcs);

//void scan_pcs(cli_t *p_cli, unsigned short argc, char **argv)
//{
//    minfds_Scan(&minifds);
//}
//CLI_CMD_REGISTER(scan, "Cli cmd history", scan_pcs);

//unsigned char getrng(void)
//{
//    unsigned char value;
//    NRF_RNG->CONFIG = 1;
//    NRF_RNG->TASKS_START = 1;
//    NRF_RNG->EVENTS_VALRDY = 0;
//    while (NRF_RNG->EVENTS_VALRDY == 0)
//        ;
//    value = NRF_RNG->VALUE;
//    NRF_RNG->TASKS_STOP = 1;
//    NRF_RNG->INTENCLR = 0;
//    NRF_RNG->CONFIG = 0;
//    return value;
//}

//void minifdstest_pcs(cli_t *p_cli, unsigned short argc, char **argv)
//{
//    static unsigned char key = 1;
//    length_t length = getrng();
//    char rec = 0;
//    int count = 0;
//    minfds_record_delete_all(&minifds);
//	unsigned char readbuff[256];
//    while (rec == 0)
//    {
////			do{
//        length = getrng();
////				length = length<<8;
////				length |= getrng();}while(length<4096+4096);

//        for (int i = 0; i < length; i++)
//        {
//            reckd[i] = getrng();
//        }
//        if (getrng() > 128)
//        {
//            rec = minfds_record_add(&minifds, key++, reckd, length);
//print_record(reckd, length);
//            if (rec == 0)
//            {							
//								rec = minfds_record_find(&minifds, key-1, readbuff, &length);
//							print_record(readbuff, length);
//								if(memcmp(reckd,readbuff,length)!=0)
//								{
//									MINIFDS_PRINT("-----------------------------------------------------------------------------ERROR- read f--------------  %d\r\n", count);
//								}	
//								
//                count++;
//                if (minifds.record_count != count)
//                {
//                    MINIFDS_PRINT("-----------------------------------------------------------------------------ERROR---------------  %d\r\n", count);
//                }
//            }
//            if (rec == MINIFDS_ERR_NOT_FREE_CAPACITY)
//            {
//                rec = minfds_record_delete_all(&minifds);
//                key = 1;
//                if (rec == 0)
//                {
//                    count = 0;
//                }
//            }
//        }
//        else
//        {
//            minfds_record_update(&minifds, getrng(), reckd, length);
//        }
//    }
//    MINIFDS_PRINT("minifdstest_pcs(cli_t* p_cli, unsigned short argc, char** argv)  %d\r\n", count);
//    key = 1;
//    //      minfds_Scan(&minifds);
//}
//CLI_CMD_REGISTER(minifdstest_pcs, "Cli cmd history", minifdstest_pcs);

//char fds4k_read_words(const unsigned int addr, unsigned int *p_words, unsigned short length_words)
//{
//    for (unsigned int i = 0; i < length_words; i++)
//    {
//        p_words[i] = *((unsigned int *)(addr + i * 4));
//    }
//    return 0;
//}
//void fds4k_print_cli_pcs(cli_t *p_cli, unsigned short argc, char **argv)
//{
//    unsigned int temp[4];
//    unsigned int addr = minifds.start_addr;
//    for (unsigned int i = 0; i < (minifds.end_addr - minifds.start_addr) / 16 + 3; i++)
//    {
//        if (fds4k_read_words(addr, temp, 4) == 0)
//        {
//            MINIFDS_PRINT("%4d 0x%8x 0x%8x 0x%8x 0x%8x 0x%8x \r\n", i, addr, temp[0], temp[1], temp[2], temp[3]);
//            for (int k = 0; k < 0xffff; k++)
//                ;
//        }
//        addr += 16;
//    }
//}
//CLI_CMD_REGISTER(fds_printf, "Cli cmd history", fds4k_print_cli_pcs);

//int main(void)
//{
//    minfds_init(&minifds);
//    while (1)
//    {
//        cli_process(&clirtt);
//    }
//}
