diff --git a/src/gps.c b/src/gps.c --- a/src/gps.c +++ b/src/gps.c @@ -1,20 +1,12 @@ // TODO: Transition to using https://github.com/cuspaceflight/joey-m/blob/master/firmware/gps.c requesting UBX data + #include "stm32f0xx_hal.h" - #include #include "config.h" +#include "usart.h" #include "gps.h" -/* -void serial0_sendString(const char* string) { - while(*string != 0x00) - { - usart_send_blocking(USART1, *string); - string++; - } -} -*/ // Circular buffer for incoming data uint8_t nmeaBuffer[NMEABUFFER_SIZE]; @@ -44,13 +36,13 @@ char tramsmissionType[7]; void gps_poweron(void) { // NOTE: pchannel - HAL_GPIO_WritePin(GPS_ONOFF, 0); + gpio_clear(GPS_ONOFF); } void gps_poweroff(void) { // NOTE: pchannel - HAL_GPIO_WritePin(GPS_ONOFF, 1); + gpio_set(GPS_ONOFF); } char timestamp[12]; //hhmmss.ss @@ -111,9 +103,9 @@ char* get_gpsaltitude() return altitude; } -//char wgs84Height[8]; //sxxx.x -//char lastUpdated[8]; //blank - included for testing -//char stationID[8]; //blank - included for testing +char wgs84Height[8]; //sxxx.x +char lastUpdated[8]; //blank - included for testing +char stationID[8]; //blank - included for testing char checksum[3]; //xx char knots[8]; //xxx.xx @@ -180,24 +172,15 @@ enum decodeState { void usart1_isr(void) { -// uint8_t recv = usart_recv(GPS_USART); -// HAL_UART_Receive(huart1, uint8_t *pData, uint16_t Size, uint32_t Timeout); - + uint8_t recv = usart_recv(GPS_USART); //ECHO debug: usart_send_blocking(GPS_USART, recv); -// nmeaBuffer[nmeaBufferDataPosition % NMEABUFFER_SIZE] = recv; + nmeaBuffer[nmeaBufferDataPosition % NMEABUFFER_SIZE] = recv; nmeaBufferDataPosition = (nmeaBufferDataPosition + 1) % NMEABUFFER_SIZE; } - -UART_HandleTypeDef huart1; -DMA_HandleTypeDef hdma_usart1_rx; -DMA_HandleTypeDef hdma_usart1_tx; - - - - void gps_init() { + uart_init(); timestamp[0] = 0x00; latitude[0] = 0x00; longitude[0] = 0x00; @@ -207,66 +190,6 @@ void gps_init() course[0] = 0x00; dayofmonth[0] = 0x00; - // Initialize GPS pins - __GPIOF_CLK_ENABLE(); - GPIO_InitTypeDef GPIO_InitStruct; - GPIO_InitStruct.Pin = GPS_ONOFF_PIN; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_LOW; - HAL_GPIO_Init(GPS_ONOFF_PORT, &GPIO_InitStruct); - - - __USART1_CLK_ENABLE(); - GPIO_InitStruct.Pin = GPS_TX_PIN|GPS_RX_PIN; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_PULLUP; - GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; - GPIO_InitStruct.Alternate = GPIO_AF0_USART1; - HAL_GPIO_Init(GPS_RXTX_PORT, &GPIO_InitStruct); - -/* - hdma_usart1_rx.Instance = DMA1_Channel3; - hdma_usart1_rx.Init.Direction = DMA_PERIPH_TO_MEMORY; - hdma_usart1_rx.Init.PeriphInc = DMA_PINC_DISABLE; - hdma_usart1_rx.Init.MemInc = DMA_MINC_DISABLE; - hdma_usart1_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; - hdma_usart1_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; - hdma_usart1_rx.Init.Mode = DMA_CIRCULAR; - hdma_usart1_rx.Init.Priority = DMA_PRIORITY_LOW; - HAL_DMA_Init(&hdma_usart1_rx); - - __HAL_LINKDMA(huart,hdmarx,hdma_usart1_rx); - - hdma_usart1_tx.Instance = DMA1_Channel2; - hdma_usart1_tx.Init.Direction = DMA_MEMORY_TO_PERIPH; - hdma_usart1_tx.Init.PeriphInc = DMA_PINC_DISABLE; - hdma_usart1_tx.Init.MemInc = DMA_MINC_DISABLE; - hdma_usart1_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; - hdma_usart1_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; - hdma_usart1_tx.Init.Mode = DMA_NORMAL; - hdma_usart1_tx.Init.Priority = DMA_PRIORITY_LOW; - HAL_DMA_Init(&hdma_usart1_tx); - - __HAL_LINKDMA(huart,hdmatx,hdma_usart1_tx); -*/ -// HAL_NVIC_SetPriority(USART1_IRQn, 0, 0); -// HAL_NVIC_EnableIRQ(USART1_IRQn); - - - huart1.Instance = USART1; - huart1.Init.BaudRate = 9600; - huart1.Init.WordLength = UART_WORDLENGTH_8B; - huart1.Init.StopBits = UART_STOPBITS_1; - huart1.Init.Parity = UART_PARITY_NONE; - huart1.Init.Mode = UART_MODE_TX_RX; - huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; - huart1.Init.OverSampling = UART_OVERSAMPLING_16; - huart1.Init.OneBitSampling = UART_ONEBIT_SAMPLING_DISABLED ; - huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; - HAL_UART_Init(&huart1); - - gps_poweron(); HAL_Delay(100); // Make sure GPS is awake and alive @@ -286,10 +209,13 @@ void gps_init() } - void gps_sendubx(uint8_t* dat, uint8_t size) { - HAL_UART_Transmit(&huart1, dat, size, 100); + uint8_t sendctr; + for(sendctr = 0; sendctr < size; sendctr++) + { + usart_send(GPS_USART, dat[sendctr]); + } } // Could inline if program space available @@ -310,7 +236,7 @@ static void setParserState(uint8_t state //// MKa GPS transmission parser START -void gps_process(void){ +void parse_gps_transmission(void){ // Pull byte off of the buffer char byte; @@ -530,14 +456,14 @@ void gps_process(void){ } else if(byte == ',') //end of this data type { - //wgs84Height[numBytes] = 0x00; + wgs84Height[numBytes] = 0x00; setParserState(GGA_LAST_UPDATE); skipBytes = 0; //prep for next phase of parse numBytes = 0; } else //store data { - //wgs84Height[numBytes] = byte; //adjust number of bytes to fit array + wgs84Height[numBytes] = byte; //adjust number of bytes to fit array numBytes++; setParserState(GGA_WGS84); } @@ -548,13 +474,13 @@ void gps_process(void){ { if (byte == ',') //end of this data type { - //lastUpdated[numBytes] = 0x00; + lastUpdated[numBytes] = 0x00; setParserState(GGA_STATION_ID); numBytes = 0; //prep for next phase of parse } else //store data - this should be blank { - //lastUpdated[numBytes] = byte; //adjust number of bytes to fit array + lastUpdated[numBytes] = byte; //adjust number of bytes to fit array numBytes++; setParserState(GGA_LAST_UPDATE); } @@ -565,13 +491,13 @@ void gps_process(void){ { if (byte == ',' || byte == '*') //end of this data type { - //stationID[numBytes] = 0x00; + stationID[numBytes] = 0x00; setParserState(GPS_CHECKSUM); numBytes = 0; //prep for next phase of parse } else //store data - this should be blank { - //stationID[numBytes] = byte; //adjust number of bytes to fit array + stationID[numBytes] = byte; //adjust number of bytes to fit array numBytes++; setParserState(GGA_STATION_ID); }