/**
 * @file comms_uhf_init.c
 *
 * @brief This file contains functions to initialize and setup the UHF communications interface.
 *
 * @copyright Copyright 2023 Antaris, Inc.
 *
 * 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 "sdr_app_main.h"
#include "comms_uhf_init.h"
#include "comms_uhf_api_map.h"
#include "nvm.h"
#include "comms_uhf_tmr.h"
#include "exo_common.h"
#include "csp_types.h"
#include "csp_if_uhf.h"
#include "sdr_app_main.h"

s_uhf_rf_tx_cfg PLACE_IN_EXT_RAM_MEM uhf_nvm_tx_cfg;
s_uhf_rf_rx_cfg PLACE_IN_EXT_RAM_MEM uhf_nvm_rx_cfg;
s_uhf_rf_tx_pkt_cfg PLACE_IN_EXT_RAM_MEM uhf_nvm_tx_pkt_cfg;
s_uhf_rf_rx_pkt_cfg PLACE_IN_EXT_RAM_MEM uhf_nvm_rx_pkt_cfg;
s_uhf_rf_pwr_cfg PLACE_IN_EXT_RAM_MEM uhf_nvm_pwr_cfg;
s_uhf_general_param_global PLACE_IN_EXT_RAM_MEM uhf_nvm_gen_param;

uint8_t PLACE_IN_EXT_RAM_MEM uhf_nvm_write_sts = 0;

extern s_sdr_tmr_cfg PLACE_IN_EXT_RAM_MEM uhf_tmr_cfg;

extern s_uhf_comms_timer PLACE_IN_EXT_RAM_MEM uhf_trans_timer;
extern s_comms_uhf_get_tm_prop PLACE_IN_EXT_RAM_MEM comms_uhf_tm_read;
extern s_sdr_uhf_mh_info PLACE_IN_EXT_RAM_MEM sdr_uhf_mh;
extern s_seri_pack_send_t PLACE_IN_EXT_RAM_MEM snd_pack;
extern s_uhf_cc1110_reg_map PLACE_IN_EXT_RAM_MEM uhf_reg_map;
extern s_uhf_cc1110_reg_map PLACE_IN_EXT_RAM_MEM uhf_reg_rb;
extern s_uhf_pa_cfg PLACE_IN_EXT_RAM_MEM uhf_pa_cfg;
extern s_uhf_pkt_cfg PLACE_IN_EXT_RAM_MEM uhf_pkt_cfg;
extern s_uhf_rf_cfg PLACE_IN_EXT_RAM_MEM uhf_rf_cfg;
extern s_comms_uhf_beacon_data PLACE_IN_EXT_RAM_MEM uhf_tx_beacon_data;
extern uint8_t PLACE_IN_EXT_RAM_MEM uhf_tc_cmd_id;
extern uint8_t PLACE_IN_EXT_RAM_MEM uhf_sch_gs_contact;
extern uint8_t PLACE_IN_EXT_RAM_MEM comms_uhf_otsu_cb_sts;
extern uint8_t PLACE_IN_EXT_RAM_MEM comms_uhf_first_gs_contact;

extern uint8_t PLACE_IN_EXT_RAM_MEM fw_wr_succ;
extern uint8_t PLACE_IN_EXT_RAM_MEM UHF_FW_UP;
extern uint32_t PLACE_IN_EXT_RAM_MEM csp_uhf_data_count;
extern uint8_t PLACE_IN_EXT_RAM_MEM uhf_tc_len;
extern uint32_t PLACE_IN_EXT_RAM_MEM uhf_fw_page;
extern uint8_t PLACE_IN_EXT_RAM_MEM uhf_fw_page_num;
extern uint8_t PLACE_IN_EXT_RAM_MEM beacon_op;
extern uint16_t PLACE_IN_EXT_RAM_MEM uhf_tc_tm_id;
extern uint16_t PLACE_IN_EXT_RAM_MEM uhf_seq_num;
extern uint16_t PLACE_IN_EXT_RAM_MEM uhf_data_seq_num;
extern uint8_t PLACE_IN_EXT_RAM_MEM comms_uhf_otsu_gs_contact;
extern volatile uint8_t PLACE_IN_EXT_RAM_MEM uhf_gs_contact_valid;
extern uint32_t PLACE_IN_EXT_RAM_MEM uhf_beacon_seq_num;
extern uint16_t PLACE_IN_EXT_RAM_MEM uhf_tc_seq_no;
extern int PLACE_IN_EXT_RAM_MEM line_count;
extern int PLACE_IN_EXT_RAM_MEM total_data;
extern uint8_t PLACE_IN_EXT_RAM_MEM beacon_en;
extern uint8_t PLACE_IN_EXT_RAM_MEM uhf_fw_upd_sts;
extern unsigned int PLACE_IN_EXT_RAM_MEM byte_count;
extern uint8_t PLACE_IN_EXT_RAM_MEM comms_uhf_csw_rx_buf[512];
extern int8 PLACE_IN_EXT_RAM_MEM outbuff[mem_size];
extern uint8_t PLACE_IN_EXT_RAM_MEM tx_buff[UHF_MAX_PLD];
extern uint8_t PLACE_IN_EXT_RAM_MEM uhf_rx_cmd_buff[UHF_MAX_PAYLOAD+1];
extern s_comms_uhf_tm_prop PLACE_IN_EXT_RAM_MEM comms_uhf_tm;
extern s_sdr_beacon_pld uhf_beacon_data;
#ifndef LINUX_TEMP_PORT
extern uint8_t PLACE_IN_EXT_RAM_MEM uhf_uart_rsp[400];
extern uint16_t PLACE_IN_EXT_RAM_MEM uhf_uart_rsp_len;
#endif
/**
 * @brief This function is used to initialize UHF configuration
 */
void comms_uhf_init_uhf_cfg(void)
{   
    os_memset(&uhf_trans_timer,0,sizeof(s_uhf_comms_timer));
    os_memset(&uhf_nvm_tx_cfg,0,sizeof(s_uhf_rf_tx_cfg));
    os_memset(&uhf_nvm_rx_cfg,0,sizeof(s_uhf_rf_rx_cfg));
    os_memset(&uhf_nvm_tx_pkt_cfg,0,sizeof(s_uhf_rf_tx_pkt_cfg));
    os_memset(&uhf_nvm_rx_pkt_cfg,0,sizeof(s_uhf_rf_rx_pkt_cfg));
    os_memset(&uhf_nvm_pwr_cfg,0,sizeof(s_uhf_rf_pwr_cfg));
    os_memset(&uhf_tmr_cfg,0,sizeof(s_sdr_tmr_cfg));
    os_memset(&comms_uhf_tm_read,0,sizeof(s_comms_uhf_get_tm_prop));
    os_memset(&uhf_nvm_gen_param,0,sizeof(s_uhf_general_param_global));
    os_memset(&sdr_uhf_mh,0,sizeof(s_sdr_uhf_mh_info));
    os_memset(&snd_pack,0,sizeof(s_seri_pack_send_t));
    os_memset(&uhf_reg_map,0,sizeof(s_uhf_cc1110_reg_map));
    os_memset(&uhf_reg_rb,0,sizeof(s_uhf_cc1110_reg_map));
    os_memset(&uhf_pa_cfg,0,sizeof(s_uhf_pa_cfg));
    os_memset(&uhf_pkt_cfg,0,sizeof(s_uhf_pkt_cfg));
    os_memset(&uhf_rf_cfg,0,sizeof(s_uhf_rf_cfg));
    os_memset(&uhf_tx_beacon_data,0,sizeof(s_comms_uhf_beacon_data));
    os_memset(&comms_uhf_tm,0,sizeof(s_comms_uhf_tm_prop));

    os_memset(comms_uhf_csw_rx_buf,0,sizeof(comms_uhf_csw_rx_buf));
    os_memset(outbuff,0,sizeof(outbuff));
    os_memset(tx_buff,0,sizeof(tx_buff));
    os_memset(uhf_rx_cmd_buff,0,sizeof(uhf_rx_cmd_buff));
    
    os_memset(&uhf_beacon_data,0,sizeof(s_sdr_beacon_pld));

    uhf_tc_cmd_id =0;
    uhf_sch_gs_contact =0;
    uhf_nvm_write_sts =0;
    comms_uhf_otsu_cb_sts =0;
    comms_uhf_first_gs_contact =0;
    fw_wr_succ =0;
    UHF_FW_UP =0;
    csp_uhf_data_count =0;
    uhf_tc_len =0;
    uhf_fw_page =0;
    uhf_fw_page_num =0;
    beacon_op =2;
    uhf_tc_tm_id =0;
    uhf_seq_num =0;
    uhf_data_seq_num =0;
    comms_uhf_otsu_gs_contact = 0;
    uhf_gs_contact_valid = 0;
    uhf_beacon_seq_num = 0;
    uhf_tc_seq_no =0;
    line_count = 0;
    total_data = 0;
    beacon_en =1;
    byte_count = 0;
    uhf_fw_upd_sts = 0;
#ifndef LINUX_TEMP_PORT
    uhf_uart_rsp_len =0;
    os_memset(uhf_uart_rsp,0,sizeof(uhf_uart_rsp));
#endif
    comms_uhf_timer_init_default();
    comms_uhf_timer_init();
    comms_uhf_cfg_nvm_read();
    // TODO: Temporarily added unitl NVM available
}

/**
 * @brief Initialize UHF timers with default values
 * 
 * This function initializes the various timers used by the UHF
 * communication system to default values. It will be called as part 
 * of the system initialization sequence.
 */
