
/**
 * @file comms_uhf_init.h
 *
 * @brief This file has the prototypes of functions used for UHF driver initialisation
 *
 * @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.
*
*/

#ifndef COMMS_UHF_INIT_H_
#define COMMS_UHF_INIT_H_


#include <stdio.h>
#include "comms_uhf_main.h"
#include "comms_uhf_api.h"

#define MAX_CHUNK_SIZE 213                    ///< Maximum chunk size
#define MAX_PLD_SIZE 213                      ///< Maximum payload size


/***NVM_MACRO_TO CHECK_THE RANGE****/
#define MIN_CHAN_NUM 0
#define MAX_CHAN_NUM 8

#define MIN_MOD_TYPE 0
#define MAX_MOD_TYPE 2 //2FSK

#define MIN_SYNC_MODE 0
#define MAX_SYNC_MODE 7

#define MIN_ENB_DC_FILTER 0
#define MAX_ENB_DC_FILTER 1

#define MIN_FEC_ENB 0
#define MAX_FEC_ENB 1

#define MIN_PREAMBLE_NUM 0
#define MAX_PREAMBLE_NUM 7

#define MIN_MANCHESTER_ENABLE 0
#define MAX_MANCHESTER_ENABLE 1

#define MIN_BASE_FREQ 400000000//hz
#define MAX_BASE_FREQ 480000000//hz

#define MIN_IF_FREQ 100000//hz
#define MAX_IF_FREQ 200000//hz

#define MIN_CHAN_SPACING 1 
#define MAX_CHAN_SPACING 405000 //hz

#define MIN_FREQ_OFST 0 //hz
#define MAX_FREQ_OFST 3000 //hz

#define MIN_DATA_RATE  800//bps
#define MAX_DATA_RATE  200000//bps

#define MIN_CHANNEL_BW 2
#define MAX_CHANNEL_BW 812000//hz

#define MIN_FREQ_DEV 7.5
#define MAX_FREQ_DEV 15000//hz

#define MIN_RX_ATTENUATION 0
#define MAX_RX_ATTENUATION 3

#define MIN_RX_SYNC_TIME_OUT 0
#define MAX_RX_SYNC_TIME_OUT 255

#define MIN_POWER_TABLE_SEL 0
#define MAX_POWER_TABLE_SEL 7

#define MIN_RF_OUTPUT_POWER 0
#define MAX_RF_OUTPUT_POWER 255

#define MIN_MAX_DVGA_GAIN 0 
#define MAX_MAX_DVGA_GAIN 255 

#define MIN_MAX_LNA_GAIN 0
#define MAX_MAX_LNA_GAIN 255

#define MIN_LNA_SEL 0
#define MAX_LNA_SEL 255

#define MIN_DEMOD_SYNC_WORD 0
#define MAX_DEMOD_SYNC_WORD 65535

#define MIN_MAX_PKT_LEN 10
#define MAX_MAX_PKT_LEN 255

#define MIN_WHITENING_ENB 0
#define MAX_WHITENING_ENB 1

#define MIN_PKT_FMT 0
#define MAX_PKT_FMT 255

#define MIN_CRC_ENB 0
#define MAX_CRC_ENB 1

#define MIN_PKT_LEN_CFG 0
#define MAX_PKT_LEN_CFG 1

#define MIN_DEVICE_ADDR 0
#define MAX_DEVICE_ADDR 255

#define MIN_BEACON_TX_TIMEOUT 0  
#define MAX_BEACON_TX_TIMEOUT 255

#define MIN_BEACON_TX_INTERVAL 0
#define MAX_BEACON_TX_INTERVAL 255

#define MIN_BEACON_MODE_TIMEOUT 0
#define MAX_BEACON_MODE_TIMEOUT 4294967296

#define MIN_BEACON_PAYLOAD_LEN 0
#define MAX_BEACON_PAYLOAD_LEN 255

#define MIN_TX_WIN_TIMEOUT 0
#define MAX_TX_WIN_TIMEOUT 255

#define MIN_RX_WIN_TIMEOUT 0
#define MAX_RX_WIN_TIMEOUT 255


#define MIN_FILTER_LEN 0
#define MAX_FILTER_LEN 255

#define DEFAULT_TX_BASE_FREQ 400200000

#define DEFAULT_TX_IF_FREQ 158203

#define DEFAULT_TX_CHAN_NUM 0

#define DEFAULT_TX_CHAN_SPACING 363372.8027

#define DEFAULT_TX_FREQ_OFST 0

#define DEFAULT_TX_MOD_TYPE 0

#define DEFAULT_TX_SYNC_MODE 3

#define DEFAULT_TX_DATA_RATE 7415.771

#define DEFAULT_TX_ENB_DC_FILTER 0

#define DEFAULT_TX_FEC_ENB 1

#define DEFAULT_TX_PREAMBLE_NUM 2

#define DEFAULT_TX_CHANNEL_BW 60267

#define DEFAULT_TX_MANCHESTER_ENABLE 0

#define DEFAULT_TX_FREQ_DEV 3707.866

#define DEFAULT_RX_BASE_FREQ 450100000

#define DEFAULT_RX_IF_FREQ 158203

#define DEFAULT_RX_CHAN_NUM 0

#define DEFAULT_RX_CHAN_SPACING 363372.8027

#define DEFAULT_RX_FREQ_OFST 0

#define DEFAULT_RX_MOD_TYPE 0

#define DEFAULT_RX_SYNC_MODE 3

#define DEFAULT_RX_DATA_RATE 7415.771

#define DEFAULT_RX_ENB_DC_FILTER 0

#define DEFAULT_RX_FEC_ENB 1

#define DEFAULT_RX_PREAMBLE_NUM 2

#define DEFAULT_RX_CHANNEL_BW 60267.857

#define DEFAULT_RX_MANCHESTER_ENABLE 0

#define DEFAULT_RX_FREQ_DEV 3707.866

#define DEFAULT_RX_ATTENUATION 0

#define DEFAULT_RX_SYNC_TIME_OUT 7

#define DEFAULT_TX_DEMOD_SYNC_WORD 37331

#define DEFAULT_TX_MAX_PKT_LEN 255

#define DEFAULT_TX_WHITENING_ENB 1

#define DEFAULT_TX_PKT_FMT 0

#define DEFAULT_TX_CRC_ENB 0

#define DEFAULT_TX_PKT_LEN_CFG 1

#define DEFAULT_LNA_SEL 1

#define DEFAULT_TX_DEVICE_ADDR 0

#define DEFAULT_RX_DEMOD_SYNC_WORD 37331

#define DEFAULT_RX_MAX_PKT_LEN 255

#define DEFAULT_RX_WHITENING_ENB 1

#define DEFAULT_RX_PKT_FMT 0
#define DEFAULT_RX_CRC_ENB 0

#define DEFAULT_RX_PKT_LEN_CFG 1

#define DEFAULT_RX_DEVICE_ADDR 0

#define DEFAULT_BEACON_TX_TIMEOUT 30

#define DEFAULT_BEACON_TX_INTERVAL 60

#define DEFAULT_BEACON_MODE_TIMEOUT 600

#define DEFAULT_BEACON_PAYLOAD_LEN 0

#define DEFAULT_TX_WIN_TIMEOUT 0

#define DEFAULT_RX_WIN_TIMEOUT 0

#define DEFAULT_POWER_TABLE_SEL 0

#define DEFAULT_RF_OUTPUT_POWER 192

#define DEFAULT_MAX_DVGA_GAIN 0

#define DEFAULT_FILTER_LEN 1

#define DEFAULT_MAX_LNA_GAIN 0

#define DEFAULT_TX_RSVD 0


/**
* @brief  This function is used for write the S-band configuration to NVM memory
*/
void comms_uhf_cfg_nvm_write(void);

/**
* @brief  This function is used for reading the UHF configuration parameters from NVM memory
*/
void comms_uhf_cfg_nvm_read(void);

/**
* @brief  This function is used for updating the ground contact status post OTSU reset
*/
void uhf_nvm_upd_otsu_ground_contact(void);

/**
* @brief  This function is used for updating the very first ground contact status
*/
void uhf_nvm_upd_first_ground_contact(void);

/**
* @brief  This function is used for fetching the satellite flight time stored in the NVM location
*
* @return epochtime of the satellite flight start
*/
uint64_t uhf_permanant_timer_read(void);

/**
* @brief  This function is used for UHF parameters initialisation
*/
void comms_uhf_init_uhf_cfg(void);

void comms_uhf_timer_init_default(void);

void comms_uhf_init_cfg_param();

#endif /*COMMS_UHF_INIT_H_*/
