Browse Source

Revised to use component structure. It's highly likely I broke something
/ everything.

curiousmuch 4 years ago
parent
commit
847b04a1ed

+ 0 - 1
Makefile

@@ -4,6 +4,5 @@
 #
 
 PROJECT_NAME := Arrow
-
 include $(IDF_PATH)/make/project.mk
 

+ 19 - 9
main/afsk_demodulator.c → components/aprs/afsk_demodulator.c

@@ -13,12 +13,24 @@
 int8_t window[WINDOW_SIZE];
 //int32_t lpf_window[WINDOW_SIZE];
 
-double goertzelFilter(int8_t samples[], double freq, unsigned int N)
+void goertzel_init(float freq0, float freq1, float *coeff0, float *coeff1)
 {
-    double s_prev = 0.0;
-    double s_prev2 = 0.0;
-    double coeff,normalizedfreq,power,s;
-    unsigned int i;
+	float normalizedfreq;
+
+	// calculate coeff0
+	normalizedfreq = freq0 / SAMPLEFREQUENCY;
+	*coeff0 = (float) 2*cos(2*M_PI*normalizedfreq);
+
+	// calculate coeff1
+	normalizedfreq = freq1 / SAMPLEFREQUENCY;
+	*coeff1 = (float) 2*cos(2*M_PI*normalizedfreq);
+}
+
+float goertzelFilter(int samples[], float freq, int N) {
+    float s_prev = 0.0;
+    float s_prev2 = 0.0;
+    float coeff,normalizedfreq,power,s;
+    int i;
     normalizedfreq = freq / SAMPLEFREQUENCY;
     coeff = 2*cos(2*M_PI*normalizedfreq);
     for (i=0; i<N; i++) {
@@ -30,14 +42,12 @@ double goertzelFilter(int8_t samples[], double freq, unsigned int N)
     return power;
 }
 
-float goertzelFilter2(int8_t samples[], float freq, unsigned int N)
+float goertzel_filter(int8_t samples[], float coeff, unsigned int N)
 {
     float s_prev = 0.0;
     float s_prev2 = 0.0;
-    float coeff,normalizedfreq,power,s;
+    float power, s;
     unsigned int i;
-    normalizedfreq = freq / SAMPLEFREQUENCY;
-    coeff = 2*cos(2*M_PI*normalizedfreq);
     for (i=0; i<N; i++) {
         s = samples[i] + coeff * s_prev - s_prev2;
         s_prev2 = s_prev;

+ 0 - 0
main/aprs_decoder.c → components/aprs/aprs_decoder.c


+ 25 - 0
components/aprs/include/afsk_demodulator.h

@@ -0,0 +1,25 @@
+/*
+ * afsk_decoder.h
+ *
+ *  Created on: Sep 10, 2019
+ *      Author: curiousmuch
+ */
+
+#ifndef AFSK_DEMODULATOR_H_
+#define AFSK_DEMODULATOR_H_
+
+#define WINDOW_SIZE 11
+#define SAMPLEFREQUENCY 13200
+
+void window_init(void);
+void window_add(int8_t sample);
+int8_t* window_get(void);
+unsigned int window_get_size(void);
+float goertzel_filter(int8_t samples[], float freq, unsigned int N);
+void goertzel_init(float freq0, float freq1, float *coeff0, float *coeff1);
+float goertzelFilter(int samples[], float freq, int N);
+
+
+
+
+#endif /* MAIN_AFSK_DECODER_H_ */

+ 0 - 2
main/aprs_decoder.h → components/aprs/include/aprs_decoder.h

@@ -61,6 +61,4 @@ void frame_buffer_init(uint8_t *buf, uint32_t len);
 void aprs_decoder_init(void);
 decoder_output_t aprs_decoder_feed_bit(uint8_t nrzi_bit);
 
-
-
 #endif /* APRS_DECODER_H_ */

+ 1 - 1
main/bt_spp.c → components/bluetooth/bt_spp.c

@@ -21,7 +21,7 @@
 #include "bt_spp.h"
 
 // TODO: Remove and add call back functions to tie to main
-#include "kiss.c"
+#include "kiss.h"
 
 
 // Why are these global? Should I move this to a .h settings file?

+ 1 - 0
main/bt_spp.h → components/bluetooth/include/bt_spp.h

@@ -9,5 +9,6 @@
 #define MAIN_BT_SPP_H_
 
 void bt_spp_tx(uint8_t *buf, uint32_t len);
+void bt_spp_init();
 
 #endif /* MAIN_BT_SPP_H_ */

+ 0 - 0
main/board.c → components/board/board.c


+ 2 - 2
main/board.h → components/board/include/board.h

@@ -5,8 +5,8 @@
  *      Author: curiousmuch
  */
 
-#ifndef MAIN_BOARD_H_
-#define MAIN_BOARD_H_
+#ifndef BOARD_H_
+#define BOARD_H_
 
 // Battery Measurement
 #define ENABLE_VOLTAGE_DIVIDER	25

+ 1 - 0
main/kiss.h → components/kiss/include/kiss.h

@@ -87,6 +87,7 @@ typedef struct {
 void kiss_receive(uint8_t *data, uint16_t len);
 void kiss_init(void);
 void kiss_configure(void);
+void kiss_transmit(uint8_t type, uint8_t *data, uint32_t len);
 
 
 

+ 1 - 1
main/kiss.c → components/kiss/kiss.c

@@ -13,9 +13,9 @@
 #include "esp_log.h"
 #include <stdio.h>
 #include "cc1200.h"
-#include "fcs_calc.h"
 #include "kiss.h"
 #include "bt_spp.h"
+#include "fcs_calc.h"
 
 kiss_buffer_t rx_buffer;
 kiss_buffer_t tx_buffer;

+ 0 - 22
main/afsk_demodulator.h

@@ -1,22 +0,0 @@
-/*
- * afsk_decoder.h
- *
- *  Created on: Sep 10, 2019
- *      Author: curiousmuch
- */
-
-#ifndef MAIN_AFSK_DEMODULATOR_H_
-#define MAIN_AFSK_DEMODULATOR_H_
-
-#define WINDOW_SIZE 5
-#define SAMPLEFREQUENCY 6000
-
-void window_init(void);
-void window_add(int8_t sample);
-int8_t* window_get(void);
-unsigned int window_get_size(void);
-float goertzelFilter2(int8_t samples[], float freq, unsigned int N);
-
-
-
-#endif /* MAIN_AFSK_DECODER_H_ */

+ 0 - 0
main/fcs_calc.h → main/include/fcs_calc.h


+ 41 - 19
main/main.c

@@ -1,11 +1,21 @@
 /*
  * Project: Arrow
  * Author: 	curiousmuch
+ * Description: This project is an APRS transceiver based on the ESP32 and CC1200.
+ * TODO: Refactor Code to isolate into seperate components
+ * TODO: Isolate BT_SPP.C functionality
+ * TODO: Isolate KISS.C functionality
+ * TODO: Remove any dependancies on Direwolf.
+ * TODO: Transfer DSP functions to APRS folder
+ * TODO: Abstract includes to be nicer (#include aprs.h) for example
+ * TODO: Isolate CC1200 functions from other parts / maybe integrate most of TX scheme into task.
  */
 #include <stdio.h>
 #include "freertos/FreeRTOS.h"
 #include "freertos/task.h"
 #include "freertos/semphr.h"
+#include "freertos/ringbuf.h"
+
 #include "driver/gpio.h"
 #include "sdkconfig.h"
 #include "esp_task_wdt.h"
@@ -22,7 +32,7 @@
 #include "esp_gap_bt_api.h"
 #include "esp_bt_device.h"
 #include "esp_spp_api.h"
-#include "bt_spp.c"
+#include "bt_spp.h"
 
 #include "ax25_pad2.h"
 #include "ax25_pad.h"
@@ -39,11 +49,6 @@
 
 //#include "esp_dsp.h"
 
-uint8_t APRS_TEST_PACKET[] = { 0x82, 0x98, 0x98, 0x40, 0x40, 0x40, 0xe0, 0x96, 0x84, 0x66, 0xaa, 0x96, 0xac, 0xe0, 0xae, 0x92,
-									 0x88, 0x8a, 0x62, 0x40, 0x62, 0xae, 0x92, 0x88, 0x8a, 0x64, 0x40, 0x65, 0x03, 0xf0, 0x3a, 0x4b,
-									 0x42, 0x33, 0x55, 0x4b, 0x56, 0x2d, 0x32, 0x20, 0x3a, 0x48, 0x69, 0x21, 0x20, 0x54, 0x68, 0x69, 0x73,
-									 0x20, 0x69, 0x73, 0x20, 0x61, 0x20, 0x54, 0x65, 0x73, 0x74, 0x7b, 0x31, 0xad, 0xa1 };
-
 RingbufHandle_t radio_tx_buf;
 RingbufHandle_t radio_rx_buf;
 
@@ -113,7 +118,7 @@ void Radio_Task(void *pvParameters)
 	rx_config.auto_reload = TIMER_AUTORELOAD_EN;
     timer_init(TIMER_GROUP_0, TIMER_0, &rx_config);
     timer_set_counter_value(TIMER_GROUP_0, TIMER_0, 0x00000000ULL);
-    timer_set_alarm_value(TIMER_GROUP_0, TIMER_0, 6666);
+    timer_set_alarm_value(TIMER_GROUP_0, TIMER_0, 3030);
     timer_isr_register(TIMER_GROUP_0, TIMER_0, rx_timer_isr,
     		(void *) TIMER_0, ESP_INTR_FLAG_IRAM, NULL);
 
@@ -205,26 +210,33 @@ void dsps_biquad_f32_ansi(const float *input, float *output, int len, float *coe
     return;
 }
 
-float lpf_coef[5];
-float lpf_delay[2];
+float lpf_coef0[5];
+float lpf_coef1[5];
+float lpf_delay0[2];
+float lpf_delay1[2];
 
 void lpf_init(void)
 {
 	// generate filter coef
-	dsps_biquad_gen_lpf_f32(lpf_coef, 0.1999, 1);
+	dsps_biquad_gen_lpf_f32(lpf_coef0, 0.10, 0.54119610);
+	dsps_biquad_gen_lpf_f32(lpf_coef1, 0.10, 1.3065630);
+
 
 	// setup delay line and lpf_input window
 	int i;
-	for(i=0;i<sizeof(lpf_delay)/sizeof(float);i++)
+	for(i=0;i<2;i++)
 	{
-		lpf_delay[i] = 0;
+		lpf_delay0[i] = 0;
+		lpf_delay1[i] = 0;
 	}
 }
 
 float lpf_baseband(float input)
 {
-	float output;
-	dsps_biquad_f32_ansi(&input, &output, 1, lpf_coef, lpf_delay);
+	float output, temp;
+	dsps_biquad_f32_ansi(&input, &temp, 1, lpf_coef0, lpf_delay0);
+	dsps_biquad_f32_ansi(&temp, &output, 1, lpf_coef1, lpf_delay1);
+
 	return output;
 }
 
@@ -233,12 +245,17 @@ void RX_DSP_Task(void *pvParameters)
 {
 	// algorithm variables
 	volatile float E_s1=0, E_s2=0, lpf_output;
-	uint8_t raw_bit=0, previous_raw_bit=0;
+	volatile uint8_t raw_bit=0, previous_raw_bit=1;
 	volatile int32_t d_pll=0, dpll_error=0, err_div=0, dpll_margin = 1;
 	uint32_t success = 0;
+	float coeff0, coeff1;
+
+	volatile uint32_t count_start, count_stop; // needed for debuging
+
 
 	aprs_decoder_init();
 	frame_buffer_init(aprs_buf, 256);
+	goertzel_init(1200, 2200, &coeff0, &coeff1);
 	lpf_init();
 
 	// Sampling Semaphore
@@ -246,6 +263,7 @@ void RX_DSP_Task(void *pvParameters)
 
 	while(1)
 	{
+		count_start = xthal_get_ccount();
 		if( xSemaphoreTake(xRadioRXISRSemaphore, portMAX_DELAY) == pdTRUE)
 		{
 
@@ -255,6 +273,7 @@ void RX_DSP_Task(void *pvParameters)
 				//disable_debug_IO(DEBUG_0);
 				//enable_debug_IO(DEBUG_0);
 				EXTERNAL_DATA = (int)cc1200_radio_read_CFM();
+				//EXTERNAL_DATA = gpio_get_level(CC1120_GPIO2);
 				xSemaphoreGive(xRadioMutex);
 				//disable_debug_IO(DEBUG_0);
 			}
@@ -267,8 +286,10 @@ void RX_DSP_Task(void *pvParameters)
 
 			window_add(EXTERNAL_DATA);
 			int8_t *window = window_get();
-			E_s1 = goertzelFilter2(window, 1200, WINDOW_SIZE);
-			E_s2 = goertzelFilter2(window, 2200, WINDOW_SIZE);
+			E_s1 = goertzel_filter(window, coeff0, WINDOW_SIZE);
+			E_s2 = goertzel_filter(window, coeff1, WINDOW_SIZE);
+			//E_s1 = goertzelFilter(window, 1200, WINDOW_SIZE);
+			//E_s1 = goertzelFilter(window, 2200, WINDOW_SIZE);
 			lpf_output = lpf_baseband((E_s1 - E_s2));
 
 			if (lpf_output > 0)
@@ -307,7 +328,7 @@ void RX_DSP_Task(void *pvParameters)
 			if (d_pll >= D_PLL_MAX)
 			{
 				// set clock debug I/O high
-				enable_debug_IO(DEBUG_0);
+				enable_debug_IO(DEBUG_3);
 
 				// feed bit to aprs decoder algorithm
 				switch(aprs_decoder_feed_bit(raw_bit))
@@ -333,8 +354,9 @@ void RX_DSP_Task(void *pvParameters)
 			else
 			{
 				// set clock debug I/O low
-				disable_debug_IO(DEBUG_0);
+				disable_debug_IO(DEBUG_3);
 			}
+			count_stop = xthal_get_ccount();
 			previous_raw_bit = raw_bit;
 		}
 	}