void comms_uhf_timer_init_default(void)
{
    uhf_tmr_cfg.beacon_enb_tmr = 3*60*1000; // 30 seconds
    uhf_tmr_cfg.beacon_prd_tmr = 10*1000; // 10 seconds
    uhf_tmr_cfg.beacon_rep_tmr = 2*1000; // 2 second
    uhf_tmr_cfg.sdr_tm_tx_tmr = 2*60*1000; // 2 minute
    uhf_tmr_cfg.sdr_tx_on_tmr = 30*1000; // 30 seconds
    uhf_tmr_cfg.sdr_rx_on_tmr = 20*1000; // 20 seconds
    uhf_tmr_cfg.sdr_tm_read_tmr = 2*60*1000; // 2 m
    DEBUG_CPRINT(("\nuhf_tmr_cfg.beacon_enb_tmr %d", uhf_tmr_cfg.beacon_enb_tmr));
    DEBUG_CPRINT(("\nuhf_tmr_cfg.beacon_prd_tmr %d", uhf_tmr_cfg.beacon_prd_tmr));
    DEBUG_CPRINT(("\nuhf_tmr_cfg.beacon_rep_tmr %d", uhf_tmr_cfg.beacon_rep_tmr));
    DEBUG_CPRINT(("\nuhf_tmr_cfg.beacon_tm-tx_tmr %d", uhf_tmr_cfg.sdr_tm_tx_tmr));
    DEBUG_CPRINT(("\nuhf_tmr_cfg.beacon_tx_on %d", uhf_tmr_cfg.sdr_tx_on_tmr));
    DEBUG_CPRINT(("\nuhf_tmr_cfg.beacon_rx_on %d", uhf_tmr_cfg.sdr_rx_on_tmr));
    DEBUG_CPRINT(("\nuhf_tmr_cfg.beacon_tm_read %d", uhf_tmr_cfg.sdr_tm_read_tmr));
}


/** 
 * @brief Initialize UHF configuration parameters
 * 
 * This function initializes the UHF configuration parameter 
 * structure with default values. It will be called during
 * system boot to initialize the config params.
 */  
void comms_uhf_init_cfg_param()
{
    uhf_nvm_tx_cfg.base_freq = 400200000;
    uhf_nvm_tx_cfg.if_freq = 158203;
    uhf_nvm_tx_cfg.chan_num = 0;
    uhf_nvm_tx_cfg.chan_spacing= 363372.8027;
    uhf_nvm_tx_cfg.freq_ofst = 0;
    uhf_nvm_tx_cfg.mod_type = 0;
    uhf_nvm_tx_cfg.sync_mode  = 3;
    uhf_nvm_tx_cfg.data_rate =7415.771;
    uhf_nvm_tx_cfg.enb_dc_filter =0;
    uhf_nvm_tx_cfg.fec_enb = 1;
    uhf_nvm_tx_cfg.preamble_num = 2;
    uhf_nvm_tx_cfg.channel_bw = 60267;
    uhf_nvm_tx_cfg.manchester_enable =0;
    uhf_nvm_tx_cfg.freq_dev = 3707.866;

    uhf_nvm_rx_cfg.base_freq= 450100000;
    uhf_nvm_rx_cfg.if_freq = 158203;
    uhf_nvm_rx_cfg.chan_num= 0;
    uhf_nvm_rx_cfg.chan_spacing= 363372.8027;
    uhf_nvm_rx_cfg.freq_ofst= 0;
    uhf_nvm_rx_cfg.mod_type = 0;
    uhf_nvm_rx_cfg.sync_mode= 3;
    uhf_nvm_rx_cfg.data_rate =7415.771;
    uhf_nvm_rx_cfg.enb_dc_filter =0;
    uhf_nvm_rx_cfg.fec_enb = 1;
    uhf_nvm_rx_cfg.preamble_num = 2;
    uhf_nvm_rx_cfg.channel_bw = 60267.857;
    uhf_nvm_rx_cfg.manchester_enable=0;
    uhf_nvm_rx_cfg.freq_dev= 3707.866;
    uhf_nvm_rx_cfg.rx_sync_time_out = 7;
    uhf_nvm_rx_cfg.rx_attenuation = 0;

    uhf_nvm_tx_pkt_cfg.demod_sync_word = 37331;
    uhf_nvm_tx_pkt_cfg.max_pkt_len= 255; 
    uhf_nvm_tx_pkt_cfg.whitening_enb = 1;
    uhf_nvm_tx_pkt_cfg.pkt_fmt = 0;
    uhf_nvm_tx_pkt_cfg.crc_enb= 0;
    uhf_nvm_tx_pkt_cfg.pkt_len_cfg= 1;
    uhf_nvm_tx_pkt_cfg.device_addr = 0;

    uhf_nvm_rx_pkt_cfg.demod_sync_word = 37331;
    uhf_nvm_rx_pkt_cfg.max_pkt_len = 255;
    uhf_nvm_rx_pkt_cfg.whitening_enb = 1;
    uhf_nvm_rx_pkt_cfg.pkt_fmt = 0;
    uhf_nvm_rx_pkt_cfg.crc_enb = 0; 
    uhf_nvm_rx_pkt_cfg.pkt_len_cfg = 1;
    uhf_nvm_rx_pkt_cfg.device_addr = 0;

    uhf_nvm_pwr_cfg.max_dvga_gain = 0;
    uhf_nvm_pwr_cfg.max_lna_gain = 0;
    uhf_nvm_pwr_cfg.lna_sel= 1;
    uhf_nvm_pwr_cfg.filter_len = 1;
    uhf_nvm_pwr_cfg.power_table_sel= 0;
    uhf_nvm_pwr_cfg.rf_output_power = 192;

    uhf_nvm_gen_param.beacon_tx_timeout = 30;
    uhf_nvm_gen_param.beacon_tx_interval = 60;
    uhf_nvm_gen_param.beacon_mode_timeout = 600;
    sprintf((char *) uhf_nvm_gen_param.fw_aes_key,"%s","4b7c6a8712acd892083e682fb71c890");
}

/*MACRO defined to check whether the NVM value is within range*/ 

/*#define RANGE_CHECK_AND_ASSIGN(value,min,max,def_val) \
    ((value>=min)&&(value<=max))?value:def_val*/

/**
 * @brief This function is used to write UHF configuration to NVM location
 *
 * This function writes the current UHF configuration from RAM
 * to non-volatile memory for persistent storage.
 */
