/* * Project: Arrow * Author: curiousmuch */ #include #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "freertos/semphr.h" #include "driver/gpio.h" #include "sdkconfig.h" #include "esp_task_wdt.h" #include "cc1200.h" #include "cc1200_protocol.h" #include "board.h" #include "nvs.h" #include "nvs_flash.h" #include "esp_log.h" #include "esp_bt.h" #include "esp_bt_main.h" #include "esp_gap_bt_api.h" #include "esp_bt_device.h" #include "esp_spp_api.h" #include "bt_spp.c" #include "ax25_pad2.h" #include "ax25_pad.h" #include "fcs_calc.h" #include "math.h" #include "driver/timer.h" //#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; SemaphoreHandle_t xRadioRXISRSemaphore; SemaphoreHandle_t xRadioRXSemaphore; SemaphoreHandle_t xRadioTXSemaphore; //RingbufHandle_t radio_rx_buf; extern int8_t EXTERNAL_DATA; #define WINDOW_SIZE 6 #define SAMPLEFREQUENCY 6000 int window[WINDOW_SIZE]; int lpf_window[WINDOW_SIZE]; double goertzelFilter(int samples[], double freq, int N) { double s_prev = 0.0; double s_prev2 = 0.0; double coeff,normalizedfreq,power,s; int i; normalizedfreq = freq / SAMPLEFREQUENCY; coeff = 2*cos(2*M_PI*normalizedfreq); for (i=0; i E_s2) { enable_debug_IO(DEBUG_0); } else { disable_debug_IO(DEBUG_0); } //disable_debug_IO(DEBUG_0); } } } void radio_init() { // Setup Task Communications radio_tx_buf = xRingbufferCreate(1028, RINGBUF_TYPE_NOSPLIT); xRadioRXSemaphore = xSemaphoreCreateBinary(); xRadioTXSemaphore = xSemaphoreCreateBinary(); // Initialize Radio cc1200_radio_init(APRS_RX_SETTINGS, sizeof(APRS_RX_SETTINGS)/sizeof(cc1200_reg_settings_t)); cc1200_radio_frequency(144390000-6000); // Setup Sampling Timer timer_config_t config; config.divider = 2; config.counter_dir = TIMER_COUNT_UP; config.counter_en = TIMER_PAUSE; config.alarm_en = TIMER_ALARM_EN; config.intr_type = TIMER_INTR_LEVEL; config.auto_reload = TIMER_AUTORELOAD_EN; 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() { // Initialize Flash esp_err_t ret = nvs_flash_init(); if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { ESP_ERROR_CHECK(nvs_flash_erase()); ret = nvs_flash_init(); } ESP_ERROR_CHECK( ret ); // Board IO Initialize board_init(); // Radio Task Initialize radio_init(); // Setup Kiss Decoder and Encoder kiss_init(); // Initalize BLE bt_spp_init(); }