FCPIT todo - aman396271/Flagchip_Study GitHub Wiki

Feature

对比普通FTU,只能支持16bit的计数值,DCPIT支持32bit计数值 image 且支持多种定时器模式 image

计数器代码分析

单计数器

FCPIT初始化 void Bsp_Fcpit_Init(void) { FCPIT_CommonInitType tCommonInitStruct = {(FCPIT_ChannelType)0}; FCPIT_ChannelInitType tInitStruct = {(FCPIT_ChannelType)0}; FCPIT_IntType tIntStruct = {(FCPIT_ChannelType)0};

tCommonInitStruct.bDebugEn = true;
tCommonInitStruct.bLowPowerModeEn = true;

FCPIT_CommonInit(&gFcpitHandle,&tCommonInitStruct);

tInitStruct.eMode = FCPIT_32PERIODIC_COUNTER;
tInitStruct.eFcpitChannel = FCPIT_CHANNEL_0;       /* configure fcpit channel 0 */
tInitStruct.u32TimerValue = (uint32_t)18750000;    /* set the value to 75000000, the demo input frequency is 75000000,
                                                      please refer to PCC configuration for details. */
FCPIT_ChannelInit(&gFcpitHandle,&tInitStruct);

tIntStruct.eFcpitChannel = FCPIT_CHANNEL_0;       /* configure fcpit channel 0*/
tIntStruct.bChannelIsrEn = true;                  /* enable interrupt function */
tIntStruct.pChannelCallback = Bsp_FCPIT_IRQHandler;     /* set interrupt notification function */

FCPIT_InitInterrupt(&gFcpitHandle,&tIntStruct);

}

开启可调试和低功耗开关

    tCommonInitStruct.bDebugEn = true;
    tCommonInitStruct.bLowPowerModeEn = true;

    FCPIT_CommonInit(&gFcpitHandle,&tCommonInitStruct);

设置FCPIT为32位周期计数模式,设置通道,在SDK Demo中,设置了FCPIT的时钟源位PLL0,分频为DIV1,按照时钟树,FCPIT的外设频率为15000000/(1+1)=75000000,即1s75000000次计数,将u32TimerValue 设置为37500000,则一次计时为37500000/75000000=0.5s

    tInitStruct.eMode = FCPIT_32PERIODIC_COUNTER;
    tInitStruct.eFcpitChannel = FCPIT_CHANNEL_0;       /* configure fcpit channel 0 */
    tInitStruct.u32TimerValue = (uint32_t)37500000;    /* the demo input frequency is 75000000,
                                                          please refer to PCC configuration for details. */
    FCPIT_ChannelInit(&gFcpitHandle,&tInitStruct);

使能中断并定义中断回调函数

    tIntStruct.eFcpitChannel = FCPIT_CHANNEL_0;       /* configure fcpit channel 0*/
    tIntStruct.bChannelIsrEn = true;                  /* enable interrupt function */
    tIntStruct.pChannelCallback = Bsp_FCPIT_IRQHandler;     /* set interrupt notification function */
    FCPIT_InitInterrupt(&gFcpitHandle,&tIntStruct);

ChainMode 级联

image 第N-1个通道超时,第N个通道向下计数1次

#include "Fcpit.h"

FCPIT_HandleType gFcpitHandle;
static void Bsp_FCPIT_IRQHandler(FCPIT_HandleType *pHandle,uint32_t u32channel);

static void Bsp_FCPIT_IRQHandler(FCPIT_HandleType *pHandle,uint32_t u32channel)
{
	PROCESS_UNUSED_VAR(pHandle);
	if(u32channel == FCPIT_CHANNEL_1)
	{
		GPIO_Toggle(GPIO_C, PORT_PIN_30);
		GPIO_Toggle(GPIO_D, PORT_PIN_4);
		GPIO_Toggle(GPIO_B, PORT_PIN_28);
	}

}

void Bsp_Fcpit_Ch0_Init(void)
{
    FCPIT_ChannelInitType tInitStruct = {(FCPIT_ChannelType)0};
    tInitStruct.eMode = FCPIT_32PERIODIC_COUNTER;
    tInitStruct.eFcpitChannel = FCPIT_CHANNEL_0;
    tInitStruct.u32TimerValue = (uint32_t)5;
    FCPIT_ChannelInit(&gFcpitHandle,&tInitStruct);

}

void Bsp_Fcpit_Ch1_Init(void)
{
    FCPIT_ChannelInitType tInitStruct = {(FCPIT_ChannelType)0};
    FCPIT_IntType tIntStruct = {(FCPIT_ChannelType)0};

    tInitStruct.eMode = FCPIT_32PERIODIC_COUNTER;
    tInitStruct.eFcpitChannel = FCPIT_CHANNEL_1;
    tInitStruct.bChainModeEn = true;
    tInitStruct.u32TimerValue = (uint32_t)15000000;
    FCPIT_ChannelInit(&gFcpitHandle,&tInitStruct);

    tIntStruct.eFcpitChannel = FCPIT_CHANNEL_1;       /* configure fcpit channel 0*/
    tIntStruct.bChannelIsrEn = true;                  /* enable interrupt function */
    tIntStruct.pChannelCallback = Bsp_FCPIT_IRQHandler;     /* set interrupt notification function */

    FCPIT_InitInterrupt(&gFcpitHandle,&tIntStruct);

}

void Bsp_Fcpit_Init(void)
{
	Bsp_Fcpit_Ch0_Init();
	Bsp_Fcpit_Ch1_Init();
}

void Bsp_FcpitStart(void)
{
    FCPIT_Start(&gFcpitHandle,FCPIT_CHANNEL_0);
    FCPIT_Start(&gFcpitHandle,FCPIT_CHANNEL_1);
}

触发

#1