board/timer4led.c
#include "stdio.h"
#include "s5pv210.h"
void t4_init()
{
//TCFG0[15:8] = 99 //设置t4预分频值
rTCFG0 &=~(0xff<<8);
rTCFG0 |=(0x63<<8);
//TCFG1[19:16] = 0100 //选择PWM定时器的选通输入
rTCFG1 &=~(0xf<<16);
rTCFG1 |=(0x4<<16);
//TCNTB4[] = 41250
rTCNTB4=41250;
// 计数器大小66MHZ/(99+1)/16。这里为1秒
//TINT_CSTAT[4]=1;[9]=1;//定时器中断激活,而且状态位,写1清除
rTINT_CSTAT |=(0x210<<0);
//TCON[21] = 1;
//TCON[21] = 0;
//TCON[22] = 1; //auto reload 相当于开关中断
rTCON &=~(0x3<<21);
rTCON |=(0x3<<21);
rTCON &=~(0x1<<21);
}
void Timer4_isr()
{
printf("timer4 time out\n");
//TINT_CSTAT[9] = 1; clear flag
rTINT_CSTAT |=(0x1<<9);
rVIC0ADDRESS = 0x0;
rGPJ2DAT ^=(0x1<<0);
//rGPD0DAT ^=(0x1<<0);
}
void t4_vic0init()
{
//VIC0INTENCLEAR[25] = 0
rVIC0INTENCLEAR &=~(0x1<<25);
//VIC0INTSELECT[25] = 0 -> EINT16 IRQ
rVIC0INTSELECT &=~(0x1<<25);
//VIC0INTENABLE[25] = 1 -> EINT16 ENABLE
*((unsigned int *)0xf2000164) = (unsigned int)Timer4_isr;
rVIC0ADDRESS = 0x0;
rVIC0INTENABLE |=(0x1<<25);
}
void t4_onoff()
{
//TCON[20] = 1;
rTCON |=(0x1<<20);
}
void led_init()
{
//GPJ2CON[3:0] = 0B0001
rGPJ2CON &=~(0xffff<<0);
rGPJ2CON |=(0x1111<<0);
//GPJ2DAT[0] = 0/1
rGPJ2DAT |=(0xf<<0);
rGPD0CON &=~(0xf<<0);
rGPD0CON |=(0x1<<0);
//rGPD0DAT |=(0xf<<0);
}
int timer4led()
{
led_init();
t4_init();
t4_vic0init();
t4_onoff();
//while(1);
}
cpu/board.c
#include "stdio.h"
#include "api.h"
int start_armboot()
{
printf(">>>>> welcome to c <<<<<<<\n");
timer4led();
return 0;
}
cpu/start.S
.text
.extern uart_init
.extern printf
.extern start_armboot
.global _start
_start:
mov r5,lr
bl uart_init
ldr r0,=fmt
bl printf
bl exc_vectable
bl cpsr_init
bl start_armboot
return_uboot:
mov lr,r5
bx lr
cpsr_init:
mrs r0,cpsr
bic r0,r0,#0xc0
msr cpsr,r0
bx lr
exc_vectable:
ldr r0,=Handler_IRQ
ldr r1,=0xd0037418
@iram里的地址
str r0,[r1]
bx lr
Handler_IRQ:
sub lr,lr,#4
stmfd sp!,{r0-r12,lr}
ldr lr,=return_irq
ldr r0,=0xf2000000
@vic0地址
ldr r1,[r0]
cmp r1,#0
beq return_irq
ldr r0,=0xf2000f00
@VIC0ADDRESS地址
ldr pc,[r0]
return_irq:
ldmfd sp!,{r0-r12,pc}^
fmt:
.asciz ">>>>> welcome to arm <<<<<<<\n"
.end
makefile
CC = arm-linux-gcc
LD = arm-linux-ld
OBJCOPY = arm-linux-objcopy
INCLUDEDIR := $(shell pwd)/include/
CPPFLAGS := -nostdinc -nostdlib -I$(INCLUDEDIR)
CFLAGS := -fno-builtin -Wall -O2
export CC LD OBJCOPY CPPFLAGS CFLAGS
OBJS := cpu/start.o cpu/board.o board/timer4led.o lib/uart.o lib/libc.a
all:start.bin clean
start.bin:$(OBJS)
$(LD) -Ttext=0x40000000 $(OBJS) -o start.elf
$(OBJCOPY) -O binary -S start.elf $@
%.o:%.S
$(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
%.o:%.c
$(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
clean:
rm -rf ./start.elf
make clean -C cpu
make clean -C board
说明:
这里要用到中断,因为没有输出,内部进行定时。
参考:
http://blog.chinaunix.net/uid-28458801-id-3808196.html