因为刚接触uboot,对uboot的原理没有很深的理解,就从简单的点亮LED做起吧。ok6410里的移植好的uboot运行后这时4个LED灯中LED1,LED3亮,LED2,LED4灭,这2个LED会亮的设置我找了半天也没找到,索性不找了。
查看原理图得知4个LED用了GPM0-3,找到寄存器地址是0x7F008000,只要设置GPMCON和GPMDAT就行了,GPMPUD默认就好。
写了个简单的led.c,源码如下,再简单不过了,只做测试,如要好看,可以把延迟写成函数,灯跳转写个算法:
编译生成led.bin后用dnw 50008000下载,go 50008000,运行可看到灯亮,我原以为0是亮的,结果是1是亮,我懒得改了,知道就行。
void (*show)(char *,...) = 0xcfe121d0;
#define CFG_LED_GMPCON 0x7F008820
#define CFG_LED_BASE 0x7F008824
#define led_toggle(_msk) \
do { \
*((volatile long *) (CFG_LED_BASE)) ^= (_msk); \
} while(0)
#define led_set(_msk, _st) \
do { \
if ((_st)) \
*((volatile long *) (CFG_LED_BASE)) &= ~(_msk); \
else \
*((volatile long *) (CFG_LED_BASE)) |= (_msk); \
} while(0)
#define led_init() \
do { \
*((volatile long *) (CFG_LED_GMPCON)) |= 0x1111; \
*((volatile long *) (CFG_LED_BASE)) |= 0x34; \
} while(0)
int main(void)
{
long i,j=20;
show("\nLED TEST\n");
show("ganlan style!\n");
led_init();
while(j)
{
led_set(0x00000001,0);
led_set(0x00000002,1);
led_set(0x00000004,1);
led_set(0x00000008,1);
for(i=0;i<0x00100000;i++)
{
}
led_set(0x00000001,1);
led_set(0x00000002,0);
led_set(0x00000004,1);
led_set(0x00000008,1);
for(i=0;i<0x00100000;i++)
{
}
led_set(0x00000001,1);
led_set(0x00000002,1);
led_set(0x00000004,0);
led_set(0x00000008,1);
for(i=0;i<0x00100000;i++)
{
}
led_set(0x00000001,1);
led_set(0x00000002,1);
led_set(0x00000004,1);
led_set(0x00000008,0);
for(i=0;i<0x00100000;i++)
{
}
led_set(0x00000001,0);
led_set(0x00000002,0);
led_set(0x00000004,0);
led_set(0x00000008,0);
for(i=0;i<0x00100000;i++)
{
}
j--;
}
return 0;
}