以下示例以周期模式配置TimerA0,并使用重复计数功能每隔2秒切换一次GPIO。注意:重复计数功能特定于TimerA0实例,而不是其他TimerA实例。这里是一次500毫秒,重复了四次
主函数:
#include "ti_msp_dl_config.h"int main(void)
{SYSCFG_DL_init();NVIC_EnableIRQ(TIMER_0_INST_INT_IRQN); //允许中断DL_SYSCTL_enableSleepOnExit(); //低功耗语句可以删掉DL_TimerA_startCounter(TIMER_0_INST); //让TIMA0开始计数while (1) {__WFI(); //低功耗语句可以删掉}
}void TIMER_0_INST_IRQHandler(void)
{switch (DL_TimerA_getPendingInterrupt(TIMER_0_INST)) //判断是不是TIMA0中断,并确定是TIMA0中哪一个中断{case DL_TIMERA_IIDX_REPEAT_COUNT: //如果是重复计数中断DL_GPIO_togglePins(GPIO_LEDS_PORT,GPIO_LEDS_USER_LED_1_PIN | GPIO_LEDS_USER_TEST_PIN);break;default:break;}
}
宏定义:
#ifndef ti_msp_dl_config_h
#define ti_msp_dl_config_h#define CONFIG_MSPM0G350X#if defined(__ti_version__) || defined(__TI_COMPILER_VERSION__)
#define SYSCONFIG_WEAK __attribute__((weak))
#elif defined(__IAR_SYSTEMS_ICC__)
#define SYSCONFIG_WEAK __weak
#elif defined(__GNUC__)
#define SYSCONFIG_WEAK __attribute__((weak))
#endif#include <ti/devices/msp/msp.h>
#include <ti/driverlib/driverlib.h>
#include <ti/driverlib/m0p/dl_core.h>#ifdef __cplusplus
extern "C" {
#endif/** ======== SYSCFG_DL_init ========* Perform all required MSP DL initialization** This function should be called once at a point before any use of* MSP DL.*//* clang-format off */#define POWER_STARTUP_DELAY (16)#define CPUCLK_FREQ 32000000/* Defines for TIMER_0 */
#define TIMER_0_INST (TIMA0)
#define TIMER_0_INST_IRQHandler TIMA0_IRQHandler
#define TIMER_0_INST_INT_IRQN (TIMA0_INT_IRQn)
#define TIMER_0_INST_LOAD_VALUE (16383U)
#define TIMER_0_REPEAT_COUNT_4 (3)/* Port definition for Pin Group GPIO_LEDS */
#define GPIO_LEDS_PORT (GPIOA)/* Defines for USER_LED_1: GPIOA.0 with pinCMx 1 on package pin 33 */
#define GPIO_LEDS_USER_LED_1_PIN (DL_GPIO_PIN_0)
#define GPIO_LEDS_USER_LED_1_IOMUX (IOMUX_PINCM1)
/* Defines for USER_TEST: GPIOA.15 with pinCMx 37 on package pin 8 */
#define GPIO_LEDS_USER_TEST_PIN (DL_GPIO_PIN_15)
#define GPIO_LEDS_USER_TEST_IOMUX (IOMUX_PINCM37)/* clang-format on */void SYSCFG_DL_init(void);
void SYSCFG_DL_initPower(void);
void SYSCFG_DL_GPIO_init(void);
void SYSCFG_DL_SYSCTL_init(void);
void SYSCFG_DL_TIMER_0_init(void);bool SYSCFG_DL_saveConfiguration(void);
bool SYSCFG_DL_restoreConfiguration(void);#ifdef __cplusplus
}
#endif#endif /* ti_msp_dl_config_h */
主函数中有这一函数:
DL_TimerA_getPendingInterrupt(TIMER_0_INST)
是用来判断终端是否来自TIMA0中断,并确定是TIMA0中的哪个中断
这里虽然名字有TIMERA,其实还是TIMER,这里有了重定义
函数用法:
配置: