RNode_Firmware/Config.h

197 lines
5.6 KiB
C
Raw Normal View History

2023-01-13 18:11:02 -05:00
// Copyright (C) 2023, Mark Qvist
// 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/>.
#include "ROM.h"
2024-02-09 09:29:54 -05:00
#include "Boards.h"
2018-04-05 12:10:42 -04:00
#ifndef CONFIG_H
#define CONFIG_H
#define MAJ_VERS 0x01
2024-09-28 21:10:32 -04:00
#define MIN_VERS 0x4b
2022-01-09 17:40:30 -05:00
2018-06-20 11:45:22 -04:00
#define MODE_HOST 0x11
#define MODE_TNC 0x12
2022-10-30 13:58:12 -04:00
#define CABLE_STATE_DISCONNECTED 0x00
#define CABLE_STATE_CONNECTED 0x01
uint8_t cable_state = CABLE_STATE_DISCONNECTED;
#define BT_STATE_NA 0xff
#define BT_STATE_OFF 0x00
#define BT_STATE_ON 0x01
#define BT_STATE_PAIRING 0x02
#define BT_STATE_CONNECTED 0x03
uint8_t bt_state = BT_STATE_NA;
uint32_t bt_ssp_pin = 0;
bool bt_ready = false;
bool bt_enabled = false;
bool bt_allow_pairing = false;
2023-01-07 10:35:07 -05:00
#define M_FRQ_S 27388122
#define M_FRQ_R 27388061
bool console_active = false;
2024-01-19 05:08:55 -05:00
bool modem_installed = false;
2023-01-07 10:35:07 -05:00
#define MTU 508
2018-04-05 12:10:42 -04:00
#define SINGLE_MTU 255
#define HEADER_L 1
2020-05-28 16:18:19 -04:00
#define MIN_L 1
#define CMD_L 64
2018-04-05 12:10:42 -04:00
2024-01-19 05:08:55 -05:00
bool mw_radio_online = false;
#define eeprom_addr(a) (a+EEPROM_OFFSET)
#if (MODEM == SX1262 || MODEM == SX1280) && defined(NRF52840_XXAA)
2024-01-19 05:08:55 -05:00
SPIClass spiModem(NRF_SPIM2, pin_miso, pin_sclk, pin_mosi);
#endif
2018-04-05 12:10:42 -04:00
// MCU independent configuration parameters
2022-01-10 16:14:30 -05:00
const long serial_baudrate = 115200;
2018-04-05 12:10:42 -04:00
// SX1276 RSSI offset to get dBm value from
// packet RSSI register
2022-01-09 17:40:30 -05:00
const int rssi_offset = 157;
2018-04-05 12:10:42 -04:00
// Default LoRa settings
const int lora_rx_turnaround_ms = 66;
const int lora_post_tx_yield_slots = 6;
uint32_t post_tx_yield_timeout = 0;
#define LORA_PREAMBLE_SYMBOLS_HW 4
2023-11-02 13:09:29 -04:00
#define LORA_PREAMBLE_SYMBOLS_MIN 18
#define LORA_PREAMBLE_TARGET_MS 15
#define LORA_CAD_SYMBOLS 3
int csma_slot_ms = 50;
float csma_p_min = 0.1;
float csma_p_max = 0.8;
uint8_t csma_p = 0;
int lora_sf = 0;
int lora_cr = 5;
int lora_txp = 0xFF;
uint32_t lora_bw = 0;
uint32_t lora_freq = 0;
uint32_t lora_bitrate = 0;
long lora_preamble_symbols = 6;
float lora_symbol_time_ms = 0.0;
float lora_symbol_rate = 0.0;
float lora_us_per_byte = 0.0;
2018-04-05 12:10:42 -04:00
// Operational variables
2021-03-12 12:48:50 -05:00
bool radio_locked = true;
bool radio_online = false;
2023-09-14 16:32:26 -04:00
bool community_fw = true;
2021-03-12 12:48:50 -05:00
bool hw_ready = false;
2023-09-14 16:32:26 -04:00
bool radio_error = false;
bool disp_ready = false;
bool pmu_ready = false;
2021-03-12 12:48:50 -05:00
bool promisc = false;
bool implicit = false;
uint8_t implicit_l = 0;
2018-06-27 05:42:48 -04:00
2018-06-20 11:45:22 -04:00
uint8_t op_mode = MODE_HOST;
uint8_t model = 0x00;
uint8_t hwrev = 0x00;
2021-12-13 19:50:37 -05:00
int current_rssi = -292;
2018-06-27 08:08:16 -04:00
int last_rssi = -292;
uint8_t last_rssi_raw = 0x00;
uint8_t last_snr_raw = 0x80;
2018-04-05 12:10:42 -04:00
uint8_t seq = 0xFF;
2022-01-14 14:49:50 -05:00
uint16_t read_len = 0;
2021-12-13 19:50:37 -05:00
2020-05-28 16:18:19 -04:00
// Incoming packet buffer
2018-04-05 12:10:42 -04:00
uint8_t pbuf[MTU];
2020-05-28 16:18:19 -04:00
// KISS command buffer
uint8_t cmdbuf[CMD_L];
2018-04-05 12:10:42 -04:00
2020-05-28 16:18:19 -04:00
// LoRa transmit buffer
uint8_t tbuf[MTU];
2018-06-27 04:22:44 -04:00
2018-04-05 12:10:42 -04:00
uint32_t stat_rx = 0;
uint32_t stat_tx = 0;
#define STATUS_INTERVAL_MS 3
2024-01-19 05:08:55 -05:00
#if MCU_VARIANT == MCU_ESP32 || MCU_VARIANT == MCU_NRF52
#define DCD_SAMPLES 2500
#define UTIL_UPDATE_INTERVAL_MS 1000
#define UTIL_UPDATE_INTERVAL (UTIL_UPDATE_INTERVAL_MS/STATUS_INTERVAL_MS)
#define AIRTIME_LONGTERM 3600
#define AIRTIME_LONGTERM_MS (AIRTIME_LONGTERM*1000)
#define AIRTIME_BINLEN_MS (STATUS_INTERVAL_MS*DCD_SAMPLES)
#define AIRTIME_BINS ((AIRTIME_LONGTERM*1000)/AIRTIME_BINLEN_MS)
bool util_samples[DCD_SAMPLES];
uint16_t airtime_bins[AIRTIME_BINS];
float longterm_bins[AIRTIME_BINS];
int dcd_sample = 0;
float local_channel_util = 0.0;
float total_channel_util = 0.0;
float longterm_channel_util = 0.0;
float airtime = 0.0;
float longterm_airtime = 0.0;
#define current_airtime_bin(void) (millis()%AIRTIME_LONGTERM_MS)/AIRTIME_BINLEN_MS
#endif
float st_airtime_limit = 0.0;
float lt_airtime_limit = 0.0;
bool airtime_lock = false;
bool stat_signal_detected = false;
bool stat_signal_synced = false;
bool stat_rx_ongoing = false;
bool dcd = false;
bool dcd_led = false;
bool dcd_waiting = false;
long dcd_wait_until = 0;
uint16_t dcd_count = 0;
uint16_t dcd_threshold = 2;
2018-04-26 09:52:43 -04:00
uint32_t status_interval_ms = STATUS_INTERVAL_MS;
2018-04-26 09:52:43 -04:00
uint32_t last_status_update = 0;
uint32_t last_dcd = 0;
2018-04-26 09:52:43 -04:00
// Status flags
const uint8_t SIG_DETECT = 0x01;
const uint8_t SIG_SYNCED = 0x02;
const uint8_t RX_ONGOING = 0x04;
// Power management
#define BATTERY_STATE_DISCHARGING 0x01
#define BATTERY_STATE_CHARGING 0x02
#define BATTERY_STATE_CHARGED 0x03
2022-10-30 17:27:30 -04:00
bool battery_installed = false;
bool battery_indeterminate = false;
2022-10-30 17:27:30 -04:00
bool external_power = false;
bool battery_ready = false;
float battery_voltage = 0.0;
float battery_percent = 0.0;
uint8_t battery_state = 0x00;
uint8_t display_intensity = 0xFF;
uint8_t display_addr = 0xFF;
2024-09-28 20:33:02 -04:00
bool display_blanking_enabled = false;
2023-09-14 16:32:26 -04:00
bool display_diagnostics = true;
bool device_init_done = false;
bool eeprom_ok = false;
bool firmware_update_mode = false;
2021-12-26 05:27:32 -05:00
// Boot flags
#define START_FROM_BOOTLOADER 0x01
#define START_FROM_POWERON 0x02
#define START_FROM_BROWNOUT 0x03
#define START_FROM_JTAG 0x04
2022-01-24 13:30:00 -05:00
#endif