| | |
| | | #include "deca_device_api.h" |
| | | #include "Flash.h" |
| | | //#define DEBUG_MODE |
| | | |
| | | void Device_Init(void) |
| | | { |
| | | RCC_Configuration(); |
| | |
| | | uint16_t vel_factor,pos_factor; |
| | | |
| | | extern u8 module_power; |
| | | u16 slottime,max_slotnum,current_slotpos; |
| | | u16 slottime,max_slotnum,current_slotpos,dist_threshold; |
| | | void Program_Init(void) |
| | | {uint16_t i; |
| | | float temp; |
| | |
| | | group_id=g_com_map[GROUP_ID]; |
| | | vel_factor=g_com_map[FILTER_COEFFICIENT]; |
| | | pos_factor=g_com_map[FILTER_COEFFICIENT]; |
| | | dist_threshold = (g_com_map[SPEEDFILTER_THRES]*10)/(1000/g_com_map[COM_INTERVAL]); |
| | | if(dist_threshold<300) |
| | | {dist_threshold = 300;} |
| | | if(dist_threshold>15000) |
| | | {dist_threshold = 15000;} |
| | | if(dev_id==0) |
| | | sync_mainbase=1; |
| | | module_power = g_com_map[POWER]; |
| | |
| | | { |
| | | module_power=67; |
| | | } |
| | | g_com_map[VERSION] = 0x011f; |
| | | g_com_map[VERSION] = 0x012e; |
| | | g_com_map[SW_TYPE] = SW_MODBUS; |
| | | temp=(float)g_com_map[MAX_REPORT_ANC_NUM]*4/3; |
| | | temp2=g_com_map[MAX_REPORT_ANC_NUM]*4/3; |
| | | if(temp2<temp) |
| | |
| | | // 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]); |
| | | |
| | | |
| | | memcpy(g_com_map2,g_com_map,COM_MAP_SIZE); |
| | | for(i=0;i<255;i++) |
| | | { |
| | | g_Tagdist[i]=0xffff; |
| | |
| | | void IdleTask(void) |
| | | { |
| | | g_start_sync_flag=0; |
| | | UART_CheckReceive(); |
| | | UART_CheckSend(); |
| | | UART_CheckReceive(); |
| | | UART_CheckSend(); |
| | | if( memcmp(g_com_map2,g_com_map,COM_MAP_SIZE)!=0) |
| | | { |
| | | SendAnchorState(SM_MAPERROR); |
| | | delay_ms(100); |
| | | SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //杞浣嶅洖鍒癰ootloader |
| | | } |
| | | if(g_com_map[MAP_SIGN_INDEX]!=0x55AA) |
| | | { |
| | | SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //杞浣嶅洖鍒癰ootloader |
| | | } |
| | | if(heartbeat_timer>1000) |
| | | { |
| | | heartbeat_timer=0; |
| | |
| | | HeatBeat(); |
| | | } |
| | | |
| | | if(g_com_map[CNT_UPDATE]==1) |
| | | { |
| | | uint32_t result = 0; |
| | | u16 tmp = 0xAAAA; |
| | | __disable_irq(); |
| | | result = FLASH_Prepare(0x8004A38, 2); |
| | | if(result) |
| | | 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; //杞浣嶅洖鍒癰ootloader |
| | | } |
| | | if(g_com_map[CNT_REBOOT]==1) |
| | | { |
| | | g_com_map[CNT_REBOOT]=0; |
| | | g_com_map[MAP_SIGN_INDEX]=0; |
| | | save_com_map_to_flash(); |
| | | delay_ms(100); |
| | | SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //杞浣嶅洖鍒癰ootloader |
| | | } |
| | | if(g_com_map[CNT_RESTART]==1) |
| | | { |
| | | g_com_map[CNT_RESTART]=0; |
| | | save_com_map_to_flash(); |
| | | delay_ms(100); |
| | | SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //杞浣嶅洖鍒癰ootloader |
| | | } |
| | | |
| | | } |
| | | uint16_t temp; |
| | | float dw_vbat; |
| | | int main(void) |
| | | { |
| | | |
| | | Device_Init(); |
| | | Program_Init(); |
| | | Dw1000_Init(); |
| | |
| | | Modbus_RegMap(); |
| | | while(1) |
| | | { |
| | | if(g_com_map[0] != 0x55AA) |
| | | { |
| | | while(1) |
| | | IdleTask(); |
| | | } |
| | | if(g_start_send_flag) |
| | | { |
| | | g_start_send_flag = 0; |