123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- #include "main.h"
- #include "ReadKey.h"
- #include "key.h"
- #include "ReadKey.h"
- #include "crc8.h"
- #include "led.h"
- #include "eventUnit.h"
- #include "myADC.h"
- #include "myInputCapture.h"
- #include "myLcd.h"
- #include "myDisplayUnit.h"
- #include "myFlashData.h"
- #include "myTim.h"
- #include "myUart.h"
- #include "myUart3.h"
- #include "myRadio.h"
- #define SOFT_VERSION 0x11
- #define SET_RF_FREQ_HZ(base, ch,step) base+ch*step*10*1000
- //---------------key
- KeyParamExt_ts *getKeyReturn;
- key_value_te keyPressValue;
- static uint16_t present_adcValue;
- static uartPacket_ts uart3Packet;
- static uartPacket_ts uartPackage_Rx;
- static bool startToCountingRx = false;
- static float present_moduleCurrendValue;
- static float validPackageCount = 0;
- static uint32_t rfContinuousFreq = 1;
- static float rfRxTestRate = 1;
- static uint8_t packetTxMode;
- static uint8_t packetRxMode;
- static rfRxPacket_ts rfRecvPacket;
- static rfTxPacket_ts rfTxPacket;
- static uint32_t rfTxCount = 0;
- static uint32_t rfRxCount = 0;
- static uint32_t rfTxAndGetAckTime_ms = 0;
- static uint32_t rfTxAndGetAckTimeSet_ms = 1000;
- static uint32_t rfTxReTmCount = 0;
- static bool rfTxGetAckStatus = false;
- static uint8_t rfCtrlMode;
- const uint32_t rfBaseFreqList[DVTP_MAX_COUNT] =
- {
- 2400000000, 2400000000, 2400000000, 2400000000
- };
- const uint32_t rfBaudrateList[MAX_RF_BAUDRATE_GF_COUNT] =
- {
- 125, 250, 250, 400, 400, 500, 500, 800, 800, 1000, 1000, 1600, 2000
- };
- const uint32_t rfBaudrateList_flr[MAX_RF_BAUDRATE_FLR_COUNT] =
- {
- 130000, 260000, 520000, 1040000
- };
- const uint32_t rfLoraBaudrateList[MAX_RF_BAUDRATE_LR_COUNT] =
- {
- 216, 1000, 5000, 10000, 20000, 61000, 127000, 203000
- };
- const int8_t rfTxPowerList[RF_TX_PWR_MAX_COUNT] =
- {
- -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
- };
- static bool rftxflag = false;
- static void rcc_init(void)
- {
- RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA, ENABLE );
- RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE );
- RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOC, ENABLE );
- RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOD, ENABLE );
- RCC_APB2PeriphClockCmd( RCC_APB2Periph_SPI1, ENABLE );
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
- #if defined (STM32F10X_LD_VL) || defined (STM32F10X_MD_VL) || defined (STM32F10X_HD_VL)
- /* ADCCLK = PCLK2/2 */
- RCC_ADCCLKConfig(RCC_PCLK2_Div2);
- #else
- /* ADCCLK = PCLK2/4 */
- RCC_ADCCLKConfig(RCC_PCLK2_Div4);
- #endif
- }
- void TIM3_CALLBACK(void)
- {
- static uint8_t timeCnt_1ms = 0;
- if(timeCnt_1ms ++ == 5)
- {
- timeCnt_1ms = 0;
- }
- }
- void rfRx_callback(uint8_t status, rfRxPacket_ts packet)
- {
- switch (status)
- {
- case RX_STA_SECCESS:
- {
- rfRecvPacket = packet;
- myRadio_receiver();
-
- }
- break;
- case RX_STA_TIMEOUT:
- {
- myRadio_receiver();
- }
- break;
- case RX_STA_PAYLOAD_ERROR:
- {
- myRadio_receiver();
- }
- break;
- case TX_STA_SECCESS:
- {
- myRadio_receiver();
- rftxflag = false;
- }
- break;
- default:
- break;
- }
- }
- int main(void)
- {
- userParams_ts userParamsTemp;
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//
- #ifdef BOOTLOADER_APP
- SCB->VTOR = FLASH_BASE | 0x000C800;
- #endif
- rcc_init();
-
- GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);//
- myTim1_init(200, TIM3_CALLBACK);
- myRadio_init(0, rfRx_callback);
- myRadio_setFrequency(2402000000);
- myRadio_setTxPower(3);
- myRadio_setBaudrate(RF_BAUDRATE_LR_127K);
- myRadio_receiver();
- while(1)
- {
- if (rftxflag == false)
- {
- myRadio_delay(500);
- rftxflag = true;
- rfTxPacket.len = 5;
- strcpy(rfTxPacket.payload, "hello");
- myRadio_transmit(&rfTxPacket);
- }
- myRadio_process();
- }
- }
|