Skip to content

Commit d8099f4

Browse files
committed
clean up
1 parent b9d586b commit d8099f4

File tree

5 files changed

+43
-31
lines changed

5 files changed

+43
-31
lines changed

libraries/InternalFileSytem/src/InternalFileSystem.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,23 @@ static int _internal_flash_read (const struct lfs_config *c, lfs_block_t block,
4747
{
4848
(void) c;
4949

50-
uint32_t addr = lba2addr(block) + off;
50+
uint32_t addr = lba2addr(block) + off;
5151
flash_nrf5x_read(buffer, addr, size);
5252

53-
return 0;
53+
return 0;
5454
}
5555

5656
// Program a region in a block. The block must have previously
5757
// been erased. Negative error codes are propogated to the user.
5858
// May return LFS_ERR_CORRUPT if the block should be considered bad.
59-
static int _internal_flash_prog (const struct lfs_config *c, lfs_block_t block, lfs_off_t off, const void *buffer,
60-
lfs_size_t size)
59+
static int _internal_flash_prog (const struct lfs_config *c, lfs_block_t block, lfs_off_t off, const void *buffer, lfs_size_t size)
6160
{
6261
(void) c;
6362

64-
uint32_t addr = lba2addr(block) + off;
63+
uint32_t addr = lba2addr(block) + off;
6564
flash_nrf5x_write(addr, buffer, size);
6665

67-
return 0;
66+
return 0;
6867
}
6968

7069
// Erase a block. A block must be erased before being programmed.
@@ -75,17 +74,17 @@ static int _internal_flash_erase (const struct lfs_config *c, lfs_block_t block)
7574
{
7675
(void) c;
7776

78-
uint32_t addr = lba2addr(block);
77+
uint32_t addr = lba2addr(block);
7978

80-
// implement as write 0xff to whole block address
79+
// implement as write 0xff to whole block address
8180
for(int i=0; i <LFS_BLOCK_SIZE; i++)
8281
{
8382
flash_nrf5x_write8(addr + i, 0xFF);
8483
}
8584

86-
// flash_nrf5x_flush();
85+
// flash_nrf5x_flush();
8786

88-
return 0;
87+
return 0;
8988
}
9089

9190
// Sync the state of the underlying block device. Negative error codes

libraries/InternalFileSytem/src/flash/flash_cache.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static inline uint32_t page_offset_of (uint32_t addr)
4141
return addr & (FLASH_CACHE_SIZE - 1);
4242
}
4343

44-
uint32_t flash_cache_write (flash_cache_t* fc, uint32_t dst, void const * src, uint32_t len)
44+
int flash_cache_write (flash_cache_t* fc, uint32_t dst, void const * src, uint32_t len)
4545
{
4646
uint8_t const * src8 = (uint8_t const *) src;
4747
uint32_t remain = len;
@@ -95,7 +95,7 @@ void flash_cache_flush (flash_cache_t* fc)
9595
fc->cache_addr = FLASH_CACHE_INVALID_ADDR;
9696
}
9797

98-
void flash_cache_read (flash_cache_t* fc, void* dst, uint32_t addr, uint32_t count)
98+
int flash_cache_read (flash_cache_t* fc, void* dst, uint32_t addr, uint32_t count)
9999
{
100100
// there is no check for overflow / wraparound for dst + count, addr + count.
101101
// this might be a useful thing to add for at least debug builds.
@@ -198,4 +198,6 @@ void flash_cache_read (flash_cache_t* fc, void* dst, uint32_t addr, uint32_t cou
198198
// not using the cache, so just forward to read from flash
199199
fc->read(dst, addr, count);
200200
}
201+
202+
return (int) count;
201203
}

libraries/InternalFileSytem/src/flash/flash_cache.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ typedef struct
4646
extern "C" {
4747
#endif
4848

49-
uint32_t flash_cache_write (flash_cache_t* fc, uint32_t dst, void const *src, uint32_t count);
49+
int flash_cache_write (flash_cache_t* fc, uint32_t dst, void const *src, uint32_t count);
5050
void flash_cache_flush (flash_cache_t* fc);
51-
void flash_cache_read (flash_cache_t* fc, void* dst, uint32_t addr, uint32_t count);
51+
int flash_cache_read (flash_cache_t* fc, void* dst, uint32_t addr, uint32_t count);
5252

5353
#ifdef __cplusplus
5454
}

