blob: 75b79ca417e825283f354d9a7d38a92a0ee84362 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
/******************************************************************************
* @brief provide commond watch dog utilities.
*
*******************************************************************************
*
* provide APIs for accessing watch dog
******************************************************************************/
#ifndef __WDOG_H__
#define __WDOG_H__
#ifdef __cplusplus
extern "C" {
#endif
/******************************************************************************
* Includes
******************************************************************************/
#include "sim.h"
/******************************************************************************
* Constants
******************************************************************************/
/******************************************************************************
* Macros
******************************************************************************/
/* wdog_unlock sequence must be performed within 16 bus clock cycles without
* any interrupt
*/
/* WDOG clock sources option */
/******************************************************************************
* define watchdog clock source selection
*
*//*! @addtogroup wdog_clock_sources
* @{
*******************************************************************************/
#define WDOG_CLK_BUS 0 /*!< clock source is bus clock */
#define WDOG_CLK_INTERNAL_32KHZ 2 /*!< clock source is internal oscillator 32 kHz (ICSIRCLK) */
#define WDOG_CLK_INTERNAL_1KHZ 1 /*!< clock source is internal LPO 1 KHz */
#define WDOG_CLK_EXTERNAL 3 /*!< clock source is external clock */
/*! @} End of wdog_clock_sources */
/* WDOG clock source selection */
#define WDOG_CLK (WDOG_CLK_INTERNAL_1KHZ)
/* WDOG default values */
#define WDOG_CS1_DEFAULT_VALUE 0x80
#define WDOG_CS2_DEFAULT_VALUE 0x01
#define WDOG_TOVAL_DEFAULT_VALUE 0x0400
#define WDOG_WIN_DEFAULT_VALUE 0x0000
/* WDOG utilities */
/******************************************************************************
* define watchdog API list
*
*//*! @addtogroup wdog_api_list
* @{
*******************************************************************************/
/*!
* @brief watchdog unlock routine.
*/
#define WDOG_Unlock() WDOG->CNT = 0x20C5; WDOG->CNT = 0x28D9
//#define WDOG_Unlock() DisableInterrupts; WDOG->CNT = 0x20C5; WDOG->CNT = 0x28D9; EnableInterrupts
/*! @} End of wdog_api_list */
/******************************************************************************
* Types
******************************************************************************/
/******************************************************************************
* define watchdog configuration structure
*
*//*! @addtogroup wdog_config_type
* @{
*******************************************************************************/
/*!
* @brief watchdog configuration structure.
*
*/
typedef struct {
struct {
uint16_t bIntEnable : 1; /*!< watchdog interrupt enable */
uint16_t bDisable : 1; /*!< disable watchdog */
uint16_t bWaitEnable : 1; /*!< enable watchdog in wait mode */
uint16_t bStopEnable : 1; /*!< enable watchdog in stop mode */
uint16_t bDbgEnable : 1; /*!< enable watchdog in debug mode */
uint16_t bWinEnable : 1; /*!< enable watchdog window mode */
uint16_t bUpdateEnable : 1; /*!< enable update of watchdog control */
uint16_t bClkSrc : 2; /*!< watchdog clock source selection */
uint16_t bPrescaler : 1; /*!< prescaler */
}sBits; /*!< bitfield structure */
uint16_t u16ETMeOut; /*!< watchdog ETMeout value */
uint16_t u16WinETMe; /*!< watchdog window value */
} WDOG_ConfigType, *WDOG_ConfigPtr; /*!< watchdog configuration structure type */
/*! @} End of wdog_config_type */
/******************************************************************************
* Global variables
******************************************************************************/
/******************************************************************************
* Global functions
******************************************************************************/
/******************************************************************************
* define watchdog API list
*
*//*! @addtogroup wdog_api_list
* @{
*******************************************************************************/
/*****************************************************************************//*!
*
* @brief set ETMe out value for WDOG.
*
* @param[in] u16ETMeOut ETMeout value to TOVAL register.
*
* @return none
*
* @ Pass/ Fail criteria: none
*
*****************************************************************************/
__STATIC_INLINE void WDOG_SetETMeOut(uint16_t u16ETMeOut)
{
WDOG->CNT = 0x20C5;
WDOG->CNT = 0x28D9;
WDOG->TOVAL8B.TOVALL = u16ETMeOut;
WDOG->TOVAL8B.TOVALH = u16ETMeOut >> 8;
}
/*****************************************************************************//*!
*
* @brief set window value for WDOG.
*
* @param[in] u16WinETMe window value to WIN register.
*
* @return none
*
* @ Pass/ Fail criteria: none
*
*****************************************************************************/
__STATIC_INLINE void WDOG_SetWindow(uint16_t u16WinETMe)
{
WDOG->CNT = 0x20C5;
WDOG->CNT = 0x28D9;
WDOG->WIN8B.WINL = u16WinETMe;
WDOG->WIN8B.WINH = u16WinETMe >> 8;
}
/*****************************************************************************//*!
*
* @brief check if watchdog reset occurs.
*
* @param none.
*
* @return TRUE if watchdog reset occurs, FALSE otherwise.
*
* @ Pass/ Fail criteria: none
*****************************************************************************/
__STATIC_INLINE uint8_t WDOG_IsReset(void)
{
if(SIM_GetStatus(SIM_SRSID_WDOG_MASK))
{
return (TRUE);
}
return (FALSE);
}
/*! @} End of wdog_api_list */
void WDOG_Init(WDOG_ConfigPtr pConfig);
void WDOG_DeInit(void);
void WDOG_Disable(void);
void WDOG_DisableWDOGEnableUpdate(void);
void WDOG_Enable(void);
void WDOG_Feed(void);
void WDOG_SetETMeOut(uint16_t u16ETMeOut);
void WDOG_SetWindow(uint16_t u16WinETMe);
void WDOG_EnableUpdate(void);
void WDOG_DisableUpdate(void);
uint8_t WDOG_IsReset(void);
#ifdef __cplusplus
}
#endif
/********************************************************************/
#endif /* __WDOG_H__ */
|