MeterLogger
Macros | Enumerations | Functions
watchdog.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define WATCHDOG_MAX   1
 
#define MQTT_WATCHDOG_ID   1
 
#define MQTT_WATCHDOG_TIMEOUT   120
 
#define NETWORK_RESTART_DELAY   6000
 

Enumerations

enum  watchdog_type_t { NOT_ENABLED, REBOOT, REBOOT_VIA_EXT_WD, NETWORK_RESTART }
 

Functions

ICACHE_FLASH_ATTR void init_watchdog ()
 
ICACHE_FLASH_ATTR void start_watchdog ()
 
ICACHE_FLASH_ATTR void stop_watchdog ()
 
ICACHE_FLASH_ATTR bool add_watchdog (uint32_t id, watchdog_type_t type, uint32_t timeout)
 
ICACHE_FLASH_ATTR bool remove_watchdog (uint32_t id)
 
ICACHE_FLASH_ATTR void reset_watchdog (uint32_t id)
 

Macro Definition Documentation

◆ MQTT_WATCHDOG_ID

#define MQTT_WATCHDOG_ID   1

Definition at line 3 of file watchdog.h.

◆ MQTT_WATCHDOG_TIMEOUT

#define MQTT_WATCHDOG_TIMEOUT   120

Definition at line 4 of file watchdog.h.

◆ NETWORK_RESTART_DELAY

#define NETWORK_RESTART_DELAY   6000

Definition at line 6 of file watchdog.h.

Referenced by watchdog_timer_func().

◆ WATCHDOG_MAX

#define WATCHDOG_MAX   1

Definition at line 1 of file watchdog.h.

Referenced by add_watchdog(), reset_watchdog(), and watchdog_timer_func().

Enumeration Type Documentation

◆ watchdog_type_t

Enumerator
NOT_ENABLED 
REBOOT 
REBOOT_VIA_EXT_WD 
NETWORK_RESTART 

Definition at line 8 of file watchdog.h.

Function Documentation

◆ add_watchdog()

ICACHE_FLASH_ATTR bool add_watchdog ( uint32_t  id,
watchdog_type_t  type,
uint32_t  timeout 
)

Definition at line 155 of file watchdog.c.

References get_uptime(), watchdog_t::id, watchdog_t::last_reset, os_printf, watchdog_t::timeout, watchdog_t::type, watchdog_list_len, and WATCHDOG_MAX.

155  {
157 #ifdef DEBUG
158  os_printf("add watchdog, id: %d\n", id);
159 #endif
165  return true;
166  }
167  else {
168 #ifdef DEBUG
169  os_printf("watchdog error, cant add more\n");
170 #endif
171  return false;
172  }
173 }
volatile uint32_t timeout
Definition: watchdog.c:18
volatile watchdog_type_t type
Definition: watchdog.c:17
volatile uint32_t id
Definition: watchdog.c:16
volatile uint32_t last_reset
Definition: watchdog.c:19
ICACHE_FLASH_ATTR uint32_t get_uptime(void)
Definition: unix_time.c:61
#define os_printf
Definition: osapi.h:62
volatile uint8_t watchdog_list_len
Definition: watchdog.c:23
watchdog_t watchdog_list[WATCHDOG_MAX]
Definition: watchdog.c:22
#define WATCHDOG_MAX
Definition: watchdog.h:1
Here is the call graph for this function:

◆ init_watchdog()

ICACHE_FLASH_ATTR void init_watchdog ( )

Definition at line 125 of file watchdog.c.

References memset, and watchdog_list_len.

125  {
126  memset(watchdog_list, 0x00, sizeof(watchdog_list));
127  watchdog_list_len = 0;
128 }
#define memset(x, a, b)
Definition: platform.h:21
volatile uint8_t watchdog_list_len
Definition: watchdog.c:23
watchdog_t watchdog_list[WATCHDOG_MAX]
Definition: watchdog.c:22

◆ remove_watchdog()

ICACHE_FLASH_ATTR bool remove_watchdog ( uint32_t  id)

Definition at line 175 of file watchdog.c.