void comms_uhf_cfg_nvm_write(void)
{

    uhf_nvm_tx_cfg.chan_num=RANGE_CHECK_AND_ASSIGN(uhf_nvm_tx_cfg.chan_num,MIN_CHAN_NUM,MAX_CHAN_NUM,DEFAULT_TX_CHAN_NUM);
    nvm_parameter_write(NVM_DATA,NVM_UHF_TX_CHAN_NUM,(uint8_t*)&uhf_nvm_tx_cfg.chan_num);

    uhf_nvm_tx_cfg.mod_type =RANGE_CHECK_AND_ASSIGN(uhf_nvm_tx_cfg.mod_type,MIN_MOD_TYPE,MAX_MOD_TYPE,DEFAULT_TX_MOD_TYPE);
    nvm_parameter_write(NVM_DATA,NVM_UHF_TX_MOD_TYPE,(uint8_t*)&uhf_nvm_tx_cfg.mod_type);

    uhf_nvm_tx_cfg.sync_mode=RANGE_CHECK_AND_ASSIGN(uhf_nvm_tx_cfg.sync_mode,MIN_SYNC_MODE,MAX_SYNC_MODE,DEFAULT_TX_SYNC_MODE);
    nvm_parameter_write(NVM_DATA,NVM_UHF_TX_SYNC_MODE,(uint8_t*)&uhf_nvm_tx_cfg.sync_mode);

    uhf_nvm_tx_cfg.enb_dc_filter=RANGE_CHECK_AND_ASSIGN(uhf_nvm_tx_cfg.enb_dc_filter,MIN_ENB_DC_FILTER,MAX_ENB_DC_FILTER,DEFAULT_TX_ENB_DC_FILTER);
    nvm_parameter_write(NVM_DATA,NVM_UHF_TX_ENABLE_DC_FILTER,(uint8_t*)&uhf_nvm_tx_cfg.enb_dc_filter);
   
    uhf_nvm_tx_cfg.fec_enb= RANGE_CHECK_AND_ASSIGN(uhf_nvm_tx_cfg.fec_enb,MIN_FEC_ENB,MAX_FEC_ENB,DEFAULT_TX_FEC_ENB);
    nvm_parameter_write(NVM_DATA,NVM_UHF_TX_FEC_ENB,(uint8_t*)&uhf_nvm_tx_cfg.fec_enb);

    uhf_nvm_tx_cfg.preamble_num=RANGE_CHECK_AND_ASSIGN(uhf_nvm_tx_cfg.preamble_num,MIN_PREAMBLE_NUM,MAX_PREAMBLE_NUM,DEFAULT_TX_PREAMBLE_NUM);
    nvm_parameter_write(NVM_DATA,NVM_UHF_TX_PREAM_NUM,(uint8_t*)&uhf_nvm_tx_cfg.preamble_num);

    uhf_nvm_tx_cfg.manchester_enable=RANGE_CHECK_AND_ASSIGN(uhf_nvm_tx_cfg.manchester_enable,MIN_MANCHESTER_ENABLE,MAX_MANCHESTER_ENABLE,DEFAULT_TX_MANCHESTER_ENABLE);
    nvm_parameter_write(NVM_DATA,NVM_UHF_TX_MANCHESTER_ENB,(uint8_t*)&uhf_nvm_tx_cfg.manchester_enable);

    nvm_parameter_write(NVM_DATA,NVM_UHF_TX_RSVD,(uint8_t*)&uhf_nvm_tx_cfg.rsvd);

    uhf_nvm_tx_cfg.base_freq=RANGE_CHECK_AND_ASSIGN(uhf_nvm_tx_cfg.base_freq,MIN_BASE_FREQ,MAX_BASE_FREQ,DEFAULT_TX_BASE_FREQ);
    nvm_parameter_write(NVM_DATA,NVM_UHF_TX_BASE_FREQ,(uint8_t*)&uhf_nvm_tx_cfg.base_freq);

    uhf_nvm_tx_cfg.if_freq=RANGE_CHECK_AND_ASSIGN(uhf_nvm_tx_cfg.if_freq,MIN_IF_FREQ,MAX_IF_FREQ,DEFAULT_TX_IF_FREQ);
    nvm_parameter_write(NVM_DATA,NVM_UHF_TX_IF_FREQ,(uint8_t*)&uhf_nvm_tx_cfg.if_freq);

    uhf_nvm_tx_cfg.chan_spacing=RANGE_CHECK_AND_ASSIGN(uhf_nvm_tx_cfg.chan_spacing,MIN_CHAN_SPACING,MAX_CHAN_SPACING,DEFAULT_TX_CHAN_SPACING);
    nvm_parameter_write(NVM_DATA,NVM_UHF_TX_CHAN_SPACING,(uint8_t*)&uhf_nvm_tx_cfg.chan_spacing);

    uhf_nvm_tx_cfg.freq_ofst=RANGE_CHECK_AND_ASSIGN(uhf_nvm_tx_cfg.freq_ofst,MIN_FREQ_OFST,MAX_FREQ_OFST,DEFAULT_TX_FREQ_OFST);
    nvm_parameter_write(NVM_DATA,NVM_UHF_TX_FREQ_OFFSET,(uint8_t*)&uhf_nvm_tx_cfg.freq_ofst);

    uhf_nvm_tx_cfg.data_rate=RANGE_CHECK_AND_ASSIGN(uhf_nvm_tx_cfg.data_rate,MIN_DATA_RATE,MAX_DATA_RATE,DEFAULT_TX_DATA_RATE);
    nvm_parameter_write(NVM_DATA,NVM_UHF_TX_DATA_RATE,(uint8_t*)&uhf_nvm_tx_cfg.data_rate);

    uhf_nvm_tx_cfg.channel_bw=RANGE_CHECK_AND_ASSIGN(uhf_nvm_tx_cfg.channel_bw,MIN_CHANNEL_BW,MAX_CHANNEL_BW,DEFAULT_TX_CHANNEL_BW);
    nvm_parameter_write(NVM_DATA,NVM_UHF_TX_CHAN_BW,(uint8_t*)&uhf_nvm_tx_cfg.channel_bw);

    uhf_nvm_tx_cfg.freq_dev=RANGE_CHECK_AND_ASSIGN(uhf_nvm_tx_cfg.freq_dev,MIN_FREQ_DEV,MAX_FREQ_DEV,DEFAULT_TX_FREQ_DEV);
    nvm_parameter_write(NVM_DATA,NVM_UHF_TX_FREQ_DEV,(uint8_t*)&uhf_nvm_tx_cfg.freq_dev);
    
   uhf_nvm_rx_cfg.chan_num=RANGE_CHECK_AND_ASSIGN(uhf_nvm_rx_cfg.chan_num,MIN_CHAN_NUM,MAX_CHAN_NUM,DEFAULT_RX_CHAN_NUM);
   nvm_parameter_write(NVM_DATA,NVM_UHF_RX_CHAN_NUM,(uint8_t*)&uhf_nvm_rx_cfg.chan_num);

    uhf_nvm_rx_cfg.mod_type=RANGE_CHECK_AND_ASSIGN(uhf_nvm_rx_cfg.mod_type,MIN_MOD_TYPE,MAX_MOD_TYPE,DEFAULT_RX_MOD_TYPE);
    nvm_parameter_write(NVM_DATA,NVM_UHF_RX_MOD_TYPE,(uint8_t*)&uhf_nvm_rx_cfg.mod_type);

    uhf_nvm_rx_cfg.sync_mode=RANGE_CHECK_AND_ASSIGN(uhf_nvm_rx_cfg.sync_mode,MIN_SYNC_MODE,MAX_SYNC_MODE,DEFAULT_RX_SYNC_MODE);
    nvm_parameter_write(NVM_DATA,NVM_UHF_RX_SYNC_MOD,(uint8_t*)&uhf_nvm_rx_cfg.sync_mode);

    uhf_nvm_rx_cfg.enb_dc_filter=RANGE_CHECK_AND_ASSIGN(uhf_nvm_rx_cfg.enb_dc_filter,MIN_ENB_DC_FILTER,MAX_ENB_DC_FILTER,DEFAULT_RX_ENB_DC_FILTER);
    nvm_parameter_write(NVM_DATA,NVM_UHF_RX_ENB_DC_FILTER,(uint8_t*)&uhf_nvm_rx_cfg.enb_dc_filter);

    uhf_nvm_rx_cfg.fec_enb=RANGE_CHECK_AND_ASSIGN(uhf_nvm_rx_cfg.fec_enb,MIN_FEC_ENB,MAX_FEC_ENB,DEFAULT_RX_FEC_ENB);
    nvm_parameter_write(NVM_DATA,NVM_UHF_RX_FEC_ENB,(uint8_t*)&uhf_nvm_rx_cfg.fec_enb);

    uhf_nvm_rx_cfg.preamble_num=RANGE_CHECK_AND_ASSIGN(uhf_nvm_rx_cfg.preamble_num,MIN_PREAMBLE_NUM,MAX_PREAMBLE_NUM,DEFAULT_RX_PREAMBLE_NUM);
    nvm_parameter_write(NVM_DATA,NVM_UHF_RX_PREM_NUM,(uint8_t*)&uhf_nvm_rx_cfg.preamble_num);

    uhf_nvm_rx_cfg.manchester_enable=RANGE_CHECK_AND_ASSIGN(uhf_nvm_rx_cfg.manchester_enable,MIN_MANCHESTER_ENABLE,MAX_MANCHESTER_ENABLE,DEFAULT_RX_MANCHESTER_ENABLE);
    nvm_parameter_write(NVM_DATA,NVM_UHF_RX_MANCHESTER_ENB,(uint8_t*)&uhf_nvm_rx_cfg.manchester_enable);

    uhf_nvm_rx_cfg.rx_attenuation=RANGE_CHECK_AND_ASSIGN(uhf_nvm_rx_cfg.rx_attenuation,MIN_RX_ATTENUATION,MAX_RX_ATTENUATION,DEFAULT_RX_ATTENUATION);
    nvm_parameter_write(NVM_DATA,NVM_UHF_RX_ATTENUATION,(uint8_t*)&uhf_nvm_rx_cfg.rx_attenuation);

    uhf_nvm_rx_cfg.base_freq=RANGE_CHECK_AND_ASSIGN(uhf_nvm_rx_cfg.base_freq,MIN_BASE_FREQ,MAX_BASE_FREQ,DEFAULT_RX_BASE_FREQ);
    nvm_parameter_write(NVM_DATA,NVM_UHF_RX_BASE_FREQ,(uint8_t*)&uhf_nvm_rx_cfg.base_freq);

    uhf_nvm_rx_cfg.if_freq=RANGE_CHECK_AND_ASSIGN(uhf_nvm_rx_cfg.if_freq,MIN_IF_FREQ,MAX_IF_FREQ,DEFAULT_RX_IF_FREQ);
    nvm_parameter_write(NVM_DATA,NVM_UHF_RX_IF_FREQ,(uint8_t*)&uhf_nvm_rx_cfg.if_freq);

    uhf_nvm_rx_cfg.chan_spacing=RANGE_CHECK_AND_ASSIGN(uhf_nvm_rx_cfg.chan_spacing,MIN_CHAN_SPACING,MAX_CHAN_SPACING,DEFAULT_RX_CHAN_SPACING);
    nvm_parameter_write(NVM_DATA,NVM_UHF_RX_CHAN_SPACING,(uint8_t*)&uhf_nvm_rx_cfg.chan_spacing);

    uhf_nvm_rx_cfg.freq_ofst=RANGE_CHECK_AND_ASSIGN(uhf_nvm_rx_cfg.freq_ofst,MIN_FREQ_OFST,MAX_FREQ_OFST,DEFAULT_RX_FREQ_OFST);
    nvm_parameter_write(NVM_DATA,NVM_UHF_RX_FREQ_OFFSET,(uint8_t*)&uhf_nvm_rx_cfg.freq_ofst);

    uhf_nvm_rx_cfg.data_rate=RANGE_CHECK_AND_ASSIGN(uhf_nvm_rx_cfg.data_rate,MIN_DATA_RATE,MAX_DATA_RATE,DEFAULT_RX_DATA_RATE);
    nvm_parameter_write(NVM_DATA,NVM_UHF_RX_DATA_RATE,(uint8_t*)&uhf_nvm_rx_cfg.data_rate);

    uhf_nvm_rx_cfg.channel_bw=RANGE_CHECK_AND_ASSIGN(uhf_nvm_rx_cfg.channel_bw,MIN_CHANNEL_BW,MAX_CHANNEL_BW,DEFAULT_RX_CHANNEL_BW);
    nvm_parameter_write(NVM_DATA,NVM_UHF_RX_CHAN_BW,(uint8_t*)&uhf_nvm_rx_cfg.channel_bw);

    uhf_nvm_rx_cfg.freq_dev=RANGE_CHECK_AND_ASSIGN(uhf_nvm_rx_cfg.freq_dev,MIN_FREQ_DEV,MAX_FREQ_DEV,DEFAULT_RX_FREQ_DEV);
    nvm_parameter_write(NVM_DATA,NVM_UHF_RX_FREQ_DEV,(uint8_t*)&uhf_nvm_rx_cfg.freq_dev);

    uhf_nvm_rx_cfg.rx_sync_time_out=RANGE_CHECK_AND_ASSIGN(uhf_nvm_rx_cfg.rx_sync_time_out,MIN_RX_SYNC_TIME_OUT,MAX_RX_SYNC_TIME_OUT,DEFAULT_RX_SYNC_TIME_OUT);
    nvm_parameter_write(NVM_DATA,NVM_UHF_RX_SYNC_TIME_OUT,(uint8_t*)&uhf_nvm_rx_cfg.rx_sync_time_out);


    uhf_nvm_pwr_cfg.max_dvga_gain=RANGE_CHECK_AND_ASSIGN(uhf_nvm_pwr_cfg.max_dvga_gain,MIN_MAX_DVGA_GAIN,MAX_MAX_DVGA_GAIN,DEFAULT_MAX_DVGA_GAIN);
    nvm_parameter_write(NVM_DATA,NVM_UHF_PWR_MAX_DVGA_GAIN,(uint8_t*)&uhf_nvm_pwr_cfg.max_dvga_gain);

    uhf_nvm_pwr_cfg.max_lna_gain=RANGE_CHECK_AND_ASSIGN(uhf_nvm_pwr_cfg.max_lna_gain,MIN_MAX_LNA_GAIN,MAX_MAX_LNA_GAIN,DEFAULT_MAX_LNA_GAIN);
    nvm_parameter_write(NVM_DATA,NVM_UHF_PWR_MAX_LNA_GAIN,(uint8_t*)&uhf_nvm_pwr_cfg.max_lna_gain);

    uhf_nvm_pwr_cfg.lna_sel=RANGE_CHECK_AND_ASSIGN(uhf_nvm_pwr_cfg.lna_sel,MIN_LNA_SEL,MAX_LNA_SEL,DEFAULT_LNA_SEL);
    nvm_parameter_write(NVM_DATA,NVM_UHF_PWR_LNA_SEL,(uint8_t*)&uhf_nvm_pwr_cfg.lna_sel);

    uhf_nvm_pwr_cfg.filter_len=RANGE_CHECK_AND_ASSIGN(uhf_nvm_pwr_cfg.filter_len,MIN_FILTER_LEN,MAX_FILTER_LEN,DEFAULT_FILTER_LEN);
    nvm_parameter_write(NVM_DATA,NVM_UHF_PWR_FILTER_LEN,(uint8_t*)&uhf_nvm_pwr_cfg.filter_len);

    uhf_nvm_pwr_cfg.power_table_sel=RANGE_CHECK_AND_ASSIGN(uhf_nvm_pwr_cfg.power_table_sel,MIN_POWER_TABLE_SEL,MAX_POWER_TABLE_SEL,DEFAULT_POWER_TABLE_SEL);
    nvm_parameter_write(NVM_DATA,NVM_UHF_PWR_PWR_TABLE_SEL,(uint8_t*)&uhf_nvm_pwr_cfg.power_table_sel);

    uhf_nvm_pwr_cfg.rf_output_power=RANGE_CHECK_AND_ASSIGN(uhf_nvm_pwr_cfg.rf_output_power,MIN_RF_OUTPUT_POWER,MAX_RF_OUTPUT_POWER,DEFAULT_RF_OUTPUT_POWER);
    nvm_parameter_write(NVM_DATA,NVM_UHF_PWR_RF_OUTPUT_PWR,(uint8_t*)&uhf_nvm_pwr_cfg.rf_output_power);


    uhf_nvm_tx_pkt_cfg.demod_sync_word=RANGE_CHECK_AND_ASSIGN(uhf_nvm_tx_pkt_cfg.demod_sync_word,MIN_DEMOD_SYNC_WORD,MAX_DEMOD_SYNC_WORD,DEFAULT_TX_DEMOD_SYNC_WORD);
    nvm_parameter_write(NVM_DATA,NVM_UHF_TX_PKT_DEMOD_SYNC_WORD,(uint8_t*)&uhf_nvm_tx_pkt_cfg.demod_sync_word);

    uhf_nvm_tx_pkt_cfg.max_pkt_len=RANGE_CHECK_AND_ASSIGN(uhf_nvm_tx_pkt_cfg.max_pkt_len,MIN_MAX_PKT_LEN,MAX_MAX_PKT_LEN,DEFAULT_TX_MAX_PKT_LEN);
    nvm_parameter_write(NVM_DATA,NVM_UHF_TX_PKT_MAX_PKT_LEN,(uint8_t*)&uhf_nvm_tx_pkt_cfg.max_pkt_len);

    uhf_nvm_tx_pkt_cfg.whitening_enb=RANGE_CHECK_AND_ASSIGN(uhf_nvm_tx_pkt_cfg.whitening_enb,MIN_WHITENING_ENB,MAX_WHITENING_ENB,DEFAULT_TX_WHITENING_ENB);
    nvm_parameter_write(NVM_DATA,NVM_UHF_TX_PKT_WHITE_ENB,(uint8_t*)&uhf_nvm_tx_pkt_cfg.whitening_enb);

    uhf_nvm_tx_pkt_cfg.pkt_fmt=RANGE_CHECK_AND_ASSIGN(uhf_nvm_tx_pkt_cfg.pkt_fmt,MIN_PKT_FMT,MAX_PKT_FMT,DEFAULT_TX_PKT_FMT);
    nvm_parameter_write(NVM_DATA,NVM_UHF_TX_PKT_FORMAT,(uint8_t*)&uhf_nvm_tx_pkt_cfg.pkt_fmt);

    uhf_nvm_tx_pkt_cfg.crc_enb=RANGE_CHECK_AND_ASSIGN(uhf_nvm_tx_pkt_cfg.crc_enb,MIN_CRC_ENB,MAX_CRC_ENB,DEFAULT_TX_CRC_ENB);
    nvm_parameter_write(NVM_DATA,NVM_UHF_TX_PKT_CRC_ENB,(uint8_t*)&uhf_nvm_tx_pkt_cfg.crc_enb);

    uhf_nvm_tx_pkt_cfg.pkt_len_cfg=RANGE_CHECK_AND_ASSIGN(uhf_nvm_tx_pkt_cfg.pkt_len_cfg,MIN_PKT_LEN_CFG,MAX_PKT_LEN_CFG,DEFAULT_TX_PKT_LEN_CFG);
    nvm_parameter_write(NVM_DATA,NVM_UHF_TX_PKT_LEN_CFG,(uint8_t*)&uhf_nvm_tx_pkt_cfg.pkt_len_cfg);

    uhf_nvm_tx_pkt_cfg.device_addr=RANGE_CHECK_AND_ASSIGN(uhf_nvm_tx_pkt_cfg.device_addr,MIN_DEVICE_ADDR,MAX_DEVICE_ADDR,DEFAULT_TX_DEVICE_ADDR);
    nvm_parameter_write(NVM_DATA,NVM_UHF_TX_PKT_DEV_ADDR,(uint8_t*)&uhf_nvm_tx_pkt_cfg.device_addr);

    uhf_nvm_rx_pkt_cfg.demod_sync_word=RANGE_CHECK_AND_ASSIGN(uhf_nvm_rx_pkt_cfg.demod_sync_word,MIN_DEMOD_SYNC_WORD,MAX_DEMOD_SYNC_WORD,DEFAULT_RX_DEMOD_SYNC_WORD);
    nvm_parameter_write(NVM_DATA,NVM_UHF_RX_PKT_DEMOD_SYNC_WORD,(uint8_t*)&uhf_nvm_rx_pkt_cfg.demod_sync_word);

    uhf_nvm_rx_pkt_cfg.max_pkt_len=RANGE_CHECK_AND_ASSIGN(uhf_nvm_rx_pkt_cfg.max_pkt_len,MIN_MAX_PKT_LEN,MAX_MAX_PKT_LEN,DEFAULT_RX_MAX_PKT_LEN);
    nvm_parameter_write(NVM_DATA,NVM_UHF_RX_PKT_MAX_PKT_LEN,(uint8_t*)&uhf_nvm_rx_pkt_cfg.max_pkt_len);

    uhf_nvm_rx_pkt_cfg.whitening_enb=RANGE_CHECK_AND_ASSIGN(uhf_nvm_rx_pkt_cfg.whitening_enb,MIN_WHITENING_ENB,MAX_WHITENING_ENB,DEFAULT_RX_WHITENING_ENB);
    nvm_parameter_write(NVM_DATA,NVM_UHF_RX_PKT_WHITE_ENB,(uint8_t*)&uhf_nvm_rx_pkt_cfg.whitening_enb);

    uhf_nvm_rx_pkt_cfg.pkt_fmt=RANGE_CHECK_AND_ASSIGN(uhf_nvm_rx_pkt_cfg.pkt_fmt,MIN_PKT_FMT,MAX_PKT_FMT,DEFAULT_RX_PKT_FMT);
    nvm_parameter_write(NVM_DATA,NVM_UHF_RX_PKT_FORMAT,(uint8_t*)&uhf_nvm_rx_pkt_cfg.pkt_fmt);

    uhf_nvm_rx_pkt_cfg.crc_enb=RANGE_CHECK_AND_ASSIGN(uhf_nvm_rx_pkt_cfg.crc_enb,MIN_CRC_ENB,MAX_CRC_ENB,DEFAULT_RX_CRC_ENB);
    nvm_parameter_write(NVM_DATA,NVM_UHF_RX_PKT_CRC_ENB,(uint8_t*)&uhf_nvm_rx_pkt_cfg.crc_enb);

    uhf_nvm_rx_pkt_cfg.pkt_len_cfg=RANGE_CHECK_AND_ASSIGN(uhf_nvm_rx_pkt_cfg.pkt_len_cfg,MIN_PKT_LEN_CFG,MAX_PKT_LEN_CFG,DEFAULT_TX_PKT_LEN_CFG);
    nvm_parameter_write(NVM_DATA,NVM_UHF_RX_PKT_LEN_CFG,(uint8_t*)&uhf_nvm_rx_pkt_cfg.pkt_len_cfg);

   uhf_nvm_rx_pkt_cfg.device_addr=RANGE_CHECK_AND_ASSIGN(uhf_nvm_rx_pkt_cfg.device_addr,MIN_DEVICE_ADDR,MAX_DEVICE_ADDR,DEFAULT_RX_DEVICE_ADDR);
   nvm_parameter_write(NVM_DATA,NVM_UHF_RX_PKT_DEV_ADDR,(uint8_t*)&uhf_nvm_rx_pkt_cfg.device_addr);

    uhf_nvm_gen_param.beacon_tx_timeout=RANGE_CHECK_AND_ASSIGN(uhf_nvm_gen_param.beacon_tx_timeout,MIN_BEACON_TX_TIMEOUT,MAX_BEACON_TX_TIMEOUT,DEFAULT_BEACON_TX_TIMEOUT);
    nvm_parameter_write(NVM_DATA,NVM_UHF_BEACON_TX_TIMEOUT,(uint8_t*)&uhf_nvm_gen_param.beacon_tx_timeout);

    nvm_parameter_write(NVM_DATA,NVM_UHF_BEACON_TX_INTERVAL,(uint8_t*)&uhf_nvm_gen_param.beacon_tx_interval);

    uhf_nvm_gen_param.beacon_mode_timeout=RANGE_CHECK_AND_ASSIGN(uhf_nvm_gen_param.beacon_mode_timeout,MIN_BEACON_MODE_TIMEOUT,MAX_BEACON_MODE_TIMEOUT,DEFAULT_BEACON_MODE_TIMEOUT);
    nvm_parameter_write(NVM_DATA,NVM_UHF_BEACON_MODE_TIMEOUT,(uint8_t*)&uhf_nvm_gen_param.beacon_mode_timeout);

    uhf_nvm_gen_param.beacon_payload_len=RANGE_CHECK_AND_ASSIGN(uhf_nvm_gen_param.beacon_payload_len,MIN_BEACON_PAYLOAD_LEN,MAX_BEACON_PAYLOAD_LEN,DEFAULT_BEACON_PAYLOAD_LEN);
    nvm_parameter_write(NVM_DATA,NVM_UHF_BEACON_PAYLOAD_LEN,(uint8_t*)&uhf_nvm_gen_param.beacon_payload_len);
    
    uhf_nvm_gen_param.tx_win_timeout=RANGE_CHECK_AND_ASSIGN(uhf_nvm_gen_param.tx_win_timeout,MIN_TX_WIN_TIMEOUT,MAX_TX_WIN_TIMEOUT,DEFAULT_TX_WIN_TIMEOUT);
    nvm_parameter_write(NVM_DATA,NVM_UHF_TX_WIN_TIMEOUT,(uint8_t*)&uhf_nvm_gen_param.tx_win_timeout);

    uhf_nvm_gen_param.rx_win_timeout=RANGE_CHECK_AND_ASSIGN(uhf_nvm_gen_param.rx_win_timeout,MIN_RX_WIN_TIMEOUT,MAX_RX_WIN_TIMEOUT,DEFAULT_RX_WIN_TIMEOUT);
    nvm_parameter_write(NVM_DATA,NVM_UHF_RX_WIN_TIMEOUT,(uint8_t*)&uhf_nvm_gen_param.rx_win_timeout);
    nvm_parameter_write(NVM_DATA,NVM_UHF_LAST_UPTIME,(uint8_t*)&uhf_nvm_gen_param.last_uptime);
    nvm_parameter_write(NVM_DATA,NVM_UHF_FW_AES_KEY,(uint8_t*)&uhf_nvm_gen_param.fw_aes_key);
}
/**
 * @brief This function is used to read UHF configuration from NVM location
 * 
 * This function reads the UHF configuration data from non-volatile 
 * memory into the RAM config structure during system initialization.
 */
