gps_os.c
上传用户:yj_qqy
上传日期:2017-01-28
资源大小:2911k
文件大小:10k
- #include <includes.h>
- #if (GPS_MODULE == DEF_ENABLED)
- /*
- *********************************************************************************************************
- * INITIALISE GPS COM PORT
- *********************************************************************************************************
- */
- void GPS_InitTarget ()
- {
- GPIO_InitTypeDef gpio_init;
- USART_InitTypeDef usart_init;
- USART_ClockInitTypeDef usart_clk_init;
- /* ----------------- INIT USART STRUCT ---------------- */
- usart_init.USART_BaudRate = 4800;
- usart_init.USART_WordLength = USART_WordLength_8b;
- usart_init.USART_StopBits = USART_StopBits_1;
- usart_init.USART_Parity = USART_Parity_No ;
- usart_init.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
- usart_init.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
- usart_clk_init.USART_Clock = USART_Clock_Disable;
- usart_clk_init.USART_CPOL = USART_CPOL_Low;
- usart_clk_init.USART_CPHA = USART_CPHA_2Edge;
- usart_clk_init.USART_LastBit = USART_LastBit_Disable;
- #if (GPS_COMM_SEL == GPS_UART_1)
- BSP_PeriphEn(BSP_PERIPH_ID_USART1);
- /* ----------------- SETUP USART1 GPIO ---------------- */
- BSP_PeriphEn(BSP_PERIPH_ID_IOPA);
- /* Configure GPIOA.9 as push-pull */
- gpio_init.GPIO_Pin = GPIO_Pin_9;
- gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
- gpio_init.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_Init(GPIOA, &gpio_init);
- /* Configure GPIOA.10 as input floating */
- gpio_init.GPIO_Pin = GPIO_Pin_10;
- gpio_init.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_Init(GPIOA, &gpio_init);
- /* ------------------ SETUP USART1 -------------------- */
- USART_Init(USART1, &usart_init);
- USART_ClockInit(USART1, &usart_clk_init);
- USART_Cmd(USART1, ENABLE);
- BSP_IntVectSet(BSP_INT_ID_USART1, GPS_RxTxISRHandler);
- BSP_IntEn(BSP_INT_ID_USART1);
- #endif
- #if (GPS_COMM_SEL == GPS_UART_2)
- BSP_PeriphEn(BSP_PERIPH_ID_USART2);
- /* ----------------- SETUP USART2 GPIO ---------------- */
- BSP_PeriphEn(BSP_PERIPH_ID_IOPA);
- /* Configure GPIOA.2 as push-pull */
- gpio_init.GPIO_Pin = GPIO_Pin_2;
- gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
- gpio_init.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_Init(GPIOA, &gpio_init);
- /* Configure GPIOA.3 as input floating */
- gpio_init.GPIO_Pin = GPIO_Pin_3;
- gpio_init.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_Init(GPIOA, &gpio_init);
- /* ------------------ SETUP USART2 -------------------- */
- USART_Init(USART2, &usart_init);
- USART_ClockInit(USART2, &usart_clk_init);
- USART_Cmd(USART2, ENABLE);
- BSP_IntVectSet(BSP_INT_ID_USART2, GPS_RxTxISRHandler);
- BSP_IntEn(BSP_INT_ID_USART2);
- #endif
- #if (GPS_COMM_SEL == GPS_UART_3)
- BSP_PeriphEn(BSP_PERIPH_ID_USART3);
- /* ----------------- SETUP USART3 GPIO ---------------- */
- BSP_PeriphEn(BSP_PERIPH_ID_IOPB);
- /* Configure GPIOB.10 as push-pull */
- gpio_init.GPIO_Pin = GPIO_Pin_10;
- gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
- gpio_init.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_Init(GPIOB, &gpio_init);
- /* Configure GPIOB.11 as input floating */
- gpio_init.GPIO_Pin = GPIO_Pin_11;
- gpio_init.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_Init(GPIOB, &gpio_init);
- /* ------------------ SETUP USART3 -------------------- */
- USART_Init(USART3, &usart_init);
- USART_ClockInit(USART3, &usart_clk_init);
- USART_Cmd(USART3, ENABLE);
- BSP_IntVectSet(BSP_INT_ID_USART3, GPS_RxTxISRHandler);
- BSP_IntEn(BSP_INT_ID_USART3);
- #endif
- }
- /*$PAGE*/
- /*
- *********************************************************************************************************
- * Disable Rx Interrupts
- *********************************************************************************************************
- */
- void GPS_RxIntDis (void)
- {
- #if (GPS_COMM_SEL == GPS_UART_1)
- USART_ITConfig(USART1, USART_IT_RXNE, DISABLE);
- #endif
- #if (GPS_COMM_SEL == GPS_UART_2)
- USART_ITConfig(USART2, USART_IT_RXNE, DISABLE);
- #endif
- #if (GPS_COMM_SEL == GPS_UART_3)
- USART_ITConfig(USART3, USART_IT_RXNE, DISABLE);
- #endif
- }
- /*
- *********************************************************************************************************
- * Enable Rx Interrupts
- *********************************************************************************************************
- */
- void GPS_RxIntEn (void)
- {
- #if (GPS_COMM_SEL == GPS_UART_1)
- USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
- #endif
- #if (GPS_COMM_SEL == GPS_UART_2)
- USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
- #endif
- #if (GPS_COMM_SEL == GPS_UART_3)
- USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
- #endif
- }
- /*
- *********************************************************************************************************
- * Rx Communication handler for GPS
- *
- * Description: This function is called by GPS_RxISR (see OS_VIEWa.ASM) to process a received
- * character interrupt.
- *
- * Note(s) : This adaptation of GPS assumes that a 'combined' interrupt is generated by the UART
- * and thus this function is not needed.
- *********************************************************************************************************
- */
- void GPS_RxISRHandler (void)
- {
- }
- /*
- *********************************************************************************************************
- * Rx/Tx Communication handler for GPS
- *
- * Description: This function is NOT called because the M16C has a separate Rx and Tx ISR.
- *********************************************************************************************************
- */
- void GPS_RxTxISRHandler (void)
- {
- USART_TypeDef *usart;
- CPU_INT08U rx_data;
- CPU_SR cpu_sr;
- CPU_CRITICAL_ENTER(); /* Tell uC/OS-II that we are starting an ISR */
- OSIntNesting++;
- CPU_CRITICAL_EXIT();
- #if (GPS_COMM_SEL == GPS_UART_1)
- usart = USART1;
- #elif (GPS_COMM_SEL == GPS_UART_2)
- usart = USART2;
- #elif (GPS_COMM_SEL == GPS_UART_3)
- usart = USART3;
- #else
- OSIntExit();
- return;
- #endif
- if (USART_GetITStatus(usart, USART_IT_RXNE) != RESET) {
- rx_data = USART_ReceiveData(usart) & 0xFF; /* Read one byte from the receive data register */
- GPS_RxHandler(rx_data);
- USART_ClearITPendingBit(usart, USART_IT_RXNE); /* Clear the USART1 Receive interrupt */
- }
- if (USART_GetITStatus(usart, USART_IT_TXE) != RESET) {
- GPS_TxHandler();
- USART_ClearITPendingBit(usart, USART_IT_TXE); /* Clear the USART1 transmit interrupt */
- }
- OSIntExit(); /* Tell uC/OS-II that we are leaving the ISR */
- }
- /*$PAGE*/
- /*
- *********************************************************************************************************
- * Communication for GPS
- *
- * Description: Send 1 character to COM Port
- *********************************************************************************************************
- */
- void GPS_Tx1 (INT8U c)
- {
- #if GPS_COMM_SEL == GPS_UART_1
- USART_SendData(USART1, c);
- #endif
- #if GPS_COMM_SEL == GPS_UART_2
- USART_SendData(USART2, c);
- #endif
- #if GPS_COMM_SEL == GPS_UART_3
- USART_SendData(USART3, c);
- #endif
- }
- /*$PAGE*/
- /*
- *********************************************************************************************************
- * Disable Tx Interrupts
- *********************************************************************************************************
- */
- void GPS_TxIntDis (void)
- {
- #if (GPS_COMM_SEL == GPS_UART_1)
- USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
- #endif
- #if (GPS_COMM_SEL == GPS_UART_2)
- USART_ITConfig(USART2, USART_IT_TXE, DISABLE);
- #endif
- #if (GPS_COMM_SEL == GPS_UART_3)
- USART_ITConfig(USART3, USART_IT_TXE, DISABLE);
- #endif
- }
- /*
- *********************************************************************************************************
- * Enable Tx Interrupts
- *********************************************************************************************************
- */
- void GPS_TxIntEn (void)
- {
- #if (GPS_COMM_SEL == GPS_UART_1)
- USART_ITConfig(USART1, USART_IT_TXE, ENABLE);
- #endif
- #if (GPS_COMM_SEL == GPS_UART_2)
- USART_ITConfig(USART2, USART_IT_TXE, ENABLE);
- #endif
- #if (GPS_COMM_SEL == GPS_UART_3)
- USART_ITConfig(USART3, USART_IT_TXE, ENABLE);
- #endif
- }
- #endif