|
21 | 21 |
|
22 | 22 | static bool setup_done = false; // to check if setup is done
|
23 | 23 | static bool write_done = false; // to check if writing to flash is done
|
| 24 | +static bool load_done = false; // to check if the process was loaded successfully |
24 | 25 |
|
25 | 26 | /******************************************************************************************************
|
26 | 27 | * Callback functions
|
@@ -48,6 +49,14 @@ static void app_write_done_callback(__attribute__((unused)) int length,
|
48 | 49 | write_done = true;
|
49 | 50 | }
|
50 | 51 |
|
| 52 | +static void app_load_done_callback( __attribute__((unused)) int length, |
| 53 | + __attribute__((unused)) int arg1, |
| 54 | + __attribute__((unused)) int arg2, |
| 55 | + __attribute__((unused)) void *ud) |
| 56 | +{ |
| 57 | + load_done = true; |
| 58 | +} |
| 59 | + |
51 | 60 | static void button_callback(int btn_num,
|
52 | 61 | int val,
|
53 | 62 | __attribute__ ((unused)) int arg2,
|
@@ -75,6 +84,7 @@ static void button_callback(int btn_num,
|
75 | 84 | printf("[Log] Exiting Application.\n");
|
76 | 85 | tock_exit(ret); // we failed, so we exit the program.
|
77 | 86 | } else {
|
| 87 | + printf("[Log] Yielding for setup done.\n"); |
78 | 88 | yield_for(&setup_done); // wait until the padding app write is done before you send your app, or it will fail during write
|
79 | 89 | setup_done = false;
|
80 | 90 | printf("[Success] Setup successful. Attempting to write app to flash now.\n");
|
@@ -173,6 +183,7 @@ int write_app(double size, uint8_t binary[]){
|
173 | 183 | ret = app_loader_command_write(flash_offset, FLASH_BUFFER_SIZE);
|
174 | 184 | if (ret != 0) {
|
175 | 185 | printf("[Error] Failed writing data to flash at address: 0x%lx\n", flash_offset);
|
| 186 | + printf("[Error] Error nature: %d\n", ret); |
176 | 187 | return -1;
|
177 | 188 | }
|
178 | 189 | yield_for(&write_done); // wait until write done callback
|
@@ -202,26 +213,34 @@ int main(void) {
|
202 | 213 | button_enable_interrupt(i);
|
203 | 214 | }
|
204 | 215 |
|
205 |
| - // set up the write done and button press callbacks |
| 216 | + // set up the setup done callback |
206 | 217 | int err1 = app_loader_setup_subscribe(app_setup_done_callback, NULL);
|
207 | 218 | if (err1 != 0) {
|
208 | 219 | printf("[Error] Failed to set setup done callback: %d\n", err1);
|
209 | 220 | return err1;
|
210 | 221 | }
|
211 | 222 |
|
212 |
| - // set up the write done and button press callbacks |
| 223 | + // set up the write done callback |
213 | 224 | int err2 = app_loader_write_subscribe(app_write_done_callback, NULL);
|
214 | 225 | if (err2 != 0) {
|
215 | 226 | printf("[Error] Failed to set flash write done callback: %d\n", err2);
|
216 | 227 | return err2;
|
217 | 228 | }
|
218 | 229 |
|
219 |
| - int err3 = button_subscribe(button_callback, NULL); |
| 230 | + // set up the load done callback |
| 231 | + int err3 = app_loader_load_subscribe(app_load_done_callback, NULL); |
220 | 232 | if (err3 != 0) {
|
221 |
| - printf("[Error] Failed to set button callback: %d.\n", err3); |
| 233 | + printf("[Error] Failed to set load done callback: %d\n", err3); |
222 | 234 | return err3;
|
223 | 235 | }
|
224 | 236 |
|
| 237 | + // setup the button press callback |
| 238 | + int err4 = button_subscribe(button_callback, NULL); |
| 239 | + if (err4 != 0) { |
| 240 | + printf("[Error] Failed to set button callback: %d.\n", err4); |
| 241 | + return err4; |
| 242 | + } |
| 243 | + |
225 | 244 | // Check if the app_loader driver exists.
|
226 | 245 | int ret;
|
227 | 246 | ret = app_loader_exists();
|
|
0 commit comments