main.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #include "main.h"
  2. #include "ReadKey.h"
  3. #include "key.h"
  4. #include "ReadKey.h"
  5. #include "crc8.h"
  6. #include "led.h"
  7. #include "eventUnit.h"
  8. #include "myADC.h"
  9. #include "myInputCapture.h"
  10. #include "myLcd.h"
  11. #include "myDisplayUnit.h"
  12. #include "myFlashData.h"
  13. #include "myTim.h"
  14. #include "myUart.h"
  15. #include "myUart3.h"
  16. #include "myRadio.h"
  17. #define SOFT_VERSION 0x11
  18. #define SET_RF_FREQ_HZ(base, ch,step) base+ch*step*10*1000
  19. //---------------key
  20. KeyParamExt_ts *getKeyReturn;
  21. key_value_te keyPressValue;
  22. static uint16_t present_adcValue;
  23. static uartPacket_ts uart3Packet;
  24. static uartPacket_ts uartPackage_Rx;
  25. static bool startToCountingRx = false;
  26. static float present_moduleCurrendValue;
  27. static float validPackageCount = 0;
  28. static uint32_t rfContinuousFreq = 1;
  29. static float rfRxTestRate = 1;
  30. static uint8_t packetTxMode;
  31. static uint8_t packetRxMode;
  32. static rfRxPacket_ts rfRecvPacket;
  33. static rfTxPacket_ts rfTxPacket;
  34. static uint32_t rfTxCount = 0;
  35. static uint32_t rfRxCount = 0;
  36. static uint32_t rfTxAndGetAckTime_ms = 0;
  37. static uint32_t rfTxAndGetAckTimeSet_ms = 1000;
  38. static uint32_t rfTxReTmCount = 0;
  39. static bool rfTxGetAckStatus = false;
  40. static uint8_t rfCtrlMode;
  41. const uint32_t rfBaseFreqList[DVTP_MAX_COUNT] =
  42. {
  43. 2400000000, 2400000000, 2400000000, 2400000000
  44. };
  45. const uint32_t rfBaudrateList[MAX_RF_BAUDRATE_GF_COUNT] =
  46. {
  47. 125, 250, 250, 400, 400, 500, 500, 800, 800, 1000, 1000, 1600, 2000
  48. };
  49. const uint32_t rfBaudrateList_flr[MAX_RF_BAUDRATE_FLR_COUNT] =
  50. {
  51. 130000, 260000, 520000, 1040000
  52. };
  53. const uint32_t rfLoraBaudrateList[MAX_RF_BAUDRATE_LR_COUNT] =
  54. {
  55. 216, 1000, 5000, 10000, 20000, 61000, 127000, 203000
  56. };
  57. const int8_t rfTxPowerList[RF_TX_PWR_MAX_COUNT] =
  58. {
  59. -18, -17, -16, -15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13
  60. };
  61. static bool rftxflag = false;
  62. static void rcc_init(void)
  63. {
  64. RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA, ENABLE );
  65. RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE );
  66. RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOC, ENABLE );
  67. RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOD, ENABLE );
  68. RCC_APB2PeriphClockCmd( RCC_APB2Periph_SPI1, ENABLE );
  69. RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
  70. #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL)
  71. /* ADCCLK = PCLK2/2 */
  72. RCC_ADCCLKConfig(RCC_PCLK2_Div2);
  73. #else
  74. /* ADCCLK = PCLK2/4 */
  75. RCC_ADCCLKConfig(RCC_PCLK2_Div4);
  76. #endif
  77. }
  78. void TIM3_CALLBACK(void)
  79. {
  80. static uint8_t timeCnt_1ms = 0;
  81. if(timeCnt_1ms ++ == 5)
  82. {
  83. timeCnt_1ms = 0;
  84. }
  85. }
  86. void rfRx_callback(uint8_t status, rfRxPacket_ts packet)
  87. {
  88. switch (status)
  89. {
  90. case RX_STA_SECCESS:
  91. {
  92. rfRecvPacket = packet;
  93. myRadio_receiver();
  94. }
  95. break;
  96. case RX_STA_TIMEOUT:
  97. {
  98. myRadio_receiver();
  99. }
  100. break;
  101. case RX_STA_PAYLOAD_ERROR:
  102. {
  103. myRadio_receiver();
  104. }
  105. break;
  106. case TX_STA_SECCESS:
  107. {
  108. myRadio_receiver();
  109. rftxflag = false;
  110. }
  111. break;
  112. default:
  113. break;
  114. }
  115. }
  116. int main(void)
  117. {
  118. userParams_ts userParamsTemp;
  119. NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//
  120. #ifdef BOOTLOADER_APP
  121. SCB->VTOR = FLASH_BASE | 0x000C800;
  122. #endif
  123. rcc_init();
  124. GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);//
  125. myTim1_init(200, TIM3_CALLBACK);
  126. myRadio_init(0, rfRx_callback);
  127. myRadio_setFrequency(2402000000);
  128. myRadio_setTxPower(3);
  129. myRadio_setBaudrate(RF_BAUDRATE_LR_127K);
  130. myRadio_receiver();
  131. while(1)
  132. {
  133. if (rftxflag == false)
  134. {
  135. myRadio_delay(500);
  136. rftxflag = true;
  137. rfTxPacket.len = 5;
  138. strcpy(rfTxPacket.payload, "hello");
  139. myRadio_transmit(&rfTxPacket);
  140. }
  141. myRadio_process();
  142. }
  143. }