|
@@ -44,13 +44,12 @@ RingbufHandle_t radio_tx_buf;
|
|
SemaphoreHandle_t xRadioRXISRSemaphore;
|
|
SemaphoreHandle_t xRadioRXISRSemaphore;
|
|
SemaphoreHandle_t xRadioRXSemaphore;
|
|
SemaphoreHandle_t xRadioRXSemaphore;
|
|
SemaphoreHandle_t xRadioTXSemaphore;
|
|
SemaphoreHandle_t xRadioTXSemaphore;
|
|
-TaskHandle_t xRadioRXTaskHandle;
|
|
|
|
|
|
|
|
//RingbufHandle_t radio_rx_buf;
|
|
//RingbufHandle_t radio_rx_buf;
|
|
|
|
|
|
extern int8_t EXTERNAL_DATA;
|
|
extern int8_t EXTERNAL_DATA;
|
|
|
|
|
|
-#define WINDOW_SIZE 7
|
|
|
|
|
|
+#define WINDOW_SIZE 6
|
|
#define SAMPLEFREQUENCY 6000
|
|
#define SAMPLEFREQUENCY 6000
|
|
|
|
|
|
int window[WINDOW_SIZE];
|
|
int window[WINDOW_SIZE];
|
|
@@ -108,6 +107,35 @@ int window_get_size(void)
|
|
return WINDOW_SIZE;
|
|
return WINDOW_SIZE;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+// Timer Functions
|
|
|
|
+void IRAM_ATTR rx_timer_isr(void *para)
|
|
|
|
+{
|
|
|
|
+
|
|
|
|
+ //GPIO.out_w1ts = (1 << DEBUG_0);
|
|
|
|
+
|
|
|
|
+ int timer_idx = (int) para;
|
|
|
|
+
|
|
|
|
+ /* Clear the interrupt
|
|
|
|
+ and update the alarm time for the timer with without reload */
|
|
|
|
+ TIMERG0.int_clr_timers.t0 = 1;
|
|
|
|
+
|
|
|
|
+ // after the alarm has been triggered
|
|
|
|
+ // we need enable it again, so it is triggered the next time
|
|
|
|
+ TIMERG0.hw_timer[0].config.alarm_en = TIMER_ALARM_EN;
|
|
|
|
+
|
|
|
|
+ static BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
|
|
|
+
|
|
|
|
+ xSemaphoreGiveFromISR(xRadioRXISRSemaphore, &xHigherPriorityTaskWoken);
|
|
|
|
+ if (xHigherPriorityTaskWoken == pdTRUE)
|
|
|
|
+ {
|
|
|
|
+ portYIELD_FROM_ISR( );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //GPIO.out_w1tc = (1 << DEBUG_0);
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
// The TX Task should have the highest
|
|
// The TX Task should have the highest
|
|
void TX_Task(void *pvParameters)
|
|
void TX_Task(void *pvParameters)
|
|
{
|
|
{
|
|
@@ -122,7 +150,10 @@ void TX_Task(void *pvParameters)
|
|
// send packet
|
|
// send packet
|
|
if (p != NULL)
|
|
if (p != NULL)
|
|
{
|
|
{
|
|
|
|
+
|
|
// disable RX mode
|
|
// disable RX mode
|
|
|
|
+ timer_pause(TIMER_GROUP_0, TIMER_0);
|
|
|
|
+ timer_disable_intr(TIMER_GROUP_0, TIMER_0);
|
|
cc1200_radio_stop_APRSRX();
|
|
cc1200_radio_stop_APRSRX();
|
|
|
|
|
|
// setup LEDs for TX mode
|
|
// setup LEDs for TX mode
|
|
@@ -138,6 +169,9 @@ void TX_Task(void *pvParameters)
|
|
enable_green_led();
|
|
enable_green_led();
|
|
|
|
|
|
cc1200_radio_start_APRSRX();
|
|
cc1200_radio_start_APRSRX();
|
|
|
|
+ timer_enable_intr(TIMER_GROUP_0, TIMER_0);
|
|
|
|
+ timer_set_counter_value(TIMER_GROUP_0, TIMER_0, 0x00000000ULL);
|
|
|
|
+ timer_start(TIMER_GROUP_0, TIMER_0);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -157,16 +191,15 @@ void RX_Task(void *pvParameters)
|
|
// Sampling Semaphore
|
|
// Sampling Semaphore
|
|
xRadioRXISRSemaphore = xSemaphoreCreateBinary();
|
|
xRadioRXISRSemaphore = xSemaphoreCreateBinary();
|
|
|
|
|
|
- // get task handle for sampling isr
|
|
|
|
- xRadioRXTaskHandle = xTaskGetCurrentTaskHandle();
|
|
|
|
-
|
|
|
|
// setup LEDs for RX mode
|
|
// setup LEDs for RX mode
|
|
enable_green_led();
|
|
enable_green_led();
|
|
disable_red_led();
|
|
disable_red_led();
|
|
|
|
|
|
cc1200_radio_start_APRSRX();
|
|
cc1200_radio_start_APRSRX();
|
|
|
|
+ timer_enable_intr(TIMER_GROUP_0, TIMER_0);
|
|
|
|
+ timer_set_counter_value(TIMER_GROUP_0, TIMER_0, 0x00000000ULL);
|
|
|
|
+ timer_start(TIMER_GROUP_0, TIMER_0);
|
|
|
|
|
|
- uint32_t ulNotificationValue;
|
|
|
|
|
|
|
|
while(1)
|
|
while(1)
|
|
{
|
|
{
|
|
@@ -191,36 +224,10 @@ void RX_Task(void *pvParameters)
|
|
{
|
|
{
|
|
disable_debug_IO(DEBUG_0);
|
|
disable_debug_IO(DEBUG_0);
|
|
}
|
|
}
|
|
- ulNotificationValue = 0;
|
|
|
|
//disable_debug_IO(DEBUG_0);
|
|
//disable_debug_IO(DEBUG_0);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-// This task might want to run on CPU0 instead of CPU1. This tasks purpose is to decide which radio should be running and how long
|
|
|
|
-// we should wait before transmitting if data is received. It's also responsible for LBT, etc. This task should be lower priority than BLE etc.
|
|
|
|
-
|
|
|
|
-//void Radio_Controller_Task(void *pvParameters)
|
|
|
|
-//{
|
|
|
|
-// size_t p_size;
|
|
|
|
-//
|
|
|
|
-// cc1200_radio_init(APRS_RX_SETTINGS, sizeof(APRS_RX_SETTINGS)/sizeof(cc1200_reg_settings_t));
|
|
|
|
-// cc1200_radio_frequency(144390000-6000);
|
|
|
|
-//
|
|
|
|
-// while(1)
|
|
|
|
-// {
|
|
|
|
-// // check for a pending APRS packet in the buffer queue
|
|
|
|
-// uint8_t *p = (uint8_t *)xRingbufferReceive(radio_tx_buf, &p_size, 0); // TODO: Modify to something which will check CC1200 status
|
|
|
|
-// if (p != NULL)
|
|
|
|
-// {
|
|
|
|
-// // TODO:schedule packet based on TNC settings
|
|
|
|
-// xSemaphoreGive(xRadioTXSemaphore);
|
|
|
|
-// }
|
|
|
|
-// else
|
|
|
|
-// {
|
|
|
|
-// xSemaphoreGive(xRadioRXSemaphore);
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-//}
|
|
|
|
|
|
|
|
void radio_init()
|
|
void radio_init()
|
|
{
|
|
{
|
|
@@ -233,10 +240,27 @@ void radio_init()
|
|
cc1200_radio_init(APRS_RX_SETTINGS, sizeof(APRS_RX_SETTINGS)/sizeof(cc1200_reg_settings_t));
|
|
cc1200_radio_init(APRS_RX_SETTINGS, sizeof(APRS_RX_SETTINGS)/sizeof(cc1200_reg_settings_t));
|
|
cc1200_radio_frequency(144390000-6000);
|
|
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
|
|
// Create Tasks
|
|
// xTaskCreatePinnedToCore(Radio_Controller_Task, "Radio_Controller", 1024*4, 0, 10, NULL, 0);
|
|
// xTaskCreatePinnedToCore(Radio_Controller_Task, "Radio_Controller", 1024*4, 0, 10, NULL, 0);
|
|
- xTaskCreatePinnedToCore(RX_Task, "RX Task", 1024*4, 0, 1, NULL, 1);
|
|
|
|
xTaskCreatePinnedToCore(TX_Task, "TX Task", 1024*4, 0, 2, NULL, 1);
|
|
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);
|
|
// xTaskCreatePinnedToCore(UART_Task, "UART Task", 1024*4, 0, 5, NULL, 0);
|