minifds_test.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. #include "minifds.h"
  2. #include "nrf_sdh_soc.h"
  3. void minifds_sys_evt_handler(uint32_t sys_evt, void *p_context)
  4. {
  5. // UNUSED_PARAMETER(p_context);
  6. MINIFDS_PRINT(" NRF_EVT_FLASH_OPERATION_SUCCESS,");
  7. if ((sys_evt != NRF_EVT_FLASH_OPERATION_SUCCESS) && (sys_evt != NRF_EVT_FLASH_OPERATION_ERROR))
  8. {
  9. /* Ignore any non-flash events. */
  10. return;
  11. }
  12. switch (sys_evt)
  13. {
  14. case NRF_EVT_FLASH_OPERATION_SUCCESS:
  15. MINIFDS_PRINT(" NRF_EVT_FLASH_OPERATION_SUCCESS,");
  16. break;
  17. case NRF_EVT_FLASH_OPERATION_ERROR:
  18. break;
  19. }
  20. }
  21. /* Define a nrf_sdh_soc event observer to receive SoftDevice system events. */
  22. NRF_SDH_SOC_OBSERVER(m_sys_obs, 0, minifds_sys_evt_handler, NULL);
  23. unsigned int sdflash_write(unsigned int *p_dst, unsigned int const *p_src, unsigned int sizewords)
  24. {
  25. unsigned int rev = 0;
  26. rev = sd_flash_write(p_dst, p_src, sizewords);
  27. // MINIFDS_PRINT(" %d sd_flash_write,0x%x 0x%x %d\r\n",rev, (unsigned int)p_dst, (unsigned int)p_src, sizewords);
  28. if ((unsigned int)p_dst + (sizewords * 4) > 0x78000)
  29. {
  30. MINIFDS_PRINT(" ----------------------------%d sd_flash_write,0x%x 0x%x %d\r\n", rev, (unsigned int)p_dst, (unsigned int)p_src, sizewords);
  31. rev = 10;
  32. }
  33. return rev;
  34. }
  35. unsigned int sdflash_page_erase(unsigned int page_addr)
  36. {
  37. unsigned int page_number = page_addr / 4096;
  38. return sd_flash_page_erase(page_number);
  39. }
  40. DEFINE_MINIINF(minifds, 0x00074000UL, 0x00078000UL, sdflash_write, sdflash_page_erase);
  41. unsigned char reckd[4096+4096];
  42. void add_pcs(cli_t *p_cli, unsigned short argc, char **argv)
  43. {
  44. char recalue = 0;
  45. static unsigned char key = 1;
  46. for (int i = 0; i < sizeof(reckd); i++)
  47. {
  48. reckd[i] = 0x11;
  49. }
  50. reckd[sizeof(reckd) - 1] = 0x0B;
  51. recalue = minfds_record_add(&minifds, key++, reckd, sizeof(reckd));
  52. cli_printf(p_cli, " %d =minfds_record_add(&minifds,2,reckd,sizeof(reckd))", recalue);
  53. }
  54. CLI_CMD_REGISTER(add, "Cli cmd history", add_pcs);
  55. void update_pcs(cli_t *p_cli, unsigned short argc, char **argv)
  56. {
  57. char recalue = 0;
  58. for (int i = 0; i < sizeof(reckd); i++)
  59. {
  60. reckd[i] = 0x11;
  61. }
  62. reckd[sizeof(reckd) - 1] = 0x0B;
  63. recalue = minfds_record_update(&minifds, 2, reckd, sizeof(reckd));
  64. cli_printf(p_cli, " %d =minfds_record_update(&minifds,2,reckd,sizeof(reckd))", recalue);
  65. }
  66. CLI_CMD_REGISTER(update, "Cli cmd history", update_pcs);
  67. void del_pcs(cli_t *p_cli, unsigned short argc, char **argv)
  68. {
  69. char recalue = 0;
  70. unsigned char reckd[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
  71. recalue = minfds_record_delete(&minifds, 2);
  72. cli_printf(p_cli, " %d =minfds_record_delete(&minifds,2,reckd,sizeof(reckd))", recalue);
  73. }
  74. CLI_CMD_REGISTER(del, "Cli cmd history", del_pcs);
  75. void da_pcs(cli_t *p_cli, unsigned short argc, char **argv)
  76. {
  77. char recalue = 0;
  78. unsigned char reckd[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
  79. recalue = minfds_record_delete_all(&minifds);
  80. cli_printf(p_cli, " %d =minfds_record_delete(&minifds,2,reckd,sizeof(reckd))", recalue);
  81. }
  82. CLI_CMD_REGISTER(da, "Cli cmd history", da_pcs);
  83. void find_pcs(cli_t *p_cli, unsigned short argc, char **argv)
  84. {
  85. char recalue = 0;
  86. unsigned char reckd[64] = {0};
  87. length_t length = 0;
  88. recalue = minfds_record_find(&minifds, 2, reckd, &length);
  89. cli_printf(p_cli, " %d = minfds_record_find", recalue);
  90. for (unsigned int i = 0; i < length; i++)
  91. {
  92. MINIFDS_PRINT("0x%2x ", reckd[i]);
  93. }
  94. MINIFDS_PRINT("\r\n");
  95. }
  96. CLI_CMD_REGISTER(find, "Cli cmd history", find_pcs);
  97. void gc_pcs(cli_t *p_cli, unsigned short argc, char **argv)
  98. {
  99. minfds_gc(&minifds);
  100. }
  101. CLI_CMD_REGISTER(gc, "Cli cmd history", gc_pcs);
  102. void cb_pcs(cli_t *p_cli, unsigned short argc, char **argv)
  103. {
  104. printctb(&minifds);
  105. }
  106. CLI_CMD_REGISTER(cb, "Cli cmd history", cb_pcs);
  107. void scan_pcs(cli_t *p_cli, unsigned short argc, char **argv)
  108. {
  109. minfds_Scan(&minifds);
  110. }
  111. CLI_CMD_REGISTER(scan, "Cli cmd history", scan_pcs);
  112. unsigned char getrng(void)
  113. {
  114. unsigned char value;
  115. NRF_RNG->CONFIG = 1;
  116. NRF_RNG->TASKS_START = 1;
  117. NRF_RNG->EVENTS_VALRDY = 0;
  118. while (NRF_RNG->EVENTS_VALRDY == 0)
  119. ;
  120. value = NRF_RNG->VALUE;
  121. NRF_RNG->TASKS_STOP = 1;
  122. NRF_RNG->INTENCLR = 0;
  123. NRF_RNG->CONFIG = 0;
  124. return value;
  125. }
  126. void minifdstest_pcs(cli_t *p_cli, unsigned short argc, char **argv)
  127. {
  128. static unsigned char key = 1;
  129. unsigned char length = getrng();
  130. char rec = 0;
  131. int count = 0;
  132. minfds_record_delete_all(&minifds);
  133. unsigned char readbuff[256];
  134. while (rec == 0)
  135. {
  136. // do{
  137. length = getrng();
  138. // length = length<<8;
  139. // length |= getrng();}while(length<4096+4096);
  140. for (int i = 0; i < length; i++)
  141. {
  142. reckd[i] = getrng();
  143. }
  144. if (getrng() > 128)
  145. {
  146. rec = minfds_record_add(&minifds, key++, reckd, length);
  147. print_record(reckd, length);
  148. if (rec == 0)
  149. {
  150. rec = minfds_record_find(&minifds, key-1, readbuff, &length);
  151. print_record(readbuff, length);
  152. if(memcmp(reckd,readbuff,length)!=0)
  153. {
  154. MINIFDS_PRINT("-----------------------------------------------------------------------------ERROR- read f-------------- %d\r\n", count);
  155. }
  156. count++;
  157. if (minifds.record_count != count)
  158. {
  159. MINIFDS_PRINT("-----------------------------------------------------------------------------ERROR--------------- %d\r\n", count);
  160. }
  161. }
  162. if (rec == MINIFDS_ERR_NOT_FREE_CAPACITY)
  163. {
  164. rec = minfds_record_delete_all(&minifds);
  165. key = 1;
  166. if (rec == 0)
  167. {
  168. count = 0;
  169. }
  170. }
  171. }
  172. else
  173. {
  174. minfds_record_update(&minifds, getrng(), reckd, length);
  175. }
  176. }
  177. MINIFDS_PRINT("minifdstest_pcs(cli_t* p_cli, unsigned short argc, char** argv) %d\r\n", count);
  178. key = 1;
  179. // minfds_Scan(&minifds);
  180. }
  181. CLI_CMD_REGISTER(minifdstest_pcs, "Cli cmd history", minifdstest_pcs);
  182. char fds4k_read_words(const unsigned int addr, unsigned int *p_words, unsigned short length_words)
  183. {
  184. for (unsigned int i = 0; i < length_words; i++)
  185. {
  186. p_words[i] = *((unsigned int *)(addr + i * 4));
  187. }
  188. return 0;
  189. }
  190. void fds4k_print_cli_pcs(cli_t *p_cli, unsigned short argc, char **argv)
  191. {
  192. unsigned int temp[4];
  193. unsigned int addr = minifds.start_addr;
  194. for (unsigned int i = 0; i < (minifds.end_addr - minifds.start_addr) / 16 + 3; i++)
  195. {
  196. if (fds4k_read_words(addr, temp, 4) == 0)
  197. {
  198. 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]);
  199. for (int k = 0; k < 0xffff; k++)
  200. ;
  201. }
  202. addr += 16;
  203. }
  204. }
  205. CLI_CMD_REGISTER(fds_printf, "Cli cmd history", fds4k_print_cli_pcs);
  206. int main(void)
  207. {
  208. minfds_init(&minifds);
  209. while (1)
  210. {
  211. cli_process(&clirtt);
  212. }
  213. }