-
Notifications
You must be signed in to change notification settings - Fork 0
/
watchdog.c
51 lines (46 loc) · 1.47 KB
/
watchdog.c
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
/*
* File: watchdog.c
* Author: Henrik J. Koch - 2021
*
* Created on 16. june 2021, 21:31
*
* Used as a function library for different funcktions on the Microchip Couriosity Board rev. 4
*
*/
#include <xc.h>
#if defined(_16LF1829)
#include <stdio.h> // printf
#endif
void set_watchdog_timer_64ms(void) {
WDTCONbits.WDTPS = 0b00110; // 00110 = 1:2048 (Interval 64 ms nominal)
}
void set_watchdog_timer_128ms(void) {
WDTCONbits.WDTPS = 0b00111; // 00111 = 1:4096 (Interval 128 ms nominal)
}
void set_watchdog_timer_256ms(void) {
WDTCONbits.WDTPS = 0b01000; // 01000 = 1:8192 (Interval 256 ms nominal)
}
void set_watchdog_timer_1s(void) {
WDTCONbits.WDTPS = 0b01010; // 01010 = 1:32768 (Interval 1s nominal)
#if defined(_16LF1829)
printf("set_watchdog_timer_1s\r\n");
#endif
}
void set_watchdog_timer_4s(void) {
WDTCONbits.WDTPS = 0b01100; // 01100 = 1:131072 (2^17) (Interval 4s nominal)
#if defined(_16LF1829)
printf("set_watchdog_timer_4s\r\n");
#endif
}
void set_watchdog_timer_256s(void) {
WDTCONbits.WDTPS = 0b10010; // 10010 = 1:8388608 (2^23) (Interval 256s nominal) watch-dog timer
#if defined(_16LF1829)
printf("set_watchdog_timer_256s\r\n");
#endif
}
void enable_watchdog_timer(void) {
WDTCONbits.SWDTEN = 1; // enable SW controlled watch-dog
}
void disable_watchdog_timer(void) {
WDTCONbits.SWDTEN = 0; // disable SW controlled watch-dog
}