s3c2410_gpio_cfgpin(S3C2410_GPB0, S3C2410_GPB0_TOUT0); 我們可以這樣控制外設(shè)寄存器,想過它怎么實(shí)現(xiàn)的嗎?
首先分析下structmachine_desc (include/asm-arm/Mach/Arch.h)
這是一個(gè)非常重要的結(jié)構(gòu)體,內(nèi)核通過 machine_desc 來控制體系架構(gòu)相關(guān)部分的初始化,包括map_io,init_irq,init_machine,pthys_io,timer等
本文引用地址:http://butianyuan.cn/article/201611/316658.htmstructmachine_desc{ /* * Note! The first five elements are used * by assembler code in head-armv.S */ unsignedintnr;/* architecture number*/ unsignedintphys_ram;/* start of physical ram */ unsignedintphys_io;/* start of physical io*/ unsignedintio_pg_offst;/* byte offset for io * page tabe entry*/ constchar*name;/* architecture name*/ unsignedlongboot_params;/* tagged list*/ unsignedintvideo_start;/* start of video RAM*/ unsignedintvideo_end;/* end of video RAM*/ unsignedintreserve_lp0:1;/* never has lp0*/ unsignedintreserve_lp1:1;/* never has lp1*/ unsignedintreserve_lp2:1;/* never has lp2*/ unsignedintsoft_reboot:1;/* soft reboot*/ void(*fixup)(structmachine_desc*, structtag*,char**, structmeminfo*); void(*map_io)(void);/* IO mapping function*/ void(*init_irq)(void); structsys_timer*timer;/* system tick timer*/ void(*init_machine)(void); }; |
那我們?cè)趺磩?chuàng)建自己的machine_desc呢?
內(nèi)核給我們提供了一個(gè)宏:
#defineMACHINE_START(_type,_name)/ conststructmachine_desc __mach_desc_##_type/ __attribute__((__section__(".arch.info.init")))={/ .nr=MACH_TYPE_##_type,/ .name=_name, #defineMACHINE_END/ }; |
這樣我們就可以定義自己的machine_desc了
MACHINE_START(SMDK2410,"SMDK2410")/* @TODO: request a new identifier and switch * to SMDK2410 */ /* Maintainer: Jonas Dietsche */ .phys_ram=S3C2410_SDRAM_PA, .phys_io=S3C2410_PA_UART, .io_pg_offst=(((u32)S3C24XX_VA_UART)>>18)&0xfffc, .boot_params=S3C2410_SDRAM_PA+0x100, .map_io=smdk2410_map_io, .init_irq=smdk2410_init_irq, .init_machine=sdmk2410_init, .timer=&s3c24xx_timer, MACHINE_END |
這里我們創(chuàng)建了 machine_desc,并給其中一些成員賦了值,這相當(dāng)于是內(nèi)核給我們提供的編程接口,這樣就可以調(diào)用自己的函數(shù)了。
這其中map_io 在 setup_arch 中調(diào)用調(diào)用,我們跟進(jìn)去會(huì)發(fā)現(xiàn):
在smdk2410_map_io-->s3c24xx_init_io(smdk2410_iodesc, ARRAY_SIZE(smdk2410_iodesc))->iotable_init(s3c_iodesc, ARRAY_SIZE(s3c_iodesc)) 看到:
void__init iotable_init(structmap_desc*io_desc,intnr) { inti; for(i=0;icreate_mapping(io_desc+i); } |
就是在這里調(diào)用create_mapping()創(chuàng)建的頁(yè)表,這里的第一個(gè)參數(shù),map_desc 定義如下:
structmap_desc{ unsignedlongvirtual; unsignedlongphysical; unsignedlonglength; unsignedinttype; }; |
create_mapping()就是通過這個(gè)結(jié)構(gòu)體創(chuàng)建的映射表,這樣我們可以通過創(chuàng)建 map_desc 然后傳給這個(gè)函數(shù)就可以創(chuàng)建相應(yīng)的 虛擬地址-->物理地址 映射.
在 inlcude/asm-arch/Arch-s3c2410/Map.h
定義了每一種資源用于 map_desc變量的宏定義,如:
/* MMC controller - available on the S3C2400 */ #defineS3C2400_VA_MMC S3C2400_ADDR(0x00700000) #defineS3C2400_PA_MMC (0x15A00000) #defineS3C2400_SZ_MMC SZ_1M
/* UARTs */ #defineS3C24XX_VA_UART S3C2410_ADDR(0x00800000) #defineS3C2400_PA_UART(0x15000000) #defineS3C2410_PA_UART(0x50000000) #defineS3C24XX_SZ_UART SZ_1M
/* Timers */ #defineS3C24XX_VA_TIMER S3C2410_ADDR(0x00900000) #defineS3C2400_PA_TIMER(0x15100000) #defineS3C2410_PA_TIMER(0x51000000) #defineS3C24XX_SZ_TIMER SZ_1M |
然后針對(duì)具體的某個(gè)外設(shè),有具體寄存器的定義,如:
include/asm/arch-s3c2410/regs-timer.h
#ifndef__ASM_ARCH_REGS_TIMER_H #define__ASM_ARCH_REGS_TIMER_H"$Id: timer.h,v 1.4 2003/05/06 19:30:50 ben Exp $"
#defineS3C2410_TIMERREG(x)(S3C24XX_VA_TIMER+(x)) #defineS3C2410_TIMERREG2(tmr,reg)S3C2410_TIMERREG((reg)+0x0c+((tmr)*0x0c))
#defineS3C2410_TCFG0 S3C2410_TIMERREG(0x00) #defineS3C2410_TCFG1 S3C2410_TIMERREG(0x04) #defineS3C2410_TCON S3C2410_TIMERREG(0x08)
#defineS3C2410_TCFG_PRESCALER0_MASK(255<<0) #defineS3C2410_TCFG_PRESCALER1_MASK(255<<8) #defineS3C2410_TCFG_PRESCALER1_SHIFT(8) #defineS3C2410_TCFG_DEADZONE_MASK(255<<16) #defineS3C2410_TCFG_DEADZONE_SHIFT(16) ......................... |
評(píng)論