Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
MaJerle committed May 27, 2023
2 parents b696584 + 12ca443 commit b3ad58e
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 14 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Develop

## v1.1.0

- Print error message only on one trial
- Add print option to list all expired watchdogs

## v1.0.0

- Added option to remove wdg from the list
Expand Down
2 changes: 1 addition & 1 deletion dev/lwwdg_opts.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* This file is part of LWWDG - Lightweight watchdog for RTOS in embedded systems.
*
* Author: Tilen MAJERLE <tilen@majerle.eu>
* Version: v1.0.0
* Version: v1.1.0
*/
#ifndef LWWDG_HDR_OPTS_H
#define LWWDG_HDR_OPTS_H
Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ breathe>=4.9.1
urllib3==1.26.15
docutils==0.16
colorama
sphinx_rtd_theme>=1.0.0
sphinx_rtd_theme>=1.1.0
sphinx-tabs
sphinxcontrib-svg2pdfconverter
sphinx-sitemap
2 changes: 2 additions & 0 deletions examples/example_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,7 @@ example_win32(void) {
}
Sleep(500); /* Make some sleep to offload messages in the WIN32 example */
}
printf("List of expired watchdogs\r\n");
lwwdg_print_expired();
printf("Example completed - a hardware should reset the system now...\r\n");
}
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "LwWDG",
"version": "v1.0.0",
"version": "v1.1.0",
"description": "Lightweight watchdog for operating systems and embedded systems",
"keywords": "lwwdg, watchdog, lightweight, independent, watchdog, rtos, os, system",
"repository": {
Expand Down
3 changes: 2 additions & 1 deletion lwwdg/src/include/lwwdg/lwwdg.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* This file is part of LWWDG - Lightweight watchdog for RTOS in embedded systems.
*
* Author: Tilen MAJERLE <tilen@majerle.eu>
* Version: v1.0.0
* Version: v1.1.0
*/
#ifndef LWWDG_HDR_H
#define LWWDG_HDR_H
Expand Down Expand Up @@ -68,6 +68,7 @@ uint8_t lwwdg_remove(lwwdg_wdg_t* wdg);
uint8_t lwwdg_reload(lwwdg_wdg_t* wdg);
uint8_t lwwdg_process(void);
void lwwdg_set_name(lwwdg_wdg_t* wdg, const char* name);
void lwwdg_print_expired(void);

/**
* \}
Expand Down
2 changes: 1 addition & 1 deletion lwwdg/src/include/lwwdg/lwwdg_opt.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* This file is part of LWWDG - Lightweight watchdog for RTOS in embedded systems.
*
* Author: Tilen MAJERLE <tilen@majerle.eu>
* Version: v1.0.0
* Version: v1.1.0
*/
#ifndef LWWDG_OPT_HDR_H
#define LWWDG_OPT_HDR_H
Expand Down
2 changes: 1 addition & 1 deletion lwwdg/src/include/lwwdg/lwwdg_opts_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* This file is part of LWWDG - Lightweight watchdog for RTOS in embedded systems.
*
* Author: Tilen MAJERLE <tilen@majerle.eu>
* Version: v1.0.0
* Version: v1.1.0
*/
#ifndef LWWDG_OPTS_HDR_H
#define LWWDG_OPTS_HDR_H
Expand Down
43 changes: 35 additions & 8 deletions lwwdg/src/lwwdg/lwwdg.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@
* This file is part of LWWDG - Lightweight watchdog for RTOS in embedded systems.
*
* Author: Tilen MAJERLE <tilen@majerle.eu>
* Version: v1.0.0
* Version: v1.1.0
*/
#include <stdint.h>
#include <string.h>
#include "lwwdg/lwwdg.h"

/* Check if WDG did expire */
#define WDG_IS_EXPIRED(_wdg_, _time_) (((_time_) - (_wdg_)->last_reload_time) > (_wdg_)->timeout)

/* Pointer to first watchdog entry */
static lwwdg_wdg_t* wdgs;

/**
Expand Down Expand Up @@ -93,6 +97,25 @@ lwwdg_set_name(lwwdg_wdg_t* wdg, const char* name) {
wdg->name = name;
}

/**
* \brief Print all expired watchdogs
*
* \note \ref LWWDG_CFG_ENABLE_WDG_NAME and \ref LWWDG_CFG_WDG_NAME_ERR_DEBUG must
* be enabled and implemented
*/
void
lwwdg_print_expired(void) {
LWWDG_CRITICAL_SECTION_DEFINE;
LWWDG_CRITICAL_SECTION_LOCK();

for (lwwdg_wdg_t* wdg = wdgs; wdg != NULL; wdg = wdg->next) {
if (WDG_IS_EXPIRED(wdg, time)) {
LWWDG_CFG_WDG_NAME_ERR_DEBUG(wdg->name);
}
}
LWWDG_CRITICAL_SECTION_UNLOCK();
}

#endif /* LWWDG_CFG_ENABLE_WDG_NAME || __DOXYGEN__ */

/**
Expand Down Expand Up @@ -141,10 +164,9 @@ uint8_t
lwwdg_reload(lwwdg_wdg_t* wdg) {
LWWDG_CRITICAL_SECTION_DEFINE;
uint8_t ret = 0;
uint32_t time = LWWDG_GET_TIME();

LWWDG_CRITICAL_SECTION_LOCK();
if ((time - wdg->last_reload_time) < wdg->timeout) {
if (!WDG_IS_EXPIRED(wdg, LWWDG_GET_TIME())) {
wdg->last_reload_time = time;
ret = 1;
}
Expand All @@ -165,13 +187,18 @@ lwwdg_reload(lwwdg_wdg_t* wdg) {
uint8_t
lwwdg_process(void) {
LWWDG_CRITICAL_SECTION_DEFINE;
uint8_t ret = 1;
uint32_t time = LWWDG_GET_TIME();
static uint32_t failed = 0;
uint32_t time;

if (failed) {
return !failed;
}

time = LWWDG_GET_TIME();
LWWDG_CRITICAL_SECTION_LOCK();
for (lwwdg_wdg_t* wdg = wdgs; wdg != NULL; wdg = wdg->next) {
if ((time - wdg->last_reload_time) > wdg->timeout) {
ret = 0;
if (WDG_IS_EXPIRED(wdg, time)) {
failed = 1;
#if LWWDG_CFG_ENABLE_WDG_NAME
LWWDG_CFG_WDG_NAME_ERR_DEBUG(wdg->name);
#else /* LWWDG_CFG_ENABLE_WDG_NAME */
Expand All @@ -180,5 +207,5 @@ lwwdg_process(void) {
}
}
LWWDG_CRITICAL_SECTION_UNLOCK();
return ret;
return !failed;
}

0 comments on commit b3ad58e

Please sign in to comment.