code of blink led

Sean McNeil sean at mcneil.com
Thu Jun 5 19:29:40 CEST 2008


Hi,

I'm not sure why you want to reinvent/recode the startup. Usually one 
just uses ld or gcc (which ends up calling ld) with a program and lets 
it add in the crt*.o that it determines you need. Then your main() gets 
run without any problem.

Also, when you are accessing hardware in an application, you usually 
don't go into the harware registers but you use an abstraction layer. 
For the LEDs, this would be accessing /sys/class/leds/*.

Here is an example of how I use the LEDs...

1) put into trigger mode so I can blink them: write "trigger" to 
/sys/class/leds/gta02-aux:red/trigger
2) write the amount of time off to /sys/class/leds/gta02-aux:red/delay_off
3) write the amount of time on to /sys/class/leds/gta02-aux:red/delay_on

On the GTA02, there are 3 LEDs. They are behind the buttons. The red LED 
is behind the aux button on the upper left of the device. The Blue and 
Amber are under the power button. You can essentially make 3 colors 
under the power button: Blue, Amber, or Purple (both on).

Once you have your program, you can either run it directly over an nfs 
mount to your host computer from the phone, copy onto the phone with 
ssh, ftp, or some other mechanism, put on an sdcard, or some other 
method depending on your resources and needs.

Cheers,
Sean

xiangfu wrote:
> Hi
> I write some code. but i don't know how to download it to GTA02
> and how to run it?
> another question :
>    where is the GTA02's LED? :-)
>    what is the best TEXT_BASE value
>
>
> ::::::::::::::
> led.c
> ::::::::::::::
> extern void delay(int time);
> #define GPBCON        (*(volatile unsigned *)0x56000010)
> #define GPBDAT        (*(volatile unsigned *)0x56000014)
> #define GPBUP        (*(volatile unsigned *)0x56000018)  #define    
> LED3_ON()    (GPBDAT &= ~(0x1)) #define    LED4_ON()    (GPBDAT &= 
> ~(0x2))  #define    LED3_OFF()   (GPBDAT |= (0x1))
> #define    LED4_OFF()   (GPBDAT |= (0x2))
> void main()
> {
>    GPBCON = 0x5;
>    GPBUP = 0xffff;
>    while(1)
>    {
>    LED3_ON();
>    delay(0xfffff);
>    LED4_ON();
>    delay(0xfffff);
>    LED3_OFF() ;
>    delay(0xfffff);
>    LED4_OFF();
>    delay(0xfffff);     }
> }
> ::::::::::::::
> led.s
> ::::::::::::::
> .text
> .global _start
>    ldr sp,=1024*4
> .extern main
>    bl main
> .global delay
> delay:
>    sub   r0,r0,#1
>    cmp   r0,#0x0
>    bne   delay
>    mov   pc,lr
> .end
>   ::::::::::::::
> Makefile
> ::::::::::::::
> CROSS_COMPILE=arm-angstrom-linux-gnueabi-
> TEXT_BASE=0x0000000
> led_on: led.s led.c
>    $(CROSS_COMPILE)gcc -g -c -o led.o led.s
>    $(CROSS_COMPILE)gcc -g -c -o led_on.o led.c
>    $(CROSS_COMPILE)ld -Ttext $(TEXT_BASE) -g led.o led_on.o  -o 
> led_on_c.o
>    $(CROSS_COMPILE)objcopy -O binary -S led_on_c.o led_on
>
> clean:
>    rm -f *.o
>    rm -f led_on
>





More information about the openmoko-kernel mailing list