cortex-A7核按键中断实验

cortex-A7核按键中断实验_第1张图片

流程图

cortex-A7核按键中断实验_第2张图片

.h

#ifndef __INTERRUPT_H__
#define __INTERRUPT_H__
#include "stm32mp1xx_gpio.h"
#include "stm32mp1xx_uart.h"
#include "stm32mp1xx_gic.h"
#include "stm32mp1xx_rcc.h"
#include "stm32mp1xx_exti.h"
//key1----PF9
//初始化exti层
void pf9_exti_init();


//初始化gicd层
void pf9_gicd_init();

//初始化gicc层
void pf9_gicc_init();

//key2----PF7
//初始化exti层
void pf7_exti_init();


//初始化gicd层
void pf7_gicd_init();

//初始化gicc层
void pf7_gicc_init();

//key1----PF8
//初始化exti层
void pf8_exti_init();


//初始化gicd层
void pf8_gicd_init();

//初始化gicc层
void pf8_gicc_init();



#endif

 .c

#include "interrupt.h"


//key1----PF9
//初始化exti层
void pf9_exti_init()
{
	//RCC章节初始化
	//1.设置GPIOF时钟使能
	RCC->MP_AHB4ENSETR |=(0x1 << 5);
	//GPIO章节初始化
	//1.设置PF9引脚为输入模式
	 GPIOF->MODER &=(~(0x3 << 18));

	//EXTI章节初始化
	//1.设置PF9引脚和EXTI9控制器进行连接
	EXTI->EXTICR3 &=(~(0xff << 8));
    EXTI->EXTICR3 |=(0x5 << 8);

	//2.设置PF9引脚检测方式为下降沿
    EXTI->FTSR1 |=(0x1 << 9);


	//3.设置PF9引脚中断不屏蔽
	EXTI->C1IMR1 |=(0x1 << 9);
	
}


//初始化gicd层
void pf9_gicd_init()
{
   //1. 设置GICD层全局中断使能
   GICD->CTRL |=(0x1 << 0);

   //2.设置GICD层中断使能寄存器(中断号)
   GICD->ISENABLER[3] |=(0x1 << 3);

   //3.设置中断优先级寄存器 设为8
   //GICD->IPRIORITYR[24] &=(~(0x20 << 27));
   GICD->IPRIORITYR[24] |=(0x4 << 27);


   //4.设置GICD层中断目标分配寄存器
  // GICD->ITARGETSR[24] &=(~(0x3 << 24));
   GICD->ITARGETSR[24] |=(0x1 << 24);

}

//初始化gicc层
void pf9_gicc_init()
{
    //1.设置GICC层全局中断使能寄存器
	 GICC->CTRL |=(0x1 << 0);

	//2.设置GICC层中断优先级寄存器
	 GICC->PMR &=(~(0x20 << 3));
     GICC->PMR |=(0x9 << 3);

}




//key2----PF7
//初始化exti层
void pf7_exti_init()
{
	//RCC章节初始化
	//1.设置GPIOF时钟使能
	RCC->MP_AHB4ENSETR |=(0x1 << 5);
	//GPIO章节初始化
	//1.设置PF9引脚为输入模式
	 GPIOF->MODER &=(~(0x3 << 14));

	//EXTI章节初始化
	//1.设置PF9引脚和EXTI9控制器进行连接
//	EXTI->EXTICR2 &=(~(0xff << 24));
    EXTI->EXTICR2 |=(0x5 << 24);

	//2.设置PF9引脚检测方式为下降沿
    EXTI->FTSR1 |=(0x1 << 7);


	//3.设置PF9引脚中断不屏蔽
	EXTI->C1IMR1 |=(0x1 << 7);
	
}


//初始化gicd层
void pf7_gicd_init()
{
   //1. 设置GICD层全局中断使能
   GICD->CTRL |=(0x1 << 0);

   //2.设置GICD层中断使能寄存器(中断号)
   GICD->ISENABLER[3] |=(0x1 << 1);

   //3.设置中断优先级寄存器 设为8
   //GICD->IPRIORITYR[24] &=(~(0x20 << 27));
   GICD->IPRIORITYR[24] |=(0x4 << 11);


   //4.设置GICD层中断目标分配寄存器
  // GICD->ITARGETSR[24] &=(~(0x3 << 24));
   GICD->ITARGETSR[24] |=(0x1 << 8);

}

