S32 SDK
wdog_hal.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015, Freescale Semiconductor, Inc.
3  * Copyright 2016 NXP
4  * All rights reserved.
5  *
6  * THIS SOFTWARE IS PROVIDED BY NXP "AS IS" AND ANY EXPRESSED OR
7  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
8  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
9  * IN NO EVENT SHALL NXP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
10  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
11  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
12  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
13  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
14  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
15  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
16  * THE POSSIBILITY OF SUCH DAMAGE.
17  */
18 
29 #include "wdog_hal.h"
30 
31 
32 /*******************************************************************************
33  * Code
34  ******************************************************************************/
35 /*FUNCTION**********************************************************************
36  *
37  * Function Name : WDOG_HAL_Init
38  * Description : Initializes the WDOG to known state.
39  *
40  * Implements : WDOG_HAL_Init_Activity
41  *END**************************************************************************/
43 {
44  WDOG_UNLOCK(base);
45 
46  /* Set all R/W registers to their reset value. Exception: set UPDATE bit in
47  * order to allow further configurations of the WDOG */
52 
53  /* Reset interrupt flags */
54  base->CS = (base->CS & ~WDOG_CS_FLG_MASK) | WDOG_CS_FLG(1U);
55 }
56 
57 /*FUNCTION**********************************************************************
58  *
59  * Function Name : WDOG_HAL_Config
60  * Description : Configures all WDOG registers.
61  *
62  * Implements : WDOG_HAL_Config_Activity
63  *END**************************************************************************/
64 void WDOG_HAL_Config(WDOG_Type *base, const wdog_user_config_t *config)
65 {
66  uint32_t cs = base->CS;
67 
68  /* Clear the bits used for configuration */
72  /* Construct CS register new value */
73  cs |= WDOG_CS_WIN(config->winEnable? 1UL : 0UL);
74  cs |= WDOG_CS_PRES(config->prescalerEnable? 1UL : 0UL);
75  cs |= WDOG_CS_CLK(config->clkSource);
76  cs |= WDOG_CS_INT(config->intEnable? 1UL : 0UL);
77  cs |= WDOG_CS_UPDATE(config->updateEnable? 1UL : 0UL);
78  cs |= WDOG_CS_DBG(config->opMode.debug? 1UL : 0UL);
79  cs |= WDOG_CS_WAIT(config->opMode.wait? 1UL : 0UL);
80  cs |= WDOG_CS_STOP(config->opMode.stop? 1UL : 0UL);
81  /* Reset interrupt flags */
82  cs |= WDOG_CS_FLG_MASK;
83  /* Enable WDOG in 32-bit mode */
85 
86  WDOG_UNLOCK(base);
87 
88  base->CS = cs;
89  base->TOVAL = config->timeoutValue;
90  if (config->winEnable)
91  {
92  base->WIN = config->windowValue;
93  }
94 }
95 
96 /*FUNCTION**********************************************************************
97  *
98  * Function Name : WDOG_HAL_GetConfig
99  * Description : Gets the current WDOG configuration.
100  *
101  * Implements : WDOG_HAL_GetConfig_Activity
102  *END**************************************************************************/
104 {
105  wdog_user_config_t config;
106  uint32_t cs = base->CS;
107 
108  /* Construct CS register new value */
109  config.winEnable = ((cs & WDOG_CS_WIN_MASK) != 0U);
110  config.prescalerEnable = ((cs & WDOG_CS_PRES_MASK) != 0U);
111  config.intEnable = ((cs & WDOG_CS_INT_MASK) != 0U);
112  config.updateEnable = ((cs & WDOG_CS_UPDATE_MASK) != 0U);
113  config.opMode.debug = ((cs & WDOG_CS_DBG_MASK) != 0U);
114  config.opMode.wait = ((cs & WDOG_CS_WAIT_MASK) != 0U);
115  config.opMode.stop = ((cs & WDOG_CS_STOP_MASK) != 0U);
116  config.timeoutValue = base->TOVAL;
117  config.windowValue = base->WIN;
118 
119  switch((cs & WDOG_CS_CLK_MASK) >> WDOG_CS_CLK_SHIFT)
120  {
121  case 0U:
122  config.clkSource = WDOG_BUS_CLOCK;
123  break;
124  case 1U:
125  config.clkSource = WDOG_LPO_CLOCK;
126  break;
127  case 2U:
128  config.clkSource = WDOG_SOSC_CLOCK;
129  break;
130  case 3U:
131  config.clkSource = WDOG_SIRC_CLOCK;
132  break;
133  default:
134  config.clkSource = WDOG_BUS_CLOCK;
135  break;
136  }
137 
138  return config;
139 }
140 /*******************************************************************************
141  * EOF
142  ******************************************************************************/
143 
#define FEATURE_WDOG_TO_RESET_VALUE
#define WDOG_CS_EN_MASK
Definition: S32K144.h:11323
#define WDOG_CS_CLK(x)
Definition: S32K144.h:11330
#define FEATURE_WDOG_WIN_RESET_VALUE
void WDOG_HAL_Config(WDOG_Type *base, const wdog_user_config_t *config)
Configures all WDOG registers.
Definition: wdog_hal.c:64
#define WDOG_CS_WIN(x)
Definition: S32K144.h:11354
wdog_user_config_t WDOG_HAL_GetConfig(const WDOG_Type *base)
Gets the current WDOG configuration.
Definition: wdog_hal.c:103
#define WDOG_CS_INT_MASK
Definition: S32K144.h:11319
#define WDOG_CS_STOP(x)
Definition: S32K144.h:11302
#define WDOG_CS_FLG(x)
Definition: S32K144.h:11350
#define WDOG_CS_CLK_SHIFT
Definition: S32K144.h:11328
__IO uint32_t CS
Definition: S32K144.h:11263
#define WDOG_CS_UPDATE(x)
Definition: S32K144.h:11318
#define WDOG_CS_PRES_MASK
Definition: S32K144.h:11339
#define WDOG_CS_DBG_MASK
Definition: S32K144.h:11307
WDOG configuration structure Implements : wdog_user_config_t_Class.
Definition: wdog_hal.h:90
uint32_t windowValue
Definition: wdog_hal.h:96
#define WDOG_CS_WIN_MASK
Definition: S32K144.h:11351
void WDOG_HAL_Init(WDOG_Type *base)
Initializes the WDOG.
Definition: wdog_hal.c:42
#define FEATURE_WDOG_CS_RESERVED_MASK
#define WDOG_CS_CLK_MASK
Definition: S32K144.h:11327
wdog_clk_source_t clkSource
Definition: wdog_hal.h:91
__IO uint32_t TOVAL
Definition: S32K144.h:11265
wdog_op_mode_t opMode
Definition: wdog_hal.h:92
#define WDOG_CS_WAIT_MASK
Definition: S32K144.h:11303
#define WDOG_CS_FLG_MASK
Definition: S32K144.h:11347
#define WDOG_UNLOCK(base)
Definition: wdog_hal.h:118
#define WDOG_CS_DBG(x)
Definition: S32K144.h:11310
#define WDOG_CS_STOP_MASK
Definition: S32K144.h:11299
#define WDOG_CS_CMD32EN_MASK
Definition: S32K144.h:11343
#define WDOG_CS_WAIT(x)
Definition: S32K144.h:11306
uint32_t timeoutValue
Definition: wdog_hal.h:97
#define WDOG_CS_UPDATE_MASK
Definition: S32K144.h:11315
bool prescalerEnable
Definition: wdog_hal.h:98
#define WDOG_CS_INT(x)
Definition: S32K144.h:11322
#define WDOG_CS_PRES(x)
Definition: S32K144.h:11342
__IO uint32_t WIN
Definition: S32K144.h:11266