DSP 中的看门狗

25 篇文章 6 订阅

DSP 中的看门狗

  (2012-11-20 13:43:01)

标签: 

 

dsp

 

看门狗

分类: DSP

看门狗电路的应用,使单片机可以在无人状态下实现连续工作,其工作原理是:看门狗芯片和单片机的一个I/O引脚相连,该I/O引脚通过程序控制它定时地往看门狗的这个引脚上送入高电平(或低电平),这一程序语句是分散地放在单片机其他控制语句中间的,一旦单片机由于干扰造成程序跑飞后而陷入某一程序段 进入死循环状态时,写看门狗引脚的程序便不能被执行,这个时候,看门狗电路就会由于得不到单片机送来的信号,便在它和单片机复位引脚相连的引脚上送出一个复位信号,使单片机发生复位,即程序从程序存储器的起始位置开始执行,这样便实现了单片机的自动复位。

总结就是 喂狗狗不叫,没人喂了狗就要叫CPU复位

看门狗的机理:

  主要核心是一个定时器,当定时器时间到时复位

  正常运行程序过程中每次在看门狗的定时器时间到之前重启看门狗定时器

TMS320F2833X 看门狗的组成

 

1.定时器(计数器) WD Counter 

  2.看门狗重启管理器(WD Reset Register)

  3.看门狗时钟发生器。

  4.看门狗状态位

DSP <wbr>中的看门狗

 

看门狗时钟发生器:

  WDCLK = CLKOUT/512,HALT时停止

6-bits预定标选择:WDCLK再分频后送给看门狗定时器。WDPS2~0 in WDCR

DSP <wbr>中的看门狗

 

看门狗控制寄存器:WDCR

 DSP <wbr>中的看门狗
 

 DSP <wbr>中的看门狗

 

WDFLAG: 0-未发生复位,1-发生复位

WDDIS: 0-使能看门狗,1-禁止看门狗

WDCHK2~0: 101   系统正常运行

      其他值  复位

 WDCR = 0X 28  (00 101 000) 使能看门狗

 

 

看门狗定时器(计数器) WDCNTR:

    低8位为计数器,当低8位溢出时,产生一个复位信号。此寄存器为只读的。

看门狗重启管理器 WDKEY:

    低8位为寄存器,只有先写入55h后写入AAh后重启看门狗计数器。

    不是此顺序写入55h或AAh,则无效。

    写入其他数值时产生复位信号。

 

 

使用时,,首先写SCSR 寄存器 。System Control and Status Register

 

在 文档中 TMS320x2833x, 2823x System Control and Interrupts 找到

DSP <wbr>中的看门狗
 

 

DSP <wbr>中的看门狗
 

 

 

 

 

#include "DSP2833x_Device.h"     // Headerfile Include File

#include "DSP2833x_Examples.h"   // Examples Include File

 

// Prototype statements for functions found within this file.

interrupt void wakeint_isr(void);

 

// Global variables for this example

Uint32 WakeCount;

Uint32 LoopCount;

 

void main(void)

{

 

   InitSysCtrl();

 

// Disable CPU interrupts 

   DINT;

 

   InitPieCtrl();

 

// Disable CPU interrupts and clear all CPU interrupt flags:

   IER = 0x0000;

   IFR = 0x0000;

 

 

   InitPieVectTable();

 

// Interrupts that are used in this example are re-mapped to

// ISR functions found within this file.  

   EALLOW; // This is needed to write to EALLOW protected registers

   PieVectTable.WAKEINT = &wakeint_isr;

   EDIS;   // This is needed to disable write to EALLOW protected registers

 

 

 

// Clear the counters

   WakeCount = 0; // Count interrupts

   LoopCount = 0; // Count times through idle loop

 

// Connect the watchdog to the WAKEINT interrupt of the PIE

// Write to the whole SCSR register to avoid clearing WDOVERRIDE bit

   EALLOW;

   SysCtrlRegs.SCSR = BIT1;      //WDENINT写1,使能watchdog 中断

   EDIS;

 

// Enable WAKEINT in the PIE: Group 1 interrupt 8

// Enable INT1 which is connected to WAKEINT:

   PieCtrlRegs.PIECTRL.bit.ENPIE = 1;   // Enable the PIE block

   PieCtrlRegs.PIEIER1.bit.INTx8 = 1;   // Enable PIE Gropu 1 INT8   WAKEINT中断  

   IER |= M_INT1;                       // Enable CPU int1

   EINT;                                // Enable Global Interrupts

 

// Reset the watchdog counter

  ServiceDog();

      

// Enable the watchdog

   EALLOW;

   SysCtrlRegs.WDCR = 0x0028;   

   EDIS;

   

// Step 6. IDLE loop. Just sit and loop forever (optional):

   for(;;)

   {

      LoopCount++;

   

    

    ServiceDog();

   }

 

 

}

 

 

interrupt void wakeint_isr(void)

{

WakeCount++;

 

// Acknowledge this interrupt to get more from group 1

PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;

}

 

 

void ServiceDog(void)

{

    EALLOW;

    SysCtrlRegs.WDKEY = 0x0055;

    SysCtrlRegs.WDKEY = 0x00AA;

    EDIS;

}

 

DSP <wbr>中的看门狗
 

 

本实验中 WakeCount 是进入wakeint_isr 中断一次以后加1.

 

在程序段

 

for(;;)

   {

      LoopCount++;

   

      // Uncomment ServiceDog to just loop here

      // Comment ServiceDog to take the WAKEINT instead

    ServiceDog();

   }

中不断地喂狗,,主程序进不了中断, WakeCount不会+1,一直为零。

 

如果把这段程序注释掉。就会不停进入中断。WakeCount就会一直增加。

  • 1
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值