2024-10-12 18:04:19 +01:00
|
|
|
// Copyright (C) 2024, Mark Qvist
|
2023-01-14 00:11:02 +01:00
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
2018-12-01 19:31:51 +01:00
|
|
|
#include <Arduino.h>
|
2018-04-05 18:10:42 +02:00
|
|
|
#include <SPI.h>
|
2019-01-01 15:52:48 +01:00
|
|
|
#include "Utilities.h"
|
2018-04-05 18:10:42 +02:00
|
|
|
|
2024-09-12 10:57:16 -04:00
|
|
|
#if MCU_VARIANT == MCU_NRF52
|
|
|
|
|
#define INTERFACE_SPI
|
2024-10-16 21:24:18 +01:00
|
|
|
#if BOARD_MODEL == BOARD_RAK4631 || BOARD_MODEL == BOARD_OPENCOM_XL
|
2024-08-06 17:37:47 +01:00
|
|
|
// Required because on RAK4631, non-default SPI pins must be initialised when class is declared.
|
|
|
|
|
SPIClass interface_spi[1] = {
|
|
|
|
|
// SX1262
|
|
|
|
|
SPIClass(
|
|
|
|
|
NRF_SPIM2,
|
|
|
|
|
interface_pins[0][3],
|
|
|
|
|
interface_pins[0][1],
|
|
|
|
|
interface_pins[0][2]
|
|
|
|
|
)
|
|
|
|
|
};
|
2024-09-12 10:57:16 -04:00
|
|
|
#elif BOARD_MODEL == BOARD_TECHO
|
|
|
|
|
SPIClass interface_spi[1] = {
|
|
|
|
|
// SX1262
|
|
|
|
|
SPIClass(
|
|
|
|
|
NRF_SPIM3,
|
|
|
|
|
interface_pins[0][3],
|
|
|
|
|
interface_pins[0][1],
|
|
|
|
|
interface_pins[0][2]
|
|
|
|
|
)
|
|
|
|
|
};
|
|
|
|
|
#endif
|
2024-08-06 17:37:47 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef INTERFACE_SPI
|
|
|
|
|
// INTERFACE_SPI is only required on NRF52 platforms, as the SPI pins are set in the class constructor and not by a setter method.
|
|
|
|
|
// Even if custom SPI interfaces are not needed, the array must exist to prevent compilation errors.
|
|
|
|
|
#define INTERFACE_SPI
|
|
|
|
|
SPIClass interface_spi[1];
|
2024-07-04 13:57:51 +01:00
|
|
|
#endif
|
|
|
|
|
|
2020-05-28 22:18:19 +02:00
|
|
|
FIFOBuffer serialFIFO;
|
2020-06-01 12:43:59 +02:00
|
|
|
uint8_t serialBuffer[CONFIG_UART_BUFFER_SIZE+1];
|
2020-05-28 22:18:19 +02:00
|
|
|
|
2024-07-03 11:06:52 +01:00
|
|
|
uint16_t packet_starts_buf[(CONFIG_QUEUE_MAX_LENGTH)+1];
|
2020-05-28 22:18:19 +02:00
|
|
|
|
2024-07-03 11:06:52 +01:00
|
|
|
uint16_t packet_lengths_buf[(CONFIG_QUEUE_MAX_LENGTH)+1];
|
2020-05-28 22:18:19 +02:00
|
|
|
|
2024-06-10 13:05:21 +01:00
|
|
|
FIFOBuffer16 packet_starts[INTERFACE_COUNT];
|
|
|
|
|
FIFOBuffer16 packet_lengths[INTERFACE_COUNT];
|
2020-05-28 22:18:19 +02:00
|
|
|
|
2024-06-10 13:05:21 +01:00
|
|
|
volatile uint8_t queue_height[INTERFACE_COUNT] = {0};
|
|
|
|
|
volatile uint16_t queued_bytes[INTERFACE_COUNT] = {0};
|
|
|
|
|
|
|
|
|
|
volatile uint16_t queue_cursor[INTERFACE_COUNT] = {0};
|
|
|
|
|
volatile uint16_t current_packet_start[INTERFACE_COUNT] = {0};
|
2020-05-29 14:58:10 +02:00
|
|
|
volatile bool serial_buffering = false;
|
2025-06-17 18:37:23 +01:00
|
|
|
extern void setup_interfaces(); // from src/misc/ModemISR.h
|
2024-04-23 00:52:57 +02:00
|
|
|
#if HAS_BLUETOOTH || HAS_BLE == true
|
2022-10-30 14:52:22 +01:00
|
|
|
bool bt_init_ran = false;
|
|
|
|
|
#endif
|
2020-05-29 14:58:10 +02:00
|
|
|
|
2023-01-06 22:29:23 +01:00
|
|
|
#if HAS_CONSOLE
|
|
|
|
|
#include "Console.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2024-10-12 18:04:19 +01:00
|
|
|
#define MODEM_QUEUE_SIZE 4*INTERFACE_COUNT
|
|
|
|
|
typedef struct {
|
|
|
|
|
size_t len;
|
|
|
|
|
int rssi;
|
|
|
|
|
int snr_raw;
|
|
|
|
|
uint8_t interface;
|
2024-10-15 17:34:16 +01:00
|
|
|
uint8_t data[];
|
2024-10-12 18:04:19 +01:00
|
|
|
} modem_packet_t;
|
|
|
|
|
static xQueueHandle modem_packet_queue = NULL;
|
|
|
|
|
|
2020-05-29 14:58:10 +02:00
|
|
|
char sbuf[128];
|
|
|