Callisto4Bootloader: lib/c4_watchdog.c File Reference

Callisto4Bootloader

Macros | Functions | Variables
c4_watchdog.c File Reference

Implements watchdog functionality. More...

`#include "c4_watchdog_types.h"`
`#include "c4_watchdog.h"`
`#include "bl_api.h"`
`#include "fsl_wdog.h"`
`#include <stdbool.h>`

Go to the source code of this file.

## Macros

#define | PRINT_BIT(base, reg) printf("\t "#base"."#reg" : %s\n", (base.B.reg ? "TRUE" : "false"))
| Macro to print specified bit as boolean. More...

## Functions

void | WDOG1_IRQHandler (void)
| Watchdog interrupt handler function. More...
exit_code_t | c4_initWatchdog (c4_wdog_t wdog, uint16_t to, uint16_t ito)
| Initialise watchdog subsystem. More...
exit_code_t | c4_disableWdog (c4_wdog_t wdog)
| disables the watchdog. More...
exit_code_t | c4_enableWdog (c4_wdog_t wdog)
| enables the watchdog. More...
exit_code_t | c4_setWdogTimeout (c4_wdog_t wdog, uint16_t to)
| Set timeout on watchdog. More...
exit_code_t | c4_setWdogInterrupt (c4_wdog_t wdog, uint16_t to)
| Enable interrupt on watchdog before expiry. More...
exit_code_t | c4_getResetHistory ()
| Retrieve reset history from watchdog registers and from System Register. More...

## Variables

static const uint16_t | WDOG_MAX_TO = 1280U
| Maximum watchdog timeout in deciseconds (ds). More...
static const uint16_t | WDOG_MIN_TO = 5U
| Minimum watchdog timeout in deciseconds (ds). More...
static const uint16_t | WDOG_MAX_INT = 1275U
| Maximum watchdog interrupt delay in deciseconds (ds). More...
static const uint16_t | WDOG_MIN_INT = 0U
| Minimum timeout in deciseconds (ds). More...
wdog_config_t | sWdogConfig [C4_NUM_WDOG]
| Watchdog configuration structures. More...
c4_WDOG_reg_t *const | sWdogRegisters [C4_NUM_WDOG]
| Watchdog control registers. More...
static bool | WDOG_INITIALISED = false
| Flag to prevent reinitialisation of watchdogs. More...

## Detailed Description

Implements watchdog functionality.

The watchdog is initialised and setup to reset the processor if it is not serviced within the timeout.

It is up to the main processor to add a mechanism to service the watchdog.

An interrupt is set to be raised a fixed time before the watchdog expires.

Copyright
  2020 Remsdaq Ltd.

Date
  : 23 Jul 2020

Author
  : Dan Smithers dwhs@.nosp@m.rems.nosp@m.daq.c.nosp@m.om

Definition in file c4_watchdog.c.

## Macro Definition Documentation

## ◆ PRINT_BIT

#define PRINT_BIT | ( |  | base,
|  |  | reg
| ) |  | printf("\t "#base"."#reg" : %s\n", (base.B.reg ? "TRUE" : "false"))

Macro to print specified bit as boolean.

The macro expands a bit-field variable that is overlaid on a register and prints on the output.

Parameters

  base | Register to print. This is a bit-field on a register.
  reg | Name of bit-field entry to print.

Definition at line 55 of file c4_watchdog.c.

## Function Documentation

## ◆ c4_disableWdog()

exit_code_t c4_disableWdog | ( | c4_wdog_t | wdog | ) |

disables the watchdog.

Parameters

  [in] | wdog | Watchdog to disable.

Returns
  exit code

Return values

  ERR_OK | - success.

Definition at line 159 of file c4_watchdog.c.

## ◆ c4_enableWdog()

exit_code_t c4_enableWdog | ( | c4_wdog_t | wdog | ) |

enables the watchdog.

Parameters

  [in] | wdog | Watchdog to enable.

Returns
  exit code

Return values

  ERR_OK | - success.

Definition at line 176 of file c4_watchdog.c.

## ◆ c4_getResetHistory()

exit_code_t c4_getResetHistory | ( |  | ) |

Retrieve reset history from watchdog registers and from System Register.

Returns
  exit code

Return values

  ERR_OK | - success.

Definition at line 258 of file c4_watchdog.c.

## ◆ c4_initWatchdog()

exit_code_t c4_initWatchdog | ( | c4_wdog_t | wdog,
|  | uint16_t | to,
|  | uint16_t | ito
| ) |  |

Initialise watchdog subsystem.

Timeout for Watchdog is specified in deci-seconds in half-second increments.

The register timeout range is 0x00 - 0xFF which is 0.5 - 128 s or 50 - 1280 ds.

The watchdog timeout can be changed at any point and will take effect the next time the watchdog is reset.

Interrupt time ahead of expiry for watchdog is in deci-seconds in half-second increments.

The register interrupt ante-delay range is 0x00 - 0xFF which is 0 - 127.5 s or 0 - 1275 ds.

Note
  The interrupt value can be set once once only and cannot be changed until the next system reset.

Definition at line 109 of file c4_watchdog.c.

## ◆ c4_setWdogInterrupt()

exit_code_t c4_setWdogInterrupt | ( | c4_wdog_t | wdog,
|  | uint16_t | to
| ) |  |

Enable interrupt on watchdog before expiry.

It appears that this can only be set before the watchdog is enabled, and that the interrupt time and enable bit must be set together.

Definition at line 213 of file c4_watchdog.c.

References c4_WDOG_reg_t::B, c4_WDOG_reg_t::c4_WDOG_wicr::B, C4_WDOG1, C4_WDOG2, NVIC_EnableIRQ, c4_WDOG_reg_t::c4_WDOG_wicr::R, sWdogRegisters, WDOG1_IRQn, WDOG2_IRQn, WDOG_MAX_INT, WDOG_MIN_INT, c4_WDOG_reg_t::WICR, and c4_WDOG_reg_t::c4_WDOG_wicr::WICT.

## ◆ c4_setWdogTimeout()

exit_code_t c4_setWdogTimeout | ( | c4_wdog_t | wdog,
|  | uint16_t | to
| ) |  |

Set timeout on watchdog.

This enables the watchdog for the specified timeout.

Parameters

  [in] | wdog | Watchdog to programme.
  [in] | to | Timeout in deci-seconds.

Returns
  exit code

Return values

  ERR_OK | - success.

Definition at line 193 of file c4_watchdog.c.

## ◆ WDOG1_IRQHandler()

WEAK void WDOG1_IRQHandler | ( | void |  | ) |

Watchdog interrupt handler function.

This over-rides the WEAK function defined in startup_mimxrt1062.h

The interrupt also needs to be enabled before it is active using

NVIC_EnableIRQ(WDOG1_IRQn);

Definition at line 300 of file c4_watchdog.c.

## Variable Documentation

## ◆ sWdogConfig

wdog_config_t sWdogConfig[C4_NUM_WDOG]

Watchdog configuration structures.

Definition at line 80 of file c4_watchdog.c.

## ◆ sWdogRegisters

c4_WDOG_reg_t* const sWdogRegisters[C4_NUM_WDOG]

Initial value:
=
{(c4_WDOG_reg_t *)WDOG1_BASE,
(c4_WDOG_reg_t *)WDOG2_BASE}

Watchdog control registers.

This is equivalent to the WDOG_Type representation.

Definition at line 85 of file c4_watchdog.c.

Referenced by c4_setWdogInterrupt(), and watchdog_test().

## ◆ WDOG_INITIALISED

bool WDOG_INITIALISED = false

static

Flag to prevent reinitialisation of watchdogs.

Definition at line 90 of file c4_watchdog.c.

## ◆ WDOG_MAX_INT

const uint16_t WDOG_MAX_INT = 1275U

static

Maximum watchdog interrupt delay in deciseconds (ds).

Definition at line 42 of file c4_watchdog.c.

Referenced by c4_setWdogInterrupt().

## ◆ WDOG_MAX_TO

const uint16_t WDOG_MAX_TO = 1280U

static

Maximum watchdog timeout in deciseconds (ds).

Definition at line 36 of file c4_watchdog.c.

## ◆ WDOG_MIN_INT

const uint16_t WDOG_MIN_INT = 0U

static

Minimum timeout in deciseconds (ds).

Definition at line 45 of file c4_watchdog.c.

Referenced by c4_setWdogInterrupt().

## ◆ WDOG_MIN_TO

const uint16_t WDOG_MIN_TO = 5U

static

Minimum watchdog timeout in deciseconds (ds).

Definition at line 39 of file c4_watchdog.c.

WDOG2_BASE
#define WDOG2_BASE
Definition: MIMXRT1062.h:46494
c4_WDOG_reg_t
Structure to overlay on the watchdog registers.
Definition: c4_watchdog_types.h:32
WDOG1_IRQn
Definition: MIMXRT1062.h:182
WDOG1_BASE
#define WDOG1_BASE
Definition: MIMXRT1062.h:46490
NVIC_EnableIRQ
#define NVIC_EnableIRQ
Definition: core_armv81mml.h:2119