From 66b8ddea875dffbd3ef8d1a106a45d5763606e92 Mon Sep 17 00:00:00 2001
From: mar-kub <markus@kubertzki.de>
Date: Thu, 25 Mar 2021 00:33:37 +0100
Subject: firmware fix: update for newer gcc versions

---
 firmware/bluetooth_rxtx/bluetooth.c        |  6 ++++++
 firmware/bluetooth_rxtx/bluetooth.h        | 10 +++++-----
 firmware/bluetooth_rxtx/cc2400_rangetest.c |  2 ++
 firmware/bluetooth_rxtx/cc2400_rangetest.h |  2 +-
 firmware/bluetooth_rxtx/ubertooth_clock.c  | 13 +++++++++++++
 firmware/bluetooth_rxtx/ubertooth_clock.h  | 16 ++++++++--------
 firmware/bluetooth_rxtx/ubertooth_cs.c     |  5 +++++
 firmware/bluetooth_rxtx/ubertooth_cs.h     |  8 ++++----
 firmware/bluetooth_rxtx/ubertooth_dma.c    | 14 ++++++++++++++
 firmware/bluetooth_rxtx/ubertooth_dma.h    | 12 ++++++------
 firmware/bluetooth_rxtx/ubertooth_rssi.c   |  4 ++++
 firmware/bluetooth_rxtx/ubertooth_rssi.h   |  6 +++---
 12 files changed, 71 insertions(+), 27 deletions(-)

diff --git a/firmware/bluetooth_rxtx/bluetooth.c b/firmware/bluetooth_rxtx/bluetooth.c
index 4a10bc7..accb98b 100644
--- a/firmware/bluetooth_rxtx/bluetooth.c
+++ b/firmware/bluetooth_rxtx/bluetooth.c
@@ -21,6 +21,12 @@
 
 #include "bluetooth.h"
 
+bdaddr target;
+u64 syncword;
+u8 afh_enabled;
+u8 afh_map[10];
+u8 used_channels;
+
 /* these values for hop() can be precalculated (at leastin part) */
 u8 a1, b, c1, e;
 u16 d1;
diff --git a/firmware/bluetooth_rxtx/bluetooth.h b/firmware/bluetooth_rxtx/bluetooth.h
index 4f4c2ca..2222c31 100644
--- a/firmware/bluetooth_rxtx/bluetooth.h
+++ b/firmware/bluetooth_rxtx/bluetooth.h
@@ -27,11 +27,11 @@
 
 #define MAX_SYNCWORD_ERRS 5
 
-bdaddr target;
-u64 syncword;
-u8 afh_enabled;
-u8 afh_map[10];
-u8 used_channels;
+extern bdaddr target;
+extern u64 syncword;
+extern u8 afh_enabled;
+extern u8 afh_map[10];
+extern u8 used_channels;
 
 /* Barker distance/correct gains us very little when sniffing a known AC
 static const u8 ao_barker_distance[] = {
diff --git a/firmware/bluetooth_rxtx/cc2400_rangetest.c b/firmware/bluetooth_rxtx/cc2400_rangetest.c
index 28534f8..30a36cb 100644
--- a/firmware/bluetooth_rxtx/cc2400_rangetest.c
+++ b/firmware/bluetooth_rxtx/cc2400_rangetest.c
@@ -46,6 +46,8 @@
  *   crc: 2 bytes
  */
 
