在线时间0 小时
UID2044460
注册时间2013-9-26
NXP金币0
该用户从未签到
新手上路

- 积分
- 21
- 最后登录
- 1970-1-1
|
以下是我测试看门狗的代码,系统会不断复位,但复位后没有打印“wdog_isr”。 没有调用到中断处理函数wdog_isr. 不知何故?
void wdog_isr(void)
{
UART_printf("wdog_isr\n");
}
//test wdog
void test_wdog(void)
{
int cnt = 0;
int cnt2 = 0;
wdog_init(10000,wdog_isr); //10s timeout
PIT_Init(0, 1/*ms*/, (uint32_t) pit_isr, 15);
UART_printf("============test_wdog============\n");
.........
UART_printf("2. do not feed dog . system will reset in 10sec:\n");
cnt = 0;
while(1) {
if(g_SysTimerMs > 1000) {
UART_printf(" %d",cnt++);
g_SysTimerMs = 0;
}
}
}
/////////////////////////////////////////////
void wdog_init(uint16_t timeOutMs /*ms*/,void (*timeout_isr)(void))
{
uint32_t Value;
uint16_t timeOutValueH;
uint16_t timeOutValueL;
/* First unlock the watchdog so that we can write to registers */
//修改控制寄存器,先写入钥匙。 xzf:两个写操作必须在20 个总线周期内完成,必须关闭中断 p520
wdog_unlock();
int_disable();
Value = ((g_periph_clk_khz/8)*timeOutMs); //XZF. 必须在busclock 初始化之后
timeOutValueH = (uint16_t)((Value&0xFFFF0000)>>16);
timeOutValueL = (uint16_t)(Value&0x0000FFFF);
//xzf: wait one bus clock cycle?
//默认选择BusClock 设置分频器,设置值为8
/* WDOG_STCTRLH: ??=0,DISTESTWDOG=0,BYTESEL=0,TESTSEL=0,TESTWDOG=0,??=0,STNDBYEN=1,WAITEN=1,STOPEN=1,DBGEN=0,ALLOWUPDATE=1,WINEN=0,IRQRSTEN=0,CLKSRC=1(alternate clock),WDOGEN=0 */
//WDOG_BASE_PTR->STCTRLH = (uint16_t)(0x01D3u); //no need DBGEN = 1??
WDOG_BASE_PTR->STCTRLH = (uint16_t)(0x09F7u);
WDOG_BASE_PTR-> RESC = WDOG_PRESC_PRESCVAL(7); //wdog clock = g_periph_clk_khz/(7+1).
//p536:the watchdog clock must be at least five times slower than the system bus clock at all times.
WDOG_BASE_PTR->TOVALH = timeOutValueH;
WDOG_BASE_PTR->TOVALL = timeOutValueL;
int_enable();
if(timeout_isr != NULL) {
//WDOG_BASE_PTR->STCTRLH |= WDOG_STCTRLH_IRQRSTEN_MASK;
irq_set_isr(22,(uint32_t)timeout_isr); //22: wdog irq idx. use macro
irq_set_priority(22,0);
irq_enable(22);
}
}
////////////////////////////////////////////
void irq_set_isr(uint8_t irq, uint32_t isr_addr) {
uint32_t isr_pos = 0;
if (irq > MAX_IRQ) {
UART_printf("\nERR! Invalid IRQ value passed to irq function!\n");
return;
}
isr_pos = (SCB_VTOR + (irq + 16)*4 );
//DisableInterrupts;
*((volatile int*)isr_pos) = isr_addr;
//__VECTOR_RAM[(irq + 14)*4] = isr_addr; //use
//EnableInterrupts;
}
void irq_enable (uint8_t irq)
{
uint8_t div;
/* Make sure that the IRQ is an allowable number. Right now up to 91 is
* used.
*/
if (irq > MAX_IRQ) {
//UART_printf("\nERR! Invalid IRQ value passed to enable irq function!\n");
return;
}
/* Determine which of the NVICISERs corresponds to the irq */
div = irq/32;
switch (div) {
case 0x0:
NVICICPR0 |= 1
|
|