From 8b301eb075a3c374d83efed66debec859e2139b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gero=20M=C3=BCller?= Date: Sat, 23 Mar 2019 10:40:52 +0100 Subject: [PATCH] add api --- sys/checkpoint/Makefile | 1 + sys/checkpoint/sytare.c | 71 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 sys/checkpoint/Makefile create mode 100644 sys/checkpoint/sytare.c diff --git a/sys/checkpoint/Makefile b/sys/checkpoint/Makefile new file mode 100644 index 000000000000..48422e909a47 --- /dev/null +++ b/sys/checkpoint/Makefile @@ -0,0 +1 @@ +include $(RIOTBASE)/Makefile.base diff --git a/sys/checkpoint/sytare.c b/sys/checkpoint/sytare.c new file mode 100644 index 000000000000..ca13c7738d8f --- /dev/null +++ b/sys/checkpoint/sytare.c @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2018 INRIA + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup sys + * @ingroup sys_sytare + * @{ + * + * @file + * @brief Sytare implementation + * + * @author Gero Müller + * @} + */ + +#include "irq.h" +#include + +/** + * @brief Save all active periphs state + * + * @param[out] state buffer to save the state + */ +extern void _sytare_save_periphs_state(uint8_t checkpoint); + +/** + * @brief Restore all active periphs state + * + * @param[in] state buffer storing the state + */ +extern void _sytare_restore_periphs_state(uint8_t checkpoint); + +extern void _sytare_save_ram(uint8_t checkpoint); +extern void _sytare_restore_ram(uint8_t checkpoint); + +// returns the next checkpoint index +extern uint8_t _sytare_next_checkpoint(void); +extern uint8_t _sytare_current_checkpoint(void); + +// returns the next checkpoint index + +void sytare_save(void) +{ + unsigned irq_status = irq_disable(); + + const uint8_t checkpoint = _sytare_next_checkpoint(); + + _sytare_save_periphs_state(checkpoint); + + _sytare_save_ram(checkpoint); + + irq_restore(irq_status); +} + +void sytare_restore(void) +{ + unsigned irq_status = irq_disable(); + + const uint8_t checkpoint = _sytare_current_checkpoint(); + + _sytare_restore_periphs_state(checkpoint); + + _sytare_restore_ram(checkpoint); + + irq_restore(irq_status); +}