34#if !defined(FT9XX_PLATFORM) && !defined(RP2040_PLATFORM)
67static bool loadRawFile(
EVE_HalContext *phost,
uint32_t address,
const char *filename,
const wchar_t *filenameW)
80 err = filename ? fopen_s(&afile, filename,
"rb") : _wfopen_s(&afile, filenameW, L
"rb");
82 err = fopen_s(&afile, filename,
"rb");
84 if (err || afile == NULL)
94 fseek(afile, 0, SEEK_END);
95 ftsize = ftell(afile);
96 fseek(afile, 0, SEEK_SET);
99 blocklen = ftsize > 8192 ? 8192 : (
uint16_t)ftsize;
100 blocklen = (
uint16_t)fread(pbuff, 1, blocklen, afile);
114 return loadRawFile(phost, address, filename, NULL);
119 return loadRawFile(phost, address, NULL, filename);
134static bool loadInflateFile(
EVE_HalContext *phost,
uint32_t address,
const char *filename,
const wchar_t *filenameW)
150 err = filename ? fopen_s(&afile, filename,
"rb") : _wfopen_s(&afile, filenameW, L
"rb");
152 err = fopen_s(&afile, filename,
"rb");
154 if (err || afile == NULL)
166 fseek(afile, 0, SEEK_END);
167 ftsize = ftell(afile);
168 fseek(afile, 0, SEEK_SET);
171 blocklen = ftsize > 8192 ? 8192 : (
uint16_t)ftsize;
172 blocklen = (
uint16_t)fread(pbuff, 1, blocklen, afile);
190 return loadInflateFile(phost, address, filename, NULL);
195 return loadInflateFile(phost, address, NULL, filename);
227 err = filename ? fopen_s(&afile, filename,
"rb") : _wfopen_s(&afile, filenameW, L
"rb");
229 err = fopen_s(&afile, filename,
"rb");
231 if (err || afile == NULL)
248 fseek(afile, 0, SEEK_END);
249 ftsize = ftell(afile);
250 fseek(afile, 0, SEEK_SET);
253 blocklen = ftsize > 8192 ? 8192 : (
uint16_t)ftsize;
254 blocklen = (
uint16_t)fread(pbuff, 1, blocklen, afile);
278 return loadImageFile(phost, address, filename, NULL, format);
283 return loadImageFile(phost, address, NULL, filename, format);
289static bool loadCmdFile(
EVE_HalContext *phost,
const char *filename,
const wchar_t *filenameW,
uint32_t *transfered)
302 err = filename ? fopen_s(&afile, filename,
"rb") : _wfopen_s(&afile, filenameW, L
"rb");
304 err = fopen_s(&afile, filename,
"rb");
306 if (err || afile == NULL)
316 fseek(afile, 0, SEEK_END);
317 ftsize = ftell(afile);
318 fseek(afile, 0, SEEK_SET);
321 blocklen = ftsize > 8192 ? 8192 : (
uint16_t)ftsize;
322 blocklen = (
uint16_t)fread(pbuff, 1, blocklen, afile);
329 *transfered += blocklen;
341 return loadCmdFile(phost, filename, NULL, transfered);
346 return loadCmdFile(phost, NULL, filename, transfered);
364 err = filename ? fopen_s(&afile, filename,
"rb") : _wfopen_s(&afile, filenameW, L
"rb");
366 err = fopen_s(&afile, filename,
"rb");
368 if (err || afile == NULL)
378 read = fread(
buffer, 1, size, afile);
387 return readFile(phost,
buffer, size, filename, NULL);
392 return readFile(phost,
buffer, size, NULL, filename);
397#if (EVE_SUPPORT_CHIPID >= EVE_FT810)
399static bool loadMediaFile(
EVE_HalContext *phost,
const char *filename,
const wchar_t *filenameW,
uint32_t *transfered)
408#pragma warning(disable : 6255)
417 if (phost->LoadFileHandle)
419 afile = phost->LoadFileHandle;
424 err = _wfopen_s(&afile, filenameW, L
"rb");
429 err = fopen_s(&afile, filename,
"rb");
431 if (err || afile == NULL)
441 if (!phost->LoadFileHandle)
443 fseek(afile, 0, SEEK_END);
444 remaining = ftell(afile);
445 fseek(afile, transfered ? *transfered : 0, SEEK_SET);
447 phost->LoadFileHandle = afile;
453 while (remaining > 0)
455 blocklen = (
uint16_t)min(blockSize, remaining);
456 blocklen = (
uint16_t)fread((
void *)pbuff, 1, blocklen, afile);
460 eve_printf_debug(
"Read 0 bytes, unexpected end of file, %i bytes remaining", (
int)remaining);
464 remaining -= blocklen;
472 *transfered += transferedPart;
473 if (transferedPart < blocklen)
475 long offset = (long)transferedPart - (
long)blocklen;
476 fseek(afile, offset, SEEK_CUR);
506 if (phost->LoadFileHandle)
508 fclose(phost->LoadFileHandle);
509 phost->LoadFileHandle = NULL;
518 return loadMediaFile(phost, filename, NULL, transfered);
523 return loadMediaFile(phost, NULL, filename, transfered);
EVE_HAL_EXPORT bool EVE_Cmd_wrMem(EVE_HalContext *phost, const uint8_t *buffer, uint32_t size)
Write buffer to Coprocessor's comand fifo.
EVE_HAL_EXPORT uint32_t EVE_Cmd_waitSpace(EVE_HalContext *phost, uint32_t size)
EVE_HAL_EXPORT bool EVE_Cmd_wr32(EVE_HalContext *phost, uint32_t value)
Write 4 bytes to Coprocessor's command fifo.
EVE_HAL_EXPORT uint32_t EVE_Hal_rd32(EVE_HalContext *phost, uint32_t addr)
Read 4 bytes from Coprocessor's memory.
EVE_HAL_EXPORT void EVE_Hal_wrMem(EVE_HalContext *phost, uint32_t addr, const uint8_t *buffer, uint32_t size)
Write a buffer to Coprocessor's memory.
Eve_Hal framework APIs for loading file.
EVE_HAL_EXPORT bool EVE_Util_loadInflateFile(EVE_HalContext *phost, uint32_t address, const char *filename)
Load file into RAM_G by CMD_INFLATE.
EVE_HAL_EXPORT bool EVE_Util_loadCmdFile(EVE_HalContext *phost, const char *filename, uint32_t *transfered)
EVE_HAL_EXPORT bool EVE_Util_loadRawFile(EVE_HalContext *phost, uint32_t address, const char *filename)
Load a raw file into RAM_G.
EVE_HAL_EXPORT void EVE_Util_closeFile(EVE_HalContext *phost)
EVE_HAL_EXPORT bool EVE_Util_loadImageFile(EVE_HalContext *phost, uint32_t address, const char *filename, uint32_t *format)
Load image into RAM_G.
EVE_HAL_EXPORT bool EVE_Util_loadMediaFile(EVE_HalContext *phost, const char *filename, uint32_t *transfered)
EVE_HAL_EXPORT bool EVE_Util_loadSdCard(EVE_HalContext *phost)
Mount the SDcard.
EVE_HAL_EXPORT size_t EVE_Util_readFile(EVE_HalContext *phost, uint8_t *buffer, size_t size, const char *filename)
EVE_HAL_EXPORT bool EVE_Util_sdCardReady(EVE_HalContext *phost)
static ft_uint32_t ft_uint8_t * buffer
void EVE_Cmd_waitFlush(EVE_HalContext *host)
ptrdiff_t LoadFileRemaining