主函数:
#include "ti_msp_dl_config.h"
int main(void)
{
SYSCFG_DL_init();
/* Enable Interrupt for both GPIOA and GPIOB ports */
NVIC_EnableIRQ(GPIO_SWITCHES_GPIOA_INT_IRQN); //启用SWITCHES——A的中断
NVIC_EnableIRQ(GPIO_SWITCHES_GPIOB_INT_IRQN); //启用SWITCHES——B的中断
while (1) {
__WFI();
}
}
void GROUP1_IRQHandler(void)
{
/*
* Get the pending interrupt for the GPIOA port and store for
* comparisons later //获取GPIOA端口的挂起中断,并存储以供稍后进行比较
*/
uint32_t gpioA = DL_GPIO_getEnabledInterruptStatus(GPIOA,GPIO_SWITCHES_USER_SWITCH_1_PIN | GPIO_SWITCHES_USER_SWITCH_3_PIN);
//获取已经启用的中断状态(这里是1和3的中断)
/*
* Bitwise AND the pending interrupt with the pin you want to check,
* then check if it is equal to the pins. Clear the interrupt status.
*/ //将挂起的中断与要检查的引脚逐位AND,然后检查它是否等于引脚。清除中断状态。
//类似于32中得到中断标志位,再判断中断标志位是谁的
if ((gpioA & GPIO_SWITCHES_USER_SWITCH_1_PIN) ==GPIO_SWITCHES_USER_SWITCH_1_PIN) //如果成立,则是该中断
{
DL_GPIO_togglePins(GPIO_LEDS_USER_LED_1_PORT, GPIO_LEDS_USER_LED_1_PIN);
DL_GPIO_clearInterruptStatus(GPIOA, GPIO_SWITCHES_USER_SWITCH_1_PIN);
}
if ((gpioA & GPIO_SWITCHES_USER_SWITCH_3_PIN) == GPIO_SWITCHES_USER_SWITCH_3_PIN)
{
DL_GPIO_togglePins(GPIO_LEDS_USER_LED_3_PORT, GPIO_LEDS_USER_LED_3_PIN);
DL_GPIO_clearInterruptStatus(GPIOA, GPIO_SWITCHES_USER_SWITCH_3_PIN);
}
/* Repeat with GPIOB Port */
uint32_t gpioB = DL_GPIO_getEnabledInterruptStatus( GPIOB, GPIO_SWITCHES_USER_SWITCH_2_PIN);
if ((gpioB & GPIO_SWITCHES_USER_SWITCH_2_PIN) == GPIO_SWITCHES_USER_SWITCH_2_PIN)
{
DL_GPIO_togglePins(GPIO_LEDS_USER_LED_2_PORT, GPIO_LEDS_USER_LED_2_PIN);
DL_GPIO_clearInterruptStatus(GPIOB, GPIO_SWITCHES_USER_SWITCH_2_PIN);
}
}
宏定义函数:
#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 USER_LED_1: GPIOA.0 with pinCMx 1 on package pin 33 */
#define GPIO_LEDS_USER_LED_1_PORT (GPIOA)
#define GPIO_LEDS_USER_LED_1_PIN (DL_GPIO_PIN_0)
#define GPIO_LEDS_USER_LED_1_IOMUX (IOMUX_PINCM1)
/* Defines for USER_LED_2: GPIOB.27 with pinCMx 58 on package pin 29 */
#define GPIO_LEDS_USER_LED_2_PORT (GPIOB)
#define GPIO_LEDS_USER_LED_2_PIN (DL_GPIO_PIN_27)
#define GPIO_LEDS_USER_LED_2_IOMUX (IOMUX_PINCM58)
/* Defines for USER_LED_3: GPIOB.26 with pinCMx 57 on package pin 28 */
#define GPIO_LEDS_USER_LED_3_PORT (GPIOB)
#define GPIO_LEDS_USER_LED_3_PIN (DL_GPIO_PIN_26)
#define GPIO_LEDS_USER_LED_3_IOMUX (IOMUX_PINCM57)
/* Defines for USER_SWITCH_1: GPIOA.12 with pinCMx 34 on package pin 5 */
#define GPIO_SWITCHES_USER_SWITCH_1_PORT (GPIOA)
// pins affected by this interrupt request:["USER_SWITCH_1","USER_SWITCH_3"]
#define GPIO_SWITCHES_GPIOA_INT_IRQN (GPIOA_INT_IRQn)
#define GPIO_SWITCHES_GPIOA_INT_IIDX (DL_INTERRUPT_GROUP1_IIDX_GPIOA)
#define GPIO_SWITCHES_USER_SWITCH_1_IIDX (DL_GPIO_IIDX_DIO12)
#define GPIO_SWITCHES_USER_SWITCH_1_PIN (DL_GPIO_PIN_12)
#define GPIO_SWITCHES_USER_SWITCH_1_IOMUX (IOMUX_PINCM34)
/* Defines for USER_SWITCH_2: GPIOB.12 with pinCMx 29 on package pin 64 */
#define GPIO_SWITCHES_USER_SWITCH_2_PORT (GPIOB)
// pins affected by this interrupt request:["USER_SWITCH_2"]
#define GPIO_SWITCHES_GPIOB_INT_IRQN (GPIOB_INT_IRQn)
#define GPIO_SWITCHES_GPIOB_INT_IIDX (DL_INTERRUPT_GROUP1_IIDX_GPIOB)
#define GPIO_SWITCHES_USER_SWITCH_2_IIDX (DL_GPIO_IIDX_DIO12)
#define GPIO_SWITCHES_USER_SWITCH_2_PIN (DL_GPIO_PIN_12)
#define GPIO_SWITCHES_USER_SWITCH_2_IOMUX (IOMUX_PINCM29)
/* Defines for USER_SWITCH_3: GPIOA.13 with pinCMx 35 on package pin 6 */
#define GPIO_SWITCHES_USER_SWITCH_3_PORT (GPIOA)
#define GPIO_SWITCHES_USER_SWITCH_3_IIDX (DL_GPIO_IIDX_DIO13)
#define GPIO_SWITCHES_USER_SWITCH_3_PIN (DL_GPIO_PIN_13)
#define GPIO_SWITCHES_USER_SWITCH_3_IOMUX (IOMUX_PINCM35)
/* 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);
#ifdef __cplusplus
}
#endif
#endif /* ti_msp_dl_config_h */
主函数中使用了该函数:
DL_GPIO_getEnabledInterruptStatus
用法,参数,返回值如下: