gps_os.c
上传用户:yj_qqy
上传日期:2017-01-28
资源大小:2911k
文件大小:10k
源码类别:

uCOS

开发平台:

C/C++

  1. #include <includes.h>
  2. #if (GPS_MODULE == DEF_ENABLED)
  3. /*
  4. *********************************************************************************************************
  5. *                                    INITIALISE GPS COM PORT
  6. *********************************************************************************************************
  7. */
  8. void  GPS_InitTarget ()
  9. {
  10.     GPIO_InitTypeDef        gpio_init;
  11.     USART_InitTypeDef       usart_init;
  12.     USART_ClockInitTypeDef  usart_clk_init;
  13.                                                                 /* ----------------- INIT USART STRUCT ---------------- */
  14.     usart_init.USART_BaudRate            = 4800;
  15.     usart_init.USART_WordLength          = USART_WordLength_8b;
  16.     usart_init.USART_StopBits            = USART_StopBits_1;
  17.     usart_init.USART_Parity              = USART_Parity_No ;
  18.     usart_init.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  19.     usart_init.USART_Mode                = USART_Mode_Rx | USART_Mode_Tx;
  20.     usart_clk_init.USART_Clock           = USART_Clock_Disable;
  21.     usart_clk_init.USART_CPOL            = USART_CPOL_Low;
  22.     usart_clk_init.USART_CPHA            = USART_CPHA_2Edge;
  23.     usart_clk_init.USART_LastBit         = USART_LastBit_Disable;
  24. #if (GPS_COMM_SEL == GPS_UART_1)
  25.     BSP_PeriphEn(BSP_PERIPH_ID_USART1);
  26.                                                                 /* ----------------- SETUP USART1 GPIO ---------------- */
  27.     BSP_PeriphEn(BSP_PERIPH_ID_IOPA);
  28.                                                                 /* Configure GPIOA.9 as push-pull                       */
  29.     gpio_init.GPIO_Pin   = GPIO_Pin_9;
  30.     gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
  31.     gpio_init.GPIO_Mode  = GPIO_Mode_AF_PP;
  32.     GPIO_Init(GPIOA, &gpio_init);
  33.                                                                 /* Configure GPIOA.10 as input floating                 */
  34.     gpio_init.GPIO_Pin   = GPIO_Pin_10;
  35.     gpio_init.GPIO_Mode  = GPIO_Mode_IN_FLOATING;
  36.     GPIO_Init(GPIOA, &gpio_init);
  37.                                                                 /* ------------------ SETUP USART1 -------------------- */
  38.     USART_Init(USART1, &usart_init);
  39.     USART_ClockInit(USART1, &usart_clk_init);
  40.     USART_Cmd(USART1, ENABLE);
  41.     BSP_IntVectSet(BSP_INT_ID_USART1, GPS_RxTxISRHandler);
  42.     BSP_IntEn(BSP_INT_ID_USART1);
  43. #endif
  44. #if (GPS_COMM_SEL == GPS_UART_2)
  45.     BSP_PeriphEn(BSP_PERIPH_ID_USART2);
  46.                                                                 /* ----------------- SETUP USART2 GPIO ---------------- */
  47.     BSP_PeriphEn(BSP_PERIPH_ID_IOPA);
  48.                                                                 /* Configure GPIOA.2 as push-pull                       */
  49.     gpio_init.GPIO_Pin   = GPIO_Pin_2;
  50.     gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
  51.     gpio_init.GPIO_Mode  = GPIO_Mode_AF_PP;
  52.     GPIO_Init(GPIOA, &gpio_init);
  53.                                                                 /* Configure GPIOA.3 as input floating                  */
  54.     gpio_init.GPIO_Pin   = GPIO_Pin_3;
  55.     gpio_init.GPIO_Mode  = GPIO_Mode_IN_FLOATING;
  56.     GPIO_Init(GPIOA, &gpio_init);
  57.                                                                 /* ------------------ SETUP USART2 -------------------- */
  58.     USART_Init(USART2, &usart_init);
  59.     USART_ClockInit(USART2, &usart_clk_init);
  60.     USART_Cmd(USART2, ENABLE);
  61.     BSP_IntVectSet(BSP_INT_ID_USART2, GPS_RxTxISRHandler);
  62.     BSP_IntEn(BSP_INT_ID_USART2);
  63. #endif
  64. #if (GPS_COMM_SEL == GPS_UART_3)
  65.     BSP_PeriphEn(BSP_PERIPH_ID_USART3);
  66.                                                                 /* ----------------- SETUP USART3 GPIO ---------------- */
  67.     BSP_PeriphEn(BSP_PERIPH_ID_IOPB);
  68.                                                                 /* Configure GPIOB.10 as push-pull                      */
  69.     gpio_init.GPIO_Pin   = GPIO_Pin_10;
  70.     gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
  71.     gpio_init.GPIO_Mode  = GPIO_Mode_AF_PP;
  72.     GPIO_Init(GPIOB, &gpio_init);
  73.                                                                 /* Configure GPIOB.11 as input floating                 */
  74.     gpio_init.GPIO_Pin   = GPIO_Pin_11;
  75.     gpio_init.GPIO_Mode  = GPIO_Mode_IN_FLOATING;
  76.     GPIO_Init(GPIOB, &gpio_init);
  77.                                                                 /* ------------------ SETUP USART3 -------------------- */
  78.     USART_Init(USART3, &usart_init);
  79.     USART_ClockInit(USART3, &usart_clk_init);
  80.     USART_Cmd(USART3, ENABLE);
  81.     BSP_IntVectSet(BSP_INT_ID_USART3, GPS_RxTxISRHandler);
  82.     BSP_IntEn(BSP_INT_ID_USART3);
  83. #endif
  84. }
  85. /*$PAGE*/
  86. /*
  87. *********************************************************************************************************
  88. *                                       Disable Rx Interrupts
  89. *********************************************************************************************************
  90. */
  91. void  GPS_RxIntDis (void)
  92. {
  93. #if (GPS_COMM_SEL == GPS_UART_1)
  94.     USART_ITConfig(USART1, USART_IT_RXNE, DISABLE);
  95. #endif
  96. #if (GPS_COMM_SEL == GPS_UART_2)
  97.     USART_ITConfig(USART2, USART_IT_RXNE, DISABLE);
  98. #endif
  99. #if (GPS_COMM_SEL == GPS_UART_3)
  100.     USART_ITConfig(USART3, USART_IT_RXNE, DISABLE);
  101. #endif
  102. }
  103. /*
  104. *********************************************************************************************************
  105. *                                       Enable Rx Interrupts
  106. *********************************************************************************************************
  107. */
  108. void  GPS_RxIntEn (void)
  109. {
  110. #if (GPS_COMM_SEL == GPS_UART_1)
  111.     USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
  112. #endif
  113. #if (GPS_COMM_SEL == GPS_UART_2)
  114.     USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
  115. #endif
  116. #if (GPS_COMM_SEL == GPS_UART_3)
  117.     USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
  118. #endif
  119. }
  120. /*
  121. *********************************************************************************************************
  122. *                                 Rx Communication handler for GPS
  123. *
  124. * Description: This function is called by GPS_RxISR (see OS_VIEWa.ASM) to process a received
  125. *              character interrupt.
  126. *
  127. * Note(s)    : This adaptation of GPS assumes that a 'combined' interrupt is generated by the UART
  128. *              and thus this function is not needed.
  129. *********************************************************************************************************
  130. */
  131. void  GPS_RxISRHandler (void)
  132. {
  133. }
  134. /*
  135. *********************************************************************************************************
  136. *                                Rx/Tx Communication handler for GPS
  137. *
  138. * Description: This function is NOT called because the M16C has a separate Rx and Tx ISR.
  139. *********************************************************************************************************
  140. */
  141. void  GPS_RxTxISRHandler (void)
  142. {
  143.     USART_TypeDef  *usart;
  144.     CPU_INT08U      rx_data;
  145.     CPU_SR          cpu_sr;
  146.     CPU_CRITICAL_ENTER();                                       /* Tell uC/OS-II that we are starting an ISR            */
  147.     OSIntNesting++;
  148.     CPU_CRITICAL_EXIT();
  149. #if   (GPS_COMM_SEL == GPS_UART_1)
  150.     usart = USART1;
  151. #elif (GPS_COMM_SEL == GPS_UART_2)
  152.     usart = USART2;
  153. #elif (GPS_COMM_SEL == GPS_UART_3)
  154.     usart = USART3;
  155. #else
  156.     OSIntExit();
  157.     return;
  158. #endif
  159.     if (USART_GetITStatus(usart, USART_IT_RXNE) != RESET) {
  160.         rx_data = USART_ReceiveData(usart) & 0xFF;              /* Read one byte from the receive data register         */
  161.         GPS_RxHandler(rx_data);
  162.         USART_ClearITPendingBit(usart, USART_IT_RXNE);          /* Clear the USART1 Receive interrupt                   */
  163.     }
  164.     if (USART_GetITStatus(usart, USART_IT_TXE) != RESET) {
  165.         GPS_TxHandler();
  166.         USART_ClearITPendingBit(usart, USART_IT_TXE);           /* Clear the USART1 transmit interrupt                  */
  167.     }
  168.     OSIntExit();                                                /* Tell uC/OS-II that we are leaving the ISR            */
  169. }
  170. /*$PAGE*/
  171. /*
  172. *********************************************************************************************************
  173. *                                      Communication for GPS
  174. *
  175. * Description: Send 1 character to COM Port
  176. *********************************************************************************************************
  177. */
  178. void  GPS_Tx1 (INT8U c)
  179. {
  180. #if GPS_COMM_SEL == GPS_UART_1
  181. USART_SendData(USART1, c);
  182. #endif
  183. #if GPS_COMM_SEL == GPS_UART_2
  184. USART_SendData(USART2, c);
  185. #endif
  186. #if GPS_COMM_SEL == GPS_UART_3
  187. USART_SendData(USART3, c);
  188. #endif
  189. }
  190. /*$PAGE*/
  191. /*
  192. *********************************************************************************************************
  193. *                                       Disable Tx Interrupts
  194. *********************************************************************************************************
  195. */
  196. void  GPS_TxIntDis (void)
  197. {
  198. #if (GPS_COMM_SEL == GPS_UART_1)
  199.     USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
  200. #endif
  201. #if (GPS_COMM_SEL == GPS_UART_2)
  202.     USART_ITConfig(USART2, USART_IT_TXE, DISABLE);
  203. #endif
  204. #if (GPS_COMM_SEL == GPS_UART_3)
  205.     USART_ITConfig(USART3, USART_IT_TXE, DISABLE);
  206. #endif
  207. }
  208. /*
  209. *********************************************************************************************************
  210. *                                       Enable Tx Interrupts
  211. *********************************************************************************************************
  212. */
  213. void  GPS_TxIntEn (void)
  214. {
  215. #if (GPS_COMM_SEL == GPS_UART_1)
  216.     USART_ITConfig(USART1, USART_IT_TXE, ENABLE);
  217. #endif
  218. #if (GPS_COMM_SEL == GPS_UART_2)
  219.     USART_ITConfig(USART2, USART_IT_TXE, ENABLE);
  220. #endif
  221. #if (GPS_COMM_SEL == GPS_UART_3)
  222.     USART_ITConfig(USART3, USART_IT_TXE, ENABLE);
  223. #endif
  224. }
  225. #endif