References watchdog_t::id, NOT_ENABLED, os_printf, watchdog_t::timeout, watchdog_t::type, and watchdog_list_len.

175  {
176  if (watchdog_list_len > 0) {
177 #ifdef DEBUG
178  os_printf("remove watchdog, id: %d\n", id);
179 #endif
184  return true;
185  }
186  else {
187 #ifdef DEBUG
188  os_printf("watchdog error, cant remove %d\n", id);
189 #endif
190  return false;
191  }
192 }
volatile uint32_t timeout
Definition: watchdog.c:18
volatile watchdog_type_t type
Definition: watchdog.c:17
volatile uint32_t id
Definition: watchdog.c:16
#define os_printf
Definition: osapi.h:62
volatile uint8_t watchdog_list_len
Definition: watchdog.c:23
watchdog_t watchdog_list[WATCHDOG_MAX]
Definition: watchdog.c:22

◆ reset_watchdog()

ICACHE_FLASH_ATTR void reset_watchdog ( uint32_t  id)

Definition at line 194 of file watchdog.c.

References get_uptime(), watchdog_t::last_reset, os_printf, and WATCHDOG_MAX.

194  {
195  uint32_t i;
196 
197 #ifdef DEBUG
198  os_printf("reset watchdog, id: %d\n", id);
199 #endif
200  for (i = 0; i < WATCHDOG_MAX; i++) {
201  if (watchdog_list[i].id == id) {
203  }
204  }
205 }
volatile uint32_t last_reset
Definition: watchdog.c:19
ICACHE_FLASH_ATTR uint32_t get_uptime(void)
Definition: unix_time.c:61
#define os_printf
Definition: osapi.h:62
watchdog_t watchdog_list[WATCHDOG_MAX]
Definition: watchdog.c:22
#define WATCHDOG_MAX
Definition: watchdog.h:1
Here is the call graph for this function:

◆ start_watchdog()

ICACHE_FLASH_ATTR void start_watchdog ( )

Definition at line 130 of file watchdog.c.

References ext_watchdog_timer, ext_watchdog_timer_func(), gpio16_output_conf(), gpio16_output_set(), NULL, os_printf, os_timer_arm, os_timer_disarm, os_timer_func_t, os_timer_setfn, watchdog_timer, and watchdog_timer_func().

130  {
131 #ifdef DEBUG
132  os_printf("watchdog started\n");
133 #endif
134  // start configurable software watchdog system
137  os_timer_arm(&watchdog_timer, 1000, 1);
138 
139  // start extern watchdog timer (MCP1316)
142  os_timer_arm(&ext_watchdog_timer, 1000, 1);
143  //Set GPIO16 to output mode
145  gpio16_output_set(1);
146 }
#define os_timer_disarm
Definition: osapi.h:51
ICACHE_FLASH_ATTR static void watchdog_timer_func(void *arg)
Definition: watchdog.c:72
ICACHE_FLASH_ATTR static void ext_watchdog_timer_func(void *arg)
Definition: watchdog.c:25
#define NULL
Definition: def.h:47
void ICACHE_FLASH_ATTR gpio16_output_conf(void)
Definition: gpio16.c:6
#define os_timer_func_t
Definition: os_type.h:35
#define os_printf
Definition: osapi.h:62
#define os_timer_setfn
Definition: osapi.h:52
void ICACHE_FLASH_ATTR gpio16_output_set(uint8 value)
Definition: gpio16.c:19
static os_timer_t watchdog_timer
Definition: watchdog.c:11
static os_timer_t ext_watchdog_timer
Definition: watchdog.c:12
#define os_timer_arm(a, b, c)
Definition: osapi.h:50
Here is the call graph for this function:

◆ stop_watchdog()

ICACHE_FLASH_ATTR void stop_watchdog ( )

Definition at line 148 of file watchdog.c.

References ext_watchdog_timer, os_printf, and os_timer_disarm.

148  {
149 #ifdef DEBUG
150  os_printf("watchdog stopped\n");
151 #endif
153 }
#define os_timer_disarm
Definition: osapi.h:51
#define os_printf
Definition: osapi.h:62
static os_timer_t ext_watchdog_timer
Definition: watchdog.c:12