|
| 1 | +/* |
| 2 | + This file is part of ArduinoIoTCloud. |
| 3 | +
|
| 4 | + Copyright 2020 ARDUINO SA (http://www.arduino.cc/) |
| 5 | +
|
| 6 | + This software is released under the GNU General Public License version 3, |
| 7 | + which covers the main part of arduino-cli. |
| 8 | + The terms of this license can be found at: |
| 9 | + https://www.gnu.org/licenses/gpl-3.0.en.html |
| 10 | +
|
| 11 | + You can be released from the requirements of the above licenses by purchasing |
| 12 | + a commercial license. Buying such a license is mandatory if you want to modify or |
| 13 | + otherwise use the software for commercial activities involving the Arduino |
| 14 | + software without disclosing the source code of your own applications. To purchase |
| 15 | + a commercial license, send an email to [email protected]. |
| 16 | +*/ |
| 17 | + |
| 18 | +#ifdef ARDUINO_ARCH_SAMD |
| 19 | + |
| 20 | +/****************************************************************************** |
| 21 | + * INCLUDE |
| 22 | + ******************************************************************************/ |
| 23 | + |
| 24 | +#include "OTA.h" |
| 25 | + |
| 26 | +#include <Arduino.h> |
| 27 | +#include <Arduino_DebugUtils.h> |
| 28 | + |
| 29 | +#include "../watchdog/Watchdog.h" |
| 30 | + |
| 31 | +#if OTA_STORAGE_SNU |
| 32 | +# include <WiFiNINA.h> /* WiFiStorage */ |
| 33 | +#endif |
| 34 | + |
| 35 | +/****************************************************************************** |
| 36 | + * FUNCTION DEFINITION |
| 37 | + ******************************************************************************/ |
| 38 | + |
| 39 | +int samd_onOTARequest(char const * ota_url) |
| 40 | +{ |
| 41 | + samd_watchdog_reset(); |
| 42 | + |
| 43 | +#if OTA_STORAGE_SNU |
| 44 | + /* Just to be safe delete any remains from previous updates. */ |
| 45 | + WiFiStorage.remove("/fs/UPDATE.BIN.LZSS"); |
| 46 | + WiFiStorage.remove("/fs/UPDATE.BIN.LZSS.TMP"); |
| 47 | + |
| 48 | + samd_watchdog_reset(); |
| 49 | + |
| 50 | + /* Trigger direct download to nina module. */ |
| 51 | + uint8_t nina_ota_err_code = 0; |
| 52 | + if (!WiFiStorage.downloadOTA(ota_url, &nina_ota_err_code)) |
| 53 | + { |
| 54 | + DEBUG_ERROR("ArduinoIoTCloudTCP::%s error download to nina: %d", __FUNCTION__, nina_ota_err_code); |
| 55 | + return static_cast<int>(OTAError::DownloadFailed); |
| 56 | + } |
| 57 | + |
| 58 | + /* Perform the reset to reboot to SxU. */ |
| 59 | + NVIC_SystemReset(); |
| 60 | +#endif /* OTA_STORAGE_SNU */ |
| 61 | +} |
| 62 | + |
| 63 | +#endif /* ARDUINO_ARCH_SAMD */ |
0 commit comments