void comms_uhf_cfg_nvm_read(void)
{
    // int8 status = 0;
    nvm_parameter_read(NVM_DATA,NVM_UHF_TX_BASE_FREQ,(uint8_t*)&uhf_nvm_tx_cfg.base_freq);
    uhf_nvm_tx_cfg.chan_num=RANGE_CHECK_AND_ASSIGN(uhf_nvm_tx_cfg.base_freq,MIN_BASE_FREQ,MAX_BASE_FREQ,DEFAULT_TX_BASE_FREQ);    
    nvm_parameter_read(NVM_DATA,NVM_UHF_TX_CHAN_NUM,(uint8_t*)&uhf_nvm_tx_cfg.chan_num);
    uhf_nvm_tx_cfg.chan_num=RANGE_CHECK_AND_ASSIGN(uhf_nvm_tx_cfg.chan_num,MIN_CHAN_NUM,MAX_CHAN_NUM,DEFAULT_TX_CHAN_NUM);

    nvm_parameter_read(NVM_DATA,NVM_UHF_TX_MOD_TYPE,(uint8_t*)&uhf_nvm_tx_cfg.mod_type);
    uhf_nvm_tx_cfg.mod_type= RANGE_CHECK_AND_ASSIGN(uhf_nvm_tx_cfg.mod_type,MIN_MOD_TYPE,MAX_MOD_TYPE,DEFAULT_TX_MOD_TYPE);

    nvm_parameter_read(NVM_DATA,NVM_UHF_TX_SYNC_MODE,(uint8_t*)&uhf_nvm_tx_cfg.sync_mode);
    uhf_nvm_tx_cfg.sync_mode=RANGE_CHECK_AND_ASSIGN(uhf_nvm_tx_cfg.sync_mode,MIN_SYNC_MODE,MAX_SYNC_MODE,DEFAULT_TX_SYNC_MODE);

    nvm_parameter_read(NVM_DATA,NVM_UHF_TX_ENABLE_DC_FILTER,(uint8_t*)&uhf_nvm_tx_cfg.enb_dc_filter);
    uhf_nvm_tx_cfg.enb_dc_filter=RANGE_CHECK_AND_ASSIGN(uhf_nvm_tx_cfg.enb_dc_filter,MIN_ENB_DC_FILTER,MAX_ENB_DC_FILTER,DEFAULT_TX_ENB_DC_FILTER);

    nvm_parameter_read(NVM_DATA,NVM_UHF_TX_FEC_ENB,(uint8_t*)&uhf_nvm_tx_cfg.fec_enb);
    uhf_nvm_tx_cfg.fec_enb=RANGE_CHECK_AND_ASSIGN(uhf_nvm_tx_cfg.fec_enb,MIN_FEC_ENB,MAX_FEC_ENB,DEFAULT_TX_FEC_ENB);

    nvm_parameter_read(NVM_DATA,NVM_UHF_TX_PREAM_NUM,(uint8_t*)&uhf_nvm_tx_cfg.preamble_num);
    uhf_nvm_tx_cfg.preamble_num=RANGE_CHECK_AND_ASSIGN(uhf_nvm_tx_cfg.preamble_num,MIN_PREAMBLE_NUM,MAX_PREAMBLE_NUM,DEFAULT_TX_PREAMBLE_NUM);
    nvm_parameter_read(NVM_DATA,NVM_UHF_TX_MANCHESTER_ENB,(uint8_t*)&uhf_nvm_tx_cfg.manchester_enable);
    uhf_nvm_tx_cfg.manchester_enable=RANGE_CHECK_AND_ASSIGN(uhf_nvm_tx_cfg.manchester_enable,MIN_MANCHESTER_ENABLE,MAX_MANCHESTER_ENABLE,DEFAULT_TX_MANCHESTER_ENABLE);
    nvm_parameter_read(NVM_DATA,NVM_UHF_TX_RSVD,(uint8_t*)&uhf_nvm_tx_cfg.rsvd);
    nvm_parameter_read(NVM_DATA,NVM_UHF_TX_BASE_FREQ,(uint8_t*)&uhf_nvm_tx_cfg.base_freq);
    uhf_nvm_tx_cfg.base_freq=RANGE_CHECK_AND_ASSIGN(uhf_nvm_tx_cfg.base_freq,MIN_BASE_FREQ,MAX_BASE_FREQ,DEFAULT_TX_BASE_FREQ);
    nvm_parameter_read(NVM_DATA,NVM_UHF_TX_IF_FREQ,(uint8_t*)&uhf_nvm_tx_cfg.if_freq);
    uhf_nvm_tx_cfg.if_freq=RANGE_CHECK_AND_ASSIGN(uhf_nvm_tx_cfg.if_freq,MIN_IF_FREQ,MAX_IF_FREQ,DEFAULT_TX_IF_FREQ);
    nvm_parameter_read(NVM_DATA,NVM_UHF_TX_CHAN_SPACING,(uint8_t*)&uhf_nvm_tx_cfg.chan_spacing);
    uhf_nvm_tx_cfg.chan_spacing=RANGE_CHECK_AND_ASSIGN(uhf_nvm_tx_cfg.chan_spacing,MIN_CHAN_SPACING,MAX_CHAN_SPACING,DEFAULT_TX_CHAN_SPACING);
    nvm_parameter_read(NVM_DATA,NVM_UHF_TX_FREQ_OFFSET,(uint8_t*)&uhf_nvm_tx_cfg.freq_ofst);
    uhf_nvm_tx_cfg.freq_ofst=RANGE_CHECK_AND_ASSIGN(uhf_nvm_tx_cfg.freq_ofst,MIN_FREQ_OFST,MAX_FREQ_OFST,DEFAULT_TX_FREQ_OFST);
    nvm_parameter_read(NVM_DATA,NVM_UHF_TX_DATA_RATE,(uint8_t*)&uhf_nvm_tx_cfg.data_rate);
    uhf_nvm_tx_cfg.data_rate=RANGE_CHECK_AND_ASSIGN(uhf_nvm_tx_cfg.data_rate,MIN_DATA_RATE,MAX_DATA_RATE,DEFAULT_TX_DATA_RATE);
    nvm_parameter_read(NVM_DATA,NVM_UHF_TX_CHAN_BW,(uint8_t*)&uhf_nvm_tx_cfg.channel_bw);
    uhf_nvm_tx_cfg.channel_bw=RANGE_CHECK_AND_ASSIGN(uhf_nvm_tx_cfg.channel_bw,MIN_CHANNEL_BW,MAX_CHANNEL_BW,DEFAULT_TX_CHANNEL_BW);

    nvm_parameter_read(NVM_DATA,NVM_UHF_TX_FREQ_DEV,(uint8_t*)&uhf_nvm_tx_cfg.freq_dev);
    uhf_nvm_tx_cfg.freq_dev=RANGE_CHECK_AND_ASSIGN(uhf_nvm_tx_cfg.freq_dev,MIN_FREQ_DEV,MAX_FREQ_DEV,DEFAULT_TX_FREQ_DEV);


   nvm_parameter_read(NVM_DATA,NVM_UHF_RX_CHAN_NUM,(uint8_t*)&uhf_nvm_rx_cfg.chan_num);
   uhf_nvm_rx_cfg.chan_num=RANGE_CHECK_AND_ASSIGN(uhf_nvm_rx_cfg.chan_num,MIN_CHAN_NUM,MAX_CHAN_NUM,DEFAULT_RX_CHAN_NUM);
   nvm_parameter_read(NVM_DATA,NVM_UHF_RX_MOD_TYPE,(uint8_t*)&uhf_nvm_rx_cfg.mod_type);
   uhf_nvm_rx_cfg.mod_type=RANGE_CHECK_AND_ASSIGN(uhf_nvm_rx_cfg.mod_type,MIN_MOD_TYPE,MAX_MOD_TYPE,DEFAULT_RX_MOD_TYPE);
   nvm_parameter_read(NVM_DATA,NVM_UHF_RX_SYNC_MOD,(uint8_t*)&uhf_nvm_rx_cfg.sync_mode);
   uhf_nvm_rx_cfg.sync_mode=RANGE_CHECK_AND_ASSIGN(uhf_nvm_rx_cfg.sync_mode,MIN_SYNC_MODE,MAX_SYNC_MODE,DEFAULT_RX_SYNC_MODE);
   nvm_parameter_read(NVM_DATA,NVM_UHF_RX_ENB_DC_FILTER,(uint8_t*)&uhf_nvm_rx_cfg.enb_dc_filter);
   uhf_nvm_rx_cfg.enb_dc_filter=RANGE_CHECK_AND_ASSIGN(uhf_nvm_rx_cfg.enb_dc_filter,MIN_ENB_DC_FILTER,MAX_ENB_DC_FILTER,DEFAULT_RX_ENB_DC_FILTER);
    nvm_parameter_read(NVM_DATA,NVM_UHF_RX_FEC_ENB,(uint8_t*)&uhf_nvm_rx_cfg.fec_enb);
    uhf_nvm_rx_cfg.fec_enb=RANGE_CHECK_AND_ASSIGN(uhf_nvm_rx_cfg.fec_enb,MIN_FEC_ENB,MAX_FEC_ENB,DEFAULT_RX_FEC_ENB);
    nvm_parameter_read(NVM_DATA,NVM_UHF_RX_PREM_NUM,(uint8_t*)&uhf_nvm_rx_cfg.preamble_num);
    uhf_nvm_rx_cfg.preamble_num=RANGE_CHECK_AND_ASSIGN(uhf_nvm_rx_cfg.preamble_num,MIN_PREAMBLE_NUM,MAX_PREAMBLE_NUM,DEFAULT_RX_PREAMBLE_NUM);
    nvm_parameter_read(NVM_DATA,NVM_UHF_RX_MANCHESTER_ENB,(uint8_t*)&uhf_nvm_rx_cfg.manchester_enable);
    uhf_nvm_rx_cfg.manchester_enable=RANGE_CHECK_AND_ASSIGN(uhf_nvm_rx_cfg.manchester_enable,MIN_MANCHESTER_ENABLE,MAX_MANCHESTER_ENABLE,DEFAULT_RX_MANCHESTER_ENABLE);
    nvm_parameter_read(NVM_DATA,NVM_UHF_RX_ATTENUATION,(uint8_t*)&uhf_nvm_rx_cfg.rx_attenuation);
    uhf_nvm_rx_cfg.rx_attenuation=RANGE_CHECK_AND_ASSIGN(uhf_nvm_rx_cfg.rx_attenuation,MIN_RX_ATTENUATION,MAX_RX_ATTENUATION,DEFAULT_RX_ATTENUATION);
    nvm_parameter_read(NVM_DATA,NVM_UHF_RX_BASE_FREQ,(uint8_t*)&uhf_nvm_rx_cfg.base_freq);
    uhf_nvm_rx_cfg.base_freq=RANGE_CHECK_AND_ASSIGN(uhf_nvm_rx_cfg.base_freq,MIN_BASE_FREQ,MAX_BASE_FREQ,DEFAULT_RX_BASE_FREQ);
    nvm_parameter_read(NVM_DATA,NVM_UHF_RX_IF_FREQ,(uint8_t*)&uhf_nvm_rx_cfg.if_freq);
    uhf_nvm_rx_cfg.if_freq=RANGE_CHECK_AND_ASSIGN(uhf_nvm_rx_cfg.if_freq,MIN_IF_FREQ,MAX_IF_FREQ,DEFAULT_RX_IF_FREQ);
    nvm_parameter_read(NVM_DATA,NVM_UHF_RX_CHAN_SPACING,(uint8_t*)&uhf_nvm_rx_cfg.chan_spacing);
    uhf_nvm_rx_cfg.chan_spacing=RANGE_CHECK_AND_ASSIGN(uhf_nvm_rx_cfg.chan_spacing,MIN_CHAN_SPACING,MAX_CHAN_SPACING,DEFAULT_RX_CHAN_SPACING);
    nvm_parameter_read(NVM_DATA,NVM_UHF_RX_FREQ_OFFSET,(uint8_t*)&uhf_nvm_rx_cfg.freq_ofst);
    uhf_nvm_rx_cfg.freq_ofst=RANGE_CHECK_AND_ASSIGN(uhf_nvm_rx_cfg.freq_ofst,MIN_FREQ_OFST,MAX_FREQ_OFST,DEFAULT_RX_FREQ_OFST);
    nvm_parameter_read(NVM_DATA,NVM_UHF_RX_DATA_RATE,(uint8_t*)&uhf_nvm_rx_cfg.data_rate);
    uhf_nvm_rx_cfg.data_rate=RANGE_CHECK_AND_ASSIGN(uhf_nvm_rx_cfg.data_rate,MIN_DATA_RATE,MAX_DATA_RATE,DEFAULT_RX_DATA_RATE);
    nvm_parameter_read(NVM_DATA,NVM_UHF_RX_CHAN_BW,(uint8_t*)&uhf_nvm_rx_cfg.channel_bw);
    uhf_nvm_rx_cfg.channel_bw=RANGE_CHECK_AND_ASSIGN(uhf_nvm_rx_cfg.channel_bw,MIN_CHANNEL_BW,MAX_CHANNEL_BW,DEFAULT_RX_CHANNEL_BW);
    nvm_parameter_read(NVM_DATA,NVM_UHF_RX_FREQ_DEV,(uint8_t*)&uhf_nvm_rx_cfg.freq_dev);
    uhf_nvm_rx_cfg.freq_dev=RANGE_CHECK_AND_ASSIGN(uhf_nvm_rx_cfg.freq_dev,MIN_FREQ_DEV,MAX_FREQ_DEV,DEFAULT_RX_FREQ_DEV);
    nvm_parameter_read(NVM_DATA,NVM_UHF_RX_SYNC_TIME_OUT,(uint8_t*)&uhf_nvm_rx_cfg.rx_sync_time_out);
    uhf_nvm_rx_cfg.rx_sync_time_out=RANGE_CHECK_AND_ASSIGN(uhf_nvm_rx_cfg.rx_sync_time_out,MIN_RX_SYNC_TIME_OUT,MAX_RX_SYNC_TIME_OUT,DEFAULT_RX_SYNC_TIME_OUT);



    nvm_parameter_read(NVM_DATA,NVM_UHF_PWR_MAX_DVGA_GAIN,(uint8_t*)&uhf_nvm_pwr_cfg.max_dvga_gain);
    uhf_nvm_pwr_cfg.max_dvga_gain=RANGE_CHECK_AND_ASSIGN(uhf_nvm_pwr_cfg.max_dvga_gain,MIN_MAX_DVGA_GAIN,MAX_MAX_DVGA_GAIN,DEFAULT_MAX_DVGA_GAIN);
    nvm_parameter_read(NVM_DATA,NVM_UHF_PWR_MAX_LNA_GAIN,(uint8_t*)&uhf_nvm_pwr_cfg.max_lna_gain);
    uhf_nvm_pwr_cfg.max_lna_gain=RANGE_CHECK_AND_ASSIGN(uhf_nvm_pwr_cfg.max_lna_gain,MIN_MAX_LNA_GAIN,MAX_MAX_LNA_GAIN,DEFAULT_MAX_LNA_GAIN);
    nvm_parameter_read(NVM_DATA,NVM_UHF_PWR_LNA_SEL,(uint8_t*)&uhf_nvm_pwr_cfg.lna_sel);
    uhf_nvm_pwr_cfg.lna_sel=RANGE_CHECK_AND_ASSIGN(uhf_nvm_pwr_cfg.lna_sel,MIN_LNA_SEL,MAX_LNA_SEL,DEFAULT_LNA_SEL);
    nvm_parameter_read(NVM_DATA,NVM_UHF_PWR_FILTER_LEN,(uint8_t*)&uhf_nvm_pwr_cfg.filter_len);
    uhf_nvm_pwr_cfg.filter_len=RANGE_CHECK_AND_ASSIGN(uhf_nvm_pwr_cfg.filter_len,MIN_FILTER_LEN,MAX_FILTER_LEN,DEFAULT_FILTER_LEN);
    nvm_parameter_read(NVM_DATA,NVM_UHF_PWR_PWR_TABLE_SEL,(uint8_t*)&uhf_nvm_pwr_cfg.power_table_sel);
    uhf_nvm_pwr_cfg.power_table_sel=RANGE_CHECK_AND_ASSIGN(uhf_nvm_pwr_cfg.power_table_sel,MIN_POWER_TABLE_SEL,MAX_POWER_TABLE_SEL,DEFAULT_POWER_TABLE_SEL);
    nvm_parameter_read(NVM_DATA,NVM_UHF_PWR_RF_OUTPUT_PWR,(uint8_t*)&uhf_nvm_pwr_cfg.rf_output_power);
    uhf_nvm_pwr_cfg.rf_output_power=RANGE_CHECK_AND_ASSIGN(uhf_nvm_pwr_cfg.rf_output_power,MIN_RF_OUTPUT_POWER,MAX_RF_OUTPUT_POWER,DEFAULT_RF_OUTPUT_POWER);


    nvm_parameter_read(NVM_DATA,NVM_UHF_TX_PKT_DEMOD_SYNC_WORD,(uint8_t*)&uhf_nvm_tx_pkt_cfg.demod_sync_word);
    uhf_nvm_tx_pkt_cfg.demod_sync_word=RANGE_CHECK_AND_ASSIGN(uhf_nvm_tx_pkt_cfg.demod_sync_word,MIN_DEMOD_SYNC_WORD,MAX_DEMOD_SYNC_WORD,DEFAULT_TX_DEMOD_SYNC_WORD);
    nvm_parameter_read(NVM_DATA,NVM_UHF_TX_PKT_MAX_PKT_LEN,(uint8_t*)&uhf_nvm_tx_pkt_cfg.max_pkt_len);
    uhf_nvm_tx_pkt_cfg.max_pkt_len=RANGE_CHECK_AND_ASSIGN(uhf_nvm_tx_pkt_cfg.max_pkt_len,MIN_MAX_PKT_LEN,MAX_MAX_PKT_LEN,DEFAULT_TX_MAX_PKT_LEN);
    nvm_parameter_read(NVM_DATA,NVM_UHF_TX_PKT_WHITE_ENB,(uint8_t*)&uhf_nvm_tx_pkt_cfg.whitening_enb);
    uhf_nvm_tx_pkt_cfg.whitening_enb=RANGE_CHECK_AND_ASSIGN(uhf_nvm_tx_pkt_cfg.whitening_enb,MIN_WHITENING_ENB,MAX_WHITENING_ENB,DEFAULT_TX_WHITENING_ENB);
    nvm_parameter_read(NVM_DATA,NVM_UHF_TX_PKT_FORMAT,(uint8_t*)&uhf_nvm_tx_pkt_cfg.pkt_fmt);
    uhf_nvm_tx_pkt_cfg.pkt_fmt=RANGE_CHECK_AND_ASSIGN(uhf_nvm_tx_pkt_cfg.pkt_fmt,MIN_PKT_FMT,MAX_PKT_FMT,DEFAULT_TX_PKT_FMT);
    nvm_parameter_read(NVM_DATA,NVM_UHF_TX_PKT_CRC_ENB,(uint8_t*)&uhf_nvm_tx_pkt_cfg.crc_enb);
    uhf_nvm_tx_pkt_cfg.crc_enb=RANGE_CHECK_AND_ASSIGN(uhf_nvm_tx_pkt_cfg.crc_enb,MIN_CRC_ENB,MAX_CRC_ENB,DEFAULT_TX_CRC_ENB);
    nvm_parameter_read(NVM_DATA,NVM_UHF_TX_PKT_LEN_CFG,(uint8_t*)&uhf_nvm_tx_pkt_cfg.pkt_len_cfg);
    uhf_nvm_tx_pkt_cfg.pkt_len_cfg=RANGE_CHECK_AND_ASSIGN(uhf_nvm_tx_pkt_cfg.pkt_len_cfg,MIN_PKT_LEN_CFG,MAX_PKT_LEN_CFG,DEFAULT_TX_PKT_LEN_CFG);
    nvm_parameter_read(NVM_DATA,NVM_UHF_TX_PKT_DEV_ADDR,(uint8_t*)&uhf_nvm_tx_pkt_cfg.device_addr);
    uhf_nvm_tx_pkt_cfg.device_addr=RANGE_CHECK_AND_ASSIGN(uhf_nvm_tx_pkt_cfg.device_addr,MIN_DEVICE_ADDR,MAX_DEVICE_ADDR,DEFAULT_TX_DEVICE_ADDR);

    nvm_parameter_read(NVM_DATA,NVM_UHF_RX_PKT_DEMOD_SYNC_WORD,(uint8_t*)&uhf_nvm_rx_pkt_cfg.demod_sync_word);
    uhf_nvm_rx_pkt_cfg.demod_sync_word=RANGE_CHECK_AND_ASSIGN(uhf_nvm_rx_pkt_cfg.demod_sync_word,MIN_DEMOD_SYNC_WORD,MAX_DEMOD_SYNC_WORD,DEFAULT_RX_DEMOD_SYNC_WORD);
    nvm_parameter_read(NVM_DATA,NVM_UHF_RX_PKT_MAX_PKT_LEN,(uint8_t*)&uhf_nvm_rx_pkt_cfg.max_pkt_len);
    uhf_nvm_rx_pkt_cfg.max_pkt_len=RANGE_CHECK_AND_ASSIGN(uhf_nvm_rx_pkt_cfg.max_pkt_len,MIN_MAX_PKT_LEN,MAX_MAX_PKT_LEN,DEFAULT_RX_MAX_PKT_LEN);
    nvm_parameter_read(NVM_DATA,NVM_UHF_RX_PKT_WHITE_ENB,(uint8_t*)&uhf_nvm_rx_pkt_cfg.whitening_enb);
    uhf_nvm_rx_pkt_cfg.whitening_enb=RANGE_CHECK_AND_ASSIGN(uhf_nvm_rx_pkt_cfg.whitening_enb,MIN_WHITENING_ENB,MAX_WHITENING_ENB,DEFAULT_TX_WHITENING_ENB);
    nvm_parameter_read(NVM_DATA,NVM_UHF_RX_PKT_FORMAT,(uint8_t*)&uhf_nvm_rx_pkt_cfg.pkt_fmt);
    uhf_nvm_rx_pkt_cfg.pkt_fmt=RANGE_CHECK_AND_ASSIGN(uhf_nvm_rx_pkt_cfg.pkt_fmt,MIN_PKT_FMT,MAX_PKT_FMT,DEFAULT_RX_PKT_FMT);
    nvm_parameter_read(NVM_DATA,NVM_UHF_RX_PKT_CRC_ENB,(uint8_t*)&uhf_nvm_rx_pkt_cfg.crc_enb);
    uhf_nvm_rx_pkt_cfg.crc_enb=RANGE_CHECK_AND_ASSIGN(uhf_nvm_rx_pkt_cfg.crc_enb,MIN_CRC_ENB,MAX_CRC_ENB,DEFAULT_RX_CRC_ENB);
    nvm_parameter_read(NVM_DATA,NVM_UHF_RX_PKT_LEN_CFG,(uint8_t*)&uhf_nvm_rx_pkt_cfg.pkt_len_cfg);
    uhf_nvm_rx_pkt_cfg.pkt_len_cfg=RANGE_CHECK_AND_ASSIGN(uhf_nvm_rx_pkt_cfg.pkt_len_cfg,MIN_PKT_LEN_CFG,MAX_PKT_LEN_CFG,DEFAULT_RX_PKT_LEN_CFG);
    nvm_parameter_read(NVM_DATA,NVM_UHF_RX_PKT_DEV_ADDR,(uint8_t*)&uhf_nvm_rx_pkt_cfg.device_addr);
    uhf_nvm_rx_pkt_cfg.device_addr=RANGE_CHECK_AND_ASSIGN(uhf_nvm_rx_pkt_cfg.device_addr,MIN_DEVICE_ADDR,MAX_DEVICE_ADDR,DEFAULT_RX_DEVICE_ADDR);

    nvm_parameter_read(NVM_DATA,NVM_UHF_BEACON_TX_TIMEOUT,(uint8_t*)&uhf_nvm_gen_param.beacon_tx_timeout);
    uhf_nvm_gen_param.beacon_tx_timeout=RANGE_CHECK_AND_ASSIGN(uhf_nvm_gen_param.beacon_tx_timeout,MIN_BEACON_TX_TIMEOUT,MAX_BEACON_TX_TIMEOUT,DEFAULT_BEACON_TX_TIMEOUT);
    nvm_parameter_read(NVM_DATA,NVM_UHF_BEACON_TX_INTERVAL,(uint8_t*)&uhf_nvm_gen_param.beacon_tx_interval);
    uhf_nvm_gen_param.beacon_tx_interval=RANGE_CHECK_AND_ASSIGN(uhf_nvm_gen_param.beacon_tx_interval,MIN_BEACON_TX_INTERVAL,MAX_BEACON_TX_INTERVAL,DEFAULT_BEACON_TX_INTERVAL);
    nvm_parameter_read(NVM_DATA,NVM_UHF_BEACON_MODE_TIMEOUT,(uint8_t*)&uhf_nvm_gen_param.beacon_mode_timeout);
    uhf_nvm_gen_param.beacon_mode_timeout=RANGE_CHECK_AND_ASSIGN(uhf_nvm_gen_param.beacon_mode_timeout,MIN_BEACON_MODE_TIMEOUT,MAX_BEACON_MODE_TIMEOUT,DEFAULT_BEACON_MODE_TIMEOUT);
    nvm_parameter_read(NVM_DATA,NVM_UHF_BEACON_PAYLOAD_LEN,(uint8_t*)&uhf_nvm_gen_param.beacon_payload_len);
    uhf_nvm_gen_param.beacon_payload_len=RANGE_CHECK_AND_ASSIGN(uhf_nvm_gen_param.beacon_payload_len,MIN_BEACON_PAYLOAD_LEN,MAX_BEACON_PAYLOAD_LEN,DEFAULT_BEACON_PAYLOAD_LEN);
    nvm_parameter_read(NVM_DATA,NVM_UHF_TX_WIN_TIMEOUT,(uint8_t*)&uhf_nvm_gen_param.tx_win_timeout);
    uhf_nvm_gen_param.tx_win_timeout=RANGE_CHECK_AND_ASSIGN(uhf_nvm_gen_param.tx_win_timeout,MIN_TX_WIN_TIMEOUT,MAX_TX_WIN_TIMEOUT,DEFAULT_TX_WIN_TIMEOUT);
    nvm_parameter_read(NVM_DATA,NVM_UHF_RX_WIN_TIMEOUT,(uint8_t*)&uhf_nvm_gen_param.rx_win_timeout);
    uhf_nvm_gen_param.rx_win_timeout=RANGE_CHECK_AND_ASSIGN(uhf_nvm_gen_param.rx_win_timeout,MIN_RX_WIN_TIMEOUT,MAX_RX_WIN_TIMEOUT,DEFAULT_RX_WIN_TIMEOUT);
    nvm_parameter_read(NVM_DATA,NVM_UHF_LAST_UPTIME,(uint8_t*)&uhf_nvm_gen_param.last_uptime);
    nvm_parameter_read(NVM_DATA,NVM_UHF_FW_AES_KEY,(uint8_t*)&uhf_nvm_gen_param.fw_aes_key);

#ifdef LINUX_TEMP_PORT
    DEBUG_CPRINT(("\nNVM_UHF_TX_CHAN_NUM:%d\n",uhf_nvm_tx_cfg.chan_num));
    DEBUG_CPRINT(("\nNVM_UHF_TX_MOD_TYPE:%d\n",uhf_nvm_tx_cfg.mod_type));
    DEBUG_CPRINT(("\nNVM_UHF_TX_SYNC_MODE:%d\n",uhf_nvm_tx_cfg.sync_mode));
    DEBUG_CPRINT(("\nNVM_UHF_TX_ENABLE_DC_FILTER:%d\n",uhf_nvm_tx_cfg.enb_dc_filter));
    DEBUG_CPRINT(("\nNVM_UHF_TX_FEC_ENB:%d\n",uhf_nvm_tx_cfg.fec_enb));
    DEBUG_CPRINT(("\nNVM_UHF_TX_PREAM_NUM:%d\n",uhf_nvm_tx_cfg.preamble_num));
    DEBUG_CPRINT(("\nNVM_UHF_TX_MANCHESTER_ENB:%d\n",uhf_nvm_tx_cfg.manchester_enable));
    DEBUG_CPRINT(("\nNVM_UHF_TX_BASE_FREQ:%lf\n",uhf_nvm_tx_cfg.base_freq));
    DEBUG_CPRINT(("\nNVM_UHF_TX_IF_FREQ:%lf\n",uhf_nvm_tx_cfg.if_freq));
    DEBUG_CPRINT(("\nNVM_UHF_TX_CHAN_SPACING:%lf\n",uhf_nvm_tx_cfg.chan_spacing));
    DEBUG_CPRINT(("\nNVM_UHF_TX_FREQ_OFFSET:%lf\n",uhf_nvm_tx_cfg.freq_ofst));
    DEBUG_CPRINT(("\nNVM_UHF_TX_DATA_RATE:%lf\n",uhf_nvm_tx_cfg.data_rate));
    DEBUG_CPRINT(("\nNVM_UHF_TX_CHAN_BW:%lf\n",uhf_nvm_tx_cfg.channel_bw));
    DEBUG_CPRINT(("\nNVM_UHF_TX_FREQ_DEV:%lf\n",uhf_nvm_tx_cfg.freq_dev));
    DEBUG_CPRINT(("\nNVM_UHF_RX_CHAN_NUM:%d\n",uhf_nvm_rx_cfg.chan_num));
    DEBUG_CPRINT(("\nNVM_UHF_RX_MOD_TYPE:%d\n",uhf_nvm_rx_cfg.mod_type));
    DEBUG_CPRINT(("\nNVM_UHF_RX_SYNC_MOD:%d\n",uhf_nvm_rx_cfg.sync_mode));
    DEBUG_CPRINT(("\nNVM_UHF_RX_ENB_DC_FILTER:%d\n",uhf_nvm_rx_cfg.enb_dc_filter));
    DEBUG_CPRINT(("\nNVM_UHF_RX_FEC_ENB:%d\n",uhf_nvm_rx_cfg.fec_enb));
    DEBUG_CPRINT(("\nNVM_UHF_RX_PREM_NUM:%d\n",uhf_nvm_rx_cfg.preamble_num));
    DEBUG_CPRINT(("\nNVM_UHF_RX_MANCHESTER_ENB:%d\n",uhf_nvm_rx_cfg.manchester_enable));
    DEBUG_CPRINT(("\nNVM_UHF_RX_ATTENUATION:%d\n",uhf_nvm_rx_cfg.rx_attenuation));
    DEBUG_CPRINT(("\nNVM_UHF_RX_BASE_FREQ:%lf\n",uhf_nvm_rx_cfg.base_freq));
    DEBUG_CPRINT(("\nNVM_UHF_RX_IF_FREQ:%lf\n",uhf_nvm_rx_cfg.if_freq));
    DEBUG_CPRINT(("\nNVM_UHF_RX_CHAN_SPACING:%lf\n",uhf_nvm_rx_cfg.chan_spacing));
    DEBUG_CPRINT(("\nNVM_UHF_RX_FREQ_OFFSET:%lf\n",uhf_nvm_rx_cfg.freq_ofst));
    DEBUG_CPRINT(("\nNVM_UHF_RX_DATA_RATE:%lf\n",uhf_nvm_rx_cfg.data_rate));
    DEBUG_CPRINT(("\nNVM_UHF_RX_CHAN_BW:%lf\n",uhf_nvm_rx_cfg.channel_bw));
    DEBUG_CPRINT(("\nNVM_UHF_RX_FREQ_DEV:%lf\n",uhf_nvm_rx_cfg.freq_dev));
    DEBUG_CPRINT(("\nNVM_UHF_RX_SYNC_TIME_OUT:%lf\n",uhf_nvm_rx_cfg.rx_sync_time_out));
    DEBUG_CPRINT(("\nNVM_UHF_PWR_MAX_DVGA_GAIN:%d\n",uhf_nvm_pwr_cfg.max_dvga_gain));
    DEBUG_CPRINT(("\nNVM_UHF_PWR_MAX_LNA_GAIN:%d\n",uhf_nvm_pwr_cfg.max_lna_gain));
    DEBUG_CPRINT(("\nNVM_UHF_PWR_LNA_SEL:%d\n",uhf_nvm_pwr_cfg.lna_sel));
    DEBUG_CPRINT(("\nNVM_UHF_PWR_FILTER_LEN:%d\n",uhf_nvm_pwr_cfg.filter_len));
    DEBUG_CPRINT(("\nNVM_UHF_PWR_PWR_TABLE_SEL:%d\n",uhf_nvm_pwr_cfg.power_table_sel));
    DEBUG_CPRINT(("\nNVM_UHF_PWR_RF_OUTPUT_PWR:%d\n",uhf_nvm_pwr_cfg.rf_output_power));
    DEBUG_CPRINT(("\nNVM_UHF_TX_PKT_DEMOD_SYNC_WORD:%d\n",uhf_nvm_tx_pkt_cfg.demod_sync_word));
    DEBUG_CPRINT(("\nNVM_UHF_TX_PKT_MAX_PKT_LEN:%d\n",uhf_nvm_tx_pkt_cfg.max_pkt_len));
    DEBUG_CPRINT(("\nNVM_UHF_TX_PKT_WHITE_ENB:%d\n",uhf_nvm_tx_pkt_cfg.whitening_enb));
    DEBUG_CPRINT(("\nNVM_UHF_TX_PKT_FORMAT:%d\n",uhf_nvm_tx_pkt_cfg.pkt_fmt));
    DEBUG_CPRINT(("\nNVM_UHF_TX_PKT_CRC_ENB:%d\n",uhf_nvm_tx_pkt_cfg.crc_enb));
    DEBUG_CPRINT(("\nNVM_UHF_TX_PKT_LEN_CFG:%d\n",uhf_nvm_tx_pkt_cfg.pkt_len_cfg));
    DEBUG_CPRINT(("\nNVM_UHF_TX_PKT_DEV_ADDR:%d\n",uhf_nvm_tx_pkt_cfg.device_addr));
    DEBUG_CPRINT(("\nNVM_UHF_RX_PKT_DEMOD_SYNC_WORD:%d\n",uhf_nvm_rx_pkt_cfg.demod_sync_word));
    DEBUG_CPRINT(("\nNVM_UHF_RX_PKT_MAX_PKT_LEN:%d\n",uhf_nvm_rx_pkt_cfg.max_pkt_len));
    DEBUG_CPRINT(("\nNVM_UHF_RX_PKT_WHITE_ENB:%d\n",uhf_nvm_rx_pkt_cfg.whitening_enb));
    DEBUG_CPRINT(("\nNVM_UHF_RX_PKT_FORMAT:%d\n",uhf_nvm_rx_pkt_cfg.pkt_fmt));
    DEBUG_CPRINT(("\nNVM_UHF_RX_PKT_CRC_ENB:%d\n",uhf_nvm_rx_pkt_cfg.crc_enb));
    DEBUG_CPRINT(("\nNVM_UHF_RX_PKT_LEN_CFG:%d\n",uhf_nvm_rx_pkt_cfg.pkt_len_cfg));
    DEBUG_CPRINT(("\nNVM_UHF_RX_PKT_DEV_ADDR:%d\n",uhf_nvm_rx_pkt_cfg.device_addr));
    DEBUG_CPRINT(("\nNVM_UHF_BEACON_TX_TIMEOUT:%d\n",uhf_nvm_gen_param.beacon_tx_timeout));
    DEBUG_CPRINT(("\nNVM_UHF_BEACON_TX_INTERVAL:%d\n",uhf_nvm_gen_param.beacon_tx_interval));
    DEBUG_CPRINT(("\nNVM_UHF_BEACON_MODE_TIMEOUT:%d\n",uhf_nvm_gen_param.beacon_mode_timeout));
    DEBUG_CPRINT(("\nNVM_UHF_BEACON_PAYLOAD_LEN:%d\n",uhf_nvm_gen_param.beacon_payload_len));
    DEBUG_CPRINT(("\nNVM_UHF_TX_WIN_TIMEOUT:%d\n",uhf_nvm_gen_param.tx_win_timeout));
    DEBUG_CPRINT(("\nNVM_UHF_RX_WIN_TIMEOUT:%d\n",uhf_nvm_gen_param.rx_win_timeout));
    DEBUG_CPRINT(("\nNVM_UHF_LAST_UPTIME:%d\n",uhf_nvm_gen_param.last_uptime));
#endif
}

