ChibiOS/HAL  6.1.0
hal_wdg.c
Go to the documentation of this file.
1 /*
2  ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 
17 /**
18  * @file hal_wdg.c
19  * @brief WDG Driver code.
20  *
21  * @addtogroup WDG
22  * @{
23  */
24 
25 #include "hal.h"
26 
27 #if (HAL_USE_WDG == TRUE) || defined(__DOXYGEN__)
28 
29 /*===========================================================================*/
30 /* Driver local definitions. */
31 /*===========================================================================*/
32 
33 /*===========================================================================*/
34 /* Driver exported variables. */
35 /*===========================================================================*/
36 
37 /*===========================================================================*/
38 /* Driver local variables. */
39 /*===========================================================================*/
40 
41 /*===========================================================================*/
42 /* Driver local functions. */
43 /*===========================================================================*/
44 
45 /*===========================================================================*/
46 /* Driver exported functions. */
47 /*===========================================================================*/
48 
49 /**
50  * @brief WDG Driver initialization.
51  * @note This function is implicitly invoked by @p halInit(), there is
52  * no need to explicitly initialize the driver.
53  *
54  * @init
55  */
56 void wdgInit(void) {
57 
58  wdg_lld_init();
59 }
60 
61 /**
62  * @brief Configures and activates the WDG peripheral.
63  *
64  * @param[in] wdgp pointer to the @p WDGDriver object
65  * @param[in] config pointer to the @p WDGConfig object
66  *
67  * @api
68  */
69 void wdgStart(WDGDriver *wdgp, const WDGConfig *config) {
70 
71  osalDbgCheck((wdgp != NULL) && (config != NULL));
72 
73  osalSysLock();
74  osalDbgAssert((wdgp->state == WDG_STOP) || (wdgp->state == WDG_READY),
75  "invalid state");
76  wdgp->config = config;
77  wdg_lld_start(wdgp);
78  wdgp->state = WDG_READY;
79  osalSysUnlock();
80 }
81 
82 /**
83  * @brief Deactivates the WDG peripheral.
84  *
85  * @param[in] wdgp pointer to the @p WDGDriver object
86  *
87  * @api
88  */
89 void wdgStop(WDGDriver *wdgp) {
90 
91  osalDbgCheck(wdgp != NULL);
92 
93  osalSysLock();
94 
95  osalDbgAssert((wdgp->state == WDG_STOP) || (wdgp->state == WDG_READY),
96  "invalid state");
97 
98  wdg_lld_stop(wdgp);
99  wdgp->config = NULL;
100  wdgp->state = WDG_STOP;
101 
102  osalSysUnlock();
103 }
104 
105 /**
106  * @brief Resets WDG's counter.
107  *
108  * @param[in] wdgp pointer to the @p WDGDriver object
109  *
110  * @api
111  */
112 void wdgReset(WDGDriver *wdgp) {
113 
114  osalDbgCheck(wdgp != NULL);
115 
116  osalSysLock();
117  osalDbgAssert(wdgp->state == WDG_READY, "not ready");
118  wdgResetI(wdgp);
119  osalSysUnlock();
120 }
121 
122 #endif /* HAL_USE_WDG == TRUE */
123 
124 /** @} */
#define wdgResetI(wdgp)
Resets WDG's counter.
Definition: hal_wdg.h:68
void wdg_lld_start(WDGDriver *wdgp)
Configures and activates the WDG peripheral.
Definition: hal_wdg_lld.c:73
HAL subsystem header.
void wdg_lld_stop(WDGDriver *wdgp)
Deactivates the WDG peripheral.
Definition: hal_wdg_lld.c:85
static void osalSysUnlock(void)
Leaves a critical zone from thread context.
Definition: osal.h:540
wdgstate_t state
Driver state.
Definition: hal_wdg_lld.h:78
const WDGConfig * config
Current configuration data.
Definition: hal_wdg_lld.h:82
void wdgStop(WDGDriver *wdgp)
Deactivates the WDG peripheral.
Definition: hal_wdg.c:89
void wdgInit(void)
WDG Driver initialization.
Definition: hal_wdg.c:56
#define osalDbgCheck(c)
Function parameters check.
Definition: osal.h:278
static void osalSysLock(void)
Enters a critical zone from thread context.
Definition: osal.h:530
Structure representing an WDG driver.
Definition: hal_wdg_lld.h:74
void wdgStart(WDGDriver *wdgp, const WDGConfig *config)
Configures and activates the WDG peripheral.
Definition: hal_wdg.c:69
#define osalDbgAssert(c, remark)
Condition assertion.
Definition: osal.h:258
void wdgReset(WDGDriver *wdgp)
Resets WDG's counter.
Definition: hal_wdg.c:112
void wdg_lld_init(void)
Low level WDG driver initialization.
Definition: hal_wdg_lld.c:62
Driver configuration structure.
Definition: hal_wdg_lld.h:68