make watchdog management slightly more abstract to simplify porting

This commit is contained in:
nvt-se 2010-01-14 21:16:58 +00:00
parent 46753473fa
commit d2655eac7a
2 changed files with 22 additions and 12 deletions

View File

@ -52,7 +52,13 @@
#include "cfs/cfs.h" #include "cfs/cfs.h"
#include "cfs-coffee-arch.h" #include "cfs-coffee-arch.h"
#include "cfs/cfs-coffee.h" #include "cfs/cfs-coffee.h"
#include "dev/watchdog.h"
#ifndef COFFEE_WATCHDOG_START
#define COFFEE_WATCHDOG_START()
#endif
#ifndef COFFEE_WATCHDOG_STOP
#define COFFEE_WATCHDOG_STOP()
#endif
#if COFFEE_START & (COFFEE_SECTOR_SIZE - 1) #if COFFEE_START & (COFFEE_SECTOR_SIZE - 1)
#error COFFEE_START must point to the first byte in a sector. #error COFFEE_START must point to the first byte in a sector.
@ -284,7 +290,7 @@ collect_garbage(int mode)
struct sector_status stats; struct sector_status stats;
coffee_page_t first_page, isolation_count; coffee_page_t first_page, isolation_count;
watchdog_stop(); COFFEE_WATCHDOG_STOP();
PRINTF("Coffee: Running the file system garbage collector in %s mode\n", PRINTF("Coffee: Running the file system garbage collector in %s mode\n",
mode == GC_RELUCTANT ? "reluctant" : "greedy"); mode == GC_RELUCTANT ? "reluctant" : "greedy");
@ -322,7 +328,7 @@ collect_garbage(int mode)
} }
} }
watchdog_start(); COFFEE_WATCHDOG_START();
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static coffee_page_t static coffee_page_t
@ -538,10 +544,10 @@ reserve(const char *name, coffee_page_t pages,
coffee_page_t page; coffee_page_t page;
struct file *file; struct file *file;
watchdog_stop(); COFFEE_WATCHDOG_STOP();
if(!allow_duplicates && find_file(name) != NULL) { if(!allow_duplicates && find_file(name) != NULL) {
watchdog_start(); COFFEE_WATCHDOG_START();
return NULL; return NULL;
} }
@ -553,7 +559,7 @@ reserve(const char *name, coffee_page_t pages,
collect_garbage(GC_GREEDY); collect_garbage(GC_GREEDY);
page = find_contiguous_pages(pages); page = find_contiguous_pages(pages);
if(page == INVALID_PAGE) { if(page == INVALID_PAGE) {
watchdog_start(); COFFEE_WATCHDOG_START();
*gc_wait = 1; *gc_wait = 1;
return NULL; return NULL;
} }
@ -570,7 +576,7 @@ reserve(const char *name, coffee_page_t pages,
file = load_file(page, &hdr); file = load_file(page, &hdr);
file->end = 0; file->end = 0;
watchdog_start(); COFFEE_WATCHDOG_START();
return file; return file;
} }
@ -735,21 +741,21 @@ merge_log(coffee_page_t file_page, int extend)
} }
offset = 0; offset = 0;
watchdog_stop(); COFFEE_WATCHDOG_STOP();
do { do {
char buf[hdr.log_record_size == 0 ? COFFEE_PAGE_SIZE : hdr.log_record_size]; char buf[hdr.log_record_size == 0 ? COFFEE_PAGE_SIZE : hdr.log_record_size];
n = cfs_read(fd, buf, sizeof(buf)); n = cfs_read(fd, buf, sizeof(buf));
if(n < 0) { if(n < 0) {
remove_by_page(new_file->page, 0, 0); remove_by_page(new_file->page, 0, 0);
cfs_close(fd); cfs_close(fd);
watchdog_start(); COFFEE_WATCHDOG_START();
return -1; return -1;
} else if(n > 0) { } else if(n > 0) {
COFFEE_WRITE(buf, n, absolute_offset(new_file->page, offset)); COFFEE_WRITE(buf, n, absolute_offset(new_file->page, offset));
offset += n; offset += n;
} }
} while(n != 0); } while(n != 0);
watchdog_start(); COFFEE_WATCHDOG_START();
for(i = 0; i < COFFEE_FD_SET_SIZE; i++) { for(i = 0; i < COFFEE_FD_SET_SIZE; i++) {
if(coffee_fd_set[i].flags != COFFEE_FD_FREE && if(coffee_fd_set[i].flags != COFFEE_FD_FREE &&
@ -1208,12 +1214,12 @@ cfs_coffee_format(void)
*next_free = 0; *next_free = 0;
watchdog_stop(); COFFEE_WATCHDOG_STOP();
for(i = 0; i < COFFEE_SECTOR_COUNT; i++) { for(i = 0; i < COFFEE_SECTOR_COUNT; i++) {
COFFEE_ERASE(i); COFFEE_ERASE(i);
PRINTF("."); PRINTF(".");
} }
watchdog_start(); COFFEE_WATCHDOG_START();
/* Formatting invalidates the file information. */ /* Formatting invalidates the file information. */
memset(&protected_mem, 0, sizeof(protected_mem)); memset(&protected_mem, 0, sizeof(protected_mem));

View File

@ -42,6 +42,7 @@
#include "contiki-conf.h" #include "contiki-conf.h"
#include "dev/xmem.h" #include "dev/xmem.h"
#include "dev/watchdog.h"
/* Coffee configuration parameters. */ /* Coffee configuration parameters. */
#define COFFEE_SECTOR_SIZE 65536UL #define COFFEE_SECTOR_SIZE 65536UL
@ -57,6 +58,9 @@
#define COFFEE_MICRO_LOGS 1 #define COFFEE_MICRO_LOGS 1
#define COFFEE_WATCHDOG_START() watchdog_start()
#define COFFEE_WATCHDOG_STOP() watchdog_stop()
/* Flash operations. */ /* Flash operations. */
#define COFFEE_WRITE(buf, size, offset) \ #define COFFEE_WRITE(buf, size, offset) \
xmem_pwrite((char *)(buf), (size), COFFEE_START + (offset)) xmem_pwrite((char *)(buf), (size), COFFEE_START + (offset))