| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- #include "FreeRTOS.h"
- #include "board.h"
- #include "chip.h"
- #include "sfud.h"
- #include "romfile.h"
- #include "ota_update.h"
- #include "sysinfo.h"
- #include "ff_stdio.h"
- #include "test_demo.h"
- #include "delta_update.h"
- #ifdef USB_SUPPORT
- #if USB_TEST
- #define USB_DEV_PLUGED 0
- #define USB_DEV_UNPLUGED 1
- extern int usb_wait_stor_dev_pluged(uint32_t timeout);
- extern void hub_usb_dev_reset(void);
- static void usb_read_thread(void *para)
- {
- unsigned int status;
- for (;;) {
- status = usb_wait_stor_dev_pluged(portMAX_DELAY);
- if (status == USB_DEV_PLUGED) {
- printf("usb dev inserted.\n");
- #ifdef OTA_UPDATE_SUPPORT
- int filetype;
- char filename[32];
- FF_FILE *fp;
- #ifdef DELTA_UPDATE_SUPPORT
- //Demo从U盘读取patch文件来模拟接收patch文件
- size_t filesize;
- uint8_t *filebuf;
- size_t leftsize;
- size_t wrsize;
- uint32_t offset;
- #if DEVICE_TYPE_SELECT != EMMC_FLASH
- sfud_flash *sflash = sfud_get_device(0);
- #endif
- filebuf = pvPortMalloc(0x10000);
- if (!filebuf) {
- printf("%s filebuf malloc fail.\n", __func__);
- continue;
- }
- for (filetype = UPFILE_TYPE_LDR; filetype < UPFILE_TYPE_NUM; filetype++) {
- strcpy(filename, "/usb/");
- strcat(filename, g_upfilename[filetype]);
- strcpy(strrchr(filename, '.'), "_patch.bin");
- fp = ff_fopen(filename, "rb");
- if (!fp) {
- printf("not found patch file %s.\n", filename);
- continue;
- }
- offset = OTA_MEDIA_OFFSET;
- filesize = ff_filelength(fp);
- leftsize = filesize;
- #if DEVICE_TYPE_SELECT != EMMC_FLASH
- sfud_erase(sflash, OTA_MEDIA_OFFSET, filesize);
- #endif
- while (leftsize) {
- wrsize = leftsize > 0x10000 ? 0x10000 : leftsize;
- ff_fread(filebuf, 1, wrsize, fp);
- #if DEVICE_TYPE_SELECT == EMMC_FLASH
- emmc_write(offset, wrsize, filebuf);
- #else
- sfud_write(sflash, offset, wrsize, filebuf);
- #endif
- offset += wrsize;
- leftsize -= wrsize;
- }
- ff_fclose(fp);
- delta_update(filetype, filesize);
- }
- vPortFree(filebuf);
- #else
- for (filetype = UPFILE_TYPE_LDR; filetype < UPFILE_TYPE_NUM; filetype++) {
- sprintf(filename, "%s/%s", "/usb", g_upfilename[filetype]);
- fp = ff_fopen(filename, "rb");
- if (fp) {
- ff_fclose(fp);
- update_from_media("/usb", filetype);
- }
- }
- if (get_update_status()) {
- printf("%s, entry wdt reset.\n", __func__);
- wdt_cpu_reboot();
- }
- #endif
- #endif
- } else if (status == USB_DEV_UNPLUGED) {
- printf("usb removed.\n");
- }
- }
- }
- void usb_read_demo(void)
- {
- if (xTaskCreate(usb_read_thread, "usb_read_demo", configMINIMAL_STACK_SIZE * 16, NULL,
- 1, NULL) != pdPASS) {
- printf("create usbread task fail.\n");
- }
- }
- #endif
- #endif
|