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

/*! \brief  Contains public interface to various functions related
 *          to the Field Weakening (FW) object
 */

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

#include <stdint.h>
#include "common/iqmath/iqmath.h"

#ifdef __cplusplus
extern "C" {
#endif

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

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

typedef struct _FwType_
{
    _iq refValue;   /*!< Input: The reference value */
    _iq fbackValue; /*!< Input: The feedback value */

    _iq outMax;     /*!< Parameter: Maximum output */
    _iq outMin;     /*!< Parameter: Minimum output */
    _iq deltaInc;   /*!< Parameter: The field weakening delta increment of Id reference */
    _iq deltaDec;   /*!< Parameter: The field weakening delta decrement of Id reference */

    _iq output;     /*!< Output: The output of field weakening */
} FwType;

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

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

/*! \brief Initialize the Fw object
 *
 * This function initalizes Fw by setting configuration parameters
 *
 * \param[in] obj : pointer to Fw instance
 * \param[in] maxNegIdRef : max -id reference value
 */
extern void Fw_Init(FwType *obj, _iq maxNegIdRef);

/*! \brief Run the field weakening control
 *
 * This function runs Fw function, perform motor control functions
 *
 * \param[in] obj : pointer to Fw instance
 */
extern void Fw_Run(FwType *obj);

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

#endif /* _FW_H_ */
