AC7802x支持NMI(不可屏蔽中断)。开发板引出了NMI(PB2)到按键。经学习示例:\AC7802x_Demo_V1.0.0\GPIO\SampleCode\04_GPIO_NMI_Wakeup示例,下面体验如何在linux下面实现对NMI的编程。1. 新建文件夹:AC7802_NMI文件夹,并把原来【杰发科技AC7802x测评】linux下开发按键中断试验 - - 21ic电子技术开**坛的工程文件复到该文件夹下:cp -r ./AC7802_GPIO/* ./AC7802_NMI/
2、用vscode打开该文件夹,并修改gpio.h如下:
#ifndef _GPIO_H__
#define _GPIO_H__
#include "ac780x_gpio.h"
#define LED1_PORT (GPIOA)
#define LED1_PIN (GPIO_PIN2)
#define LED2_PORT (GPIOA)
#define LED2_PIN (GPIO_PIN3)
/*LED1动作定义.*/
#define LED1_ON do{GPIO_SetPinLevel(LED1_PORT, LED1_PIN, GPIO_LEVEL_HIGH);}while(0)
#define LED1_OFF do{GPIO_SetPinLevel(LED1_PORT, LED1_PIN, GPIO_LEVEL_LOW);}while(0)
#define LED1_TOGGLE do{if(GPIO_GetPinLevel(LED1_PORT, LED1_PIN)){LED1_OFF;}else{LED1_ON;}}while(0)
/*LED2动作定义.*/
#define LED2_ON do{GPIO_SetPinLevel(LED2_PORT, LED2_PIN, GPIO_LEVEL_HIGH);}while(0)
#define LED2_OFF do{GPIO_SetPinLevel(LED2_PORT, LED2_PIN, GPIO_LEVEL_LOW);}while(0)
#define LED2_TOGGLE do{if(GPIO_GetPinLevel(LED2_PORT, LED2_PIN)){LED2_OFF;}else{LED2_ON;}}while(0)
#define KEY_PORT (GPIOA)
#define KEY_PIN (GPIO_PIN11)
#define NMI_PORT (GPIOB)
#define NMI_PIN (GPIO_PIN2)
void GPIO_LedInit(void);
void GPIO_NMIInit(void);
void GPIO_MCUGotoSleep(void);
#endif
2、修改gpio.c如下:
#include "gpio.h"
#include "stdbool.h"
void GPIO_LedInit(void)
{
GPIO_SetFunc(LED1_PORT, LED1_PIN, GPIO_FUN0);
GPIO_SetFunc(LED2_PORT, LED2_PIN, GPIO_FUN0);
GPIO_SetDir(LED1_PORT, LED1_PIN, GPIO_OUT);
GPIO_SetDir(LED2_PORT, LED2_PIN, GPIO_OUT);
LED1_ON;
LED2_ON;
}
void GPIO_NMIInit(void)
{
GPIO_SetFunc(NMI_PORT, NMI_PIN, GPIO_FUN1);
SPM_EnableModuleWakeup(SPM_MODULE_NMI, ENABLE);
}
void GPIO_MCUGotoSleep(void)
{
mdelay(2000);
LED1_OFF;
LED2_OFF;
SysStop();
LED1_ON;
LED2_ON;
}
3、 修改main.c如下:
#include "main.h"
#include "AC7802x_irq_cb.h"
#include "ac780x_gpio.h"
#include "gpio.h"
int main(void)
{
InitDelay();
GPIO_LedInit();
GPIO_NMIInit();
while(1)
{
GPIO_MCUGotoSleep();
}
}
4、修改makefile修改我们编译的target:
TARGET = AC7802_NMI
5、makeclearn 再编译执行make就生成了AC7802_NMI.elf的固件:
arm-none-eabi-size build/AC7802_NMI.elf
text data bss dec hex filename
2904 8 2112 5024 13a0 build/AC7802_NMI.elf
arm-none-eabi-objcopy -O ihex build/AC7802_NMI.elf build/AC7802_NMI.hex
arm-none-eabi-objcopy -O binary -S build/AC7802_NMI.elf build/AC7802_NMI.bin
lugl@lugl-virtual-machine:~/ac7802/AC7802_NMI$
6、下载,执行:pyocd load ./build/AC7802_NMI.elf --target ac78022mbqa(如果上次是烧写这个软件,需要复位一下,要 进入休眠会导致连接到target失败:0000334 C STLink error (11): Debug power error [__main__])。
lugl@lugl-virtual-machine:~/ac7802/AC7802_NMI$ pyocd load ./build/AC7802_NMI.elf --target ac78022mbqa
0000372 I Loading /home/lugl/ac7802/AC7802_NMI/build/AC7802_NMI.elf [load_cmd]
[==================================================] 100%
0000832 I Erased 0 bytes (0 sectors), programmed 0 bytes (0 pages), skipped 3072 bytes (6 pages) at 6.54 kB/s [loader]
7、运行效果,开机后两个LED灯会亮2秒钟后两个LED熄灭,然后我按们下Key2(NMI)就会唤醒系统,2秒钟后也会进入休眠模式,LED1、LED2熄灭。
【总结】AC7802是基于Cortex-M0+的内核,支持NMI的中断。相比其他中断,他的配置更新精简。
|