Internal and external module buffers are now private

This commit is contained in:
Raphael Coeffic
2022-08-11 12:15:46 +02:00
committed by Raphael Coeffic
parent ab6033e4d5
commit f952c5f7c7
24 changed files with 280 additions and 216 deletions
+9 -5
View File
@@ -121,7 +121,7 @@ bool FrskyDeviceFirmwareUpdate::readBuffer(uint8_t * buffer, uint8_t count, uint
uint32_t elapsed = 0;
uint8_t index = 0;
while (index < count && elapsed < timeout) {
if (intmoduleFifo.pop(buffer[index])) {
if (IntmoduleSerialDriver.getByte(uart_ctx, &(buffer[index]))) {
++index;
}
else {
@@ -141,14 +141,15 @@ bool FrskyDeviceFirmwareUpdate::readBuffer(uint8_t * buffer, uint8_t count, uint
}
#endif
const uint8_t * FrskyDeviceFirmwareUpdate::readFullDuplexFrame(ModuleFifo & fifo, uint32_t timeout)
const uint8_t * FrskyDeviceFirmwareUpdate::readFullDuplexFrame(uint32_t timeout)
{
#if defined(INTMODULE_USART)
uint8_t len = 0;
bool bytestuff = false;
while (len < 10) {
uint32_t elapsed = 0;
uint8_t byte;
while (!fifo.pop(byte)) {
uint8_t byte = 0;
while (IntmoduleSerialDriver.getByte(uart_ctx, &byte) == 0) {
RTOS_WAIT_MS(1);
if (elapsed++ >= timeout) {
return nullptr;
@@ -170,6 +171,9 @@ const uint8_t * FrskyDeviceFirmwareUpdate::readFullDuplexFrame(ModuleFifo & fifo
}
}
return &frame[1];
#else
return nullptr;
#endif
}
const uint8_t * FrskyDeviceFirmwareUpdate::readHalfDuplexFrame(uint32_t timeout)
@@ -193,7 +197,7 @@ const uint8_t * FrskyDeviceFirmwareUpdate::readFrame(uint32_t timeout)
switch (module) {
#if defined(INTERNAL_MODULE_PXX2)
case INTERNAL_MODULE:
return readFullDuplexFrame(intmoduleFifo, timeout);
return readFullDuplexFrame(timeout);
#endif
default:
+1 -5
View File
@@ -24,10 +24,6 @@
#include "dataconstants.h"
#include "definitions.h"
#include "frsky_pxx2.h"
#include "pulses/modules_helpers.h"
#include "ff.h"
#include "popups.h"
enum FrskyFirmwareProductFamily {
FIRMWARE_FAMILY_INTERNAL_MODULE,
@@ -143,7 +139,7 @@ class FrskyDeviceFirmwareUpdate {
void sendFrame();
bool readBuffer(uint8_t * buffer, uint8_t count, uint32_t timeout);
const uint8_t * readFullDuplexFrame(ModuleFifo & fifo, uint32_t timeout);
const uint8_t * readFullDuplexFrame(uint32_t timeout);
const uint8_t * readHalfDuplexFrame(uint32_t timeout);
const uint8_t * readFrame(uint32_t timeout);
bool waitState(State state, uint32_t timeout);
-81
View File
@@ -1,81 +0,0 @@
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef _IO_PXX2_H_
#define _IO_PXX2_H_
#include "fifo.h"
#include "pulses/pxx.h"
#include "board.h"
class ModuleFifo : public Fifo<uint8_t, INTMODULE_FIFO_SIZE> {
public:
bool getFrame(uint8_t * frame)
{
while (true) {
if (isEmpty()) {
return false;
}
else if (fifo[ridx] != 0x7E) {
skip();
}
else {
break;
}
}
uint32_t next = nextIndex(ridx);
uint8_t len = fifo[next];
if (len > 40) {
clear();
return false;
}
if (size() < unsigned(len + 4 /* 2 bytes header + 2 bytes CRC */)) {
// frame not fully received
return false;
}
// we keep the length in frame[0]
frame[0] = fifo[next];
next = nextIndex(next);
uint16_t crc = 0xFFFF;
for (uint32_t i = 1; i <= len; i++) {
frame[i] = fifo[next];
crc -= frame[i];
next = nextIndex(next);
}
uint8_t crcLow = fifo[next];
next = nextIndex(next);
uint8_t crcHigh = fifo[next];
ridx = nextIndex(next);
return ((crc >> 8) == crcLow) && ((crc & 0xFF) == crcHigh);
}
};
#endif
+2 -2
View File
@@ -106,7 +106,7 @@ class MultiInternalUpdateDriver: public MultiFirmwareUpdateDriver
bool getByte(uint8_t & byte) const override
{
return intmoduleFifo.pop(byte);
return IntmoduleSerialDriver.getByte(uart_ctx, &byte) > 0;
}
void sendByte(uint8_t byte) const override
@@ -116,7 +116,7 @@ class MultiInternalUpdateDriver: public MultiFirmwareUpdateDriver
void clear() const override
{
intmoduleFifo.clear();
IntmoduleSerialDriver.clearRxBuffer(uart_ctx);
}
void deinit(bool inverted) override