forked from xuos/xiuos
				
			json file download needs to check whether the sd card is mounted successfully
This commit is contained in:
		
							parent
							
								
									9fd61d3d2a
								
							
						
					
					
						commit
						b41a1709c6
					
				| 
						 | 
					@ -274,6 +274,8 @@ static struct SdioDevDone dev_done =
 | 
				
			||||||
    SdioRead,
 | 
					    SdioRead,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static bool is_mount_ok = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(FS_VFS) && defined(MOUNT_SDCARD_FS)
 | 
					#if defined(FS_VFS) && defined(MOUNT_SDCARD_FS)
 | 
				
			||||||
#include <iot-vfs.h>
 | 
					#include <iot-vfs.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -283,10 +285,13 @@ static struct SdioDevDone dev_done =
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
static int MountSDCardFs(enum FilesystemType fs_type)
 | 
					static int MountSDCardFs(enum FilesystemType fs_type)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    if (MountFilesystem(SDIO_BUS_NAME, SDIO_DEVICE_NAME, SDIO_DRIVER_NAME, fs_type, "/") == 0)
 | 
					    if (MountFilesystem(SDIO_BUS_NAME, SDIO_DEVICE_NAME, SDIO_DRIVER_NAME, fs_type, "/") == 0){
 | 
				
			||||||
        KPrintf("Sd card mount to '/'");
 | 
					        KPrintf("Sd card mount to '/'");
 | 
				
			||||||
    else
 | 
					        is_mount_ok = true;
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
        KPrintf("Sd card mount to '/' failed!");
 | 
					        KPrintf("Sd card mount to '/' failed!");
 | 
				
			||||||
 | 
					        is_mount_ok = false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -329,6 +334,7 @@ static void SdCardDetach(void)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef MOUNT_SDCARD_FS
 | 
					#ifdef MOUNT_SDCARD_FS
 | 
				
			||||||
    UnmountFileSystem("/");
 | 
					    UnmountFileSystem("/");
 | 
				
			||||||
 | 
					    is_mount_ok = false;
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -350,9 +356,10 @@ static uint8 SdCardReadCd(void)
 | 
				
			||||||
    return BusDevReadData(pin->owner_haldev, &read_param);
 | 
					    return BusDevReadData(pin->owner_haldev, &read_param);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int sd_card_status = 0;
 | 
					 | 
				
			||||||
static void SdCardTask(void* parameter)
 | 
					static void SdCardTask(void* parameter)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					    static int sd_card_status = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    while (1) {
 | 
					    while (1) {
 | 
				
			||||||
        if (!SdCardReadCd()) {
 | 
					        if (!SdCardReadCd()) {
 | 
				
			||||||
            if (!sd_card_status) {
 | 
					            if (!sd_card_status) {
 | 
				
			||||||
| 
						 | 
					@ -368,11 +375,6 @@ static void SdCardTask(void* parameter)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int GetSdCardStatus(void)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    return sd_card_status;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef MOUNT_SDCARD
 | 
					#ifdef MOUNT_SDCARD
 | 
				
			||||||
int MountSDCard()
 | 
					int MountSDCard()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					@ -390,6 +392,13 @@ int MountSDCard()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool GetSdMountStatus(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if(!is_mount_ok) 
 | 
				
			||||||
 | 
					        KPrintf("The SD card was not mounted successfully or not inserted, please check!\r\n");
 | 
				
			||||||
 | 
					    return is_mount_ok;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int Imxrt1052HwSdioInit(void)
 | 
					int Imxrt1052HwSdioInit(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    x_err_t ret = EOK;
 | 
					    x_err_t ret = EOK;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -874,7 +874,7 @@ static void mqttCloudInteraction(void* parameter)
 | 
				
			||||||
reconnect:
 | 
					reconnect:
 | 
				
			||||||
    if((AdapterNetActive() == 0) && MQTT_Connect() && MQTT_SubscribeTopic(topicdatabuff[0]) && MQTT_SubscribeTopic(topicdatabuff[1]))
 | 
					    if((AdapterNetActive() == 0) && MQTT_Connect() && MQTT_SubscribeTopic(topicdatabuff[0]) && MQTT_SubscribeTopic(topicdatabuff[1]))
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        KPrintf("Log in to the cloud platform and subscribe to the ota topic successfully.\n"); 
 | 
					        KPrintf("Log in to the cloud platform and subscribe to the topic successfully.\n"); 
 | 
				
			||||||
        PropertyVersion();
 | 
					        PropertyVersion();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
| 
						 | 
					@ -888,9 +888,9 @@ reconnect:
 | 
				
			||||||
    uint8_t jsonfilename[32];
 | 
					    uint8_t jsonfilename[32];
 | 
				
			||||||
    memset(jsontopicdatabuff,0,sizeof(jsontopicdatabuff));
 | 
					    memset(jsontopicdatabuff,0,sizeof(jsontopicdatabuff));
 | 
				
			||||||
    sprintf(jsontopicdatabuff,"protocol/%s/files",CLIENTID);
 | 
					    sprintf(jsontopicdatabuff,"protocol/%s/files",CLIENTID);
 | 
				
			||||||
    if(MQTT_SubscribeTopic(jsontopicdatabuff))
 | 
					    if(!MQTT_SubscribeTopic(jsontopicdatabuff))
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        KPrintf("subscribe to the json download topic successfully.\n"); 
 | 
					        KPrintf("subscribe to the json download topic failed!\n"); 
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1015,8 +1015,8 @@ reconnect:
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
#ifdef USING_DOWNLOAD_JSON
 | 
					#ifdef USING_DOWNLOAD_JSON
 | 
				
			||||||
            // 3.下载json文件,SD卡要确保已经插入
 | 
					            // 3.下载json文件,SD卡要确保已经插入
 | 
				
			||||||
            extern int GetSdCardStatus(void);
 | 
					            extern bool GetSdMountStatus(void);
 | 
				
			||||||
            if(strstr((char *)Platform_mqtt.cmdbuff,jsontopicdatabuff) && GetSdCardStatus())
 | 
					            if(strstr((char *)Platform_mqtt.cmdbuff,jsontopicdatabuff) && GetSdMountStatus())
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                KPrintf("------Start download joson file !------\r\n");
 | 
					                KPrintf("------Start download joson file !------\r\n");
 | 
				
			||||||
                memset(jsonfilename,0,sizeof(jsonfilename));
 | 
					                memset(jsonfilename,0,sizeof(jsonfilename));
 | 
				
			||||||
| 
						 | 
					@ -1079,8 +1079,6 @@ reconnect:
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        KPrintf("firmware file transfer failed,start reboot!\n");
 | 
					        KPrintf("firmware file transfer failed,start reboot!\n");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    MQTT_UnSubscribeTopic(topicdatabuff[0]);
 | 
					 | 
				
			||||||
    MQTT_UnSubscribeTopic(topicdatabuff[1]);
 | 
					 | 
				
			||||||
    MQTT_Disconnect();
 | 
					    MQTT_Disconnect();
 | 
				
			||||||
    mcuboot.flash_deinit();
 | 
					    mcuboot.flash_deinit();
 | 
				
			||||||
    MdelayKTask(2000);
 | 
					    MdelayKTask(2000);
 | 
				
			||||||
| 
						 | 
					@ -1319,7 +1317,6 @@ reconnect:
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        KPrintf("firmware file transfer failed,start reboot!\n");
 | 
					        KPrintf("firmware file transfer failed,start reboot!\n");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    MQTT_UnSubscribeTopic(topicdatabuff);
 | 
					 | 
				
			||||||
    MQTT_Disconnect();
 | 
					    MQTT_Disconnect();
 | 
				
			||||||
    mcuboot.flash_deinit();
 | 
					    mcuboot.flash_deinit();
 | 
				
			||||||
    MdelayKTask(2000);
 | 
					    MdelayKTask(2000);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue