/*!
 * @file        g32a10xx_int.c
 *
 * @brief       Main Interrupt Service Routines
 *
 * @version     V1.0.0
 *
 * @date        2026-02-25
 *
 * @attention
 *
 *  Copyright (C) 2026 Geehy Semiconductor
 *
 *  You may not use this file except in compliance with the
 *  GEEHY COPYRIGHT NOTICE (Geehy Semiconductor Software License Agreement).
 *
 *  The program is only for reference, which is distributed in the hope
 *  that it will be useful and instructional for customers to develop
 *  their software. Unless required by applicable law or agreed to in
 *  writing, the program is distributed on an "AS IS" BASIS, WITHOUT
 *  ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the Geehy Semiconductor Software License Agreement for the governing permissions
 *  and limitations under the License.
 */

/* Includes */
#include "g32a10xx_int.h"
#include "user_tmr_config.h"
#include "stdio.h"

/** @addtogroup Examples
  @{
*/

/** @addtogroup TMR_Examples
@{
*/

/** @addtogroup TMR_EncoderInterface
  @{
*/

/** @defgroup TMR_EncoderInterface_INT_Variables INT_Variables
  @{
*/



/**@} end of group TMR_EncoderInterface_INT_Variables */

/** @defgroup TMR_EncoderInterface_INT_Functions INT_Functions
  @{
*/



/*!
 * @brief        This function handles Hard Fault exception
 *
 * @param        None
 *
 * @retval       None
 *
 * @note
 */
void HardFault_Handler(void)
{
}

/*!
 * @brief        This function handles SVCall exception
 *
 * @param        None
 *
 * @retval       None
 *
 * @note
 */
void SVC_Handler(void)
{
}

/*!
 * @brief        This function handles PendSV_Handler exception
 *
 * @param        None
 *
 * @retval       None
 *
 * @note
 */
void PendSV_Handler(void)
{
}

/*!
 * @brief        This function handles SysTick Handler
 *
 * @param        None
 *
 * @retval       None
 *
 * @note
 */
void SysTick_Handler(void)
{
}

/*!
 * @brief   This function handles TMR1 Update Handler
 *
 * @param   None
 *
 * @retval  None
 *
 */
void TMR1_BRK_UP_TRG_COM_IRQHandler(void)
{
    /* The interrupt flag bit must be cleared first. */
    Tmr_ClearIntFlag(TMR1, (uint16_t)TMR_INT_FLAG_UPDATE);
    if ((TMR1->CTRL1_R.CTRL1_B.CNTDIR) != 0u)
    {
        g_encoderNum--;
    }
    else
    {
        g_encoderNum++;
    }
    printf("g_encoderNum: %08x\r\n", g_encoderNum);
    Tmr_SetCounter(TMR1, 0x0004);
}

/*!
 * @brief   This function handles TMR2 Handler
 *
 * @param   None
 *
 * @retval  None
 *
 */
void TMR3_IRQHandler(void)
{
    if (Tmr_ReadIntFlag(TMR3, TMR_INT_FLAG_UPDATE) == (uint16_t)SET)
    {
        /* The interrupt flag bit must be cleared first. */
        Tmr_ClearIntFlag(TMR3, (uint16_t)TMR_INT_FLAG_UPDATE);
        g_tick = g_tick + (uint32_t)1;
    }
    else
    {
        /* nothing */
    }
}

/**@} end of group TMR_EncoderInterface_INT_Functions */
/**@} end of group TMR_EncoderInterface */
/**@} end of group TMR_Examples */
/**@} end of group Examples */
