/* Copyright Statement:
 *
 * This software/firmware and related documentation ("AutoChips Software") are
 * protected under relevant copyright laws. The information contained herein is
 * confidential and proprietary to AutoChips Inc. and/or its licensors. Without
 * the prior written permission of AutoChips inc. and/or its licensors, any
 * reproduction, modification, use or disclosure of AutoChips Software, and
 * information contained herein, in whole or in part, shall be strictly
 * prohibited.
 *
 * AutoChips Inc. (C) 2022. All rights reserved.
 *
 * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
 * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("AUTOCHIPS SOFTWARE")
 * RECEIVED FROM AUTOCHIPS AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
 * ON AN "AS-IS" BASIS ONLY. AUTOCHIPS EXPRESSLY DISCLAIMS ANY AND ALL
 * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
 * NONINFRINGEMENT. NEITHER DOES AUTOCHIPS PROVIDE ANY WARRANTY WHATSOEVER WITH
 * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
 * INCORPORATED IN, OR SUPPLIED WITH THE AUTOCHIPS SOFTWARE, AND RECEIVER AGREES
 * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
 * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
 * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN AUTOCHIPS
 * SOFTWARE. AUTOCHIPS SHALL ALSO NOT BE RESPONSIBLE FOR ANY AUTOCHIPS SOFTWARE
 * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
 * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND AUTOCHIPS'S
 * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE AUTOCHIPS SOFTWARE
 * RELEASED HEREUNDER WILL BE, AT AUTOCHIPS'S OPTION, TO REVISE OR REPLACE THE
 * AUTOCHIPS SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
 * CHARGE PAID BY RECEIVER TO AUTOCHIPS FOR SUCH AUTOCHIPS SOFTWARE AT ISSUE.
 */

#ifndef _AC780x_CTU_REG_H
#define _AC780x_CTU_REG_H
/*!
 * @file ac780x_ctu_reg.h
 *
 * @brief module-to-module interconnections module access register inline function definition.
 *
 */
