you

watdog(3)

把watdog一直开着,当来一个watdog 中断,打印一句话,当灯亮/灯灭。

*********************************************************************************

watdog.h:

//interrupt

#define VIC0INTENABLE(*(volatile unsigned long *)0x71200010

#define VIC0INTSELECT (*(volatile unsigned long *)0x7120000C)

//模拟watdog
#define VIC0SOFTINT (*(volatile unsigned long *)0x71200018)
#define VIC0SOFTINTCLAR (*(volatile unsigned long *)0x7120001C)
//watdog
#define WTCON    (*(volatile unsigned long *)0x7E004000) 
#define WTDAT    (*(volatile unsigned long *)0x7E004004) 
#define WTCNT    (*(volatile unsigned long *)0x7E004008) 
#define WTCLRINT (*(volatile unsigned long *)0x7E00400C)
//led
#define GPMCON (*(volatile unsigned long *)0x7F008820)
#define GPMDAT (*(volatile unsigned long *)0x7F008824)

*****************************************************************************

test.c:

#include "watdog.h"
void hander_irq();
int (*printf)(char *,...) = (void *)0x57e11d4c;
int tmp=0;
int main()
{
*(volatile unsigned long *)0x56000000 = hander_irq;
//cpsr
__asm__ __volatile__(


"mrs r0,cpsr\n"
"bic r0,r0,#0x80\n"
"msr cpsr,r0\n"
:
:
:"r0","memory"
);
//enable
VIC0INTENABLE |=(1<<26);
//select
VIC0INTSELECT &=~(1<<26);
  //softirq
// VIC0SOFTINT |=(1<<26);


//watdog
WTCON = (1<<2)|(0<<3)|(1<<5)|(255<<8);

//如果WTCON=(1<<0)|(1<<2)|(0<<3)|(1<<5)|(255<<8);中断来的时候就是重启
WTCNT = 0x8000;
WTDAT = 0x8000;
//led
GPMCON = (1<<0)|(1<<4)|(1<<8)|(1<<12);
}
void hander_irq()
{
WTCLRINT = 0;//清楚watdog,wadcnt减完了又会来一次中断,watdat又填充watcnt
printf("this is wat_dong:wang wang\n");
if(tmp == 0)
{
GPMDAT = 0;
tmp = 1;
}
else
{
GPMDAT = 0xf;
tmp = 0;
}
}

*********************************************************************************

vector.s

b reset
b und
b swi
b pre_abt
b data_abt
.word 0x0
b irq
b firq
reset:
und:
mov sp,#0x56000000
mov ip,sp
stmdb sp!,{fp,ip,lr}
sub fp,ip,#4

ldr r0,=string_und
ldr r1,printf
blx r1

mov sp,#0x56000000
ldmdb sp,{fp,sp,pc}^
swi:
mov sp,#0x56000000
mov ip,sp
stmdb sp!,{fp,ip,lr}
sub fp,ip,#4

ldr r0,=string_swi
ldr r1,printf
blx r1

mov sp,#0x56000000
ldmdb sp,{fp,sp,pc}^
pre_abt:
data_abt:
mov sp,#0x56000000
mov ip,sp
sub lr,lr,#4
stmdb sp!,{fp,ip,lr}
sub fp,ip,#4

ldr r0,=string_pre_abt
ldr r1,printf
blx r1

mov sp,#0x56000000
ldmdb sp,{fp,sp,pc}^
irq:
mov sp,#0x56000000
mov ip,sp
sub lr,lr,#4
stmdb sp!,{fp,ip,lr}
sub fp,ip,#4
# 调用函数
mov r0,#0x56000000
ldr r1,[r0]
blx r1

mov sp,#0x56000000
ldmdb sp,{fp,sp,pc}^
firq:
printf:
.word 0x57e11d4c
string_und:
.asciz "hello undefine \n"
.align 2
string_swi:
.asciz "hello swi\n"
.align 2
string_pre_abt:
.asciz "hell data_abt\n"
.align 2
string_irq:
.asciz "hello irq ,wang wang wang  \n"
.align 2

*******************************************************************


makefile同以前。


阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/youhaibo1990/article/details/17144433
文章标签: watdog
个人分类: [ bootloader-6410X ]
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

watdog(3)

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