Removed the experimental checkpointing code
This commit is contained in:
parent
189b1535e9
commit
0fd503af42
@ -64,7 +64,7 @@ SYSTEM = process.c procinit.c autostart.c elfloader.c \
|
||||
compower.c serial-line.c
|
||||
THREADS = mt.c
|
||||
LIBS = memb.c mmem.c timer.c list.c etimer.c ctimer.c energest.c rtimer.c stimer.c trickle-timer.c \
|
||||
print-stats.c ifft.c crc16.c random.c checkpoint.c ringbuf.c settings.c
|
||||
print-stats.c ifft.c crc16.c random.c ringbuf.c settings.c
|
||||
DEV = nullradio.c
|
||||
|
||||
include $(CONTIKI)/core/net/Makefile.uip
|
||||
|
@ -5,7 +5,7 @@ shell_src = shell.c shell-reboot.c \
|
||||
shell-rime-ping.c shell-rime-sniff.c shell-rime-netcmd.c \
|
||||
shell-rime-debug.c shell-rime-debug-runicast.c shell-coffee.c \
|
||||
shell-wget.c shell-httpd.c shell-irc.c \
|
||||
shell-checkpoint.c shell-power.c \
|
||||
shell-power.c \
|
||||
shell-tcpsend.c shell-udpsend.c shell-ping.c shell-netstat.c \
|
||||
shell-rime-sendcmd.c shell-download.c shell-rime-neighbors.c \
|
||||
shell-rime-unicast.c \
|
||||
|
@ -1,107 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2009, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "shell.h"
|
||||
|
||||
#include "cfs/cfs.h"
|
||||
#include "cfs/cfs-coffee.h"
|
||||
#include "lib/checkpoint.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(shell_checkpoint_process, "checkpoint");
|
||||
SHELL_COMMAND(checkpoint_command,
|
||||
"checkpoint",
|
||||
"checkpoint <filename>: checkpoint local state to file",
|
||||
&shell_checkpoint_process);
|
||||
PROCESS(shell_rollback_process, "rollback");
|
||||
SHELL_COMMAND(rollback_command,
|
||||
"rollback",
|
||||
"rollback <filename>: rollback local state from file",
|
||||
&shell_rollback_process);
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(shell_checkpoint_process, ev, data)
|
||||
{
|
||||
int fd = 0;
|
||||
|
||||
PROCESS_BEGIN();
|
||||
|
||||
/* Make sure file does not already exist */
|
||||
cfs_remove(data);
|
||||
|
||||
cfs_coffee_reserve(data, checkpoint_arch_size());
|
||||
fd = cfs_open(data, CFS_WRITE);
|
||||
|
||||
if(fd < 0) {
|
||||
shell_output_str(&checkpoint_command,
|
||||
"checkpoint: could not open file for writing: ", data);
|
||||
} else {
|
||||
shell_output_str(&checkpoint_command, "checkpoint to: ", data);
|
||||
checkpoint_checkpoint(fd);
|
||||
cfs_close(fd);
|
||||
shell_output_str(&checkpoint_command, "checkpointing done", "");
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(shell_rollback_process, ev, data)
|
||||
{
|
||||
int fd = 0;
|
||||
|
||||
PROCESS_BEGIN();
|
||||
|
||||
fd = cfs_open(data, CFS_READ);
|
||||
|
||||
if(fd < 0) {
|
||||
shell_output_str(&rollback_command,
|
||||
"rollback: could not open file for reading: ", data);
|
||||
} else {
|
||||
shell_output_str(&rollback_command, "rollback from: ", data);
|
||||
checkpoint_rollback(fd);
|
||||
cfs_close(fd);
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
shell_checkpoint_init(void)
|
||||
{
|
||||
checkpoint_init();
|
||||
shell_register_command(&checkpoint_command);
|
||||
shell_register_command(&rollback_command);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2009, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SHELL_CHECKPOINT_H_
|
||||
#define SHELL_CHECKPOINT_H_
|
||||
|
||||
#include "shell.h"
|
||||
|
||||
void shell_checkpoint_init(void);
|
||||
|
||||
#endif /* SHELL_CHECKPOINT_H_ */
|
@ -374,7 +374,6 @@ struct shell_input {
|
||||
|
||||
#include "shell-base64.h"
|
||||
#include "shell-blink.h"
|
||||
#include "shell-checkpoint.h"
|
||||
#include "shell-collect-view.h"
|
||||
#include "shell-coffee.h"
|
||||
#include "shell-download.h"
|
||||
|
@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2009, Swedish Institute of Computer Science
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Checkpoint library.
|
||||
* \author
|
||||
* Fredrik Osterlind <fros@sics.se>
|
||||
*/
|
||||
|
||||
#include "lib/checkpoint.h"
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
checkpoint_init(void)
|
||||
{
|
||||
checkpoint_arch_init();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
checkpoint_checkpoint(int fd)
|
||||
{
|
||||
checkpoint_arch_checkpoint(fd);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
checkpoint_rollback(int fd)
|
||||
{
|
||||
checkpoint_arch_rollback(fd);
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2009, Swedish Institute of Computer Science
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Checkpoint library header.
|
||||
* \author
|
||||
* Fredrik Osterlind <fros@sics.se>
|
||||
*/
|
||||
|
||||
#ifndef CHECKPOINT_H
|
||||
#define CHECKPOINT_H
|
||||
|
||||
#include "contiki.h"
|
||||
|
||||
void checkpoint_init(void);
|
||||
|
||||
void checkpoint_checkpoint(int fd);
|
||||
|
||||
void checkpoint_rollback(int fd);
|
||||
|
||||
void checkpoint_arch_init(void);
|
||||
|
||||
void checkpoint_arch_checkpoint(int fd);
|
||||
|
||||
void checkpoint_arch_rollback(int fd);
|
||||
|
||||
int checkpoint_arch_size();
|
||||
|
||||
#endif /* CHECKPOINT_H */
|
@ -73,7 +73,6 @@ PROCESS_THREAD(collect_view_shell_process, ev, data)
|
||||
/* shell_base64_init(); */
|
||||
shell_text_init();
|
||||
shell_time_init();
|
||||
/* shell_checkpoint_init(); */
|
||||
/* shell_sendtest_init(); */
|
||||
|
||||
#if CONTIKI_TARGET_SKY
|
||||
|
@ -60,7 +60,6 @@ PROCESS_THREAD(example_shell_process, ev, data)
|
||||
|
||||
shell_base64_init();
|
||||
shell_blink_init();
|
||||
/*shell_checkpoint_init();*/
|
||||
/*shell_coffee_init();*/
|
||||
shell_download_init();
|
||||
/*shell_exec_init();*/
|
||||
|
@ -43,8 +43,6 @@
|
||||
#include "dev/sht11.h"
|
||||
#include "dev/battery-sensor.h"
|
||||
|
||||
#include "lib/checkpoint.h"
|
||||
|
||||
#include "net/rime/timesynch.h"
|
||||
|
||||
#include <stdio.h>
|
||||
@ -72,7 +70,6 @@ PROCESS_THREAD(sky_shell_process, ev, data)
|
||||
/*shell_sky_init();*/
|
||||
shell_text_init();
|
||||
/*shell_time_init();*/
|
||||
/* shell_checkpoint_init();*/
|
||||
shell_exec_init();
|
||||
shell_base64_init();
|
||||
|
||||
|
@ -1,89 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2008, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Tmote Sky-specific Contiki shell
|
||||
* \author
|
||||
* Adam Dunkels <adam@sics.se>
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "shell.h"
|
||||
#include "serial-shell.h"
|
||||
|
||||
#include "net/rime.h"
|
||||
#include "dev/leds.h"
|
||||
|
||||
#include "lib/checkpoint.h"
|
||||
|
||||
#include "net/rime/timesynch.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <io.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "cfs/cfs.h"
|
||||
#include "cfs/cfs-coffee.h"
|
||||
#include "lib/checkpoint.h"
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(sky_shell_process, "Sky Contiki shell");
|
||||
AUTOSTART_PROCESSES(&sky_shell_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(sky_shell_process, ev, data)
|
||||
{
|
||||
PROCESS_BEGIN();
|
||||
|
||||
serial_shell_init();
|
||||
/*shell_blink_init();*/
|
||||
shell_file_init();
|
||||
shell_coffee_init();
|
||||
/*shell_ps_init();*/
|
||||
/*shell_reboot_init();*/
|
||||
shell_rime_init();
|
||||
/*shell_rime_netcmd_init();*/
|
||||
/*shell_rime_ping_init();*/
|
||||
/*shell_rime_debug_init();*/
|
||||
/*shell_rime_sniff_init();*/
|
||||
shell_rime_sendcmd_init();
|
||||
shell_download_init();
|
||||
/*shell_sky_init();*/
|
||||
shell_text_init();
|
||||
shell_time_init();
|
||||
shell_checkpoint_init();
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
@ -87,7 +87,6 @@ PROCESS_THREAD(sky_shell_process, ev, data)
|
||||
/* shell_base64_init();*/
|
||||
shell_text_init();
|
||||
shell_time_init();
|
||||
/* shell_checkpoint_init();*/
|
||||
/* shell_sendtest_init();*/
|
||||
|
||||
shell_collect_view_init();
|
||||
|
@ -3,7 +3,7 @@
|
||||
ARCH=spi.c ds2411.c xmem.c i2c.c node-id.c sensors.c cfs-coffee.c \
|
||||
cc2420.c cc2420-aes.c cc2420-arch.c cc2420-arch-sfd.c \
|
||||
sky-sensors.c uip-ipchksum.c \
|
||||
checkpoint-arch.c uart1.c slip_uart1.c uart1-putchar.c
|
||||
uart1.c slip_uart1.c uart1-putchar.c
|
||||
|
||||
CONTIKI_TARGET_DIRS = . dev apps net
|
||||
ifndef CONTIKI_TARGET_MAIN
|
||||
|
@ -1,692 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2010, Swedish Institute of Computer Science
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Checkpoint library implementation for the Tmote Sky platform.
|
||||
*
|
||||
* \author
|
||||
* Fredrik Osterlind <fros@sics.se>
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
|
||||
#include "lib/crc16.h"
|
||||
#include "lib/checkpoint.h"
|
||||
|
||||
#include "sys/rtimer.h"
|
||||
#include "sys/mt.h"
|
||||
#include "sys/energest.h"
|
||||
#include "sys/compower.h"
|
||||
#include "dev/leds.h"
|
||||
#include "dev/watchdog.h"
|
||||
#include "dev/serial-line.h"
|
||||
#include "dev/uart1.h"
|
||||
#include "dev/cc2420.h"
|
||||
#include "dev/button-sensor.h"
|
||||
#include "cfs/cfs.h"
|
||||
#include "cfs/cfs-coffee.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#define DEBUG 0
|
||||
#if DEBUG
|
||||
#define PRINTF(...) printf(__VA_ARGS__)
|
||||
#else
|
||||
#define PRINTF(...)
|
||||
#endif
|
||||
|
||||
#ifndef CHECKPOINT_ROLLBACK_BUTTON
|
||||
#define CHECKPOINT_ROLLBACK_BUTTON 1 /* rollback "cp_wdt" on button click */
|
||||
#endif /* CHECKPOINT_ROLLBACK_BUTTON */
|
||||
|
||||
#if CHECKPOINT_ROLLBACK_BUTTON
|
||||
PROCESS(checkpoint_button_process, "Rollback on button");
|
||||
#endif /* CHECKPOINT_ROLLBACK_BUTTON */
|
||||
|
||||
#define WITH_SERIAL_COMMANDS 0 /* checkpoint via serial port */
|
||||
#if WITH_SERIAL_COMMANDS
|
||||
#if UART1_CONF_TX_WITH_INTERRUPT
|
||||
#error TX_WITH_INTERRUPTS must be 0
|
||||
#endif /* UART1_CONF_TX_WITH_INTERRUPT */
|
||||
#define PRINTF_COMMAND(...) printf(__VA_ARGS__)
|
||||
#else /* WITH_SERIAL_COMMANDS */
|
||||
#define PRINTF_COMMAND(...)
|
||||
#endif /* WITH_SERIAL_COMMANDS */
|
||||
|
||||
#define COMMAND_ROLLBACK 1
|
||||
#define COMMAND_CHECKPOINT 2
|
||||
#define COMMAND_METRICS 3
|
||||
|
||||
#define INCLUDE_RAM 1 /* Less then 10240 bytes */
|
||||
#define INCLUDE_TIMERS 1 /* 16 bytes */
|
||||
#define INCLUDE_LEDS 1 /* 1 bytes */
|
||||
/* ... */
|
||||
|
||||
/* 10kb memory */
|
||||
#define RAM_START 0x1100
|
||||
#define RAM_END 0x3900
|
||||
|
||||
#define PAUSE_TIME() \
|
||||
TACTL &= ~(MC1); \
|
||||
TBCTL &= ~(MC1); \
|
||||
watchdog_stop();
|
||||
#define RESUME_TIME() \
|
||||
TACTL |= MC1; \
|
||||
TBCTL |= MC1; \
|
||||
TACCR1 = clock_fine_max(); \
|
||||
watchdog_start();
|
||||
#define PAUSE_TIME_INT() \
|
||||
dint(); \
|
||||
PAUSE_TIME();
|
||||
#define RESUME_TIME_INT() \
|
||||
RESUME_TIME(); \
|
||||
eint();
|
||||
|
||||
static struct mt_thread checkpoint_thread;
|
||||
static uint8_t preset_cmd;
|
||||
static int preset_fd;
|
||||
|
||||
/* bookkeeping */
|
||||
#if WITH_SERIAL_COMMANDS
|
||||
static int nr_pongs=0;
|
||||
#endif /* WITH_SERIAL_COMMANDS */
|
||||
static int nr_checkpoints=0, nr_rollbacks=0, nr_metrics=0;
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
typedef union {
|
||||
unsigned char u8[2];
|
||||
unsigned short u16;
|
||||
} word_union_t;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
write_byte(int fd, uint8_t c)
|
||||
{
|
||||
return cfs_write(fd, &c, 1);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
write_word(int fd, uint16_t w)
|
||||
{
|
||||
word_union_t tmp;
|
||||
tmp.u16 = w;
|
||||
write_byte(fd, tmp.u8[0]);
|
||||
write_byte(fd, tmp.u8[1]);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static uint8_t
|
||||
read_byte(int fd)
|
||||
{
|
||||
uint8_t c;
|
||||
cfs_read(fd, &c, 1);
|
||||
return c;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static uint16_t
|
||||
read_word(int fd)
|
||||
{
|
||||
word_union_t tmp;
|
||||
tmp.u8[0] = read_byte(fd);
|
||||
tmp.u8[1] = read_byte(fd);
|
||||
return tmp.u16;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
thread_checkpoint(int fd)
|
||||
{
|
||||
#if INCLUDE_RAM
|
||||
unsigned char *addr;
|
||||
uint16_t size = 0;
|
||||
unsigned char *thread_mem_start = (unsigned char *)&checkpoint_thread.thread.stack;
|
||||
unsigned char *thread_mem_end = thread_mem_start + sizeof(checkpoint_thread.thread.stack) - 1;
|
||||
unsigned char *coffee_mem_start = cfs_coffee_get_protected_mem(&size);
|
||||
unsigned char *coffee_mem_end = coffee_mem_start + size - 1;
|
||||
#endif /* INCLUDE_RAM */
|
||||
|
||||
/*PRINTF("protected thread memory: %u, size=%u\n", (uint16_t) thread_mem_start, sizeof(checkpoint_thread.thread.stack));*/
|
||||
/*PRINTF("protected coffee memory: %u, size=%u\n", (uint16_t) coffee_mem_start, size);*/
|
||||
|
||||
/* RAM */
|
||||
#if INCLUDE_RAM
|
||||
for(addr = (unsigned char *)RAM_START;
|
||||
addr < (unsigned char *)RAM_END;
|
||||
addr++) {
|
||||
|
||||
if((addr >= thread_mem_start && addr <= thread_mem_end)) {
|
||||
/* Skip */
|
||||
continue;
|
||||
}
|
||||
|
||||
if((addr >= coffee_mem_start && addr <= coffee_mem_end)) {
|
||||
/* Skip */
|
||||
continue;
|
||||
}
|
||||
|
||||
/* TODO Use write_array() */
|
||||
write_byte(fd, *addr);
|
||||
|
||||
/*if(((int)addr % 512) == 0) {
|
||||
PRINTF(".");
|
||||
}*/
|
||||
}
|
||||
|
||||
#endif /* INCLUDE_RAM */
|
||||
|
||||
/* Timers */
|
||||
#if INCLUDE_TIMERS
|
||||
write_word(fd, TACTL);
|
||||
write_word(fd, TACCTL1);
|
||||
write_word(fd, TACCR1);
|
||||
write_word(fd, TAR);
|
||||
|
||||
write_word(fd, TBCTL);
|
||||
write_word(fd, TBCCTL1);
|
||||
write_word(fd, TBCCR1);
|
||||
write_word(fd, TBR);
|
||||
#endif /* INCLUDE_TIMERS */
|
||||
|
||||
/* LEDs */
|
||||
#if INCLUDE_LEDS
|
||||
write_byte(fd, leds_arch_get());
|
||||
#endif /* INCLUDE_LEDS */
|
||||
|
||||
/* Radio */
|
||||
/* ADC */
|
||||
/* ... */
|
||||
|
||||
write_byte(fd, -1); /* Coffee padding byte */
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
thread_rollback(int fd)
|
||||
{
|
||||
#if INCLUDE_RAM
|
||||
unsigned char *addr;
|
||||
uint16_t size = 0;
|
||||
unsigned char *thread_mem_start = (unsigned char *)&checkpoint_thread.thread.stack;
|
||||
unsigned char *thread_mem_end = thread_mem_start + sizeof(checkpoint_thread.thread.stack) - 1;
|
||||
unsigned char *coffee_mem_start = cfs_coffee_get_protected_mem(&size);
|
||||
unsigned char *coffee_mem_end = coffee_mem_start + size - 1;
|
||||
#endif /* INCLUDE_RAM */
|
||||
|
||||
/*PRINTF("protected thread memory: %u, size=%u\n", (uint16_t) thread_mem_start, sizeof(checkpoint_thread.thread.stack));*/
|
||||
/*PRINTF("protected coffee memory: %u, size=%u\n", (uint16_t) coffee_mem_start, size);*/
|
||||
|
||||
/* RAM */
|
||||
#if INCLUDE_RAM
|
||||
for(addr = (unsigned char *)RAM_START;
|
||||
addr < (unsigned char *)RAM_END;
|
||||
addr++) {
|
||||
if((addr >= thread_mem_start && addr <= thread_mem_end)) {
|
||||
/* Skip */
|
||||
continue;
|
||||
}
|
||||
|
||||
if((addr >= coffee_mem_start && addr <= coffee_mem_end)) {
|
||||
/* Skip */
|
||||
continue;
|
||||
}
|
||||
|
||||
*addr = read_byte(fd);
|
||||
}
|
||||
#endif /* INCLUDE_RAM */
|
||||
|
||||
/* Timers */
|
||||
#if INCLUDE_TIMERS
|
||||
TACTL = read_word(fd);
|
||||
TACCTL1 = read_word(fd);
|
||||
TACCR1 = read_word(fd);
|
||||
TAR = read_word(fd);
|
||||
|
||||
TBCTL = read_word(fd);
|
||||
TBCCTL1 = read_word(fd);
|
||||
TBCCR1 = read_word(fd);
|
||||
TBR = read_word(fd);
|
||||
#endif /* INCLUDE_TIMERS */
|
||||
|
||||
/* LEDs */
|
||||
#if INCLUDE_LEDS
|
||||
leds_arch_set(read_byte(fd));
|
||||
#endif /* INCLUDE_LEDS */
|
||||
|
||||
/* Radio */
|
||||
/* ADC */
|
||||
/* ... */
|
||||
|
||||
read_byte(fd); /* Coffee padding byte */
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#if WITH_SERIAL_COMMANDS
|
||||
static uint32_t
|
||||
thread_metric_tx(void)
|
||||
{
|
||||
energest_flush();
|
||||
return energest_type_time(ENERGEST_TYPE_TRANSMIT);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static uint32_t
|
||||
thread_metric_rx(void)
|
||||
{
|
||||
energest_flush();
|
||||
return energest_type_time(ENERGEST_TYPE_LISTEN);
|
||||
}
|
||||
#endif /* WITH_SERIAL_COMMANDS */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
thread_metrics(void)
|
||||
{
|
||||
PRINTF_COMMAND("METRICS:START\n");
|
||||
PRINTF_COMMAND("M:RTIMER_NOW:%u\n", RTIMER_NOW()); /* TODO extract */
|
||||
PRINTF_COMMAND("M:ENERGY_TX:%lu\n", thread_metric_tx());
|
||||
PRINTF_COMMAND("M:ENERGY_RX:%lu\n", thread_metric_rx());
|
||||
PRINTF_COMMAND("M:RTIMER_NOW2:%u\n", RTIMER_NOW());
|
||||
nr_metrics++;
|
||||
PRINTF_COMMAND("METRICS:DONE %u\n", nr_metrics);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
checkpoint_thread_loop(void *data)
|
||||
{
|
||||
uint8_t cmd;
|
||||
int fd;
|
||||
|
||||
while(1) {
|
||||
/* Store command and file descriptor on stack */
|
||||
cmd = preset_cmd;
|
||||
fd = preset_fd;
|
||||
|
||||
/* Handle command */
|
||||
if(cmd == COMMAND_ROLLBACK) {
|
||||
PRINTF_COMMAND("RB:START\n");
|
||||
thread_rollback(fd);
|
||||
nr_rollbacks++;
|
||||
PRINTF_COMMAND("RB:DONE %u\n", nr_rollbacks);
|
||||
/* TODO Synch before leaving this thread. */
|
||||
} else if(cmd == COMMAND_CHECKPOINT) {
|
||||
PRINTF_COMMAND("CP:START\n");
|
||||
thread_checkpoint(fd);
|
||||
thread_metrics();
|
||||
nr_checkpoints++;
|
||||
PRINTF_COMMAND("CP:DONE %u\n", nr_checkpoints);
|
||||
} else if(cmd == COMMAND_METRICS) {
|
||||
thread_metrics();
|
||||
} else {
|
||||
printf("ERROR: Unknown thread command: %u\n", cmd);
|
||||
}
|
||||
|
||||
/* Return to Contiki */
|
||||
mt_yield();
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
checkpoint_arch_size()
|
||||
{
|
||||
return 10258;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
checkpoint_arch_checkpoint(int fd)
|
||||
{
|
||||
PAUSE_TIME_INT();
|
||||
|
||||
preset_cmd = COMMAND_CHECKPOINT;
|
||||
preset_fd = fd;
|
||||
mt_exec(&checkpoint_thread);
|
||||
|
||||
RESUME_TIME_INT();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
checkpoint_arch_rollback(int fd)
|
||||
{
|
||||
PAUSE_TIME_INT();
|
||||
|
||||
preset_cmd = COMMAND_ROLLBACK;
|
||||
preset_fd = fd;
|
||||
mt_exec(&checkpoint_thread);
|
||||
|
||||
RESUME_TIME_INT();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static uint8_t inited = 0;
|
||||
void
|
||||
checkpoint_arch_init(void)
|
||||
{
|
||||
if(inited) {
|
||||
return;
|
||||
}
|
||||
|
||||
mt_init();
|
||||
mt_start(&checkpoint_thread, checkpoint_thread_loop, NULL);
|
||||
inited = 1;
|
||||
|
||||
#if CHECKPOINT_ROLLBACK_BUTTON
|
||||
process_start(&checkpoint_button_process, NULL);
|
||||
#endif /* CHECKPOINT_ROLLBACK_BUTTON */
|
||||
|
||||
/*mt_stop(&checkpoint_thread);*/
|
||||
/*mt_remove();*/
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
struct power_log {
|
||||
uint32_t transmit;
|
||||
uint32_t listen;
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#if WITH_SERIAL_COMMANDS
|
||||
static void
|
||||
serial_interrupt_checkpoint()
|
||||
{
|
||||
int fd = 0;
|
||||
PAUSE_TIME();
|
||||
|
||||
if(SPI_IS_ENABLED()) {
|
||||
/* SPI is busy, abort */
|
||||
PRINTF_COMMAND("CP:SPIBUSY\n");
|
||||
RESUME_TIME();
|
||||
return;
|
||||
}
|
||||
|
||||
/* Open file */
|
||||
cfs_remove("cp");
|
||||
cfs_coffee_reserve("cp", checkpoint_arch_size());
|
||||
fd = cfs_open("cp", CFS_WRITE);
|
||||
|
||||
if(fd < 0) {
|
||||
printf("ERROR: No file access (cp)\n");
|
||||
RESUME_TIME();
|
||||
return;
|
||||
}
|
||||
|
||||
/* Checkpoint */
|
||||
preset_cmd = COMMAND_CHECKPOINT;
|
||||
preset_fd = fd;
|
||||
mt_exec(&checkpoint_thread);
|
||||
|
||||
/* Close file */
|
||||
cfs_close(fd);
|
||||
|
||||
RESUME_TIME();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
serial_interrupt_rollback()
|
||||
{
|
||||
int fd = 0;
|
||||
PAUSE_TIME();
|
||||
|
||||
if(SPI_IS_ENABLED()) {
|
||||
/* SPI is busy, abort */
|
||||
PRINTF_COMMAND("RB:SPIBUSY\n");
|
||||
RESUME_TIME();
|
||||
return;
|
||||
}
|
||||
|
||||
/* Open file */
|
||||
fd = cfs_open("cp", CFS_READ);
|
||||
|
||||
if(fd < 0) {
|
||||
printf("ERROR: No file access (rb)\n");
|
||||
RESUME_TIME();
|
||||
return;
|
||||
}
|
||||
|
||||
/* Rollback */
|
||||
preset_cmd = COMMAND_ROLLBACK;
|
||||
preset_fd = fd;
|
||||
mt_exec(&checkpoint_thread);
|
||||
|
||||
/* Close file */
|
||||
cfs_close(fd);
|
||||
|
||||
RESUME_TIME();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
serial_interrupt_metrics()
|
||||
{
|
||||
PAUSE_TIME();
|
||||
|
||||
preset_cmd = COMMAND_METRICS;
|
||||
preset_fd = -1;
|
||||
mt_exec(&checkpoint_thread);
|
||||
|
||||
RESUME_TIME();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static const unsigned char command_checkpoint[] = { 'c', 'p', '\n' };
|
||||
static const unsigned char command_rollback[] = { 'r', 'b', '\n' };
|
||||
static const unsigned char command_metrics[] = { 'm', 't', '\n' };
|
||||
static volatile int command_checkpoint_state = 0;
|
||||
static volatile int command_rollback_state = 0;
|
||||
static volatile int command_metrics_state = 0;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
serial_input_byte_intercept(unsigned char c)
|
||||
{
|
||||
/* Detect checkpoint request */
|
||||
if(command_checkpoint[command_checkpoint_state] == c) {
|
||||
command_checkpoint_state++;
|
||||
|
||||
if(command_checkpoint_state == sizeof(command_checkpoint)) {
|
||||
serial_interrupt_checkpoint();
|
||||
command_checkpoint_state = 0;
|
||||
}
|
||||
} else {
|
||||
command_checkpoint_state = 0;
|
||||
}
|
||||
|
||||
/* Detect rollback request */
|
||||
if(command_rollback[command_rollback_state] == c) {
|
||||
command_rollback_state++;
|
||||
|
||||
if(command_rollback_state == sizeof(command_rollback)) {
|
||||
serial_interrupt_rollback();
|
||||
command_rollback_state = 0;
|
||||
}
|
||||
} else {
|
||||
command_rollback_state = 0;
|
||||
}
|
||||
|
||||
/* Detect metrics request */
|
||||
if(command_metrics[command_metrics_state] == c) {
|
||||
command_metrics_state++;
|
||||
|
||||
if(command_metrics_state == sizeof(command_metrics)) {
|
||||
serial_interrupt_metrics();
|
||||
command_metrics_state = 0;
|
||||
}
|
||||
} else {
|
||||
command_metrics_state = 0;
|
||||
}
|
||||
|
||||
/* Forward to serial line input byte */
|
||||
return serial_line_input_byte(c);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
handle_get_command(void)
|
||||
{
|
||||
int fd = 0;
|
||||
fd = cfs_open("cp", CFS_READ);
|
||||
if(fd < 0) {
|
||||
printf("ERROR: No file access (get)\n");
|
||||
} else {
|
||||
PRINTF_COMMAND("GET:START\n");
|
||||
char data[8];
|
||||
int offset=0, size=0, read=8;
|
||||
unsigned short crc = 0;
|
||||
cfs_seek(fd, offset, CFS_SEEK_SET);
|
||||
|
||||
while (read == 8) {
|
||||
int i;
|
||||
|
||||
/*if(offset != cfs_seek(fd, offset, CFS_SEEK_SET)) {
|
||||
printf("bad seek, breaking\n");
|
||||
break;
|
||||
}*/
|
||||
read = cfs_read(fd, data, 8);
|
||||
size += read;
|
||||
|
||||
printf("%04i: ", offset); /*REMOVE*/
|
||||
for (i=0; i < read; i++) {
|
||||
crc = crc16_add((uint8_t) data[i], crc);
|
||||
printf("%02x", (uint8_t) (0xff&data[i]));
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
offset += 8;
|
||||
}
|
||||
|
||||
PRINTF_COMMAND("GET:DONE CRC=%u\n", crc);
|
||||
cfs_close(fd);
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
hex_decode_char(char c)
|
||||
{
|
||||
if(c >= 'A' && c <= 'F') {
|
||||
return c - 'A' + 10;
|
||||
} else if(c >= 'a' && c <= 'f') {
|
||||
return c - 'a' + 10;
|
||||
} else if(c >= '0' && c <= '9') {
|
||||
return c - '0';
|
||||
} else {
|
||||
printf("WARN: bad hex: %c\n", c);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(checkpoint_serial_process, "Checkpoint via serial commands");
|
||||
PROCESS_THREAD(checkpoint_serial_process, ev, data)
|
||||
{
|
||||
static int set_fd = -1;
|
||||
static int set_count = -1;
|
||||
|
||||
PROCESS_BEGIN();
|
||||
|
||||
/* Note: 'cp', 'rb', and 'mt' commands are intercepted */
|
||||
PROCESS_PAUSE();
|
||||
uart1_set_input(serial_input_byte_intercept);
|
||||
|
||||
/* Format Coffee? */
|
||||
PRINTF("Formatting Coffee\n");
|
||||
cfs_coffee_format();
|
||||
PRINTF("Formatting Coffee... done!\n");
|
||||
|
||||
while(1) {
|
||||
PROCESS_WAIT_EVENT_UNTIL(ev == serial_line_event_message && data != NULL);
|
||||
|
||||
if(strcmp("set", data) == 0) {
|
||||
/* TODO Handle set command */
|
||||
/* Open file */
|
||||
cfs_remove("cp");
|
||||
cfs_coffee_reserve("cp", checkpoint_arch_size());
|
||||
set_fd = cfs_open("cp", CFS_WRITE);
|
||||
set_count = 0;
|
||||
if(set_fd < 0) {
|
||||
printf("SET:FSBUSY\n");
|
||||
} else {
|
||||
printf("SET:LINE\n");
|
||||
}
|
||||
} else if(set_fd >= 0 && strcmp("set:done", data) == 0) {
|
||||
cfs_close(set_fd);
|
||||
set_fd = -1;
|
||||
if(set_count == 9862) {
|
||||
printf("SET:DONE\n");
|
||||
} else {
|
||||
printf("SET:WRONGSIZE\n");
|
||||
}
|
||||
} else if(set_fd >= 0) {
|
||||
/* We are ready for another line */
|
||||
printf("SET:LINE\n");
|
||||
/* Set command: parse hex data */
|
||||
int len = strlen((char*)data);
|
||||
if(len > 16 || (len%2)!=0) {
|
||||
printf("WARN: bad set data: %s\n", (char*)data);
|
||||
} else {
|
||||
int i;
|
||||
for (i=0; i < len; i+=2) {
|
||||
uint8_t b =
|
||||
(hex_decode_char(((char*)data)[i]) << 4) +
|
||||
(hex_decode_char(((char*)data)[i+1]));
|
||||
|
||||
PRINTF("Parsing set command: writing to CFS: %02x\n", b);
|
||||
write_byte(set_fd, b); /* TODO Check return value */
|
||||
set_count++;
|
||||
}
|
||||
}
|
||||
} else if(strcmp("", data) == 0 ||
|
||||
strcmp("cp", data) == 0 ||
|
||||
strcmp("rb", data) == 0 ||
|
||||
strcmp("mt", data) == 0) {
|
||||
/* ignore commands: handled by interrupt */
|
||||
} else if(strcmp("ping", data) == 0) {
|
||||
nr_pongs++;
|
||||
printf("pong %u\n", nr_pongs);
|
||||
} else if(strcmp("get", data) == 0) {
|
||||
handle_get_command();
|
||||
} else {
|
||||
printf("WARN: Unknown command: '%s'\n", (char*)data);
|
||||
}
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
#endif /* WITH_SERIAL_COMMANDS */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#if CHECKPOINT_ROLLBACK_BUTTON
|
||||
PROCESS_THREAD(checkpoint_button_process, ev, data)
|
||||
{
|
||||
PROCESS_BEGIN();
|
||||
|
||||
button_sensor.configure(SENSORS_ACTIVE, 1);
|
||||
|
||||
while(1) {
|
||||
PROCESS_WAIT_EVENT();
|
||||
|
||||
if(ev == sensors_event && data == &button_sensor) {
|
||||
int fd = 0;
|
||||
|
||||
/* Rollback from Coffee file "cp_wdt" */
|
||||
fd = cfs_open("cp_wdt", CFS_READ);
|
||||
if(fd >= 0) {
|
||||
checkpoint_rollback(fd);
|
||||
cfs_close(fd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
#endif /* CHECKPOINT_ROLLBACK_BUTTON */
|
@ -5,12 +5,12 @@ CONTIKI_TARGET_SOURCEFILES += contiki-wismote-platform.c \
|
||||
#ARCH=spi.c ds2411.c xmem.c i2c.c node-id.c sensors.c cfs-coffee.c \
|
||||
cc2520.c cc2520-arch.c cc2520-arch-sfd.c \
|
||||
sky-sensors.c uip-ipchksum.c \
|
||||
checkpoint-arch.c uart1.c slip_uart1.c uart1-putchar.c
|
||||
uart1.c slip_uart1.c uart1-putchar.c
|
||||
|
||||
ARCH=spi.c i2c.c node-id.c sensors.c cfs-coffee.c sht15.c \
|
||||
cc2520.c cc2520-arch.c cc2520-arch-sfd.c \
|
||||
sky-sensors.c uip-ipchksum.c \
|
||||
checkpoint-arch.c uart1.c slip_uart1.c uart1-putchar.c
|
||||
uart1.c slip_uart1.c uart1-putchar.c
|
||||
|
||||
|
||||
CONTIKI_TARGET_DIRS = . dev apps net
|
||||
|
@ -1,370 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2009, Swedish Institute of Computer Science
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Checkpoint library implementation for the Tmote Sky platform.
|
||||
* \author
|
||||
* Fredrik Osterlind <fros@sics.se>
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "lib/checkpoint.h"
|
||||
|
||||
#include "sys/rtimer.h"
|
||||
#include "sys/mt.h"
|
||||
#include "cfs/cfs.h"
|
||||
#include "cfs/cfs-coffee.h"
|
||||
#include "dev/leds.h"
|
||||
#include "dev/watchdog.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define DEBUG 0
|
||||
#if DEBUG
|
||||
#define PRINTF(...) printf(__VA_ARGS__)
|
||||
#else
|
||||
#define PRINTF(...)
|
||||
#endif
|
||||
|
||||
#define COMMAND_ROLLBACK 1
|
||||
#define COMMAND_CHECKPOINT 2
|
||||
#define COMMAND_TBR 3
|
||||
|
||||
#define DATA_AS_HEX 0 /* If false, store binary data */
|
||||
|
||||
#define INCLUDE_RAM 1 /* Less then 10240 bytes */
|
||||
#define INCLUDE_TIMERS 1 /* 16 bytes */
|
||||
#define INCLUDE_LEDS 1 /* 1 bytes */
|
||||
|
||||
/* 10kb memory */
|
||||
#define RAM_START 0x1100
|
||||
#define RAM_END 0x3900
|
||||
|
||||
#define STOP_TIMERS() TACTL &= ~(MC1); TBCTL &= ~(MC1); watchdog_stop();
|
||||
#define START_TIMERS() watchdog_start(); TACTL |= MC1; TBCTL |= MC1;
|
||||
|
||||
static struct mt_thread checkpoint_thread;
|
||||
static uint8_t preset_cmd;
|
||||
static int preset_fd;
|
||||
|
||||
typedef union {
|
||||
unsigned char u8[2];
|
||||
unsigned short u16;
|
||||
} word_union_t;
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
write_byte(int fd, uint8_t c)
|
||||
{
|
||||
#if DATA_AS_HEX
|
||||
uint8_t hex[2];
|
||||
sprintf(hex, "%02x", c);
|
||||
if(cfs_write(fd, hex, 2) != 2) {
|
||||
printf("err #1\n");
|
||||
}
|
||||
#else /* DATA_AS_HEX */
|
||||
if(cfs_write(fd, &c, 1) != 1) {
|
||||
printf("err #2\n");
|
||||
}
|
||||
#endif /* DATA_AS_HEX */
|
||||
}/*---------------------------------------------------------------------------*/
|
||||
#if 0
|
||||
static void
|
||||
write_array(int fd, unsigned char *mem, uint16_t len)
|
||||
{
|
||||
#if DATA_AS_HEX
|
||||
int i;
|
||||
for(i = 0; i < len; i++) {
|
||||
write_byte(fd, mem[i]);
|
||||
}
|
||||
#else /* DATA_AS_HEX */
|
||||
cfs_write(fd, mem, len);
|
||||
#endif /* DATA_AS_HEX */
|
||||
}
|
||||
#endif /* 0 */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
write_word(int fd, uint16_t w)
|
||||
{
|
||||
word_union_t tmp;
|
||||
tmp.u16 = w;
|
||||
write_byte(fd, tmp.u8[0]);
|
||||
write_byte(fd, tmp.u8[1]);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static uint8_t
|
||||
read_byte(int fd)
|
||||
{
|
||||
#if DATA_AS_HEX
|
||||
uint8_t hex[2];
|
||||
|
||||
cfs_read(fd, hex, 2);
|
||||
|
||||
if(hex[0] >= 'A' && hex[0] <= 'F') {
|
||||
hex[0] = (hex[0] - 'A' + 0xa);
|
||||
} else if(hex[0] >= 'a' && hex[0] <= 'f') {
|
||||
hex[0] = (hex[0] - 'a' + 0xa);
|
||||
} else {
|
||||
hex[0] = (hex[0] - '0');
|
||||
}
|
||||
if(hex[1] >= 'A' && hex[1] <= 'F') {
|
||||
hex[1] = (hex[1] - 'A' + 0xa);
|
||||
} else if(hex[1] >= 'a' && hex[1] <= 'f') {
|
||||
hex[1] = (hex[1] - 'a' + 0xa);
|
||||
} else {
|
||||
hex[1] = (hex[1] - '0');
|
||||
}
|
||||
return (uint8_t)((hex[0]<<4)&0xf0) | (hex[1]&0x0f);
|
||||
#else /* DATA_AS_HEX */
|
||||
uint8_t c;
|
||||
cfs_read(fd, &c, 1);
|
||||
return c;
|
||||
#endif /* DATA_AS_HEX */
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static uint16_t
|
||||
read_word(int fd)
|
||||
{
|
||||
word_union_t tmp;
|
||||
tmp.u8[0] = read_byte(fd);
|
||||
tmp.u8[1] = read_byte(fd);
|
||||
return tmp.u16;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
thread_checkpoint(int fd)
|
||||
{
|
||||
#if INCLUDE_RAM
|
||||
unsigned char *addr;
|
||||
uint16_t size = 0;
|
||||
unsigned char *thread_mem_start = (unsigned char *)&checkpoint_thread.thread.stack;
|
||||
unsigned char *thread_mem_end = thread_mem_start + sizeof(checkpoint_thread.thread.stack) - 1;
|
||||
unsigned char *coffee_mem_start = cfs_coffee_get_protected_mem(&size);
|
||||
unsigned char *coffee_mem_end = coffee_mem_start + size - 1;
|
||||
#endif /* INCLUDE_RAM */
|
||||
|
||||
/*printf("protected thread memory: %u, size=%u\n", (uint16_t) thread_mem_start, sizeof(checkpoint_thread.thread.stack));*/
|
||||
/*printf("protected coffee memory: %u, size=%u\n", (uint16_t) coffee_mem_start, size);*/
|
||||
|
||||
/* RAM */
|
||||
#if INCLUDE_RAM
|
||||
for(addr = (unsigned char *)RAM_START;
|
||||
addr < (unsigned char *)RAM_END;
|
||||
addr++) {
|
||||
|
||||
if((addr >= thread_mem_start && addr <= thread_mem_end)) {
|
||||
/* Writing dummy memory */
|
||||
/*write_byte(fd, 1);*/
|
||||
continue;
|
||||
}
|
||||
|
||||
if((addr >= coffee_mem_start && addr <= coffee_mem_end)) {
|
||||
/* Writing dummy memory */
|
||||
/*write_byte(fd, 2);*/
|
||||
continue;
|
||||
}
|
||||
|
||||
/* TODO Use write_array() */
|
||||
write_byte(fd, *addr);
|
||||
|
||||
if(((int)addr % 512) == 0) {
|
||||
PRINTF(".");
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* INCLUDE_RAM */
|
||||
|
||||
/* Timers */
|
||||
#if INCLUDE_TIMERS
|
||||
/* write_word(fd, TACTL);
|
||||
write_word(fd, TACCTL1);
|
||||
write_word(fd, TACCR1);
|
||||
write_word(fd, TAR);
|
||||
|
||||
write_word(fd, TBCTL);
|
||||
write_word(fd, TBCCTL1);
|
||||
write_word(fd, TBCCR1);
|
||||
write_word(fd, TBR);*/
|
||||
#endif /* INCLUDE_TIMERS */
|
||||
|
||||
/* LEDs */
|
||||
#if INCLUDE_LEDS
|
||||
write_byte(fd, leds_arch_get());
|
||||
#endif /* INCLUDE_LEDS */
|
||||
|
||||
/* Radio */
|
||||
/* ADC */
|
||||
/* ... */
|
||||
|
||||
write_byte(fd, -1); /* Coffee padding byte */
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
thread_rollback(int fd)
|
||||
{
|
||||
#if INCLUDE_RAM
|
||||
unsigned char *addr;
|
||||
uint16_t size = 0;
|
||||
unsigned char *thread_mem_start = (unsigned char *)&checkpoint_thread.thread.stack;
|
||||
unsigned char *thread_mem_end = thread_mem_start + sizeof(checkpoint_thread.thread.stack) - 1;
|
||||
unsigned char *coffee_mem_start = cfs_coffee_get_protected_mem(&size);
|
||||
unsigned char *coffee_mem_end = coffee_mem_start + size - 1;
|
||||
#endif /* INCLUDE_RAM */
|
||||
|
||||
/*printf("protected thread memory: %u, size=%u\n", (uint16_t) thread_mem_start, sizeof(checkpoint_thread.thread.stack));*/
|
||||
/*printf("protected coffee memory: %u, size=%u\n", (uint16_t) coffee_mem_start, size);*/
|
||||
|
||||
/* RAM */
|
||||
#if INCLUDE_RAM
|
||||
for(addr = (unsigned char *)RAM_START;
|
||||
addr < (unsigned char *)RAM_END;
|
||||
addr++) {
|
||||
if((addr >= thread_mem_start && addr <= thread_mem_end)) {
|
||||
/* Ignoring incoming memory */
|
||||
/*read_byte(fd);*/
|
||||
continue;
|
||||
}
|
||||
|
||||
if((addr >= coffee_mem_start && addr <= coffee_mem_end)) {
|
||||
/* Ignoring incoming memory */
|
||||
/*read_byte(fd);*/
|
||||
continue;
|
||||
}
|
||||
|
||||
*addr = read_byte(fd);
|
||||
|
||||
if(((int)addr % 512) == 0) {
|
||||
PRINTF(".");
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* INCLUDE_RAM */
|
||||
|
||||
/* Timers */
|
||||
#if INCLUDE_TIMERS
|
||||
/* TACTL = read_word(fd);
|
||||
TACCTL1 = read_word(fd);
|
||||
TACCR1 = read_word(fd);
|
||||
TAR = read_word(fd);
|
||||
|
||||
TBCTL = read_word(fd);
|
||||
TBCCTL1 = read_word(fd);
|
||||
TBCCR1 = read_word(fd);
|
||||
TBR = read_word(fd);*/
|
||||
#endif /* INCLUDE_TIMERS */
|
||||
|
||||
/* LEDs */
|
||||
#if INCLUDE_LEDS
|
||||
leds_arch_set(read_byte(fd));
|
||||
#endif /* INCLUDE_LEDS */
|
||||
|
||||
/* Radio */
|
||||
/* ADC */
|
||||
/* ... */
|
||||
|
||||
read_byte(fd); /* Coffee padding byte */
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
thread_loop(void *data)
|
||||
{
|
||||
uint8_t cmd;
|
||||
int fd;
|
||||
|
||||
while(1) {
|
||||
/* Store command and file descriptor on stack */
|
||||
cmd = preset_cmd;
|
||||
fd = preset_fd;
|
||||
|
||||
/* Handle command */
|
||||
if(cmd == COMMAND_ROLLBACK) {
|
||||
PRINTF("Rolling back");
|
||||
thread_rollback(fd);
|
||||
PRINTF(" done!\n");
|
||||
} else if(cmd == COMMAND_CHECKPOINT) {
|
||||
PRINTF("Checkpointing");
|
||||
thread_checkpoint(fd);
|
||||
PRINTF(" done!\n");
|
||||
} else if(cmd == COMMAND_TBR) {
|
||||
PRINTF("Writing TBR");
|
||||
// write_word(fd, TBR);
|
||||
PRINTF(" done!\n");
|
||||
} else {
|
||||
printf("Error: unknown command: %u\n", cmd);
|
||||
}
|
||||
|
||||
/* Return to main Contiki thread */
|
||||
mt_yield();
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
checkpoint_arch_size()
|
||||
{
|
||||
return 10258;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
checkpoint_arch_checkpoint(int fd)
|
||||
{
|
||||
// STOP_TIMERS();
|
||||
|
||||
preset_cmd = COMMAND_CHECKPOINT;
|
||||
preset_fd = fd;
|
||||
mt_exec(&checkpoint_thread);
|
||||
|
||||
// START_TIMERS();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
checkpoint_arch_rollback(int fd)
|
||||
{
|
||||
//STOP_TIMERS();
|
||||
|
||||
preset_cmd = COMMAND_ROLLBACK;
|
||||
preset_fd = fd;
|
||||
mt_exec(&checkpoint_thread);
|
||||
|
||||
//START_TIMERS();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
checkpoint_arch_init(void)
|
||||
{
|
||||
mt_init();
|
||||
mt_start(&checkpoint_thread, thread_loop, NULL);
|
||||
|
||||
/*mt_stop(&checkpoint_thread);*/
|
||||
/*mt_remove();*/
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
@ -14,7 +14,7 @@ ARCH=msp430.c leds.c watchdog.c xmem.c \
|
||||
spi.c cc2420.c cc2420-aes.c cc2420-arch.c cc2420-arch-sfd.c\
|
||||
node-id.c sensors.c button-sensor.c cfs-coffee.c \
|
||||
radio-sensor.c uart0.c uart0-putchar.c uip-ipchksum.c \
|
||||
checkpoint-arch.c slip.c slip_uart0.c \
|
||||
slip.c slip_uart0.c \
|
||||
z1-phidgets.c sht11.c sht11-sensor.c light-sensor.c \
|
||||
battery-sensor.c sky-sensors.c tmp102.c temperature-sensor.c light-ziglet.c \
|
||||
relay-phidget.c tlc59116.c
|
||||
|
@ -1,369 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2009, Swedish Institute of Computer Science
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Checkpoint library implementation for the Tmote Sky platform.
|
||||
* \author
|
||||
* Fredrik Osterlind <fros@sics.se>
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "lib/checkpoint.h"
|
||||
|
||||
#include "sys/rtimer.h"
|
||||
#include "sys/mt.h"
|
||||
#include "cfs/cfs.h"
|
||||
#include "cfs/cfs-coffee.h"
|
||||
#include "dev/leds.h"
|
||||
#include "dev/watchdog.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#define DEBUG 1
|
||||
#if DEBUG
|
||||
#define PRINTF(...) printf(__VA_ARGS__)
|
||||
#else
|
||||
#define PRINTF(...)
|
||||
#endif
|
||||
|
||||
#define COMMAND_ROLLBACK 1
|
||||
#define COMMAND_CHECKPOINT 2
|
||||
#define COMMAND_TBR 3
|
||||
|
||||
#define DATA_AS_HEX 0 /* If false, store binary data */
|
||||
|
||||
#define INCLUDE_RAM 1 /* Less then 10240 bytes */
|
||||
#define INCLUDE_TIMERS 1 /* 16 bytes */
|
||||
#define INCLUDE_LEDS 1 /* 1 bytes */
|
||||
|
||||
// 8kB memory
|
||||
#define RAM_START 0x1100
|
||||
#define RAM_END 0x30FF
|
||||
|
||||
#define STOP_TIMERS() TACTL &= ~(MC1); TBCTL &= ~(MC1); watchdog_stop();
|
||||
#define START_TIMERS() watchdog_start(); TACTL |= MC1; TBCTL |= MC1;
|
||||
|
||||
static struct mt_thread checkpoint_thread;
|
||||
static uint8_t preset_cmd;
|
||||
static int preset_fd;
|
||||
|
||||
typedef union {
|
||||
unsigned char u8[2];
|
||||
unsigned short u16;
|
||||
} word_union_t;
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
write_byte(int fd, uint8_t c)
|
||||
{
|
||||
#if DATA_AS_HEX
|
||||
uint8_t hex[2];
|
||||
sprintf(hex, "%02x", c);
|
||||
if(cfs_write(fd, hex, 2) != 2) {
|
||||
printf("err #1\n");
|
||||
}
|
||||
#else /* DATA_AS_HEX */
|
||||
if(cfs_write(fd, &c, 1) != 1) {
|
||||
printf("err #2\n");
|
||||
}
|
||||
#endif /* DATA_AS_HEX */
|
||||
}/*---------------------------------------------------------------------------*/
|
||||
#if 0
|
||||
static void
|
||||
write_array(int fd, unsigned char *mem, uint16_t len)
|
||||
{
|
||||
#if DATA_AS_HEX
|
||||
int i;
|
||||
for(i = 0; i < len; i++) {
|
||||
write_byte(fd, mem[i]);
|
||||
}
|
||||
#else /* DATA_AS_HEX */
|
||||
cfs_write(fd, mem, len);
|
||||
#endif /* DATA_AS_HEX */
|
||||
}
|
||||
#endif /* 0 */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
write_word(int fd, uint16_t w)
|
||||
{
|
||||
word_union_t tmp;
|
||||
tmp.u16 = w;
|
||||
write_byte(fd, tmp.u8[0]);
|
||||
write_byte(fd, tmp.u8[1]);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static uint8_t
|
||||
read_byte(int fd)
|
||||
{
|
||||
#if DATA_AS_HEX
|
||||
uint8_t hex[2];
|
||||
|
||||
cfs_read(fd, hex, 2);
|
||||
|
||||
if(hex[0] >= 'A' && hex[0] <= 'F') {
|
||||
hex[0] = (hex[0] - 'A' + 0xa);
|
||||
} else if(hex[0] >= 'a' && hex[0] <= 'f') {
|
||||
hex[0] = (hex[0] - 'a' + 0xa);
|
||||
} else {
|
||||
hex[0] = (hex[0] - '0');
|
||||
}
|
||||
if(hex[1] >= 'A' && hex[1] <= 'F') {
|
||||
hex[1] = (hex[1] - 'A' + 0xa);
|
||||
} else if(hex[1] >= 'a' && hex[1] <= 'f') {
|
||||
hex[1] = (hex[1] - 'a' + 0xa);
|
||||
} else {
|
||||
hex[1] = (hex[1] - '0');
|
||||
}
|
||||
return (uint8_t)((hex[0]<<4)&0xf0) | (hex[1]&0x0f);
|
||||
#else /* DATA_AS_HEX */
|
||||
uint8_t c;
|
||||
cfs_read(fd, &c, 1);
|
||||
return c;
|
||||
#endif /* DATA_AS_HEX */
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static uint16_t
|
||||
read_word(int fd)
|
||||
{
|
||||
word_union_t tmp;
|
||||
tmp.u8[0] = read_byte(fd);
|
||||
tmp.u8[1] = read_byte(fd);
|
||||
return tmp.u16;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
thread_checkpoint(int fd)
|
||||
{
|
||||
#if INCLUDE_RAM
|
||||
unsigned char *addr;
|
||||
uint16_t size = 0;
|
||||
unsigned char *thread_mem_start = (unsigned char *)&checkpoint_thread.thread.stack;
|
||||
unsigned char *thread_mem_end = thread_mem_start + sizeof(checkpoint_thread.thread.stack) - 1;
|
||||
unsigned char *coffee_mem_start = cfs_coffee_get_protected_mem(&size);
|
||||
unsigned char *coffee_mem_end = coffee_mem_start + size - 1;
|
||||
#endif /* INCLUDE_RAM */
|
||||
|
||||
/*printf("protected thread memory: %u, size=%u\n", (uint16_t) thread_mem_start, sizeof(checkpoint_thread.thread.stack));*/
|
||||
/*printf("protected coffee memory: %u, size=%u\n", (uint16_t) coffee_mem_start, size);*/
|
||||
|
||||
/* RAM */
|
||||
#if INCLUDE_RAM
|
||||
for(addr = (unsigned char *)RAM_START;
|
||||
addr < (unsigned char *)RAM_END;
|
||||
addr++) {
|
||||
|
||||
if((addr >= thread_mem_start && addr <= thread_mem_end)) {
|
||||
/* Writing dummy memory */
|
||||
/*write_byte(fd, 1);*/
|
||||
continue;
|
||||
}
|
||||
|
||||
if((addr >= coffee_mem_start && addr <= coffee_mem_end)) {
|
||||
/* Writing dummy memory */
|
||||
/*write_byte(fd, 2);*/
|
||||
continue;
|
||||
}
|
||||
|
||||
/* TODO Use write_array() */
|
||||
write_byte(fd, *addr);
|
||||
|
||||
if(((int)addr % 512) == 0) {
|
||||
PRINTF(".");
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* INCLUDE_RAM */
|
||||
|
||||
/* Timers */
|
||||
#if INCLUDE_TIMERS
|
||||
write_word(fd, TACTL);
|
||||
write_word(fd, TACCTL1);
|
||||
write_word(fd, TACCR1);
|
||||
write_word(fd, TAR);
|
||||
|
||||
write_word(fd, TBCTL);
|
||||
write_word(fd, TBCCTL1);
|
||||
write_word(fd, TBCCR1);
|
||||
write_word(fd, TBR);
|
||||
#endif /* INCLUDE_TIMERS */
|
||||
|
||||
/* LEDs */
|
||||
#if INCLUDE_LEDS
|
||||
write_byte(fd, leds_arch_get());
|
||||
#endif /* INCLUDE_LEDS */
|
||||
|
||||
/* Radio */
|
||||
/* ADC */
|
||||
/* ... */
|
||||
|
||||
write_byte(fd, -1); /* Coffee padding byte */
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
thread_rollback(int fd)
|
||||
{
|
||||
#if INCLUDE_RAM
|
||||
unsigned char *addr;
|
||||
uint16_t size = 0;
|
||||
unsigned char *thread_mem_start = (unsigned char *)&checkpoint_thread.thread.stack;
|
||||
unsigned char *thread_mem_end = thread_mem_start + sizeof(checkpoint_thread.thread.stack) - 1;
|
||||
unsigned char *coffee_mem_start = cfs_coffee_get_protected_mem(&size);
|
||||
unsigned char *coffee_mem_end = coffee_mem_start + size - 1;
|
||||
#endif /* INCLUDE_RAM */
|
||||
|
||||
/*printf("protected thread memory: %u, size=%u\n", (uint16_t) thread_mem_start, sizeof(checkpoint_thread.thread.stack));*/
|
||||
/*printf("protected coffee memory: %u, size=%u\n", (uint16_t) coffee_mem_start, size);*/
|
||||
|
||||
/* RAM */
|
||||
#if INCLUDE_RAM
|
||||
for(addr = (unsigned char *)RAM_START;
|
||||
addr < (unsigned char *)RAM_END;
|
||||
addr++) {
|
||||
if((addr >= thread_mem_start && addr <= thread_mem_end)) {
|
||||
/* Ignoring incoming memory */
|
||||
/*read_byte(fd);*/
|
||||
continue;
|
||||
}
|
||||
|
||||
if((addr >= coffee_mem_start && addr <= coffee_mem_end)) {
|
||||
/* Ignoring incoming memory */
|
||||
/*read_byte(fd);*/
|
||||
continue;
|
||||
}
|
||||
|
||||
*addr = read_byte(fd);
|
||||
|
||||
if(((int)addr % 512) == 0) {
|
||||
PRINTF(".");
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* INCLUDE_RAM */
|
||||
|
||||
/* Timers */
|
||||
#if INCLUDE_TIMERS
|
||||
TACTL = read_word(fd);
|
||||
TACCTL1 = read_word(fd);
|
||||
TACCR1 = read_word(fd);
|
||||
TAR = read_word(fd);
|
||||
|
||||
TBCTL = read_word(fd);
|
||||
TBCCTL1 = read_word(fd);
|
||||
TBCCR1 = read_word(fd);
|
||||
TBR = read_word(fd);
|
||||
#endif /* INCLUDE_TIMERS */
|
||||
|
||||
/* LEDs */
|
||||
#if INCLUDE_LEDS
|
||||
leds_arch_set(read_byte(fd));
|
||||
#endif /* INCLUDE_LEDS */
|
||||
|
||||
/* Radio */
|
||||
/* ADC */
|
||||
/* ... */
|
||||
|
||||
read_byte(fd); /* Coffee padding byte */
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
thread_loop(void *data)
|
||||
{
|
||||
uint8_t cmd;
|
||||
int fd;
|
||||
|
||||
while(1) {
|
||||
/* Store command and file descriptor on stack */
|
||||
cmd = preset_cmd;
|
||||
fd = preset_fd;
|
||||
|
||||
/* Handle command */
|
||||
if(cmd == COMMAND_ROLLBACK) {
|
||||
PRINTF("Rolling back");
|
||||
thread_rollback(fd);
|
||||
PRINTF(" done!\n");
|
||||
} else if(cmd == COMMAND_CHECKPOINT) {
|
||||
PRINTF("Checkpointing");
|
||||
thread_checkpoint(fd);
|
||||
PRINTF(" done!\n");
|
||||
} else if(cmd == COMMAND_TBR) {
|
||||
PRINTF("Writing TBR");
|
||||
write_word(fd, TBR);
|
||||
PRINTF(" done!\n");
|
||||
} else {
|
||||
printf("Error: unknown command: %u\n", cmd);
|
||||
}
|
||||
|
||||
/* Return to main Contiki thread */
|
||||
mt_yield();
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
checkpoint_arch_size()
|
||||
{
|
||||
return 10258;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
checkpoint_arch_checkpoint(int fd)
|
||||
{
|
||||
STOP_TIMERS();
|
||||
|
||||
preset_cmd = COMMAND_CHECKPOINT;
|
||||
preset_fd = fd;
|
||||
mt_exec(&checkpoint_thread);
|
||||
|
||||
START_TIMERS();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
checkpoint_arch_rollback(int fd)
|
||||
{
|
||||
STOP_TIMERS();
|
||||
|
||||
preset_cmd = COMMAND_ROLLBACK;
|
||||
preset_fd = fd;
|
||||
mt_exec(&checkpoint_thread);
|
||||
|
||||
START_TIMERS();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
checkpoint_arch_init(void)
|
||||
{
|
||||
mt_init();
|
||||
mt_start(&checkpoint_thread, thread_loop, NULL);
|
||||
|
||||
/*mt_stop(&checkpoint_thread);*/
|
||||
/*mt_remove();*/
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
@ -1,196 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<simconf>
|
||||
<project>../apps/mrm</project>
|
||||
<project>../apps/mspsim</project>
|
||||
<project>../apps/avrora</project>
|
||||
<project>../apps/native_gateway</project>
|
||||
<simulation>
|
||||
<title>My simulation</title>
|
||||
<delaytime>0</delaytime>
|
||||
<randomseed>generated</randomseed>
|
||||
<motedelay_us>1000000</motedelay_us>
|
||||
<radiomedium>
|
||||
org.contikios.cooja.radiomediums.UDGM
|
||||
<transmitting_range>50.0</transmitting_range>
|
||||
<interference_range>100.0</interference_range>
|
||||
<success_ratio_tx>1.0</success_ratio_tx>
|
||||
<success_ratio_rx>1.0</success_ratio_rx>
|
||||
</radiomedium>
|
||||
<motetype>
|
||||
org.contikios.cooja.mspmote.SkyMoteType
|
||||
<identifier>sky1</identifier>
|
||||
<description>Sky Mote Type #1</description>
|
||||
<source>../../examples/sky-shell/sky-checkpoint.c</source>
|
||||
<commands>make clean TARGET=sky
|
||||
make sky-checkpoint.sky TARGET=sky</commands>
|
||||
<firmware>../../examples/sky-shell/sky-checkpoint.sky</firmware>
|
||||
<moteinterface>org.contikios.cooja.interfaces.Position</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.IPAddress</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.Mote2MoteRelations</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspClock</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.MspMoteID</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.SkyButton</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.SkyFlash</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.SkyByteRadio</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.SkySerial</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.mspmote.interfaces.SkyLED</moteinterface>
|
||||
</motetype>
|
||||
<mote>
|
||||
org.contikios.cooja.mspmote.SkyMote
|
||||
<motetype_identifier>sky1</motetype_identifier>
|
||||
<breakpoints />
|
||||
<interface_config>
|
||||
org.contikios.cooja.interfaces.Position
|
||||
<x>3.537694077190867</x>
|
||||
<y>25.877706916818877</y>
|
||||
<z>0.0</z>
|
||||
</interface_config>
|
||||
<interface_config>
|
||||
org.contikios.cooja.mspmote.interfaces.MspMoteID
|
||||
<id>1</id>
|
||||
</interface_config>
|
||||
</mote>
|
||||
</simulation>
|
||||
<plugin>
|
||||
org.contikios.cooja.plugins.SimControl
|
||||
<width>248</width>
|
||||
<z>3</z>
|
||||
<height>200</height>
|
||||
<location_x>0</location_x>
|
||||
<location_y>0</location_y>
|
||||
<minimized>false</minimized>
|
||||
</plugin>
|
||||
<plugin>
|
||||
org.contikios.cooja.plugins.Visualizer
|
||||
<plugin_config>
|
||||
<skin>Mote IDs</skin>
|
||||
<skin>Radio environment (UDGM)</skin>
|
||||
</plugin_config>
|
||||
<width>246</width>
|
||||
<z>2</z>
|
||||
<height>210</height>
|
||||
<location_x>2</location_x>
|
||||
<location_y>199</location_y>
|
||||
<minimized>false</minimized>
|
||||
</plugin>
|
||||
<plugin>
|
||||
org.contikios.cooja.plugins.LogListener
|
||||
<plugin_config>
|
||||
<filter />
|
||||
</plugin_config>
|
||||
<width>849</width>
|
||||
<z>1</z>
|
||||
<height>246</height>
|
||||
<location_x>0</location_x>
|
||||
<location_y>409</location_y>
|
||||
<minimized>false</minimized>
|
||||
</plugin>
|
||||
<plugin>
|
||||
org.contikios.cooja.plugins.ScriptRunner
|
||||
<plugin_config>
|
||||
<script>TIMEOUT(360000, log.log("timeout at phase " + phase + ". last message: " + msg + "\n"));
|
||||
phase=0;
|
||||
|
||||
/* Wait until node has booted */
|
||||
WAIT_UNTIL(msg.startsWith('Starting'));
|
||||
log.log("Shell started\n");
|
||||
phase++;
|
||||
|
||||
/* 1. BACKGROUND PROCESS - NO CHECKPOINTING */
|
||||
write(mote, "repeat 10 1 echo bg process &\n");
|
||||
log.log("Starting background process without checkpointing\n");
|
||||
expected=10;
|
||||
while (expected > 0) {
|
||||
YIELD_THEN_WAIT_UNTIL(msg.contains('bg process'));
|
||||
expected--;
|
||||
}
|
||||
|
||||
/* Make sure background process has exited */
|
||||
GENERATE_MSG(3000, "continue");
|
||||
while (!msg.contains('continue')) {
|
||||
YIELD();
|
||||
if (msg.contains('bg process')) {
|
||||
log.log("Too many bg messages at phase: " + phase + "\n");
|
||||
log.testFailed(); /* We are done! */
|
||||
while (true) YIELD();
|
||||
}
|
||||
}
|
||||
log.log("Background process without checkpointing done\n\n");
|
||||
phase++;
|
||||
|
||||
/* 2. BACKGROUND PROCESS - CHECKPOINTING EVERY SECOND */
|
||||
write(mote, "repeat 10 1 echo bg process &\n");
|
||||
log.log("Starting background process with periodic checkpointing\n");
|
||||
expected=10;
|
||||
while (expected > 0) {
|
||||
YIELD_THEN_WAIT_UNTIL(msg.contains('bg process'));
|
||||
expected--;
|
||||
write(mote, "checkpoint file" + expected + "\n");
|
||||
log.log("> checkpoint file" + expected + "\n");
|
||||
}
|
||||
|
||||
/* Make sure background process has exited */
|
||||
GENERATE_MSG(3000, "continue");
|
||||
while (!msg.contains('continue')) {
|
||||
YIELD();
|
||||
if (msg.contains('bg process')) {
|
||||
log.log("Too many bg messages at phase: " + phase + "\n");
|
||||
log.testFailed(); /* We are done! */
|
||||
while (true) YIELD();
|
||||
}
|
||||
}
|
||||
log.log("Background process with periodic checkpointing done\n\n");
|
||||
phase++;
|
||||
|
||||
/* 3. LIST ALL FILES */
|
||||
write(mote, "ls");
|
||||
YIELD_THEN_WAIT_UNTIL(msg.contains('file9'));
|
||||
YIELD_THEN_WAIT_UNTIL(msg.contains('file8'));
|
||||
YIELD_THEN_WAIT_UNTIL(msg.contains('file7'));
|
||||
YIELD_THEN_WAIT_UNTIL(msg.contains('file6'));
|
||||
YIELD_THEN_WAIT_UNTIL(msg.contains('file5'));
|
||||
YIELD_THEN_WAIT_UNTIL(msg.contains('file4'));
|
||||
YIELD_THEN_WAIT_UNTIL(msg.contains('file3'));
|
||||
YIELD_THEN_WAIT_UNTIL(msg.contains('file2'));
|
||||
YIELD_THEN_WAIT_UNTIL(msg.contains('file1'));
|
||||
YIELD_THEN_WAIT_UNTIL(msg.contains('file0'));
|
||||
GENERATE_MSG(1000, "continue");
|
||||
YIELD_THEN_WAIT_UNTIL(msg.contains('continue'));
|
||||
log.log("All checkpoints are stored in the filesystem\n\n");
|
||||
phase++;
|
||||
|
||||
/* 4. ROLLBACK TO RESTORE BACKGROUND PROCESS */
|
||||
write(mote, "rollback file7");
|
||||
log.log("Rolling back background process at count 7\n");
|
||||
expected=7;
|
||||
while (expected > 0) {
|
||||
YIELD_THEN_WAIT_UNTIL(msg.contains('bg process'));
|
||||
expected--;
|
||||
}
|
||||
|
||||
/* Make sure background process has exited */
|
||||
GENERATE_MSG(3000, "continue");
|
||||
while (!msg.contains('continue')) {
|
||||
YIELD();
|
||||
if (msg.contains('bg process')) {
|
||||
log.log("Too many bg messages at phase: " + phase + "\n");
|
||||
log.testFailed(); /* We are done! */
|
||||
while (true) YIELD();
|
||||
}
|
||||
}
|
||||
log.log("Background process was rolled back successfully\n\n");
|
||||
phase++;
|
||||
|
||||
|
||||
log.testOK(); /* We are done! */</script>
|
||||
<active>true</active>
|
||||
</plugin_config>
|
||||
<width>604</width>
|
||||
<z>0</z>
|
||||
<height>409</height>
|
||||
<location_x>246</location_x>
|
||||
<location_y>0</location_y>
|
||||
<minimized>false</minimized>
|
||||
</plugin>
|
||||
</simconf>
|
||||
|
@ -22,10 +22,10 @@
|
||||
org.contikios.cooja.mspmote.SkyMoteType
|
||||
<identifier>sky1</identifier>
|
||||
<description>Sky Mote Type #sky1</description>
|
||||
<source>[CONTIKI_DIR]/examples/sky-shell/sky-checkpoint.c</source>
|
||||
<source>[CONTIKI_DIR]/examples/sky-shell/sky-shell.c</source>
|
||||
<commands>make clean TARGET=sky
|
||||
make sky-checkpoint.sky TARGET=sky</commands>
|
||||
<firmware>[CONTIKI_DIR]/examples/sky-shell/sky-checkpoint.sky</firmware>
|
||||
make sky-shell.sky TARGET=sky</commands>
|
||||
<firmware>[CONTIKI_DIR]/examples/sky-shell/sky-shell.sky</firmware>
|
||||
<moteinterface>org.contikios.cooja.interfaces.Position</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.IPAddress</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.Mote2MoteRelations</moteinterface>
|
||||
|
Loading…
Reference in New Issue
Block a user