×
单片机 > 单片机程序设计 > 详情

msp432记录-timer

发布时间:2021-01-22 发布时间:
|

timer驱动API非常简单,就只有几个,开始计时,停止计时,获得计数值。认识初始化参数结构体即可


typdef struct {

Timer_Mode timerMode;  //模式

Timer_PeriodUnits periodUnits; //计数周期单位

Timer_CallBackFxn timerCallback; //回调函数

uint32_t period; //计数周期,联系periodUnits

}


//下面记录一下具体的数据结构参数


//模式结构体 注意,某些定时器可以被配置为向上计数和向下计数模式,通过Timer_getCount()得到计数值

typedef enum{

Timer_ONESHOT_CALLBACK, //非阻塞,只会产生一次到时中断,再次用Timer_start()可以再次生成一次定时

Timer_ONESHOT_BLOCKING, //一次阻塞型

Timer_CONTINUOUS_CALLBACK, //周期性定时

Timer_FREE_RUNNING //非阻塞,一直计数,不会产生中断,一般与Timer_getCount()配套使用

}Timer_Mode;


//计数单位

typedef enum{

Timer_PERIOD_US, //微秒级计数

Timer_PERIOD_HZ, //秒级计数

Timer_PERIOD_COUNTS //自定义

}Timer_PeriodUnits;


//中断回调函数

typedef void (*Timer_CallBackFxn)(Timer_Handle handle);


仅仅知道上面并不能完全使用定时器的驱动库,还需要去了解MSP_EXP432P401R.c与.h文件关于定时器的使用以及定时器相关头文件的地址、时钟等参数定义


/*

共有六个定时器,2个32位

TIMER32_1

TIMER32_2

TIMER_A0

TIMER_A1

TIMER_A2

TIMER_A3

*/


#include

#include


TimerMSP432_Object timerMSP432Objects[MSP_EXP432P401R_TIMERCOUNT];


const TimerMSP432_HWAttrs timerMSP432HWAttrs[MSP_EXP432P401R_TIMERCOUNT] = {

    /* Timer32_0 */

    {

        .timerBaseAddress = TIMER32_0_BASE,

        .clockSource = TIMER_A_CLOCKSOURCE_SMCLK,

        .intNum = INT_T32_INT1,

        .intPriority = ~0

    },

    {

        .timerBaseAddress = TIMER32_1_BASE,

        .clockSource = TIMER_A_CLOCKSOURCE_SMCLK,

        .intNum = INT_T32_INT2,

        .intPriority = ~0

    },

    /* Timer_A1 */

    {

        .timerBaseAddress = TIMER_A1_BASE,

        .clockSource = TIMER_A_CLOCKSOURCE_ACLK,

        .intNum = INT_TA1_0,

        .intPriority = ~0

    },

    /* Timer_A2 */

    {

        .timerBaseAddress = TIMER_A2_BASE,

        .clockSource = TIMER_A_CLOCKSOURCE_ACLK,

        .intNum = INT_TA2_0,

        .intPriority = ~0

    },

    /* Timer_A3 */

    {

        .timerBaseAddress = TIMER_A3_BASE,

        .clockSource = TIMER_A_CLOCKSOURCE_ACLK,

        .intNum = INT_TA3_0,

        .intPriority = ~0

    }

};


const Timer_Config Timer_config[MSP_EXP432P401R_TIMERCOUNT] = {

    {

        .fxnTablePtr = &TimerMSP432_Timer32_fxnTable,

        .object = &timerMSP432Objects[MSP_EXP432P401R_TIMER_T32_0],

        .hwAttrs = &timerMSP432HWAttrs[MSP_EXP432P401R_TIMER_T32_0]

    },

    {

        .fxnTablePtr = &TimerMSP432_Timer32_fxnTable,

        .object = &timerMSP432Objects[MSP_EXP432P401R_TIMER_T32_1],

        .hwAttrs = &timerMSP432HWAttrs[MSP_EXP432P401R_TIMER_T32_1]

    },

    {

        .fxnTablePtr = &TimerMSP432_Timer_A_fxnTable,

        .object = &timerMSP432Objects[MSP_EXP432P401R_TIMER_TA_1],

        .hwAttrs = &timerMSP432HWAttrs[MSP_EXP432P401R_TIMER_TA_1]

    },

    {

        .fxnTablePtr = &TimerMSP432_Timer_A_fxnTable,

        .object = &timerMSP432Objects[MSP_EXP432P401R_TIMER_TA_2],

        .hwAttrs = &timerMSP432HWAttrs[MSP_EXP432P401R_TIMER_TA_2]

    },

    {

        .fxnTablePtr = &TimerMSP432_Timer_A_fxnTable,

        .object = &timerMSP432Objects[MSP_EXP432P401R_TIMER_TA_3],

        .hwAttrs = &timerMSP432HWAttrs[MSP_EXP432P401R_TIMER_TA_3]

    }

};


const uint_least8_t Timer_count = MSP_EXP432P401R_TIMERCOUNT;



『本文转载自网络,版权归原作者所有,如有侵权请联系删除』

热门文章 更多
如何升级STM32单片机的代码