Skip to content

Commit 16401c7

Browse files
committed
pbsys/program_load: Generalize write size setter.
We will need this when setting other data, like user data.
1 parent f8856bb commit 16401c7

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

lib/pbio/include/pbsys/program_load.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
*/
2929
typedef struct _pbsys_program_load_data_header_t {
3030
/**
31-
* How much to write on shutdown. This is reset to 0 on load, and should be
32-
* set whenever any data is updated. This must always remain the first
33-
* element of this structure.
31+
* How much to write on shutdown (and how much to load on boot). This is
32+
* reset to 0 in RAM on load, and should be set whenever any data is
33+
* updated. This must always remain the first element of this structure.
3434
*/
3535
uint32_t write_size;
3636
#if PBSYS_CONFIG_PROGRAM_LOAD_OVERLAPS_BOOTLOADER_CHECKSUM

lib/pbio/sys/program_load.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ typedef struct {
3838
data_map_t pbsys_user_ram_data_map __attribute__((section(".noinit"), used));
3939
static data_map_t *map = &pbsys_user_ram_data_map;
4040

41+
/**
42+
* Sets write size to how much data must be written on shutdown. This is not
43+
* simply a boolean flag because it is also used as the load size on boot.
44+
*/
45+
static void update_write_size(void) {
46+
map->header.write_size = sizeof(pbsys_program_load_data_header_t) + map->header.program_size;
47+
}
48+
4149
static bool pbsys_program_load_start_user_program_requested;
4250
static bool pbsys_program_load_start_repl_requested;
4351

@@ -87,9 +95,11 @@ pbio_error_t pbsys_program_load_set_program_size(uint32_t size) {
8795
return PBIO_ERROR_BUSY;
8896
}
8997

98+
// Update program size.
9099
map->header.program_size = size;
91-
// Data was updated, so set the write size.
92-
map->header.write_size = size + sizeof(pbsys_program_load_data_header_t);
100+
101+
// Program size was updated, so set the write size.
102+
update_write_size();
93103

94104
return PBIO_SUCCESS;
95105
}

0 commit comments

Comments
 (0)