bsp.c 4.2 KB

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