forked from markqvist/RNode_Firmware
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Config.h
148 lines (118 loc) · 3.44 KB
/
Config.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include "ROM.h"
#ifndef CONFIG_H
#define CONFIG_H
#define MAJ_VERS 0x01
#define MIN_VERS 0x0A
#define MCU_328P 0x90
#define MCU_1284P 0x91
#define MCU_ESP32 0x92
#define MODE_HOST 0x11
#define MODE_TNC 0x12
#if defined(__AVR_ATmega328P__)
#define MCU_VARIANT MCU_328P
#warning "Firmware is being compiled for atmega328p based boards"
#elif defined(__AVR_ATmega1284P__)
#define MCU_VARIANT MCU_1284P
#warning "Firmware is being compiled for atmega1284p based boards"
#elif defined(ESP32)
#define MCU_VARIANT MCU_ESP32
#warning "Firmware is being compiled for esp32 based boards"
#else
#error "The firmware cannot be compiled for the selected MCU variant"
#endif
#define MTU 500
#define SINGLE_MTU 255
#define HEADER_L 1
#define CMD_L 4
// MCU dependent configuration parameters
#if MCU_VARIANT == MCU_328P
const int pin_cs = 7;
const int pin_reset = 6;
const int pin_dio = 2;
const int pin_led_rx = 5;
const int pin_led_tx = 4;
#define FLOW_CONTROL_ENABLED true
#define QUEUE_SIZE 0
#define EEPROM_SIZE 512
#define EEPROM_OFFSET EEPROM_SIZE-EEPROM_RESERVED
#endif
// ESP32 PWM channels
const int ch_led_rx = 0;
const int ch_led_tx = 1;
#if MCU_VARIANT == MCU_1284P
const int pin_cs = 4;
const int pin_reset = 3;
const int pin_dio = 2;
const int pin_led_rx = 12;
const int pin_led_tx = 13;
#define FLOW_CONTROL_ENABLED true
#define QUEUE_SIZE 24
#define QUEUE_BUF_SIZE (QUEUE_SIZE+1)
#define QUEUE_MEM QUEUE_BUF_SIZE * MTU
#define EEPROM_SIZE 4096
#define EEPROM_OFFSET EEPROM_SIZE-EEPROM_RESERVED
#endif
#if MCU_VARIANT == MCU_ESP32
const int pin_cs = SS;//18;
const int pin_reset = 23;
const int pin_dio = 26;
const int pin_led_rx = 14;
const int pin_led_tx = 14;
#define FLOW_CONTROL_ENABLED true
#define QUEUE_SIZE 24
#define QUEUE_BUF_SIZE (QUEUE_SIZE+1)
#define QUEUE_MEM QUEUE_BUF_SIZE * MTU
#define EEPROM_SIZE 4096
#define EEPROM_OFFSET EEPROM_SIZE-EEPROM_RESERVED
#endif
#define eeprom_addr(a) (a+EEPROM_OFFSET)
// MCU independent configuration parameters
const long serial_baudrate = 115200;
const int rssi_offset = 292;
const int lora_rx_turnaround_ms = 50;
// Default LoRa settings
int lora_sf = 0;
int lora_cr = 5;
int lora_txp = 0xFF;
uint32_t lora_bw = 0;
uint32_t lora_freq = 0;
// Operational variables
bool radio_locked = true;
bool radio_online = false;
bool hw_ready = false;
bool promisc = false;
uint8_t op_mode = MODE_HOST;
uint8_t model = 0x00;
uint8_t hwrev = 0x00;
int last_rssi = -292;
uint8_t last_rssi_raw = 0x00;
size_t read_len = 0;
uint8_t seq = 0xFF;
uint8_t pbuf[MTU];
uint8_t sbuf[MTU];
uint8_t cbuf[CMD_L];
#if QUEUE_SIZE > 0
uint8_t tbuf[MTU];
uint8_t qbuf[QUEUE_MEM];
size_t queued_lengths[QUEUE_BUF_SIZE];
#endif
uint32_t stat_rx = 0;
uint32_t stat_tx = 0;
bool outbound_ready = false;
size_t queue_head = 0;
size_t queue_tail = 0;
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;
uint16_t dcd_count = 0;
uint16_t dcd_threshold = 15;
uint32_t status_interval_ms = 3;
uint32_t last_status_update = 0;
// Status flags
const uint8_t SIG_DETECT = 0x01;
const uint8_t SIG_SYNCED = 0x02;
const uint8_t RX_ONGOING = 0x04;
#endif