shell_port.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 <pthread.h>
  19. Shell shell;
  20. char shellBuffer[512];
  21. /**
  22. * @brief 获取系统tick
  23. *
  24. * @return unsigned int 系统tick
  25. */
  26. unsigned int userGetTick()
  27. {
  28. struct timeval tv;
  29. gettimeofday(&tv, NULL);
  30. return (tv.tv_sec * 1000 + tv.tv_usec / 1000) & 0x7FFFFFFF;
  31. }
  32. /**
  33. * @brief 用户shell写
  34. *
  35. * @param data 数据
  36. */
  37. unsigned short userShellWrite(char *data, unsigned short len)
  38. {
  39. unsigned short length = len;
  40. while (length--)
  41. {
  42. putchar(*data++);
  43. }
  44. return len;
  45. }
  46. /**
  47. * @brief 用户shell读
  48. *
  49. * @param data 数据
  50. * @return char 状态
  51. */
  52. unsigned short userShellRead(char *data, unsigned short len)
  53. {
  54. unsigned short length = len;
  55. while (length--)
  56. {
  57. *data++ = getchar();
  58. }
  59. return len;
  60. }
  61. /**
  62. * @brief 用户shell初始化
  63. *
  64. */
  65. void userShellInit(void)
  66. {
  67. shell.write = userShellWrite;
  68. shell.read = userShellRead;
  69. shellInit(&shell, shellBuffer, 512);
  70. shellTask(&shell);
  71. }