48 #include "dev/watchdog.h"
53 #define PRINTF(...) printf(__VA_ARGS__)
58 #define COMMAND_ROLLBACK 1
59 #define COMMAND_CHECKPOINT 2
65 #define INCLUDE_TIMERS 1
66 #define INCLUDE_LEDS 1
69 #define RAM_START 0x1100
70 #define RAM_END 0x30FF
72 #define STOP_TIMERS() TACTL &= ~(MC1); TBCTL &= ~(MC1); watchdog_stop();
73 #define START_TIMERS() watchdog_start(); TACTL |= MC1; TBCTL |= MC1;
75 static struct mt_thread checkpoint_thread;
76 static uint8_t preset_cmd;
86 write_byte(
int fd, uint8_t c)
90 sprintf(hex,
"%02x", c);
91 if(cfs_write(fd, hex, 2) != 2) {
95 if(cfs_write(fd, &c, 1) != 1) {
102 write_array(
int fd,
unsigned char *mem, uint16_t len)
106 for(i = 0; i < len; i++) {
107 write_byte(fd, mem[i]);
110 cfs_write(fd, mem, len);
116 write_word(
int fd, uint16_t w)
120 write_byte(fd, tmp.u8[0]);
121 write_byte(fd, tmp.u8[1]);
130 cfs_read(fd, hex, 2);
132 if(hex[0] >=
'A' && hex[0] <=
'F') {
133 hex[0] = (hex[0] -
'A' + 0xa);
134 }
else if(hex[0] >=
'a' && hex[0] <=
'f') {
135 hex[0] = (hex[0] -
'a' + 0xa);
137 hex[0] = (hex[0] -
'0');
139 if(hex[1] >=
'A' && hex[1] <=
'F') {
140 hex[1] = (hex[1] -
'A' + 0xa);
141 }
else if(hex[1] >=
'a' && hex[1] <=
'f') {
142 hex[1] = (hex[1] -
'a' + 0xa);
144 hex[1] = (hex[1] -
'0');
146 return (uint8_t)((hex[0]<<4)&0xf0) | (hex[1]&0x0f);
158 tmp.u8[0] = read_byte(fd);
159 tmp.u8[1] = read_byte(fd);
164 thread_checkpoint(
int fd)
169 unsigned char *thread_mem_start = (
unsigned char *)&checkpoint_thread.thread.stack;
170 unsigned char *thread_mem_end = thread_mem_start +
sizeof(checkpoint_thread.thread.stack) - 1;
172 unsigned char *coffee_mem_end = coffee_mem_start + size - 1;
180 for(addr = (
unsigned char *)RAM_START;
181 addr < (
unsigned char *)RAM_END;
184 if((addr >= thread_mem_start && addr <= thread_mem_end)) {
190 if((addr >= coffee_mem_start && addr <= coffee_mem_end)) {
197 write_byte(fd, *addr);
199 if(((
int)addr % 512) == 0) {
208 write_word(fd, TACTL);
209 write_word(fd, TACCTL1);
210 write_word(fd, TACCR1);
213 write_word(fd, TBCTL);
214 write_word(fd, TBCCTL1);
215 write_word(fd, TBCCR1);
221 write_byte(fd, leds_arch_get());
232 thread_rollback(
int fd)
237 unsigned char *thread_mem_start = (
unsigned char *)&checkpoint_thread.thread.stack;
238 unsigned char *thread_mem_end = thread_mem_start +
sizeof(checkpoint_thread.thread.stack) - 1;
240 unsigned char *coffee_mem_end = coffee_mem_start + size - 1;
248 for(addr = (
unsigned char *)RAM_START;
249 addr < (
unsigned char *)RAM_END;
251 if((addr >= thread_mem_start && addr <= thread_mem_end)) {
257 if((addr >= coffee_mem_start && addr <= coffee_mem_end)) {
263 *addr = read_byte(fd);
265 if(((
int)addr % 512) == 0) {
274 TACTL = read_word(fd);
275 TACCTL1 = read_word(fd);
276 TACCR1 = read_word(fd);
279 TBCTL = read_word(fd);
280 TBCCTL1 = read_word(fd);
281 TBCCR1 = read_word(fd);
287 leds_arch_set(read_byte(fd));
298 thread_loop(
void *data)
309 if(cmd == COMMAND_ROLLBACK) {
310 PRINTF(
"Rolling back");
313 }
else if(cmd == COMMAND_CHECKPOINT) {
314 PRINTF(
"Checkpointing");
315 thread_checkpoint(fd);
317 }
else if(cmd == COMMAND_TBR) {
318 PRINTF(
"Writing TBR");
322 printf(
"Error: unknown command: %u\n", cmd);
331 checkpoint_arch_size()
337 checkpoint_arch_checkpoint(
int fd)
341 preset_cmd = COMMAND_CHECKPOINT;
349 checkpoint_arch_rollback(
int fd)
353 preset_cmd = COMMAND_ROLLBACK;
361 checkpoint_arch_init(
void)