#include "Storage.h" #include #include #include #include #include #include using namespace QURT; #define QURT_STORAGE_MAX_WRITE 512 #define QURT_STORAGE_LINE_SHIFT 9 #define QURT_STORAGE_LINE_SIZE (1<>QURT_STORAGE_LINE_SHIFT; line <= end>>QURT_STORAGE_LINE_SHIFT; line++) { _dirty_mask |= 1U << line; } } void Storage::read_block(void *dst, uint16_t loc, size_t n) { if (loc >= sizeof(_buffer)-(n-1)) { return; } init(); memcpy(dst, &_buffer[loc], n); } void Storage::write_block(uint16_t loc, const void *src, size_t n) { if (loc >= sizeof(_buffer)-(n-1)) { return; } if (memcmp(src, &_buffer[loc], n) != 0) { init(); memcpy(&_buffer[loc], src, n); _mark_dirty(loc, n); } } void Storage::_timer_tick(void) { if (!_initialised || _dirty_mask == 0 || _fd == -1) { return; } // write out the first dirty set of lines. We don't write more // than one to keep the latency of this call to a minimum uint8_t i, n; for (i=0; i>QURT_STORAGE_LINE_SHIFT); n++) { if (!(_dirty_mask & (1<<(n+i)))) { break; } // mark that line clean write_mask |= (1<<(n+i)); } /* write the lines. This also updates _dirty_mask. Note that because this is a SCHED_FIFO thread it will not be preempted by the main task except during blocking calls. This means we don't need a semaphore around the _dirty_mask updates. */ if (lseek(_fd, i<