主程序

先看一下TI提供的看门狗例程源程序,如下

// TI File $Revision: /main/8 $
// Checkin $Date: August 10, 2007   09:07:57 $
//###########################################################################
//
// FILE:   Example_2833xWatchdog.c
//
// TITLE:  DSP2833x Watchdog interrupt test program.
//
// ASSUMPTIONS:
//
//    This program requires the DSP2833x header files.
//
//    As supplied, this project is configured for "boot to SARAM"
//    operation.  The 2833x Boot Mode table is shown below.
//    For information on configuring the boot mode of an eZdsp,
//    please refer to the documentation included with the eZdsp,
//
//       $Boot_Table:
//
//         GPIO87   GPIO86     GPIO85   GPIO84
//          XA15     XA14       XA13     XA12
//           PU       PU         PU       PU
//        ==========================================
//            1        1          1        1    Jump to Flash
//            1        1          1        0    SCI-A boot
//            1        1          0        1    SPI-A boot
//            1        1          0        0    I2C-A boot
//            1        0          1        1    eCAN-A boot
//            1        0          1        0    McBSP-A boot
//            1        0          0        1    Jump to XINTF x16
//            1        0          0        0    Jump to XINTF x32
//            0        1          1        1    Jump to OTP
//            0        1          1        0    Parallel GPIO I/O boot
//            0        1          0        1    Parallel XINTF boot
//            0        1          0        0    Jump to SARAM       <- "boot to SARAM"
//            0        0          1        1    Branch to check boot mode
//            0        0          1        0    Boot to flash, bypass ADC cal
//            0        0          0        1    Boot to SARAM, bypass ADC cal
//            0        0          0        0    Boot to SCI-A, bypass ADC cal
//                                              Boot_Table_End$
//
// DESCRIPTION:
//
//   This program exercises the watchdog.
//
//   First the watchdog is connected to the WAKEINT interrupt of the
//   PIE block.  The code is then put into an infinite loop.
//
//   The user can select to feed the watchdog key register or not
//   by commenting one line of code in the infinite loop.
//
//   If the watchdog key register is fed by the ServiceDog function
//   then the WAKEINT interrupt is not taken.  If the key register
//   is not fed by the ServiceDog function then WAKEINT will be taken.
//
//      Watch Variables:
//         LoopCount for the number of times through the infinite loop
//         WakeCount for the number of times through WAKEINT
//
//###########################################################################
// $TI Release: DSP2833x Header Files V1.01 $
// $Release Date: September 26, 2007 $
//############################################################################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)
{// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP2833x_SysCtrl.c file.InitSysCtrl();// Step 2. Initalize GPIO:
// This example function is found in the DSP2833x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
// InitGpio();  // Skipped for this example  // Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts DINT;// Initialize PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the DSP2833x_PieCtrl.c file.InitPieCtrl();// Disable CPU interrupts and clear all CPU interrupt flags:IER = 0x0000;IFR = 0x0000;// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example.  This is useful for debug purposes.
// The shell ISR routines are found in DSP2833x_DefaultIsr.c.
// This function is found in DSP2833x_PieVect.c.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 registersPieVectTable.WAKEINT = &wakeint_isr;EDIS;   // This is needed to disable write to EALLOW protected registers// Step 4. Initialize all the Device Peripherals:
// This function is found in DSP2833x_InitPeripherals.c
// InitPeripherals(); // Not required for this example// Step 5. User specific code, enable interrupts:// Clear the countersWakeCount = 0; // Count interruptsLoopCount = 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 bitEALLOW;SysCtrlRegs.SCSR = BIT1;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 blockPieCtrlRegs.PIEIER1.bit.INTx8 = 1;   // Enable PIE Gropu 1 INT8IER |= M_INT1;                       // Enable CPU int1EINT;                                // Enable Global Interrupts// Reset the watchdog counterServiceDog();// Enable the watchdogEALLOW;SysCtrlRegs.WDCR = 0x0028;   EDIS;// Step 6. IDLE loop. Just sit and loop forever (optional): for(;;){LoopCount++;// Uncomment ServiceDog to just loop here// Comment ServiceDog to take the WAKEINT instead// ServiceDog();}}  // Step 7. Insert all local Interrupt Service Routines (ISRs) and functions here:
// If local ISRs are used, reassign vector addresses in vector table as
// shown in Step 5interrupt void wakeint_isr(void)
{WakeCount++;// Acknowledge this interrupt to get more from group 1PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}//===========================================================================
// No more.
//===========================================================================

以上程序就是通过两个全局变量来计数看门狗触发的次数WakeCount以及最后死循环的循环次数LoopCount。通过CCS6.0调试功能可是实时看到两个变量的变化。
可以通过注释死循环里面ServiceDog()函数来决定是否喂狗。若每次循环都喂狗,就可以发现循环次数会不断增加,而中断服务程序就不会触发,即WakeCount为0;
否则的话,将喂狗函数注释掉,那么,中断服务程序就会不断被触发WakeCount也就不断增加,即看门狗不断触发。

下面,我们就研究一下,看门狗被打开与关闭的条件。

相关寄存器

先引用<手把手教你学DSP(第二版)>第88页的寄存器说明

看门狗控制寄存器WDCR

名称 描述
15~8 保留
7 WDFLAG 看门狗复位状态标志位;0:不满足标志位,1:满足了复位条件
6 WDDIS 看门狗禁止;0:使能看门狗功能;1:禁止看门狗功能
5~3 WDCHK 看门狗逻辑校验位,必须写101
2~0 WDPS 看门狗时钟分频,若为000或001时候,看门狗时钟频率=晶振频率/512,其余时候,看门狗时钟频率=晶振频率/512/(2^(WDPS-1))

系统控制和状态寄存器SCSR

名称 描述
15~3 保留
2 WDINTS 看门狗中断状态位,反应看门狗模块WDINT‾\overline{{\rm WDINT}}WDINT信号状态
1 WDENINT 0:将复位信号WDRST‾\overline{{\rm WDRST}}WDRST屏蔽,将中断信号WDINT‾\overline{{\rm WDINT}}WDINT使能;1:将复位信号WDRST‾\overline{{\rm WDRST}}WDRST使能,将中断信号WDINT‾\overline{{\rm WDINT}}WDINT屏蔽;
0 WDOVERRIDE 如果该位是1,允许用户改变看门狗控制器寄存器屏蔽位WDDIS;如果通过将该位置1将其清零,用户不能改变WDDIS位置的设置。若该位被清除,只有系统复位后才能改变状态。用户可以随时读取该状态位。
注意
  • 以上基本就是引用书上的原文,通过这两个寄存器的设置基本上就可以实现DSP看门狗打开与屏蔽功能。
  • 书中关于WDOVERRIDE位的设置描述非常模糊。而该位直接影响看门狗的开启与关闭,所以,我个人的实验结果终结如下
    • 该位可以读取与写入,且读取与写入的数据并不相同,也就是说,当该位写入1时,读取的结果为0,该位置0后读取的结果为1
    • 读取到
      • 0:不能通过将WDDIS置1的方式关闭看门狗功能。此时,看门狗功能一直开启,知道系统复位。
      • 1:可以通过WDDIS开启或者关闭看门狗功能。
    • 写入数据
      • 0:可以通过WDDIS位开启或者关闭看门狗。
      • 1:开启看门狗功能,直到系统重启。不可以通过WDDIS位关闭看门狗,也无法重新将WDOVERRIDE置0来重新关闭看门狗。

程序实现

 //配置SCSREALLOW;//关闭保护、//将中断信号WDINT使能,且允许屏蔽看门狗SysCtrlRegs.SCSR = 0x0002;//0010                          EDIS;//打开保护//配置WDCREALLOW;SysCtrlRegs.WDCR = 0x0028;//0010 1000:使能看门狗,分频数为512EDIS;EALLOW;SysCtrlRegs.WDCR= 0x0068;//0110 1000;关闭看门狗EDIS;

上述程序可以实现看门狗的关闭。

 //配置SCSREALLOW;//关闭保护、//将中断信号WDINT使能,打开且不允许屏蔽看门狗SysCtrlRegs.SCSR = 0x0003;//0011                        EDIS;//打开保护//配置WDCREALLOW;SysCtrlRegs.WDCR = 0x0028;//0010 1000:看门狗已经打开EDIS;EALLOW;SysCtrlRegs.WDCR= 0x0068;//0110 1000;不起作用。EDIS;

上述程序不能关闭看门狗。

更新

关于SCSR寄存器,我又参考了TI的官方手册。如下图:

下方的中文介绍截取自<TMS320F28335DSP原理及开发编程>:

F28335第一篇——看门狗的开断相关推荐

  1. RTOS 系统篇-看门狗 WatchDog 2

    RTOS 系统篇-看门狗 WatchDog 2 概述 上一节在 RTOS 系统篇-看门狗 WatchDog[不喂狗就咬你] 讲解了 看门狗的基本原理,以及任务.中断中触发看门狗的原因.解决方法. 本小 ...

  2. RTOS 系统篇-看门狗 WatchDog[不喂狗就咬你]

    RTOS 系统篇-看门狗 WatchDog[不喂狗就咬你] 概述 程序设计完成后,要开始考虑系统整体的稳定性了. 在设备上线后,可能因为程序设计不合理.硬件设计有 bug,电气干扰.静电噪声.电源故障 ...

  3. linux设备驱动归纳总结(十一):简单的看门狗驱动

    http://blog.chinaunix.net/uid-25014876-id-112879.html 设备驱动的归纳已经差不多了,趁着知识点还没有遗忘,写点代码巩固一下,来个简单的看门狗驱动-- ...

  4. 嵌入式单片机基础篇(八)之两只看门狗

    嵌入式单片机基础篇(八)之两只看门狗 独立看门狗与窗口看门狗 第一部分:stm32 .STM32 内部自带了 2 个看门狗:独立看门狗(IWDG)和窗口看门狗(WWDG). (一)独立看门狗 STM3 ...

  5. 【Linux】ARM篇七--WDT看门狗实验

    ARM篇七--WDT看门狗实验 一.前言 二.准备工作 三.看门狗简介 四.看门狗寄存器介绍 1.看门狗结构 2.看门狗寄存器 3.WTCON寄存器 4.WTCNT寄存器 五.看门狗代码编写 1.程序 ...

  6. stm32mp1 Cortex M4开发篇7:窗口看门狗

    本文章为<ARM Cortex-M4裸机开发篇>系列中的一篇,,全系列总计14篇,笔者使用的开发平台为华清远见FS-MP1A开发板(STM32MP157开发板).针对FS-MP1A开发板, ...

  7. 疯狂的大柚柚带你玩转MSP-ESP430G2(基础篇)----(十一)看门狗

    疯狂的大柚柚带你玩转MSP-ESP430G2(基础篇) (十一) 看门狗 开看门狗(默认开):WDTCTL=WDTPW; 清看门狗:WDTCTL=WDTPW+WDTCNTCL; 关看门狗:WDTCTL ...

  8. 第一个驱动程序:at91sam9g45核心板的看门狗驱动

    纪念第一个驱动程序:at91sam9g45核心板的看门狗驱动 看门狗的驱动一般来说比较简单,只要做寄存器的设置实现开启.关闭.喂狗功能.本项目中我们使用的是at91sam9g45处理器,带有看门狗定时 ...

  9. 六、【中级篇】看门狗(watch dog)

    看门狗watch dog 1.看门狗的使用环境 2.看门狗的简介 3.看门狗的喂狗 4.看门狗外设资源 5.介绍STM32芯片中的看门狗 1.看门狗的使用环境 在工业的工作环境中设备经常面临一些恶劣的 ...

  10. 初出茅庐的小李第92篇博客之看门狗总结

    什么是看门狗呢 看门狗是一条狗吗?显然不是,它其实是一种外设只不过呢这种外设有点看门狗的意思.试想一下有个人家里比较富,而且有一些宝贵的古董在院子里,但是呢他家里还没有有到能请得起一个保安,这时候它怎 ...

最新文章

  1. 初始Java DVD项目
  2. OpenSceneGraph 笔记--如何导出三角形数据
  3. OpenCASCADE绘制测试线束:简单的向量代数和测量之测量命令
  4. 最长公共子序列(稀疏序列)nlogn解法
  5. [转] 前端中的MVC
  6. 二分查找算法举例说明C语言,C语言快速排序与二分查找算法示例
  7. 树链剖分 讲解+模板+习题
  8. java事务代码_关于java中实现JDBC事务控制代码示例
  9. linux挂载CentOS yum,centos7本地挂载yum仓库
  10. 重装64位WIN7之后再装KUBUNTU遇到的问题
  11. 摩托罗拉linux专属游戏,摩托罗拉E680g Linux系统手机也可以玩游戏
  12. 321电商学院 与华中师大联手 - 2014-10-22
  13. IIS中发布网站的问题
  14. 团队-科学计算器-代码设计规范
  15. 为癌症医生提供最匹配的医学文献,达摩院精准医学搜索引擎TREC PM 2020评测夺冠...
  16. unity下载及安装
  17. 六、3D数学矩阵线性变换
  18. js高级--jsonp跨域
  19. 20170223找女朋友之路思考总结
  20. 会计记账公式、六要素、记账流程

热门文章

  1. 英语音标原来这么丰富,换个角度把欧洲语言作为一个体系
  2. 《大数据技术原理与应用》(第三章 HDFS 课后答案)
  3. 路畅安卓最新固件升级_路畅导航系统固件升级刷机包
  4. 自然语言处理之词袋模型Bag_of_words
  5. sql获取当前时间精确到秒的字符串
  6. SI 9000 及阻抗匹配学习笔记(三)
  7. python识别文字软件_使用Python和大漠插件进行文字识别含软件源码
  8. tableau 地图不显示怎么回事
  9. web前端编程实现福彩投注站彩票投注助手
  10. 【颗粒归仓】(四)代码走查工具---StyleCop