1 /**
2  * @file xmc_wdt.c
3  * @date 2015-06-20
4  *
5  * @cond
6  *********************************************************************************************************************
7  * XMClib v2.1.24 - XMC Peripheral Driver Library
8  *
9  * Copyright (c) 2015-2019, Infineon Technologies AG
10  * All rights reserved.
11  *
12  * Redistribution and use in source and binary forms, with or without modification,are permitted provided that the
13  * following conditions are met:
14  *
15  * Redistributions of source code must retain the above copyright notice, this list of conditions and the following
16  * disclaimer.
17  *
18  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
19  * disclaimer in the documentation and/or other materials provided with the distribution.
20  *
21  * Neither the name of the copyright holders nor the names of its contributors may be used to endorse or promote
22  * products derived from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
25  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE  FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29  * WHETHER IN CONTRACT, STRICT LIABILITY,OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * To improve the quality of the software, users are encouraged to share modifications, enhancements or bug fixes with
33  * Infineon Technologies AG dave@infineon.com).
34  *********************************************************************************************************************
35  *
36  * Change History
37  * --------------
38  *
39  * 2015-02-20:
40  *     - Initial <br>
41  *
42  * 2015-06-20:
43  *     - Removed definition of GetDriverVersion API <br>
44  *
45  * @endcond
46  */
47 
48 /*********************************************************************************************************************
49  * HEADER FILES
50  ********************************************************************************************************************/
51 #include "xmc_wdt.h"
52 #include "xmc_scu.h"
53 
54 /*********************************************************************************************************************
55  * API IMPLEMENTATION
56   ********************************************************************************************************************/
57 
58 /* Enables watchdog clock and releases watchdog reset. */
XMC_WDT_Enable(void)59 void XMC_WDT_Enable(void)
60 {
61 #if UC_FAMILY == XMC4
62   XMC_SCU_CLOCK_EnableClock(XMC_SCU_CLOCK_WDT);
63 #endif
64 
65 #if defined(CLOCK_GATING_SUPPORTED)
66   XMC_SCU_CLOCK_UngatePeripheralClock(XMC_SCU_PERIPHERAL_CLOCK_WDT);
67 #endif
68 #if defined(PERIPHERAL_RESET_SUPPORTED)
69   XMC_SCU_RESET_DeassertPeripheralReset(XMC_SCU_PERIPHERAL_RESET_WDT);
70 #endif
71 }
72 
73 /* Disables watchdog clock and resets watchdog. */
XMC_WDT_Disable(void)74 void XMC_WDT_Disable(void)
75 {
76 #if defined(PERIPHERAL_RESET_SUPPORTED)
77   XMC_SCU_RESET_AssertPeripheralReset(XMC_SCU_PERIPHERAL_RESET_WDT);
78 #endif
79 #if defined(CLOCK_GATING_SUPPORTED)
80   XMC_SCU_CLOCK_GatePeripheralClock(XMC_SCU_PERIPHERAL_CLOCK_WDT);
81 #endif
82 
83 #if UC_FAMILY == XMC4
84   XMC_SCU_CLOCK_DisableClock(XMC_SCU_CLOCK_WDT);
85 #endif
86 }
87 /* Initializes and configures watchdog with configuration data pointed by \a config. */
XMC_WDT_Init(const XMC_WDT_CONFIG_t * const config)88 void XMC_WDT_Init(const XMC_WDT_CONFIG_t *const config)
89 {
90   XMC_WDT_Enable();
91   WDT->CTR = config->wdt_ctr;
92   WDT->WLB = config->window_lower_bound;
93   WDT->WUB = config->window_upper_bound;
94 }
95