1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-23 08:15:30 +03:00

If GPS serial data remains, reschedule task to run again after 1ms

This commit is contained in:
Steve Evans 2021-12-19 20:26:36 +00:00
parent aa4f0f7517
commit 7f147479fc
3 changed files with 13 additions and 4 deletions

View file

@ -489,7 +489,7 @@ task_t tasks[TASK_COUNT] = {
#endif #endif
#ifdef USE_GPS #ifdef USE_GPS
[TASK_GPS] = DEFINE_TASK("GPS", NULL, NULL, gpsUpdate, TASK_PERIOD_HZ(100), TASK_PRIORITY_MEDIUM), // Required to prevent buffer overruns if running at 115200 baud (115 bytes / period < 256 bytes buffer) [TASK_GPS] = DEFINE_TASK("GPS", NULL, NULL, gpsUpdate, TASK_PERIOD_HZ(TASK_GPS_RATE), TASK_PRIORITY_MEDIUM), // Required to prevent buffer overruns if running at 115200 baud (115 bytes / period < 256 bytes buffer)
#endif #endif
#ifdef USE_MAG #ifdef USE_MAG

View file

@ -683,13 +683,19 @@ void gpsUpdate(timeUs_t currentTimeUs)
timeUs_t executeTimeUs; timeUs_t executeTimeUs;
gpsState_e gpsCurState = gpsData.state; gpsState_e gpsCurState = gpsData.state;
// read out available GPS bytes // read out available GPS bytes
if (gpsPort) { if (gpsPort) {
while (serialRxBytesWaiting(gpsPort) && (cmpTimeUs(micros(), currentTimeUs) < GPS_MAX_WAIT_DATA_RX)) { while (serialRxBytesWaiting(gpsPort)) {
if (cmpTimeUs(micros(), currentTimeUs) > GPS_MAX_WAIT_DATA_RX) {
// Wait 1ms and come back
rescheduleTask(TASK_SELF, TASK_PERIOD_HZ(TASK_GPS_RATE_FAST));
return;
}
gpsNewData(serialRead(gpsPort)); gpsNewData(serialRead(gpsPort));
} }
} else if (GPS_update & GPS_MSP_UPDATE) { // GPS data received via MSP // Restore default task rate
rescheduleTask(TASK_SELF, TASK_PERIOD_HZ(TASK_GPS_RATE));
} else if (GPS_update & GPS_MSP_UPDATE) { // GPS data received via MSP
gpsSetState(GPS_STATE_RECEIVING_DATA); gpsSetState(GPS_STATE_RECEIVING_DATA);
gpsData.lastMessage = millis(); gpsData.lastMessage = millis();
sensorsSet(SENSOR_GPS); sensorsSet(SENSOR_GPS);

View file

@ -180,6 +180,9 @@ extern uint8_t GPS_svinfo_cno[16]; // Carrier to Noise Ratio (Signal Str
#define GPS_DBHZ_MIN 0 #define GPS_DBHZ_MIN 0
#define GPS_DBHZ_MAX 55 #define GPS_DBHZ_MAX 55
#define TASK_GPS_RATE 100
#define TASK_GPS_RATE_FAST 1000
void gpsInit(void); void gpsInit(void);
void gpsUpdate(timeUs_t currentTimeUs); void gpsUpdate(timeUs_t currentTimeUs);
bool gpsNewFrame(uint8_t c); bool gpsNewFrame(uint8_t c);