led灯点亮
手工點亮led arm匯編
start_led: mov r0,#8mov r1,#0 bl _gpio_direction_output mov r1,#0x500000 delayloop:nop sub r1,r1,#1cmp r1,#0bne delayloopmov r0,#8mov r1,#1 bl _gpio_direction_output nop mov r1,#0x500000 delayloop2:nop sub r1,r1,#1cmp r1,#0bne delayloop2/* bl _arm_blink_led */b start_ledC點亮led
int _arm_blink_led() {__asm__ __volatile__ ( "start_led:\n\t""mov r0,#8\n\t""mov r1,#0\n\t""bl _gpio_direction_output\n\t""mov r1,#0x500000\n\t" "delayloop:\n\t""nop\n\t""sub r1,r1,#1\n\t""cmp r1,#0\n\t""bne delayloop\n\t""mov r0,#8\n\t""mov r1,#1\n\t""bl _gpio_direction_output\n\t""nop\n\t""mov r1,#0x500000\n\t" "delayloop2:\n\t""nop\n\t""sub r1,r1,#1\n\t""cmp r1,#0\n\t""bne delayloop2\n\t" "b start_led\n\t");}
while(1);燈滅for (i=0,init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr,i++) {if ((*init_fnc_ptr)() != 0) {hang ();}?? ??? ?if(i==0)while(1);//燈滅if(i==1)while(1);//燈亮void start_armboot (void) {init_fnc_t **init_fnc_ptr;char *s;int i; #ifndef CFG_NO_FLASHulong size; #endif #if defined(CONFIG_VFD) || defined(CONFIG_LCD)unsigned long addr; #endif/* Pointer is writable since we allocated a register for it */gd = (gd_t*)(_armboot_start - CFG_MALLOC_LEN - sizeof(gd_t));/* compiler optimization barrier needed for GCC >= 3.4 */__asm__ __volatile__("": : :"memory");memset ((void*)gd, 0, sizeof (gd_t));gd->bd = (bd_t*)((char*)gd - sizeof(bd_t));memset (gd->bd, 0, sizeof (bd_t));monitor_flash_len = _bss_start - _armboot_start;gpio_direction_output(8, 0);//while(1);燈亮 }
start.s 調用c的方法
X:\c300\uboot\board\mindspeed\c300v2evm\board.cint _gpio_direction_output(unsigned gpio, int level) { gpio_direction_output(gpio,level);return 0;} X:\c300\uboot\include\asm\arch\comcerto-300.h #ifndef __ASSEMBLY__ #include <asm/types.h> void comcerto300_init(void); int comcerto300_set_fcs(int enable, u8 cs, int base_addr, int size); int comcerto300_set_cs_type(u8 cs, int sdram_enable); int comcerto300_set_cs_region(u8 cs, u32 base, u32 size); int comcerto300_set_cse(u8 cs, int enable); void comcerto300_set_cse_highmem_to_cs1(int enable); int comcerto300_uexp_cfg_cs(u8 cs, u16 cfga, u16 cfgb, u16 cfgc); void comcerto300_pll_set_clocks(u32 arm_clock, u32 bus_clock, u32 spu_clock); void comcerto300_pll_set_arm_clock(u16 clkf, u16 clkr, u16 clkod); void comcerto300_pll_set_spu_clock(u16 clkf, u16 clkr, u16 clkod); void comcerto300_pll_set_amba_clock(u16 clkf, u16 clkr, u16 clkod); void comcerto300_ntg_8mhz_init(void); int _gpio_direction_output(unsigned gpio, int level);#endif X:\c300\uboot\cpu\arm1136\start.Smov r0,#8 mov r1,#0 bl _gpio_direction_outputffff: b ffff
int board_init(void) {/* reset on-board peripherals via GPIO line */gpio_direction_output(CFG_GPIO_OUT_PERIPHERAL_RESET, 0);while(1);udelay(100);gpio_set_value(CFG_GPIO_OUT_PERIPHERAL_RESET, 1);/* CS0 is used for SDRAM, see bsp_init() *//* CS1 and CS2 used for flash memories */nor_init();
static int __init mru_init(void) {if(misc_register(&misc)){printk(KERN_ERR "failed to register mru\n");return -1;}mru_led_enable = 0;mru_led_stat = 0;gpio_direction_output(MRU_STAT_PIN, mru_led_stat);setup_timer(&mru_timer, mru_timer_proc, (unsigned long)&mru_timer);mod_timer(&mru_timer, jiffies + msecs_to_jiffies(50));printk(KERN_INFO "register mru\n");return 0; } static void mru_timer_proc(unsigned long data) {if(mru_led_enable && ++mru_led_count >= 10){mru_led_count = 0;mru_led_stat = !mru_led_stat;gpio_set_value(MRU_STAT_PIN, mru_led_stat);}mod_timer((struct timer_list*)data, jiffies + msecs_to_jiffies(50)); } 在linux驅動中常常會碰到gpio_set_value(port_num,0/1)或gpio_direction_output (port_num,0/1) 這兩者有什么關系呢gpio_set_value(port_num,0/1) 一般只是在這個GPIO口的寄存器上寫上某個值,至于這個端口是否設置為輸出,它就管不了!而gpio_direction_output (port_num,0/1),在某個GPIO口寫上某個值之后,還會把這個端口設置為輸出模式。 因此,有人也許就會建議,把gpio_set_value這個函數直接去掉不用,是否可以,顯然是可以的。 但是為什么系統還要用呢, 我個人分析是, 系統開發人員在要結合這兩者來使用,以便提高效率。 一般某個端口設置好了輸入與輸出模式后,最好不要經常變動。 首先要調用gpio_direction_output(),以后要設置高低電平時,直接使用gpio_set_value()就可以了,這樣可以省卻再次調用設置輸出模式的操作,從而提高運行效率!
Control and status reporting for the GPIO resources is provided through nine registers. The base address for the
GPIO control registers is mapped to 0x10070000. The GPIO control registers can be accessed by adding the
associated “Offset” to the GPIO base address.
| 54 | r | 32 | GPIO中斷狀態寄存器 | ? | ? |
| 54 | w | ? | GPIO中斷狀態寄存器清除 | ? | ? |
| ? | ? | ? | ? | ? | ? |
| 58 | RW | ? | 中斷屏蔽寄存器 | 0 | 0 禁止中斷 |
| 5c | RW | ? | Watchdog Timer to GPIO Select Register (default: ‘0’) | 0 | ? |
| 64 | rw | ? | Bootstrap Pin Override Register (default : all ‘0’). The control bits in this register allow the programmer to override the bootstrap pins on the device. | ? | ? |
| ? | ? | ? | ? | ? | ? |
| ? | ? | ? | ? | ? | ? |
| ? | ? | ? | ? | ? | ? |
| ? | ? | ? | ? | ? | ? |
| ? | ? | ? | ? | ? | ? |
| 0 | RW | 32 | GPIO 寫 | 缺省全0 | ? |
| 4 | rw | 32 | GPIO寫使能 | 缺省全0 | 1 輸出使能 0 輸入使能 |
| 8 | RW | ? | 上升沿中斷使能 | 缺省0 | 1使能(僅當電平中斷使能沒有配置) |
| c | RW | ? | 下降沿中斷使能 | 0 | 1使能 |
| 10 | R | ? | 輸入寄存器 | ? | 表示每個管腳的狀態 |
| 18 | RW | ? | 復用配置寄存器 | 0 | ? |
| 1c | R | ? | 系統狀態寄存器 | ? | 0 Status of ARAMBOOT_n pin In Normal Mode, EPROM = H and ARAMBOOT= L enable boot from internal ARAM. |
| 28 | RW | ? | tdm復用控制寄存器 | "0010000_00000000 | ? |
| 34 | RW | ? | DDR SSTL Buffer Type Register | (default: “00000000_00000001”) | ? |
| 50 | RW | ? | 電平中斷使能寄存器 | 0 | 1 使能 |
總結
- 上一篇: 交易系统解析(六) -- 前台报盘应用
- 下一篇: 基于Java的石头迷阵小游戏的设计与实现