shell_port.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /**
  2. * @file shell_port.c
  3. * @author Letter (NevermindZZT@gmail.com)
  4. * @brief
  5. * @version 0.1
  6. * @date 2019-02-22
  7. *
  8. * @copyright (c) 2019 Letter
  9. *
  10. */
  11. #include "shell.h"
  12. // #include <stdio.h>
  13. // #include <dirent.h>
  14. // #include <unistd.h>
  15. // #include <stddef.h>
  16. // #include <string.h>
  17. #include <sys/time.h>
  18. #include <string.h>
  19. #include <stdio.h>
  20. // #include <pthread.h>
  21. Shell shell;
  22. char shellBuffer[512];
  23. /**
  24. * @brief 获取系统tick
  25. *
  26. * @return unsigned int 系统tick
  27. */
  28. unsigned int userGetTick()
  29. {
  30. struct timeval tv;
  31. gettimeofday(&tv, NULL);
  32. return (tv.tv_sec * 1000 + tv.tv_usec / 1000) & 0x7FFFFFFF;
  33. }
  34. /**
  35. * @brief 用户shell写
  36. *
  37. * @param data 数据
  38. */
  39. unsigned short userShellWrite(char *data, unsigned short len)
  40. {
  41. unsigned short length = len;
  42. while (length--)
  43. {
  44. putchar(*data++);
  45. }
  46. return len;
  47. }
  48. /**
  49. * @brief 用户shell读
  50. *
  51. * @param data 数据
  52. * @return char 状态
  53. */
  54. unsigned short userShellRead(char *data, unsigned short len)
  55. {
  56. unsigned short length = len;
  57. while (length--)
  58. {
  59. *data++ = getchar();
  60. }
  61. return len;
  62. }
  63. /**
  64. * @brief 用户shell初始化
  65. *
  66. */
  67. void userShellInit(void)
  68. {
  69. shell.write = userShellWrite;
  70. shell.read = userShellRead;
  71. shellInit(&shell, shellBuffer, 512);
  72. shellTask(&shell);
  73. }