/**
 * @brief This function is used to update the first ground contact status to NVM location
 * 
 * This function updates the first ground contact flag in NVM to 
 * indicate UHF has established initial contact with the ground.
 */
void uhf_nvm_upd_first_ground_contact(void)
{
    uint8_t gs = 1;
    nvm_parameter_write(NVM_DATA,NVM_UHF_GS_FIRST_CONTACT,(uint8_t*)&gs);
}

/**
 * @brief This function is used to update the ground contact status after OTSU reset to NVM location
 * 
 * This function updates the OTSU ground contact counter in NVM
 * which tracks total UHF contacts through the satellite's lifetime. 
 */
void uhf_nvm_upd_otsu_ground_contact(void)
{
    uint8_t gs = 1;
    nvm_parameter_write(NVM_DATA,NVM_UHF_OTSU_FIRST_CONTACT,(uint8_t*)&gs);
}

/**
 * @brief This function is used to fetch the flight time of the satellite from NVM location
 * 
 * This function reads the permanent timer values for UHF from NVM
 * into the timer structure during system initialization.
 */
uint64_t uhf_permanant_timer_read(void)
{
    uint64_t epoch_time =0;
    nvm_parameter_read(NVM_DATA,RTC_TIME_DATE_PERMANENT,(uint8_t*)&epoch_time);
    return epoch_time;
}
