微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 内存管理单元MMU 地址映射一

内存管理单元MMU 地址映射一

时间:11-28 来源:互联网 点击:

MMU_SECDESC;

virtuladdr = 0xB0000000;

physicaladdr = 0x30000000;

while (virtuladdr < 0xB4000000)

{

*(mmu_tlb_base + (virtuladdr >> 20)) = (physicaladdr & 0xFFF00000) |

MMU_SECDESC_WB;

virtuladdr += 0x100000;//右移20位就是1

physicaladdr += 0x100000;//右移20位就是1

}

}

void mmu_init(void)

{

unsigned long ttb = 0x30000000;

__asm__(

"mov r0, #0"

"mcr p15, 0, r0, c7, c7, 0"

"mcr p15, 0, r0, c7, c10, 4"

"mcr p15, 0, r0, c8, c7, 0"

"mov r4, %0"

"mcr p15, 0, r4, c2, c0, 0"

"mvn r0, #0"

"mcr p15, 0, r0, c3, c0, 0"

"mrc p15, 0, r0, c1, c0, 0"

"bic r0, r0, #0x3000"

"bic r0, r0, #0x0300"

"bic r0, r0, #0x0087"

"orr r0, r0, #0x0002"

"orr r0, r0, #0x0004"

"orr r0, r0, #0x1000"

"orr r0, r0, #0x0001"

"mcr p15, 0, r0, c1, c0, 0"

:

: "r" (ttb) );

}

#define GPBCON (*(volatile unsigned long *)0xA0000010) // 物理地址0x56000010

#define GPBDAT (*(volatile unsigned long *)0xA0000014) // 物理地址0x56000014

#define GPB5_out (1<(5*2))

#define GPB6_out (1<(6*2))

#define GPB7_out (1<(7*2))

#define GPB8_out (1<(8*2))

static inline void wait(unsigned long dly)

{

for(; dly > 0; dly--);

}

int main(void)

{

unsigned long i = 0;

// 将LED1-4对应的GPB5/6/7/8四个引脚设为输出

GPBCON = GPB5_out|GPB6_out|GPB7_out|GPB8_out;

while(1){

wait(30000);

GPBDAT = (~(i<5)); // 根据i的值,点亮LED1-4

if(++i == 16)

i = 0;

}

return 0;

}

最后是Makefile

objs := head.o init.o leds.o

mmu.bin : $(objs)

arm-linux-ld -Tmmu.lds -o mmu_elf $^

arm-linux-objcopy -O binary -S mmu_elf $@

arm-linux-objdump -D -m arm mmu_elf > mmu.dis

%.o:%.c

arm-linux-gcc -Wall -O2 -c -o $@ $

%.o:%.S

arm-linux-gcc -Wall -O2 -c -o $@ $

clean:

rm -f mmu.bin mmu_elf mmu.dis *.o

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top