simulator.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <curses.h>
  4. #include <unistd.h>
  5. #include <stdint.h>
  6. #include "nr_micro_shell.h"
  7. #include <sys/mman.h>
  8. int main(int argc, char *argv[])
  9. {
  10. int c;
  11. int i = 0;
  12. system("stty -echo");
  13. system("stty -icanon");
  14. shell_init();
  15. #ifdef NR_SHELL_DEBUG
  16. #if defined(NR_SHELL_CMD_RD) || defined(NR_SHELL_CMD_WR)
  17. /* To test wr/rd cmd, malloc 4KB mem to fixed address 0x10000000 */
  18. uint8_t *buf = mmap((void *)0x10000000, 4096, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
  19. if (buf == NULL) {
  20. shell_printf("malloc failed\r\n");
  21. return -1;
  22. }
  23. for (i = 0; i < 4096; i++) {
  24. buf[i] = (unsigned char)(i % 256);
  25. }
  26. shell_printf("malloc 4KB mem, address: %p\r\n", buf);
  27. #endif
  28. #endif
  29. while (1) {
  30. c = getchar();
  31. shell(c);
  32. if (c == 'q') {
  33. i++;
  34. } else {
  35. i = 0;
  36. }
  37. if (i > 3) {
  38. break;
  39. }
  40. }
  41. #ifdef NR_SHELL_DEBUG
  42. #if defined(NR_SHELL_CMD_RD) || defined(NR_SHELL_CMD_WR)
  43. munmap(buf, 4096);
  44. #endif
  45. #endif
  46. system("stty echo");
  47. system("stty icanon");
  48. return 0;
  49. }