| | |
| | | power_wakeup_enable((enum POWER_WAKEUP_SOURCE_T)BOARD_SW_1, POWER_WAKEUP_LEVEL_LOW); |
| | | } |
| | | |
| | | void board_led_init(void) |
| | | void board_mode_pin_init(void) |
| | | { |
| | | // 判断是Airtag还是免布线模式 |
| | | io_pin_mux_set(MODE_CHANGE_PIN, IO_FUNC0); |
| | | gpio_pin_set_dir( MODE_CHANGE_PIN, GPIO_DIR_IN, 0); |
| | | io_pull_set(MODE_CHANGE_PIN , IO_PULL_DOWN, IO_PULL_UP_LEVEL2); |
| | | //初始化NRST脚 |
| | | io_pin_mux_set(LORA_NRST, IO_FUNC0); |
| | | gpio_pin_set_dir(LORA_NRST , GPIO_DIR_OUT, 1); |
| | | io_pull_set(LORA_NRST, IO_HIGH_Z, IO_PULL_UP_NONE); |
| | | gpio_pin_set(LORA_NRST); |
| | | } |
| | | |
| | | void board_led_on(enum IO_PIN_T idx) |
| | |
| | | #define CALIB_CH5 1 |
| | | #define CALIB_CH2 2 |
| | | #define CALIB_CH_NUM 3 |
| | | |
| | | #define SLEEP_TIMER_NUM 500 |
| | | #define CALIB_CH(x) (x == 9 ? 0 : (x == 5 ? 1 : 2)) |
| | | |
| | | enum BOARD_NVM_ITEM_ID_T |
| | |
| | | * @brief Configure LED GPIO. |
| | | * |
| | | */ |
| | | void board_led_init(void); |
| | | void board_mode_pin_init(void); |
| | | |
| | | /** |
| | | * @brief LED on. |
| | |
| | | //0组 |
| | | #define MCU_A 0x01 |
| | | #define CHG_G 0x02 |
| | | #define LORA_IRQ 0x03 |
| | | #define LORA_NRST 0x04 |
| | | //#define LORA_IRQ 0x03 |
| | | //#define LORA_NRST 0x04 |
| | | #define ADC_MINIUS 0x05 |
| | | #define INPUT_5V 0x06 |
| | | #define PWR_ON 0x07 |
| | |
| | | //input 0组 |
| | | #define MCU_A_POSITION (1<<(MAX_GPIO_NUM-MCU_A)) |
| | | #define CHG_G_POSITION (1<<(MAX_GPIO_NUM-CHG_G)) |
| | | #define LORA_IRQ_POSITION (1<<(MAX_GPIO_NUM-LORA_IRQ)) |
| | | #define LORA_NRST_POSITION (1<<(MAX_GPIO_NUM-LORA_NRST)) |
| | | //#define LORA_IRQ_POSITION (1<<(MAX_GPIO_NUM-LORA_IRQ)) |
| | | //#define LORA_NRST_POSITION (1<<(MAX_GPIO_NUM-LORA_NRST)) |
| | | #define ADC_MINIUS_POSITION (1<<(MAX_GPIO_NUM-ADC_MINIUS)) |
| | | #define INPUT_5V_POSITION (1<<(MAX_GPIO_NUM-INPUT_5V)) |
| | | #define PWR_ON_POSITION (1<<(MAX_GPIO_NUM-PWR_ON)) |
| | |
| | | #define MAX_REPORT_ANC_NUM 0x4 //单次通讯基站上限 |
| | | #define GROUP_ID 0x5 //单次通讯基站下限 |
| | | #define DIST_OFFSET 0x6 |
| | | #define LORA_POWER 0x6 |
| | | #define DEV_ROLE 0x7 //该设备是anchor还是tag |
| | | #define ANC_POLL 0x8 //基站主动测距 |
| | | |
| | |
| | | static uint16_t tagid_list[TAG_NUM_IN_SYS]; |
| | | uint16_t CmpTagInList(uint16_t tagid); |
| | | uint8_t Anchor_RecNearPoll(uint8_t ancrec_nearbasepos); |
| | | uint8_t report_ancnum; |
| | | static uint8_t send_buffer[100]; |
| | | static uint8_t tagofflinetime[TAG_NUM_IN_SYS]; |
| | | uint32_t temp_count=0; |
| | |
| | | //***************************************************************************** |
| | | #define WSF_BUF_POOLS 5 |
| | | void Fira_Change_Task(void); |
| | | extern uint8_t normal_flag,log_4g_enable_flag; |
| | | extern uint8_t normal_flag,log_4g_enable_flag,lora_tx_flag; |
| | | extern uint16_t ip0,ip1,ip2,ip3,port; |
| | | uint8_t group_id,enable_sleep_count; |
| | | uint32_t dev_id; |
| | | uint16_t disoffset; |
| | | uint8_t flag_sleeptimer,flag_secondtask,secondtask_count; |
| | | float nomove_count; |
| | | // Default pool descriptor. |
| | | static wsfBufPoolDesc_t poolDescriptors[WSF_BUF_POOLS] = { |
| | | {32, 26}, {64, 24}, {128, 4}, {256 + 32, 4}, {1024 + 32, 2}, |
| | |
| | | static void sleep_timer_callback(void *dev, uint32_t time) |
| | | { |
| | | // LOG_INFO(TRACE_MODULE_APP, "Wake up by sleep timer %d\r\n", time); |
| | | } |
| | | static void sleep_timer_callback_normal(void *dev, uint32_t time) |
| | | { |
| | | if(secondtask_count++%2==0) |
| | | { |
| | | flag_secondtask = 1; |
| | | }else{ |
| | | flag_secondtask = 0; |
| | | } |
| | | // if(delaysleep_count>0) |
| | | // delaysleep_count--; |
| | | } |
| | | void Program_Init(void) |
| | | { |
| | |
| | | LOG_INFO(TRACE_MODULE_APP,"固件版本:4G-GPS定位手环 V%d.%d. \r\n",g_com_map[VERSION]>>8,g_com_map[VERSION]&0xff); |
| | | LOG_INFO(TRACE_MODULE_APP,"服务器地址: %d.%d.%d.%d:%d.\r\n",ip0,ip1,ip2,ip3,port); |
| | | } |
| | | void MinuteTask(void) |
| | | { |
| | | // adc_get(&sample[0], NUM_SAMPLES, adc_callback);//adc采样 |
| | | } |
| | | /********************************************************************************************************/ |
| | | static void Lora_irq_handler(enum IO_PIN_T pin) |
| | | { |
| | | RadioIrqProcess(); |
| | | } |
| | | void SecondTask(void) |
| | | {static uint8_t second_count; |
| | | if(second_count++>60) |
| | | { |
| | | second_count = 0; |
| | | MinuteTask(); |
| | | } |
| | | lora_tx_flag=1; |
| | | //Lora_Tx_Poll(); |
| | | // //UWB状态检测 |
| | | //if(!power_low_flag)//低供电下不需要检测重连 |
| | | // { |
| | | // if(IfTCPConnected()) |
| | | // { |
| | | // TCP_reconnect_timer =0; |
| | | // flag_TCP_reconnectting = 0; |
| | | // } else { |
| | | // if(TCP_reconnect_timer<30)//如果TCP没有连接,每隔10分钟尝试连接30秒 |
| | | // { |
| | | // flag_TCP_reconnectting = 1; |
| | | // } else { |
| | | // flag_TCP_reconnectting = 0; |
| | | // } |
| | | // if(TCP_reconnect_timer++>600) |
| | | // { |
| | | // TCP_reconnect_timer = 0; |
| | | // } |
| | | |
| | | // } |
| | | // } |
| | | |
| | | HIDO_TimerTick(); |
| | | if(nomove_count<=g_com_map[NOMOVESLEEP_TIME])//防止溢出 |
| | | nomove_count++; |
| | | else{ |
| | | nomove_count=g_com_map[NOMOVESLEEP_TIME]+1; |
| | | } |
| | | } |
| | | void spi_init(void) |
| | | { |
| | | struct SPI_CFG_T usr_spi_cfg = |
| | | { |
| | | .bit_rate = 1000000, |
| | | .data_bits = 8, |
| | | //#if TEST_SPI_MASTER |
| | | .slave = 0, |
| | | //#else |
| | | // .slave = 1, |
| | | //#endif |
| | | .clk_phase = 0, |
| | | .clk_polarity = 0, |
| | | .ti_mode = 0, |
| | | //#if (TEST_SPI_MODE == TEST_SPI_POLL_MODE) |
| | | .dma_rx = false, |
| | | .dma_tx = false, |
| | | .int_rx = false, |
| | | .int_tx = false, |
| | | //#elif (TEST_SPI_MODE == TEST_SPI_INTERUPT_MODE) |
| | | // .dma_rx = false, |
| | | // .dma_tx = false, |
| | | // .int_rx = true, |
| | | // .int_tx = true, |
| | | //#elif (TEST_SPI_MODE == TEST_SPI_DMA_MODE) |
| | | // .dma_rx = true, |
| | | // .dma_tx = true, |
| | | // .int_rx = false, |
| | | // .int_tx = false, |
| | | //#endif |
| | | }; |
| | | |
| | | spi_open(SPI_ID0, &usr_spi_cfg); |
| | | } |
| | | static void board_init(void) |
| | | { |
| | | uint32_t internal_flash = (REG_READ(0x40000018) >> 17) & 0x1; |
| | |
| | | gpio_pin_set_dir(IO_PIN_4, GPIO_DIR_OUT, 0); |
| | | #else |
| | | Program_Init(); |
| | | // led |
| | | board_led_init(); |
| | | spi_init(); |
| | | // 模式判断脚和spi nrst脚初始化 |
| | | board_mode_pin_init(); |
| | | // board_led_on(BOARD_LED_1); |
| | | #endif |
| | | Board_LORA_NVIC_Init(Lora_irq_handler); |
| | | board_configure(); |
| | | } |
| | | |
| | |
| | | uart_receive(UART_ID1,m_EUART_DMA_RXBuf,EUART_RX_BUF_SIZE,uart_receive_callback); |
| | | } |
| | | |
| | | uint8_t bat_percent; |
| | | int main(void) |
| | | { |
| | | // Initialize MCU system |
| | |
| | | } |
| | | }else{ |
| | | // adc_open(&usr_adc_cfg); |
| | | Lora_1268_Init(); |
| | | SwitchLoraSettings(478,7,22); |
| | | Uwb_init();//默认为我们测距配置 |
| | | OpenUWB(); |
| | | uart_receive(UART_ID1,m_EUART_DMA_RXBuf,EUART_RX_BUF_SIZE,uart_receive_callback); |
| | | power_init(); |
| | | sleep_timer_open(true, SLEEP_TIMER_MODE_RELOAD, sleep_timer_callback_normal); |
| | | sleep_timer_start(__MS_TO_32K_CNT(SLEEP_TIMER_NUM));//测试 |
| | | while (1) |
| | | { |
| | | uwb_app_poll();//我们的测距逻辑 |
| | | Lora_Tx_Poll(); |
| | | |
| | | if(flag_secondtask) |
| | | { |
| | | flag_secondtask = 0; |
| | | SecondTask(); |
| | | } |
| | | IdleTask(); |
| | | } |
| | | } |
| | |
| | | </File> |
| | | </Files> |
| | | </Group> |
| | | <Group> |
| | | <GroupName>Radio</GroupName> |
| | | <Files> |
| | | <File> |
| | | <FileName>crc.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>.\include\src\Radio\crc.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>delay.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>.\include\src\Radio\delay.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>lora_1268.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>.\include\src\Radio\lora_1268.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>radio.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>.\include\src\Radio\radio.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>sx126x.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>.\include\src\Radio\sx126x.c</FilePath> |
| | | </File> |
| | | <File> |
| | | <FileName>sx126x-board.c</FileName> |
| | | <FileType>1</FileType> |
| | | <FilePath>.\include\src\Radio\sx126x-board.c</FilePath> |
| | | </File> |
| | | </Files> |
| | | </Group> |
| | | </Groups> |
| | | </Target> |
| | | </Targets> |
| | |
| | | |
| | | #else |
| | | |
| | | //增加SPI初始化 |
| | | //SPI0/MOSI/MISO/CLK/CS |
| | | io_pin_mux_set(LORA_CS, IO_FUNC0); |
| | | gpio_pin_set_dir(LORA_CS , GPIO_DIR_OUT, 0); |
| | | io_pull_set(LORA_CS, IO_HIGH_Z, IO_PULL_UP_NONE); |
| | | |
| | | io_pin_mux_set(LORA_MOSI, IO_FUNC2); |
| | | io_pin_mux_set(LORA_MISO, IO_FUNC2); |
| | | io_pin_mux_set(LORA_CLK, IO_FUNC2); |
| | | io_pin_mux_set(LORA_IRQ, IO_FUNC0); |
| | | io_pin_mux_set(LORA_NRST, IO_FUNC0); |
| | | //初始化lora引脚 |
| | | // UART0 TX/RX |
| | | io_pin_mux_set(IO_PIN_5, IO_FUNC4); |
| | | io_pin_mux_set(IO_PIN_6, IO_FUNC4); |
| | |
| | | #if BOARD_TYPE == MK8000_EVK |
| | | |
| | | // UART1 RX/TX |
| | | io_pin_mux_set(IO_PIN_0, IO_FUNC4); |
| | | io_pin_mux_set(IO_PIN_14, IO_FUNC4); |
| | | io_pin_mux_set(IO_PIN_1, IO_FUNC4); |
| | | |
| | | |
| | |
| | | #endif |
| | | #endif |
| | | } |
| | | void Board_LORA_NVIC_Init(GPIO_IRQ_HANDLER_T irq_handler) //LORA 中断配置 |
| | | { |
| | | // io_pin_mux_set(_4G_USART_RX_Pin,IO_FUNC0);//把原先io 变为普通GPIO |
| | | gpio_pin_set_dir(LORA_IRQ , GPIO_DIR_IN, 0); |
| | | io_pull_set(LORA_IRQ, IO_HIGH_Z, IO_PULL_UP_NONE); |
| | | gpio_enable_irq(LORA_IRQ, GPIO_IRQ_TYPE_RISING_EDGE, irq_handler); |
| | | } |
| | |
| | | #define UWB_RX_OPEN_IN_ADVANCE (US_TO_PHY_TIMER_COUNT(10)) |
| | | /// RX window - 750us |
| | | #define UWB_RX_WINDOW (US_TO_PHY_TIMER_COUNT(750)) |
| | | #define LED_PIN IO_PIN_4 |
| | | //#define LED_PIN IO_PIN_4 |
| | | #define INPUT_5V_Pin IO_PIN_11 |
| | | #define MODE_CHANGE_PIN IO_PIN_4 |
| | | #define MODE_CHANGE_PIN IO_PIN_0 |
| | | #define LORA_CS IO_PIN_8 |
| | | #define LORA_MOSI IO_PIN_11 |
| | | #define LORA_MISO IO_PIN_12 |
| | | #define LORA_CLK IO_PIN_13 |
| | | #define LORA_IRQ IO_PIN_7 |
| | | #define LORA_BUSY IO_PIN_2 |
| | | #define LORA_NRST IO_PIN_4 |
| | | /* =========================================================================================================================== */ |
| | | /* ================ End ================ */ |
| | | /* =========================================================================================================================== */ |