luat_shell_air101.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include "luat_shell.h"
  2. #include "wm_include.h"
  3. #define LUAT_LOG_TAG "luat.shell"
  4. #include "luat_log.h"
  5. static int drv = -1;
  6. #define CONSOLE_BUF_SIZE 512
  7. typedef struct console_st
  8. {
  9. size_t rx_data_len;
  10. char rx_buf[CONSOLE_BUF_SIZE]; /*uart rx*/
  11. } console;
  12. static console ShellConsole;
  13. void luat_shell_write(char* buff, size_t len) {
  14. if (drv > -1 && len >= 0) {
  15. tls_uart_write(drv, buff, len);
  16. }
  17. }
  18. char* luat_shell_read(size_t *len) {
  19. if(ShellConsole.rx_data_len == 0)
  20. {
  21. *len = 0;
  22. return NULL;
  23. }
  24. if (ShellConsole.rx_data_len > CONSOLE_BUF_SIZE)
  25. ShellConsole.rx_data_len = CONSOLE_BUF_SIZE;
  26. int ret = tls_uart_read(drv, ShellConsole.rx_buf, ShellConsole.rx_data_len);
  27. *len = ret;
  28. return ShellConsole.rx_buf;
  29. }
  30. void luat_shell_notify_recv(void) {
  31. ShellConsole.rx_data_len = 0;
  32. }
  33. int16_t demo_console_rx(uint16_t len, void* user_data){
  34. ShellConsole.rx_data_len += len;
  35. luat_shell_notify_read();
  36. return 0;
  37. }
  38. void luat_shell_poweron(int _drv) {
  39. drv = _drv;
  40. memset(ShellConsole.rx_buf, 0, CONSOLE_BUF_SIZE + 1);
  41. tls_uart_rx_callback_register(drv,(int16_t(*)(uint16_t, void*))demo_console_rx, NULL);
  42. luat_shell_notify_recv();
  43. }