【嵌入式学习】ARM day04.16

一、练习

do_irq.c

#include "mykey.h"
extern void printf(const char *fmt, ...);
unsigned int i = 0;

void do_irq(void) 
{
    unsigned int irqno=(GICC->IAR&0X3FF);
    static int key1_flag=0;
    static  int key2_flag=0;
    static int key3_flag=0;
    switch (irqno)
    {
    case 99:
        {
            //中断处理逻辑
            if(key1_flag==0)
            {
            GPIOE->ODR |= (0x1<<10);
            key1_flag=1;
            }
            else if(key1_flag==1)
            {
                 GPIOE->ODR &=(~(0x1<<10));
                key1_flag=0;
            }        
            //清除GICD的中断标志
            GICD->ICPENDR[3] |=(0X1<<3);
            //清除EXTI的中断触发标志
            EXTI->FPR1 |=(0X1<<9);
        }
        break;
    case 98:
        {
             //中断处理逻辑
             //中断处理逻辑
            if(key2_flag==0)
            {
            GPIOF->ODR |= (0x1<<10);
            key2_flag=1;
            }
            else if(key2_flag==1)
            {
                 GPIOF->ODR &=(~(0x1<<10));
                key2_flag=0;
            }
            //清除GICD的中断标志
            GICD->ICPENDR[3] |=(0X1<<2);
            //清除EXTI的中断触发标志
            EXTI->FPR1 |=(0X1<<8);
        }
        break;
    case 97:
        {
            //中断处理逻辑
             //中断处理逻辑
            if(key3_flag==0)
            {
            GPIOE->ODR |= (0x1<<8);
            key3_flag=1;
            }
            else if(key3_flag==1)
            {
                 GPIOE->ODR &=(~(0x1<<8));
                key3_flag=0;
            }
            //清除GICD的中断标志
            GICD->ICPENDR[3] |=(0X1<<1);
            //清除EXTI的中断触发标志
            EXTI->FPR1 |=(0X1<<7);
        }
        break;
    default:
        break;
    }
    GICC->EOIR=irqno;
}

my_key.h

#ifndef __MYKEY_H__
#define __MYKEY_H__
#include "stm32mp1XX_gpio.h"
#include "stm32mp1XX_gic.h"
#include "stm32mp1XX_exti.h"
#include "stm32mp1XX_rcc.h"

void key1_int_config();
void key2_int_config();
void key3_int_config();
void led_init();

#endif

mykey.c

#include "mykey.h"

void key1_int_config()
{
    //使能GPIOF外设时钟
    RCC->MP_AHB4ENSETR |= (0X1<<5);
    //设置PF9为输入
    GPIOF->MODER &=(~(0X3<<18));
   // 设置PF9产生EXTI9事件
   EXTI->EXTICR3 &=(~(0xff<<8));
   EXTI->EXTICR3 |=(0x05<<8);
   //设置EXTI9为下降沿检测
   EXTI->FTSR1 |=(0x1<<9);
    //取消EXTI9的屏蔽
    EXTI->C1IMR1 |=(0x1<<9);
    //全局使能99号中断
    GICD->ISENABLER[3] |=(0x1<<3);
    //设置99号中断的优先级
    GICD->IPRIORITYR[24] &=(~(0x1f<<27));
    //设置99号中断的目标处理器
    GICD->ITARGETSR[24] |=(0x1<<24);
    //允许组0中断被转发到GICC层
    GICD->CTRL |=0x1;
    //设置中断优先级掩码
    GICC->PMR |=(0x1f<<3);
    //允许组0中断被转发给处理器
    GICC->CTRL |=0x1;
}
void key2_int_config()
{
    //使能GPIOF外设时钟
    RCC->MP_AHB4ENSETR |= (0X1<<5);
    //设置PF8为输入
    GPIOF->MODER &=(~(0X3<<16));
   // 设置PF8产生EXTI8事件
   EXTI->EXTICR3 &=(~(0xff<<0));
   EXTI->EXTICR3 |=(0x05<<0);
   //设置EXTI8为下降沿检测
   EXTI->FTSR1 |=(0x1<<8);
    //取消EXTI8的屏蔽
    EXTI->C1IMR1 |=(0x1<<8);
    //全局使能98号中断
    GICD->ISENABLER[3] |=(0x1<<2);
    //设置98号中断的优先级
    GICD->IPRIORITYR[24] &=(~(0x1f<<19));
    //设置98号中断的目标处理器
    GICD->ITARGETSR[24] |=(0x1<<16);
    //允许组0中断被转发到GICC层
    GICD->CTRL |=0x1;
    //设置中断优先级掩码
    GICC->PMR |=(0x1f<<3);
    //允许组0中断被转发给处理器
    GICC->CTRL |=0x1;
}
void key3_int_config()
{
    //使能GPIOF外设时钟
    RCC->MP_AHB4ENSETR |= (0X1<<5);
    //设置PF7为输入
    GPIOF->MODER &=(~(0X3<<14));
   // 设置PF7产生EXTI7事件
   EXTI->EXTICR2 &=(~(0xff<<24));
   EXTI->EXTICR2 |=(0x05<<24);
   //设置EXTI7为下降沿检测
   EXTI->FTSR1 |=(0x1<<7);
    //取消EXTI7的屏蔽
    EXTI->C1IMR1 |=(0x1<<7);
    //全局使能97号中断
    GICD->ISENABLER[3] |=(0x1<<1);
    //设置97号中断的优先级
    GICD->IPRIORITYR[24] &=(~(0x1f<<11));
    //设置97号中断的目标处理器
    GICD->ITARGETSR[24] |=(0x1<<8);
    //允许组0中断被转发到GICC层
    GICD->CTRL |=0x1;
    //设置中断优先级掩码
    GICC->PMR |=(0x1f<<3);
    //允许组0中断被转发给处理器
    GICC->CTRL |=0x1;
}

main.c

#include "mykey.h"

int main()
{
	key1_int_config();
	key2_int_config();
	key3_int_config();
	led_init();
	while (1)

	{
	}
	
	return 0;

}

 

 

 

相关推荐

  1. 嵌入学习-ARM

    2024-04-23 07:08:03       39 阅读
  2. 嵌入学习-ARM

    2024-04-23 07:08:03       37 阅读
  3. 嵌入安全学习路标

    2024-04-23 07:08:03       57 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-23 07:08:03       91 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-23 07:08:03       97 阅读
  3. 在Django里面运行非项目文件

    2024-04-23 07:08:03       78 阅读
  4. Python语言-面向对象

    2024-04-23 07:08:03       88 阅读

热门阅读

  1. c++计算DNA探针的熔解温度

    2024-04-23 07:08:03       36 阅读
  2. MapReduce——数据切片与MapTask并行度决定机制

    2024-04-23 07:08:03       35 阅读
  3. 代码随想录:链表

    2024-04-23 07:08:03       39 阅读
  4. 分发糖果——使用贪心算法

    2024-04-23 07:08:03       33 阅读
  5. CentOS 7 上安装 MySQL 8.0详细步骤

    2024-04-23 07:08:03       40 阅读
  6. 前端需要知道的知识点,附有链接

    2024-04-23 07:08:03       37 阅读
  7. FPGA ——Verilog语法示例

    2024-04-23 07:08:03       30 阅读
  8. 【Leetcode】并查集/DFS/BFS多解

    2024-04-23 07:08:03       36 阅读