ChibiOS/HAL 9.0.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 */
56void wdgInit(void) {
57
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 * @return The operation status.
67 *
68 * @api
69 */
70msg_t wdgStart(WDGDriver *wdgp, const WDGConfig *config) {
71 msg_t msg;
72
73 osalDbgCheck((wdgp != NULL) && (config != NULL));
74
76 osalDbgAssert((wdgp->state == WDG_STOP) || (wdgp->state == WDG_READY),
77 "invalid state");
78
79 wdgp->config = config;
80
81#if defined(WDG_LLD_ENHANCED_API)
82 msg = wdg_lld_start(wdgp);
83 if (msg == HAL_RET_SUCCESS) {
84 wdgp->state = WDG_READY;
85 }
86 else {
87 wdgp->state = WDG_STOP;
88 }
89#else
90 wdg_lld_start(wdgp);
91 wdgp->state = WDG_READY;
92 msg = HAL_RET_SUCCESS;
93#endif
94
96
97 return msg;
98}
99
100/**
101 * @brief Deactivates the WDG peripheral.
102 *
103 * @param[in] wdgp pointer to the @p WDGDriver object
104 *
105 * @api
106 */
107void wdgStop(WDGDriver *wdgp) {
108
109 osalDbgCheck(wdgp != NULL);
110
111 osalSysLock();
112
113 osalDbgAssert((wdgp->state == WDG_STOP) || (wdgp->state == WDG_READY),
114 "invalid state");
115
116 wdg_lld_stop(wdgp);
117 wdgp->config = NULL;
118 wdgp->state = WDG_STOP;
119
121}
122
123/**
124 * @brief Resets WDG's counter.
125 *
126 * @param[in] wdgp pointer to the @p WDGDriver object
127 *
128 * @api
129 */
130void wdgReset(WDGDriver *wdgp) {
131
132 osalDbgCheck(wdgp != NULL);
133
134 osalSysLock();
135 osalDbgAssert(wdgp->state == WDG_READY, "not ready");
136 wdgResetI(wdgp);
138}
139
140#endif /* HAL_USE_WDG == TRUE */
141
142/** @} */
#define HAL_RET_SUCCESS
Definition hal.h:93
static void osalSysLock(void)
Enters a critical zone from thread context.
Definition osal.h:601
static void osalSysUnlock(void)
Leaves a critical zone from thread context.
Definition osal.h:611
int32_t msg_t
Type of a message.
Definition osal.h:159
#define osalDbgAssert(c, remark)
Condition assertion.
Definition osal.h:264
#define osalDbgCheck(c)
Function parameters check.
Definition osal.h:284
void wdgReset(WDGDriver *wdgp)
Resets WDG's counter.
Definition hal_wdg.c:130
void wdg_lld_init(void)
Low level WDG driver initialization.
Definition hal_wdg_lld.c:62
msg_t wdgStart(WDGDriver *wdgp, const WDGConfig *config)
Configures and activates the WDG peripheral.
Definition hal_wdg.c:70
void wdgInit(void)
WDG Driver initialization.
Definition hal_wdg.c:56
void wdgStop(WDGDriver *wdgp)
Deactivates the WDG peripheral.
Definition hal_wdg.c:107
#define wdgResetI(wdgp)
Resets WDG's counter.
Definition hal_wdg.h:68
void wdg_lld_stop(WDGDriver *wdgp)
Deactivates the WDG peripheral.
Definition hal_wdg_lld.c:85
void wdg_lld_start(WDGDriver *wdgp)
Configures and activates the WDG peripheral.
Definition hal_wdg_lld.c:73
@ WDG_READY
Definition hal_wdg.h:52
@ WDG_STOP
Definition hal_wdg.h:51
HAL subsystem header.
Driver configuration structure.
Definition hal_wdg_lld.h:68
Structure representing an WDG driver.
Definition hal_wdg_lld.h:74
const WDGConfig * config
Current configuration data.
Definition hal_wdg_lld.h:82
wdgstate_t state
Driver state.
Definition hal_wdg_lld.h:78