diff options
author | Purnank H. G. <purnank@google.com> | 2024-04-19 14:28:23 +0800 |
---|---|---|
committer | Purnank G <purnank@google.com> | 2024-04-21 11:14:38 +0000 |
commit | 0a004588ecd567008bce657ba2dc49719ac9a7f4 (patch) | |
tree | 15302129cf9149d77fbe29acbebc1e98b4904f7b | |
parent | c44feda797145384e1b5a8e506a9653ffcce842a (diff) | |
download | uwb-0a004588ecd567008bce657ba2dc49719ac9a7f4.tar.gz |
Refactored SR1XX Calibration to separate file.
Bug: 335774498
Test: Ranging between devices
Change-Id: I4357508da7a594468942fd0476ccfcbf37750076
Merged-In: I4357508da7a594468942fd0476ccfcbf37750076
-rw-r--r-- | halimpl/hal/phNxpUwbCalib.cc | 182 | ||||
-rw-r--r-- | halimpl/hal/phNxpUwbCalib.h | 21 | ||||
-rw-r--r-- | halimpl/hal/sr1xx/NxpUwbChipSr1xx.cc | 154 |
3 files changed, 205 insertions, 152 deletions
diff --git a/halimpl/hal/phNxpUwbCalib.cc b/halimpl/hal/phNxpUwbCalib.cc new file mode 100644 index 0000000..fdab160 --- /dev/null +++ b/halimpl/hal/phNxpUwbCalib.cc @@ -0,0 +1,182 @@ +/* + * Copyright 2021-2023 NXP + * Copyright 2024 Google + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include "phNxpUwbCalib.h" +#include "phUwbStatus.h" +#include "phNxpUciHal_ext.h" + +/* SR1XX is same as SR2XX */ +static tHAL_UWB_STATUS sr1xx_apply_calibration(extcal_param_id_t id, const uint8_t ch, const uint8_t *data, size_t data_len); +static tHAL_UWB_STATUS sr1xx_set_conf(const std::vector<uint8_t> &tlv); +static tHAL_UWB_STATUS sr1xx_set_calibration(uint8_t channel, const std::vector<uint8_t> &tlv); + + +tHAL_UWB_STATUS phNxpUwbCalib_apply_calibration(extcal_param_id_t id, const uint8_t ch, const uint8_t *data, size_t data_len) { + return sr1xx_apply_calibration(id, ch, data, data_len); +} + +// +// SR1XX Device Calibrations: +// +// Based on NXP SR1xx UCI v2.0.5 +// current HAL impl only supports "xtal" read from otp +// others should be existed in .conf files + +static tHAL_UWB_STATUS sr1xx_set_calibration(uint8_t channel, const std::vector<uint8_t> &tlv) +{ + // SET_CALIBRATION_CMD header: GID=0xF OID=0x21 + std::vector<uint8_t> packet({ (0x20 | UCI_GID_PROPRIETARY_0X0F), UCI_MSG_SET_DEVICE_CALIBRATION, 0x00, 0x00}); + + // use 9 for channel-independent parameters + if (!channel) { + channel = 9; + } + packet.push_back(channel); + packet.insert(packet.end(), tlv.begin(), tlv.end()); + packet[3] = packet.size() - 4; + return phNxpUciHal_send_ext_cmd(packet.size(), packet.data()); +} + +static tHAL_UWB_STATUS sr1xx_set_conf(const std::vector<uint8_t> &tlv) +{ + // SET_CALIBRATION_CMD header: GID=0xF OID=0x21 + std::vector<uint8_t> packet({ (0x20 | UCI_GID_CORE), UCI_MSG_CORE_SET_CONFIG, 0x00, 0x00}); + packet.push_back(1); // number of parameters + packet.insert(packet.end(), tlv.begin(), tlv.end()); + packet[3] = packet.size() - 4; + return phNxpUciHal_send_ext_cmd(packet.size(), packet.data()); +} + +static tHAL_UWB_STATUS sr1xx_apply_calibration(extcal_param_id_t id, const uint8_t ch, const uint8_t *data, size_t data_len) +{ + // Device Calibration + const uint8_t UCI_PARAM_ID_RF_CLK_ACCURACY_CALIB = 0x01; + const uint8_t UCI_PARAM_ID_RX_ANT_DELAY_CALIB = 0x02; + const uint8_t UCI_PARAM_ID_TX_POWER_PER_ANTENNA = 0x04; + + // Device Configurations + const uint16_t UCI_PARAM_ID_TX_BASE_BAND_CONFIG = 0xe426; + const uint16_t UCI_PARAM_ID_DDFS_TONE_CONFIG = 0xe427; + const uint16_t UCI_PARAM_ID_TX_PULSE_SHAPE_CONFIG = 0xe428; + + switch (id) { + case EXTCAL_PARAM_CLK_ACCURACY: + { + if (data_len != 6) { + return UWBSTATUS_FAILED; + } + + std::vector<uint8_t> tlv; + // Tag + tlv.push_back(UCI_PARAM_ID_RF_CLK_ACCURACY_CALIB); + // Length + tlv.push_back((uint8_t)data_len + 1); + // Value + tlv.push_back(3); // number of register (must be 0x03) + tlv.insert(tlv.end(), data, data + data_len); + + return sr1xx_set_calibration(ch, tlv); + } + case EXTCAL_PARAM_RX_ANT_DELAY: + { + if (!ch || data_len < 1 || !data[0] || (data[0] * 3) != (data_len - 1)) { + return UWBSTATUS_FAILED; + } + + std::vector<uint8_t> tlv; + // Tag + tlv.push_back(UCI_PARAM_ID_RX_ANT_DELAY_CALIB); + // Length + tlv.push_back((uint8_t)data_len); + // Value + tlv.insert(tlv.end(), data, data + data_len); + + return sr1xx_set_calibration(ch, tlv); + } + case EXTCAL_PARAM_TX_POWER: + { + if (!ch || data_len < 1 || !data[0] || (data[0] * 5) != (data_len - 1)) { + return UWBSTATUS_FAILED; + } + + std::vector<uint8_t> tlv; + // Tag + tlv.push_back(UCI_PARAM_ID_TX_POWER_PER_ANTENNA); + // Length + tlv.push_back((uint8_t)data_len); + // Value + tlv.insert(tlv.end(), data, data + data_len); + + return sr1xx_set_calibration(ch, tlv); + } + case EXTCAL_PARAM_TX_BASE_BAND_CONTROL: + { + if (data_len != 1) { + return UWBSTATUS_FAILED; + } + + std::vector<uint8_t> tlv; + // Tag + tlv.push_back(UCI_PARAM_ID_TX_BASE_BAND_CONFIG >> 8); + tlv.push_back(UCI_PARAM_ID_TX_BASE_BAND_CONFIG & 0xff); + // Length + tlv.push_back(1); + // Value + tlv.push_back(data[0]); + + return sr1xx_set_conf(tlv); + } + case EXTCAL_PARAM_DDFS_TONE_CONFIG: + { + if (!data_len) { + return UWBSTATUS_FAILED; + } + + std::vector<uint8_t> tlv; + // Tag + tlv.push_back(UCI_PARAM_ID_DDFS_TONE_CONFIG >> 8); + tlv.push_back(UCI_PARAM_ID_DDFS_TONE_CONFIG & 0xff); + // Length + tlv.push_back(data_len); + // Value + tlv.insert(tlv.end(), data, data + data_len); + + return sr1xx_set_conf(tlv); + } + case EXTCAL_PARAM_TX_PULSE_SHAPE: + { + if (!data_len) { + return UWBSTATUS_FAILED; + } + + std::vector<uint8_t> tlv; + // Tag + tlv.push_back(UCI_PARAM_ID_TX_PULSE_SHAPE_CONFIG >> 8); + tlv.push_back(UCI_PARAM_ID_TX_PULSE_SHAPE_CONFIG & 0xff); + // Length + tlv.push_back(data_len); + // Value + tlv.insert(tlv.end(), data, data + data_len); + + return sr1xx_set_conf(tlv); + } + default: + NXPLOG_UCIHAL_E("Unsupported parameter: 0x%x", id); + return UWBSTATUS_FAILED; + } +} diff --git a/halimpl/hal/phNxpUwbCalib.h b/halimpl/hal/phNxpUwbCalib.h new file mode 100644 index 0000000..a88a2b4 --- /dev/null +++ b/halimpl/hal/phNxpUwbCalib.h @@ -0,0 +1,21 @@ +/* + * Copyright 2024 Google + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include "NxpUwbChip.h" + +tHAL_UWB_STATUS phNxpUwbCalib_apply_calibration(extcal_param_id_t id, const uint8_t ch, const uint8_t *data, size_t data_len); diff --git a/halimpl/hal/sr1xx/NxpUwbChipSr1xx.cc b/halimpl/hal/sr1xx/NxpUwbChipSr1xx.cc index f39ccae..679e5a4 100644 --- a/halimpl/hal/sr1xx/NxpUwbChipSr1xx.cc +++ b/halimpl/hal/sr1xx/NxpUwbChipSr1xx.cc @@ -5,6 +5,7 @@ #include "phNxpUciHal_utils.h" #include "phUwbStatus.h" #include "phUwbTypes.h" +#include "phNxpUwbCalib.h" #include "uci_defs.h" #define UCI_MSG_UWB_ESE_BINDING_LEN 11 @@ -29,157 +30,6 @@ static void report_binding_status(uint8_t binding_status) } } -// -// SR1XX Device Calibrations: -// -// Based on NXP SR1xx UCI v2.0.5 -// current HAL impl only supports "xtal" read from otp -// others should be existed in .conf files - -static tHAL_UWB_STATUS sr1xx_set_calibration(uint8_t channel, const std::vector<uint8_t> &tlv) -{ - // SET_CALIBRATION_CMD header: GID=0xF OID=0x21 - std::vector<uint8_t> packet({ (0x20 | UCI_GID_PROPRIETARY_0X0F), UCI_MSG_SET_DEVICE_CALIBRATION, 0x00, 0x00}); - - // use 9 for channel-independent parameters - if (!channel) { - channel = 9; - } - packet.push_back(channel); - packet.insert(packet.end(), tlv.begin(), tlv.end()); - packet[3] = packet.size() - 4; - return phNxpUciHal_send_ext_cmd(packet.size(), packet.data()); -} - -static tHAL_UWB_STATUS sr1xx_set_conf(const std::vector<uint8_t> &tlv) -{ - // SET_CALIBRATION_CMD header: GID=0xF OID=0x21 - std::vector<uint8_t> packet({ (0x20 | UCI_GID_CORE), UCI_MSG_CORE_SET_CONFIG, 0x00, 0x00}); - packet.push_back(1); // number of parameters - packet.insert(packet.end(), tlv.begin(), tlv.end()); - packet[3] = packet.size() - 4; - return phNxpUciHal_send_ext_cmd(packet.size(), packet.data()); -} - -static tHAL_UWB_STATUS sr1xx_apply_calibration(extcal_param_id_t id, const uint8_t ch, const uint8_t *data, size_t data_len) -{ - // Device Calibration - const uint8_t UCI_PARAM_ID_RF_CLK_ACCURACY_CALIB = 0x01; - const uint8_t UCI_PARAM_ID_RX_ANT_DELAY_CALIB = 0x02; - const uint8_t UCI_PARAM_ID_TX_POWER_PER_ANTENNA = 0x04; - - // Device Configurations - const uint16_t UCI_PARAM_ID_TX_BASE_BAND_CONFIG = 0xe426; - const uint16_t UCI_PARAM_ID_DDFS_TONE_CONFIG = 0xe427; - const uint16_t UCI_PARAM_ID_TX_PULSE_SHAPE_CONFIG = 0xe428; - - switch (id) { - case EXTCAL_PARAM_CLK_ACCURACY: - { - if (data_len != 6) { - return UWBSTATUS_FAILED; - } - - std::vector<uint8_t> tlv; - // Tag - tlv.push_back(UCI_PARAM_ID_RF_CLK_ACCURACY_CALIB); - // Length - tlv.push_back((uint8_t)data_len + 1); - // Value - tlv.push_back(3); // number of register (must be 0x03) - tlv.insert(tlv.end(), data, data + data_len); - - return sr1xx_set_calibration(ch, tlv); - } - case EXTCAL_PARAM_RX_ANT_DELAY: - { - if (!ch || data_len < 1 || !data[0] || (data[0] * 3) != (data_len - 1)) { - return UWBSTATUS_FAILED; - } - - std::vector<uint8_t> tlv; - // Tag - tlv.push_back(UCI_PARAM_ID_RX_ANT_DELAY_CALIB); - // Length - tlv.push_back((uint8_t)data_len); - // Value - tlv.insert(tlv.end(), data, data + data_len); - - return sr1xx_set_calibration(ch, tlv); - } - case EXTCAL_PARAM_TX_POWER: - { - if (!ch || data_len < 1 || !data[0] || (data[0] * 5) != (data_len - 1)) { - return UWBSTATUS_FAILED; - } - - std::vector<uint8_t> tlv; - // Tag - tlv.push_back(UCI_PARAM_ID_TX_POWER_PER_ANTENNA); - // Length - tlv.push_back((uint8_t)data_len); - // Value - tlv.insert(tlv.end(), data, data + data_len); - - return sr1xx_set_calibration(ch, tlv); - } - case EXTCAL_PARAM_TX_BASE_BAND_CONTROL: - { - if (data_len != 1) { - return UWBSTATUS_FAILED; - } - - std::vector<uint8_t> tlv; - // Tag - tlv.push_back(UCI_PARAM_ID_TX_BASE_BAND_CONFIG >> 8); - tlv.push_back(UCI_PARAM_ID_TX_BASE_BAND_CONFIG & 0xff); - // Length - tlv.push_back(1); - // Value - tlv.push_back(data[0]); - - return sr1xx_set_conf(tlv); - } - case EXTCAL_PARAM_DDFS_TONE_CONFIG: - { - if (!data_len) { - return UWBSTATUS_FAILED; - } - - std::vector<uint8_t> tlv; - // Tag - tlv.push_back(UCI_PARAM_ID_DDFS_TONE_CONFIG >> 8); - tlv.push_back(UCI_PARAM_ID_DDFS_TONE_CONFIG & 0xff); - // Length - tlv.push_back(data_len); - // Value - tlv.insert(tlv.end(), data, data + data_len); - - return sr1xx_set_conf(tlv); - } - case EXTCAL_PARAM_TX_PULSE_SHAPE: - { - if (!data_len) { - return UWBSTATUS_FAILED; - } - - std::vector<uint8_t> tlv; - // Tag - tlv.push_back(UCI_PARAM_ID_TX_PULSE_SHAPE_CONFIG >> 8); - tlv.push_back(UCI_PARAM_ID_TX_PULSE_SHAPE_CONFIG & 0xff); - // Length - tlv.push_back(data_len); - // Value - tlv.insert(tlv.end(), data, data + data_len); - - return sr1xx_set_conf(tlv); - } - default: - NXPLOG_UCIHAL_E("Unsupported parameter: 0x%x", id); - return UWBSTATUS_FAILED; - } -} - /****************************************************************************** * Function otp_read_data * @@ -627,7 +477,7 @@ tHAL_UWB_STATUS NxpUwbChipSr1xx::read_otp(extcal_param_id_t id, uint8_t *data, s tHAL_UWB_STATUS NxpUwbChipSr1xx::apply_calibration(extcal_param_id_t id, const uint8_t ch, const uint8_t *data, size_t data_len) { - return sr1xx_apply_calibration(id, ch, data, data_len); + return phNxpUwbCalib_apply_calibration(id, ch, data, data_len); } int16_t NxpUwbChipSr1xx::extra_group_delay(void) { |