Extending MDx GPS driver also to MD-UV3x0 and MD-9600 targets.

This commit is contained in:
Silvano Seva 2021-02-10 21:36:54 +01:00
parent ebaee7b113
commit 2fbf5fcdeb
4 changed files with 54 additions and 11 deletions

View File

@ -217,6 +217,7 @@ mduv380_src = src + stm32f405_src + ['platform/drivers/display/HX8353_MDx.c',
'platform/drivers/ADC/ADC1_MDx.c', 'platform/drivers/ADC/ADC1_MDx.c',
'platform/drivers/tones/toneGenerator_MDx.c', 'platform/drivers/tones/toneGenerator_MDx.c',
'platform/drivers/baseband/radio_UV3x0.c', 'platform/drivers/baseband/radio_UV3x0.c',
'platform/drivers/GPS/GPS_MDx.c',
'platform/targets/MD-UV380/platform.c'] 'platform/targets/MD-UV380/platform.c']
mduv380_inc = inc + stm32f405_inc + ['platform/targets/MD-UV380'] mduv380_inc = inc + stm32f405_inc + ['platform/targets/MD-UV380']

View File

@ -25,7 +25,7 @@
#include <string.h> #include <string.h>
#include <os.h> #include <os.h>
static int8_t detectStatus = -1; int8_t detectStatus = -1;
size_t bufPos = 0; size_t bufPos = 0;
size_t maxPos = 0; size_t maxPos = 0;
char *dataBuf; char *dataBuf;
@ -34,11 +34,21 @@ bool receiving = false;
OS_FLAG_GRP sentenceReady; OS_FLAG_GRP sentenceReady;
OS_ERR err; OS_ERR err;
#ifdef PLATFORM_MD3x0
#define PORT USART3
#else
#define PORT USART1
#endif
#ifdef PLATFORM_MD3x0
void __attribute__((used)) USART3_IRQHandler() void __attribute__((used)) USART3_IRQHandler()
#else
void __attribute__((used)) USART1_IRQHandler()
#endif
{ {
if(USART3->SR & USART_SR_RXNE) if(PORT->SR & USART_SR_RXNE)
{ {
char value = USART3->DR; char value = PORT->DR;
if((receiving == false) && (value == '$') && (bufPos == 0)) if((receiving == false) && (value == '$') && (bufPos == 0))
{ {
@ -70,7 +80,7 @@ void __attribute__((used)) USART3_IRQHandler()
} }
} }
USART3->SR = 0; PORT->SR = 0;
} }
@ -80,17 +90,27 @@ void gps_init(const uint16_t baud)
gpio_setMode(GPS_DATA, ALTERNATE); gpio_setMode(GPS_DATA, ALTERNATE);
gpio_setAlternateFunction(GPS_DATA, 7); gpio_setAlternateFunction(GPS_DATA, 7);
#ifdef PLATFORM_MD3x0
const unsigned int quot = 2*42000000/baud; /* APB1 clock is 42MHz */
RCC->APB1ENR |= RCC_APB1ENR_USART3EN; RCC->APB1ENR |= RCC_APB1ENR_USART3EN;
#else
const unsigned int quot = 2*84000000/baud; /* APB2 clock is 84MHz */
RCC->APB2ENR |= RCC_APB2ENR_USART1EN;
#endif
__DSB(); __DSB();
const unsigned int quot = 2*42000000/baud; PORT->BRR = quot/2 + (quot & 1);
USART3->BRR = quot/2 + (quot & 1); PORT->CR3 |= USART_CR3_ONEBIT;
USART3->CR3 |= USART_CR3_ONEBIT; PORT->CR1 = USART_CR1_RE
USART3->CR1 = USART_CR1_RE
| USART_CR1_RXNEIE; | USART_CR1_RXNEIE;
#ifdef PLATFORM_MD3x0
NVIC_ClearPendingIRQ(USART3_IRQn); NVIC_ClearPendingIRQ(USART3_IRQn);
NVIC_SetPriority(USART3_IRQn, 14); NVIC_SetPriority(USART3_IRQn, 14);
#else
NVIC_ClearPendingIRQ(USART1_IRQn);
NVIC_SetPriority(USART1_IRQn, 14);
#endif
OSFlagCreate(&sentenceReady, "", 0, &err); OSFlagCreate(&sentenceReady, "", 0, &err);
} }
@ -99,20 +119,30 @@ void gps_terminate()
{ {
OSFlagDel(&sentenceReady, OS_OPT_DEL_NO_PEND, &err); OSFlagDel(&sentenceReady, OS_OPT_DEL_NO_PEND, &err);
gps_disable(); gps_disable();
#ifdef PLATFORM_MD3x0
RCC->APB1ENR &= ~RCC_APB1ENR_USART3EN; RCC->APB1ENR &= ~RCC_APB1ENR_USART3EN;
#else
RCC->APB2ENR &= ~RCC_APB2ENR_USART1EN;
#endif
} }
void gps_enable() void gps_enable()
{ {
gpio_setPin(GPS_EN); gpio_setPin(GPS_EN);
USART3->CR1 |= USART_CR1_UE; PORT->CR1 |= USART_CR1_UE;
} }
void gps_disable() void gps_disable()
{ {
gpio_clearPin(GPS_EN); gpio_clearPin(GPS_EN);
USART3->CR1 &= ~USART_CR1_UE; PORT->CR1 &= ~USART_CR1_UE;
#ifdef PLATFORM_MD3x0
NVIC_DisableIRQ(USART3_IRQn); NVIC_DisableIRQ(USART3_IRQn);
#else
NVIC_DisableIRQ(USART1_IRQn);
#endif
} }
bool gps_detect(uint16_t timeout) bool gps_detect(uint16_t timeout)
@ -154,14 +184,22 @@ int gps_getNmeaSentence(char *buf, const size_t maxLength)
maxPos = maxLength; maxPos = maxLength;
dataBuf = buf; dataBuf = buf;
#ifdef PLATFORM_MD3x0
NVIC_EnableIRQ(USART3_IRQn); NVIC_EnableIRQ(USART3_IRQn);
#else
NVIC_EnableIRQ(USART1_IRQn);
#endif
OS_FLAGS status = OSFlagPend(&sentenceReady, 0x03, 0, OS_FLAGS status = OSFlagPend(&sentenceReady, 0x03, 0,
OS_OPT_PEND_FLAG_SET_ANY | OS_OPT_PEND_FLAG_SET_ANY |
OS_OPT_PEND_FLAG_CONSUME | OS_OPT_PEND_FLAG_CONSUME |
OS_OPT_PEND_BLOCKING, NULL, &err); OS_OPT_PEND_BLOCKING, NULL, &err);
#ifdef PLATFORM_MD3x0
NVIC_DisableIRQ(USART3_IRQn); NVIC_DisableIRQ(USART3_IRQn);
#else
NVIC_DisableIRQ(USART1_IRQn);
#endif
if(status & 0x01) if(status & 0x01)
{ {

View File

@ -103,6 +103,10 @@
#define AMP_EN GPIOB,9 #define AMP_EN GPIOB,9
#define SPK_MUTE GPIOB,8 #define SPK_MUTE GPIOB,8
/* GPS, for the devices who have it */
#define GPS_EN GPIOA,9
#define GPS_DATA GPIOA,10
/* /*
* To enable pwm for display backlight dimming uncomment this directive. * To enable pwm for display backlight dimming uncomment this directive.
* *

View File

@ -25,7 +25,7 @@
#include <stdio.h> #include <stdio.h>
#include <hwconfig.h> #include <hwconfig.h>
#include <minmea.h> #include <minmea.h>
#include <GPS.h> #include <interfaces/gps.h>
char line[MINMEA_MAX_LENGTH*10]; char line[MINMEA_MAX_LENGTH*10];