luat_shell_air101.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. typedef struct {
  8. size_t len;
  9. char buff[0];
  10. }uart_data;
  11. void luat_shell_write(char* buff, size_t len) {
  12. int i=0;
  13. while (i < len){
  14. while(tls_reg_read32(HR_UART0_FIFO_STATUS) & 0x3F);
  15. tls_reg_write32(HR_UART0_TX_WIN, (unsigned int)buff[i++]);
  16. }
  17. }
  18. void luat_shell_notify_recv(void) {
  19. }
  20. static tls_os_queue_t *shell_queue = NULL;
  21. static int16_t luat_shell_uart_cb(uint16_t len, void* user_data){
  22. int uartid = (int)user_data;
  23. char buff[512] = {0};
  24. if(uartid >= 100)
  25. {
  26. int l = 1;
  27. while (l > 0) {
  28. l = luat_uart_read(0, buff, 512);
  29. //printf("uart read buff %d %s\n", l, buff);
  30. if (l > 0){
  31. // luat_shell_push(buff, l);
  32. uart_data* send_buf = (uart_data*)luat_heap_malloc(sizeof(uart_data)+l);
  33. send_buf->len = l;
  34. memcpy(send_buf->buff, buff, l);
  35. tls_os_queue_send(shell_queue, (void *)send_buf, sizeof(uart_data)+l);
  36. }
  37. }
  38. }
  39. return 0;
  40. }
  41. static void luat_shell(void *sdata){
  42. uart_data* receive_buf;
  43. while (1) {
  44. tls_os_queue_receive(shell_queue, (void **) &receive_buf, 0, 0);
  45. // printf("uart read buff %s\n", (char*)msg);
  46. luat_shell_push(receive_buf->buff, receive_buf->len);
  47. luat_heap_free(receive_buf);
  48. }
  49. }
  50. #define TASK_START_STK_SIZE 2048
  51. static OS_STK __attribute__((aligned(4))) TaskStartStk[TASK_START_STK_SIZE] = {0};
  52. void luat_shell_poweron(int _drv) {
  53. tls_uart_rx_callback_register(0, luat_shell_uart_cb, NULL);
  54. tls_os_queue_create(&shell_queue, 2048);
  55. tls_os_task_create(NULL, NULL,
  56. luat_shell,
  57. NULL,
  58. (void *)TaskStartStk, /* task's stack start address */
  59. TASK_START_STK_SIZE * sizeof(u32), /* task's stack size, unit:byte */
  60. 10,
  61. 0);
  62. }