|
@@ -46,7 +46,7 @@ spi_device_interface_config_t interface_config =
|
|
|
.dummy_bits = 0,
|
|
|
.mode = 0,
|
|
|
.spics_io_num = CC1120_CS,
|
|
|
- .clock_speed_hz = (APB_CLK_FREQ/8),
|
|
|
+ .clock_speed_hz = (APB_CLK_FREQ/16),
|
|
|
.flags = 0,
|
|
|
.queue_size = 20
|
|
|
|
|
@@ -180,6 +180,20 @@ void IRAM_ATTR cc1200_spi_read_byte(uint16_t addr, uint8_t* data)
|
|
|
ESP_ERROR_CHECK(ret);
|
|
|
}
|
|
|
|
|
|
+uint8_t IRAM_ATTR cc1200_radio_read_RSSI(void)
|
|
|
+{
|
|
|
+ uint8_t data = 0;
|
|
|
+ cc1200_spi_read_byte(CC120X_RSSI1, &data);
|
|
|
+ return data;
|
|
|
+}
|
|
|
+
|
|
|
+uint8_t IRAM_ATTR cc1200_radio_read_CFM(void)
|
|
|
+{
|
|
|
+ uint8_t data = 0;
|
|
|
+ cc1200_spi_read_byte(CC120X_CFM_RX_DATA_OUT, &data);
|
|
|
+ return data;
|
|
|
+}
|
|
|
+
|
|
|
void cc1200_spi_read_bytes(uint16_t addr, uint8_t* data, uint8_t len)
|
|
|
{
|
|
|
esp_err_t ret;
|
|
@@ -396,17 +410,20 @@ void IRAM_ATTR cc1200_radio_APRSTXPacket(uint8_t *f, uint16_t f_len, uint8_t tx
|
|
|
vTaskSuspendAll();
|
|
|
|
|
|
// setup data rate for CFM TX
|
|
|
- cc1200_radio_write(APRS_TX_RATE, sizeof(APRS_TX_RATE)/sizeof(cc1200_reg_settings_t));
|
|
|
+ cc1200_radio_write(APRS_TX_SETTINGS, sizeof(APRS_TX_SETTINGS)/sizeof(cc1200_reg_settings_t));
|
|
|
+ cc1200_radio_frequency(144390000-6000);
|
|
|
+
|
|
|
|
|
|
// start CW transmission
|
|
|
cc1200_spi_write_byte(CC120X_FIFO, 0x12);
|
|
|
- cc1200_spi_strobe(CC120X_STX);
|
|
|
+ while(cc1200_spi_strobe(CC120X_STX) != CC120X_STATE_TX);
|
|
|
|
|
|
// enable interrupt pin for CC1120 for timing packets
|
|
|
gpio_install_isr_service(ESP_INTR_FLAG_IRAM);
|
|
|
-
|
|
|
gpio_isr_handler_add(CC1120_GPIO3, cc1200_aprs_tx_isr, NULL);
|
|
|
gpio_set_intr_type(CC1120_GPIO3, GPIO_INTR_POSEDGE);
|
|
|
+ gpio_intr_enable(CC1120_GPIO3);
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -414,98 +431,70 @@ void IRAM_ATTR cc1200_radio_APRSTXPacket(uint8_t *f, uint16_t f_len, uint8_t tx
|
|
|
uint16_t p_len = tx_delay * 12;
|
|
|
uint16_t t_len = tx_tail * 12 + 1;
|
|
|
|
|
|
- // Start CW transmission
|
|
|
- cc1200_spi_write_byte(CC120X_FIFO, 0x12);
|
|
|
- cc1200_spi_strobe(CC120X_STX);
|
|
|
+ // Start CW transmission
|
|
|
+ cc1200_spi_write_byte(CC120X_FIFO, 0x12);
|
|
|
+ cc1200_spi_strobe(CC120X_STX);
|
|
|
|
|
|
- sample_count = 0;
|
|
|
- new_sample = 0;
|
|
|
+ sample_count = 0;
|
|
|
+ new_sample = 0;
|
|
|
|
|
|
- // Send HDLC Flag for TX Delay Time
|
|
|
- for (i = 0; i<p_len; i++)
|
|
|
+ // Send HDLC Flag for TX Delay Time
|
|
|
+ for (i = 0; i<p_len; i++)
|
|
|
+ {
|
|
|
+ esp_task_wdt_reset();
|
|
|
+ aprs_flags.byte = 0x7E;
|
|
|
+ for(j=0; j<8; j++)
|
|
|
{
|
|
|
- esp_task_wdt_reset();
|
|
|
- aprs_flags.byte = 0x7E;
|
|
|
- for(j=0; j<8; j++)
|
|
|
- {
|
|
|
- aprs_flags.cur_bit = aprs_flags.byte & 0x01;
|
|
|
+ aprs_flags.cur_bit = aprs_flags.byte & 0x01;
|
|
|
|
|
|
- // NRZ-I Encoding
|
|
|
- if (aprs_flags.cur_bit)
|
|
|
- {
|
|
|
- // do nothing
|
|
|
- aprs_flags.one_count++;
|
|
|
+ // NRZ-I Encoding
|
|
|
+ if (aprs_flags.cur_bit)
|
|
|
+ {
|
|
|
+ // do nothing
|
|
|
+ aprs_flags.one_count++;
|
|
|
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- aprs_flags.tone = aprs_flags.tone ^ 1; // switch tone
|
|
|
- aprs_flags.one_count = 0;
|
|
|
- }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ aprs_flags.tone = aprs_flags.tone ^ 1; // switch tone
|
|
|
+ aprs_flags.one_count = 0;
|
|
|
+ }
|
|
|
|
|
|
- aprs_flags.byte = (aprs_flags.byte >> 1);
|
|
|
+ aprs_flags.byte = (aprs_flags.byte >> 1);
|
|
|
|
|
|
- while(sample_count < 11) // wait for symbol to be sent
|
|
|
+ while(sample_count < 11) // wait for symbol to be sent
|
|
|
+ {
|
|
|
+ if ( new_sample )
|
|
|
{
|
|
|
- if ( new_sample )
|
|
|
- {
|
|
|
- LUT_lookup();
|
|
|
- new_sample = 0;
|
|
|
- }
|
|
|
+ LUT_lookup();
|
|
|
+ new_sample = 0;
|
|
|
}
|
|
|
- sample_count = 0;
|
|
|
- //printf("Symbol: %x\n", aprs_flags.cur_bit);
|
|
|
-
|
|
|
}
|
|
|
+ sample_count = 0;
|
|
|
+ //printf("Symbol: %x\n", aprs_flags.cur_bit);
|
|
|
+
|
|
|
}
|
|
|
- aprs_flags.one_count = 0;
|
|
|
+ }
|
|
|
+ aprs_flags.one_count = 0;
|
|
|
|
|
|
- // Send Packet / Frame
|
|
|
- //for (i=0;i<aprs_flags.packet_len;i++)
|
|
|
- for (i=0;i<f_len;i++)
|
|
|
+ // Send Packet / Frame
|
|
|
+ //for (i=0;i<aprs_flags.packet_len;i++)
|
|
|
+ for (i=0;i<f_len;i++)
|
|
|
+ {
|
|
|
+ esp_task_wdt_reset();
|
|
|
+ aprs_flags.byte = f[i];
|
|
|
+ for(j=0; j<8; j++)
|
|
|
{
|
|
|
- esp_task_wdt_reset();
|
|
|
- aprs_flags.byte = f[i];
|
|
|
- for(j=0; j<8; j++)
|
|
|
- {
|
|
|
- aprs_flags.cur_bit = aprs_flags.byte & 0x01; // bool of first bit
|
|
|
-
|
|
|
- // Zero Stuffing
|
|
|
- if (aprs_flags.one_count == 5)
|
|
|
- {
|
|
|
- aprs_flags.tone = aprs_flags.tone ^ 1;
|
|
|
- aprs_flags.one_count = 0;
|
|
|
-
|
|
|
- // wait for symbol to be sent
|
|
|
- while(sample_count < 11)
|
|
|
- {
|
|
|
- if ( new_sample )
|
|
|
- {
|
|
|
- LUT_lookup();
|
|
|
- new_sample = 0;
|
|
|
- }
|
|
|
- }
|
|
|
- toggle2 = toggle2 ^ 1;
|
|
|
- //gpio_set_level(DEBUG_0, toggle2);
|
|
|
- sample_count = 0;
|
|
|
- }
|
|
|
-
|
|
|
- // NRZ-I Encoding
|
|
|
- if (aprs_flags.cur_bit)
|
|
|
- {
|
|
|
- // do nothing
|
|
|
- aprs_flags.one_count++;
|
|
|
-
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- aprs_flags.tone = aprs_flags.tone ^ 1; // switch tone
|
|
|
- aprs_flags.one_count = 0;
|
|
|
- }
|
|
|
+ aprs_flags.cur_bit = aprs_flags.byte & 0x01; // bool of first bit
|
|
|
|
|
|
- aprs_flags.byte = (aprs_flags.byte >> 1);
|
|
|
+ // Zero Stuffing
|
|
|
+ if (aprs_flags.one_count == 5)
|
|
|
+ {
|
|
|
+ aprs_flags.tone = aprs_flags.tone ^ 1;
|
|
|
+ aprs_flags.one_count = 0;
|
|
|
|
|
|
- while(sample_count < 11) // wait for symbol to be sent
|
|
|
+ // wait for symbol to be sent
|
|
|
+ while(sample_count < 11)
|
|
|
{
|
|
|
if ( new_sample )
|
|
|
{
|
|
@@ -516,73 +505,105 @@ void IRAM_ATTR cc1200_radio_APRSTXPacket(uint8_t *f, uint16_t f_len, uint8_t tx
|
|
|
toggle2 = toggle2 ^ 1;
|
|
|
//gpio_set_level(DEBUG_0, toggle2);
|
|
|
sample_count = 0;
|
|
|
- //printf("Symbol: %x\n", aprs_flags.cur_bit);
|
|
|
}
|
|
|
- }
|
|
|
- aprs_flags.one_count = 0;
|
|
|
|
|
|
- // Send HDLC Flag for TX Tail
|
|
|
- for (i = 0; i<t_len; i++)
|
|
|
- {
|
|
|
- esp_task_wdt_reset();
|
|
|
- aprs_flags.byte = 0x7E;
|
|
|
- for(j=0; j<8;j++)
|
|
|
+ // NRZ-I Encoding
|
|
|
+ if (aprs_flags.cur_bit)
|
|
|
{
|
|
|
- aprs_flags.cur_bit = aprs_flags.byte & 0x01;
|
|
|
+ // do nothing
|
|
|
+ aprs_flags.one_count++;
|
|
|
|
|
|
- // NRZ-I Encoding
|
|
|
- if (aprs_flags.cur_bit)
|
|
|
- {
|
|
|
- // do nothing
|
|
|
- aprs_flags.one_count++;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ aprs_flags.tone = aprs_flags.tone ^ 1; // switch tone
|
|
|
+ aprs_flags.one_count = 0;
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
- else
|
|
|
+ aprs_flags.byte = (aprs_flags.byte >> 1);
|
|
|
+
|
|
|
+ while(sample_count < 11) // wait for symbol to be sent
|
|
|
+ {
|
|
|
+ if ( new_sample )
|
|
|
{
|
|
|
- aprs_flags.tone = aprs_flags.tone ^ 1; // switch tone
|
|
|
- aprs_flags.one_count = 0;
|
|
|
+ LUT_lookup();
|
|
|
+ new_sample = 0;
|
|
|
}
|
|
|
+ }
|
|
|
+ toggle2 = toggle2 ^ 1;
|
|
|
+ //gpio_set_level(DEBUG_0, toggle2);
|
|
|
+ sample_count = 0;
|
|
|
+ //printf("Symbol: %x\n", aprs_flags.cur_bit);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ aprs_flags.one_count = 0;
|
|
|
+
|
|
|
+ // Send HDLC Flag for TX Tail
|
|
|
+ for (i = 0; i<t_len; i++)
|
|
|
+ {
|
|
|
+ esp_task_wdt_reset();
|
|
|
+ aprs_flags.byte = 0x7E;
|
|
|
+ for(j=0; j<8;j++)
|
|
|
+ {
|
|
|
+ aprs_flags.cur_bit = aprs_flags.byte & 0x01;
|
|
|
|
|
|
- aprs_flags.byte = (aprs_flags.byte >> 1);
|
|
|
+ // NRZ-I Encoding
|
|
|
+ if (aprs_flags.cur_bit)
|
|
|
+ {
|
|
|
+ // do nothing
|
|
|
+ aprs_flags.one_count++;
|
|
|
|
|
|
- while(sample_count < 11) // wait for symbol to be sent
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ aprs_flags.tone = aprs_flags.tone ^ 1; // switch tone
|
|
|
+ aprs_flags.one_count = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ aprs_flags.byte = (aprs_flags.byte >> 1);
|
|
|
+
|
|
|
+ while(sample_count < 11) // wait for symbol to be sent
|
|
|
+ {
|
|
|
+ if ( new_sample )
|
|
|
{
|
|
|
- if ( new_sample )
|
|
|
- {
|
|
|
- LUT_lookup();
|
|
|
- new_sample = 0;
|
|
|
- }
|
|
|
+ LUT_lookup();
|
|
|
+ new_sample = 0;
|
|
|
}
|
|
|
- sample_count = 0;
|
|
|
-
|
|
|
}
|
|
|
+ sample_count = 0;
|
|
|
+
|
|
|
}
|
|
|
- cc1200_spi_strobe(CC120X_SIDLE);
|
|
|
- //cc1200_spi_strobe(CC120X_SFTX);
|
|
|
- xTaskResumeAll();
|
|
|
- spi_device_release_bus(spi);
|
|
|
- gpio_uninstall_isr_service();
|
|
|
+ }
|
|
|
+
|
|
|
+ gpio_intr_disable(CC1120_GPIO3);
|
|
|
+ gpio_set_intr_type(CC1120_GPIO3, GPIO_INTR_DISABLE);
|
|
|
+ while(cc1200_spi_strobe(CC120X_SIDLE)!= CC120X_STATE_IDLE);
|
|
|
+ xTaskResumeAll();
|
|
|
+ spi_device_release_bus(spi);
|
|
|
+ gpio_uninstall_isr_service();
|
|
|
}
|
|
|
|
|
|
extern SemaphoreHandle_t xRadioRXSemaphore;
|
|
|
+int8_t EXTERNAL_DATA;
|
|
|
|
|
|
static void IRAM_ATTR cc1200_aprs_rx_isr(void* arg)
|
|
|
{
|
|
|
|
|
|
//uint8_t data = 0;
|
|
|
//cc1200_spi_read_byte(CC120X_CFM_RX_DATA_OUT, &data);
|
|
|
- static BaseType_t xHigherPriorityTaskWoken;
|
|
|
+ static BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
|
|
|
|
|
|
|
|
- gpio_set_intr_type(CC1120_GPIO2, GPIO_INTR_DISABLE);
|
|
|
+ //gpio_set_intr_type(CC1120_GPIO2, GPIO_INTR_DISABLE);
|
|
|
|
|
|
+ cc1200_spi_read_byte(CC120X_CFM_RX_DATA_OUT, (uint8_t *)&EXTERNAL_DATA);
|
|
|
xSemaphoreGiveFromISR(xRadioRXSemaphore, &xHigherPriorityTaskWoken);
|
|
|
if (xHigherPriorityTaskWoken == pdTRUE)
|
|
|
{
|
|
|
portYIELD_FROM_ISR( );
|
|
|
}
|
|
|
|
|
|
- //cc1200_spi_read_byte(CC120X_RSSI1, &data);
|
|
|
+
|
|
|
|
|
|
//toggle = toggle ^ 1;
|
|
|
// gpio_set_level(DEBUG_0, toggle);
|
|
@@ -598,24 +619,28 @@ void IRAM_ATTR cc1200_radio_start_APRSRX(void)
|
|
|
// acquire SPI bus for fastest possible SPI transactions
|
|
|
spi_device_acquire_bus(spi, portMAX_DELAY);
|
|
|
|
|
|
- //vTaskSuspendAll();
|
|
|
|
|
|
// start RX transmission
|
|
|
- cc1200_radio_write(APRS_RX_RATE, sizeof(APRS_RX_RATE)/sizeof(cc1200_reg_settings_t));
|
|
|
- while(cc1200_spi_strobe(CC120X_SRX) != CC120X_STATE_RX);
|
|
|
+ cc1200_radio_write(APRS_RX_SETTINGS, sizeof(APRS_RX_SETTINGS)/sizeof(cc1200_reg_settings_t));
|
|
|
+ cc1200_radio_frequency(144390000-6000);
|
|
|
|
|
|
-
|
|
|
- // enable interrupt pin for CC1120 for timing packets
|
|
|
+ // 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);
|
|
|
+
|
|
|
+ while(cc1200_spi_strobe(CC120X_SRX) != CC120X_STATE_RX);
|
|
|
}
|
|
|
|
|
|
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();
|
|
|
- cc1200_spi_strobe(CC120X_SIDLE);
|
|
|
+
|
|
|
+ while(cc1200_spi_strobe(CC120X_SIDLE) != CC120X_STATE_IDLE);
|
|
|
spi_device_release_bus(spi);
|
|
|
}
|
|
|
|
|
@@ -627,9 +652,9 @@ void cc1200_radio_init(const cc1200_reg_settings_t* rf_settings, uint8_t len)
|
|
|
|
|
|
cc1200_radio_reset(); gpio_set_level(CC1120_RESET, 1);
|
|
|
|
|
|
- uint8_t data;
|
|
|
- cc1200_spi_read_byte(CC120X_PARTNUMBER, &data);
|
|
|
- printf("%x", data);
|
|
|
+ //uint8_t data;
|
|
|
+ //cc1200_spi_read_byte(CC120X_PARTNUMBER, &data);
|
|
|
+ //printf("%x", data);
|
|
|
|
|
|
|
|
|
uint8_t i;
|
|
@@ -638,6 +663,8 @@ void cc1200_radio_init(const cc1200_reg_settings_t* rf_settings, uint8_t len)
|
|
|
{
|
|
|
cc1200_spi_write_byte(rf_settings[i].addr, rf_settings[i].data);
|
|
|
}
|
|
|
+ while(cc1200_spi_strobe(CC120X_SIDLE) != CC120X_STATE_IDLE);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|