| | |
| | | |
| | | /* Private define ------------------------------------------------------------*/ |
| | | /* USER CODE BEGIN PD */ |
| | | #define DEBUG_MODE |
| | | //#define DEBUG_MODE |
| | | #define Period (uint32_t) 32768 - 1 |
| | | #define Timeout (uint32_t) 32768 - 1//(32768 - 1) |
| | | /* USER CODE END PD */ |
| | |
| | | uint32_t dev_id; |
| | | uint16_t heartbeat_timer,poll_timer,sync_timer; |
| | | uint8_t aRxBuffer[1],group_id; |
| | | |
| | | void IdleTask(void) |
| | | uint8_t bat_percent=0,g_start_send_flag; |
| | | extern u8 motor_state; |
| | | uint16_t tyncpoll_time,lpsettime; |
| | | uint16_t slottime,max_slotpos; |
| | | uint16_t lastpoll_count,interval_count,slot_startcount,tag_frequency,lastpoll_time,current_time; |
| | | extern uint8_t module_power; |
| | | uint8_t imu_enable,motor_enable; |
| | | u16 GetLPTime(void) |
| | | { |
| | | u16 count=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | return count*LPTIMER_LSB/1000; |
| | | } |
| | | void IdleTask(void) |
| | | {u16 current_time; |
| | | |
| | | UART_CheckReceive(); |
| | | UART_CheckSend(); |
| | |
| | | { |
| | | SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader |
| | | } |
| | | if(!HAL_GPIO_ReadPin(PWR_ON_GPIO_Port,PWR_ON_Pin)) |
| | | { |
| | | LED_TR_ON; |
| | | LED_TB_OFF; |
| | | }else{ |
| | | LED_TR_OFF; |
| | | //if(!HAL_GPIO_ReadPin(PWR_ON_GPIO_Port,PWR_ON_Pin)) |
| | | //{ |
| | | // LED_TR_ON; |
| | | // LED_TB_OFF; |
| | | //}else{ |
| | | // LED_TR_OFF; |
| | | current_time=GetLPTime(); |
| | | //motor_state=2; |
| | | switch(motor_state) |
| | | {case 0: |
| | | MOTOR_OFF; |
| | | break; |
| | | case 1: |
| | | if(current_time<MOTOR_ONTIME) |
| | | { |
| | | MOTOR_ON; |
| | | }else{ |
| | | MOTOR_OFF; |
| | | } |
| | | |
| | | break; |
| | | case 2: |
| | | MOTOR_ON; |
| | | break; |
| | | case 3: |
| | | MOTOR_OFF; |
| | | break; |
| | | } |
| | | if(HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin)) |
| | | { |
| | | LED_TB_ON; |
| | | } |
| | | if(bat_percent>99) |
| | | { |
| | | LED_TR_OFF; |
| | | LED_TB_ON; |
| | | }else{ |
| | | LED_TR_ON; |
| | | LED_TB_OFF; |
| | | } |
| | | }else{ |
| | | LED_TR_OFF; |
| | | LED_TB_OFF; |
| | | // } |
| | | } |
| | | if(g_com_map[CNT_UPDATE]==1) |
| | | { |
| | |
| | | |
| | | } |
| | | |
| | | uint16_t tyncpoll_time,lpsettime; |
| | | uint16_t slottime,max_slotpos; |
| | | uint16_t lastpoll_count,interval_count,slot_startcount,tag_frequency; |
| | | extern uint8_t module_power; |
| | | uint8_t imu_enable,motor_enable; |
| | | |
| | | u16 total_slotnum,current_slotnum; |
| | | extern int32_t offsettimeus; |
| | | |
| | | void SetNextPollTime(u16 time) |
| | | { |
| | | int32_t lpcount,lptime,target_time; |
| | | |
| | | time=0; |
| | | if(current_slotnum>=total_slotnum) |
| | | current_slotnum-=total_slotnum; |
| | | |
| | | target_time=((current_slotnum*g_com_map[COM_INTERVAL])+time)*1000; |
| | | //if(target_time<90000) |
| | | { |
| | | lptime=target_time-offsettimeus; |
| | | lpcount = lptime/LPTIMER_LSB; |
| | | if(lpcount>LPTIMER_1S_COUNT) |
| | | lpcount-=LPTIMER_1S_COUNT; |
| | | if(lpcount<0) |
| | | { |
| | | lpcount+=LPTIMER_1S_COUNT; |
| | | } |
| | | __HAL_LPTIM_COMPARE_SET(&hlptim1, lpcount); |
| | | } |
| | | } |
| | | void Program_Init(void) |
| | | { float temp; |
| | | uint16_t temp2; |
| | |
| | | Usart1ParseDataCallback = UsartParseDataHandler; |
| | | parameter_init(); |
| | | //deca_sleep(1000); |
| | | g_com_map[VERSION] = 0x0109; |
| | | g_com_map[VERSION] = 0x010A; |
| | | #ifdef DEBUG_MODE |
| | | // g_com_map[DEV_ROLE]=1; |
| | | // g_com_map[DEV_ID]=1; |
| | |
| | | |
| | | group_id=g_com_map[GROUP_ID]; |
| | | dev_id = g_com_map[DEV_ID]; |
| | | slottime=ceil((double)g_com_map[MAX_REPORT_ANC_NUM]*4/3); |
| | | slottime=ceil((double)g_com_map[MAX_REPORT_ANC_NUM]/4)+4; |
| | | max_slotpos=g_com_map[COM_INTERVAL]/slottime; |
| | | tyncpoll_time=(g_com_map[DEV_ID]%max_slotpos)*slottime; |
| | | |
| | | slot_startcount=(float)(tyncpoll_time+10)*1000/LPTIMER_LSB; |
| | | lastpoll_count=slot_startcount; |
| | | interval_count=(float)g_com_map[COM_INTERVAL]*1000/LPTIMER_LSB; |
| | | slot_startcount=tyncpoll_time*1000/LPTIMER_LSB; |
| | | lastpoll_time=tyncpoll_time; |
| | | tag_frequency = 1000/g_com_map[COM_INTERVAL]; |
| | | total_slotnum = 1000/g_com_map[COM_INTERVAL]; |
| | | current_slotnum=1; |
| | | current_time=GetLPTime(); |
| | | if (HAL_LPTIM_TimeOut_Start_IT(&hlptim1, LPTIMER_1S_COUNT, slot_startcount) != HAL_OK) //system time is 1010ms 1 puls=30.518us |
| | | { |
| | | Error_Handler(); |
| | |
| | | uint32_t temp; |
| | | extern uint8_t sleep_flag,m_bEUARTTxEn; |
| | | uint16_t waitusart_timer; |
| | | uint8_t bat_percent=0,g_start_send_flag; |
| | | //void HAL_UART_RxCpltCallback(UART_HandleTypeDef *UartHandle) |
| | | //{ |
| | | // /* Set transmission flag: trasfer complete*/ |
| | |
| | | Dw1000_App_Init(); |
| | | |
| | | dwt_configuresleep(DWT_PRESRV_SLEEP | DWT_CONFIG, DWT_WAKE_CS | DWT_WAKE_WK| DWT_SLP_EN); |
| | | // dwt_entersleep(); |
| | | dwt_entersleep(); |
| | | waitusart_timer=1; |
| | | DW_DISABLE; |
| | | |
| | | // HAL_Delay(2000); |
| | | // mcu_sleep(); |
| | | //LED0_BLINK; |
| | |
| | | /* USER CODE BEGIN 3 */ |
| | | if(g_start_send_flag) |
| | | { static uint16_t blink_count=0; |
| | | //SystemClock_Config(); |
| | | SystemClock_Config(); |
| | | g_start_send_flag = 0; |
| | | |
| | | // if(current_count>slot_startcount&¤t_count<slot_startcount+interval_count) |
| | | // { |
| | | // HAL_GPIO_WritePin(LED0_GPIO, GPIO_PIN_9, GPIO_PIN_SET); |
| | | // }else{ |
| | | // HAL_GPIO_WritePin(LED0_GPIO, GPIO_PIN_9, GPIO_PIN_RESET); |
| | | // } |
| | | LED_TR_BLINK; |
| | | // LED_TR_BLINK; |
| | | |
| | | bat_percent=Get_Battary(); |
| | | if(bat_percent>15) |
| | | {// LED0_ON; |
| | | { LED0_ON; |
| | | Tag_App(); |
| | | // LED0_OFF; |
| | | LED0_OFF; |
| | | }else{ |
| | | //LED_LR_ON; |
| | | LED_LR_ON; |
| | | Tag_App(); |
| | | // LED_LR_OFF; |
| | | LED_LR_OFF; |
| | | } |
| | | //LED0_BLINK; |
| | | IdleTask(); |
| | |
| | | Error_Handler(); |
| | | } |
| | | /* USER CODE BEGIN LPTIM1_Init 2 */ |
| | | if (HAL_LPTIM_TimeOut_Start_IT(&hlptim1, Period, Timeout) != HAL_OK) |
| | | { |
| | | Error_Handler(); |
| | | } |
| | | // if (HAL_LPTIM_TimeOut_Start_IT(&hlptim1, Period, Timeout) != HAL_OK) |
| | | // { |
| | | // Error_Handler(); |
| | | // } |
| | | /* USER CODE END LPTIM1_Init 2 */ |
| | | |
| | | } |
| | |
| | | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
| | | |
| | | /*Configure GPIO pin : SPI_CS_Pin */ |
| | | GPIO_InitStruct.Pin = SPI_CS_Pin; |
| | | GPIO_InitStruct.Pin = SPI_CS_Pin|GPIO_PIN_9; |
| | | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
| | | GPIO_InitStruct.Pull = GPIO_NOPULL; |
| | | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; |
| | |
| | | static uint8_t i=0; |
| | | i++; |
| | | g_start_send_flag=1; |
| | | lastpoll_count+=interval_count; |
| | | if(lastpoll_count>LPTIMER_1S_COUNT-30) |
| | | { |
| | | lastpoll_count = slot_startcount; |
| | | } |
| | | __HAL_LPTIM_COMPARE_SET(&hlptim1, lastpoll_count); |
| | | |
| | | current_slotnum++; |
| | | SetNextPollTime(tyncpoll_time); |
| | | nomove_count+=(float)g_com_map[COM_INTERVAL]/1000; |
| | | if(nomove_count>g_com_map[NOMOVESLEEP_TIME]&&imu_enable) |
| | | { |
| | | // mcu_sleep(); |
| | | mcu_sleep(); |
| | | } |
| | | } |
| | | /* USER CODE END 4 */ |