GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usbx_host_classes/src/ux_host_class_storage_transport.c Lines: 13 13 100.0 %
Date: 2026-03-06 18:57:10 Branches: 6 6 100.0 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 * Copyright (c) 2026-present Eclipse ThreadX contributors
4
 *
5
 * This program and the accompanying materials are made available under the
6
 * terms of the MIT License which is available at
7
 * https://opensource.org/licenses/MIT.
8
 *
9
 * SPDX-License-Identifier: MIT
10
 **************************************************************************/
11
12
13
/**************************************************************************/
14
/**************************************************************************/
15
/**                                                                       */
16
/** USBX Component                                                        */
17
/**                                                                       */
18
/**   Storage Class                                                       */
19
/**                                                                       */
20
/**************************************************************************/
21
/**************************************************************************/
22
23
24
/* Include necessary system files.  */
25
26
#define UX_SOURCE_CODE
27
28
#include "ux_api.h"
29
#include "ux_host_class_storage.h"
30
#include "ux_host_stack.h"
31
32
33
/**************************************************************************/
34
/*                                                                        */
35
/*  FUNCTION                                               RELEASE        */
36
/*                                                                        */
37
/*    _ux_host_class_storage_transport                    PORTABLE C      */
38
/*                                                           6.1.10       */
39
/*  AUTHOR                                                                */
40
/*                                                                        */
41
/*    Chaoqiong Xiao, Microsoft Corporation                               */
42
/*                                                                        */
43
/*  DESCRIPTION                                                           */
44
/*                                                                        */
45
/*    This function is the transport layer for all protocols. It perform  */
46
/*    the error recovery and retries if needed.                           */
47
/*                                                                        */
48
/*    It's for RTOS mode only.                                            */
49
/*                                                                        */
50
/*  INPUT                                                                 */
51
/*                                                                        */
52
/*    storage                               Pointer to storage class      */
53
/*    data_pointer                          Pointer to data               */
54
/*                                                                        */
55
/*  OUTPUT                                                                */
56
/*                                                                        */
57
/*    Completion Status                                                   */
58
/*                                                                        */
59
/*  CALLS                                                                 */
60
/*                                                                        */
61
/*    (ux_host_class_storage_transport)     Class storage transport       */
62
/*    _ux_host_class_storage_device_reset   Reset device                  */
63
/*    _ux_host_class_storage_request_sense  Class request sense           */
64
/*    _ux_host_stack_endpoint_reset         Reset endpoint                */
65
/*                                                                        */
66
/*  CALLED BY                                                             */
67
/*                                                                        */
68
/*    Storage Class                                                       */
69
/*                                                                        */
70
/**************************************************************************/
71
2632
UINT  _ux_host_class_storage_transport(UX_HOST_CLASS_STORAGE *storage, UCHAR *data_pointer)
72
{
73
#if defined(UX_HOST_STANDALONE)
74
    UX_PARAMETER_NOT_USED(storage);
75
    UX_PARAMETER_NOT_USED(data_pointer);
76
    return(UX_FUNCTION_NOT_SUPPORTED);
77
#else
78
79
UINT        status;
80
UINT        csw_status;
81
82
83
    /* Reset the sense code.  */
84
2632
    storage -> ux_host_class_storage_sense_code =  UX_SUCCESS;
85
86
    /* Send the command to the appropriate transport.  */
87
2632
    status =  storage -> ux_host_class_storage_transport(storage, data_pointer);
88
89
#ifdef UX_HOST_CLASS_STORAGE_INCLUDE_LEGACY_PROTOCOL_SUPPORT
90
    /* The treatment of errors is different according to the protocol used. BO and CB belong
91
       to the CSW group. CBI is separate.  */
92
    if (storage -> ux_host_class_storage_interface -> ux_interface_descriptor.bInterfaceProtocol != UX_HOST_CLASS_STORAGE_PROTOCOL_CBI)
93
    {
94
#endif
95
96
    /* Check the status.  */
97
2632
    if (status != UX_SUCCESS)
98
99
        /* There was a more serious error. Just give up!  */
100
280
        return(status);
101
102
    /* The command transfer was OK but maybe we have a CSW error.  */
103
2352
    csw_status =  storage -> ux_host_class_storage_csw[UX_HOST_CLASS_STORAGE_CSW_STATUS];
104
2352
    if (csw_status == 0)
105
2158
        return(UX_SUCCESS);
106
107
    /* Check for a command failure. If so, we need to sense the error with
108
       a REQUEST SENSE command.  */
109
194
    status =  _ux_host_class_storage_request_sense(storage);
110
111
    /* If we have an transport failure here, we are in trouble! The storage device is in
112
       an unstable state and should be reset completely.  */
113
194
    if (status != UX_SUCCESS)
114
    {
115
116
        /* Reset device.  */
117
3
        _ux_host_class_storage_device_reset(storage);
118
3
        return(status);
119
    }
120
121
    /* The sense code is saved in the device instance. We can return safely.  */
122
191
    return(UX_SUCCESS);
123
124
#ifdef UX_HOST_CLASS_STORAGE_INCLUDE_LEGACY_PROTOCOL_SUPPORT
125
    }
126
    else
127
    {
128
129
        switch (status)
130
        {
131
132
        case UX_SUCCESS:
133
            return(UX_SUCCESS);
134
135
        case UX_TRANSFER_STALLED:
136
137
            /* The endpoint was halted by a stall condition and needs to be reset.  */
138
            _ux_host_stack_endpoint_reset(storage -> ux_host_class_storage_bulk_in_endpoint);
139
140
            /* The endpoint was halted by a stall condition and needs to be reset.  */
141
            _ux_host_stack_endpoint_reset(storage -> ux_host_class_storage_bulk_out_endpoint);
142
143
            /* Check for a command failure. If so, we need to sense the error with
144
               a REQUEST SENSE command.  */
145
            status =  _ux_host_class_storage_request_sense(storage);
146
            return(status);
147
148
        default:
149
150
            /* There was a more serious error. Just give up!  */
151
            return(status);
152
        }
153
    }
154
#endif
155
#endif
156
}