From 0fd503af4265638a5ad53398d9ce810a55f6ef12 Mon Sep 17 00:00:00 2001 From: Adam Dunkels Date: Tue, 26 Nov 2013 22:47:11 +0100 Subject: [PATCH] Removed the experimental checkpointing code --- Makefile.include | 2 +- apps/shell/Makefile.shell | 2 +- apps/shell/shell-checkpoint.c | 107 --- apps/shell/shell-checkpoint.h | 40 - apps/shell/shell.h | 1 - core/lib/checkpoint.c | 59 -- core/lib/checkpoint.h | 59 -- examples/collect/collect-view-shell.c | 1 - examples/example-shell/example-shell.c | 1 - examples/sky-shell-exec/sky-shell-exec.c | 3 - examples/sky-shell/sky-checkpoint.c | 89 --- examples/sky-shell/sky-shell.c | 1 - platform/sky/Makefile.common | 2 +- platform/sky/checkpoint-arch.c | 692 ------------------ platform/wismote/Makefile.wismote | 4 +- platform/wismote/checkpoint-arch.c | 370 ---------- platform/z1/Makefile.common | 2 +- platform/z1/checkpoint-arch.c | 369 ---------- .../03-base/04-sky-checkpointing.csc | 196 ----- .../06-shell/03-sky-shell-sendcmd.csc | 6 +- 20 files changed, 9 insertions(+), 1997 deletions(-) delete mode 100644 apps/shell/shell-checkpoint.c delete mode 100644 apps/shell/shell-checkpoint.h delete mode 100644 core/lib/checkpoint.c delete mode 100644 core/lib/checkpoint.h delete mode 100644 examples/sky-shell/sky-checkpoint.c delete mode 100644 platform/sky/checkpoint-arch.c delete mode 100644 platform/wismote/checkpoint-arch.c delete mode 100644 platform/z1/checkpoint-arch.c delete mode 100644 regression-tests/03-base/04-sky-checkpointing.csc diff --git a/Makefile.include b/Makefile.include index fb215a404..937f02d98 100644 --- a/Makefile.include +++ b/Makefile.include @@ -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 diff --git a/apps/shell/Makefile.shell b/apps/shell/Makefile.shell index 10ceec53a..97cd5663f 100644 --- a/apps/shell/Makefile.shell +++ b/apps/shell/Makefile.shell @@ -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 \ diff --git a/apps/shell/shell-checkpoint.c b/apps/shell/shell-checkpoint.c deleted file mode 100644 index 3a6bf308b..000000000 --- a/apps/shell/shell-checkpoint.c +++ /dev/null @@ -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 - -/*---------------------------------------------------------------------------*/ -PROCESS(shell_checkpoint_process, "checkpoint"); -SHELL_COMMAND(checkpoint_command, - "checkpoint", - "checkpoint : checkpoint local state to file", - &shell_checkpoint_process); -PROCESS(shell_rollback_process, "rollback"); -SHELL_COMMAND(rollback_command, - "rollback", - "rollback : 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); -} -/*---------------------------------------------------------------------------*/ diff --git a/apps/shell/shell-checkpoint.h b/apps/shell/shell-checkpoint.h deleted file mode 100644 index 61a57e53e..000000000 --- a/apps/shell/shell-checkpoint.h +++ /dev/null @@ -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_ */ diff --git a/apps/shell/shell.h b/apps/shell/shell.h index 0ce566475..750cee02f 100644 --- a/apps/shell/shell.h +++ b/apps/shell/shell.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" diff --git a/core/lib/checkpoint.c b/core/lib/checkpoint.c deleted file mode 100644 index 479d1b860..000000000 --- a/core/lib/checkpoint.c +++ /dev/null @@ -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 - */ - -#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); -} diff --git a/core/lib/checkpoint.h b/core/lib/checkpoint.h deleted file mode 100644 index 4a8164536..000000000 --- a/core/lib/checkpoint.h +++ /dev/null @@ -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 - */ - -#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 */ diff --git a/examples/collect/collect-view-shell.c b/examples/collect/collect-view-shell.c index 74e12e487..b6ee159f4 100644 --- a/examples/collect/collect-view-shell.c +++ b/examples/collect/collect-view-shell.c @@ -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 diff --git a/examples/example-shell/example-shell.c b/examples/example-shell/example-shell.c index 471d63282..97943a308 100644 --- a/examples/example-shell/example-shell.c +++ b/examples/example-shell/example-shell.c @@ -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();*/ diff --git a/examples/sky-shell-exec/sky-shell-exec.c b/examples/sky-shell-exec/sky-shell-exec.c index 5580c58f2..f1059f33a 100644 --- a/examples/sky-shell-exec/sky-shell-exec.c +++ b/examples/sky-shell-exec/sky-shell-exec.c @@ -43,8 +43,6 @@ #include "dev/sht11.h" #include "dev/battery-sensor.h" -#include "lib/checkpoint.h" - #include "net/rime/timesynch.h" #include @@ -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(); diff --git a/examples/sky-shell/sky-checkpoint.c b/examples/sky-shell/sky-checkpoint.c deleted file mode 100644 index 396972922..000000000 --- a/examples/sky-shell/sky-checkpoint.c +++ /dev/null @@ -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 - */ - -#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 -#include - -#include -#include - -#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(); -} -/*---------------------------------------------------------------------------*/ diff --git a/examples/sky-shell/sky-shell.c b/examples/sky-shell/sky-shell.c index 5ccba54fc..62c4b5ba4 100644 --- a/examples/sky-shell/sky-shell.c +++ b/examples/sky-shell/sky-shell.c @@ -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(); diff --git a/platform/sky/Makefile.common b/platform/sky/Makefile.common index 64484e1da..2f8b32dc0 100644 --- a/platform/sky/Makefile.common +++ b/platform/sky/Makefile.common @@ -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 diff --git a/platform/sky/checkpoint-arch.c b/platform/sky/checkpoint-arch.c deleted file mode 100644 index 8fa5a7f39..000000000 --- a/platform/sky/checkpoint-arch.c +++ /dev/null @@ -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 - */ - -#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 - -#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 */ diff --git a/platform/wismote/Makefile.wismote b/platform/wismote/Makefile.wismote index cc87bd446..0c076652d 100644 --- a/platform/wismote/Makefile.wismote +++ b/platform/wismote/Makefile.wismote @@ -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 diff --git a/platform/wismote/checkpoint-arch.c b/platform/wismote/checkpoint-arch.c deleted file mode 100644 index 12f71bb89..000000000 --- a/platform/wismote/checkpoint-arch.c +++ /dev/null @@ -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 - */ - -#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 - -#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();*/ -} -/*---------------------------------------------------------------------------*/ diff --git a/platform/z1/Makefile.common b/platform/z1/Makefile.common index da194f9f7..bf2eb95e9 100644 --- a/platform/z1/Makefile.common +++ b/platform/z1/Makefile.common @@ -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 diff --git a/platform/z1/checkpoint-arch.c b/platform/z1/checkpoint-arch.c deleted file mode 100644 index f9fff0324..000000000 --- a/platform/z1/checkpoint-arch.c +++ /dev/null @@ -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 - */ - -#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 - -#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();*/ -} -/*---------------------------------------------------------------------------*/ diff --git a/regression-tests/03-base/04-sky-checkpointing.csc b/regression-tests/03-base/04-sky-checkpointing.csc deleted file mode 100644 index 3b4b18108..000000000 --- a/regression-tests/03-base/04-sky-checkpointing.csc +++ /dev/null @@ -1,196 +0,0 @@ - - - ../apps/mrm - ../apps/mspsim - ../apps/avrora - ../apps/native_gateway - - My simulation - 0 - generated - 1000000 - - org.contikios.cooja.radiomediums.UDGM - 50.0 - 100.0 - 1.0 - 1.0 - - - org.contikios.cooja.mspmote.SkyMoteType - sky1 - Sky Mote Type #1 - ../../examples/sky-shell/sky-checkpoint.c - make clean TARGET=sky -make sky-checkpoint.sky TARGET=sky - ../../examples/sky-shell/sky-checkpoint.sky - org.contikios.cooja.interfaces.Position - org.contikios.cooja.interfaces.IPAddress - org.contikios.cooja.interfaces.Mote2MoteRelations - org.contikios.cooja.mspmote.interfaces.MspClock - org.contikios.cooja.mspmote.interfaces.MspMoteID - org.contikios.cooja.mspmote.interfaces.SkyButton - org.contikios.cooja.mspmote.interfaces.SkyFlash - org.contikios.cooja.mspmote.interfaces.SkyByteRadio - org.contikios.cooja.mspmote.interfaces.SkySerial - org.contikios.cooja.mspmote.interfaces.SkyLED - - - org.contikios.cooja.mspmote.SkyMote - sky1 - - - org.contikios.cooja.interfaces.Position - 3.537694077190867 - 25.877706916818877 - 0.0 - - - org.contikios.cooja.mspmote.interfaces.MspMoteID - 1 - - - - - org.contikios.cooja.plugins.SimControl - 248 - 3 - 200 - 0 - 0 - false - - - org.contikios.cooja.plugins.Visualizer - - Mote IDs - Radio environment (UDGM) - - 246 - 2 - 210 - 2 - 199 - false - - - org.contikios.cooja.plugins.LogListener - - - - 849 - 1 - 246 - 0 - 409 - false - - - org.contikios.cooja.plugins.ScriptRunner - - - true - - 604 - 0 - 409 - 246 - 0 - false - - - diff --git a/regression-tests/06-shell/03-sky-shell-sendcmd.csc b/regression-tests/06-shell/03-sky-shell-sendcmd.csc index 98fef3bc0..605c6cdc3 100644 --- a/regression-tests/06-shell/03-sky-shell-sendcmd.csc +++ b/regression-tests/06-shell/03-sky-shell-sendcmd.csc @@ -22,10 +22,10 @@ org.contikios.cooja.mspmote.SkyMoteType sky1 Sky Mote Type #sky1 - [CONTIKI_DIR]/examples/sky-shell/sky-checkpoint.c + [CONTIKI_DIR]/examples/sky-shell/sky-shell.c make clean TARGET=sky -make sky-checkpoint.sky TARGET=sky - [CONTIKI_DIR]/examples/sky-shell/sky-checkpoint.sky +make sky-shell.sky TARGET=sky + [CONTIKI_DIR]/examples/sky-shell/sky-shell.sky org.contikios.cooja.interfaces.Position org.contikios.cooja.interfaces.IPAddress org.contikios.cooja.interfaces.Mote2MoteRelations