93 int startSector = start / geometry->
sectorSize;
99 if (endRemainder > 0) {
103 for (
int i = startSector;
i < endSector;
i++) {
169 static uint32_t
flashfsWriteBuffers(uint8_t
const **buffers, uint32_t *bufferSizes,
int bufferCount,
bool sync)
171 uint32_t bytesTotal = 0;
175 for (i = 0; i < bufferCount; i++) {
176 bytesTotal += bufferSizes[
i];
183 uint32_t bytesTotalRemaining = bytesTotal;
185 while (bytesTotalRemaining > 0) {
186 uint32_t bytesTotalThisIteration;
187 uint32_t bytesRemainThisIteration;
196 bytesTotalThisIteration = bytesTotalRemaining;
209 bytesRemainThisIteration = bytesTotalThisIteration;
211 for (i = 0; i < bufferCount; i++) {
212 if (bufferSizes[i] > 0) {
214 if (bufferSizes[i] >= bytesRemainThisIteration) {
217 buffers[
i] += bytesRemainThisIteration;
218 bufferSizes[
i] -= bytesRemainThisIteration;
220 bytesRemainThisIteration = 0;
226 bytesRemainThisIteration -= bufferSizes[
i];
228 buffers[
i] += bufferSizes[
i];
236 bytesTotalRemaining -= bytesTotalThisIteration;
249 return bytesTotal - bytesTotalRemaining;
277 uint8_t
const * buffers[2];
278 uint32_t bufferSizes[2];
284 return tailAddress + bufferSizes[0] + bufferSizes[1];
316 uint8_t
const * buffers[2];
317 uint32_t bufferSizes[2];
318 uint32_t bytesWritten;
339 uint8_t
const * buffers[2];
340 uint32_t bufferSizes[2];
387 uint8_t
const * buffers[3];
388 uint32_t bufferSizes[3];
395 bufferSizes[2] = len;
402 uint32_t bytesWritten;
407 if (bufferSizes[0] == 0 && bufferSizes[1] == 0) {
411 if (bufferSizes[2] == 0) {
438 len = bufferSizes[2];
446 unsigned int firstPortion = len < bufferBytesBeforeWrap ? len : bufferBytesBeforeWrap;
450 bufferHead += firstPortion;
452 data += firstPortion;
504 FREE_BLOCK_SIZE = 2048,
507 FREE_BLOCK_TEST_SIZE_INTS = 4,
508 FREE_BLOCK_TEST_SIZE_BYTES = FREE_BLOCK_TEST_SIZE_INTS *
sizeof(uint32_t),
512 uint8_t
bytes[FREE_BLOCK_TEST_SIZE_BYTES];
513 uint32_t ints[FREE_BLOCK_TEST_SIZE_INTS];
523 while (left < right) {
524 mid = (left + right) / 2;
526 if (
m25p16_readBytes(mid * FREE_BLOCK_SIZE, testBuffer.bytes, FREE_BLOCK_TEST_SIZE_BYTES) < FREE_BLOCK_TEST_SIZE_BYTES) {
533 for (i = 0; i < FREE_BLOCK_TEST_SIZE_INTS; i++) {
534 if (testBuffer.ints[i] != 0xFFFFFFFF) {
552 return result * FREE_BLOCK_SIZE;
static uint8_t flashWriteBuffer[FLASHFS_WRITE_BUFFER_SIZE]
static uint32_t flashfsTransmitBufferUsed()
uint32_t flashfsGetWriteBufferSize()
uint32_t flashfsGetOffset()
#define FLASHFS_WRITE_BUFFER_AUTO_FLUSH_LEN
uint32_t flashfsGetWriteBufferFreeSpace()
static uint8_t bufferTail
int flashfsIdentifyStartOfFreeSpace()
static uint8_t buffer[BMP280_DATA_FRAME_SIZE]
int flashfsReadAbs(uint32_t address, uint8_t *buffer, unsigned int len)
int m25p16_readBytes(uint32_t address, uint8_t *buffer, int length)
const flashGeometry_t * m25p16_getGeometry()
void flashfsEraseCompletely()
void flashfsWriteByte(uint8_t byte)
static uint8_t bufferHead
static uint32_t tailAddress
void m25p16_pageProgramContinue(const uint8_t *data, int length)
void m25p16_eraseCompletely()
static void flashfsGetDirtyDataBuffers(uint8_t const *buffers[], uint32_t bufferSizes[])
static flashGeometry_t geometry
static volatile uint8_t bytes
void flashfsSeekRel(int32_t offset)
static void flashfsSetTailAddress(uint32_t address)
static bool flashfsBufferIsEmpty()
static void flashfsAdvanceTailInBuffer(uint32_t delta)
static uint32_t flashfsWriteBuffers(uint8_t const **buffers, uint32_t *bufferSizes, int bufferCount, bool sync)
#define FLASHFS_WRITE_BUFFER_SIZE
void flashfsSeekAbs(uint32_t offset)
void flashfsEraseRange(uint32_t start, uint32_t end)
void m25p16_pageProgramBegin(uint32_t address)
#define FLASHFS_WRITE_BUFFER_USABLE
static void flashfsClearBuffer()
const flashGeometry_t * flashfsGetGeometry()
void m25p16_pageProgramFinish()
void flashfsWrite(const uint8_t *data, unsigned int len, bool sync)
uint32_t flashfsGetSize()
void m25p16_eraseSector(uint32_t address)