//#############################################################################
// $Copyright:
// Copyright (C) 2017-2023 Texas Instruments Incorporated - http://www.ti.com/
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
//   Redistributions of source code must retain the above copyright
//   notice, this list of conditions and the following disclaimer.
//
//   Redistributions in binary form 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.
//
//   Neither the name of Texas Instruments Incorporated nor the names of
//   its contributors may be used to endorse or promote products derived
//   from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER 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.
// $
//#############################################################################


//! \file   solutions/tidm_02010_dmpfc/common/include/hal_data.h
//! \brief  hardware abstraction layer (HAL) library
//!         This file is shared with all of device
//!

#ifndef HAL_DATA_H
#define HAL_DATA_H

//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif // extern "C"

//*****************************************************************************
//
//! \defgroup HAL_DATA HAL_DATA
//! @{
//
//*****************************************************************************

#include "libraries/math/include/math.h"

//*****************************************************************************
//
//! \brief Defines the ADC data
//
//*****************************************************************************
typedef struct _HAL_ADCData_t_
{
    MATH_Vec3 I_A;              //!< the phase current values
    MATH_Vec3 V_V;              //!< the voltage values

#if defined(MOTOR1_DCLINKSS) || defined(MOTOR2_DCLINKSS)
    MATH_Vec2 Idc1_A;           //!< the dc-link current up values
    MATH_Vec2 Idc2_A;           //!< the dc-link current down values
    float32_t offset_Idc_A;     //!< the motor current offset value
#endif  // MOTOR1_DCLINKSS || MOTOR2_DCLINKSS\

#if !defined(MOTOR1_DCLINKSS) || !defined(MOTOR2_DCLINKSS) // just for saving RAM
    float32_t offset_I_A[3];    //!< the motor current offset value
#endif  // MOTOR1_DCLINKSS & MOTOR2_DCLINKSS
    float32_t offset_V_sf[3];   //!< the motor voltage offset factor

    float32_t current_sf;       //!< the current scale factor, amps/cnt
    float32_t voltage_sf;       //!< the phase voltage scale factor, volts/cnt
} HAL_ADCData_t;

typedef struct _HAL_PFC_ADCData_t_
{
    float32_t IacBus;           //!< the acBus value
    float32_t VdcBus;           //!< the dcBus value
    float32_t VacBus;           //!< the acBus value

    float32_t offset_Iac;       //!< the PFC AC current offset
    float32_t offset_Vac;       //!< the PFC AC voltage offset

    float32_t currentAC_sf;     //!< the current scale factor, amps/cnt
    float32_t voltageAC_sf;     //!< the AC bus voltage scale factor, volts/cnt
    float32_t voltageDC_sf;     //!< the DC bus voltage scale factor, volts/cnt

#if defined(DMCPFC_REV3P2) || defined(DMCPFC_REV3P1)      // HVAC Rev3 Reference design boards
    float32_t VacSen;           //!< the acBus value
#elif defined(HVMTRPFC_REV1P1)
    float32_t ValBus;           //!< the acBus L line value
    float32_t VanBus;           //!< the acBus N line value
    float32_t offset_Van;       //!< the PFC ACN voltage offset
#else
    float32_t VacSen;           //!< the acBus value
#endif // HVAC Reference design boards

} HAL_PFC_ADCData_t;

//*****************************************************************************
//
//! \brief Defines the PWM data
//
//*****************************************************************************
typedef struct _HAL_PWMData_t_
{
    MATH_Vec3 Vabc_pu;     //!< the PWM time-durations for each motor phase
    float32_t period;

    uint16_t  cmpValue[3];
    uint16_t  deadband;
    uint16_t  noiseWindow;
    uint16_t  minCMPValue;
    uint16_t  socCMP;
    bool      flagEnablePwm;
} HAL_PWMData_t;

typedef struct _HAL_PFC_PWMData_t_
{
    float32_t dutyValue;     //!< the PWM time-durations for positive period
    float32_t period;

    uint16_t  cmpValue;
    bool      flagEnablePwm;
} HAL_PFC_PWMData_t;

//*****************************************************************************
//
//! \brief Defines the DAC data
//
//*****************************************************************************
typedef struct _HAL_BuffDACData_t_
{
    float32_t *ptrData[2];        //!< Input: First input pointer

    float32_t offset[2];          //!< the DAC data
    float32_t gain[2];            //!< the DAC data
} HAL_BuffDACData_t;


typedef struct _HAL_PwmDacData_t_
{
    volatile float32_t *ptrData[4];     //!< Input: First input pointer

    float32_t offset[4];                //!< the DAC data
    float32_t gain[4];                  //!< the DAC data

    uint16_t periodMax;
} HAL_PWMDACData_t;

//*****************************************************************************
//
// Close the Doxygen group.
//! @}
//
//*****************************************************************************

//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif // extern "C"

#endif // HAL_DATA_H
