mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-25 09:16:07 +03:00
Improve flashfs codegen by fixing pagesize at a constant 256 bytes
This commit is contained in:
parent
cfdb1bdc56
commit
8a06849657
4 changed files with 8 additions and 16 deletions
|
@ -23,7 +23,7 @@ typedef struct flashGeometry_t {
|
|||
uint16_t sectors; // Count of the number of erasable blocks on the device
|
||||
|
||||
uint16_t pagesPerSector;
|
||||
uint16_t pageSize; // In bytes
|
||||
const uint16_t pageSize; // In bytes
|
||||
|
||||
uint32_t sectorSize; // This is just pagesPerSector * pageSize
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@
|
|||
#define SECTOR_ERASE_TIMEOUT_MILLIS 5000
|
||||
#define BULK_ERASE_TIMEOUT_MILLIS 21000
|
||||
|
||||
static flashGeometry_t geometry;
|
||||
static flashGeometry_t geometry = {.pageSize = M25P16_PAGESIZE};
|
||||
|
||||
/*
|
||||
* Whether we've performed an action that could have made the device busy for writes.
|
||||
|
@ -150,29 +150,27 @@ static bool m25p16_readIdentification()
|
|||
// Manufacturer, memory type, and capacity
|
||||
chipID = (in[1] << 16) | (in[2] << 8) | (in[3]);
|
||||
|
||||
// All supported chips use the same pagesize of 256 bytes
|
||||
|
||||
switch (chipID) {
|
||||
case JEDEC_ID_MICRON_M25P16:
|
||||
geometry.sectors = 32;
|
||||
geometry.pagesPerSector = 256;
|
||||
geometry.pageSize = 256;
|
||||
break;
|
||||
case JEDEC_ID_MICRON_N25Q064:
|
||||
case JEDEC_ID_WINBOND_W25Q64:
|
||||
geometry.sectors = 128;
|
||||
geometry.pagesPerSector = 256;
|
||||
geometry.pageSize = 256;
|
||||
break;
|
||||
case JEDEC_ID_MICRON_N25Q128:
|
||||
case JEDEC_ID_WINBOND_W25Q128:
|
||||
geometry.sectors = 256;
|
||||
geometry.pagesPerSector = 256;
|
||||
geometry.pageSize = 256;
|
||||
break;
|
||||
default:
|
||||
// Unsupported chip or not an SPI NOR flash
|
||||
geometry.sectors = 0;
|
||||
geometry.pagesPerSector = 0;
|
||||
geometry.pageSize = 0;
|
||||
|
||||
geometry.sectorSize = 0;
|
||||
geometry.totalSize = 0;
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
#include <stdint.h>
|
||||
#include "flash.h"
|
||||
|
||||
#define M25P16_PAGESIZE 256
|
||||
|
||||
bool m25p16_init();
|
||||
|
||||
void m25p16_eraseSector(uint32_t address);
|
||||
|
|
|
@ -49,8 +49,6 @@ static uint8_t bufferHead = 0, bufferTail = 0;
|
|||
|
||||
// The position of the buffer's tail in the overall flash address space:
|
||||
static uint32_t tailAddress = 0;
|
||||
// The index of the tail within the flash page it is inside
|
||||
static uint16_t tailIndexInPage = 0;
|
||||
|
||||
static void flashfsClearBuffer()
|
||||
{
|
||||
|
@ -65,10 +63,6 @@ static bool flashfsBufferIsEmpty()
|
|||
static void flashfsSetTailAddress(uint32_t address)
|
||||
{
|
||||
tailAddress = address;
|
||||
|
||||
if (m25p16_getGeometry()->pageSize > 0) {
|
||||
tailIndexInPage = tailAddress % m25p16_getGeometry()->pageSize;
|
||||
}
|
||||
}
|
||||
|
||||
void flashfsEraseCompletely()
|
||||
|
@ -154,8 +148,6 @@ static uint32_t flashfsTransmitBufferUsed()
|
|||
*/
|
||||
static uint32_t flashfsWriteBuffers(uint8_t const **buffers, uint32_t *bufferSizes, int bufferCount, bool sync)
|
||||
{
|
||||
const flashGeometry_t *geometry = m25p16_getGeometry();
|
||||
|
||||
uint32_t bytesTotal = 0;
|
||||
|
||||
int i;
|
||||
|
@ -178,8 +170,8 @@ static uint32_t flashfsWriteBuffers(uint8_t const **buffers, uint32_t *bufferSiz
|
|||
* Each page needs to be saved in a separate program operation, so
|
||||
* if we would cross a page boundary, only write up to the boundary in this iteration:
|
||||
*/
|
||||
if (tailIndexInPage + bytesTotalRemaining > geometry->pageSize) {
|
||||
bytesTotalThisIteration = geometry->pageSize - tailIndexInPage;
|
||||
if (tailAddress % M25P16_PAGESIZE + bytesTotalRemaining > M25P16_PAGESIZE) {
|
||||
bytesTotalThisIteration = M25P16_PAGESIZE - tailAddress % M25P16_PAGESIZE;
|
||||
} else {
|
||||
bytesTotalThisIteration = bytesTotalRemaining;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue