Example #1
0
void vfs_user_remount(void)
{
    sync_lock();
    // Only start a remount if in the connected state and not in a transition
    if (!changing_state() && (VFS_USER_STATE_CONNECTED == vfs_state)) {
        vfs_state_next = VFS_USER_STATE_RECONNECTING;
        vfs_state_remaining_ms = disconnect_delay_ms;
    }
    sync_unlock();
}
Example #2
0
void vfs_mngr_fs_remount(void)
{
    sync_lock();

    // Only start a remount if in the connected state and not in a transition
    if (!changing_state() && (VFS_MNGR_STATE_CONNECTED == vfs_state)) {
        vfs_state_next = VFS_MNGR_STATE_RECONNECTING;
    }

    sync_unlock();
}
Example #3
0
void vfs_user_periodic(uint32_t elapsed_ms)
{
    vfs_user_state_t vfs_state_local;
    vfs_user_state_t vfs_state_local_prev;
    sync_assert_usb_thread();
    sync_lock();

    // Return immediately if the desired state has been reached
    if (!changing_state()) {
        sync_unlock();
        return;
    }

    // Wait until the required amount of time has passed
    // before changing state
    if (vfs_state_remaining_ms > 0) {
        vfs_state_remaining_ms -= MIN(elapsed_ms, vfs_state_remaining_ms);
        sync_unlock();
        return;
    }

    vfs_user_printf("vfs_user_periodic()\r\n");

    // Transistion to new state
    vfs_state_local_prev = vfs_state;
    vfs_state = vfs_state_next;
    switch (vfs_state) {
        case VFS_USER_STATE_RECONNECTING:
            // Transition back to the connected state
            vfs_state_next = VFS_USER_STATE_CONNECTED;
            vfs_state_remaining_ms = reconnect_delay_ms;
            break;
        default:
            // No state change logic required in other states
            break;
    }
    vfs_state_local = vfs_state;
    sync_unlock();

    // Processing when leaving a state
    vfs_user_printf("    state %i->%i\r\n", vfs_state_local_prev, vfs_state_local);
    switch (vfs_state_local_prev) {
        case VFS_USER_STATE_DISCONNECTED:
            // No action needed
            break;
        case VFS_USER_STATE_RECONNECTING:
            // No action needed
            break;
        case VFS_USER_STATE_CONNECTED:
            if (file_transfer_state.stream_open) {
                error_t status;
                file_transfer_state.stream_open = false;
                status = stream_close();
                if (ERROR_SUCCESS == fail_reason) {
                    fail_reason = status;
                }
                vfs_user_printf("    stream_close ret %i\r\n", status);
            }
            // Reset if programming was successful  //TODO - move to flash layer
            if (daplink_is_bootloader() && (ERROR_SUCCESS == fail_reason)) {
                NVIC_SystemReset();
            }
            // If hold in bootloader has been set then reset after usb is disconnected
            if (daplink_is_interface() && config_ram_get_hold_in_bl()) {
                NVIC_SystemReset();
            }
            // Resume the target if configured to do so //TODO - move to flash layer
            if (config_get_auto_rst()) {
                target_set_state(RESET_RUN);
            }
            break;
    }

    // Processing when entering a state
    switch (vfs_state_local) {
        case VFS_USER_STATE_DISCONNECTED:
            USBD_MSC_MediaReady = 0;
            break;
        case VFS_USER_STATE_RECONNECTING:
            USBD_MSC_MediaReady = 0;
            break;
        case VFS_USER_STATE_CONNECTED:
            build_filesystem();
            USBD_MSC_MediaReady = 1;
            break;
    }
    return;
}
Example #4
0
void vfs_mngr_periodic(uint32_t elapsed_ms)
{
    bool change_state;
    vfs_mngr_state_t vfs_state_local;
    vfs_mngr_state_t vfs_state_local_prev;
    sync_assert_usb_thread();
    sync_lock();

    // Return immediately if the desired state has been reached
    if (!changing_state()) {
        sync_unlock();
        return;
    }

    change_state = ready_for_state_change();

    if (time_usb_idle < MAX_EVENT_TIME_MS) {
        time_usb_idle += elapsed_ms;
    }

    sync_unlock();

    if (!change_state) {
        return;
    }

    vfs_mngr_printf("vfs_mngr_periodic()\r\n");
    vfs_mngr_printf("   time_usb_idle=%i\r\n", time_usb_idle);
    vfs_mngr_printf("   transfer_state=%i\r\n", file_transfer_state.transfer_state);
    // Transistion to new state
    vfs_state_local_prev = vfs_state;
    vfs_state = vfs_state_next;

    switch (vfs_state) {
        case VFS_MNGR_STATE_RECONNECTING:
            // Transition back to the connected state
            vfs_state_next = VFS_MNGR_STATE_CONNECTED;
            break;

        default:
            // No state change logic required in other states
            break;
    }

    vfs_state_local = vfs_state;
    time_usb_idle = 0;
    sync_unlock();
    // Processing when leaving a state
    vfs_mngr_printf("    state %i->%i\r\n", vfs_state_local_prev, vfs_state_local);

    switch (vfs_state_local_prev) {
        case VFS_MNGR_STATE_DISCONNECTED:
            // No action needed
            break;

        case VFS_MNGR_STATE_RECONNECTING:
            // No action needed
            break;

        case VFS_MNGR_STATE_CONNECTED:

            // Close ongoing transfer if there is one
            if (file_transfer_state.transfer_state != TRASNFER_FINISHED) {
                vfs_mngr_printf("    transfer timeout\r\n");
                file_transfer_state.transfer_timeout = true;
                transfer_update_state(ERROR_SUCCESS);
            }

            util_assert(TRASNFER_FINISHED == file_transfer_state.transfer_state);
            vfs_user_disconnecting();
            break;
    }

    // Processing when entering a state
    switch (vfs_state_local) {
        case VFS_MNGR_STATE_DISCONNECTED:
            USBD_MSC_MediaReady = 0;
            break;

        case VFS_MNGR_STATE_RECONNECTING:
            USBD_MSC_MediaReady = 0;
            break;

        case VFS_MNGR_STATE_CONNECTED:
            build_filesystem();
            USBD_MSC_MediaReady = 1;
            break;
    }

    return;
}