13 #include <lib/assert.h> 16 #include <cfs-coffee-arch.h> 29 #define PRINTD(FORMAT, args...) do {} while (0) 31 #define PRINTD(FORMAT, args...) printf(FORMAT, ##args) 34 #define COFFEE_PAGE_MASK (COFFEE_PAGE_SIZE - 1) 39 struct coffee_async_format_state_t
49 void coffee_async_format_callback(
struct mwork_t *
work);
55 static struct coffee_async_format_state_t coffee_async_format_state =
57 .work =
MWORK_INIT(coffee_async_format_state.work, coffee_async_format_callback),
64 static inline void negate_buffer(
void *
data, int32_t chunk)
66 uint32_t addr = (uint32_t) data;
67 uint32_t *p = (uint32_t *) (addr & ~0x03);
68 uint32_t ms = 0xFFFFFFFF << ((addr & 0x03) << 3);
70 uint32_t fs = 0xFFFFFFFF >> ((0x04 - (chunk & 0x03)) << 3);
78 for (i = 1; i < chunk; ++i)
90 void flash_read(uint32_t address,
void *data, uint32_t length)
98 next = (address | COFFEE_PAGE_MASK) + 1;
99 chunk = next - address;
104 negate_buffer(p, chunk);
115 void flash_write(uint32_t address,
const void *data, uint32_t length)
117 const char *p =
data;
121 assert(length == 0 || ((uint32_t) data & 0x20000000) != 0);
125 next = (address | COFFEE_PAGE_MASK) + 1;
126 chunk = next - address;
130 negate_buffer((
void *) p, chunk);
132 negate_buffer((
void *) p, chunk);
143 enum coffee_async_format_status_t coffee_async_format_status(
void)
146 return COFFEE_ASYNC_FORMAT_ONGOING;
148 return COFFEE_ASYNC_FORMAT_IDLE;
154 void coffee_async_format(
void)
164 memset(mem, 0, size);
165 coffee_async_format_state.work.at =
mwork_now();
166 coffee_async_format_state.sector = 0;
174 void coffee_async_format_cancel(
void)
188 void coffee_async_format_callback(
struct mwork_t *work)
190 struct coffee_async_format_state_t *state =
191 container_of(work,
struct coffee_async_format_state_t, work);
197 state->work.at += MS_TO_TICKS(30);
206 state->work.at += MS_TO_TICKS(100);
210 if (state->sector >= COFFEE_SIZE / COFFEE_SECTOR_SIZE)
221 goto reschedule_default;
225 state->work.at += MS_TO_TICKS(300);
Header file for the EVE millisecond-scale work scheduling.
bool SpiMemoryIsBusy(const struct spi_memory_t *Memory)
Name: SpiMemoryIsBusy Checks if the memory write or erase operation is in progress Called from main p...
#define PRINTD(FORMAT, args...)
#define container_of(ptr, type, mem)
bool SpiMemoryEraseBlockAsync(const struct spi_memory_t *Memory, uint32_t BlockIndex)
Name: SpiMemoryEraseBlockAsync Begines erasing given block in SPI memory. Called from main program le...
bool SpiMemoryWrite(const struct spi_memory_t *Memory, uint32_t DstAddress, const void *SrcBuffer, uint32_t ByteCount)
Name: SpiMemoryWrite Writes bytes from SrcBuffer to SPI memory. It the SPI memory is page based...
static mwork_time_t mwork_now()
static bool SpiIsBusy(const struct spi_t *Spi)
Name: SpiIsBusy WARNING: SpiCsEnable() must be called prior to this function. Testes if transmitter i...
#define MWORK_INIT(x, callback)
static bool mwork_pending(struct mwork_t *work)
uint8_t data[USBNET_RX_BUF_SIZE]
void mwork_schedule(struct mwork_t *work)
void swint_enable(swint_state_t state)
bool SpiMemoryRead(const struct spi_memory_t *Memory, void *DstBuffer, uint32_t SrcAddress, uint32_t ByteCount)
Name: SpiMemoryRead Reads bytes from SPI memory to DstBuffer. Called from main program level...
swint_state_t swint_disable(void)
void * cfs_coffee_get_protected_mem(unsigned *size)
Points out a memory region that may not be altered during checkpointing operations that use the file ...
void mwork_cancel(struct mwork_t *work)