-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.c
More file actions
80 lines (69 loc) · 1.49 KB
/
Copy pathtimer.c
File metadata and controls
80 lines (69 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
* timer.c: Watchdog Timer Linux Device Driver
*
* (C) Copyright 2012, 2016 by WinSystems, Inc.
* Author: Paul DeMetrotion <pdemetrotion@winsystems.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; version 2
* of the License.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "wdt.h"
void init_keyboard(void);
void close_keyboard(void);
int kbhit(void);
int readch(void);
int main(int argc, char *argv[])
{
int timeout, key;
// check syntax and availability
if (argc != 3)
{
printf("Usage: timer <time> <sec/min>\n");
printf("Example: timer 100 sec\n");
exit(1);
}
else if(read_wdt() < 0)
{
fprintf(stderr, "Can't access device WDT - Aborting\n");
exit(1);
}
else
{
printf("Test program WinSystems Watchdog Timer\n");
timeout = atoi(argv[1]);
printf(" Settings: %d %s\n", timeout, argv[2]);
printf(" Hit any key to start program\n");
init_keyboard();
}
// wait for keystroke
while (!kbhit()) ;
readch();
// configure wdt
if (*argv[2] == 's')
set_wdt_sec();
else
set_wdt_min();
write_wdt(timeout);
while(1)
{
printf(" ***** Current count = %d *****\n", read_wdt());
if (kbhit())
{
key = readch();
if (key == 'q') // exit
{
write_wdt(0); // disable wdt
close_keyboard();
exit(0);
}
else // reset wdt
write_wdt(timeout);
}
usleep(1000000); // wait 1 sec
}
}