libraries/InternalFileSytem/src/flash/flash_nrf5x.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@
2929
#include "delay.h"
3030
#include "rtos.h"
3131

32+
33+
#ifdef NRF52840_XXAA
34+
#define BOOTLOADER_ADDR 0xF4000
35+
#else
36+
#define BOOTLOADER_ADDR 0x74000
37+
#endif
38+
39+
// defined in linker script
40+
extern uint32_t __flash_arduino_start[];
41+
//extern uint32_t __flash_arduino_end[];
42+
3243
//--------------------------------------------------------------------+
3344
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
3445
//--------------------------------------------------------------------+
@@ -65,17 +76,20 @@ void flash_nrf5x_flush (void)
6576
flash_cache_flush(&_cache);
6677
}
6778

68-
uint32_t flash_nrf5x_write (uint32_t dst, void const * src, uint32_t len)
79+
int flash_nrf5x_write (uint32_t dst, void const * src, uint32_t len)
6980
{
70-
// TODO prevent write SD + bootloader region
81+
// Softdevice region
82+
VERIFY(dst >= ((uint32_t) __flash_arduino_start), -1);
83+
84+
// Bootloader region
85+
VERIFY(dst < BOOTLOADER_ADDR, -1);
86+
7187
return flash_cache_write(&_cache, dst, src, len);
7288
}
7389

74-
uint32_t flash_nrf5x_read (void* dst, uint32_t src, uint32_t len)
90+
int flash_nrf5x_read (void* dst, uint32_t src, uint32_t len)
7591
{
76-
// return cache value if available
77-
flash_cache_read(&_cache, dst, src, len);
78-
return len;
92+
return flash_cache_read(&_cache, dst, src, len);
7993
}
8094

8195
bool flash_nrf5x_erase(uint32_t addr)

libraries/InternalFileSytem/src/flash/flash_nrf5x.h

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,24 @@
3636
void flash_nrf5x_flush (void);
3737
bool flash_nrf5x_erase(uint32_t addr);
3838

39-
uint32_t flash_nrf5x_write (uint32_t dst, void const * src, uint32_t len);
40-
uint32_t flash_nrf5x_read (void* dst, uint32_t src, uint32_t len);
39+
int flash_nrf5x_write (uint32_t dst, void const * src, uint32_t len);
40+
int flash_nrf5x_read (void* dst, uint32_t src, uint32_t len);
4141

4242
//--------------------------------------------------------------------+
4343
// Write helper
4444
//--------------------------------------------------------------------+
45-
static inline uint32_t flash_nrf5x_write8 (uint32_t dst, uint8_t num)
45+
static inline int flash_nrf5x_write8 (uint32_t dst, uint8_t num)
4646
{
47-
flash_nrf5x_write(dst, &num, sizeof(num));
48-
return sizeof(num);
47+
return flash_nrf5x_write(dst, &num, sizeof(num));
4948
}
5049

51-
static inline uint32_t flash_nrf5x_write16 (uint32_t dst, uint8_t num)
50+
static inline int flash_nrf5x_write16 (uint32_t dst, uint8_t num)
5251
{
53-
flash_nrf5x_write(dst, &num, sizeof(num));
54-
return sizeof(num);
52+
return flash_nrf5x_write(dst, &num, sizeof(num));
5553
}
56-
static inline uint32_t flash_nrf5x_write32 (uint32_t dst, uint8_t num)
54+
static inline int flash_nrf5x_write32 (uint32_t dst, uint8_t num)
5755
{
58-
flash_nrf5x_write(dst, &num, sizeof(num));
59-
return sizeof(num);
56+
return flash_nrf5x_write(dst, &num, sizeof(num));
6057
}
6158

6259
//--------------------------------------------------------------------+

0 commit comments

Comments
 (0)