|
@@ -31,6 +31,7 @@
|
|
|
#include "math.h"
|
|
|
|
|
|
#include "driver/timer.h"
|
|
|
+#include "aprs_decoder.h"
|
|
|
|
|
|
|
|
|
//#include "esp_dsp.h"
|
|
@@ -97,7 +98,7 @@ void window_add(int sample)
|
|
|
window[0] = sample;
|
|
|
}
|
|
|
|
|
|
-uint8_t * window_get(void)
|
|
|
+int* window_get(void)
|
|
|
{
|
|
|
return window;
|
|
|
}
|
|
@@ -114,7 +115,7 @@ int window_get_size(void)
|
|
|
void IRAM_ATTR rx_timer_isr(void *para)
|
|
|
{
|
|
|
|
|
|
- //GPIO.out_w1ts = (1 << DEBUG_0);
|
|
|
+ GPIO.out_w1ts = (1 << DEBUG_0);
|
|
|
|
|
|
int timer_idx = (int) para;
|
|
|
|
|
@@ -134,7 +135,7 @@ void IRAM_ATTR rx_timer_isr(void *para)
|
|
|
portYIELD_FROM_ISR( );
|
|
|
}
|
|
|
|
|
|
- //GPIO.out_w1tc = (1 << DEBUG_0);
|
|
|
+ GPIO.out_w1tc = (1 << DEBUG_0);
|
|
|
|
|
|
}
|
|
|
|
|
@@ -178,6 +179,14 @@ void TX_Task(void *pvParameters)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// Phase Locked Loop (PLL) Parameters
|
|
|
+#define BAUD_RATE (1200)
|
|
|
+#define SAMPLES_BIT (SAMPLEFREQUENCY / BAUD_RATE)
|
|
|
+#define D_PLL_INC (SAMPLES_BIT * 1)
|
|
|
+#define D_PLL_MAX (D_PLL_INC * SAMPLES_BIT *1)
|
|
|
+#define D_PLL_MARGIN (1)
|
|
|
+
|
|
|
+uint8_t aprs_buf[256];
|
|
|
|
|
|
void RX_Task(void *pvParameters)
|
|
|
{
|
|
@@ -186,9 +195,13 @@ void RX_Task(void *pvParameters)
|
|
|
uint8_t count = 0;
|
|
|
|
|
|
// algorithm variables
|
|
|
- double E_s1, E_s2, result;
|
|
|
- E_s1 = 0; E_s2 = 0;
|
|
|
- int f_output = 0;
|
|
|
+ double E_s1=0, E_s2=0;
|
|
|
+ uint8_t raw_bit=0, previous_raw_bit=0;
|
|
|
+ int32_t d_pll=0, dpll_error=0, err_div=2;
|
|
|
+ int lpf_output = 0;
|
|
|
+
|
|
|
+ aprs_decoder_init();
|
|
|
+ frame_buffer_init(aprs_buf, 256);
|
|
|
|
|
|
// Sampling Semaphore
|
|
|
xRadioRXISRSemaphore = xSemaphoreCreateBinary();
|
|
@@ -208,23 +221,74 @@ void RX_Task(void *pvParameters)
|
|
|
if( xSemaphoreTake(xRadioRXISRSemaphore, portMAX_DELAY) == pdTRUE)
|
|
|
{
|
|
|
|
|
|
- //enable_debug_IO(DEBUG_0);
|
|
|
+ enable_debug_IO(DEBUG_0);
|
|
|
EXTERNAL_DATA = (int)cc1200_radio_read_CFM();
|
|
|
- //disable_debug_IO(DEBUG_0);
|
|
|
- //enable_debug_IO(DEBUG_0);
|
|
|
- f_output += (50000 * (((int)EXTERNAL_DATA) - f_output)) / 100000;
|
|
|
+ disable_debug_IO(DEBUG_0);
|
|
|
+ enable_debug_IO(DEBUG_0);
|
|
|
+ lpf_output += (50000 * (((int)EXTERNAL_DATA) - lpf_output)) / 100000;
|
|
|
window_add((int) EXTERNAL_DATA);
|
|
|
E_s1 = goertzelFilter(window, 1200, WINDOW_SIZE);
|
|
|
E_s2 = goertzelFilter(window, 2200, WINDOW_SIZE);
|
|
|
if (E_s1 > E_s2)
|
|
|
{
|
|
|
- enable_debug_IO(DEBUG_0);
|
|
|
+ raw_bit = 1;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ raw_bit = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ disable_debug_IO(DEBUG_0);
|
|
|
+ enable_debug_IO(DEBUG_0);
|
|
|
+ // DPLL for sampling
|
|
|
+ if (raw_bit != previous_raw_bit)
|
|
|
+ {
|
|
|
+ dpll_error = d_pll - (D_PLL_MAX / 2);
|
|
|
+ if (dpll_error > (D_PLL_MARGIN))
|
|
|
+ {
|
|
|
+ d_pll -= get_rx_status() ? D_PLL_MARGIN:
|
|
|
+ (dpll_error + err_div / 2) / err_div;
|
|
|
+ }
|
|
|
+ else if (dpll_error < (-D_PLL_MARGIN))
|
|
|
+ {
|
|
|
+ d_pll += get_rx_status() ? D_PLL_MARGIN:
|
|
|
+ (dpll_error + err_div / 2) / err_div;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ d_pll += D_PLL_INC;
|
|
|
+
|
|
|
+ disable_debug_IO(DEBUG_0);
|
|
|
+ enable_debug_IO(DEBUG_0);
|
|
|
+ if (d_pll >= D_PLL_MAX)
|
|
|
+ {
|
|
|
+ // set clock debug I/O high
|
|
|
+
|
|
|
+ // feed bit to aprs decoder algorithm
|
|
|
+ switch(aprs_decoder_feed_bit(raw_bit))
|
|
|
+ {
|
|
|
+ case NORMAL:
|
|
|
+ break;
|
|
|
+ case FRAME_DECODED:
|
|
|
+ printf("Success!\n");
|
|
|
+ ESP_LOG_BUFFER_HEXDUMP("APRS RX", aprs_buf, 100, ESP_LOG_INFO);
|
|
|
+ break;
|
|
|
+ case ERROR_FCS_MISMATCH:
|
|
|
+ //printf("FCS Incorrect!\n");
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ //printf("Weird Error\n");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ d_pll -= D_PLL_MAX;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- disable_debug_IO(DEBUG_0);
|
|
|
+ // set clock debug I/O low
|
|
|
}
|
|
|
- //disable_debug_IO(DEBUG_0);
|
|
|
+ previous_raw_bit = raw_bit;
|
|
|
+ disable_debug_IO(DEBUG_0);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -251,19 +315,12 @@ void radio_init()
|
|
|
timer_init(TIMER_GROUP_0, TIMER_0, &config);
|
|
|
timer_set_counter_value(TIMER_GROUP_0, TIMER_0, 0x00000000ULL);
|
|
|
timer_set_alarm_value(TIMER_GROUP_0, TIMER_0, 6666);
|
|
|
- //timer_enable_intr(TIMER_GROUP_0, TIMER_0);
|
|
|
timer_isr_register(TIMER_GROUP_0, TIMER_0, rx_timer_isr,
|
|
|
(void *) TIMER_0, ESP_INTR_FLAG_IRAM, NULL);
|
|
|
- //timer_start(TIMER_GROUP_0, TIMER_0);
|
|
|
-
|
|
|
|
|
|
- // Create Tasks
|
|
|
-// xTaskCreatePinnedToCore(Radio_Controller_Task, "Radio_Controller", 1024*4, 0, 10, NULL, 0);
|
|
|
xTaskCreatePinnedToCore(TX_Task, "TX Task", 1024*4, 0, 2, NULL, 1);
|
|
|
xTaskCreatePinnedToCore(RX_Task, "RX Task", 1024*4, 0, 1, NULL, 1);
|
|
|
|
|
|
-
|
|
|
-// xTaskCreatePinnedToCore(UART_Task, "UART Task", 1024*4, 0, 5, NULL, 0);
|
|
|
}
|
|
|
|
|
|
void IRAM_ATTR app_main()
|