/**
 * @file xband_main.h
 *
 * @brief This file has the control blocks, enumeration and function prototypes of SDR control layer of X-Band module
 *
 * @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 XBAND_MAIN_H
#define XBAND_MAIN_H

#include "exo_osal.h"
#include "exo_ral_cmn.h"
#include "exo_ral_mem_management.h"
#include "exo_types.h"

typedef float f32;
typedef double f64;

#ifdef __cplusplus
extern "C" {
#endif


///XBAND error codes
#define  XBAND_IPC_READ_ERROR                       -20
#define  XBAND_IPC_WRITE_ERROR                      -21
#define  XBAND_INVALID_COMMAND                      -10
#define  XBAND_NULL_PTR                              -1
#define  XBAND_OPERATION_SUCCESS                     1
#define  XBAND_IPC_OK                                2

/**
  * @brief  xband State in enum definition
  */
typedef enum
{
     XBAND_INIT_STATE,       ///< xband module initializes from reset state
     XBAND_BOOT_STATE,        ///< xband booting state
     XBAND_DFU_STATE,         ///< device firmware will be updated during this state
     XBAND_CFG_STATE,         ///< xband configuration state
     XBAND_CALIB_STATE,       ///< xband calibration state
     XBAND_SLEEP_IDLE_STATE,  ///< xband initialize sleep and idle state
     XBAND_ACTIVE_STATE,      ///< xband active state
     XBAND_SAFE_MODE_STATE,   ///< xband initialize safe mode state
     XBAND_ERROR_STATE,       ///< xband error state
     XBAND_BYPASS_STATE,      ///< xband bypass state
     XBAND_MAX_NUM_STATE
}e_xband_state;

/**
  * @brief  xband event in enum definition
  */
typedef enum
{
    XBAND_BOOT_REQ,             ///< xband boot request
    XBAND_BOOT_STS,             ///< xband boot status
    XBAND_RESET_REQ,            ///< xband reset request
    XBAND_RESET_RSP,            ///< xband reset response
    XBAND_RESET_NOTF,           ///< xband reset notification
    XBAND_ACTIVE_REQ,           ///< xband active request
    XBAND_ACTIVE_RSP,           ///< xband active response
    XBAND_ACTIVE_NOTF,          ///< xband active notification
    XBAND_SLEEP_REQ,            ///< xband sleep request
    XBAND_SLEEP_RSP,            ///< xband sleep response
    XBAND_SLEEP_NOTF,           ///< xband sleep notification
    XBAND_DFU_REQ,              ///< xband device firmware request
    XBAND_DFU_RSP,              ///< xband device firmware response
    XBAND_DFU_NOTF,             ///< xband device firmware notification
    XBAND_HEALTH_DATA_REQ,      ///< xband health data request
    XBAND_HEALTH_DATA_RSP,      ///< xband health data response
    XBAND_HEALTH_DATA_NOTF,     ///< xband health data notification
    XBAND_LOG_CFG_REQ,          ///< xband log configuration request
    XBAND_LOG_CFG_STS,          ///< xband log configuration status
    XBAND_TX_CFG_REQ,           ///< xband transmit configuration request
    XBAND_TX_CFG_STS,           ///< xband transmit configuration status
    XBAND_RX_CFG_REQ,           ///< xband receive configuration request
    XBAND_RX_CFG_STS,           ///< xband receive configuration status
    XBAND_SYS_CFG_REQ,
    XBAND_SYS_CFG_STS,
    XBAND_FE_CFG_REQ,           ///< xband feed configuration request
    XBAND_FE_CFG_STS,           ///< xband feed configuration status
    XBAND_CALIB_REQ,            ///< xband calibration request
    XBAND_CALIB_STS,            ///< xband calibration status
    XBAND_FRMWR_UPDT_REQ,       ///< xband framework update request
    XBAND_FRMWR_UPDT_STS,       ///< xband framework update status
    XBAND_TX_REQ,               ///< xband transmit request
    XBAND_TX_STS,               ///< xband transmit status
    XBAND_RX_REQ,               ///< xband receive request
    XBAND_RX_STS,               ///< xband receive status
    XBAND_IDLE_REQ,             ///< xband idle request
    XBAND_IDLE_STS,             ///< xband idle status
    XBAND_TX_RX_REQ,            ///< xband transmit and receive request
    XBAND_TX_RX_STS,            ///< xband transmit and receive status
}e_xband_event;