//初始化gicc层
void pf7_gicc_init()
{
    //1.设置GICC层全局中断使能寄存器
	 GICC->CTRL |=(0x1 << 0);

	//2.设置GICC层中断优先级寄存器
	 GICC->PMR &=(~(0x20 << 3));
     GICC->PMR |=(0x9 << 3);

}


//key3----PF8
//初始化exti层
void pf8_exti_init()
{
	//RCC章节初始化
	//1.设置GPIOF时钟使能
	RCC->MP_AHB4ENSETR |=(0x1 << 5);
	//GPIO章节初始化
	//1.设置PF9引脚为输入模式
	 GPIOF->MODER &=(~(0x3 << 16));

	//EXTI章节初始化
	//1.设置PF9引脚和EXTI9控制器进行连接
	EXTI->EXTICR3 &=(~(0xff << 0));
    EXTI->EXTICR3 |=(0x5 << 0);

	//2.设置PF9引脚检测方式为下降沿
    EXTI->FTSR1 |=(0x1 << 8);


	//3.设置PF9引脚中断不屏蔽
	EXTI->C1IMR1 |=(0x1 << 8);
	
}


//初始化gicd层
void pf8_gicd_init()
{
   //1. 设置GICD层全局中断使能
   GICD->CTRL |=(0x1 << 0);

   //2.设置GICD层中断使能寄存器(中断号)
   GICD->ISENABLER[3] |=(0x1 << 2);

   //3.设置中断优先级寄存器 设为8
   //GICD->IPRIORITYR[24] &=(~(0x20 << 27));
   GICD->IPRIORITYR[24] |=(0x4 << 19);


   //4.设置GICD层中断目标分配寄存器
  // GICD->ITARGETSR[24] &=(~(0x3 << 24));
   GICD->ITARGETSR[24] |=(0x1 << 16);

}

//初始化gicc层
void pf8_gicc_init()
{
    //1.设置GICC层全局中断使能寄存器
	 GICC->CTRL |=(0x1 << 0);

	//2.设置GICC层中断优先级寄存器
	 GICC->PMR &=(~(0x20 << 3));
     GICC->PMR |=(0x9 << 3);

}

do_irq.c

 

#include "interrupt.h"

extern void printf(const char *fmt, ...);
extern void delay_ms(int ms);
unsigned int i = 0;
void do_irq(void) 
{
    unsigned int num=0;
	//获取中断号
   	num =GICC->IAR & 0x3ff;
	switch(num)
	{
	case 97:
     	delay_ms(500);
        printf("key2########\n");

		//清除EXTI中断挂起标志位
		EXTI->FPR1 |=(0x1 << 7);
		//清除GICD中断挂起标志位
		GICD->ICPENDR[3] |=(0x1 << 1);


		break;
    case 98:
		delay_ms(500);
        printf("key3########\n");

		//清除EXTI中断挂起标志位
		EXTI->FPR1 |=(0x1 << 8);
		//清除GICD中断挂起标志位
		GICD->ICPENDR[3] |=(0x1 << 2);

		break;
    case 99:
		delay_ms(500);
        printf("key1########\n");

		//清除EXTI中断挂起标志位
		EXTI->FPR1 |=(0x1 << 9);
		//清除GICD中断挂起标志位
		GICD->ICPENDR[3] |=(0x1 << 3);

		break;

	}
    //清除中断号
	GICC->EOIR &=(~(0x3ff << 0));
    GICC->EOIR |=num;	
	

}

main.c

#include "interrupt.h"





extern void printf(const char *fmt, ...);

void delay_ms(int ms)

{

	int i,j;

	for(i = 0; i < ms;i++)

		for (j = 0; j < 1800; j++);

}



int main()

{

	//调用初始化函数

    pf9_exti_init();

	pf9_gicd_init();

	pf9_gicc_init();

	

    pf7_exti_init();

	pf7_gicd_init();

	pf7_gicc_init();

	

    pf8_exti_init();

	pf8_gicd_init();

	pf8_gicc_init();





	while(1)

	{

	}

	return 0;

}

你可能感兴趣的:(stm32,嵌入式硬件,arm)