Better USB plug/unplug handling.
This commit is contained in:
parent
c979c38fd7
commit
0dcbae7ec6
3 changed files with 32 additions and 16 deletions
|
|
@ -57,6 +57,7 @@ static const char *OTA_FILE = "/usb/esp/OTA_URL.txt";
|
|||
const char *CONFIG_FILE = "/usb/esp/config.txt";
|
||||
|
||||
__NOINIT_ATTR uint_fast8_t Restarts;
|
||||
static bool Device_Connected_This_Power_Cycle = false;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
|
|
@ -274,8 +275,6 @@ static void usb_host_task(void *args)
|
|||
|
||||
static void app_usb_task(void *args)
|
||||
{
|
||||
SemaphoreHandle_t init_complete = args;
|
||||
|
||||
static USB_State_T Current_State = USB_STATE_UNINITIALIZED;
|
||||
static msc_host_device_handle_t msc_device = NULL;
|
||||
static msc_host_vfs_handle_t vfs_handle = NULL;
|
||||
|
|
@ -311,20 +310,31 @@ static void app_usb_task(void *args)
|
|||
{
|
||||
device_address = msg.data.new_dev_address;
|
||||
Current_State = USB_STATE_DEVICE_CONNECTED;
|
||||
Device_Connected_This_Power_Cycle = true;
|
||||
Restarts = 0;
|
||||
KLOG_INFO(TAG, "Device connected.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Restarts <= 3)
|
||||
if (Device_Connected_This_Power_Cycle == false)
|
||||
{
|
||||
KLOG_ERROR(TAG, "No flash drive detected--rebooting.");
|
||||
vTaskDelay(pdMS_TO_TICKS(100));
|
||||
esp_restart();
|
||||
}
|
||||
else
|
||||
{
|
||||
KLOG_WARN(TAG, "No flash drive detected after multiple attempts.");
|
||||
if (Restarts <= 3)
|
||||
{
|
||||
KLOG_ERROR(TAG, "No flash drive detected--rebooting.");
|
||||
vTaskDelay(pdMS_TO_TICKS(100));
|
||||
esp_restart();
|
||||
}
|
||||
else
|
||||
{
|
||||
static bool warning_sent = false;
|
||||
|
||||
if (warning_sent == false)
|
||||
{
|
||||
KLOG_WARN(TAG, "No flash drive detected after multiple attempts.");
|
||||
warning_sent = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -356,7 +366,6 @@ static void app_usb_task(void *args)
|
|||
{
|
||||
Current_State = USB_STATE_VFS_REGISTERED;
|
||||
xEventGroupSetBits(Get_System_Events(), SYS_USB_FS_PRESENT);
|
||||
xSemaphoreGive(init_complete);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -401,7 +410,7 @@ static void app_usb_task(void *args)
|
|||
}
|
||||
}
|
||||
|
||||
void Initialize_USB(SemaphoreHandle_t init_complete)
|
||||
void Initialize_USB(void)
|
||||
{
|
||||
KLOG_INFO(TAG, "Initializing USB file system...");
|
||||
|
||||
|
|
@ -416,7 +425,7 @@ void Initialize_USB(SemaphoreHandle_t init_complete)
|
|||
app_usb_task, // Function that implements the task.
|
||||
"USB NVM", // Text name for the task.
|
||||
STACK_SIZE, // Stack size in bytes, not words.
|
||||
(void *)init_complete, // Parameter passed into the task.
|
||||
NULL, // Parameter passed into the task.
|
||||
tskIDLE_PRIORITY + 2, // Priority at which the task is created.
|
||||
xStack, // Array to use as the task's stack.
|
||||
&xTaskBuffer, // Variable to hold the task's data structure.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue