RTEMS 6.1-rc6
Loading...
Searching...
No Matches
fsl_rtwdog.h
1/*
2 * Copyright (c) 2016, Freescale Semiconductor, Inc.
3 * Copyright 2016-2020 NXP
4 * All rights reserved.
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8#ifndef _FSL_RTWDOG_H_
9#define _FSL_RTWDOG_H_
10
11#include "fsl_common.h"
12
18/*******************************************************************************
19 * Definitions
20 *******************************************************************************/
23#define WDOG_FIRST_WORD_OF_UNLOCK (RTWDOG_UPDATE_KEY & 0xFFFFU)
24#define WDOG_SECOND_WORD_OF_UNLOCK ((RTWDOG_UPDATE_KEY >> 16U) & 0xFFFFU)
26
29#define WDOG_FIRST_WORD_OF_REFRESH (RTWDOG_REFRESH_KEY & 0xFFFFU)
30#define WDOG_SECOND_WORD_OF_REFRESH ((RTWDOG_REFRESH_KEY >> 16U) & 0xFFFFU)
35#define FSL_RTWDOG_DRIVER_VERSION (MAKE_VERSION(2, 1, 2))
40{
46
49{
53
55typedef struct _rtwdog_work_mode
56{
61
64{
70
72typedef struct _rtwdog_config
73{
82 uint16_t windowValue;
83 uint16_t timeoutValue;
85
92{
93 kRTWDOG_InterruptEnable = RTWDOG_CS_INT_MASK,
94};
95
102{
103 kRTWDOG_RunningFlag = RTWDOG_CS_EN_MASK,
104 kRTWDOG_InterruptFlag = RTWDOG_CS_FLG_MASK,
105};
106
107/*******************************************************************************
108 * API
109 *******************************************************************************/
110
111#if defined(__cplusplus)
112extern "C" {
113#endif /* __cplusplus */
114
144
165#if defined(DOXYGEN_OUTPUT) && DOXYGEN_OUTPUT
166void RTWDOG_Init(RTWDOG_Type *base, const rtwdog_config_t *config);
167#else
168AT_QUICKACCESS_SECTION_CODE(void RTWDOG_Init(RTWDOG_Type *base, const rtwdog_config_t *config));
169#endif
170
179void RTWDOG_Deinit(RTWDOG_Type *base);
180
181/* @} */
182
197static inline void RTWDOG_Enable(RTWDOG_Type *base)
198{
199 base->CS |= RTWDOG_CS_EN_MASK;
200}
201
211static inline void RTWDOG_Disable(RTWDOG_Type *base)
212{
213 base->CS &= ~RTWDOG_CS_EN_MASK;
214}
215
228static inline void RTWDOG_EnableInterrupts(RTWDOG_Type *base, uint32_t mask)
229{
230 base->CS |= mask;
231}
232
245static inline void RTWDOG_DisableInterrupts(RTWDOG_Type *base, uint32_t mask)
246{
247 base->CS &= ~mask;
248}
249
265static inline uint32_t RTWDOG_GetStatusFlags(RTWDOG_Type *base)
266{
267 return (base->CS & (RTWDOG_CS_EN_MASK | RTWDOG_CS_FLG_MASK));
268}
269
276static inline void RTWDOG_EnableWindowMode(RTWDOG_Type *base, bool enable)
277{
278 if (enable)
279 {
280 base->CS |= RTWDOG_CS_WIN_MASK;
281 }
282 else
283 {
284 base->CS &= ~RTWDOG_CS_WIN_MASK;
285 }
286}
287
298static inline uint32_t RTWDOG_CountToMesec(RTWDOG_Type *base, uint32_t count, uint32_t clockFreqInHz)
299{
300 if ((base->CS & RTWDOG_CS_PRES_MASK) != 0U)
301 {
302 clockFreqInHz /= 256U;
303 }
304 return count * 1000U / clockFreqInHz;
305}
306
321void RTWDOG_ClearStatusFlags(RTWDOG_Type *base, uint32_t mask);
322
333static inline void RTWDOG_SetTimeoutValue(RTWDOG_Type *base, uint16_t timeoutCount)
334{
335 base->TOVAL = timeoutCount;
336}
337
348static inline void RTWDOG_SetWindowValue(RTWDOG_Type *base, uint16_t windowValue)
349{
350 base->WIN = windowValue;
351}
352
364__STATIC_FORCEINLINE void RTWDOG_Unlock(RTWDOG_Type *base)
365{
366 if (((base->CS) & RTWDOG_CS_CMD32EN_MASK) != 0U)
367 {
368 base->CNT = RTWDOG_UPDATE_KEY;
369 }
370 else
371 {
372 base->CNT = WDOG_FIRST_WORD_OF_UNLOCK;
373 base->CNT = WDOG_SECOND_WORD_OF_UNLOCK;
374 }
375 while ((base->CS & RTWDOG_CS_ULK_MASK) == 0U)
376 {
377 }
378}
379
388static inline void RTWDOG_Refresh(RTWDOG_Type *base)
389{
390 uint32_t primaskValue = 0U;
391 primaskValue = DisableGlobalIRQ();
392 if (((base->CS) & RTWDOG_CS_CMD32EN_MASK) != 0U)
393 {
394 base->CNT = RTWDOG_REFRESH_KEY;
395 }
396 else
397 {
398 base->CNT = WDOG_FIRST_WORD_OF_REFRESH;
399 base->CNT = WDOG_SECOND_WORD_OF_REFRESH;
400 }
401 EnableGlobalIRQ(primaskValue);
402}
403
412static inline uint16_t RTWDOG_GetCounterValue(RTWDOG_Type *base)
413{
414 return (uint16_t)base->CNT;
415}
416
419#if defined(__cplusplus)
420}
421#endif /* __cplusplus */
422
425#endif /* _FSL_RTWDOG_H_ */
enum _rtwdog_clock_source rtwdog_clock_source_t
Describes RTWDOG clock source.
#define WDOG_FIRST_WORD_OF_REFRESH
Definition: fsl_rtwdog.h:29
bool enableStop
Definition: fsl_rtwdog.h:58
uint16_t windowValue
Definition: fsl_rtwdog.h:82
rtwdog_test_mode_t testMode
Definition: fsl_rtwdog.h:78
rtwdog_work_mode_t workMode
Definition: fsl_rtwdog.h:77
#define WDOG_SECOND_WORD_OF_REFRESH
Definition: fsl_rtwdog.h:30
bool enableWindowMode
Definition: fsl_rtwdog.h:81
enum _rtwdog_test_mode rtwdog_test_mode_t
Describes RTWDOG test mode.
_rtwdog_interrupt_enable_t
RTWDOG interrupt configuration structure.
Definition: fsl_rtwdog.h:92
uint16_t timeoutValue
Definition: fsl_rtwdog.h:83
void RTWDOG_Deinit(RTWDOG_Type *base)
De-initializes the RTWDOG module.
Definition: fsl_rtwdog.c:139
_rtwdog_test_mode
Describes RTWDOG test mode.
Definition: fsl_rtwdog.h:64
void RTWDOG_ClearStatusFlags(RTWDOG_Type *base, uint32_t mask)
Clears the RTWDOG flag.
Definition: fsl_rtwdog.c:34
struct _rtwdog_config rtwdog_config_t
Describes RTWDOG configuration structure.
enum _rtwdog_clock_prescaler rtwdog_clock_prescaler_t
Describes the selection of the clock prescaler.
#define WDOG_FIRST_WORD_OF_UNLOCK
Definition: fsl_rtwdog.h:23
bool enableUpdate
Definition: fsl_rtwdog.h:79
void RTWDOG_GetDefaultConfig(rtwdog_config_t *config)
Initializes the RTWDOG configuration structure.
Definition: fsl_rtwdog.c:65
_rtwdog_clock_prescaler
Describes the selection of the clock prescaler.
Definition: fsl_rtwdog.h:49
_rtwdog_status_flags_t
RTWDOG status flags.
Definition: fsl_rtwdog.h:102
bool enableWait
Definition: fsl_rtwdog.h:57
_rtwdog_clock_source
Describes RTWDOG clock source.
Definition: fsl_rtwdog.h:40
rtwdog_clock_prescaler_t prescaler
Definition: fsl_rtwdog.h:76
bool enableInterrupt
Definition: fsl_rtwdog.h:80
__STATIC_FORCEINLINE void RTWDOG_Unlock(RTWDOG_Type *base)
Unlocks the RTWDOG register written.
Definition: fsl_rtwdog.h:364
rtwdog_clock_source_t clockSource
Definition: fsl_rtwdog.h:75
#define WDOG_SECOND_WORD_OF_UNLOCK
Definition: fsl_rtwdog.h:24
struct _rtwdog_work_mode rtwdog_work_mode_t
Defines RTWDOG work mode.
bool enableRtwdog
Definition: fsl_rtwdog.h:74
bool enableDebug
Definition: fsl_rtwdog.h:59
@ kRTWDOG_InterruptEnable
Definition: fsl_rtwdog.h:93
@ kRTWDOG_TestModeDisabled
Definition: fsl_rtwdog.h:65
@ kRTWDOG_HighByteTest
Definition: fsl_rtwdog.h:68
@ kRTWDOG_LowByteTest
Definition: fsl_rtwdog.h:67
@ kRTWDOG_UserModeEnabled
Definition: fsl_rtwdog.h:66
@ kRTWDOG_ClockPrescalerDivide256
Definition: fsl_rtwdog.h:51
@ kRTWDOG_ClockPrescalerDivide1
Definition: fsl_rtwdog.h:50
@ kRTWDOG_RunningFlag
Definition: fsl_rtwdog.h:103
@ kRTWDOG_InterruptFlag
Definition: fsl_rtwdog.h:104
@ kRTWDOG_ClockSource1
Definition: fsl_rtwdog.h:42
@ kRTWDOG_ClockSource2
Definition: fsl_rtwdog.h:43
@ kRTWDOG_ClockSource0
Definition: fsl_rtwdog.h:41
@ kRTWDOG_ClockSource3
Definition: fsl_rtwdog.h:44
Definition: MIMXRT1052.h:39520
Describes RTWDOG configuration structure.
Definition: fsl_rtwdog.h:73
Defines RTWDOG work mode.
Definition: fsl_rtwdog.h:56
Definition: deflate.c:114