main.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * Project: Arrow
  3. * Author: curiousmuch
  4. */
  5. #include <stdio.h>
  6. #include "freertos/FreeRTOS.h"
  7. #include "freertos/task.h"
  8. #include "freertos/semphr.h"
  9. #include "driver/gpio.h"
  10. #include "sdkconfig.h"
  11. #include "esp_task_wdt.h"
  12. #include "cc1200.h"
  13. #include "cc1200_protocol.h"
  14. #include "board.h"
  15. #include "nvs.h"
  16. #include "nvs_flash.h"
  17. #include "esp_log.h"
  18. #include "esp_bt.h"
  19. #include "esp_bt_main.h"
  20. #include "esp_gap_bt_api.h"
  21. #include "esp_bt_device.h"
  22. #include "esp_spp_api.h"
  23. #include "bt_spp.c"
  24. #include "ax25_pad2.h"
  25. #include "ax25_pad.h"
  26. #include "fcs_calc.h"
  27. uint8_t APRS_TEST_PACKET[] = { 0x82, 0x98, 0x98, 0x40, 0x40, 0x40, 0xe0, 0x96, 0x84, 0x66, 0xaa, 0x96, 0xac, 0xe0, 0xae, 0x92,
  28. 0x88, 0x8a, 0x62, 0x40, 0x62, 0xae, 0x92, 0x88, 0x8a, 0x64, 0x40, 0x65, 0x03, 0xf0, 0x3a, 0x4b,
  29. 0x42, 0x33, 0x55, 0x4b, 0x56, 0x2d, 0x32, 0x20, 0x3a, 0x48, 0x69, 0x21, 0x20, 0x54, 0x68, 0x69, 0x73,
  30. 0x20, 0x69, 0x73, 0x20, 0x61, 0x20, 0x54, 0x65, 0x73, 0x74, 0x7b, 0x31, 0xad, 0xa1 };
  31. RingbufHandle_t radio_tx_buf;
  32. SemaphoreHandle_t xRadioRXSemaphore;
  33. //RingbufHandle_t radio_rx_buf;
  34. void Radio_Task(void *pvParameters)
  35. {
  36. size_t p_size;
  37. // create sempahore
  38. xRadioRXSemaphore = xSemaphoreCreateBinary();
  39. // Setup Radio
  40. cc1200_radio_init(APRS_SETTINGS, sizeof(APRS_SETTINGS)/sizeof(cc1200_reg_settings_t));
  41. cc1200_radio_frequency(144390000-6000);
  42. cc1200_radio_start_APRSRX();
  43. uint8_t toggle=0;
  44. while(1)
  45. {
  46. // setup LEDs for RX mode
  47. enable_green_led();
  48. disable_red_led();
  49. //cc1200_radio_start_APRSRX();
  50. if (xSemaphoreTake(xRadioRXSemaphore, 0) == pdTRUE)
  51. {
  52. toggle = toggle ^ 1;
  53. gpio_set_level(DEBUG_0, toggle);
  54. gpio_set_intr_type(CC1120_GPIO2, GPIO_INTR_POSEDGE);
  55. }
  56. //esp_task_wdt_reset();
  57. // Transmit Queued Packet
  58. uint8_t *p = (uint8_t *)xRingbufferReceive(radio_tx_buf, &p_size, 0); // TODO: Modify to something which will check CC1200 status
  59. if (p != NULL)
  60. {
  61. // disable RX mode
  62. cc1200_radio_stop_APRSRX();
  63. // setup LEDs for TX mode
  64. enable_red_led();
  65. disable_green_led();
  66. cc1200_radio_APRSTXPacket(p, p_size, 2, 0);
  67. vRingbufferReturnItem(radio_tx_buf, (void *)p);
  68. cc1200_radio_start_APRSRX();
  69. }
  70. }
  71. }
  72. //void UART_Task(void *pvParameters)
  73. //{
  74. //
  75. //}
  76. //
  77. void radio_task_init()
  78. {
  79. radio_tx_buf = xRingbufferCreate(1028, RINGBUF_TYPE_NOSPLIT);
  80. xTaskCreatePinnedToCore(Radio_Task, "Radio_Task", 1024*4, 0, 1, NULL, 1);
  81. }
  82. void IRAM_ATTR app_main()
  83. {
  84. // Initialize Flash
  85. esp_err_t ret = nvs_flash_init();
  86. if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
  87. ESP_ERROR_CHECK(nvs_flash_erase());
  88. ret = nvs_flash_init();
  89. }
  90. ESP_ERROR_CHECK( ret );
  91. // Board IO Initialize
  92. board_init();
  93. // Radio Task Initialize
  94. radio_task_init();
  95. // Setup Kiss Decoder and Encoder
  96. kiss_init();
  97. // Initalize BLE
  98. bt_spp_init();
  99. }