/*---------------------------------------------------------------------------*/ 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); unsigned char *coffee_mem_start = cfs_coffee_get_protected_mem(&size); unsigned char *coffee_mem_end = coffee_mem_start + size; #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 if (coffee_mem_start < thread_mem_start) { read(fd, RAM_START, coffee_mem_start-RAM_START); read(fd, coffee_mem_end, thread_mem_start-coffee_mem_end); read(fd, thread_mem_end, RAM_END-thread_mem_end); } else { read(fd, RAM_START, thread_mem_start-RAM_START); read(fd, thread_mem_end, coffee_mem_start-thread_mem_end); read(fd, coffee_mem_end, RAM_END-coffee_mem_end); } #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 */ /* UART DMA */ #if INCLUDE_UART_DMA read_word(fd); /* DMA0SZ ignored */ uart1_reset_dma(); #endif /* INCLUDE_UART_DMA */ /* Radio */ /* ADC */ /* ... */ #if INCLUDE_PADDING read_byte(fd); #endif /* INCLUDE_PADDING */ }
/*---------------------------------------------------------------------------*/ static void thread_checkpoint(int fd) { #if INCLUDE_RAM unsigned char *addr; uint16_t size = 0; unsigned char *coffee_mem_start = cfs_coffee_get_protected_mem(&size); unsigned char *coffee_mem_end = coffee_mem_start + size; unsigned char *thread_mem_start = (unsigned char *)&checkpoint_thread.thread.stack; unsigned char *thread_mem_end = thread_mem_start + sizeof(checkpoint_thread.thread.stack); #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 if (coffee_mem_start < thread_mem_start) { write(fd, RAM_START, coffee_mem_start-RAM_START); write(fd, coffee_mem_end, thread_mem_start-coffee_mem_end); write(fd, thread_mem_end, RAM_END-thread_mem_end); } else { write(fd, RAM_START, thread_mem_start-RAM_START); write(fd, thread_mem_end, coffee_mem_start-thread_mem_end); write(fd, coffee_mem_end, RAM_END-coffee_mem_end); } #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 */ /* UART DMA */ #if INCLUDE_UART_DMA write_word(fd, DMA0SZ); #endif /* INCLUDE_UART_DMA */ /* Radio */ /* ADC */ /* ... */ #if INCLUDE_PADDING write_byte(fd, -1); #endif /* INCLUDE_PADDING */ }
/*---------------------------------------------------------------------------*/ 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 */ }
/*---------------------------------------------------------------------------*/ 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 */ }