基于IMX6ULLmini的linux裸机开发系列八:按键处理实验

目录

GIC相关寄存器

GPIO中断相关寄存器

中断服务函数表

中断向量表偏移位置

make有报错

解决方法:error: 'for' loop initial declarations are only allowed in C99 mode_‘for’ loop initial declarations are only allowed i_Young_2717的博客-CSDN博客


GIC相关寄存器

  • 分发器

    • 中断数量:GICD_TYPER

    • 中断清除: GICD_ ICENABLERn

    • 中断使能:GICD_ISACTIVERn

    • 中断优先级设置:GICD_IPRIORITYR

    详见GIC官方手册

    4.3 Distributor register descriptions

  • cpu接口单元

    • 中断优先级数量:GICC_PMR

    • 抢占优先级和子优先级设置: GICC_BPR

    • 保存中断ID:GICC_IAR

    • 通知cpu中断完成:GICC_EOIR

    详见GIC官方手册

    4.4 CPU interface register descriptions

GPIO中断相关寄存器

  • gpio中断触发类型:高/低电平、上升/下降沿

    • GPIO5_ICR1(0~15)

    • GPIO5_ICR2(16~31)

  • gpio中断屏蔽

    • GPIO5_IMR

  • gpio中断状态寄存器

    • GPIO5_ISR

  • gpio双边缘触发

    • GPIO5_EDGE_SEL

    详见芯片数据手册

  • 28.5 GPIO Memory Map/Register Definition

中断服务函数表

记录每个IRQ中断的回调函数

  • 函数指针

  • 函数参数

中断向量表偏移位置

C语言读写cp15协处理器

__ASM ( code : 输出操作数列表 : 输入操作数列表 );

  • code

    • 具体操作指令(字符串表示)

    • #是把宏参数变为一个字符串

    • ##是把两个参数连接在一起

    __STRINGIFY(p##coproc) ", ->"p15"

  • 操作数

    通过%加数字引用,比如%0 引用第一个操作数,%1 引用第二个操作数

    r:将变量放入通用寄存器

button.c

#include  "button.h"

#include "interrupt.h"



/*按键初始化函数*/

void button_init(void)

{

    /**********************************第一部分***********************************/

    /*时钟初始化*/

    CCM->CCGR1 = 0xffffffff;



    /*设置 key引脚的复用功能以及PAD属性*/

    IOMUXC_SetPinMux(IOMUXC_SNVS_SNVS_TAMPER1_GPIO5_IO01,0);     

    IOMUXC_SetPinConfig(IOMUXC_SNVS_SNVS_TAMPER1_GPIO5_IO01, 0x10B0); 

    

    /*设置GPIO5_01为输入模式*/

    GPIO5->GDIR &= ~(1<<1);  





    /**********************************第二部分**************************************/

    /*使能GPIO5_1中断*/

    GPIO5->IMR |= (1<<1);



    /*禁止GPIO5_1中断双边沿触发*/

     GPIO5->EDGE_SEL  =  0;



     /*设置GPIO5_1上升沿触发*/

     GPIO5->ICR1 |= (2<<2);



    /*添加中断服务函数到  "中断向量表"*/

     system_register_irqhandler(GPIO5_Combined_0_15_IRQn, (system_irq_handler_t)GPIO5_1_IRQHandler, NULL);



     /*开启GIC中断相应中断*/

     GIC_EnableIRQ(GPIO5_Combined_0_15_IRQn);



}



void GPIO5_1_IRQHandler(void)

{

    /*按键引脚中断服务函数*/

    if((GPIO5->DR)&(1<<1)){

         if(button_status > 0){

            button_status = 0;

        }

        else{

            button_status = 1;

        }

    }

    /*清除Gpio5_1中断标志位*/

    GPIO5->ISR |= (1 << 1);  

   

}

make有报错

gec@ubuntu:~/bare_mental/part_5$ make 
mkdir -p build
arm-none-eabi-gcc -c sources/project/main.c -o build/main.o   -Iinclude  -Isources/button  -Isources/common  -Isources/irq  -Isources/led 
arm-none-eabi-gcc -c sources/common/common.c -o build/common.o   -Iinclude  -Isources/button  -Isources/common  -Isources/irq  -Isources/led 
arm-none-eabi-gcc -c sources/irq/interrupt.c -o build/interrupt.o   -Iinclude  -Isources/button  -Isources/common  -Isources/irq  -Isources/led 
sources/irq/interrupt.c: In function 'irq_init':
sources/irq/interrupt.c:18:5: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
     for(int i = 0; i < NUMBER_OF_INT_VECTORS; i++)
     ^
sources/irq/interrupt.c:18:5: note: use option -std=c99, -std=gnu99, -std=c11 or -std=gnu11 to compile your code
Makefile:42: recipe for target 'build/interrupt.o' failed

解决方法:error: 'for' loop initial declarations are only allowed in C99 mode_‘for’ loop initial declarations are only allowed i_Young_2717的博客-CSDN博客

使用gcc编译代码是报出

error: 'for' loop initial declarations are only allowed in C99 mode

note: use option -std=c99 or -std=gnu99 to compile your code

错误,这是因为在gcc中直接在for循环中初始化了增量:
    for(int i=0; i<len; i++) {
    }
这语法在gcc中是错误的,必须先先定义i变量:
int i;
for(i=0;i<len;i++){
 
}

这是因为gcc基于c89标准,换成C99标准就可以在for循环内定义i变量了:

gcc src.c -std=c99 -o src

也就是

就可以了

猜你喜欢

转载自blog.csdn.net/qq_51519091/article/details/132380129