在嵌入式工控領域,為保障程序的持續運行,使用看門狗是必須的。
調狐上網,發現詳細介紹s3c2440 Watchdog的資料真不多。于是就對著linux kernel里的代碼自己研究吧。
偶寫的測試例程如下所示:
#include time_t backTime; static void sigAlarm(int sig) write(wt_fd, &flag, 1); //Reset Watchdog wt_fd = open('/dev/watchdog', O_RDWR); alarm(3); while(1); write(wt_fd, &flag, 1);
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
struct tm *pBackTime;
int wt_fd;
{
char flag = '0';
(void)time(&backTime);
pBackTime= localtime(&backTime);
printf('day: %d; hour: %d; min: %d; sec: %dn', pBackTime->tm_mday, pBackTime->tm_hour, pBackTime->tm_min, pBackTime->tm_sec);
alarm(2);
return;
}
int main()
{
char flag = 'V';
int ret;
int timeout = 42;
if(SIG_ERR == signal(SIGALRM, sigAlarm))
{
perror('signal (SIGALARM) error');
}
if(wt_fd <= 0)
{
printf('Fail to open watchdog device!n');
}
else
{
write(wt_fd,NULL,0);
printf('Turn on Watch Dogn');
ret = ioctl(wt_fd, WDIOC_SETTIMEOUT, &timeout);
if(EINVAL == ret)
{
printf('EINVAL Returnedn');
}
else if(EFAULT == ret)
{
printf('EFAULT Returnedn');
}
else if(0 == ret)
{
printf('Set timeout %d secs successn', timeout);
}
else
{
printf('Ret %dn', ret);
}
}
printf('Turned off Watch Dogn');
close(wt_fd);
return 0;
}
本代碼實現了啟用看門狗,設置看門狗超時時間,定時喂狗,關閉看門狗還沒有修正。
經實踐發現,42秒是s3c2440最長的超時時間。
上一篇:S3C2440上LCD驅動(FrameBuffer)實例開發講解
下一篇:移植u-boot-2010.12.tar.bz2版本到s3c2440過程
推薦閱讀最新更新時間:2025-06-17 14:09



設計資源 培訓 開發板 精華推薦
- 納祥科技2W 24位數字功放NX4920,可用于AI語音播報、WIFI播放器
- 常用解調器的定義和工作原理
- 從性能與網絡傳輸出發,講講鐵威馬MAX系列為什么一騎絕塵
- 惠普選中Hailo下一代人工智能加速器,革新零售業與酒店業運營模式
- 跨國商務溝通困局破解之道:時空壺 W4Pro 全場景應用解析
- 從矢量降噪到雙向同傳,時空壺 W4Pro 如何重構 AI 同傳技術標準?
- LoRa+NB-IoT雙模融合,地下車庫信號盲區電梯場景等的冗余通信
- LoRa與UWB的“定位之戰”,成本敏感場景高精度需求的場景切割
- 時空壺X1再升級:引領AI同傳新時代,革新演講翻譯體驗
- ARXML 規則下 ECU 總線通訊與 ADTF 測試方案