From 9dd8fc7445f5bd067d229329b9e2650c4f535d6d Mon Sep 17 00:00:00 2001 From: Polprzewodnikowy Date: Wed, 3 Aug 2022 14:05:54 +0200 Subject: [PATCH] little cleanup --- sw/controller/loader.mk | 3 ++- sw/controller/src/loader_main.c | 17 ++--------------- sw/controller/src/update.c | 20 ++++++++++++++++++++ sw/controller/src/update.h | 1 + 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/sw/controller/loader.mk b/sw/controller/loader.mk index 4681637..e04f1e4 100644 --- a/sw/controller/loader.mk +++ b/sw/controller/loader.mk @@ -8,6 +8,7 @@ SRC_FILES = \ fpga.c \ hw.c \ lcmxo2.c \ - loader_main.c + loader_main.c \ + update.c include common.mk diff --git a/sw/controller/src/loader_main.c b/sw/controller/src/loader_main.c index 88eb67a..66143ff 100644 --- a/sw/controller/src/loader_main.c +++ b/sw/controller/src/loader_main.c @@ -1,12 +1,10 @@ #include -#include "fpga.h" #include "hw.h" -#include "vendor.h" +#include "update.h" void loader_main (void) { uint32_t parameters[5]; - uint64_t buffer; hw_loader_get_parameters(parameters); @@ -16,18 +14,7 @@ void loader_main (void) { hw_gpio_set(GPIO_ID_LED); - if (parameters[2] != 0) { - hw_flash_erase(); - for (int i = 0; i < parameters[2]; i += sizeof(buffer)) { - fpga_mem_read(parameters[1] + i, sizeof(buffer), (uint8_t *) (&buffer)); - hw_flash_program(HW_FLASH_ADDRESS + i, buffer); - } - } - - if (parameters[4] != 0) { - vendor_update(parameters[3], parameters[4]); - vendor_reconfigure(); - } + update_perform(parameters); hw_gpio_reset(GPIO_ID_LED); diff --git a/sw/controller/src/update.c b/sw/controller/src/update.c index 8076b0f..16a1b97 100644 --- a/sw/controller/src/update.c +++ b/sw/controller/src/update.c @@ -1,7 +1,9 @@ #include +#include "fpga.h" #include "hw.h" #include "update.h" #include "usb.h" +#include "vendor.h" static uint32_t update_mcu_address; @@ -35,6 +37,24 @@ void update_start (void) { hw_loader_reset(parameters); } +void update_perform (uint32_t *parameters) { + uint64_t buffer; + + if (parameters[2] != 0) { + hw_flash_erase(); + for (int i = 0; i < parameters[2]; i += sizeof(buffer)) { + fpga_mem_read(parameters[1] + i, sizeof(buffer), (uint8_t *) (&buffer)); + hw_flash_program(HW_FLASH_ADDRESS + i, buffer); + } + } + + if (parameters[4] != 0) { + vendor_update(parameters[3], parameters[4]); + } + + vendor_reconfigure(); +} + void update_notify_done (void) { uint32_t parameters[5]; usb_tx_info_t packet; diff --git a/sw/controller/src/update.h b/sw/controller/src/update.h index cac8364..ec07bfe 100644 --- a/sw/controller/src/update.h +++ b/sw/controller/src/update.h @@ -15,6 +15,7 @@ typedef enum { uint32_t update_backup (uint32_t address); update_error_t update_prepare (uint32_t address, uint32_t length); void update_start (void); +void update_perform (uint32_t *parameters); void update_notify_done (void);