+rangetest_result rr;
+
 void cc2400_rangetest(volatile u16 *chan_ptr)
 {
 #ifdef TX_ENABLE
diff --git a/firmware/bluetooth_rxtx/cc2400_rangetest.h b/firmware/bluetooth_rxtx/cc2400_rangetest.h
index 70f9d35..a306f84 100644
--- a/firmware/bluetooth_rxtx/cc2400_rangetest.h
+++ b/firmware/bluetooth_rxtx/cc2400_rangetest.h
@@ -24,7 +24,7 @@
 
 #include "ubertooth.h"
 
-rangetest_result rr;
+extern rangetest_result rr;
 
 void cc2400_rangetest(volatile u16 *chan_ptr);
 
diff --git a/firmware/bluetooth_rxtx/ubertooth_clock.c b/firmware/bluetooth_rxtx/ubertooth_clock.c
index e7b0c01..ed96775 100644
--- a/firmware/bluetooth_rxtx/ubertooth_clock.c
+++ b/firmware/bluetooth_rxtx/ubertooth_clock.c
@@ -22,6 +22,19 @@
 #include "ubertooth_clock.h"
 #include "ubertooth.h"
 
+volatile uint32_t clkn;
+volatile uint32_t last_hop;
+
+volatile uint32_t clkn_offset;
+volatile uint16_t clk100ns_offset;
+
+// linear clock drift
+volatile int16_t clk_drift_ppm;
+volatile uint16_t clk_drift_correction;
+
+volatile uint32_t clkn_last_drift_fix;
+volatile uint32_t clkn_next_drift_fix;
+
 void clkn_stop()
 {
 	/* stop and reset the timer to zero */
diff --git a/firmware/bluetooth_rxtx/ubertooth_clock.h b/firmware/bluetooth_rxtx/ubertooth_clock.h
index 833899b..7674b11 100644
--- a/firmware/bluetooth_rxtx/ubertooth_clock.h
+++ b/firmware/bluetooth_rxtx/ubertooth_clock.h
@@ -32,18 +32,18 @@
  * It advances 3200 times per second.  Two clkn periods make a Bluetooth time
  * slot.
  */
-volatile uint32_t clkn;
-volatile uint32_t last_hop;
+extern volatile uint32_t clkn;
+extern volatile uint32_t last_hop;
 
-volatile uint32_t clkn_offset;
-volatile uint16_t clk100ns_offset;
+extern volatile uint32_t clkn_offset;
+extern volatile uint16_t clk100ns_offset;
 
 // linear clock drift
-volatile int16_t clk_drift_ppm;
-volatile uint16_t clk_drift_correction;
+extern volatile int16_t clk_drift_ppm;
+extern volatile uint16_t clk_drift_correction;
 
-volatile uint32_t clkn_last_drift_fix;
-volatile uint32_t clkn_next_drift_fix;
+extern volatile uint32_t clkn_last_drift_fix;
+extern volatile uint32_t clkn_next_drift_fix;
 
 #define CLK100NS (3125*(clkn & 0xfffff) + T0TC)
 #define LE_BASECLK (12500)                    // 1.25 ms in units of 100ns
diff --git a/firmware/bluetooth_rxtx/ubertooth_cs.c b/firmware/bluetooth_rxtx/ubertooth_cs.c
index 2734cb1..851a528 100644
--- a/firmware/bluetooth_rxtx/ubertooth_cs.c
+++ b/firmware/bluetooth_rxtx/ubertooth_cs.c
@@ -23,6 +23,11 @@
 #include "ubertooth.h"
 #include "ubertooth_rssi.h"
 
+uint8_t cs_no_squelch;       // rx all packets if set
+int8_t cs_threshold_req;     // requested CS threshold in dBm
+int8_t cs_threshold_cur;     // current CS threshold in dBm
+volatile uint8_t cs_trigger; // set by intr on P2.2 falling (CS)
+
 typedef enum {
 	CS_SAMPLES_1 = 1,
 	CS_SAMPLES_2 = 2,
diff --git a/firmware/bluetooth_rxtx/ubertooth_cs.h b/firmware/bluetooth_rxtx/ubertooth_cs.h
index c1327d5..214bd03 100644
--- a/firmware/bluetooth_rxtx/ubertooth_cs.h
+++ b/firmware/bluetooth_rxtx/ubertooth_cs.h
@@ -26,10 +26,10 @@
 
 #define CS_HOLD_TIME  2      // min pkts to send on trig (>=1)
 
-uint8_t cs_no_squelch;       // rx all packets if set
-int8_t cs_threshold_req;     // requested CS threshold in dBm
-int8_t cs_threshold_cur;     // current CS threshold in dBm
-volatile uint8_t cs_trigger; // set by intr on P2.2 falling (CS)
+extern uint8_t cs_no_squelch;       // rx all packets if set
+extern int8_t cs_threshold_req;     // requested CS threshold in dBm
+extern int8_t cs_threshold_cur;     // current CS threshold in dBm
+extern volatile uint8_t cs_trigger; // set by intr on P2.2 falling (CS)
 
 void cs_threshold_calc_and_set(uint16_t channel);
 void cs_trigger_enable(void);
diff --git a/firmware/bluetooth_rxtx/ubertooth_dma.c b/firmware/bluetooth_rxtx/ubertooth_dma.c
index 16ae2c7..a26b475 100644
--- a/firmware/bluetooth_rxtx/ubertooth_dma.c
+++ b/firmware/bluetooth_rxtx/ubertooth_dma.c
@@ -21,6 +21,20 @@
 
 #include "ubertooth_dma.h"
 
+volatile uint8_t rxbuf1[DMA_SIZE];
+volatile uint8_t rxbuf2[DMA_SIZE];
+
+/*
+ * The active buffer is the one with an active DMA transfer.
+ * The idle buffer is the one we can read/write between transfers.
+ */
+volatile uint8_t* volatile active_rxbuf;
+volatile uint8_t* volatile idle_rxbuf;
+
+/* rx terminal count and error interrupt counters */
+volatile uint32_t rx_tc;
+volatile uint32_t rx_err;
+
 /* DMA linked list items */
 typedef struct {
 	uint32_t src;
diff --git a/firmware/bluetooth_rxtx/ubertooth_dma.h b/firmware/bluetooth_rxtx/ubertooth_dma.h
index dfb969d..03b7b35 100644
--- a/firmware/bluetooth_rxtx/ubertooth_dma.h
+++ b/firmware/bluetooth_rxtx/ubertooth_dma.h
@@ -25,19 +25,19 @@
 #include "inttypes.h"
 #include "ubertooth.h"
 
-volatile uint8_t rxbuf1[DMA_SIZE];
-volatile uint8_t rxbuf2[DMA_SIZE];
+extern volatile uint8_t rxbuf1[DMA_SIZE];
+extern volatile uint8_t rxbuf2[DMA_SIZE];
 
 /*
  * The active buffer is the one with an active DMA transfer.
  * The idle buffer is the one we can read/write between transfers.
  */
-volatile uint8_t* volatile active_rxbuf;
-volatile uint8_t* volatile idle_rxbuf;
+extern volatile uint8_t* volatile active_rxbuf;
+extern volatile uint8_t* volatile idle_rxbuf;
 
 /* rx terminal count and error interrupt counters */
-volatile uint32_t rx_tc;
-volatile uint32_t rx_err;
+extern volatile uint32_t rx_tc;
+extern volatile uint32_t rx_err;
 
 void dma_poweron();
 void dma_poweroff();
diff --git a/firmware/bluetooth_rxtx/ubertooth_rssi.c b/firmware/bluetooth_rxtx/ubertooth_rssi.c
index 4af1e59..d78aaa1 100644
--- a/firmware/bluetooth_rxtx/ubertooth_rssi.c
+++ b/firmware/bluetooth_rxtx/ubertooth_rssi.c
@@ -25,6 +25,10 @@
 
 #define RSSI_IIR_ALPHA 3       // 3/256 = .012
 
+int8_t rssi_max;
+int8_t rssi_min;
+uint8_t rssi_count;
+
 int32_t rssi_sum;
 int16_t rssi_iir[79] = {0};
 
diff --git a/firmware/bluetooth_rxtx/ubertooth_rssi.h b/firmware/bluetooth_rxtx/ubertooth_rssi.h
index 2691171..bc25920 100644
--- a/firmware/bluetooth_rxtx/ubertooth_rssi.h
+++ b/firmware/bluetooth_rxtx/ubertooth_rssi.h
@@ -24,9 +24,9 @@
 
 #include "inttypes.h"
 
-int8_t rssi_max;
-int8_t rssi_min;
-uint8_t rssi_count;
+extern int8_t rssi_max;
+extern int8_t rssi_min;
+extern uint8_t rssi_count;
 
 void rssi_reset(void);
 void rssi_add(int8_t v);
-- 
2.30.2

