bsp.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #include "includes.h"
  2. #define VIR_WAIT_FOREVER (-1U)
  3. LSAPI_OSI_Pipe_t *at_rx_pipe = NULL;
  4. LSAPI_OSI_Pipe_t *at_tx_pipe = NULL;
  5. void vir_at_process(char *buf,unsigned int len)
  6. {
  7. if(sutApp.gtTMode==1)MSG_INFO(1,"vir_at--->%s",buf);
  8. // if(msgCmp(buf, "SV")) {
  9. // strcpy(sutApp.modemVer, buf);
  10. // sutApp.modemVer[strlen(buf)-2]=0;
  11. // }
  12. pocCmdHandler(buf,len);//
  13. }
  14. //妯″潡搴旂瓟
  15. static void prvVirtAtRespCallback(void *param, unsigned event)
  16. {
  17. LSAPI_OSI_Pipe_t *pipe = (LSAPI_OSI_Pipe_t *)param;
  18. char buf[256];
  19. for (;;)
  20. {
  21. int bytes = LSAPI_OSI_PipeRead(pipe, buf, sizeof(buf)-1);
  22. if (bytes <= 0)
  23. break;
  24. buf[bytes] = '\0';
  25. // MSG_INFO(1,"VAT1:%d,%s",bytes,buf);
  26. vir_at_process(buf,bytes);
  27. }
  28. //MSG_INFO(1,"prvVirtAtRespCallback");
  29. }
  30. void makeupsample(void *param){
  31. at_rx_pipe = LSAPI_OSI_PipeCreate(1024);
  32. at_tx_pipe = LSAPI_OSI_PipeCreate(1024);//1024
  33. LSAPI_OSI_PipeSetReaderCallback(at_tx_pipe, LSAPI_PIPE_EVENT_RX_ARRIVED,
  34. prvVirtAtRespCallback, at_tx_pipe);
  35. LSAPI_Device_AtVirtConfig_t cfg = {
  36. .name = LSAPI_MAKE_TAG('V', 'A', 'T', '1'),
  37. .rx_pipe = at_rx_pipe,
  38. .tx_pipe = at_tx_pipe,
  39. };
  40. LSAPI_Device_t *device = LSAPI_Device_AtVirtCreate(&cfg);
  41. LSAPI_Device_AtDispatch_t *dispatch = LSAPI_Device_AtDispatchCreate(device);
  42. LSAPI_Device_AtSetDispatch(device, dispatch);
  43. LSAPI_Device_Open(device);
  44. LSAPI_OSI_ThreadExit();
  45. }
  46. void CreateSerialAtThead()
  47. {
  48. if(NULL==LSAPI_OSI_ThreadCreate("virat", makeupsample, NULL, LSAPI_OSI_PRIORITY_NORMAL, 1024, 4))
  49. MSG_INFO(1,"virat thread create err");
  50. LSAPI_OSI_ThreadSleep(500);
  51. }
  52. /*
  53. innerInfo
  54. 鍙戦€佹暟鎹�埌鍐呴儴(module)API
  55. */
  56. void innerInfo(unsigned char *info, unsigned int len){
  57. if(len>0){
  58. if(0>LSAPI_OSI_PipeWriteAll(at_rx_pipe, info, len, VIR_WAIT_FOREVER))
  59. MSG_INFO(1,"LSAPI_OSI_PipeWriteAll write failed");
  60. }
  61. }
  62. void ModemSendAt(char *p)
  63. {
  64. int len;
  65. len=strlen(p);
  66. innerInfo(p,len);
  67. }
  68. /*********************************************************************
  69. 硬件UART1 DET
  70. ********************************************************************/
  71. static LSAPI_Device_t *gDeviceUart = NULL;
  72. void Ble_SendAT(char *data,int len){
  73. LSAPI_Device_Write(gDeviceUart, data, len);
  74. }
  75. static void UART1_Init(void){
  76. uint8_t r_buffer[256] = {0x00};
  77. unsigned ShowBuf[100]={0};
  78. unsigned char temp[3]={0};
  79. int ret,i = 0;
  80. LSAPI_Device_UartConfig_t uart_cfg = {
  81. .name = LSAPI_DEV_UART1,
  82. .baud = 9600,
  83. .format = LSAPI_DEVICE_FORMAT_8N1,
  84. .parity = LSAPI_DEVICE_PARITY_ODD, };
  85. uart_cfg.event_cb = NULL ;//prvMenuUartEvtCb; uart_cfg.event_cb_ctx = NULL;
  86. //gUartWRTd;
  87. gDeviceUart = LSAPI_Device_UartCreate(&uart_cfg);
  88. if(gDeviceUart == NULL) {
  89. MSG_INFO(1,"uart: creat uart faild!");
  90. return ;
  91. }
  92. ret = LSAPI_Device_Open(gDeviceUart);
  93. if(!ret){
  94. MSG_INFO(1,"uart: Open uart Failed");
  95. return ;
  96. }
  97. while (1)
  98. {
  99. int read_avail_size = LSAPI_Device_ReadAvail(gDeviceUart);
  100. if (read_avail_size > 0) {
  101. int read_size = LSAPI_Device_Read(gDeviceUart, r_buffer, sizeof(r_buffer));
  102. if (read_size > 0)
  103. {
  104. for(i=0;i<read_size;i++){
  105. snprintf(temp,3,"%02x",r_buffer[i]);
  106. strcat(ShowBuf,temp);
  107. }
  108. usbOutPut(ShowBuf,strlen(ShowBuf));
  109. MSG_INFO(1,"uart1: read: {%s}", ShowBuf);
  110. BLE_at_process(r_buffer,read_size);
  111. read_size=0;
  112. memset(ShowBuf,0,sizeof(ShowBuf));
  113. }
  114. }
  115. }
  116. }
  117. void CreateUART1_Thread(void)
  118. {
  119. if(NULL==LSAPI_OSI_ThreadCreate("uart1", UART1_Init, NULL, LSAPI_OSI_PRIORITY_NORMAL, 1024*2, 4))
  120. MSG_INFO(1,"uart1 thread create err");
  121. LSAPI_OSI_ThreadSleep(500);
  122. }