Skip to content

Commit cc5a940

Browse files
committed
drivers/memory/spiflash: Rename functions to indicate they use cache.
This patch renames the existing SPI flash API functions to reflect the fact that the go through the cache: mp_spiflash_flush -> mp_spiflash_cache_flush mp_spiflash_read -> mp_spiflash_cached_read mp_spiflash_write -> mp_spiflash_cached_write
1 parent 335d26b commit cc5a940

File tree

3 files changed

+23
-18
lines changed

3 files changed

+23
-18
lines changed

drivers/memory/spiflash.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,10 @@ STATIC int mp_spiflash_write_page(mp_spiflash_t *self, uint32_t addr, const uint
221221
return mp_spiflash_wait_wip0(self);
222222
}
223223

224-
void mp_spiflash_read(mp_spiflash_t *self, uint32_t addr, size_t len, uint8_t *dest) {
224+
/******************************************************************************/
225+
// Interface functions that use the cache
226+
227+
void mp_spiflash_cached_read(mp_spiflash_t *self, uint32_t addr, size_t len, uint8_t *dest) {
225228
if (len == 0) {
226229
return;
227230
}
@@ -261,7 +264,7 @@ void mp_spiflash_read(mp_spiflash_t *self, uint32_t addr, size_t len, uint8_t *d
261264
mp_spiflash_release_bus(self);
262265
}
263266

264-
STATIC void mp_spiflash_flush_internal(mp_spiflash_t *self) {
267+
STATIC void mp_spiflash_cache_flush_internal(mp_spiflash_t *self) {
265268
#if USE_WR_DELAY
266269
if (!(self->flags & 1)) {
267270
return;
@@ -287,21 +290,21 @@ STATIC void mp_spiflash_flush_internal(mp_spiflash_t *self) {
287290
#endif
288291
}
289292

290-
void mp_spiflash_flush(mp_spiflash_t *self) {
293+
void mp_spiflash_cache_flush(mp_spiflash_t *self) {
291294
mp_spiflash_acquire_bus(self);
292-
mp_spiflash_flush_internal(self);
295+
mp_spiflash_cache_flush_internal(self);
293296
mp_spiflash_release_bus(self);
294297
}
295298

296-
STATIC int mp_spiflash_write_part(mp_spiflash_t *self, uint32_t addr, size_t len, const uint8_t *src) {
299+
STATIC int mp_spiflash_cached_write_part(mp_spiflash_t *self, uint32_t addr, size_t len, const uint8_t *src) {
297300
// Align to 4096 sector
298301
uint32_t offset = addr & 0xfff;
299302
uint32_t sec = addr >> 12;
300303
addr = sec << 12;
301304

302305
// Restriction for now, so we don't need to erase multiple pages
303306
if (offset + len > SECTOR_SIZE) {
304-
printf("mp_spiflash_write_part: len is too large\n");
307+
printf("mp_spiflash_cached_write_part: len is too large\n");
305308
return -MP_EIO;
306309
}
307310

@@ -310,7 +313,7 @@ STATIC int mp_spiflash_write_part(mp_spiflash_t *self, uint32_t addr, size_t len
310313
// Acquire the sector buffer
311314
if (cache->user != self) {
312315
if (cache->user != NULL) {
313-
mp_spiflash_flush(cache->user);
316+
mp_spiflash_cache_flush(cache->user);
314317
}
315318
cache->user = self;
316319
cache->block = 0xffffffff;
@@ -320,7 +323,7 @@ STATIC int mp_spiflash_write_part(mp_spiflash_t *self, uint32_t addr, size_t len
320323
// Read sector
321324
#if USE_WR_DELAY
322325
if (cache->block != 0xffffffff) {
323-
mp_spiflash_flush_internal(self);
326+
mp_spiflash_cache_flush_internal(self);
324327
}
325328
#endif
326329
mp_spiflash_read_data(self, addr, SECTOR_SIZE, cache->buf);
@@ -372,7 +375,7 @@ STATIC int mp_spiflash_write_part(mp_spiflash_t *self, uint32_t addr, size_t len
372375
return 0; // success
373376
}
374377

375-
int mp_spiflash_write(mp_spiflash_t *self, uint32_t addr, size_t len, const uint8_t *src) {
378+
int mp_spiflash_cached_write(mp_spiflash_t *self, uint32_t addr, size_t len, const uint8_t *src) {
376379
uint32_t bis = addr / SECTOR_SIZE;
377380
uint32_t bie = (addr + len - 1) / SECTOR_SIZE;
378381

@@ -407,7 +410,7 @@ int mp_spiflash_write(mp_spiflash_t *self, uint32_t addr, size_t len, const uint
407410
if (rest == 0) {
408411
rest = SECTOR_SIZE;
409412
}
410-
int ret = mp_spiflash_write_part(self, addr, rest, src);
413+
int ret = mp_spiflash_cached_write_part(self, addr, rest, src);
411414
if (ret != 0) {
412415
mp_spiflash_release_bus(self);
413416
return ret;
@@ -428,7 +431,7 @@ int mp_spiflash_write(mp_spiflash_t *self, uint32_t addr, size_t len, const uint
428431
if (rest > len) {
429432
rest = len;
430433
}
431-
int ret = mp_spiflash_write_part(self, addr, rest, src);
434+
int ret = mp_spiflash_cached_write_part(self, addr, rest, src);
432435
if (ret != 0) {
433436
mp_spiflash_release_bus(self);
434437
return ret;

drivers/memory/spiflash.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ typedef struct _mp_spiflash_t {
6868
} mp_spiflash_t;
6969

7070
void mp_spiflash_init(mp_spiflash_t *self);
71-
void mp_spiflash_flush(mp_spiflash_t *self);
72-
void mp_spiflash_read(mp_spiflash_t *self, uint32_t addr, size_t len, uint8_t *dest);
73-
int mp_spiflash_write(mp_spiflash_t *self, uint32_t addr, size_t len, const uint8_t *src);
71+
72+
// These functions use the cache (which must already be configured)
73+
void mp_spiflash_cache_flush(mp_spiflash_t *self);
74+
void mp_spiflash_cached_read(mp_spiflash_t *self, uint32_t addr, size_t len, uint8_t *dest);
75+
int mp_spiflash_cached_write(mp_spiflash_t *self, uint32_t addr, size_t len, const uint8_t *src);
7476

7577
#endif // MICROPY_INCLUDED_DRIVERS_MEMORY_SPIFLASH_H

ports/stm32/spibdev.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ int32_t spi_bdev_ioctl(spi_bdev_t *bdev, uint32_t op, uint32_t arg) {
4242

4343
case BDEV_IOCTL_IRQ_HANDLER:
4444
if ((bdev->spiflash.flags & 1) && HAL_GetTick() - bdev->flash_tick_counter_last_write >= 1000) {
45-
mp_spiflash_flush(&bdev->spiflash);
45+
mp_spiflash_cache_flush(&bdev->spiflash);
4646
led_state(PYB_LED_RED, 0); // indicate a clean cache with LED off
4747
}
4848
return 0;
@@ -51,7 +51,7 @@ int32_t spi_bdev_ioctl(spi_bdev_t *bdev, uint32_t op, uint32_t arg) {
5151
if (bdev->spiflash.flags & 1) {
5252
// we must disable USB irqs to prevent MSC contention with SPI flash
5353
uint32_t basepri = raise_irq_pri(IRQ_PRI_OTG_FS);
54-
mp_spiflash_flush(&bdev->spiflash);
54+
mp_spiflash_cache_flush(&bdev->spiflash);
5555
led_state(PYB_LED_RED, 0); // indicate a clean cache with LED off
5656
restore_irq_pri(basepri);
5757
}
@@ -63,7 +63,7 @@ int32_t spi_bdev_ioctl(spi_bdev_t *bdev, uint32_t op, uint32_t arg) {
6363
int spi_bdev_readblocks(spi_bdev_t *bdev, uint8_t *dest, uint32_t block_num, uint32_t num_blocks) {
6464
// we must disable USB irqs to prevent MSC contention with SPI flash
6565
uint32_t basepri = raise_irq_pri(IRQ_PRI_OTG_FS);
66-
mp_spiflash_read(&bdev->spiflash, block_num * FLASH_BLOCK_SIZE, num_blocks * FLASH_BLOCK_SIZE, dest);
66+
mp_spiflash_cached_read(&bdev->spiflash, block_num * FLASH_BLOCK_SIZE, num_blocks * FLASH_BLOCK_SIZE, dest);
6767
restore_irq_pri(basepri);
6868

6969
return 0;
@@ -72,7 +72,7 @@ int spi_bdev_readblocks(spi_bdev_t *bdev, uint8_t *dest, uint32_t block_num, uin
7272
int spi_bdev_writeblocks(spi_bdev_t *bdev, const uint8_t *src, uint32_t block_num, uint32_t num_blocks) {
7373
// we must disable USB irqs to prevent MSC contention with SPI flash
7474
uint32_t basepri = raise_irq_pri(IRQ_PRI_OTG_FS);
75-
int ret = mp_spiflash_write(&bdev->spiflash, block_num * FLASH_BLOCK_SIZE, num_blocks * FLASH_BLOCK_SIZE, src);
75+
int ret = mp_spiflash_cached_write(&bdev->spiflash, block_num * FLASH_BLOCK_SIZE, num_blocks * FLASH_BLOCK_SIZE, src);
7676
if (bdev->spiflash.flags & 1) {
7777
led_state(PYB_LED_RED, 1); // indicate a dirty cache with LED on
7878
bdev->flash_tick_counter_last_write = HAL_GetTick();

0 commit comments

Comments
 (0)