/**
  * @brief param option in xband
  */
typedef enum
{
    XBAND_FALSE,
    XBAND_TRUE
}e_xband_param_opt_sts;

/**
  * @brief  tx,rx simultaneously run in xband
  */
typedef enum
{
    XBAND_TX_MODE,             ///< mode in xband transmit
    XBAND_RX_MODE,             ///< mode in xband receiving
    XBAND_TX_RX_MODE           ///< mode for both xband transmit and receive
}e_xband_tx_rx_mode;

/**
  * @brief  It selects type of primary and secondary boot mode
  */
typedef enum
{
    XBAND_BOOT_MODE_PRIMARY,       ///< select the primary boot mode
    XBAND_BOOT_MODE_SECONDARY      ///< select the secondary boot mode
}e_xband_boot_mode;

/**
  * @brief  It define the various calibration type
  */
typedef enum
{
    XBAND_TX_CALIB_MODE,     ///< execute tx calibration mode
    XBAND_RX_CALIB_MODE,     ///< execute rx calibration mode
    XBAND_FE_CALIB_MODE,     ///< execute fe calibration mode
    XBAND_CALIB_ALL          ///< calibrate the all mode
}e_xband_calib_type;

/**
  * @brief  Read all telemetry or param telemetry
  */
typedef enum
{
    XBAND_READ_TM_ALL,        ///< xband read telemetry all
    XBAND_READ_TM_PARAM       ///< xband read telemetry parameter
}e_xband_tm_type;

/**
  * @brief  Read DFU trigger all or trigger particular parameter
  */
typedef enum
{
    XBAND_DFU_TRIGGER_ALL,        ///< xband dfu trigger all
    XBAND_DFU_TRIGGER_PARAM      ///< xband dfu trigger param
}e_xband_dfu;

/**
  * @brief  xband reset status enum definition
  */
typedef enum
{
    XBAND_RESET_SUCCESS,
    XBAND_RESET_FAILURE
}e_xband_reset_sts;

/**
  * @brief  xband boot config enum definition
  */
typedef enum
{
    XBAND_BOOT_CFG_SUCCESS,
    XBAND_BOOT_CFG_FAILURE

}e_xband_boot_cfg_sts;

/**
  * @brief  xband tc id enum definition
  */
typedef enum
{
    TC_XBAND_SET_IDLE_CFG = 700,
    TC_XBAND_SET_RESET,
    TC_XBAND_SET_START_RF_RCV,
    TC_XBAND_SET_RF_XMT_DATA,
    TC_XBAND_SET_DVBS2_CONF,
    TC_XBAND_SET_IP_ADR_SAVE,
    TC_XBAND_SET_IP_ADR,
    TC_XBAND_GET_IP_ADR,
    TC_XBAND_GET_FLAGS_CONF,
    TC_XBAND_SET_FLAGS_CONF,
    TC_XBAND_SET_VERSION,
    TC_XBAND_GET_VERSION,
    TC_XBAND_SET_DEVICE_CONF,
    TC_XBAND_GET_DEVICE_CONF,
    TC_XBAND_GET_FEATURE_SELECT,
    TC_XBAND_GET_HOUSE_KEEP,
    TC_XBAND_GET_XPA_INF,
    TC_XBAND_SET_PROD_KEY

}e_xband_tc_id;

/**
  * @brief  xband tm id enum definition
  */
typedef enum
{
    TM_XBAND_SET_IDLE_CFG = 700,
    TM_XBAND_SET_RESET,
    TM_XBAND_SET_START_RF_RCV,
    TM_XBAND_SET_RF_XMT_DATA,
    TM_XBAND_SET_DVBS2_CONF,
    TM_XBAND_SET_IP_ADR_SAVE,
    TM_XBAND_SET_IP_ADR,
    TM_XBAND_GET_IP_ADR,
    TM_XBAND_GET_FLAGS_CONF,
    TM_XBAND_SET_FLAGS_CONF,
    TM_XBAND_SET_VERSION,
    TM_XBAND_GET_VERSION,
    TM_XBAND_SET_DEVICE_CONF,
    TM_XBAND_GET_DEVICE_CONF,
    TM_XBAND_GET_FEATURE_SELECT,
    TM_XBAND_GET_HOUSE_KEEP,
    TM_XBAND_GET_XPA_INF,
    TM_XBAND_SET_PROD_KEY

}e_xband_tm_id;


/**
  * @brief  xband State enum definition
  */
//typedef enum
//{

//}e_xband_error_code;

/**
  * @brief  xband State enum definition
  */
//typedef enum
//{

//}e_xband_reset_type;

/**
  * @brief  xband State enum definition
  */
//typedef enum
//{

//}e_xband_frmwr_req_type;

/**
 * @brief It decides the xband tx config success or failure.
 */
typedef enum
{
    XBAND_TX_CFG_SUCCESS=0,  ///< tx xband config is success
    XBAND_TX_CFG_FAILURE=1    ///< tx xband config is fail
}e_xband_tx_cfg_sts;
/**
 * @brief It decides Rx xband config success or failure.
*/
typedef enum
{
    XBAND_RX_CFG_SUCCESS=0,  ///< rx xband config is success
    XBAND_RX_CFG_FAILURE=1    ///< rx xband config is fail
}e_xband_rx_cfg_sts;
/**
 * @brief It decides system config succeeds or fails.
*/
typedef enum
{
    XBAND_SYS_CFG_SUCCESS=0,   ///< xband  system config is success
    XBAND_SYS_CFG_FAILURE=1     ///< xband system config is fail
}e_xband_sys_cfg_sts;
/**
 * @brief It decides calibration trigger is a success or failure.
*/
typedef enum
{
    XBAND_CALIB_TRGR_SUCCESS=0,   ///< xband calibration trigger is success
    XBAND_CALIB_TRGR_FAILURE=1     ///< xband calibration trigger is fail
}e_xband_calib_trgr_sts;
/**
 * @brief It decides xband tx_rx enable is a success or failure.
*/
typedef enum
{
    XBAND_TX_RX_ENBL_SUCCESS=0,    ///< enable xband tx_rx is success
    XBAND_TX_RX_ENBL_FAILURE=1      ///< enable xband tx_rx is fail
}e_xband_tx_rx_enbl_sts;
/**
 * @brief It decides whether the xband DFU trigger is a success or failure.
*/
typedef enum
{
    XBAND_DFU_TRGR_SUCCESS=0,      ///< xband trigger DFU is success
    XBAND_DFU_TRGR_FAILURE=1        ///< xband trigger DFU is fail
}e_xband_dfu_trgr_sts;
/**
 * @brief It decides whether read telemetry is a success or failure.
*/
typedef enum
{
    XBAND_READ_TM_SUCCESS=0,     ///< xband read telemetry is success
    XBAND_READ_TM_FAILURE=1       ///< xband read telemetry is fail
}e_xband_read_tm_sts;

/**
 * @brief It decides whether read telemetry is a success or failure.
*/
typedef enum
{
    XBAND_TM_SUCCESS=0,     ///< xband read telemetry is success
    XBAND_TM_FAILURE=1,       ///< xband read telemetry is fail
    XBAND_TM_BUSY=2       ///< xband read telemetry is fail
}e_xband_tm_sts;

/// xband operation status
typedef enum
{
    XBAND_RESET_DONE,
    XBAND_RESET_FAIL,
    XBAND_BYPASS_RQST,
    XBAND_BOOT_DONE,
    XBAND_BOOT_FAIL,
    XBAND_DFU_DONE,
    XBAND_DFU_FAIL,
    XBAND_LOG_CFG_DONE,
    XBAND_LOG_CFG_FAIL,
    XBAND_TX_CFG_DONE,
    XBAND_TX_CFG_FAIL,
    XBAND_RX_CFG_DONE,
    XBAND_RX_CFG_FAIL,
    XBAND_FE_CFG_DONE,
    XBAND_FE_CFG_FAIL,
    XBAND_CALIB_DONE,
    XBAND_CALIB_FAIL,
    XBAND_SLEEP_DONE,
    XBAND_SLEEP_FAIL,
    XBAND_TX_DONE,
    XBAND_TX_FAIL,
    XBAND_RX_DONE,
    XBAND_RX_FAIL,
    XBAND_TX_RX_DONE,
    XBAND_TX_RX_FAIL,
    XBAND_IDLE_DONE,
    XBAND_IDLE_FAIL
}e_xband_et;

/**
* @brief This function create the COMMS state and event threads
*
* @return status of thread
*/
int32_t xband_init(void);
/**
* @brief This function step-by-step process the COMMS states to the help
*  of event thread request
*
* @param param : unused pointer
*/
void xband_main(void *param);


/**
* @brief This function deletes the XBAND queue and release its memory
*
* @return status of os thread suspend
*/
os_status_t xband_suspend(void);
/**
* @brief This functionalities resumes the XBAND thread
*
* @return status of os thread suspend
*/
os_status_t xband_resume(void);
/**
* @brief This API handle the comms xband finite states machine
*
* @param state   : current state
* @param msg_id  : Identity of state
* @param payload : pointer to payload
*
* @return state
*/
uint8_t xband_fsm_hdlr_fn(uint8_t state,uint16_t msg_id, void *payload);

/**
* @brief This function handle xband initialization state
*
* @param msg_id  : Identity of state
* @param payload : Pointer to payload
*
* @return state of xband
*/
uint8_t xband_init_state_hdlr(uint16_t msg_id, void *payload);
/**
* @brief This function handle the xband boot state
*
* @param msg_id  : Identity of state
* @param payload : Pointer to payload
*
* @return state of xband
*/
uint8_t xband_boot_state_hdlr(uint16_t msg_id, void *payload);
/**
* @brief This function handles xband DFU states
*
* @param msg_id  : Identity of state
* @param payload : Pointer to payload
*
* @return state of xband
*/
uint8_t xband_dfu_state_hdlr(uint16_t msg_id, void *payload);
/**
* @brief This function handle xband configuration states
*
* @param msg_id  : Identity of state
* @param payload : Pointer to payload
*
* @return state of xband
*/
uint8_t xband_cfg_state_hdlr(uint16_t msg_id, void *payload);
/**
* @brief This function handle xband calibration state
*
* @param msg_id  : Identity of state
* @param payload : Pointer to payload
*
* @return state of xband
*/
uint8_t xband_calib_state_hdlr(uint16_t msg_id, void *payload);
/**
* @brief This API handle the xband idle state
*
* @param msg_id  : Identity of state
* @param payload : Pointer to payload
*
* @return state of xband
*/
uint8_t xband_sleep_idle_state_hdlr(uint16_t msg_id, void *payload);
/**
* @brief This API handle the xband active states
*
* @param msg_id  : Identity of state
* @param payload : Pointer to payload
*
* @return state of xband
*/
uint8_t xband_active_state_hdlr(uint16_t msg_id, void *payload);
/**
* @brief This functions handle the xband safe mode state
*
* @param msg_id  : Identity of state
* @param payload : Pointer to payload
*
* @return state of xband
*/
uint8_t xband_safe_mode_state_hdlr(uint16_t msg_id, void *payload);
/**
* @brief This function handle the xband error state
*
* @param msg_id  : Identity of state
* @param payload : Pointer to payload
*
* @return state of xband
*/
uint8_t xband_error_state_hdlr(uint16_t msg_id, void *payload);
/**
* @brief This function handling Bypass the xband states
*
* @param msg_id  : Identity of state
* @param payload : Pointer to payload
*
* @return state of xband
*/
uint8_t xband_bypass_state_hdlr(uint16_t msg_id, void *payload);

/**
* @brief This function Initialize the xband configuration
*/
void comms_init_xband_cfg(void);

#ifdef __cplusplus
}
#endif
#endif /*XBAND_MAIN_H */
