| | |
| | | #include "string.h" |
| | | #include "stdio.h" |
| | | #include "delay.h" |
| | | #include "lora.h" |
| | | #define NSH1 0x0001 |
| | | #define GP 0x0002 |
| | | #define FLASH_HARDWARE_VERSION_MAP (uint32_t)0x08004F00 //硬件版本号和批次信息位置 |
| | | #define DEBUG_MODE |
| | | //#define DEBUG_MODE |
| | | /* USER CODE END Includes */ |
| | | |
| | | /* Private typedef -----------------------------------------------------------*/ |
| | |
| | | uint8_t state5v = 1; |
| | | float motor_keeptime; |
| | | void IdleTask(void) |
| | | {u16 current_time; |
| | | { |
| | | //if(huart1.Instance->ISR&USART_ISR_FE) |
| | | // { |
| | | // SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader |
| | |
| | | |
| | | } |
| | | |
| | | |
| | | void delay_us(uint32_t nTimer) |
| | | { |
| | | uint32_t i=0; |
| | | for(i=0;i<nTimer;i++){ |
| | | __NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP(); |
| | | __NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP(); |
| | | __NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP(); |
| | | __NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP(); |
| | | __NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP(); |
| | | __NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP(); |
| | | __NOP();__NOP();__NOP();__NOP(); |
| | | } |
| | | } |
| | | u16 total_slotnum,current_slotnum; |
| | | extern int32_t offsettimeus; |
| | | u16 last_lpcount = 0; |
| | | void SetNextPollTime(u16 time) |
| | | { |
| | | int32_t lpcount,lptime,target_time; |
| | | int32_t lpcount; |
| | | |
| | | // if(current_slotnum>=total_slotnum) |
| | | // current_slotnum-=total_slotnum; |
| | |
| | | |
| | | u8 active_flag,nomovesleeptime; |
| | | void Program_Init(void) |
| | | { float temp; |
| | | uint16_t temp2; |
| | | uint16_t i; |
| | | { |
| | | Usart1ParseDataCallback = UsartParseDataHandler; |
| | | parameter_init(); |
| | | hardware_version = STMFLASH_ReadHalfWord(FLASH_HARDWARE_VERSION_MAP); |
| | |
| | | hardware_type = STMFLASH_ReadHalfWord(FLASH_HARDWARE_VERSION_MAP+4); |
| | | //deca_sleep(1000); |
| | | g_com_map[VERSION] = (1<<8)|0; |
| | | testprogram(); |
| | | // testprogram(); |
| | | // g_com_map[DEV_ID]=0x6777; |
| | | #ifdef DEBUG_MODE |
| | | // g_com_map[GROUP_ID]=21; |
| | |
| | | // g_com_map[NOMOVESLEEP_TIME]=10; |
| | | #endif |
| | | // g_com_map[GROUP_ID]=33; |
| | | g_com_map[UWBPOLLTIME_MS_IDX] = 100; |
| | | g_com_map[COM_INTERVAL] = 1000; |
| | | if(g_com_map[COM_INTERVAL]<1000) |
| | | {g_com_map[COM_INTERVAL] = 1000;} |
| | |
| | | } |
| | | if(module_power>67) |
| | | {module_power=67;} |
| | | if(module_power<0) |
| | | {module_power=0;} |
| | | |
| | | current_slotnum=1; |
| | | current_time=GetLPTime(); |
| | |
| | | // printf("DEVICE PAIRID: %d .\r\n",g_com_map[PAIR_ID]); |
| | | // printf("DEVICE ALARM DISTANCE: 1.%d 2.%d 3.%d .\r\n",g_com_map[ALARM_DISTANCE1],g_com_map[ALARM_DISTANCE2],g_com_map[ALARM_DISTANCE3]); |
| | | |
| | | } |
| | | |
| | | static void SystemPower_Config(void) |
| | | { |
| | | /* Enable Ultra low power mode */ |
| | | HAL_PWREx_EnableUltraLowPower(); |
| | | |
| | | /* Enable the fast wake up from Ultra low power mode */ |
| | | HAL_PWREx_EnableFastWakeUp(); |
| | | } |
| | | void mcu_sleep(void); |
| | | uint32_t temp; |
| | |
| | | { |
| | | static uint8_t first = 1; |
| | | static float last_value = 100; |
| | | static uint16_t bat_count = 0; |
| | | |
| | | //if(bat_count++%600==0) |
| | | { |
| | | temp2=dwt_readtempvbat(1); |
| | |
| | | |
| | | } |
| | | } |
| | | u8 flag_entersleep = 1; |
| | | /* USER CODE END 0 */ |
| | | |
| | | /** |
| | |
| | | MX_LPTIM1_Init(); |
| | | MX_SPI1_Init(); |
| | | MX_USART1_UART_Init(); |
| | | // MX_IWDG_Init(); |
| | | MX_IWDG_Init(); |
| | | /* USER CODE BEGIN 2 */ |
| | | LED_LG_ON; |
| | | Program_Init(); |
| | |
| | | Error_Handler(); |
| | | } |
| | | HAL_Delay(1500); |
| | | |
| | | // Lora_Init(); |
| | | SwitchLoraSettingstest(469000000,7); |
| | | Lora_Init(); |
| | | // SwitchLoraSettingstest(UWB_CHANNEL_FRQ,UWB_CHANNEL_SF); |
| | | Delay_Ms(10); |
| | | /* USER CODE END 2 */ |
| | | |
| | |
| | | /* USER CODE BEGIN 3 */ |
| | | // Send_Anchor_Vcc_Poll(); |
| | | if(g_start_send_flag) |
| | | { static uint16_t blink_count=0; |
| | | { |
| | | SystemClock_Config(); |
| | | g_start_send_flag = 0; |
| | | HAL_IWDG_Refresh(&hiwdg); |
| | |
| | | if(bat_percent>15) |
| | | { |
| | | LED_TB_ON; |
| | | // Tag_App(); |
| | | Tag_App(); |
| | | LED_TB_OFF; |
| | | }else{ |
| | | LED_TR_ON; |
| | | // Tag_App(); |
| | | Tag_App(); |
| | | LED_TR_OFF; |
| | | } |
| | | test1(); |
| | | // test1(); |
| | | |
| | | //LED0_BLINK; |
| | | IdleTask(); |
| | |
| | | // if(!HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin)) |
| | | // HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI); |
| | | #ifndef DEBUG_MODE |
| | | if(!HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin)) |
| | | if(!HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin)&&flag_entersleep) |
| | | HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI); |
| | | #endif |
| | | } |
| | |
| | | extern float freqlost_count,range_lost_time; |
| | | void HAL_LPTIM_CompareMatchCallback(LPTIM_HandleTypeDef *hlptim) |
| | | { |
| | | static uint8_t i=0,lost_jumpcount=0; |
| | | static uint8_t i=0; |
| | | i++; |
| | | |
| | | Anchor_Vcc_time++; |
| | | current_slotnum++; |
| | | freqlost_count+=1/(float)tag_frequency; |
| | | range_lost_time +=1/(float)tag_frequency; |
| | | // g_start_send_flag=1; |
| | | // if(freqlost_count>FREQ_LOST_TIME) |
| | | // { |
| | | // tag_frequency = NOTAG_FREQ; |
| | | // if(lost_jumpcount++>=0) //无测距情况下,每5秒发一次; |
| | | // { |
| | | // lost_jumpcount = 0; |
| | | // g_start_send_flag=1; |
| | | // } |
| | | // }else{ |
| | | g_start_send_flag=1; |
| | | // } |
| | | if(range_lost_time<1||freqlost_count>FREQ_LOST_TIME) |
| | | { |
| | | SetNextPollTime(0); |
| | | }else{ |
| | | SetNextPollTime(5); |
| | | } |
| | | |
| | | // nomove_count+=1/(float)tag_frequency; |
| | | // if(motor_keeptime>0) |
| | | // { |
| | | // nomove_count+=1/(float)tag_frequency; |
| | | // } |
| | | // if(!GET_USERKEY) |
| | | // { |
| | | // key_keeptime+=1/(float)tag_frequency; |
| | | // if(key_keeptime>=KEY_KEEPRESET_TIME) |
| | | // { |
| | | // g_com_map[ACTIVE_INDEX]=!active_flag; |
| | | // save_com_map_to_flash(); |
| | | //// MOTOR_ON; |
| | | // HAL_Delay(2000); |
| | | // SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; |
| | | // } |
| | | // }else{ |
| | | // key_keeptime=0; |
| | | // } |
| | | |
| | | } |
| | | /* USER CODE END 4 */ |
| | | |