在线时间36 小时
UID423505
注册时间2013-3-27
NXP金币0
该用户从未签到
高级会员

- 积分
- 651
- 最后登录
- 2020-9-4
|
本帖最后由 翱翔太空-423505 于 2016-4-12 09:41 编辑
楼主:
我正在编写K64的看门狗的程序.运行在mqx系统下,现在我作了一个初始化的程序,调用初始化程序后,一直不问狗,但不产生看门狗中断中断.
程序如下:
void wdog_init(uint16_t timeOutMs /*ms*/,void (*timeout_isr)(void))
{
uint32_t Value;
uint16_t timeOutValueH;
uint16_t timeOutValueL;
uint32_t g_periph_clk_khz = 60000000;
/* First unlock the watchdog so that we can write to registers */
//修改控制寄存器,先写入钥匙。 xzf:两个写操作必须在20 个总线周期内完成,必须关闭中断 p520
WDOG_MemMapPtr reg = WDOG_BASE_PTR;
Value = ((g_periph_clk_khz/8)*timeOutMs); //XZF. 必须在busclock 初始化之后
timeOutValueH = (uint16_t)(((Value>>16)&0xFFFF));
timeOutValueL = (uint16_t)(Value&0x0000FFFF);
int_disable();
/* unlock watchdog */
reg->UNLOCK = 0xc520;
reg->UNLOCK = 0xd928;
//默认选择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??
reg->STCTRLH = (uint16_t)(0x09F7u);
reg->PRESC = WDOG_PRESC_PRESCVAL(7); //wdog clock = g_periph_clk_khz/(7+1).
reg->TOVALH = timeOutValueH;
reg->TOVALL = timeOutValueL;
int_enable();
if(timeout_isr != NULL) {
//WDOG_BASE_PTR->STCTRLH |= WDOG_STCTRLH_IRQRSTEN_MASK;
_bsp_int_init(INT_Watchdog, 1, 0, FALSE);
}
}
void wdog_isr(void)
{
_mqx_uint n;
n++;
}
void test_wdog(void)
{
wdog_init(100,wdog_isr);
_bsp_int_enable(INT_Watchdog);
while(1)
{
_time_delay(10);
}
}
哪位大侠指点一下. 是否正确?多谢!
|
|