259 lines
13 KiB
C
259 lines
13 KiB
C
/***********************************************************************************************************************
|
|
* DISCLAIMER
|
|
* This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products.
|
|
* No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all
|
|
* applicable laws, including copyright laws.
|
|
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED
|
|
* OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
* NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY
|
|
* LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT,
|
|
* INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR
|
|
* ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
|
* Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability
|
|
* of this software. By using this software, you agree to the additional terms and conditions found by accessing the
|
|
* following link:
|
|
* http://www.renesas.com/disclaimer
|
|
*
|
|
* Copyright (C) 2011, 2021 Renesas Electronics Corporation. All rights reserved.
|
|
***********************************************************************************************************************/
|
|
|
|
/***********************************************************************************************************************
|
|
* File Name : r_cg_timer.c
|
|
* Version : CodeGenerator for RL78/G12 V2.04.06.02 [08 Nov 2021]
|
|
* Device(s) : R5F103AA
|
|
* Tool-Chain : CCRL
|
|
* Description : This file implements device driver for TAU module.
|
|
* Creation Date: 2024/7/13
|
|
***********************************************************************************************************************/
|
|
|
|
/***********************************************************************************************************************
|
|
Includes
|
|
***********************************************************************************************************************/
|
|
#include "r_cg_macrodriver.h"
|
|
#include "r_cg_timer.h"
|
|
/* Start user code for include. Do not edit comment generated here */
|
|
/* End user code. Do not edit comment generated here */
|
|
#include "r_cg_userdefine.h"
|
|
|
|
/***********************************************************************************************************************
|
|
Pragma directive
|
|
***********************************************************************************************************************/
|
|
/* Start user code for pragma. Do not edit comment generated here */
|
|
/* End user code. Do not edit comment generated here */
|
|
|
|
/***********************************************************************************************************************
|
|
Global variables and functions
|
|
***********************************************************************************************************************/
|
|
/* Start user code for global. Do not edit comment generated here */
|
|
/* End user code. Do not edit comment generated here */
|
|
|
|
/***********************************************************************************************************************
|
|
* Function Name: R_TAU0_Create
|
|
* Description : This function initializes the TAU0 module.
|
|
* Arguments : None
|
|
* Return Value : None
|
|
***********************************************************************************************************************/
|
|
void R_TAU0_Create(void)
|
|
{
|
|
TAU0EN = 1U; /* supplies input clock */
|
|
TPS0 = _0000_TAU_CKM0_FCLK_0 | _0000_TAU_CKM1_FCLK_0 | _0000_TAU_CKM2_FCLK_1 | _0000_TAU_CKM3_FCLK_8;
|
|
/* Stop all channels */
|
|
TT0 = _0001_TAU_CH0_STOP_TRG_ON | _0002_TAU_CH1_STOP_TRG_ON | _0004_TAU_CH2_STOP_TRG_ON |
|
|
_0008_TAU_CH3_STOP_TRG_ON | _0010_TAU_CH4_STOP_TRG_ON | _0020_TAU_CH5_STOP_TRG_ON |
|
|
_0040_TAU_CH6_STOP_TRG_ON | _0080_TAU_CH7_STOP_TRG_ON | _0200_TAU_CH1_H8_STOP_TRG_ON |
|
|
_0800_TAU_CH3_H8_STOP_TRG_ON;
|
|
/* Mask channel 0 interrupt */
|
|
TMMK00 = 1U; /* disable INTTM00 interrupt */
|
|
TMIF00 = 0U; /* clear INTTM00 interrupt flag */
|
|
/* Mask channel 1 interrupt */
|
|
TMMK01 = 1U; /* disable INTTM01 interrupt */
|
|
TMIF01 = 0U; /* clear INTTM01 interrupt flag */
|
|
/* Mask channel 1 higher 8 bits interrupt */
|
|
TMMK01H = 1U; /* disable INTTM01H interrupt */
|
|
TMIF01H = 0U; /* clear INTTM01H interrupt flag */
|
|
/* Mask channel 2 interrupt */
|
|
TMMK02 = 1U; /* disable INTTM02 interrupt */
|
|
TMIF02 = 0U; /* clear INTTM02 interrupt flag */
|
|
/* Mask channel 3 interrupt */
|
|
TMMK03 = 1U; /* disable INTTM03 interrupt */
|
|
TMIF03 = 0U; /* clear INTTM03 interrupt flag */
|
|
/* Mask channel 3 higher 8 bits interrupt */
|
|
TMMK03H = 1U; /* disable INTTM03H interrupt */
|
|
TMIF03H = 0U; /* clear INTTM03H interrupt flag */
|
|
/* Mask channel 4 interrupt */
|
|
TMMK04 = 1U; /* disable INTTM04 interrupt */
|
|
TMIF04 = 0U; /* clear INTTM04 interrupt flag */
|
|
/* Mask channel 5 interrupt */
|
|
TMMK05 = 1U; /* disable INTTM05 interrupt */
|
|
TMIF05 = 0U; /* clear INTTM05 interrupt flag */
|
|
/* Mask channel 6 interrupt */
|
|
TMMK06 = 1U; /* disable INTTM06 interrupt */
|
|
TMIF06 = 0U; /* clear INTTM06 interrupt flag */
|
|
/* Mask channel 7 interrupt */
|
|
TMMK07 = 1U; /* disable INTTM07 interrupt */
|
|
TMIF07 = 0U; /* clear INTTM07 interrupt flag */
|
|
/* Set INTTM00 low priority */
|
|
TMPR100 = 1U;
|
|
TMPR000 = 1U;
|
|
/* Set INTTM01 low priority */
|
|
TMPR101 = 1U;
|
|
TMPR001 = 1U;
|
|
/* Channel 0 used as interval timer */
|
|
TMR00 = _0000_TAU_CLOCK_SELECT_CKM0 | _0000_TAU_CLOCK_MODE_CKS | _0000_TAU_COMBINATION_SLAVE |
|
|
_0000_TAU_TRIGGER_SOFTWARE | _0000_TAU_MODE_INTERVAL_TIMER | _0000_TAU_START_INT_UNUSED;
|
|
TDR00 = _5DBF_TAU_TDR00_VALUE;
|
|
TO0 &= ~_0001_TAU_CH0_OUTPUT_VALUE_1;
|
|
TOE0 &= ~_0001_TAU_CH0_OUTPUT_ENABLE;
|
|
/* Channel 1 used as interval timer */
|
|
TMR01 = _0000_TAU_CLOCK_SELECT_CKM0 | _0000_TAU_CLOCK_MODE_CKS | _0000_TAU_16BITS_MODE |
|
|
_0000_TAU_TRIGGER_SOFTWARE | _0000_TAU_MODE_INTERVAL_TIMER | _0000_TAU_START_INT_UNUSED;
|
|
TDR01 = _5DBF_TAU_TDR01_VALUE;
|
|
TOM0 &= ~_0002_TAU_CH1_OUTPUT_COMBIN;
|
|
TOL0 &= ~_0002_TAU_CH1_OUTPUT_LEVEL_L;
|
|
TO0 &= ~_0002_TAU_CH1_OUTPUT_VALUE_1;
|
|
TOE0 &= ~_0002_TAU_CH1_OUTPUT_ENABLE;
|
|
/* Channel 4 is used as master channel for PWM output function */
|
|
TMR04 = _0000_TAU_CLOCK_SELECT_CKM0 | _0000_TAU_CLOCK_MODE_CKS | _0800_TAU_COMBINATION_MASTER |
|
|
_0000_TAU_TRIGGER_SOFTWARE | _0001_TAU_MODE_PWM_MASTER;
|
|
TDR04 = _5DBF_TAU_TDR04_VALUE;
|
|
TOM0 &= ~_0010_TAU_CH4_OUTPUT_COMBIN;
|
|
TOL0 &= ~_0010_TAU_CH4_OUTPUT_LEVEL_L;
|
|
TO0 &= ~_0010_TAU_CH4_OUTPUT_VALUE_1;
|
|
TOE0 &= ~_0010_TAU_CH4_OUTPUT_ENABLE;
|
|
/* Channel 5 is used as slave channel for PWM output function */
|
|
TMR05 = _0000_TAU_CLOCK_SELECT_CKM0 | _0000_TAU_CLOCK_MODE_CKS | _0000_TAU_COMBINATION_SLAVE |
|
|
_0400_TAU_TRIGGER_MASTER_INT | _0009_TAU_MODE_PWM_SLAVE;
|
|
TDR05 = _2EE0_TAU_TDR05_VALUE;
|
|
TOM0 |= _0020_TAU_CH5_OUTPUT_COMBIN;
|
|
TOL0 &= ~_0020_TAU_CH5_OUTPUT_LEVEL_L;
|
|
TO0 &= ~_0020_TAU_CH5_OUTPUT_VALUE_1;
|
|
TOE0 |= _0020_TAU_CH5_OUTPUT_ENABLE;
|
|
/* Channel 6 is used as master channel for PWM output function */
|
|
TMR06 = _0000_TAU_CLOCK_SELECT_CKM0 | _0000_TAU_CLOCK_MODE_CKS | _0800_TAU_COMBINATION_MASTER |
|
|
_0000_TAU_TRIGGER_SOFTWARE | _0001_TAU_MODE_PWM_MASTER;
|
|
TDR06 = _095F_TAU_TDR06_VALUE;
|
|
TOM0 &= ~_0040_TAU_CH6_OUTPUT_COMBIN;
|
|
TOL0 &= ~_0040_TAU_CH6_OUTPUT_LEVEL_L;
|
|
TO0 &= ~_0040_TAU_CH6_OUTPUT_VALUE_1;
|
|
TOE0 &= ~_0040_TAU_CH6_OUTPUT_ENABLE;
|
|
/* Channel 7 is used as slave channel for PWM output function */
|
|
TMR07 = _0000_TAU_CLOCK_SELECT_CKM0 | _0000_TAU_CLOCK_MODE_CKS | _0000_TAU_COMBINATION_SLAVE |
|
|
_0400_TAU_TRIGGER_MASTER_INT | _0009_TAU_MODE_PWM_SLAVE;
|
|
TDR07 = _04B0_TAU_TDR07_VALUE;
|
|
TOM0 |= _0080_TAU_CH7_OUTPUT_COMBIN;
|
|
TOL0 &= ~_0080_TAU_CH7_OUTPUT_LEVEL_L;
|
|
TO0 &= ~_0080_TAU_CH7_OUTPUT_VALUE_1;
|
|
TOE0 |= _0080_TAU_CH7_OUTPUT_ENABLE;
|
|
/* Set TO05 pin */
|
|
P1 &= 0xFBU;
|
|
PM1 &= 0xFBU;
|
|
/* Set TO07 pin */
|
|
P1 &= 0xFEU;
|
|
PM1 &= 0xFEU;
|
|
}
|
|
|
|
/***********************************************************************************************************************
|
|
* Function Name: R_TAU0_Channel0_Start
|
|
* Description : This function starts TAU0 channel 0 counter.
|
|
* Arguments : None
|
|
* Return Value : None
|
|
***********************************************************************************************************************/
|
|
void R_TAU0_Channel0_Start(void)
|
|
{
|
|
TMIF00 = 0U; /* clear INTTM00 interrupt flag */
|
|
TMMK00 = 0U; /* enable INTTM00 interrupt */
|
|
TS0 |= _0001_TAU_CH0_START_TRG_ON;
|
|
}
|
|
|
|
/***********************************************************************************************************************
|
|
* Function Name: R_TAU0_Channel0_Stop
|
|
* Description : This function stops TAU0 channel 0 counter.
|
|
* Arguments : None
|
|
* Return Value : None
|
|
***********************************************************************************************************************/
|
|
void R_TAU0_Channel0_Stop(void)
|
|
{
|
|
TT0 |= _0001_TAU_CH0_STOP_TRG_ON;
|
|
/* Mask channel 0 interrupt */
|
|
TMMK00 = 1U; /* disable INTTM00 interrupt */
|
|
TMIF00 = 0U; /* clear INTTM00 interrupt flag */
|
|
}
|
|
|
|
/***********************************************************************************************************************
|
|
* Function Name: R_TAU0_Channel1_Start
|
|
* Description : This function starts TAU0 channel 1 counter.
|
|
* Arguments : None
|
|
* Return Value : None
|
|
***********************************************************************************************************************/
|
|
void R_TAU0_Channel1_Start(void)
|
|
{
|
|
TMIF01 = 0U; /* clear INTTM01 interrupt flag */
|
|
TMMK01 = 0U; /* enable INTTM01 interrupt */
|
|
TS0 |= _0002_TAU_CH1_START_TRG_ON;
|
|
}
|
|
|
|
/***********************************************************************************************************************
|
|
* Function Name: R_TAU0_Channel1_Stop
|
|
* Description : This function stops TAU0 channel 1 counter.
|
|
* Arguments : None
|
|
* Return Value : None
|
|
***********************************************************************************************************************/
|
|
void R_TAU0_Channel1_Stop(void)
|
|
{
|
|
TT0 |= _0002_TAU_CH1_STOP_TRG_ON;
|
|
/* Mask channel 1 interrupt */
|
|
TMMK01 = 1U; /* disable INTTM01 interrupt */
|
|
TMIF01 = 0U; /* clear INTTM01 interrupt flag */
|
|
}
|
|
|
|
/***********************************************************************************************************************
|
|
* Function Name: R_TAU0_Channel4_Start
|
|
* Description : This function starts TAU0 channel 4 counter.
|
|
* Arguments : None
|
|
* Return Value : None
|
|
***********************************************************************************************************************/
|
|
void R_TAU0_Channel4_Start(void)
|
|
{
|
|
TOE0 |= _0020_TAU_CH5_OUTPUT_ENABLE;
|
|
TS0 |= _0010_TAU_CH4_START_TRG_ON | _0020_TAU_CH5_START_TRG_ON;
|
|
}
|
|
|
|
/***********************************************************************************************************************
|
|
* Function Name: R_TAU0_Channel4_Stop
|
|
* Description : This function stops TAU0 channel 4 counter.
|
|
* Arguments : None
|
|
* Return Value : None
|
|
***********************************************************************************************************************/
|
|
void R_TAU0_Channel4_Stop(void)
|
|
{
|
|
TT0 |= _0010_TAU_CH4_STOP_TRG_ON | _0020_TAU_CH5_STOP_TRG_ON;
|
|
TOE0 &= ~_0020_TAU_CH5_OUTPUT_ENABLE;
|
|
}
|
|
|
|
/***********************************************************************************************************************
|
|
* Function Name: R_TAU0_Channel6_Start
|
|
* Description : This function starts TAU0 channel 6 counter.
|
|
* Arguments : None
|
|
* Return Value : None
|
|
***********************************************************************************************************************/
|
|
void R_TAU0_Channel6_Start(void)
|
|
{
|
|
TOE0 |= _0080_TAU_CH7_OUTPUT_ENABLE;
|
|
TS0 |= _0040_TAU_CH6_START_TRG_ON | _0080_TAU_CH7_START_TRG_ON;
|
|
}
|
|
|
|
/***********************************************************************************************************************
|
|
* Function Name: R_TAU0_Channel6_Stop
|
|
* Description : This function stops TAU0 channel 6 counter.
|
|
* Arguments : None
|
|
* Return Value : None
|
|
***********************************************************************************************************************/
|
|
void R_TAU0_Channel6_Stop(void)
|
|
{
|
|
TT0 |= _0040_TAU_CH6_STOP_TRG_ON | _0080_TAU_CH7_STOP_TRG_ON;
|
|
TOE0 &= ~_0080_TAU_CH7_OUTPUT_ENABLE;
|
|
}
|
|
|
|
/* Start user code for adding. Do not edit comment generated here */
|
|
/* End user code. Do not edit comment generated here */
|