Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.32 KB | None | 0 0
  1. #include <stdint.h>
  2. #include <assert.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include "LPC177x_8x.h"
  7. #include "system_LPC177x_8x.h"
  8. #include <retarget.h>
  9. #include "at.h"
  10. #include <DRV\drv_sdram.h>
  11. #include <DRV\drv_lcd.h>
  12. #include <DRV\drv_uart.h>
  13. #include <DRV\drv_touchscreen.h>
  14. #include <DRV\drv_led.h>
  15. #include <utils\timer_software.h>
  16. #include <utils\timer_software_init.h>
  17. struct at_parser at_parser;
  18.  
  19. char* at_command_simple="AT\r\n";
  20. char* at_command_csq = "AT+CSQ\r\n";
  21.  
  22. timer_software_handler_t my_timer_handler;
  23. LCD_PIXEL foreground = {0, 255, 0, 0};
  24. LCD_PIXEL background = {0, 0, 0, 0};
  25. void timer_callback_1(timer_software_handler_t h)
  26. {
  27.  
  28. }
  29. void testLCD()
  30. {
  31. uint32_t i,j;
  32. LCD_PIXEL foreground = {0, 255, 0, 0};
  33. LCD_PIXEL background = {0, 0, 0, 0};
  34.  
  35.  
  36. for (i = 0; i < LCD_HEIGHT; i++)
  37. {
  38. for (j = 0; j < LCD_WIDTH / 3; j++)
  39. {
  40. DRV_LCD_PutPixel(i, j, 255, 0, 0);
  41. }
  42. for (j = LCD_WIDTH / 3; j < 2 * (LCD_WIDTH / 3); j++)
  43. {
  44. DRV_LCD_PutPixel(i, j, 230, 220, 0);
  45. }
  46. for (j = 2 * (LCD_WIDTH / 3); j < LCD_WIDTH; j++)
  47. {
  48. DRV_LCD_PutPixel(i, j, 0, 0, 255);
  49. }
  50. }
  51. DRV_LCD_Puts("Hello", 20, 30, foreground, background, TRUE);
  52. DRV_LCD_Puts("Hello", 20, 60, foreground, background, FALSE);
  53.  
  54.  
  55. }
  56.  
  57. void TouchScreenCallBack(TouchResult* touchData)
  58. {
  59. printf("touched X=%3d Y=%3d\n", touchData->X, touchData->Y);
  60.  
  61. }
  62.  
  63. void BoardInit()
  64. {
  65. timer_software_handler_t handler;
  66.  
  67. TIMER_SOFTWARE_init_system();
  68.  
  69.  
  70. DRV_SDRAM_Init();
  71.  
  72. initRetargetDebugSystem();
  73. DRV_LCD_Init();
  74. DRV_LCD_ClrScr();
  75. DRV_LCD_PowerOn();
  76.  
  77. DRV_TOUCHSCREEN_Init();
  78. DRV_TOUCHSCREEN_SetTouchCallback(TouchScreenCallBack);
  79. //DRV_LCD_Puts(at_command_csq, 20, 30, foreground, background, TRUE);
  80. DRV_LED_Init();
  81. printf ("Hello\n");
  82.  
  83. handler = TIMER_SOFTWARE_request_timer();
  84. TIMER_SOFTWARE_configure_timer(handler, MODE_1, 100, 1);
  85. TIMER_SOFTWARE_set_callback(handler, timer_callback_1);
  86. TIMER_SOFTWARE_start_timer(handler);
  87. }
  88.  
  89.  
  90. void SendCommand(const char *command)
  91. {
  92. DRV_UART_FlushRX(UART_3);
  93. DRV_UART_FlushTX(UART_3);
  94. DRV_UART_Write(UART_3, (uint8_t*)command, strlen(command));
  95. }
  96.  
  97.  
  98. void GetCommandResponse() {
  99.  
  100. int parser_response;
  101. uint8_t ch;
  102. BOOLEAN ready = false;
  103. my_timer_handler = TIMER_SOFTWARE_request_timer();
  104. TIMER_SOFTWARE_configure_timer(my_timer_handler, MODE_1, 1000, true);
  105. TIMER_SOFTWARE_start_timer(my_timer_handler);
  106. TIMER_SOFTWARE_reset_timer(my_timer_handler);
  107. TIMER_SOFTWARE_start_timer(my_timer_handler);
  108. while ((!TIMER_SOFTWARE_interrupt_pending(my_timer_handler)) && (ready == FALSE))
  109. {
  110. while (DRV_UART_BytesAvailable(UART_3) > 0)
  111. {
  112. DRV_UART_ReadByte(UART_3, &ch);
  113. parser_response = parse(ch);
  114. if (parser_response == 2 || parser_response == 1)
  115. {
  116. ready = TRUE;
  117. at_parser = getData();
  118. }
  119. }
  120. }
  121. }
  122.  
  123. void ExecuteCommand(const char *command)
  124. {
  125. SendCommand(command);
  126. GetCommandResponse();
  127. }
  128.  
  129.  
  130. int ExtractData()
  131. {
  132. int j = 0;
  133. int flag =0, rezultat=0;
  134. for(j=0;j<strlen(at_parser.data[0]);j++)
  135. {
  136. if(at_parser.data[0][j] == ':')
  137. flag = 1;
  138.  
  139. if(flag == 1)
  140. {
  141. j++;
  142. rezultat = atoi(&at_parser.data[0][j]);
  143. }
  144.  
  145. }
  146. return rezultat;
  147.  
  148. }
  149.  
  150. int CommandResponseValid()
  151. {
  152. if(at_parser.response == 1)
  153. return 0;
  154. else return 1;
  155.  
  156. }
  157.  
  158. int ConvertAsuToDbmw(uint32_t arg) {
  159. int val = 2 * arg - 113;
  160. return val;
  161. }
  162. int main(void)
  163. {
  164. timer_software_handler_t handler1;
  165. int i;
  166. uint32_t rssi_value_asu;
  167. uint32_t rssi_value_dbmw;
  168.  
  169. BoardInit();
  170. //testLCD();
  171. handler1 = TIMER_SOFTWARE_request_timer();
  172. DRV_UART_Configure(UART_3, UART_CHARACTER_LENGTH_8, 115200, UART_PARITY_NO_PARITY, 1, TRUE, 3);
  173. DRV_UART_Configure(UART_2, UART_CHARACTER_LENGTH_8, 115200, UART_PARITY_NO_PARITY, 1, TRUE, 3);
  174. TIMER_SOFTWARE_configure_timer(handler1, MODE_1, 1000, true);
  175. TIMER_SOFTWARE_start_timer(handler1);
  176.  
  177.  
  178. for(i=0;i<3;i++)
  179. {
  180. DRV_UART_Write(UART_3, (uint8_t*)at_command_simple, strlen(at_command_simple));
  181. TIMER_SOFTWARE_Wait(1000);
  182. }
  183.  
  184. while(1)
  185. {
  186.  
  187. if(TIMER_SOFTWARE_interrupt_pending(handler1) != 0)
  188. {
  189.  
  190. ExecuteCommand(at_command_csq);
  191. if (CommandResponseValid())
  192. {
  193. rssi_value_asu = ExtractData();
  194. rssi_value_dbmw = ConvertAsuToDbmw(rssi_value_asu);
  195. DRV_LCD_Puts((char*)rssi_value_asu, 20, 30, foreground, background, TRUE);
  196.  
  197. }
  198.  
  199. TIMER_SOFTWARE_clear_interrupt(handler1);
  200. }
  201.  
  202.  
  203.  
  204.  
  205. }
  206.  
  207.  
  208.  
  209. /*while(1)
  210. {
  211. DRV_LED_Toggle(LED_4);
  212.  
  213. }
  214. while(1)
  215. {
  216. DRV_UART_SendByte(UART_3, 'A');
  217. // TIMER_SOFTWARE_Wait(1000);
  218. }
  219.  
  220.  
  221. while(1)
  222. {
  223. if (DRV_UART_ReadByte(UART_3, &ch) == OK)
  224. {
  225. DRV_UART_SendByte(UART_3, ch);
  226. }
  227. }
  228.  
  229. while(1)
  230. {
  231. if (DRV_UART_ReadByte(UART_0, &ch) == OK)
  232. {
  233. DRV_UART_SendByte(UART_3, ch);
  234. }
  235. if (DRV_UART_ReadByte(UART_3, &ch) == OK)
  236. {
  237. DRV_UART_SendByte(UART_0, ch);
  238. }
  239. if (DRV_UART_ReadByte(UART_2, &ch) == OK)
  240. {
  241. DRV_UART_SendByte(UART_0, ch);
  242. }
  243. }
  244.  
  245. while(1)
  246. {
  247. DRV_UART_Process();
  248. DRV_TOUCHSCREEN_Process();
  249. }*/
  250.  
  251. //return 0;
  252. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement