Skip to content

Commit 1b1cf94

Browse files
authored
Merge pull request #10 from pennam/wdog-feed
Wdog feed during decompression process
2 parents fee92fa + f72bc60 commit 1b1cf94

File tree

5 files changed

+36
-3
lines changed

5 files changed

+36
-3
lines changed

src/Arduino_Portenta_OTA.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,17 @@ void Arduino_Portenta_OTA::reset()
9090
NVIC_SystemReset();
9191
}
9292

93+
void Arduino_Portenta_OTA::setFeedWatchdogFunc(ArduinoPortentaOtaWatchdogResetFuncPointer func)
94+
{
95+
_feed_watchdog_func = func;
96+
}
97+
98+
void Arduino_Portenta_OTA::feedWatchdog()
99+
{
100+
if (_feed_watchdog_func)
101+
_feed_watchdog_func();
102+
}
103+
93104
/******************************************************************************
94105
* PROTECTED MEMBER FUNCTIONS
95106
******************************************************************************/

src/Arduino_Portenta_OTA.h

+7
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
#define APOTA_LITTLEFS_FLAG (1 << 6)
4343
#define APOTA_MBR_FLAG (1 << 7)
4444

45+
#define ARDUINO_PORTENTA_OTA_HAS_WATCHDOG_FEED
46+
4547
/******************************************************************************
4648
* TYPEDEF
4749
******************************************************************************/
@@ -53,6 +55,8 @@ enum StorageTypePortenta {
5355
SD_FATFS_MBR = APOTA_SDCARD_FLAG | APOTA_FATFS_FLAG | APOTA_MBR_FLAG,
5456
};
5557

58+
typedef void(*ArduinoPortentaOtaWatchdogResetFuncPointer)(void);
59+
5660
/******************************************************************************
5761
* CLASS DECLARATION
5862
******************************************************************************/
@@ -87,6 +91,8 @@ class Arduino_Portenta_OTA
8791
*/
8892
int download(const char * url, bool const is_https);
8993
int decompress();
94+
void setFeedWatchdogFunc(ArduinoPortentaOtaWatchdogResetFuncPointer func);
95+
void feedWatchdog();
9096

9197

9298
protected:
@@ -103,6 +109,7 @@ class Arduino_Portenta_OTA
103109
private:
104110

105111
void write();
112+
ArduinoPortentaOtaWatchdogResetFuncPointer _feed_watchdog_func = 0;
106113

107114
};
108115

src/decompress/lzss.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,27 @@ unsigned char buffer[N * 2];
3636
static char write_buf[FPUTC_BUF_SIZE];
3737
static size_t write_buf_num_bytes = 0;
3838
static size_t bytes_written_fputc = 0;
39+
static ArduinoPortentaOtaWatchdogResetFuncPointer wdog_feed_func = 0;
3940

4041
/**************************************************************************************
4142
PUBLIC FUNCTIONS
4243
**************************************************************************************/
4344

44-
void lzss_init(FILE * update_file_ptr, FILE * target_file_ptr, uint32_t const lzss_file_size)
45+
void lzss_init(FILE * update_file_ptr, FILE * target_file_ptr, uint32_t const lzss_file_size, ArduinoPortentaOtaWatchdogResetFuncPointer wdog_feed_func_ptr)
4546
{
4647
update_file = update_file_ptr;
4748
target_file = target_file_ptr;
4849
LZSS_FILE_SIZE = lzss_file_size;
50+
wdog_feed_func = wdog_feed_func_ptr;
4951
}
5052

5153
void lzss_flush()
5254
{
5355
bytes_written_fputc += write_buf_num_bytes;
5456

57+
if (wdog_feed_func)
58+
wdog_feed_func();
59+
5560
fwrite(write_buf, 1, write_buf_num_bytes, target_file);
5661

5762
write_buf_num_bytes = 0;

src/decompress/lzss.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77

88
#include <Arduino.h>
99
#include <stdint.h>
10+
#include "Arduino_Portenta_OTA.h"
1011

1112
/**************************************************************************************
1213
FUNCTION DEFINITION
1314
**************************************************************************************/
1415

15-
void lzss_init(FILE * update_file_ptr, FILE * target_file_ptr, uint32_t const lzss_file_size);
16+
void lzss_init(FILE * update_file_ptr, FILE * target_file_ptr, uint32_t const lzss_file_size, ArduinoPortentaOtaWatchdogResetFuncPointer wdog_feed_func_ptr);
1617
void lzss_decode();
1718
void lzss_flush();
1819

src/decompress/utility.cpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ int Arduino_Portenta_OTA::decompress()
137137
uint32_t crc32, bytes_read;
138138
uint8_t crc_buf[128];
139139

140+
feedWatchdog();
141+
140142
/* Read the OTA header ... */
141143
fread(ota_header.buf, 1, sizeof(ota_header.buf), update_file);
142144

@@ -147,6 +149,8 @@ int Arduino_Portenta_OTA::decompress()
147149
return static_cast<int>(Error::OtaHeaderLength);
148150
}
149151

152+
feedWatchdog();
153+
150154
/* ... and the CRC second ... rewind to start of CRC verified header ... */
151155
fseek(update_file, sizeof(ota_header.header.len) + sizeof(ota_header.header.crc32), SEEK_SET);
152156
/* ... initialize CRC ... */
@@ -161,6 +165,9 @@ int Arduino_Portenta_OTA::decompress()
161165
}
162166
fread(crc_buf, 1, ota_header.header.len - bytes_read, update_file);
163167
crc32 = crc_update(crc32, crc_buf, ota_header.header.len - bytes_read);
168+
169+
feedWatchdog();
170+
164171
/* ... then finalise ... */
165172
crc32 ^= 0xFFFFFFFF;
166173
/* ... and compare. */
@@ -170,6 +177,8 @@ int Arduino_Portenta_OTA::decompress()
170177
return static_cast<int>(Error::OtaHeaderCrc);
171178
}
172179

180+
feedWatchdog();
181+
173182
if (ota_header.header.magic_number != 0x2341025b) /* 0x2341:025b = VID/PID Portenta H7 */
174183
{
175184
fclose(update_file);
@@ -184,7 +193,7 @@ int Arduino_Portenta_OTA::decompress()
184193

185194
FILE* decompressed = fopen(UPDATE_FILE_NAME, "w");
186195

187-
lzss_init(update_file, decompressed, LZSS_FILE_SIZE);
196+
lzss_init(update_file, decompressed, LZSS_FILE_SIZE, _feed_watchdog_func);
188197

189198
/* During the process of decoding UPDATE.BIN.LZSS
190199
* is decompressed and stored as UPDATE.BIN.

0 commit comments

Comments
 (0)