| | |
| | | RTC_ITConfig(RTC_FLAG_ALR,ENABLE); |
| | | } |
| | | |
| | | void RTC_Configuration(void) |
| | | void RTC_Configuration(uint16_t interval) |
| | | { |
| | | EXTI_InitTypeDef EXTI_InitStructure; |
| | | |
| | |
| | | RTC_ITConfig(RTC_IT_ALR,ENABLE); //?? RTC ??? |
| | | RTC_WaitForLastTask(); |
| | | /* Set RTC prescaler: set RTC period to 1sec */ |
| | | RTC_SetPrescaler(10000); /* RTC period = RTCCLK/RTC_PR = (32.768 KHz)/(32767+1) */ |
| | | RTC_SetPrescaler(interval); /* RTC period = RTCCLK/RTC_PR = (32.768 KHz)/(32767+1) */ |
| | | |
| | | /* Wait until last write operation on RTC registers has finished */ |
| | | RTC_WaitForLastTask(); |
| | |
| | | #include "stm32f10x.h" |
| | | |
| | | |
| | | void RTC_Configuration(void); |
| | | void RTC_Configuration(uint16_t interval); |
| | | |
| | | |
| | | #endif |
| | |
| | | NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; |
| | | NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; |
| | | |
| | | |
| | | NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; |
| | | NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; |
| | | NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; |
| | | NVIC_Init(&NVIC_InitStructure); |
| | | |
| | | NVIC_InitStructure.NVIC_IRQChannel = RTCAlarm_IRQn; |
| | | NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; |
| | |
| | | int Systick_Init(void); |
| | | void delay_us(uint32_t nTimer); |
| | | void delay_ms(uint32_t nTimer); |
| | | void RTC_Configuration(void); |
| | | void RTC_Configuration(uint16_t interval); |
| | | #endif |
| | |
| | | |
| | | USART_ClockInit(EXT_UART, &USART_ClockInitStructure); |
| | | USART_Init(EXT_UART, &USART_InitStructure); |
| | | |
| | | // USART_ITConfig(EXT_UART, USART_IT_RXNE, ENABLE);//??????,????? ?????????? |
| | | // Enable the USARTx |
| | | USART_Cmd(EXT_UART, ENABLE); |
| | | //DMAé
ç½®ï¼é¡»æ¾å°UARTåå§åä¹åï¼ |
| | |
| | | dwt_configuresleep(0x940, 0x7); |
| | | dwt_entersleep(); |
| | | } |
| | | uint16_t g_Resttimer; |
| | | uint8_t result; |
| | | void Tag_App(void)//å鿍¡å¼(TAGæ ç¾) |
| | | { |
| | | uint32_t frame_len; |
| | | uint32_t final_tx_time; |
| | | |
| | | g_Resttimer=0; |
| | | UART_CheckReceive(); |
| | | GPIO_ResetBits(SPIx_GPIO, SPIx_CS); |
| | | delay_us(2500); |
| | | GPIO_SetBits(SPIx_GPIO, SPIx_CS); |
| | |
| | | dwt_entersleep(); |
| | | |
| | | } |
| | | uint16_t g_Resttimer; |
| | | extern uint8_t g_pairstart; |
| | | void Anchor_App(void) |
| | | { |
| | | uint32_t frame_len; |
| | |
| | | while (!((status_reg = dwt_read32bitreg(SYS_STATUS_ID)) & (SYS_STATUS_RXFCG | SYS_STATUS_ALL_RX_ERR)))//䏿æ¥è¯¢è¯çç¶æç´å°æ¥æ¶æåæè
åºç°é误 |
| | | { |
| | | UART_CheckReceive(); |
| | | UART_CheckSend(); |
| | | g_Resttimer=0; |
| | | }; |
| | | |
| | |
| | | tx_resp_msg[TAG_ID_IDX] = tag_id_recv; |
| | | |
| | | |
| | | if (rx_buffer[MESSAGE_TYPE_IDX] == POLL&&tag_id_recv!= g_com_map[DEV_ID]) //夿æ¯å¦æ¯pollå
æ°æ® |
| | | if (rx_buffer[MESSAGE_TYPE_IDX] == POLL&&tag_id_recv!= g_com_map[PAIR_ID]) //夿æ¯å¦æ¯pollå
æ°æ® |
| | | { |
| | | /* Retrieve poll reception timestamp. */ |
| | | poll_rx_ts = get_rx_timestamp_u64();//è·å¾Pollå
æ¥æ¶æ¶é´T2 |
| | |
| | | g_UWB_com_interval = 0; |
| | | dis_after_filter=dist_cm; |
| | | g_Tagdist[tag_id_recv]=dist_cm; |
| | | if(g_pairstart==1&&dist_cm<20) |
| | | { |
| | | g_pairstart=0; |
| | | g_com_map[PAIR_ID]=tag_id_recv; |
| | | save_com_map_to_flash(); |
| | | printf("Pair Finish PairID: %d. \r\n",g_com_map[PAIR_ID]); |
| | | } |
| | | g_flag_Taggetdist[tag_id_recv]=0; |
| | | printf("Anchor ID: %d, Tag ID: %d, Dist = %d cm\n", g_com_map[DEV_ID], tag_id_recv, (uint16_t)dis_after_filter); |
| | | //dis_after_filter = LP_Frac_Update(p_Dis_Filter, dist_cm); |
| | |
| | | g_com_map[ALARM_DISTANCE3] = 1500; //é»è®¤æ¥è¦è·ç¦»50cm |
| | | g_com_map[ALARM_DEV] = 1; |
| | | g_com_map[DEV_ID] = 1;//DEFAULT_DEV_ID; //é»è®¤è®¾å¤ID |
| | | g_com_map[COM_INTERVAL]=500; |
| | | save_com_map_to_flash(); |
| | | } |
| | | |
| | |
| | | #define ALARM_DISTANCE1 0x21 //å°äºå¤å°è·ç¦»æ¥è¦ |
| | | #define ALARM_DISTANCE2 0x22 //å°äºå¤å°è·ç¦»æ¥è¦ |
| | | #define ALARM_DISTANCE3 0x23 //å°äºå¤å°è·ç¦»æ¥è¦ |
| | | #define PAIR_ID 0x24 //å°äºå¤å°è·ç¦»æ¥è¦ |
| | | /*------------END Map Definition-------------------*/ |
| | | |
| | | |
| | |
| | | #include <string.h> |
| | | #include <stdio.h> |
| | | #include "dw_app.h" |
| | | |
| | | #include "RTC.h" |
| | | uint8_t m_frame_data[MAX_FRAME_LEN] = {0}; |
| | | uint8_t m_frame_data_len = 0; |
| | | |
| | | uint8_t g_pairstart=0; |
| | | void ParseFrame(void) |
| | | { |
| | | if(!memcmp(m_frame_data, "DIS1", 4)) |
| | |
| | | Dw1000_App_Init(); |
| | | printf("set dev id = %d. \r\n", g_com_map[DEV_ID]); |
| | | save_com_map_to_flash(); |
| | | }else if(!memcmp(m_frame_data, "INT", 3)) |
| | | { |
| | | g_com_map[COM_INTERVAL] = 0; |
| | | for(uint8_t i=4; i < m_frame_data_len; i++) |
| | | { |
| | | if(m_frame_data[i]<58 && m_frame_data[i]>47) |
| | | { |
| | | g_com_map[COM_INTERVAL] = g_com_map[COM_INTERVAL]*10 + m_frame_data[i]- '0'; |
| | | } |
| | | else |
| | | { |
| | | printf("Error: Wrong COM_INTERVAL.\r\n"); |
| | | break; |
| | | } |
| | | } |
| | | printf("set dev interval = %d ms. \r\n", g_com_map[COM_INTERVAL]); |
| | | RTC_Configuration(g_com_map[COM_INTERVAL]*20); |
| | | save_com_map_to_flash(); |
| | | }else if(!memcmp(m_frame_data, "PAIRID", 6)) |
| | | { |
| | | g_com_map[PAIR_ID] = 0; |
| | | for(uint8_t i=7; i < m_frame_data_len; i++) |
| | | { |
| | | if(m_frame_data[i]<58 && m_frame_data[i]>47) |
| | | { |
| | | g_com_map[PAIR_ID] = g_com_map[PAIR_ID]*10 + m_frame_data[i]- '0'; |
| | | } |
| | | else |
| | | { |
| | | printf("Error: Wrong PAIR_ID.\r\n"); |
| | | break; |
| | | } |
| | | } |
| | | printf("set dev PAIR_ID = %d . \r\n", g_com_map[PAIR_ID]); |
| | | save_com_map_to_flash(); |
| | | }else if(!memcmp(m_frame_data, "STARTPAIR", 9)) |
| | | { |
| | | g_pairstart=1; |
| | | printf("Start Pair Mode. \r\n"); |
| | | }else{ |
| | | printf("Error: Wrong Command.\r\n"); |
| | | } |
| | | } |
| | | |
| | |
| | | #include "serial_at_cmd_app.h" |
| | | #include "global_param.h" |
| | | |
| | | //#define WORK_MODE_TAG |
| | | #define WORK_MODE_ANCHOR |
| | | #define WORK_MODE_TAG |
| | | //#define WORK_MODE_ANCHOR |
| | | |
| | | void Device_Init(void) |
| | | { |
| | |
| | | //SystemInit(); |
| | | Nvic_Init(); |
| | | Systick_Init(); |
| | | #ifdef WORK_MODE_TAG |
| | | RTC_Configuration(); |
| | | #endif |
| | | Led_Init(); |
| | | Beep_Init(); |
| | | DW_GPIO_Init(); |
| | |
| | | {uint16_t i; |
| | | Usart1ParseDataCallback = UsartParseDataHandler; |
| | | parameter_init(); |
| | | #ifdef WORK_MODE_TAG |
| | | printf("DEVICE MODE: TAG .\r\n"); |
| | | printf("DEVICE ID: %d .\r\n",g_com_map[DEV_ID]); |
| | | printf("DEVICE INTERVAL: %d .\r\n",g_com_map[COM_INTERVAL]); |
| | | #else |
| | | printf("DEVICE MODE: ANCHOR .\r\n"); |
| | | printf("DEVICE ID: %d .\r\n",g_com_map[DEV_ID]); |
| | | 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]); |
| | | #endif |
| | | for(i=0;i<255;i++) |
| | | { |
| | | g_Tagdist[i]=0xffff; |
| | |
| | | Dw1000_Init(); |
| | | delay_ms(1000); |
| | | #ifdef WORK_MODE_TAG |
| | | RTC_Configuration(g_com_map[COM_INTERVAL]*20); |
| | | tag_sleep_configuraion(); |
| | | #endif |
| | | Dw1000_App_Init(); |
| | |
| | | #include "global_param.h" |
| | | #include "beep_logic_app.h" |
| | | #include "led.h" |
| | | #include "Usart.h" |
| | | /* Tick timer count. */ |
| | | volatile uint32_t time32_incr; |
| | | uint8_t tt=0; |
| | |
| | | {uint16_t i; |
| | | time32_incr++; |
| | | g_UWB_com_interval++; |
| | | if(g_Resttimer++>1000) |
| | | if(g_Resttimer++>10000) |
| | | { |
| | | NVIC_SystemReset(); |
| | | } |
| | |
| | | |
| | | //SYS.wake_id|=1<<17; |
| | | } |
| | | void USART1_IRQHandler(void) |
| | | { |
| | | if(USART_GetITStatus(EXT_UART, USART_IT_RXNE) != RESET)//????????? |
| | | { |
| | | UART_CheckReceive(); |
| | | } |
| | | |
| | | /************************************************************* |
| | | |
| | | if(USART_GetITStatus(USARTy, USART_IT_TXE) != RESET) |
| | | |
| | | { |
| | | |
| | | USART_SendData(USARTy, TxBuffer1[TxCounter1++]); |
| | | |
| | | } |
| | | /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/ |
| | | } |
| | | |