cc1200.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. /*
  2. * Project: Arrow
  3. * Author: curiousmuch
  4. */
  5. #include <stdio.h>
  6. #include <math.h>
  7. #include "freertos/FreeRTOS.h"
  8. #include "freertos/task.h"
  9. #include "freertos/semphr.h"
  10. #include "freertos/portmacro.h"
  11. #include "driver/gpio.h"
  12. #include "sdkconfig.h"
  13. #include "driver/spi_master.h"
  14. #include "esp_err.h"
  15. #include "cc1200.h"
  16. #include "cc1200_protocol.h"
  17. #include "board.h"
  18. #include "esp_task_wdt.h"
  19. #include "freertos/ringbuf.h"
  20. #include "esp_log.h"
  21. #include "driver/timer.h"
  22. #define CC_TAG "CC1200_Driver"
  23. #define CC1200_WRITE_BIT 0
  24. #define CC1200_READ_BIT BIT(1)
  25. #define CC1200_BURST_BIT BIT(0)
  26. // Public Configurations for CC1120 SPI Driver
  27. spi_bus_config_t bus_config =
  28. {
  29. .miso_io_num = CC1120_MISO,
  30. .mosi_io_num = CC1120_MOSI,
  31. .sclk_io_num = CC1120_SCLK,
  32. .quadwp_io_num = -1,
  33. .quadhd_io_num = -1,
  34. .max_transfer_sz = 150,
  35. .flags = SPICOMMON_BUSFLAG_MASTER,
  36. .intr_flags = ESP_INTR_FLAG_IRAM
  37. };
  38. spi_device_interface_config_t interface_config =
  39. {
  40. .command_bits = 2,
  41. .address_bits = 6,
  42. .dummy_bits = 0,
  43. .mode = 0,
  44. .spics_io_num = CC1120_CS,
  45. .clock_speed_hz = (APB_CLK_FREQ/16),
  46. .flags = 0,
  47. .queue_size = 20
  48. };
  49. spi_device_handle_t spi;
  50. // Private CC1120 Driver Functions
  51. void cc1200_gpio_init(void)
  52. {
  53. gpio_config_t reset_pin_config =
  54. {
  55. .pin_bit_mask = (uint64_t)(BIT64(CC1120_RESET)),
  56. .mode = GPIO_MODE_OUTPUT,
  57. .pull_up_en = GPIO_PULLUP_DISABLE,
  58. .pull_down_en = GPIO_PULLDOWN_DISABLE,
  59. .intr_type = GPIO_INTR_DISABLE
  60. };
  61. gpio_config_t gpio_pin_config =
  62. {
  63. .pin_bit_mask = (uint64_t) (BIT64(CC1120_GPIO0)|BIT64(CC1120_GPIO2)|BIT64(CC1120_GPIO3)),
  64. .mode = GPIO_MODE_INPUT,
  65. .pull_up_en = GPIO_PULLUP_DISABLE,
  66. .pull_down_en = GPIO_PULLDOWN_DISABLE,
  67. .intr_type = GPIO_INTR_DISABLE
  68. };
  69. gpio_config(&reset_pin_config);
  70. gpio_config(&gpio_pin_config);
  71. gpio_set_level(CC1120_RESET, 1);
  72. }
  73. void cc1200_spi_init(void)
  74. {
  75. esp_err_t ret;
  76. ret = spi_bus_initialize(VSPI_HOST, &bus_config, 0); // this uses DMA channel 1
  77. ESP_ERROR_CHECK(ret);
  78. ret = spi_bus_add_device(VSPI_HOST, &interface_config, &spi);
  79. ESP_ERROR_CHECK(ret);
  80. }
  81. void IRAM_ATTR cc1200_spi_write_byte(uint16_t addr, uint8_t data)
  82. {
  83. esp_err_t ret;
  84. spi_transaction_t tx_trans =
  85. {
  86. .flags = SPI_TRANS_USE_TXDATA,
  87. .cmd = CC1200_WRITE_BIT,
  88. .addr = addr,
  89. .length = 8,
  90. .rxlength = 0,
  91. .tx_data[0] = data
  92. };
  93. if ((addr & 0xFF00) != 0) // send data with extended address in command field
  94. {
  95. tx_trans.flags |= (SPI_TRANS_VARIABLE_CMD | SPI_TRANS_VARIABLE_ADDR);
  96. spi_transaction_ext_t tx_trans_ext =
  97. {
  98. .base = tx_trans,
  99. .command_bits = 2,
  100. .address_bits = 14
  101. };
  102. ret = spi_device_polling_transmit(spi, (spi_transaction_t*)&tx_trans_ext);
  103. }
  104. else
  105. {
  106. ret = spi_device_polling_transmit(spi, &tx_trans);
  107. }
  108. ESP_ERROR_CHECK(ret);
  109. }
  110. void IRAM_ATTR cc1200_spi_write_bytes(uint16_t addr, uint8_t* data, uint8_t len)
  111. {
  112. esp_err_t ret;
  113. spi_transaction_t tx_trans =
  114. {
  115. .cmd = (CC1200_WRITE_BIT | CC1200_BURST_BIT),
  116. .addr = addr,
  117. .length = 8*len,
  118. .tx_buffer = data
  119. };
  120. if ((addr & 0xFF00) != 0) // send data with extended address in command field
  121. {
  122. tx_trans.flags |= (SPI_TRANS_VARIABLE_CMD | SPI_TRANS_VARIABLE_ADDR);
  123. spi_transaction_ext_t tx_trans_ext =
  124. {
  125. .base = tx_trans,
  126. .command_bits = 2,
  127. .address_bits = 14
  128. };
  129. ret = spi_device_polling_transmit(spi, (spi_transaction_t*)&tx_trans_ext);
  130. }
  131. else
  132. {
  133. ret = spi_device_polling_transmit(spi, &tx_trans);
  134. }
  135. ESP_ERROR_CHECK(ret);
  136. }
  137. void IRAM_ATTR cc1200_spi_read_byte(uint16_t addr, uint8_t* data)
  138. {
  139. esp_err_t ret;
  140. spi_transaction_t rx_trans =
  141. {
  142. .cmd = CC1200_READ_BIT,
  143. .addr = addr,
  144. .length = 8,
  145. .rxlength = 8,
  146. .rx_buffer = data
  147. };
  148. if ((addr & 0xFF00) != 0) // read data with extended address in command field
  149. {
  150. rx_trans.flags |= (SPI_TRANS_VARIABLE_CMD | SPI_TRANS_VARIABLE_ADDR);
  151. spi_transaction_ext_t rx_trans_ext =
  152. {
  153. .base = rx_trans,
  154. .command_bits = 2,
  155. .address_bits = 14
  156. };
  157. ret = spi_device_polling_transmit(spi, (spi_transaction_t*)&rx_trans_ext);
  158. }
  159. else
  160. {
  161. ret = spi_device_polling_transmit(spi, &rx_trans);
  162. }
  163. ESP_ERROR_CHECK(ret);
  164. }
  165. uint8_t IRAM_ATTR cc1200_radio_read_RSSI(void)
  166. {
  167. uint8_t data = 0;
  168. cc1200_spi_read_byte(CC120X_RSSI1, &data);
  169. return data;
  170. }
  171. uint8_t IRAM_ATTR cc1200_radio_read_CFM(void)
  172. {
  173. uint8_t data = 0;
  174. cc1200_spi_read_byte(CC120X_CFM_RX_DATA_OUT, &data);
  175. return data;
  176. }
  177. void cc1200_spi_read_bytes(uint16_t addr, uint8_t* data, uint8_t len)
  178. {
  179. esp_err_t ret;
  180. spi_transaction_t rx_trans =
  181. {
  182. .cmd = (CC1200_READ_BIT | CC1200_BURST_BIT),
  183. .addr = addr,
  184. .length = 8*len,
  185. .rxlength = 8*len,
  186. .rx_buffer = data
  187. };
  188. if ((addr & 0xFF00) != 0) // read data with extended address in command field
  189. {
  190. rx_trans.flags |= (SPI_TRANS_VARIABLE_CMD | SPI_TRANS_VARIABLE_ADDR);
  191. spi_transaction_ext_t rx_trans_ext =
  192. {
  193. .base = rx_trans,
  194. .command_bits = 2,
  195. .address_bits = 14
  196. };
  197. ret = spi_device_polling_transmit(spi, (spi_transaction_t*)&rx_trans_ext);
  198. }
  199. else
  200. {
  201. ret = spi_device_polling_transmit(spi, &rx_trans);
  202. }
  203. ESP_ERROR_CHECK(ret);
  204. }
  205. rf_status_t IRAM_ATTR cc1200_spi_strobe(uint8_t cmd)
  206. {
  207. esp_err_t ret;
  208. uint8_t temp=0;
  209. spi_transaction_t rx_trans =
  210. {
  211. .flags = (SPI_TRANS_USE_TXDATA | SPI_TRANS_VARIABLE_CMD | SPI_TRANS_VARIABLE_ADDR),
  212. .length = 8,
  213. .rxlength = 8,
  214. .rx_buffer = &temp,
  215. .tx_data[0] = cmd
  216. };
  217. spi_transaction_ext_t rx_trans_ext =
  218. {
  219. .base = rx_trans,
  220. .command_bits = 0,
  221. .address_bits = 0
  222. };
  223. ret = spi_device_polling_transmit(spi, (spi_transaction_t*)&rx_trans_ext);
  224. ESP_ERROR_CHECK(ret);
  225. return (temp & 0xF0);
  226. }
  227. // Public CC1120 Driver Functions
  228. // These function should have there own error codes as they're dependent upon the radio and
  229. // not the ESP32 :)
  230. rf_status_t cc1200_radio_reset(void)
  231. {
  232. rf_status_t status;
  233. uint8_t retry_count = 0;
  234. cc1200_spi_strobe(CC120X_SRES);
  235. status = cc1200_spi_strobe(CC120X_SNOP);
  236. vTaskDelay(20 / portTICK_PERIOD_MS);
  237. while((CC120X_RDYn_BIT & (status & 0x80)))
  238. {
  239. vTaskDelay(10 / portTICK_PERIOD_MS);
  240. if (retry_count > 3)
  241. {
  242. // place error CC1120 timeout
  243. printf("CC1120 Reset Failure\n");
  244. break;
  245. }
  246. status = cc1200_spi_strobe(CC120X_SNOP);
  247. retry_count++;
  248. }
  249. printf("%x\n", retry_count);
  250. return status;
  251. }
  252. // f_RF = f_VCO / LO Divider
  253. #define CC1200_LO_DIVIDER 24 // 136.7 - 160 MHz Band
  254. #define CC1200_XOSC 40000000 // 40MHz
  255. // f_VCO = FREQ / 2^16 * f_XOSX + FREQOFF / 2^18 * F_XOSC
  256. esp_err_t cc1200_radio_frequency(uint32_t freq)
  257. {
  258. // calculate FREQ0, FREQ, FREQ2 registers
  259. volatile double temp_freq;
  260. temp_freq = ((double) freq * 65536 * CC1200_LO_DIVIDER) / CC1200_XOSC;
  261. freq = (uint32_t)temp_freq;
  262. cc1200_spi_write_byte(CC120X_FREQ0, ((uint8_t *)&freq)[0]);
  263. cc1200_spi_write_byte(CC120X_FREQ1, ((uint8_t *)&freq)[1]);
  264. cc1200_spi_write_byte(CC120X_FREQ2, ((uint8_t *)&freq)[2]);
  265. return ESP_OK;
  266. }
  267. esp_err_t cc1200_radio_sleep(void)
  268. {
  269. return ESP_OK;
  270. }
  271. esp_err_t cc1200_radio_power(uint8_t txPower)
  272. {
  273. return ESP_OK;
  274. }
  275. void cc1200_radio_write(const cc1200_reg_settings_t* rf_settings, uint8_t len)
  276. {
  277. uint8_t i;
  278. for (i=0;i<len;i++)
  279. {
  280. cc1200_spi_write_byte(rf_settings[i].addr, rf_settings[i].data);
  281. }
  282. }
  283. #define HDLC_FLAG 0x7E
  284. #define HDLC_FLAG_LEN 10
  285. uint8_t packet_len = 0;
  286. uint8_t test_vector[] = {0x71, 0x01, 023, 0xAE, 0x75};
  287. volatile uint8_t sample_count = 0;
  288. uint8_t toggle;
  289. uint8_t toggle2;
  290. uint8_t prev_sample_count = 0;
  291. uint32_t tx_symbol = 0;
  292. uint8_t prev_tx_symbol = 0;
  293. #define SAMPLE_FREQUENCY 13200
  294. #define DAC_MAX 64
  295. #define LUT_SIZE 128
  296. DRAM_ATTR int8_t LUT[LUT_SIZE];
  297. int32_t phase_i = 0;
  298. volatile uint8_t new_sample = 0;
  299. float phase = 0.0f;
  300. float delta_phi = 0.0f;
  301. float const delta_phi_1 = (float) 1200 / SAMPLE_FREQUENCY * LUT_SIZE;
  302. float const delta_phi_2 = (float) 2200 / SAMPLE_FREQUENCY * LUT_SIZE;
  303. uint8_t data;
  304. // The output needs to be continous phase.
  305. typedef struct {
  306. uint8_t one_count;
  307. uint32_t sample_count;
  308. uint32_t byte;
  309. uint32_t packet_len;
  310. uint8_t prev_bit;
  311. uint8_t cur_bit;
  312. uint8_t tone;
  313. } aprs_flags_t;
  314. aprs_flags_t DRAM_ATTR aprs_flags = {
  315. .one_count = 0,
  316. .sample_count = 0,
  317. .byte = 0,
  318. // .packet_len = sizeof(APRS_TEST_PACKET)/sizeof(uint8_t),
  319. .prev_bit = 0,
  320. .cur_bit = 0,
  321. .tone = 0
  322. };
  323. static void IRAM_ATTR LUT_lookup(void)
  324. {
  325. if (aprs_flags.tone)
  326. delta_phi = delta_phi_1;
  327. else
  328. delta_phi = delta_phi_2;
  329. phase_i = (int32_t)phase; // get integer part of our phase
  330. phase += delta_phi; // increment phase
  331. if (phase >= (float)LUT_SIZE) // handle wraparound
  332. phase -= (float)LUT_SIZE;
  333. }
  334. void IRAM_ATTR cc1200_aprs_tx_isr(void* para)
  335. {
  336. GPIO.out_w1ts = (1 << DEBUG_0);
  337. int timer_idx = (int) para;
  338. /* Clear the interrupt
  339. and update the alarm time for the timer with without reload */
  340. TIMERG0.int_clr_timers.t1 = 1;
  341. // after the alarm has been triggered
  342. // we need enable it again, so it is triggered the next time
  343. TIMERG0.hw_timer[1].config.alarm_en = TIMER_ALARM_EN;
  344. cc1200_spi_write_byte(CC120X_CFM_TX_DATA_IN, LUT[phase_i]);
  345. sample_count++;
  346. new_sample = 1;
  347. toggle = toggle ^ 1;
  348. GPIO.out_w1tc = (1 << DEBUG_0);
  349. }
  350. void cc1200_lut_init(void)
  351. {
  352. int16_t i=0;
  353. for (i=0; i<LUT_SIZE; ++i)
  354. {
  355. LUT[i] = (int8_t)roundf(DAC_MAX * sinf(2.0f * M_PI * (float)i / LUT_SIZE));
  356. //printf("%d,\n", LUT[i]);
  357. }
  358. }
  359. #define PREAMBLE_LENGTH 20
  360. #define SUFFIX_LENGTH 1
  361. void IRAM_ATTR cc1200_radio_APRSTXPacket(uint8_t *f, uint16_t f_len, uint8_t tx_delay, uint8_t tx_tail)
  362. {
  363. // acquire SPI bus for fastest possible SPI transactions
  364. // spi_device_acquire_bus(spi, portMAX_DELAY);
  365. vTaskSuspendAll();
  366. // setup data rate for CFM TX
  367. // cc1200_radio_write(APRS_RX2_SETTINGS, sizeof(APRS_RX2_SETTINGS)/sizeof(cc1200_reg_settings_t));
  368. // cc1200_radio_frequency(144390000-6000);
  369. // start CW transmission
  370. // cc1200_spi_write_byte(CC120X_FIFO, 0x12);
  371. uint8_t state = 0x00;
  372. //while(cc1200_spi_strobe(CC120X_STX) != CC120X_STATE_TX);
  373. while(state != CC120X_STATE_TX)
  374. {
  375. state = cc1200_spi_strobe(CC120X_STX);
  376. }
  377. // enable interrupt pin for CC1120 for timing packets
  378. // gpio_install_isr_service(ESP_INTR_FLAG_IRAM);
  379. // gpio_isr_handler_add(CC1120_GPIO3, cc1200_aprs_tx_isr, NULL);
  380. // gpio_set_intr_type(CC1120_GPIO3, GPIO_INTR_POSEDGE);
  381. // gpio_intr_enable(CC1120_GPIO3);
  382. timer_enable_intr(TIMER_GROUP_0, TIMER_1);
  383. timer_set_counter_value(TIMER_GROUP_0, TIMER_1, 0x00000000ULL);
  384. timer_start(TIMER_GROUP_0, TIMER_1);
  385. int16_t i,j;
  386. uint16_t p_len = tx_delay * 12;
  387. uint16_t t_len = tx_tail * 12 + 1;
  388. //// // Start CW transmission
  389. // cc1200_spi_write_byte(CC120X_FIFO, 0x12);
  390. // cc1200_spi_strobe(CC120X_STX);
  391. sample_count = 0;
  392. new_sample = 0;
  393. // Send HDLC Flag for TX Delay Time
  394. for (i = 0; i<p_len; i++)
  395. {
  396. esp_task_wdt_reset();
  397. aprs_flags.byte = 0x7E;
  398. for(j=0; j<8; j++)
  399. {
  400. aprs_flags.cur_bit = aprs_flags.byte & 0x01;
  401. // NRZ-I Encoding
  402. if (aprs_flags.cur_bit)
  403. {
  404. // do nothing
  405. aprs_flags.one_count++;
  406. }
  407. else
  408. {
  409. aprs_flags.tone = aprs_flags.tone ^ 1; // switch tone
  410. aprs_flags.one_count = 0;
  411. }
  412. aprs_flags.byte = (aprs_flags.byte >> 1);
  413. while(sample_count < 11) // wait for symbol to be sent
  414. {
  415. if ( new_sample )
  416. {
  417. LUT_lookup();
  418. new_sample = 0;
  419. }
  420. }
  421. sample_count = 0;
  422. //printf("Symbol: %x\n", aprs_flags.cur_bit);
  423. }
  424. }
  425. aprs_flags.one_count = 0;
  426. // Send Packet / Frame
  427. //for (i=0;i<aprs_flags.packet_len;i++)
  428. for (i=0;i<f_len;i++)
  429. {
  430. esp_task_wdt_reset();
  431. aprs_flags.byte = f[i];
  432. for(j=0; j<8; j++)
  433. {
  434. aprs_flags.cur_bit = aprs_flags.byte & 0x01; // bool of first bit
  435. // Zero Stuffing
  436. if (aprs_flags.one_count == 5)
  437. {
  438. aprs_flags.tone = aprs_flags.tone ^ 1;
  439. aprs_flags.one_count = 0;
  440. // wait for symbol to be sent
  441. while(sample_count < 11)
  442. {
  443. if ( new_sample )
  444. {
  445. LUT_lookup();
  446. new_sample = 0;
  447. }
  448. }
  449. toggle2 = toggle2 ^ 1;
  450. //gpio_set_level(DEBUG_0, toggle2);
  451. sample_count = 0;
  452. }
  453. // NRZ-I Encoding
  454. if (aprs_flags.cur_bit)
  455. {
  456. // do nothing
  457. aprs_flags.one_count++;
  458. }
  459. else
  460. {
  461. aprs_flags.tone = aprs_flags.tone ^ 1; // switch tone
  462. aprs_flags.one_count = 0;
  463. }
  464. aprs_flags.byte = (aprs_flags.byte >> 1);
  465. while(sample_count < 11) // wait for symbol to be sent
  466. {
  467. if ( new_sample )
  468. {
  469. LUT_lookup();
  470. new_sample = 0;
  471. }
  472. }
  473. toggle2 = toggle2 ^ 1;
  474. //gpio_set_level(DEBUG_0, toggle2);
  475. sample_count = 0;
  476. //printf("Symbol: %x\n", aprs_flags.cur_bit);
  477. }
  478. }
  479. aprs_flags.one_count = 0;
  480. // Send HDLC Flag for TX Tail
  481. for (i = 0; i<t_len; i++)
  482. {
  483. esp_task_wdt_reset();
  484. aprs_flags.byte = 0x7E;
  485. for(j=0; j<8;j++)
  486. {
  487. aprs_flags.cur_bit = aprs_flags.byte & 0x01;
  488. // NRZ-I Encoding
  489. if (aprs_flags.cur_bit)
  490. {
  491. // do nothing
  492. aprs_flags.one_count++;
  493. }
  494. else
  495. {
  496. aprs_flags.tone = aprs_flags.tone ^ 1; // switch tone
  497. aprs_flags.one_count = 0;
  498. }
  499. aprs_flags.byte = (aprs_flags.byte >> 1);
  500. while(sample_count < 11) // wait for symbol to be sent
  501. {
  502. if ( new_sample )
  503. {
  504. LUT_lookup();
  505. new_sample = 0;
  506. }
  507. }
  508. sample_count = 0;
  509. }
  510. }
  511. // gpio_intr_disable(CC1120_GPIO3);
  512. // gpio_set_intr_type(CC1120_GPIO3, GPIO_INTR_DISABLE);
  513. timer_disable_intr(TIMER_GROUP_0, TIMER_1);
  514. timer_pause(TIMER_GROUP_0, TIMER_1);
  515. while(cc1200_spi_strobe(CC120X_SIDLE)!= CC120X_STATE_IDLE);
  516. xTaskResumeAll();
  517. // spi_device_release_bus(spi);
  518. // gpio_uninstall_isr_service();
  519. }
  520. extern SemaphoreHandle_t xRadioRXISRSemaphore;
  521. extern TaskHandle_t xRadioRXTaskHandle;
  522. int8_t EXTERNAL_DATA;
  523. static void IRAM_ATTR cc1200_aprs_rx_isr(void* arg)
  524. {
  525. //uint8_t data = 0;
  526. //cc1200_spi_read_byte(CC120X_CFM_RX_DATA_OUT, &data);
  527. //GPIO.out_w1ts = (1 << DEBUG_0);
  528. static BaseType_t xHigherPriorityTaskWoken = pdFALSE;
  529. //vTaskNotifyGiveFromISR( xRadioRXTaskHandle, &xHigherPriorityTaskWoken );
  530. xSemaphoreGiveFromISR(xRadioRXISRSemaphore, &xHigherPriorityTaskWoken);
  531. if (xHigherPriorityTaskWoken == pdTRUE)
  532. {
  533. portYIELD_FROM_ISR( );
  534. }
  535. //GPIO.out_w1tc = (1 << DEBUG_0);
  536. }
  537. void IRAM_ATTR cc1200_radio_start_APRSRX(void)
  538. {
  539. // acquire SPI bus for fastest possible SPI transactions
  540. //spi_device_acquire_bus(spi, portMAX_DELAY);
  541. // start RX transmission
  542. // cc1200_radio_write(APRS_RX2_SETTINGS, sizeof(APRS_RX2_SETTINGS)/sizeof(cc1200_reg_settings_t));
  543. // cc1200_radio_frequency(144390000-6000);
  544. // enable ISR for CC1120 for timing packets
  545. // gpio_install_isr_service(ESP_INTR_FLAG_IRAM);
  546. // gpio_isr_handler_add(CC1120_GPIO2, cc1200_aprs_rx_isr, NULL);
  547. // gpio_set_intr_type(CC1120_GPIO2, GPIO_INTR_POSEDGE);
  548. // gpio_intr_enable(CC1120_GPIO2);
  549. while(cc1200_spi_strobe(CC120X_SRX) != CC120X_STATE_RX)
  550. vTaskDelay(2/portTICK_PERIOD_MS);
  551. }
  552. void cc1200_radio_stop_APRSRX(void)
  553. {
  554. // disable interrupt
  555. // gpio_intr_disable(CC1120_GPIO2);
  556. // gpio_set_intr_type(CC1120_GPIO2, GPIO_INTR_DISABLE);
  557. // gpio_uninstall_isr_service();
  558. //spi_device_release_bus(spi);
  559. vTaskDelay(2/portTICK_PERIOD_MS);
  560. while(cc1200_spi_strobe(CC120X_SIDLE) != CC120X_STATE_IDLE)
  561. vTaskDelay(2/portTICK_PERIOD_MS);
  562. }
  563. void cc1200_radio_init(const cc1200_reg_settings_t* rf_settings, uint8_t len)
  564. {
  565. cc1200_gpio_init();
  566. cc1200_spi_init();
  567. cc1200_lut_init();
  568. spi_device_acquire_bus(spi, portMAX_DELAY);
  569. cc1200_radio_reset(); gpio_set_level(CC1120_RESET, 1);
  570. //uint8_t data;
  571. //cc1200_spi_read_byte(CC120X_PARTNUMBER, &data);
  572. //printf("%x", data);
  573. uint8_t i;
  574. for (i=0;i<len;i++)
  575. {
  576. cc1200_spi_write_byte(rf_settings[i].addr, rf_settings[i].data);
  577. }
  578. while(cc1200_spi_strobe(CC120X_SIDLE) != CC120X_STATE_IDLE);
  579. }