Skip to content

Commit 96ecf28

Browse files
committed
Add cosmetic changes to apps/examples/watchdog/main.c
1 parent 7f5a9c2 commit 96ecf28

File tree

1 file changed

+21
-26
lines changed

1 file changed

+21
-26
lines changed

apps/examples/watchdog/main.c

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@
2626

2727
/*
2828
* A task 'watched' is monitored by a watchdog task 'wdt'.
29-
* The 'watched' tasks works fine for 3 seconds, after which
29+
* The 'watched' task works fine for 3 seconds, after which
3030
* it fails to feed 'wdt' in time.
3131
*/
3232

33-
#include <stdio.h>
3433
#include <stdint.h>
3534
#include <stdlib.h>
3635
#include <string.h>
@@ -43,8 +42,8 @@
4342
#include "pal/pal.h"
4443
#include "hsm/hsm.h"
4544

46-
#define AM_WDT_FEED_TIMEOUT_MS 1000
47-
#define AM_WDT_BARK_TIMEOUT_MS (AM_WDT_FEED_TIMEOUT_MS + 100)
45+
#define AM_FEED_TIMEOUT_MS 1000
46+
#define AM_BARK_TIMEOUT_MS (AM_FEED_TIMEOUT_MS + 100)
4847

4948
enum evt {
5049
EVT_WATCHED_TIMEOUT = AM_EVT_USER,
@@ -54,13 +53,13 @@ enum evt {
5453

5554
struct watched {
5655
struct am_ao ao;
57-
struct am_timer timer_wdt_feed;
56+
struct am_timer timer_feed;
5857
int feeds_num;
5958
};
6059

6160
struct wdt {
6261
struct am_ao ao;
63-
struct am_timer timer_wdt_bark;
62+
struct am_timer timer_bark;
6463
};
6564

6665
/* tasks */
@@ -82,7 +81,7 @@ static enum am_rc watched_proc(
8281
switch (event->id) {
8382
case AM_EVT_ENTRY: {
8483
am_timer_arm_ms(
85-
&me->timer_wdt_feed, AM_WDT_FEED_TIMEOUT_MS, AM_WDT_FEED_TIMEOUT_MS
84+
&me->timer_feed, AM_FEED_TIMEOUT_MS, AM_FEED_TIMEOUT_MS
8685
);
8786
return AM_HSM_HANDLED();
8887
}
@@ -104,41 +103,37 @@ static enum am_rc watched_init(
104103
struct watched *me, const struct am_event *event
105104
) {
106105
(void)event;
107-
am_timer_ctor(
108-
&me->timer_wdt_feed,
109-
EVT_WATCHED_TIMEOUT,
110-
AM_PAL_TICK_DOMAIN_DEFAULT,
111-
/*owner=*/&me->ao
112-
);
113106
return AM_HSM_TRAN(watched_proc);
114107
}
115108

116109
static void watched_ctor(struct watched *me) {
117110
memset(me, 0, sizeof(*me));
118111
am_ao_ctor(&me->ao, AM_HSM_STATE_CTOR(watched_init));
112+
am_timer_ctor(
113+
&me->timer_feed,
114+
EVT_WATCHED_TIMEOUT,
115+
AM_PAL_TICK_DOMAIN_DEFAULT,
116+
/*owner=*/&me->ao
117+
);
119118
}
120119

121120
/* 'wdt' task */
122121

123122
static enum am_rc wdt_proc(struct wdt *me, const struct am_event *event) {
124123
switch (event->id) {
125124
case AM_EVT_ENTRY: {
126-
am_timer_arm_ms(
127-
&me->timer_wdt_bark, AM_WDT_BARK_TIMEOUT_MS, /*interval=*/0
128-
);
125+
am_timer_arm_ms(&me->timer_bark, AM_BARK_TIMEOUT_MS, /*interval=*/0);
129126
return AM_HSM_HANDLED();
130127
}
131128
case EVT_WDT_FEED: {
132129
am_pal_printff("EVT_WDT_FEED received\n");
133130
/* re-arm bark timer */
134-
am_timer_arm_ms(
135-
&me->timer_wdt_bark, AM_WDT_BARK_TIMEOUT_MS, /*interval=*/0
136-
);
131+
am_timer_arm_ms(&me->timer_bark, AM_BARK_TIMEOUT_MS, /*interval=*/0);
137132
return AM_HSM_HANDLED();
138133
}
139134
case EVT_WDT_BARK: {
140135
am_pal_printff("WATCHED TASK FAILED!\n");
141-
exit(-1);
136+
exit(EXIT_FAILURE);
142137
}
143138
default:
144139
break;
@@ -148,18 +143,18 @@ static enum am_rc wdt_proc(struct wdt *me, const struct am_event *event) {
148143

149144
static enum am_rc wdt_init(struct wdt *me, const struct am_event *event) {
150145
(void)event;
151-
am_timer_ctor(
152-
&me->timer_wdt_bark,
153-
EVT_WDT_BARK,
154-
AM_PAL_TICK_DOMAIN_DEFAULT,
155-
/*owner=*/&me->ao
156-
);
157146
return AM_HSM_TRAN(wdt_proc);
158147
}
159148

160149
static void wdt_ctor(struct wdt *me) {
161150
memset(me, 0, sizeof(*me));
162151
am_ao_ctor(&me->ao, AM_HSM_STATE_CTOR(wdt_init));
152+
am_timer_ctor(
153+
&me->timer_bark,
154+
EVT_WDT_BARK,
155+
AM_PAL_TICK_DOMAIN_DEFAULT,
156+
/*owner=*/&me->ao
157+
);
163158
}
164159

165160
/* timer task to drive timers */

0 commit comments

Comments
 (0)