#ifdef __cplusplus
extern "C" {
#endif

/* ===========================================  Includes  =========================================== */
#include "ac780x_ctu.h"

/* ============================================  Define  ============================================ */

/* ===========================================  Typedef  ============================================ */

/* ==========================================  Variables  =========================================== */

/* ====================================  Functions declaration  ===================================== */

/* ======================================  Functions define  ======================================== */
/*!
* @brief Set real-time counter(RTC) overflow to be captured by PWM1 channel 1.
*
* @param[in] state: enabling state
*               - ENABLE: RTC overflow is connected to PWM1 channel 1
*               - DISABLE: RTC overflow is not connected to PWM1 channel 1
* @return none
*/
__STATIC_INLINE void CTU_SetRtcCaptureByPwm1Ch1(ACTION_Type state)
{
    MODIFY_REG32(CTU->CONFIG0, CTU_CONFIG0_RTCC_Msk, CTU_CONFIG0_RTCC_Pos, state);
}

/*!
* @brief Set connects the output of ACMP0 to PWM2 channel 0.
*
* @param[in] state: enabling state
*               - ENABLE: ACMP0 output is connected to PWM2 channel 0
*               - DISABLE: ACMP0 output is not connected to PWM2 channel 0
* @return none
*/
__STATIC_INLINE void CTU_SetAcmpOutputCaptureByPwm2Ch0(ACTION_Type state)
{
    MODIFY_REG32(CTU->CONFIG0, CTU_CONFIG0_PWM2ACIC_Msk, CTU_CONFIG0_PWM2ACIC_Pos, state);
}

/*!
* @brief Set connects the output of ACMP0 to PWM1 channel 0.
*
* @param[in] state: enabling state
*               - ENABLE: ACMP0 output is connected to PWM1 channel 0
*               - DISABLE: ACMP0 output is not connected to PWM1 channel 0
* @return none
*/
__STATIC_INLINE void CTU_SetAcmpOutputCaptureByPwm1Ch0(ACTION_Type state)
{
    MODIFY_REG32(CTU->CONFIG0, CTU_CONFIG0_PWM1ACIC_Msk, CTU_CONFIG0_PWM1ACIC_Pos, state);
}

/*!
* @brief Set connects the output of ACMP0 to PWM0 channel 0.
*
* @param[in] state: enabling state
*               - ENABLE: ACMP0 output is connected to PWM0 channel 0
*               - DISABLE: ACMP0 output is not connected to PWM0 channel 0
* @return none
*/
__STATIC_INLINE void CTU_SetAcmpOutputCaptureByPwm0Ch0(ACTION_Type state)
{
    MODIFY_REG32(CTU->CONFIG0, CTU_CONFIG0_PWM0ACIC_Msk, CTU_CONFIG0_PWM0ACIC_Pos, state);
}

/*!
* @brief Set generates PWM synchronization trigger to the PWM module.
*
* @param[in] state: enabling state
*               - ENABLE: generates PWM synchronization trigger
*               - DISABLE: no synchronization triggered
* @return none
*/
__STATIC_INLINE void CTU_SetSoftwareTriggerPwmSync(ACTION_Type state)
{
    MODIFY_REG32(CTU->CONFIG0, CTU_CONFIG0_PWMSYNC_Msk, CTU_CONFIG0_PWMSYNC_Pos, state);
}

/*!
* @brief Set clock prescaler.
*
* @param[in] psc: prescaler divide
*               - CTU_CLK_PRESCALER_1
*               - CTU_CLK_PRESCALER_2
*               - CTU_CLK_PRESCALER_4
*               - CTU_CLK_PRESCALER_8
*               - CTU_CLK_PRESCALER_16
*               - CTU_CLK_PRESCALER_32
*               - CTU_CLK_PRESCALER_64
*               - CTU_CLK_PRESCALER_128
* @return none
*/
__STATIC_INLINE void CTU_SetClockPrescaler(CTU_ClkPrescalerType psc)
{
    MODIFY_REG32(CTU->CONFIG0, CTU_CONFIG0_PSC_Msk, CTU_CONFIG0_PSC_Pos, psc);
}

/*!
* @brief Set adc regular group trigger source.
*
* @param[in] source: trigger source
*               - CTU_TRIGGER_ADC_RTC_OVERFLOW
*               - CTU_TRIGGER_ADC_PWM0_INIT
*               - CTU_TRIGGER_ADC_PWM0_MATCH
*               - CTU_TRIGGER_ADC_PWM2_INIT
*               - CTU_TRIGGER_ADC_PWM2_MATCH
*               - CTU_TRIGGER_ADC_TIMER_CH0_OVERFLOW
*               - CTU_TRIGGER_ADC_TIMER_CH1_OVERFLOW
*               - CTU_TRIGGER_ADC_ACMP0_OUTPUT
* @return none
*/
__STATIC_INLINE void CTU_SetAdcRegularTriggerSource(CTU_AdcTriggerSourceType source)
{
    MODIFY_REG32(CTU->CONFIG0, CTU_CONFIG0_ADHWT0_Msk, CTU_CONFIG0_ADHWT0_Pos, source);
}

/*!
* @brief Get delay unit 0 active flag.
*
* delay unit 0 use for pwm trigger adc regular delay time
*
* @param[in] none
* @return none
*/
__STATIC_INLINE uint32_t CTU_GetDelay0ActiveFlag(void)
{
    return READ_BIT32(CTU->CONFIG0, CTU_CONFIG0_DLYACT0_Msk);
}

/*!
* @brief Set delay unit 0 time.
*
* delay unit 0 use for pwm trigger adc regular group delay time
*
* @param[in] delay: delay time
*               - 0 ~ 255
* @return none
*/
__STATIC_INLINE void CTU_SetDelay0Time(uint8_t delay)
{
    MODIFY_REG32(CTU->CONFIG0, CTU_CONFIG0_DELAY0_Msk, CTU_CONFIG0_DELAY0_Pos, delay);
}

/*!
* @brief Set adc injected group trigger source.
*
* @param[in] source: trigger source
*               - CTU_TRIGGER_ADC_RTC_OVERFLOW
*               - CTU_TRIGGER_ADC_PWM0_INIT
*               - CTU_TRIGGER_ADC_PWM0_MATCH
*               - CTU_TRIGGER_ADC_PWM1_INIT
*               - CTU_TRIGGER_ADC_PWM1_MATCH
*               - CTU_TRIGGER_ADC_TIMER_CH0_OVERFLOW
*               - CTU_TRIGGER_ADC_TIMER_CH1_OVERFLOW
*               - CTU_TRIGGER_ADC_ACMP0_OUTPUT
* @return none
*/
__STATIC_INLINE void CTU_SetAdcInjectTriggerSource(CTU_AdcTriggerSourceType source)
{
    MODIFY_REG32(CTU->CONFIG1, CTU_CONFIG1_ADHWT1_Msk, CTU_CONFIG1_ADHWT1_Pos, source);
}

/*!
* @brief Get delay unit 1 active flag.
*
* delay unit 1 use for pwm trigger adc regular delay time
*
* @param[in] none
* @return none
*/
__STATIC_INLINE uint32_t CTU_GetDelay1ActiveFlag(void)
{
    return READ_BIT32(CTU->CONFIG1, CTU_CONFIG1_DLYACT1_Msk);
}

/*!
* @brief Set delay unit 1 time.
*
* delay unit 1 use for pwm trigger adc injected group delay time
*
* @param[in] delay: delay time
*               - 0 ~ 255
* @return none
*/
__STATIC_INLINE void CTU_SetDelay1Time(uint8_t delay)
{
    MODIFY_REG32(CTU->CONFIG1, CTU_CONFIG1_DELAY1_Msk, CTU_CONFIG1_DELAY1_Pos, delay);
}

#ifdef __cplusplus
}
#endif

#endif /* _AC780x_CTU_REG_H */

/* =============================================  EOF  ============================================== */
