199 lines
6.7 KiB
C
Raw Normal View History

2022-01-18 00:58:54 +08:00
/*********************************************************************************************************************
* COPYRIGHT NOTICE
* Copyright (c) 2020,<EFBFBD><EFBFBD><EFBFBD>ɿƼ<EFBFBD>
* All rights reserved.
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>QQȺ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ⱥ<EFBFBD><EFBFBD>824575535
*
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD>Ȩ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɿƼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD>δ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>;<EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD>ӭ<EFBFBD><EFBFBD>λʹ<EFBFBD>ò<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɿƼ<EFBFBD><EFBFBD>İ<EFBFBD>Ȩ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @file ccu6_pit
* @company <EFBFBD>ɶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɿƼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>޹<EFBFBD>˾
* @author <EFBFBD><EFBFBD><EFBFBD>ɿƼ<EFBFBD>(QQ3184284598)
* @version <EFBFBD>doc<EFBFBD><EFBFBD>version<EFBFBD>ļ<EFBFBD> <EFBFBD>˵<EFBFBD><EFBFBD>
* @Software ADS v1.2.2
* @Target core TC264D
* @Taobao https://seekfree.taobao.com/
* @date 2020-3-23
********************************************************************************************************************/
#include "IfxCcu6_Timer.h"
#include "SysSe/Bsp/Bsp.h"
#include "isr_config.h"
#include "zf_ccu6_pit.h"
//-------------------------------------------------------------------------------------------------------------------
// @brief pit<69><74>ʼ<EFBFBD><CABC>
// @param ccu6n ѡ<><D1A1>CCU6ģ<36><C4A3>(CCU6_0<5F><30>CCU6_1)
// @param pit_ch ѡ<><D1A1>ͨ<EFBFBD><CDA8>(PIT_CH0<48><30>PIT_CH1)
// @param time <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
// @return void
// @note <09><>ʹ<EFBFBD><CAB9>.h<>ļ<EFBFBD><C4BC><EFBFBD> <20><>ʱ<EFBFBD>䵥λ<E4B5A5>ĺ궨<C4BA><EFBFBD><E5BAAF>
// Sample usage: pit_init(CCU6_0, PIT_CH0, 5000); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>5000us
//-------------------------------------------------------------------------------------------------------------------
void pit_init(CCU6N_enum ccu6n, CCU6_CHN_enum pit_ch, uint32 time)
{
uint8 i;
volatile Ifx_CCU6 *module;
uint64 timer_input_clk;
IfxCcu6_Timer g_Ccu6Timer;
IfxCcu6_Timer_Config timerConfig;
uint32 timer_period;
boolean interrupt_state = disableInterrupts();
module = IfxCcu6_getAddress((IfxCcu6_Index)ccu6n);
IfxCcu6_Timer_initModuleConfig(&timerConfig, module);
timer_input_clk = IfxScuCcu_getSpbFrequency();
i = 0;
while(i<16)
{
timer_period = (uint32)(timer_input_clk * time / 1000000);
if(timer_period < 0xffff) break;
timer_input_clk >>= 1;
i++;
}
if(16 <= i) IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, FALSE);
switch(ccu6n)
{
case CCU6_0:
{
if(PIT_CH0 == pit_ch)
{
timerConfig.interrupt1.typeOfService = CCU6_0_CH0_INT_SERVICE;
timerConfig.interrupt1.priority = CCU6_0_CH0_ISR_PRIORITY;
}
else
{
timerConfig.interrupt2.typeOfService = CCU6_0_CH1_INT_SERVICE;
timerConfig.interrupt2.priority = CCU6_0_CH1_ISR_PRIORITY;
}
}break;
case CCU6_1:
{
if(PIT_CH0 == pit_ch)
{
timerConfig.interrupt1.typeOfService = CCU6_1_CH0_INT_SERVICE;
timerConfig.interrupt1.priority = CCU6_1_CH0_ISR_PRIORITY;
}
else
{
timerConfig.interrupt2.typeOfService = CCU6_1_CH1_INT_SERVICE;
timerConfig.interrupt2.priority = CCU6_1_CH1_ISR_PRIORITY;
}
}break;
}
if(PIT_CH0 == pit_ch)
{
timerConfig.timer = IfxCcu6_TimerId_t12;
timerConfig.interrupt1.source = IfxCcu6_InterruptSource_t12PeriodMatch;
timerConfig.interrupt1.serviceRequest = IfxCcu6_ServiceRequest_1;
timerConfig.base.t12Period = timer_period;
timerConfig.base.t12Frequency = (float)timer_input_clk;
timerConfig.clock.t12countingInputMode = IfxCcu6_CountingInputMode_internal;
}
else
{
timerConfig.timer = IfxCcu6_TimerId_t13;
timerConfig.interrupt2.source = IfxCcu6_InterruptSource_t13PeriodMatch;
timerConfig.interrupt2.serviceRequest = IfxCcu6_ServiceRequest_2;
timerConfig.base.t13Period = timer_period;
timerConfig.base.t13Frequency = (float)timer_input_clk;
timerConfig.clock.t13countingInputMode = IfxCcu6_CountingInputMode_internal;
}
timerConfig.timer12.counterValue = 0;
timerConfig.timer13.counterValue = 0;
timerConfig.trigger.t13InSyncWithT12 = FALSE;
IfxCcu6_Timer_initModule(&g_Ccu6Timer, &timerConfig);
restoreInterrupts(interrupt_state);
IfxCcu6_setSuspendMode(module, IfxCcu6_SuspendMode_hard);
IfxCcu6_Timer_start(&g_Ccu6Timer);
}
//-------------------------------------------------------------------------------------------------------------------
// @brief pit<69>ر<EFBFBD>
// @param ccu6n ѡ<><D1A1>CCU6ģ<36><C4A3>(CCU6_0<5F><30>CCU6_1)
// @param pit_ch ѡ<><D1A1>ͨ<EFBFBD><CDA8>(PIT_CH0<48><30>PIT_CH1)
// @return void
// @note
// Sample usage: pit_close(CCU6_0, PIT_CH0); //<2F>ر<EFBFBD>CCU60 ͨ<><CDA8>0<EFBFBD>ļ<EFBFBD>ʱ<EFBFBD><CAB1>
//-------------------------------------------------------------------------------------------------------------------
void pit_close(CCU6N_enum ccu6n, CCU6_CHN_enum pit_ch)
{
volatile Ifx_CCU6 *module;
IfxCcu6_Timer g_Ccu6Timer;
module = IfxCcu6_getAddress((IfxCcu6_Index)ccu6n);
g_Ccu6Timer.ccu6 = module;
g_Ccu6Timer.timer = (IfxCcu6_TimerId)(pit_ch);
IfxCcu6_Timer_stop(&g_Ccu6Timer);
}
//-------------------------------------------------------------------------------------------------------------------
// @brief pit<69><74>ʼ
// @param ccu6n ѡ<><D1A1>CCU6ģ<36><C4A3>(CCU6_0<5F><30>CCU6_1)
// @param pit_ch ѡ<><D1A1>ͨ<EFBFBD><CDA8>(PIT_CH0<48><30>PIT_CH1)
// @return void
// @note
// Sample usage: pit_start(CCU6_0, PIT_CH0); //<2F><><EFBFBD><EFBFBD>CCU60 ͨ<><CDA8>0<EFBFBD>ļ<EFBFBD>ʱ<EFBFBD><CAB1>
//-------------------------------------------------------------------------------------------------------------------
void pit_start(CCU6N_enum ccu6n, CCU6_CHN_enum pit_ch)
{
volatile Ifx_CCU6 *module;
IfxCcu6_Timer g_Ccu6Timer;
module = IfxCcu6_getAddress((IfxCcu6_Index)ccu6n);
g_Ccu6Timer.ccu6 = module;
g_Ccu6Timer.timer = (IfxCcu6_TimerId)(pit_ch);
IfxCcu6_Timer_start(&g_Ccu6Timer);
}
//-------------------------------------------------------------------------------------------------------------------
// @brief <20><>ֹpit<69>ж<EFBFBD>
// @param ccu6n ѡ<><D1A1>CCU6ģ<36><C4A3>(CCU6_0<5F><30>CCU6_1)
// @param pit_ch ѡ<><D1A1>ͨ<EFBFBD><CDA8>(PIT_CH0<48><30>PIT_CH1)
// @return void
// @note
// Sample usage: pit_disable_interrupt(CCU6_0, PIT_CH0); //<2F><>ֹCCU60 ͨ<><CDA8>0<EFBFBD><30><EFBFBD>ж<EFBFBD>
//-------------------------------------------------------------------------------------------------------------------
void pit_disable_interrupt(CCU6N_enum ccu6n, CCU6_CHN_enum pit_ch)
{
volatile Ifx_CCU6 *module;
module = IfxCcu6_getAddress((IfxCcu6_Index)ccu6n);
IfxCcu6_disableInterrupt(module, pit_ch * 2 + 7);
}
//-------------------------------------------------------------------------------------------------------------------
// @brief ʹ<><CAB9>pit<69>ж<EFBFBD>
// @param ccu6n ѡ<><D1A1>CCU6ģ<36><C4A3>(CCU6_0<5F><30>CCU6_1)
// @param pit_ch ѡ<><D1A1>ͨ<EFBFBD><CDA8>(PIT_CH0<48><30>PIT_CH1)
// @return void
// @note
// Sample usage: pit_enable_interrupt(CCU6_0, PIT_CH0); //<2F><><EFBFBD><EFBFBD>CCU60 ͨ<><CDA8>0<EFBFBD><30><EFBFBD>ж<EFBFBD>
//-------------------------------------------------------------------------------------------------------------------
void pit_enable_interrupt(CCU6N_enum ccu6n, CCU6_CHN_enum pit_ch)
{
volatile Ifx_CCU6 *module;
module = IfxCcu6_getAddress((IfxCcu6_Index)ccu6n);
IfxCcu6_enableInterrupt(module, pit_ch * 2 + 7);
}