cc26xx - added optional locking mode for WDT
Added a mode, configurable by the CONTIKI_WATCHDOG_CONF_LOCK_BETWEEN_USE macro, which locks the WDT register between uses so as to prevent any accidental modifications
This commit is contained in:
parent
22d8a8dd56
commit
fde3202a3f
|
@ -45,12 +45,58 @@
|
|||
#include "contiki.h"
|
||||
#include "dev/watchdog.h"
|
||||
#include "ti-lib.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifdef CONTIKI_WATCHDOG_CONF_TIMER_TOP
|
||||
#define CONTIKI_WATCHDOG_TIMER_TOP CONTIKI_WATCHDOG_CONF_TIMER_TOP
|
||||
#else
|
||||
#define CONTIKI_WATCHDOG_TIMER_TOP 0xFFFFF
|
||||
#endif
|
||||
|
||||
#ifdef CONTIKI_WATCHDOG_CONF_LOCK_CONFIG
|
||||
#define CONTIKI_WATCHDOG_LOCK_CONFIG CONTIKI_WATCHDOG_CONF_LOCK_CONFIG
|
||||
#else
|
||||
#define CONTIKI_WATCHDOG_LOCK_CONFIG 1
|
||||
#endif
|
||||
|
||||
#define LOCK_INTERRUPTS_DISABLED 0x01
|
||||
#define LOCK_REGISTERS_UNLOCKED 0x02
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static uint32_t
|
||||
unlock_config(void)
|
||||
{
|
||||
uint32_t ret = 0;
|
||||
bool int_status;
|
||||
|
||||
if(CONTIKI_WATCHDOG_LOCK_CONFIG) {
|
||||
int_status = ti_lib_int_master_disable();
|
||||
|
||||
if(ti_lib_watchdog_lock_state()) {
|
||||
ret |= LOCK_REGISTERS_UNLOCKED;
|
||||
ti_lib_watchdog_unlock();
|
||||
}
|
||||
|
||||
ret |= (int_status) ? (0) : (LOCK_INTERRUPTS_DISABLED);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
lock_config(uint32_t status)
|
||||
{
|
||||
if(CONTIKI_WATCHDOG_LOCK_CONFIG) {
|
||||
|
||||
if(status & LOCK_REGISTERS_UNLOCKED) {
|
||||
ti_lib_watchdog_lock();
|
||||
}
|
||||
if(status & LOCK_INTERRUPTS_DISABLED) {
|
||||
ti_lib_int_master_enable();
|
||||
}
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Initialises the CC26xx WDT
|
||||
|
@ -62,6 +108,7 @@ void
|
|||
watchdog_init(void)
|
||||
{
|
||||
ti_lib_watchdog_reload_set(CONTIKI_WATCHDOG_TIMER_TOP);
|
||||
lock_config(LOCK_REGISTERS_UNLOCKED);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
@ -70,8 +117,12 @@ watchdog_init(void)
|
|||
void
|
||||
watchdog_start(void)
|
||||
{
|
||||
uint32_t lock_status = unlock_config();
|
||||
|
||||
watchdog_periodic();
|
||||
ti_lib_watchdog_reset_enable();
|
||||
|
||||
lock_config(lock_status);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
@ -90,7 +141,11 @@ watchdog_periodic(void)
|
|||
void
|
||||
watchdog_stop(void)
|
||||
{
|
||||
uint32_t lock_status = unlock_config();
|
||||
|
||||
ti_lib_watchdog_reset_disable();
|
||||
|
||||
lock_config(lock_status);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue