Program to update the D7A modem's firmware.
Dependencies: modem_ref_helper DebouncedInterrupt
Diff: cup.cpp
- Revision:
- 22:f2b01e5e087e
- Parent:
- 20:100143cecc41
- Child:
- 23:365775929293
- Child:
- 26:7fc24677a950
--- a/cup.cpp Fri Sep 15 15:52:44 2017 +0000 +++ b/cup.cpp Mon Sep 18 13:38:40 2017 +0000 @@ -1,13 +1,10 @@ -#include "mbed.h" #include "cup.h" #include "bin.h" -#include "crc.h" -#include "d7a.h" -#include "dbg.h" uint8_t const modem_data[CUP_DATA_SIZE] = CUP_DATA; uint8_t const bootloader_data[BOOTLOADER_DATA_SIZE] = BOOTLOADER_DATA; +Semaphore modem_cup_ready(0); cup_param_t const cup_modem = { .data = (uint8_t*)modem_data, @@ -53,6 +50,28 @@ .target_fw_minor = BOOTLOADER_TARGET_FW_MINOR, }; +void my_cup_callback(uint8_t terminal, int8_t err, uint8_t id) +{ + (void)id; + + if (terminal) + { + if (err) + { + PRINT("Done err %d\n", err); + FLUSH(); + while(1); + } + modem_cup_ready.release(); + } + else if (err) + { + PRINT("Got err %d\n", err); + FLUSH(); + while(1); + } +} + void cup_start_update(uint32_t offset, bool bootloader) { cup_cfg_t cfg = { @@ -68,6 +87,8 @@ Timer tim; int32_t rem; + uint8_t id = modem_get_id(my_cup_callback); + if (bootloader) { PRINT("Uploading Bootloader\r\n"); @@ -80,11 +101,10 @@ } rem = cup->data_size; - - //d7a_stop(); - + // Start CUP - D7A_WRITE((uint8_t*)&cfg, cup->cfg_fid, 0, 4, root_key); + modem_write_file_root(cup->cfg_fid, (uint8_t*)&cfg, 0, 4, root_key, id); + modem_cup_ready.wait(); // Upload file PRINT("Uploading %d bytes to CUP file. (offset %d)\r\n", cup->data_size, offset); @@ -94,12 +114,13 @@ while (rem > 0) { int32_t chunk = (rem > cup->local_mtu)? cup->local_mtu : rem; - D7A_WRITE(&(cup->data[fof]), cup->code_fid, fof + offset, chunk, NULL); + modem_write_file(cup->code_fid, &(cup->data[fof]), fof + offset, chunk, id); + modem_cup_ready.wait(); rem -= chunk; fof += chunk; percent = (100*fof)/cup->data_size; - if (percent != percent_old) + if (percent != percent_old && !(percent%5)) { PRINT("UPLOADING CUP FILE %3d percent\r\n", percent); percent_old = percent; @@ -113,7 +134,8 @@ PRINT("CUP: %d bytes written in %.2f sec (%.2f kB/s)\r\n", cup->data_size, time_s, (cup->data_size/time_s)/1024.0); // Force PFLASH-cache flushing - D7A_FLUSH(cup->code_fid, root_key); + modem_flush_file_root(cup->code_fid, root_key, id); + modem_cup_ready.wait(); // Send Upgrade command cfg.cmd = 0xC0D5; @@ -121,25 +143,9 @@ cfg.src_offset = offset; cfg.signature = cup->signature; - D7A_WRITE((uint8_t*)&cfg, cup->cfg_fid, 0, 12, root_key); + modem_write_file_root(cup->cfg_fid, (uint8_t*)&cfg, 0, 12, root_key, id); + modem_cup_ready.wait(); PRINT("Waiting self reboot...\r\n"); - - d7a_wait_ready(); - - - D7A_READ(&cfg, cup->cfg_fid, 0, 2, root_key); - - if (cfg.cmd) - { - PRINT("/!\\ CUP Error 0x%04X /!\\\r\n", cfg.cmd); - } - else - - { - PRINT("CUP OK\r\nResetting...\r\n\r\n"); - FLUSH(); - NVIC_SystemReset(); - } } \ No newline at end of file