| | |
| | | #include "global_param.h" |
| | | #include "ADC.h" |
| | | |
| | | //#define DEBUG_MODE |
| | | |
| | | void Device_Init(void) |
| | | { |
| | |
| | | //SystemInit(); |
| | | NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x5000); |
| | | Nvic_Init(); |
| | | Systick_Init(); |
| | | // Systick_Init(); |
| | | TIM3_Int_Init(); |
| | | Led_Init(); |
| | | Beep_Init(); |
| | | DW_GPIO_Init(); |
| | |
| | | checksum = Checksum_u16(&hbsend[2],12); |
| | | memcpy(&hbsend[14],&checksum,2); |
| | | } |
| | | u16 tyncpoll_time; |
| | | u16 slottime,max_slotpos; |
| | | void Program_Init(void) |
| | | {uint16_t i; |
| | | { float temp; |
| | | u16 temp2; |
| | | uint16_t i; |
| | | Usart1ParseDataCallback = UsartParseDataHandler; |
| | | parameter_init(); |
| | | //deca_sleep(1000); |
| | | HeartBeatInit(); |
| | | #ifdef DEBUG_MODE |
| | | // g_com_map[DEV_ROLE]=1; |
| | | // g_com_map[DEV_ID]=1; |
| | | // g_com_map[COM_INTERVAL]=100; |
| | | // g_com_map[MAX_REPORT_ANC_NUM]=3; |
| | | // g_com_map[NEARBASE_NUM]=1; |
| | | // g_com_map[NEARBASE_ID1]=2; |
| | | g_com_map[ANC_FLAG]=1; |
| | | save_com_map_to_flash(); |
| | | #endif |
| | | OUT485_ENABLE; |
| | | g_com_map[VERSION] = 0x010e; |
| | | dev_id = g_com_map[DEV_ID]; |
| | | 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; |
| | | |
| | | |
| | | if(g_com_map[DEV_ROLE]) |
| | | { |
| | | printf("æ ç¾ID: %d .\r\n",dev_id); |
| | | printf("é讯é´é: %d ms.\r\n",g_com_map[COM_INTERVAL]); |
| | | printf("忬¡é讯åºç«æ°é: %d个.\r\n",g_com_map[MAX_REPORT_ANC_NUM]); |
| | | }else{ |
| | | |
| | | anchor_type = dev_id%g_com_map[MAX_REPORT_ANC_NUM]; |
| | | printf("åºç«ID: %x .\r\n",dev_id); |
| | | printf("åºç«ç±»å: %c .\r\n",anchor_type+0x41); |
| | | printf("忬¡é讯åºç«æ°é: %d个.\r\n",g_com_map[MAX_REPORT_ANC_NUM]); |
| | | } |
| | | OUT485_DISABLE; |
| | | // 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]); |
| | | |
| | |
| | | { |
| | | UART_PushFrame(hbsend,16); |
| | | } |
| | | extern u8 g_start_sync_flag; |
| | | extern u8 g_start_sync_flag,usart_send_flag,anc_report_num; |
| | | u16 heartbeat_timer,poll_timer,sync_timer; |
| | | void IdleTask(void) |
| | | { |
| | | g_start_sync_flag=0; |
| | | main_logic(); |
| | | UART_CheckReceive(); |
| | | UART_CheckSend(); |
| | | if(heartbeat_timer>1000) |
| | |
| | | if(g_com_map[HEARTBEAT]&&g_com_map[DEV_ROLE]==0) |
| | | HeatBeat(); |
| | | } |
| | | if(poll_timer>=g_com_map[COM_INTERVAL]-tag_delaytime) |
| | | { |
| | | poll_timer=0; |
| | | if(g_com_map[ANC_POLL]||g_com_map[DEV_ROLE]) |
| | | { |
| | | if(g_com_map[DEV_ROLE]==0) |
| | | {int8_t correction_time; |
| | | correction_time=tag_timer-g_com_map[DEV_ID]*3; |
| | | tag_delaytime=correction_time; |
| | | if(tag_delaytime>g_com_map[COM_INTERVAL]/2) |
| | | { |
| | | tag_delaytime=tag_delaytime-g_com_map[COM_INTERVAL]; |
| | | } |
| | | } |
| | | g_start_send_flag=1; |
| | | } |
| | | |
| | | |
| | | if(g_com_map[DEV_ROLE]==0&&usart_send_flag) |
| | | {u16 checksum; |
| | | usart_send_flag=0; |
| | | usart_send_anc[2] = 5;//æ£å¸¸æ¨¡å¼ |
| | | usart_send_anc[3] = anc_report_num*6+2;//æ£å¸¸æ¨¡å¼ |
| | | checksum = Checksum_u16(&usart_send_anc[2],anc_report_num*6+2); |
| | | memcpy(&usart_send_anc[4+anc_report_num*6],&checksum,2); |
| | | UART_PushFrame(usart_send_anc,6+anc_report_num*6); |
| | | anc_report_num=0; |
| | | } |
| | | if(g_com_map[CNT_UPDATE]==1) |
| | | { |
| | |
| | | result = FLASH_Write(0x8004A38, (const uint8_t*)&tmp, 2); |
| | | __enable_irq(); |
| | | printf("è¿å
¥å级模å¼\r\n"); |
| | | g_com_map[CNT_UPDATE]=0; |
| | | save_com_map_to_flash(); |
| | | delay_ms(100); |
| | | // STMFLASH_Write_NoCheck(0x8004A38,0xAAAA); |
| | | // Delay_ms(100); |
| | | SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软å¤ä½åå°bootloader |
| | |
| | | RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); |
| | | usart_send[0]=0x55; |
| | | usart_send[1]=0xAA; |
| | | usart_send_anc[0]=0x55; |
| | | usart_send_anc[1]=0xAA; |
| | | |
| | | while(1) |
| | | { |
| | | IdleTask(); |
| | | g_start_sync_flag=0; |
| | | if(g_start_send_flag) |
| | | { |
| | | g_start_send_flag = 0; |
| | | Tag_App(); |
| | | } |
| | | |
| | | IdleTask(); |
| | | if(g_com_map[DEV_ROLE]==0) |
| | | Anchor_App(); |
| | | |
| | | } |
| | | } |
| | | |