From cc432b761c884a0bd8e9d83db0a4e26109fc08b1 Mon Sep 17 00:00:00 2001 From: chen <15335560115@163.com> Date: 星期五, 08 十一月 2024 15:35:38 +0800 Subject: [PATCH] 安邦手环GPS删除部分无用数据和修改4G波特率9600出厂测试固件 --- keil/include/src/uwb_examples/uwb_simple_example/simple_rx/simple_rx - yuan.c | 147 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 147 insertions(+), 0 deletions(-) diff --git a/keil/include/src/uwb_examples/uwb_simple_example/simple_rx/simple_rx - yuan.c b/keil/include/src/uwb_examples/uwb_simple_example/simple_rx/simple_rx - yuan.c new file mode 100644 index 0000000..8dc406a --- /dev/null +++ b/keil/include/src/uwb_examples/uwb_simple_example/simple_rx/simple_rx - yuan.c @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2019-2023 Beijing Hanwei Innovation Technology Ltd. Co. and + * its subsidiaries and affiliates (collectly called MKSEMI). + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into an MKSEMI + * integrated circuit in a product or a software update for such product, + * must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of MKSEMI nor the names of its contributors may be used + * to endorse or promote products derived from this software without + * specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * MKSEMI integrated circuit. + * + * 5. Any software provided in binary form under this license must not be + * reverse engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY MKSEMI "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL MKSEMI OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "mk_trace.h" +#include "mk_uwb.h" +#include "mk_misc.h" +#include "mk_power.h" + +#include "board.h" + +#if defined(MK_SIMPLE_RX) + +extern int simple_main(void); + +struct mk_uwb_configure +{ + uint8_t phy_work_mode; /* PHY_TX / PHY_RX / PHT_TX|PHY_RX */ + struct UWB_CONFIG_T phy_cfg; +}; + +/* Default communication configuration. */ +static struct mk_uwb_configure config = { + .phy_work_mode = (uint8_t)(PHY_RX), + .phy_cfg.ch_num = 5, /* Channel number. */ + .phy_cfg.code_index = 9, /* TRX preamble code */ + .phy_cfg.mean_prf = MEAN_PRF_64M, /* Mean prf 64/128/256M */ + .phy_cfg.data_bit_rate = DATA_BR_6M8, /* Data rate 6.8M */ + .phy_cfg.sync_sym = PREAM_LEN_128, /* Preamble duration, length of preamble 128 */ + .phy_cfg.sfd_sym = BPRF_NSFD_8, /* Identifier for SFD sequence */ + .phy_cfg.ranging_bit = 0, /* ranging bit set 0 */ + .phy_cfg.trx_mode = TRX_MODE_15_4Z_BPRF, /* IEEE802.15.4z - BPRF mode */ + .phy_cfg.sts_pkt_cfg = STS_PKT_CFG_0, /* SP0 Frame */ + .phy_cfg.sts_segnum = STS_SEGNUM_BPRF_1, /* Number of STS segments in the frame */ + .phy_cfg.sts_seglen = STS_SEGLEN_BPRF_64, /* Number of symbols in an STS segment */ + .phy_cfg.rx_ant_id = UWB_RX_ANT_3, /* UWB RX antenna port */ +}; + +/* Buffer to store received frame. */ +static uint8_t rx_buf[128]; + +/* The receive timeout is 50000us. */ +#define RX_US_TIMEOUT 50000U + +static volatile uint16_t rx_state; +static volatile uint16_t rx_length; + +/* RX done process handler. */ +static void rx_int_callback(struct MAC_HW_REPORT_T *rx_report) +{ + // Power off radio + power_off_radio(); + + rx_state = rx_report->err_code; + + /** UWB RX success */ + if (rx_state == UWB_RX_OK) + { + /* Received data does not contain FCS */ + rx_length = rx_report->pkt_len; + memcpy(rx_buf, rx_report->pkt_data, rx_length); + } + else + { + /* UWB_PLD_ERR payload error */ + /* UWB_PHR_ERR PHR error */ + /* UWB_SFD_ERR Sfd error */ + /* UWB_BD_ERR Preamble detection error */ + /* UWB_STS_ERR STS error */ + /* Receive timeout, nothing to do */ + } +} + +int simple_main(void) +{ + // The following peripherals will be initialized in the uwb_open function + // phy/mac/aes/lsp/phy timers initialized + uwb_open(); + + // Set calibration parameters + uwb_calibration_params_set(config.phy_cfg.ch_num); + + // uwb configure + uwb_configure(config.phy_work_mode, board_param.tx_power_fcc[CALIB_CH(config.phy_cfg.ch_num)], &config.phy_cfg); + + // Register rx interrupt callback function + mac_register_process_handler(NULL, rx_int_callback); + + while (1) + { + // Target time equals 0 means recv immediately + // Program the MAC to receive UWB packet + uwb_rx(0, 0, RX_US_TIMEOUT); + + // Check the MAC busy state + while (mac_is_busy()) + { + } + + if (rx_state == UWB_RX_OK) + { + LOG_INFO(TRACE_MODULE_APP, "Frame Recvived: "); + for (int i = 0; i < rx_length; i++) + { + LOG_INFO(TRACE_NO_OPTION | TRACE_MODULE_UWB, " %02x", rx_buf[i]); + } + LOG_INFO(TRACE_NO_OPTION | TRACE_MODULE_UWB, "\r\n"); + } + } +} +#endif -- Gitblit v1.9.3