luat_shell_air101.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include "luat_shell.h"
  2. #include "wm_include.h"
  3. #define LUAT_LOG_TAG "luat.shell"
  4. #include "luat_log.h"
  5. #include "wm_uart.h"
  6. #include "luat_uart.h"
  7. void luat_shell_write(char* buff, size_t len) {
  8. int i=0;
  9. while (i < len){
  10. while(tls_reg_read32(HR_UART0_FIFO_STATUS) & 0x3F);
  11. tls_reg_write32(HR_UART0_TX_WIN, (unsigned int)buff[i++]);
  12. }
  13. }
  14. void luat_shell_notify_recv(void) {
  15. }
  16. static tls_os_queue_t *shell_queue = NULL;
  17. static int16_t luat_shell_uart_cb(uint16_t len, void* user_data){
  18. int uartid = (int)user_data;
  19. char buff[512] = {0};
  20. if(uartid >= 100)
  21. {
  22. int l = 1;
  23. while (l > 0) {
  24. l = luat_uart_read(0, buff, 512);
  25. //printf("uart read buff %d %s\n", l, buff);
  26. if (l > 0){
  27. // luat_shell_push(buff, l);
  28. tls_os_queue_send(shell_queue, (void *)buff, sizeof(rtos_msg_t));
  29. }
  30. }
  31. }
  32. return 0;
  33. }
  34. extern void luat_cmux_read(unsigned char* buff,size_t len);
  35. static void luat_shell(void *sdata){
  36. void* msg;
  37. while (1) {
  38. tls_os_queue_receive(shell_queue, (void **) &msg, 0, 0);
  39. // printf("uart read buff %s\n", (char*)msg);
  40. luat_shell_push((char*)msg, strlen(msg));
  41. }
  42. }
  43. #define TASK_START_STK_SIZE 2048
  44. static OS_STK __attribute__((aligned(4))) TaskStartStk[TASK_START_STK_SIZE] = {0};
  45. void luat_shell_poweron(int _drv) {
  46. tls_uart_rx_callback_register(0, luat_shell_uart_cb, NULL);
  47. tls_os_queue_create(&shell_queue, 2048);
  48. tls_os_task_create(NULL, NULL,
  49. luat_shell,
  50. NULL,
  51. (void *)TaskStartStk, /* task's stack start address */
  52. TASK_START_STK_SIZE * sizeof(u32), /* task's stack size, unit:byte */
  53. 31,
  54. 0);
  55. }