/*
 * Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
 * All rights reserved.
 *
 * Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
 * exclusively with CVA's microcontroller products. This file can be freely
 * distributed within development tools that are supporting such microcontroller
 * products.
 *
 * THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED
 * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
 * CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
 * OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
 */

#ifndef _IPARK_H_
#define _IPARK_H_

/*! \brief  Contains the public interface to the
 *          Park transform module routines
 */

/*******************************************************************************
 * the includes
 ******************************************************************************/

#include "common/iqmath/iqmath.h"

#ifdef __cplusplus
extern "C" {
#endif

/*******************************************************************************
 * the defines
 ******************************************************************************/

/*******************************************************************************
 * the typedefs
 ******************************************************************************/

/*! \brief Defines the IPARK object
 *
 */
typedef struct _IparkType_
{
    _iq sinTh; /*!< Input: sin value of rotating angle (pu) */
    _iq cosTh; /*!< Input: cos value of rotating angle (pu) */
    _iq Ds;    /*!< Input: rotating d-axis stator variable */
    _iq Qs;    /*!< Input: rotating q-axis stator variable */

    _iq alpha; /*!< Output: stationary alpha-axis stator variable */
    _iq beta;  /*!< Output: stationary beta-axis stator variable */
} IparkType;

/*******************************************************************************
 * the globals
 ******************************************************************************/

/*******************************************************************************
 * the function prototypes
 ******************************************************************************/

/*! \brief Process the IPARK algorithm
 *
 * This function runs IPARK function to calculate stationary axis variable
 *
 * \param[in] obj : pointer to Ipark instance
 */
static inline void IPark_Run(IparkType *obj)
{
    obj->alpha = _IQmpy(obj->Ds, obj->cosTh) - _IQmpy(obj->Qs, obj->sinTh);
    obj->beta  = _IQmpy(obj->Qs, obj->cosTh) + _IQmpy(obj->Ds, obj->sinTh);
}

#ifdef __cplusplus
}
#endif /* extern "C" */

#endif /* _IPARK_H_ */
