@@ -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 ;
0 commit comments