Skip to content

Commit

Permalink
pbsys/program_load: Generalize write size setter.
Browse files Browse the repository at this point in the history
We will need this when setting other data, like user data.
  • Loading branch information
laurensvalk committed Oct 21, 2022
1 parent f8856bb commit 335fe57
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
6 changes: 3 additions & 3 deletions lib/pbio/include/pbsys/program_load.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
*/
typedef struct _pbsys_program_load_data_header_t {
/**
* How much to write on shutdown. This is reset to 0 on load, and should be
* set whenever any data is updated. This must always remain the first
* element of this structure.
* How much to write on shutdown (and how much to load on boot). This is
* reset to 0 in RAM on load, and should be set whenever any data is
* updated. This must always remain the first element of this structure.
*/
uint32_t write_size;
#if PBSYS_CONFIG_PROGRAM_LOAD_OVERLAPS_BOOTLOADER_CHECKSUM
Expand Down
14 changes: 12 additions & 2 deletions lib/pbio/sys/program_load.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ typedef struct {
data_map_t pbsys_user_ram_data_map __attribute__((section(".noinit"), used));
static data_map_t *map = &pbsys_user_ram_data_map;

/**
* Sets write size to how much data must be written on shutdown. This is not
* simply a boolean flag because it is also used as the load size on boot.
*/
static void update_write_size(void) {
map->header.write_size = sizeof(pbsys_program_load_data_header_t) + map->header.program_size;
}

static bool pbsys_program_load_start_user_program_requested;
static bool pbsys_program_load_start_repl_requested;

Expand Down Expand Up @@ -87,9 +95,11 @@ pbio_error_t pbsys_program_load_set_program_size(uint32_t size) {
return PBIO_ERROR_BUSY;
}

// Update program size.
map->header.program_size = size;
// Data was updated, so set the write size.
map->header.write_size = size + sizeof(pbsys_program_load_data_header_t);

// Program size was updated, so set the write size.
update_write_size();

return PBIO_SUCCESS;
}
Expand Down

0 comments on commit 335fe57

Please sign in to comment.