/*
 * 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 _PARK_H_
#define _PARK_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 PARK object
 */
typedef struct _ParkType_
{
    _iq alpha; /*!< Input: stationary d-axis stator variable */
    _iq beta;  /*!< Input: stationary q-axis stator variable */
    _iq sinTh; /*!< Input: sin value of rotating angle (pu) */
    _iq cosTh; /*!< Input: cos value of rotating angle (pu) */

    _iq Ds;    /*!< Output: rotating d-axis stator variable */
    _iq Qs;    /*!< Output: rotating q-axis stator variable */
} ParkType;

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

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

/*! \brief The main process function of Park
 *
 * This function runs Park function to calculate rotating axis variable
 *
 * \param[in] obj : pointer to Park instance
 */
static inline void Park_Run(ParkType *obj)
{
    obj->Ds = _IQmpy(obj->alpha, obj->cosTh) + _IQmpy(obj->beta, obj->sinTh);
    obj->Qs = _IQmpy(obj->beta, obj->cosTh) - _IQmpy(obj->alpha, obj->sinTh);
}

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

#endif /* _PARK_H_ */
