cli.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. #include "cli.h"
  2. #include "cli_inter_actor.h"
  3. #include "cli_inter_preter.h"
  4. #include "flash.h"
  5. #include <stdint.h>
  6. #include <stdio.h>
  7. // #include "led.h"
  8. // #include "usart.h"
  9. // #include <stdio.h>
  10. #define CLI_ANSI_ENABLE 1
  11. void command_help(void);
  12. void command_version(void);
  13. void command_clear(void);
  14. void command_reset(void);
  15. void command_ps(void);
  16. void command_led_control(void);
  17. command_entry main_table[] = {
  18. CLI_COMPONENTS_LIST
  19. command_entry_action_with_detail("help", command_help, "", "help infomation", (const char *const *)NULL),
  20. command_entry_action_with_detail("version", command_version, "", "show version", (const char *const *)NULL),
  21. command_entry_action_with_detail("reset", command_reset, "", "reset system", (const char *const *)NULL),
  22. command_entry_action_with_detail("clear", command_clear, "", "clear screen", (const char *const *)NULL),
  23. command_entry_action_with_detail("ps", command_ps, "", "print string", (const char *const *)NULL),
  24. command_entry_terminator()};
  25. command_entry command_debug_table[] = {
  26. command_entry_action_with_detail("led", command_led_control, "u", "led_control", (const char *const *)0),
  27. command_entry_terminator()};
  28. uint8_t led_states;
  29. void command_led_control(void)
  30. {
  31. if (cli_ipt_arg_list[0][0] == 1)
  32. {
  33. // LED2;
  34. led_states = 1;
  35. }
  36. else if (cli_ipt_arg_list[0][0] == 2)
  37. {
  38. led_states = 2;
  39. }
  40. else
  41. {
  42. led_states = 0;
  43. }
  44. }
  45. command_entry command_ble_table[] = {
  46. command_entry_terminator()};
  47. command_entry command_eeprom_table[] = {
  48. command_entry_terminator()};
  49. void command_flash_read(void)
  50. {
  51. uint32_t read_byte = 0;
  52. uint16_t read_buf[100] = {0};
  53. if (cli_ipt_arg_list[0][0] == 1)
  54. {
  55. fmc_clear_flag_star();
  56. read_byte = fmc_read_byte(cli_ipt_arg_list[1][0]);
  57. fmc_clear_flag_end();
  58. CLI_PRINTF("%x\r\n", read_byte);
  59. }
  60. else if (cli_ipt_arg_list[0][0] == 2)
  61. {
  62. fmc_clear_flag_star();
  63. read_byte = fmc_read_half_word(cli_ipt_arg_list[1][0]);
  64. fmc_clear_flag_end();
  65. CLI_PRINTF("%x\r\n", read_byte);
  66. }
  67. else if (cli_ipt_arg_list[0][0] == 3)
  68. {
  69. fmc_clear_flag_star();
  70. read_byte = fmc_read_n_half_word(cli_ipt_arg_list[1][0], read_buf, 10);
  71. fmc_clear_flag_end();
  72. CLI_PRINTF("%x\r\n", read_buf);
  73. }
  74. else
  75. {
  76. led_states = 0;
  77. }
  78. }
  79. void command_flash_write(void)
  80. {
  81. uint32_t read_byte = 0;
  82. uint16_t read_buf[100] = {0};
  83. if (cli_ipt_arg_list[0][0] == 1)
  84. {
  85. fmc_clear_flag_star();
  86. read_buf[0] = cli_ipt_arg_list[2][0] >> 8;
  87. read_buf[1] = cli_ipt_arg_list[2][0];
  88. read_byte = fmc_erase_pages(cli_ipt_arg_list[1][0], cli_ipt_arg_list[3][0]);
  89. CLI_PRINTF("%x\r\n", read_byte);
  90. read_byte = fmc_write_n_half_word(cli_ipt_arg_list[1][0], read_buf, cli_ipt_arg_list[3][0]);
  91. fmc_clear_flag_end();
  92. CLI_PRINTF("%x\r\n", read_byte);
  93. }
  94. // else if (cli_ipt_arg_list[0][0] == 2)
  95. // {
  96. // fmc_clear_flag_star();
  97. // read_byte = fmc_read_half_word(cli_ipt_arg_list[1][0]);
  98. // fmc_clear_flag_end();
  99. // CLI_PRINTF("%x\r\n", read_byte);
  100. // }
  101. // else if (cli_ipt_arg_list[0][0] == 3)
  102. // {
  103. // fmc_clear_flag_star();
  104. // read_byte = fmc_read_n_half_word(cli_ipt_arg_list[1][0], read_buf, 10);
  105. // fmc_clear_flag_end();
  106. // CLI_PRINTF("%x\r\n", read_buf);
  107. // }
  108. }
  109. command_entry command_flash_table[] = {
  110. command_entry_action_with_detail("r", command_flash_read, "uu", "command_flash_read", (const char *const *)0),
  111. command_entry_action_with_detail("w", command_flash_write, "uuuu", "command_flash_write", (const char *const *)0),
  112. command_entry_terminator()};
  113. void command_version(void)
  114. {
  115. CLI_PRINTF("version 3.0.16. CC by[" __DATE__ " " __TIME__ "] \r\n");
  116. }
  117. void command_reset(void)
  118. {
  119. cli_reset();
  120. }
  121. void command_help(void)
  122. {
  123. print_entry(main_table);
  124. }
  125. void command_clear(void)
  126. {
  127. #if CLI_ANSI_ENABLE == 1
  128. CLI_PRINTF("%c[2J", '\033');
  129. CLI_PRINTF("%c[41A", '\033');
  130. #else
  131. for (uint8_t i = 0; i < 40; i++)
  132. {
  133. CLI_PRINTF("# \r\n");
  134. }
  135. #endif
  136. }
  137. void command_ps(void)
  138. {
  139. CLI_PRINTF("%s\r\n", &cli_ipt_arg_list[0][0]);
  140. }
  141. void cli_init(void)
  142. {
  143. // CLI_COMPONENTS_INIT
  144. }
  145. int ch = 0;
  146. void cli_loop(void)
  147. {
  148. // CLI_COMPONENTS_LOOP
  149. ch = getchar();
  150. if (ch != -1)
  151. {
  152. cli_itt_input(CLI_CHL_COM, ch);
  153. }
  154. }