nvic.c

来自「ARM公司ATC培训的所有练习源码」· C语言 代码 · 共 53 行

C
53
字号
#include "nvic.h"

#define REGION_128K 0x20
#define REGION_256K 0x22
#define REGION_512K 0x24
#define REGION_1M   0x26

/* -- Interrupt Wiring in ISSM --
        timer.TimerInt0 => intn.int5;
        timer.TimerInt1 => intn.int6;
        timer.TimerInt2 => intn.int7;
        uart.UART_INTR => intn.int1;
*/

#pragma arm section zidata="nvic_registers"

NVIC_t NVIC;

#pragma arm section


void NVIC_init(void)
{
    /***Example MPU initialisation code***/

    /* Configure region 1 to cover ROM (Executable, Read-only) */
    /* Start address, Region field valid, Region number */
    NVIC.MPU.RegionBaseAddr = 0x00000000 | 0x10 | 1;
    /* Access control bits, Size, Enable */
    NVIC.MPU.RegionAttrSize = 0x06030000 | REGION_128K | 0x1;

    /* Configure a region to cover RAM (Executable, Read-Write) */
    NVIC.MPU.RegionBaseAddr = 0x20000000 | 0x10 | 2;
    NVIC.MPU.RegionAttrSize = 0x03030000 | REGION_128K | 0x1;

    /* Configure a region to cover Heap and Stack (Not Executable, Read-Write) */
    NVIC.MPU.RegionBaseAddr = 0x20100000 | 0x10 | 3;
    NVIC.MPU.RegionAttrSize = 0x13030000 | REGION_1M | 0x1;

    /* Configure a region to cover UART Registers (Not Executable, Read-Write) */
    NVIC.MPU.RegionBaseAddr = 0x40018000 | 0x10 | 4;
    NVIC.MPU.RegionAttrSize = 0x13030000 | REGION_128K | 0x1;
    
    /* Enable the MPU */
    NVIC.MPU.Ctrl |= 1;
}

void NVIC_enableISR(unsigned isr)
{
    /* No need to do a read-modify-write; writing a 0 to the enable register does nothing */
    NVIC.IRQ.Enable[ (isr/32) ] = 1<<(isr % 32);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?