Improved ESP32 compatibility

This commit is contained in:
Mark Qvist 2022-01-14 21:12:33 +01:00
parent 7cc777ff3f
commit 1afc9fd2a9
2 changed files with 111 additions and 140 deletions

View File

@ -83,7 +83,7 @@
#define BOARD_MODEL BOARD_TBEAM
#define CONFIG_UART_BUFFER_SIZE 64
#define CONFIG_UART_BUFFER_SIZE 6144
#define CONFIG_QUEUE_SIZE 6144
#define CONFIG_QUEUE_MAX_LENGTH 250

View File

@ -22,18 +22,13 @@ volatile bool serial_buffering = false;
char sbuf[128];
#if MCU_VARIANT == MCU_ESP32
#include "soc/rtc_wdt.h"
#define ISR_VECT IRAM_ATTR
bool packet_ready = false;
#else
#define ISR_VECT
#endif
void setup() {
#if MCU_VARIANT == MCU_ESP32
delay(500);
EEPROM.begin(EEPROM_SIZE);
// TODO: Check this
Serial.setRxBufferSize(CONFIG_UART_BUFFER_SIZE);
#endif
@ -70,15 +65,8 @@ void setup() {
LoRa.setPins(pin_cs, pin_reset, pin_dio);
#if MCU_VARIANT == MCU_ESP32
// ESP32-specific initialisation
Serial1.begin(GPS_BAUD_RATE, SERIAL_8N1, PIN_GPS_RX, PIN_GPS_TX);
// rtc_wdt_protect_off();
// rtc_wdt_set_stage(RTC_WDT_STAGE0, RTC_WDT_STAGE_ACTION_RESET_SYSTEM);
// rtc_wdt_set_time(RTC_WDT_STAGE0, 25);
// rtc_wdt_protect_on();
// rtc_wdt_enable();
Wire.begin(I2C_SDA, I2C_SCL);
initPMU();
kiss_indicate_reset();
#endif
@ -97,7 +85,7 @@ void lora_receive() {
inline void kiss_write_packet() {
Serial.write(FEND);
Serial.write(CMD_DATA);
for (int i = 0; i < read_len; i++) {
for (uint16_t i = 0; i < read_len; i++) {
uint8_t byte = pbuf[i];
if (byte == FEND) { Serial.write(FESC); byte = TFEND; }
if (byte == FESC) { Serial.write(FESC); byte = TFESC; }
@ -110,27 +98,13 @@ inline void kiss_write_packet() {
#endif
}
inline void getPacketData(int len) {
inline void getPacketData(uint16_t len) {
while (len-- && read_len < MTU) {
pbuf[read_len++] = LoRa.read();
}
}
#if MCU_VARIANT == MCU_ESP32
portMUX_TYPE isr_lock = portMUX_INITIALIZER_UNLOCKED;
#endif
bool handling_packet = false;
void ISR_VECT receive_callback(int packet_size) {
#if MCU_VARIANT == MCU_ESP32
portENTER_CRITICAL_ISR(&isr_lock);
#endif
#if MCU_VARIANT == MCU_ESP32
if (!handling_packet) {
handling_packet = true;
#endif
if (!promisc) {
// The standard operating mode allows large
// packets with a payload up to 500 bytes,
@ -240,15 +214,7 @@ void ISR_VECT receive_callback(int packet_size) {
getPacketData(packet_size);
packet_ready = true;
#endif
#if MCU_VARIANT == MCU_ESP32
}
handling_packet = false;
#endif
}
#if MCU_VARIANT == MCU_ESP32
portEXIT_CRITICAL_ISR(&isr_lock);
#endif
}
@ -628,9 +594,22 @@ void serialCallback(uint8_t sbyte) {
}
}
#if MCU_VARIANT == MCU_ESP32
portMUX_TYPE update_lock = portMUX_INITIALIZER_UNLOCKED;
#endif
void updateModemStatus() {
#if MCU_VARIANT == MCU_ESP32
portENTER_CRITICAL(&update_lock);
#endif
uint8_t status = LoRa.modemStatus();
last_status_update = millis();
#if MCU_VARIANT == MCU_ESP32
portEXIT_CRITICAL(&update_lock);
#endif
if (status & SIG_DETECT == SIG_DETECT) { stat_signal_detected = true; } else { stat_signal_detected = false; }
if (status & SIG_SYNCED == SIG_SYNCED) { stat_signal_synced = true; } else { stat_signal_synced = false; }
if (status & RX_ONGOING == RX_ONGOING) { stat_rx_ongoing = true; } else { stat_rx_ongoing = false; }
@ -801,14 +780,6 @@ void buffer_serial() {
#endif
}
#if MCU_VARIANT == MCU_ESP32
// Discard GPS data for now
c = 0;
while (c < MAX_CYCLES && Serial1.available()) {
Serial1.read();
}
#endif
serial_buffering = false;
}
}