Helper library to use modem_ref driver.

Dependencies:   WizziCom WizziDebug ram_fs modem_ref

Dependents:   D7A_Localisation D7A_1x_demo_send_file_data_and_forget D7A_1x_demo_CodeUpgradeProtocol D7A_1x_demo_LoRaWAN ... more

Committer:
Jeej
Date:
Thu Mar 10 09:40:29 2022 +0000
Revision:
87:ae859849b6b4
Parent:
75:dad2f09cb870
Increase cb stack size

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jeej 75:dad2f09cb870 1 #include "DebouncedInterrupt.h"
Jeej 75:dad2f09cb870 2 #include "modem_cup.h"
Jeej 75:dad2f09cb870 3
Jeej 75:dad2f09cb870 4 // Semaphore for notifiying button presses
Jeej 75:dad2f09cb870 5 static Semaphore button_user(0);
Jeej 75:dad2f09cb870 6 static Semaphore boot(0);
Jeej 75:dad2f09cb870 7
Jeej 75:dad2f09cb870 8 uint8_t const modem_data[CUP_DATA_SIZE] = CUP_DATA;
Jeej 75:dad2f09cb870 9 uint8_t const libex_data[LIBEX_DATA_SIZE] = LIBEX_DATA;
Jeej 75:dad2f09cb870 10 uint8_t const bootloader_data[BOOTLOADER_DATA_SIZE] = BOOTLOADER_DATA;
Jeej 75:dad2f09cb870 11
Jeej 75:dad2f09cb870 12 // Interrupt Service Routine on button press.
Jeej 75:dad2f09cb870 13 static void button_push_isr( void )
Jeej 75:dad2f09cb870 14 {
Jeej 75:dad2f09cb870 15 button_user.release();
Jeej 75:dad2f09cb870 16 }
Jeej 75:dad2f09cb870 17
Jeej 75:dad2f09cb870 18 static void cup_boot(u8 cause, u16 number)
Jeej 75:dad2f09cb870 19 {
Jeej 75:dad2f09cb870 20 PRINT("Modem BOOT[%c] #%d\r\n", cause, number);
Jeej 75:dad2f09cb870 21 boot.release();
Jeej 75:dad2f09cb870 22 }
Jeej 75:dad2f09cb870 23
Jeej 75:dad2f09cb870 24 cup_param_t const cup_modem = {
Jeej 75:dad2f09cb870 25 .data = (uint8_t*)modem_data,
Jeej 75:dad2f09cb870 26 .cfg_fid = CUP_CFG_FID,
Jeej 75:dad2f09cb870 27 .code_fid = CUP_CODE_FID,
Jeej 75:dad2f09cb870 28 .code_size = CUP_CODE_SIZE,
Jeej 75:dad2f09cb870 29 .data_size = CUP_DATA_SIZE,
Jeej 75:dad2f09cb870 30 .local_mtu = CUP_LOCAL_MTU,
Jeej 75:dad2f09cb870 31 .nb_archives = CUP_NB_ARCHIVES,
Jeej 75:dad2f09cb870 32 .signature = CUP_SIGNATURE,
Jeej 75:dad2f09cb870 33 .mfg_id = CUP_MFG_ID,
Jeej 75:dad2f09cb870 34 .dev_id = CUP_DEV_ID,
Jeej 75:dad2f09cb870 35 .hw_id = CUP_HW_ID,
Jeej 75:dad2f09cb870 36 .fw_major = CUP_FW_MAJOR,
Jeej 75:dad2f09cb870 37 .fw_minor = CUP_FW_MINOR,
Jeej 75:dad2f09cb870 38 .fw_patch = CUP_FW_PATCH,
Jeej 75:dad2f09cb870 39 .fw_hash = CUP_FW_HASH,
Jeej 75:dad2f09cb870 40 .target_fw_major = CUP_TARGET_FW_MAJOR,
Jeej 75:dad2f09cb870 41 .target_fw_minor = CUP_TARGET_FW_MINOR,
Jeej 75:dad2f09cb870 42 .target_fw_patch = 0,
Jeej 75:dad2f09cb870 43 .target_fw_hash = 0,
Jeej 75:dad2f09cb870 44 };
Jeej 75:dad2f09cb870 45
Jeej 75:dad2f09cb870 46 cup_param_t const cup_libex = {
Jeej 75:dad2f09cb870 47 .data = (uint8_t*)libex_data,
Jeej 75:dad2f09cb870 48 .cfg_fid = CUP_CFG_FID,
Jeej 75:dad2f09cb870 49 .code_fid = CUP_CODE_FID,
Jeej 75:dad2f09cb870 50 .code_size = CUP_CODE_SIZE,
Jeej 75:dad2f09cb870 51 .data_size = LIBEX_DATA_SIZE,
Jeej 75:dad2f09cb870 52 .local_mtu = CUP_LOCAL_MTU,
Jeej 75:dad2f09cb870 53 .nb_archives = 1,
Jeej 75:dad2f09cb870 54 .signature = LIBEX_SIGNATURE,
Jeej 75:dad2f09cb870 55 .mfg_id = CUP_MFG_ID,
Jeej 75:dad2f09cb870 56 .dev_id = CUP_DEV_ID,
Jeej 75:dad2f09cb870 57 .hw_id = CUP_HW_ID,
Jeej 75:dad2f09cb870 58 .fw_major = CUP_FW_MAJOR,
Jeej 75:dad2f09cb870 59 .fw_minor = CUP_FW_MINOR,
Jeej 75:dad2f09cb870 60 .fw_patch = CUP_FW_PATCH,
Jeej 75:dad2f09cb870 61 .fw_hash = CUP_FW_HASH,
Jeej 75:dad2f09cb870 62 .target_fw_major = CUP_FW_MAJOR,
Jeej 75:dad2f09cb870 63 .target_fw_minor = CUP_FW_MINOR,
Jeej 75:dad2f09cb870 64 .target_fw_patch = CUP_FW_PATCH,
Jeej 75:dad2f09cb870 65 .target_fw_hash = CUP_FW_HASH,
Jeej 75:dad2f09cb870 66 };
Jeej 75:dad2f09cb870 67
Jeej 75:dad2f09cb870 68 cup_param_t const cup_bootloader = {
Jeej 75:dad2f09cb870 69 .data = (uint8_t*)bootloader_data,
Jeej 75:dad2f09cb870 70 .cfg_fid = BOOTLOADER_CFG_FID,
Jeej 75:dad2f09cb870 71 .code_fid = BOOTLOADER_CODE_FID,
Jeej 75:dad2f09cb870 72 .code_size = BOOTLOADER_CODE_SIZE,
Jeej 75:dad2f09cb870 73 .data_size = BOOTLOADER_DATA_SIZE,
Jeej 75:dad2f09cb870 74 .local_mtu = BOOTLOADER_LOCAL_MTU,
Jeej 75:dad2f09cb870 75 .nb_archives = BOOTLOADER_NB_ARCHIVES,
Jeej 75:dad2f09cb870 76 .signature = BOOTLOADER_SIGNATURE,
Jeej 75:dad2f09cb870 77 .mfg_id = BOOTLOADER_MFG_ID,
Jeej 75:dad2f09cb870 78 .dev_id = BOOTLOADER_DEV_ID,
Jeej 75:dad2f09cb870 79 .hw_id = BOOTLOADER_HW_ID,
Jeej 75:dad2f09cb870 80 .fw_major = BOOTLOADER_FW_MAJOR,
Jeej 75:dad2f09cb870 81 .fw_minor = BOOTLOADER_FW_MINOR,
Jeej 75:dad2f09cb870 82 .fw_patch = BOOTLOADER_FW_PATCH,
Jeej 75:dad2f09cb870 83 .fw_hash = BOOTLOADER_FW_HASH,
Jeej 75:dad2f09cb870 84 .target_fw_major = BOOTLOADER_TARGET_FW_MAJOR,
Jeej 75:dad2f09cb870 85 .target_fw_minor = BOOTLOADER_TARGET_FW_MINOR,
Jeej 75:dad2f09cb870 86 };
Jeej 75:dad2f09cb870 87
Jeej 75:dad2f09cb870 88 static void modem_cup_start_update(uint32_t offset, cup_param_t* cup)
Jeej 75:dad2f09cb870 89 {
Jeej 75:dad2f09cb870 90 cup_cfg_t cfg = {
Jeej 75:dad2f09cb870 91 .cmd = 0x10AD,
Jeej 75:dad2f09cb870 92 .arch_nb = 20,
Jeej 75:dad2f09cb870 93 };
Jeej 75:dad2f09cb870 94
Jeej 75:dad2f09cb870 95 uint32_t fof = 0;
Jeej 75:dad2f09cb870 96 uint8_t percent = 0;
Jeej 75:dad2f09cb870 97 uint8_t percent_old = 255;
Jeej 75:dad2f09cb870 98 Timer tim;
Jeej 75:dad2f09cb870 99 int32_t rem;
Jeej 75:dad2f09cb870 100 float now = 0;
Jeej 75:dad2f09cb870 101
Jeej 75:dad2f09cb870 102 float speed_before = 0;
Jeej 75:dad2f09cb870 103 float speed = 0;
Jeej 75:dad2f09cb870 104 int speed_data = 0;
Jeej 75:dad2f09cb870 105
Jeej 75:dad2f09cb870 106 float time_before = 0;
Jeej 75:dad2f09cb870 107 float time_left = 0;
Jeej 75:dad2f09cb870 108
Jeej 75:dad2f09cb870 109 float print_before = 0;
Jeej 75:dad2f09cb870 110
Jeej 75:dad2f09cb870 111 rem = cup->data_size;
Jeej 75:dad2f09cb870 112
Jeej 75:dad2f09cb870 113 // Start CUP
Jeej 75:dad2f09cb870 114 modem_write_file(cup->cfg_fid, (uint8_t*)&cfg, 0, 4);
Jeej 75:dad2f09cb870 115
Jeej 75:dad2f09cb870 116 // Upload file
Jeej 75:dad2f09cb870 117 PRINT("Uploading %d bytes to CUP file. (offset %d)\r\n", cup->data_size, offset);
Jeej 75:dad2f09cb870 118
Jeej 75:dad2f09cb870 119 tim.start();
Jeej 75:dad2f09cb870 120
Jeej 75:dad2f09cb870 121 while (rem > 0)
Jeej 75:dad2f09cb870 122 {
Jeej 75:dad2f09cb870 123 int32_t chunk = (rem > cup->local_mtu)? cup->local_mtu : rem;
Jeej 75:dad2f09cb870 124 modem_write_file(cup->code_fid, &(cup->data[fof]), fof + offset, chunk);
Jeej 75:dad2f09cb870 125 rem -= chunk;
Jeej 75:dad2f09cb870 126 fof += chunk;
Jeej 75:dad2f09cb870 127
Jeej 75:dad2f09cb870 128 now = tim.read();
Jeej 75:dad2f09cb870 129 speed_data += chunk;
Jeej 75:dad2f09cb870 130
Jeej 75:dad2f09cb870 131 // Update speed
Jeej 75:dad2f09cb870 132 if (now - speed_before > 1.0 || speed_before == 0)
Jeej 75:dad2f09cb870 133 {
Jeej 75:dad2f09cb870 134 speed = (speed_data/(now - speed_before))/1024.0;
Jeej 75:dad2f09cb870 135 speed_before = now;
Jeej 75:dad2f09cb870 136 speed_data = 0;
Jeej 75:dad2f09cb870 137 }
Jeej 75:dad2f09cb870 138
Jeej 75:dad2f09cb870 139 // Update time left
Jeej 75:dad2f09cb870 140 if (now - time_before > 0.2 || time_before == 0 || rem == 0)
Jeej 75:dad2f09cb870 141 {
Jeej 75:dad2f09cb870 142 time_before = now;
Jeej 75:dad2f09cb870 143 time_left = (rem / speed) / 1024.0;
Jeej 75:dad2f09cb870 144 }
Jeej 75:dad2f09cb870 145
Jeej 75:dad2f09cb870 146 // Print
Jeej 75:dad2f09cb870 147 if (now - print_before > 0.1 || print_before == 0 || rem == 0)
Jeej 75:dad2f09cb870 148 {
Jeej 75:dad2f09cb870 149 percent = (100*fof)/cup->data_size;
Jeej 75:dad2f09cb870 150 print_before = now;
Jeej 75:dad2f09cb870 151 PRINT("\rUPLOADING NEW FIRMWARE %d/%d (%3d%%) %.2f kB/s %.0fs ", fof, cup->data_size, percent, speed, time_left);
Jeej 75:dad2f09cb870 152 }
Jeej 75:dad2f09cb870 153 }
Jeej 75:dad2f09cb870 154
Jeej 75:dad2f09cb870 155 PRINT("\n");
Jeej 75:dad2f09cb870 156
Jeej 75:dad2f09cb870 157 float time_s = tim.read();
Jeej 75:dad2f09cb870 158 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);
Jeej 75:dad2f09cb870 159
Jeej 75:dad2f09cb870 160 // Force PFLASH-cache flushing
Jeej 75:dad2f09cb870 161 modem_flush_file(cup->code_fid);
Jeej 75:dad2f09cb870 162
Jeej 75:dad2f09cb870 163 // Send Upgrade command
Jeej 75:dad2f09cb870 164 cfg.cmd = 0xC0D5;
Jeej 75:dad2f09cb870 165 cfg.arch_nb = cup->nb_archives;
Jeej 75:dad2f09cb870 166 cfg.src_offset = offset;
Jeej 75:dad2f09cb870 167 cfg.signature = cup->signature;
Jeej 75:dad2f09cb870 168
Jeej 75:dad2f09cb870 169 modem_write_file(cup->cfg_fid, (uint8_t*)&cfg, 0, 12);
Jeej 75:dad2f09cb870 170
Jeej 75:dad2f09cb870 171 PRINT("Waiting self reboot...\r\n");
Jeej 75:dad2f09cb870 172
Jeej 75:dad2f09cb870 173 boot.acquire();
Jeej 75:dad2f09cb870 174 }
Jeej 75:dad2f09cb870 175
Jeej 75:dad2f09cb870 176 static uint8_t check_parameter(const char* str, uint32_t param1, uint32_t param2)
Jeej 75:dad2f09cb870 177 {
Jeej 75:dad2f09cb870 178 PRINT("Checking %s ", str);
Jeej 75:dad2f09cb870 179 if (param1 != param2)
Jeej 75:dad2f09cb870 180 {
Jeej 75:dad2f09cb870 181 PRINT("Failed. (0x%08X != 0x%08X)\r\n", param1, param2);
Jeej 75:dad2f09cb870 182 return 1;
Jeej 75:dad2f09cb870 183 }
Jeej 75:dad2f09cb870 184 else
Jeej 75:dad2f09cb870 185 {
Jeej 75:dad2f09cb870 186 PRINT("OK. (0x%08X)\r\n", param1);
Jeej 75:dad2f09cb870 187 return 0;
Jeej 75:dad2f09cb870 188 }
Jeej 75:dad2f09cb870 189 }
Jeej 75:dad2f09cb870 190
Jeej 75:dad2f09cb870 191 static void print_check_rev(void)
Jeej 75:dad2f09cb870 192 {
Jeej 75:dad2f09cb870 193 PRINT("\r\n"
Jeej 75:dad2f09cb870 194 "/!\\ Please, check that you are at the right commit in the mbed revision tree /!\\\r\n"
Jeej 75:dad2f09cb870 195 );
Jeej 75:dad2f09cb870 196 }
Jeej 75:dad2f09cb870 197
Jeej 75:dad2f09cb870 198 static void print_check_hardware(void)
Jeej 75:dad2f09cb870 199 {
Jeej 75:dad2f09cb870 200 PRINT("Please, check that you chose the right Hardware in bin.h\r\n");
Jeej 75:dad2f09cb870 201 }
Jeej 75:dad2f09cb870 202
Jeej 75:dad2f09cb870 203 static int32_t check_slack(uint32_t cup_max_size, uint32_t cup_data_size)
Jeej 75:dad2f09cb870 204 {
Jeej 75:dad2f09cb870 205 //PRINT("key: %d data: %d code: %d src: %d\r\n", cup_cfg->key, cup->data_size, cup->code_size, cup_cfg->src_offset);
Jeej 75:dad2f09cb870 206 PRINT("Checking CUP Slack... ");
Jeej 75:dad2f09cb870 207
Jeej 75:dad2f09cb870 208 //int32_t data_size = (((cup->data_size/256)+1)*256);
Jeej 75:dad2f09cb870 209 int32_t cup_slack = cup_max_size - cup_data_size;
Jeej 75:dad2f09cb870 210
Jeej 75:dad2f09cb870 211 cup_slack = ((cup_slack/256)*256);
Jeej 75:dad2f09cb870 212
Jeej 75:dad2f09cb870 213 if (cup_slack < 0)
Jeej 75:dad2f09cb870 214 {
Jeej 75:dad2f09cb870 215 PRINT("Failed. (%d bytes short)\r\n", -cup_slack);
Jeej 75:dad2f09cb870 216 }
Jeej 75:dad2f09cb870 217 else
Jeej 75:dad2f09cb870 218 {
Jeej 75:dad2f09cb870 219 PRINT("OK. (%d bytes)\r\n", cup_slack);
Jeej 75:dad2f09cb870 220 }
Jeej 75:dad2f09cb870 221
Jeej 75:dad2f09cb870 222 return cup_slack;
Jeej 75:dad2f09cb870 223 }
Jeej 75:dad2f09cb870 224
Jeej 75:dad2f09cb870 225 static int modem_cup_check(revision_t* rev, cup_param_t* cup)
Jeej 75:dad2f09cb870 226 {
Jeej 75:dad2f09cb870 227 int cup_slack = -1;
Jeej 75:dad2f09cb870 228
Jeej 75:dad2f09cb870 229 do
Jeej 75:dad2f09cb870 230 {
Jeej 75:dad2f09cb870 231 // Check modem revision
Jeej 75:dad2f09cb870 232 if (check_parameter("Manufacturer ID... ", rev->manufacturer_id, cup->mfg_id))
Jeej 75:dad2f09cb870 233 {
Jeej 75:dad2f09cb870 234 print_check_rev();
Jeej 75:dad2f09cb870 235 break;
Jeej 75:dad2f09cb870 236 }
Jeej 75:dad2f09cb870 237
Jeej 75:dad2f09cb870 238 if (check_parameter("Hardware version... ", rev->hw_version, cup->hw_id))
Jeej 75:dad2f09cb870 239 {
Jeej 75:dad2f09cb870 240 print_check_hardware();
Jeej 75:dad2f09cb870 241 break;
Jeej 75:dad2f09cb870 242 }
Jeej 75:dad2f09cb870 243
Jeej 75:dad2f09cb870 244 if (rev->device_id != cup->dev_id)
Jeej 75:dad2f09cb870 245 {
Jeej 75:dad2f09cb870 246 // Update bootloader
Jeej 75:dad2f09cb870 247 PRINT("\r\n"
Jeej 75:dad2f09cb870 248 "/!\\ Not a modem firmware. /!\\\r\n"
Jeej 75:dad2f09cb870 249 );
Jeej 75:dad2f09cb870 250 break;
Jeej 75:dad2f09cb870 251 }
Jeej 75:dad2f09cb870 252 else
Jeej 75:dad2f09cb870 253 {
Jeej 75:dad2f09cb870 254 // Update modem
Jeej 75:dad2f09cb870 255 if (check_parameter("Device ID... ", rev->device_id, cup->dev_id))
Jeej 75:dad2f09cb870 256 {
Jeej 75:dad2f09cb870 257 print_check_rev();
Jeej 75:dad2f09cb870 258 break;
Jeej 75:dad2f09cb870 259 }
Jeej 75:dad2f09cb870 260
Jeej 75:dad2f09cb870 261 if (&cup_libex != cup)
Jeej 75:dad2f09cb870 262 {
Jeej 75:dad2f09cb870 263 PRINT("Checking Firmware version major... ");
Jeej 75:dad2f09cb870 264 if (rev->fw_version.major < cup->target_fw_major)
Jeej 75:dad2f09cb870 265 {
Jeej 75:dad2f09cb870 266 PRINT("Failed. (0x%08X != 0x%08X)\r\n", rev->fw_version.major, cup->target_fw_major);
Jeej 75:dad2f09cb870 267 print_check_rev();
Jeej 75:dad2f09cb870 268 break;
Jeej 75:dad2f09cb870 269 }
Jeej 75:dad2f09cb870 270 else
Jeej 75:dad2f09cb870 271 {
Jeej 75:dad2f09cb870 272 PRINT("OK. (0x%08X)\r\n", rev->fw_version.major);
Jeej 75:dad2f09cb870 273 }
Jeej 75:dad2f09cb870 274
Jeej 75:dad2f09cb870 275 PRINT("Checking Firmware version minor... ");
Jeej 75:dad2f09cb870 276 if (rev->fw_version.minor < cup->target_fw_minor && rev->fw_version.major == cup->target_fw_major)
Jeej 75:dad2f09cb870 277 {
Jeej 75:dad2f09cb870 278 PRINT("Failed. (0x%08X != 0x%08X)\r\n", rev->fw_version.minor, cup->target_fw_minor);
Jeej 75:dad2f09cb870 279 print_check_rev();
Jeej 75:dad2f09cb870 280 break;
Jeej 75:dad2f09cb870 281 }
Jeej 75:dad2f09cb870 282 else
Jeej 75:dad2f09cb870 283 {
Jeej 75:dad2f09cb870 284 PRINT("OK. (0x%08X)\r\n", rev->fw_version.minor);
Jeej 75:dad2f09cb870 285 }
Jeej 75:dad2f09cb870 286 }
Jeej 75:dad2f09cb870 287 else
Jeej 75:dad2f09cb870 288 {
Jeej 75:dad2f09cb870 289 if (check_parameter("Firmware version major...", rev->fw_version.major, cup->target_fw_major))
Jeej 75:dad2f09cb870 290 {
Jeej 75:dad2f09cb870 291 print_check_rev();
Jeej 75:dad2f09cb870 292 break;
Jeej 75:dad2f09cb870 293 }
Jeej 75:dad2f09cb870 294
Jeej 75:dad2f09cb870 295 if (check_parameter("Firmware version minor...", rev->fw_version.minor, cup->target_fw_minor))
Jeej 75:dad2f09cb870 296 {
Jeej 75:dad2f09cb870 297 print_check_rev();
Jeej 75:dad2f09cb870 298 break;
Jeej 75:dad2f09cb870 299 }
Jeej 75:dad2f09cb870 300
Jeej 75:dad2f09cb870 301 if (check_parameter("Firmware version patch...", rev->fw_version.patch, cup->target_fw_patch))
Jeej 75:dad2f09cb870 302 {
Jeej 75:dad2f09cb870 303 print_check_rev();
Jeej 75:dad2f09cb870 304 break;
Jeej 75:dad2f09cb870 305 }
Jeej 75:dad2f09cb870 306
Jeej 75:dad2f09cb870 307 if (check_parameter("Firmware version hash... ", rev->fw_version.hash, cup->target_fw_hash))
Jeej 75:dad2f09cb870 308 {
Jeej 75:dad2f09cb870 309 print_check_rev();
Jeej 75:dad2f09cb870 310 break;
Jeej 75:dad2f09cb870 311 }
Jeej 75:dad2f09cb870 312 }
Jeej 75:dad2f09cb870 313
Jeej 75:dad2f09cb870 314 cup_slack = check_slack(rev->cup_max_size, cup->data_size);
Jeej 75:dad2f09cb870 315
Jeej 75:dad2f09cb870 316 if (cup_slack < 0)
Jeej 75:dad2f09cb870 317 {
Jeej 75:dad2f09cb870 318 PRINT("\r\n"
Jeej 75:dad2f09cb870 319 "/!\\ Not enough space for modem firmware binary. /!\\\r\n"
Jeej 75:dad2f09cb870 320 "\r\n"
Jeej 75:dad2f09cb870 321 );
Jeej 75:dad2f09cb870 322 break;
Jeej 75:dad2f09cb870 323 }
Jeej 75:dad2f09cb870 324 }
Jeej 75:dad2f09cb870 325
Jeej 75:dad2f09cb870 326 return cup_slack;
Jeej 75:dad2f09cb870 327
Jeej 75:dad2f09cb870 328 } while (0);
Jeej 75:dad2f09cb870 329
Jeej 75:dad2f09cb870 330 FLUSH();
Jeej 75:dad2f09cb870 331 while(true)
Jeej 75:dad2f09cb870 332 {
Jeej 75:dad2f09cb870 333 ThisThread::sleep_for(500);
Jeej 75:dad2f09cb870 334 }
Jeej 75:dad2f09cb870 335 }
Jeej 75:dad2f09cb870 336
Jeej 75:dad2f09cb870 337 void modem_cup_update(revision_t* rev)
Jeej 75:dad2f09cb870 338 {
Jeej 75:dad2f09cb870 339 bool bootloader;
Jeej 75:dad2f09cb870 340 cup_param_t* cup = (cup_param_t*)&cup_modem;
Jeej 75:dad2f09cb870 341 int32_t cup_slack = 0;
Jeej 75:dad2f09cb870 342 uint32_t version_old = (rev->fw_version.major << 24) | (rev->fw_version.minor << 16) | rev->fw_version.patch;
Jeej 75:dad2f09cb870 343 uint32_t version_new = (cup->fw_major << 24) | (cup->fw_minor << 16) | cup->fw_patch;
Jeej 75:dad2f09cb870 344
Jeej 75:dad2f09cb870 345 if (version_old < version_new)
Jeej 75:dad2f09cb870 346 {
Jeej 75:dad2f09cb870 347 #ifdef DEBUG_BUTTON
Jeej 75:dad2f09cb870 348 DebouncedInterrupt user_interrupt(DEBUG_BUTTON);
Jeej 75:dad2f09cb870 349 user_interrupt.attach(button_push_isr, IRQ_FALL, 200, true);
Jeej 75:dad2f09cb870 350 #endif
Jeej 75:dad2f09cb870 351 modem_ref_set_boot_cb(cup_boot);
Jeej 75:dad2f09cb870 352
Jeej 75:dad2f09cb870 353 cup_slack = modem_cup_check(rev, cup);
Jeej 75:dad2f09cb870 354
Jeej 75:dad2f09cb870 355 PRINT("\r\nYour modem version is behind the recommended version for this driver.");
Jeej 75:dad2f09cb870 356 PRINT("\r\nUpgrading modem firmware: v%d.%d.%d --> v%d.%d.%d\r\n",
Jeej 75:dad2f09cb870 357 rev->fw_version.major, rev->fw_version.minor, rev->fw_version.patch,
Jeej 75:dad2f09cb870 358 cup->fw_major, cup->fw_minor, cup->fw_patch);
Jeej 75:dad2f09cb870 359 #ifdef DEBUG_BUTTON
Jeej 75:dad2f09cb870 360 PRINT("PRESS USER BUTTON TO START UPGRADE...\r\n");
Jeej 75:dad2f09cb870 361 button_user.acquire();
Jeej 75:dad2f09cb870 362 #endif
Jeej 75:dad2f09cb870 363 modem_cup_start_update(cup_slack, cup);
Jeej 75:dad2f09cb870 364
Jeej 75:dad2f09cb870 365 if (LIBEX_NB_ARCHIVES)
Jeej 75:dad2f09cb870 366 {
Jeej 75:dad2f09cb870 367 ThisThread::sleep_for(500);
Jeej 75:dad2f09cb870 368 PRINT("Updating Libex...\r\n");
Jeej 75:dad2f09cb870 369
Jeej 75:dad2f09cb870 370 modem_read_file(D7A_FID_FIRMWARE_VERSION, (uint8_t*)rev, 0, sizeof(revision_t));
Jeej 75:dad2f09cb870 371
Jeej 75:dad2f09cb870 372 cup = (cup_param_t*)&cup_libex;
Jeej 75:dad2f09cb870 373 cup_slack = modem_cup_check(rev, cup);
Jeej 75:dad2f09cb870 374
Jeej 75:dad2f09cb870 375 modem_cup_start_update(cup_slack, cup);
Jeej 75:dad2f09cb870 376 }
Jeej 75:dad2f09cb870 377
Jeej 75:dad2f09cb870 378 PRINT("Restarting application...\r\n");
Jeej 75:dad2f09cb870 379 FLUSH();
Jeej 75:dad2f09cb870 380 NVIC_SystemReset();
Jeej 75:dad2f09cb870 381 }
Jeej 75:dad2f09cb870 382 }