at91sam7在系统重启后不起作用。如何强行重启?

时间:2014-12-07 14:11:01

标签: arm microcontroller watchdog

我在我的项目中使用 at91sam7s64 标题板,一切正常,我使用usb端口从微控制器读取和写入数据。但是当Windows或Linux重新启动或在待机后唤醒时,设备不再工作,我必须从USB端口断开/连接设备。在Windows i上,使用hidapi库与设备通信 有没有办法强制 at91sam7s 在看门狗或任何其他方式的情况下重新启动自己?

upade

我从Flash NOT RAM运行我的代码。似乎“Windows内部有两个USB复位类型。软复位只是在总线上复位信号。它重置通信管道,但已经加载的驱动程序保持活动状态。硬复位将在设备顶部建立整个驱动程序树在设备方面,你看不出任何差异“

2 个答案:

答案 0 :(得分:0)

首先没有USB连接是否可行(如果你能以某种方式为电路板供电)?尝试排除理论上的假设,即电路板上的固件在工作期间与PC上的主机操作系统进行了主动通信,这可能导致嵌入式系统在断开USB电缆时挂起/崩溃。

请清楚(并且最好将其包含在此处),您可以从IDE运行代码而不是从RAM运行代码,例如,来自IDE的模拟器。

您也可以尝试使用JTAG(如果有的话)和断点来调试停止执行的代码段。同样你可以试着找到打印到一些端口(如连续出版物)。

答案 1 :(得分:0)

我使用来自makecontroller

的看门狗代码解决了这个问题

<强>溶液

watchdogEnable(2000); // start the countdown

  void MyTask()
  {
    while (1) {
      if (everything_is_normal()) {
        watchdogReset();
      }
      else {
        // if things are not normal, the timer is not reset and will eventually expire
      }
    }
  }

文件:

watchdog.c

#include "config.h"
#ifdef WATCHDOG_ENABLE

#include "watchdog.h"
#include "at91sam7.h"

#define WATCHDOG_KEY (0xA5 << 24)

/**
  \defgroup Watchdog
  The Watchdog timer resets the board in the event that it's not behaving as expected.
  This is more robust than using other kinds of timers, because in the worst case, when
  your app has malfunctioned, it can still reset since it's not relying on your app to
  actually be running.

  \section Usage
  The watchdog is disabled by default.  If you want to make use of it, add the following
  line to your config.h file: \code #define WATCHDOG_ENABLE \endcode

  If you want to use it, specify the length of the countdown to watchdogEnable() and then
  periodically call watchdogReset() to reset the countdown.  If the countdown ever gets
  all the way to zero, the board will reset.

  \b Example
  \code
  watchdogEnable(2000); // start the countdown

  void MyTask()
  {
    while (1) {
      if (everything_is_normal()) {
        watchdogReset();
      }
      else {
        // if things are not normal, the timer is not reset and will eventually expire
      }
    }
  }
  \endcode
  \ingroup Core
  @{
*/

/**
  Enable the watchdog timer.
  Specify the number of milliseconds that the watchdog should wait before 
  resetting.  Remember that watchdogEnable() or watchdogDisable() can only be called
  once until the processor is reset again.

  The maximum countdown length is 16 seconds (16000 ms).
  @param millis The number of milliseconds in which a reset will occur.
*/
void watchdogEnable(int millis)
{
  int period = (millis * 256) / 1000;
  AT91C_BASE_WDTC->WDTC_WDMR =  AT91C_WDTC_WDRSTEN |        // enable reset on timeout
                                AT91C_WDTC_WDDBGHLT |       // respect debug mode
                                AT91C_WDTC_WDIDLEHLT |      // respect idle mode
                                ((period << 16 ) & AT91C_WDTC_WDD) | // delta is as wide as the period, so we can restart anytime
                                (period & AT91C_WDTC_WDV);  // set the period
}

/**
  Reset the watchdog timer countdown.
  Call watchdogEnable() first, and then call this occasionally to reset
  the watchdog countdown so that it doesn't expire.
*/
void watchdogReset()
{
  AT91C_BASE_WDTC->WDTC_WDCR = WATCHDOG_KEY | AT91C_WDTC_WDRSTT;
}

/**
  Disable the watchdog timer.
  Turn the watchdog off completely if you don't need it.

  If \b WATCHDOG_ENABLE is not defined in your config.h, this is done automatically.
*/
void watchdogDisable()
{
  AT91C_BASE_WDTC->WDTC_WDMR = AT91C_WDTC_WDDIS;
}

/** @}
*/

#endif // WATCHDOG_ENABLE

watchdog.h

#ifndef WATCHDOG_H
#define WATCHDOG_H

#ifdef __cplusplus
extern "C" {
#endif
void watchdogEnable(int millis);
void watchdogReset(void);
void watchdogDisable(void);
#ifdef __cplusplus
}
#endif
#endif // WATCHDOG_H