IRPyro messaging application
Communications program between IRPyro and IRPyro evaluation tool
Watchdog_Driver.c
Go to the documentation of this file.
1
/**
2
******************************************************************************
3
* @file Watchdog_Driver.c
4
* @author Hugo Vargas Llanas, _KEMET Ltd.
5
* @date 21-April-2015
6
* @version v1.1
7
* @brief This file contains all the functions involving the watchdog Timer
8
******************************************************************************
9
*/
10
11
12
/* Includes ------------------------------------------------------------------*/
13
#include "
Watchdog_Driver.h
"
14
15
/* Private Variables -----------------------------------------------------*/
16
static
Watchdog_Config_Type
Config
= {0};
// Configuration Structure
17
static
uint8_t
Config_Set_Flag
= 0;
// Flag indicating that module has been configured
18
19
/** @defgroup Watchdog Watchdog driver
20
* @ingroup IRPyro_microcontroller_interface
21
* @{
22
*/
23
/**
24
* @brief Initializes the Watchdog Timer used incase the MCU hangs up
25
*/
26
void
Watchdog_Init
(
Watchdog_Config_Type
* External_Config)
27
{
28
29
// Check Configuration
30
if
(External_Config)
31
{
32
Config
.
Enabled
= External_Config->
Enabled
;
33
Config
.
Short_Timeout
= External_Config->
Short_Timeout
;
34
Config
.
Long_Timeout
= External_Config->
Long_Timeout
;
35
Config
.
Timeout_Setting_Default
= External_Config->
Timeout_Setting_Default
;
36
37
// Only initialize if Watchdog Enabled Flag is set
38
if
(
Config
.
Enabled
)
39
{
40
// Enable Writing
41
IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
42
43
// Set prescaler to 16
44
IWDG_SetPrescaler(IWDG_Prescaler_256);
45
46
// Set reload value
47
if
(
Config
.
Timeout_Setting_Default
==
Long_Timeout
)
48
{
49
IWDG_SetReload(
Config
.
Long_Timeout
);
50
}
51
else
52
{
53
IWDG_SetReload(
Config
.
Short_Timeout
);
54
}
55
56
// Disable Writing
57
IWDG_WriteAccessCmd(IWDG_WriteAccess_Disable);
58
59
// Reload Counter
60
IWDG_ReloadCounter();
61
62
// Initialize Watchdog
63
IWDG_Enable();
64
}
65
66
// Set configure flag
67
Config_Set_Flag
=1;
68
}
69
70
}
71
72
/**
73
* @brief Used to increase the timeout period.
74
* This is used when the device is going to be doing a very time consuming task
75
* that would temporarily freeze the main loop.
76
*/
77
void
Timeout_Set
(
Timeout_Length_Type
Timeout_Length_Types)
78
{
79
80
// Only change if configure flag is set
81
if
(
Config_Set_Flag
)
82
{
83
84
// Enable Writing
85
IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
86
87
// Set reload value
88
if
(Timeout_Length_Types ==
Long_Timeout
)
89
{
90
IWDG_SetReload(
Config
.
Long_Timeout
);
91
}
92
else
93
{
94
IWDG_SetReload(
Config
.
Short_Timeout
);
95
}
96
97
// Disable Writing
98
IWDG_WriteAccessCmd(IWDG_WriteAccess_Disable);
99
100
// Ensure Watchdog is ready
101
while
(IWDG_GetFlagStatus(IWDG_FLAG_RVU)) {};
102
103
// Reload Counter
104
IWDG_ReloadCounter();
105
}
106
}
107
/**
108
* @brief Reloads the counter for the watchdog to avoid resetting when the hardware has not hung up.
109
*/
110
void
Reload_Counter
(
void
)
111
{
112
113
// Only set if configure flag is set
114
if
(
Config_Set_Flag
)
115
{
116
// Reload Counter
117
IWDG_ReloadCounter();
118
}
119
}
120
/** end of Watchdog driver group
121
* @}
122
*/
123
124
/* ********** Copyright (c) 2018 _KEMET, Ltd. **********END OF FILE************/
Config
static Watchdog_Config_Type Config
Definition:
Watchdog_Driver.c:16
Watchdog_Config_Type::Long_Timeout
uint16_t Long_Timeout
Definition:
Watchdog_Driver.h:30
Long_Timeout
@ Long_Timeout
Definition:
Watchdog_Driver.h:24
Watchdog_Init
void Watchdog_Init(Watchdog_Config_Type *External_Config)
Initializes the Watchdog Timer used incase the MCU hangs up.
Definition:
Watchdog_Driver.c:26
Timeout_Length_Type
Timeout_Length_Type
Definition:
Watchdog_Driver.h:22
Watchdog_Config_Type::Short_Timeout
uint16_t Short_Timeout
Definition:
Watchdog_Driver.h:29
Watchdog_Config_Type::Enabled
uint8_t Enabled
Definition:
Watchdog_Driver.h:28
Timeout_Set
void Timeout_Set(Timeout_Length_Type Timeout_Length_Types)
Used to increase the timeout period. This is used when the device is going to be doing a very time co...
Definition:
Watchdog_Driver.c:77
Watchdog_Config_Type
Definition:
Watchdog_Driver.h:27
Config_Set_Flag
static uint8_t Config_Set_Flag
Definition:
Watchdog_Driver.c:17
Watchdog_Driver.h
This file contains all the functions involving the watchdog Timer.
Watchdog_Config_Type::Timeout_Setting_Default
Timeout_Length_Type Timeout_Setting_Default
Definition:
Watchdog_Driver.h:31
Reload_Counter
void Reload_Counter(void)
Reloads the counter for the watchdog to avoid resetting when the hardware has not hung up.
Definition:
Watchdog_Driver.c:110
source
IRPyro_API_messaging_application
src
Watchdog_Driver.c
Generated on Thu Jul 2 2020 16:22:16 for IRPyro messaging application by
1.8.18