Browse Source

Switch RX sampling trigger to internal clock and switch RX mode to transparent. This needs to be implmented for TX.

curiousmuch 4 years ago
parent
commit
fd45a758fe
4 changed files with 100 additions and 43 deletions
  1. 27 0
      .vscode/launch.json
  2. 9 7
      main/cc1200.c
  3. 7 3
      main/cc1200_protocol.h
  4. 57 33
      main/main.c

+ 27 - 0
.vscode/launch.json

@@ -0,0 +1,27 @@
+{
+    // Use IntelliSense to learn about possible attributes.
+    // Hover to view descriptions of existing attributes.
+    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
+    "version": "0.2.0",
+    "configurations": [
+        {
+            "name": "(gdb) Launch",
+            "type": "cppdbg",
+            "request": "launch",
+            "program": "enter program name, for example ${workspaceFolder}/a.out",
+            "args": [],
+            "stopAtEntry": false,
+            "cwd": "${workspaceFolder}",
+            "environment": [],
+            "externalConsole": false,
+            "MIMode": "gdb",
+            "setupCommands": [
+                {
+                    "description": "Enable pretty-printing for gdb",
+                    "text": "-enable-pretty-printing",
+                    "ignoreFailures": true
+                }
+            ]
+        }
+    ]
+}

+ 9 - 7
main/cc1200.c

@@ -19,6 +19,8 @@
 #include "freertos/ringbuf.h"
 #include "esp_log.h"
 
+#include "driver/timer.h"
+
 #define CC_TAG "CC1200_Driver"
 
 #define CC1200_WRITE_BIT 	0
@@ -618,10 +620,10 @@ void IRAM_ATTR cc1200_radio_start_APRSRX(void)
 	cc1200_radio_frequency(144390000-6000);
 
 	// enable ISR for CC1120 for timing packets
-	gpio_install_isr_service(ESP_INTR_FLAG_IRAM);
-	gpio_isr_handler_add(CC1120_GPIO2, cc1200_aprs_rx_isr, NULL);
-	gpio_set_intr_type(CC1120_GPIO2, GPIO_INTR_POSEDGE);
-	gpio_intr_enable(CC1120_GPIO2);
+//	gpio_install_isr_service(ESP_INTR_FLAG_IRAM);
+//	gpio_isr_handler_add(CC1120_GPIO2, cc1200_aprs_rx_isr, NULL);
+//	gpio_set_intr_type(CC1120_GPIO2, GPIO_INTR_POSEDGE);
+//	gpio_intr_enable(CC1120_GPIO2);
 
 	while(cc1200_spi_strobe(CC120X_SRX) != CC120X_STATE_RX);
 }
@@ -629,9 +631,9 @@ void IRAM_ATTR cc1200_radio_start_APRSRX(void)
 void cc1200_radio_stop_APRSRX(void)
 {
 	// disable interrupt
-	gpio_intr_disable(CC1120_GPIO2);
-	gpio_set_intr_type(CC1120_GPIO2, GPIO_INTR_DISABLE);
-	gpio_uninstall_isr_service();
+//	gpio_intr_disable(CC1120_GPIO2);
+//	gpio_set_intr_type(CC1120_GPIO2, GPIO_INTR_DISABLE);
+//	gpio_uninstall_isr_service();
 
 	while(cc1200_spi_strobe(CC120X_SIDLE) != CC120X_STATE_IDLE);
 	spi_device_release_bus(spi);

+ 7 - 3
main/cc1200_protocol.h

@@ -63,20 +63,24 @@ static const cc1200_reg_settings_t APRS_RX_SETTINGS[]=
   {CC120X_IQIC,              0xCB},
   {CC120X_CHAN_BW,           0x9C},
   {CC120X_MDMCFG1, 			 0x00},	// Random guess
-  {CC120X_MDMCFG0,           0x05},
+  {CC120X_MDMCFG0,           0x41},
+  //{CC120X_MDMCFG0,           0x05},
   // 6 kHz
   {CC120X_SYMBOL_RATE2,      0x63},
   {CC120X_SYMBOL_RATE1,      0xA9},
   {CC120X_SYMBOL_RATE0,      0x2A},
   {CC120X_AGC_REF,           0x30},
   {CC120X_AGC_CS_THR,        0xEC},
+  {CC120X_AGC_CFG3, 		 0x11}, // new
   {CC120X_AGC_CFG1,          0x51},
   {CC120X_AGC_CFG0,          0x87},
   {CC120X_FIFO_CFG,          0x00},
   {CC120X_FS_CFG,            0x1B},
-  {CC120X_PKT_CFG2,          0x01},
+  {CC120X_PKT_CFG2,          0x03},
   {CC120X_PKT_CFG1,          0x00},
-  {CC120X_PKT_CFG0,          0x20},
+  {CC120X_PKT_CFG0,          0x40},	// new
+  {CC120X_RFEND_CFG1,        0x0F},	// new
+  {CC120X_RFEND_CFG0,        0x00},
   {CC120X_PA_CFG1,           0x3F},
   {CC120X_PKT_LEN,           0xFF},
   {CC120X_IF_MIX_CFG,        0x1C},

+ 57 - 33
main/main.c

@@ -44,13 +44,12 @@ RingbufHandle_t radio_tx_buf;
 SemaphoreHandle_t xRadioRXISRSemaphore;
 SemaphoreHandle_t xRadioRXSemaphore;
 SemaphoreHandle_t xRadioTXSemaphore;
-TaskHandle_t xRadioRXTaskHandle;
 
 //RingbufHandle_t radio_rx_buf;
 
 extern int8_t EXTERNAL_DATA;
 
-#define WINDOW_SIZE 7
+#define WINDOW_SIZE 6
 #define SAMPLEFREQUENCY 6000
 
 int window[WINDOW_SIZE];
@@ -108,6 +107,35 @@ int window_get_size(void)
 	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
 void TX_Task(void *pvParameters)
 {
@@ -122,7 +150,10 @@ void TX_Task(void *pvParameters)
 		// send packet
 		if (p != NULL)
 		{
+
 			// disable RX mode
+			timer_pause(TIMER_GROUP_0, TIMER_0);
+		    timer_disable_intr(TIMER_GROUP_0, TIMER_0);
 			cc1200_radio_stop_APRSRX();
 
 			// setup LEDs for TX mode
@@ -138,6 +169,9 @@ void TX_Task(void *pvParameters)
 			enable_green_led();
 
 			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
 	xRadioRXISRSemaphore = xSemaphoreCreateBinary();
 
-	// get task handle for sampling isr
-	xRadioRXTaskHandle = xTaskGetCurrentTaskHandle();
-
 	// setup LEDs for RX mode
 	enable_green_led();
 	disable_red_led();
 
 	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)
 	{
@@ -191,36 +224,10 @@ void RX_Task(void *pvParameters)
 			{
 				disable_debug_IO(DEBUG_0);
 			}
-			ulNotificationValue = 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()
 {
@@ -233,10 +240,27 @@ void radio_init()
 	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(RX_Task, "RX Task", 1024*4, 0, 1, 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);