/*
 * 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 _CLARKE_H_
#define _CLARKE_H_

/*! \brief Contains public interface to various functions related
 *         to the clarke modules
 */

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

#include "common/iqmath/iqmath.h"

#ifdef __cplusplus
extern "C" {
#endif

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

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

/*! \brief Clarke prototype definition
 */
typedef struct _ClarkeType_
{
    _iq As;    /*!< phase A component */
    _iq Bs;    /*!< phase B component */
    _iq Cs;    /*!< phase C component */
    _iq alpha; /*!< the alpha component */
    _iq beta;  /*!< the beta component */
} ClarkeType;

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

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

/*! \brief Runs the clarke function
 *
 * This function runs clarke function, calculates clarke transforms value
 *
 * \param[in] obj : pointer to Clarke instance
 */
static inline void Clarke_Run(ClarkeType *obj)
{
    obj->alpha = _IQmpy(_IQmpy2(obj->As) - (obj->Bs + obj->Cs), IQMATH_ONE_OVER_THREE);
    obj->beta  = _IQmpy((obj->Bs - obj->Cs), IQMATH_ONE_OVER_SQRT_THREE);
}

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

#endif /* _CLARKE_H_ */
