//***************************************************************************** // //! Sends data over the UART port. //! //! \param pucData is the buffer containing the data to write out to the UART //! port. //! \param ulSize is the number of bytes provided in \e pucData buffer that //! will be written out to the UART port. //! //! This function sends \e ulSize bytes of data from the buffer pointed to by //! \e pucData via the UART port. //! //! \return None. // //***************************************************************************** void UARTSend(const unsigned char *pucData, unsigned long ulSize) { // // Transmit the number of bytes requested on the UART port. // while(ulSize--) { // // Make sure that the transmit FIFO is not full. // while((HWREG(UART0_BASE + UART_O_FR) & UART_FR_TXFF)) { } // // Send out the next byte. // HWREG(UART0_BASE + UART_O_DR) = *pucData++; } // // Wait until the UART is done transmitting. // UARTFlush(); }
//***************************************************************************** // //! Sends data over the UART port. //! //! \param pui8Data is the buffer containing the data to write out to the UART //! port. //! \param ui32Size is the number of bytes provided in \e pui8Data buffer that //! will be written out to the UART port. //! //! This function sends \e ui32Size bytes of data from the buffer pointed to by //! \e pui8Data via the UART port. //! //! \return None. // //***************************************************************************** void UARTSend(const uint8_t *pui8Data, uint32_t ui32Size) { // // Transmit the number of bytes requested on the UART port. // while(ui32Size--) { // // Make sure that the transmit FIFO is not full. // while((HWREG(UARTx_BASE + UART_O_FR) & UART_FR_TXFF)) { } // // Send out the next byte. // HWREG(UARTx_BASE + UART_O_DR) = *pui8Data++; } // // Wait until the UART is done transmitting. // UARTFlush(); }
/** * static int Gps_set(void * _self, va_list *app) - Perform a new gps acquisition. * \param *_self - pointer to the device * \param *app - none * \return: <LI><Breturn = 0:</B>when the GPS device is connected on a Grove nest DIG port, with or without a valid connection </LI> <LI><Breturn = -1:</B>when the GPS device is not connected on a Grove nest DIG port. </LI> </UL> */ static int Gps_set(void *_self,va_list *app) { struct Gps *self = _self; char gps_sentences[70]; unsigned int timer = 65000; flag = 1; nmea_zero_INFO(&self->info); nmea_parser_init(&self->parser); UARTOn(self->uart_module); UARTFlush(self->uart_module); vTaskDelay(50); while((UARTBufferSize(self->uart_module)<3) && timer) timer--; if(!timer) return -1; timer = 500; while((gps_sentences[0] != '$') && timer) { timer--; while(UARTBufferSize(self->uart_module)<1); UARTRead(self->uart_module,gps_sentences,1); if(gps_sentences[0] == '$') { while(UARTBufferSize(self->uart_module) < 5); UARTRead(self->uart_module,(gps_sentences+1),5); //Reads all the chars in the if((gps_sentences[4] == 'M')) { while(UARTBufferSize(self->uart_module) < 65); UARTRead(self->uart_module,(gps_sentences+6),64); //Reads all the chars in the gps_sentences[70] = '\0'; int i = 0; i = nmea_parse(&self->parser, gps_sentences, (int)strlen(gps_sentences), &self->info); if(i) { flag = 0; self->lat = nmea_ndeg2degree (self->info.lat); self->lon = -nmea_ndeg2degree (self->info.lon); self->year = self->info.utc.year+1900; self->mon = self->info.utc.mon; self->day = self->info.utc.day; self->hour = self->info.utc.hour; self->min = self->info.utc.min; self->sec = self->info.utc.sec; self->speed = self->info.speed; break; } } } gps_sentences[0]= 0; } nmea_parser_destroy(&self->parser); UARTOff(self->uart_module); return 0; }