GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usbx_host_classes/src/ux_host_class_storage_unit_ready_test.c Lines: 7 7 100.0 %
Date: 2024-12-12 17:16:36 Branches: 0 0 - %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 *
4
 * This program and the accompanying materials are made available under the
5
 * terms of the MIT License which is available at
6
 * https://opensource.org/licenses/MIT.
7
 *
8
 * SPDX-License-Identifier: MIT
9
 **************************************************************************/
10
11
12
/**************************************************************************/
13
/**************************************************************************/
14
/**                                                                       */
15
/** USBX Component                                                        */
16
/**                                                                       */
17
/**   Storage Class                                                       */
18
/**                                                                       */
19
/**************************************************************************/
20
/**************************************************************************/
21
22
23
/* Include necessary system files.  */
24
25
#define UX_SOURCE_CODE
26
27
#include "ux_api.h"
28
#include "ux_host_class_storage.h"
29
#include "ux_host_stack.h"
30
31
32
/**************************************************************************/
33
/*                                                                        */
34
/*  FUNCTION                                               RELEASE        */
35
/*                                                                        */
36
/*    _ux_host_class_storage_unit_ready_test              PORTABLE C      */
37
/*                                                           6.1.10       */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    Chaoqiong Xiao, Microsoft Corporation                               */
41
/*                                                                        */
42
/*  DESCRIPTION                                                           */
43
/*                                                                        */
44
/*    This function will verify that a SCSI unit is ready for data        */
45
/*    transfer. This command is used when the device does not mount       */
46
/*    when power is supplied.                                             */
47
/*                                                                        */
48
/*  INPUT                                                                 */
49
/*                                                                        */
50
/*    storage                               Pointer to storage class      */
51
/*                                                                        */
52
/*  OUTPUT                                                                */
53
/*                                                                        */
54
/*    Completion Status                                                   */
55
/*                                                                        */
56
/*  CALLS                                                                 */
57
/*                                                                        */
58
/*    _ux_host_class_storage_cbw_initialize Initialize the CBW            */
59
/*    _ux_host_class_storage_transport      Send transport layer command  */
60
/*                                                                        */
61
/*  CALLED BY                                                             */
62
/*                                                                        */
63
/*    Storage Class                                                       */
64
/*                                                                        */
65
/*  RELEASE HISTORY                                                       */
66
/*                                                                        */
67
/*    DATE              NAME                      DESCRIPTION             */
68
/*                                                                        */
69
/*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
70
/*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
71
/*                                            resulting in version 6.1    */
72
/*  01-31-2022     Chaoqiong Xiao           Modified comment(s),          */
73
/*                                            added standalone support,   */
74
/*                                            resulting in version 6.1.10 */
75
/*                                                                        */
76
/**************************************************************************/
77
379
UINT  _ux_host_class_storage_unit_ready_test(UX_HOST_CLASS_STORAGE *storage)
78
{
79
80
UINT            status;
81
UCHAR           *cbw;
82
UINT            command_length;
83
84
    /* If trace is enabled, insert this event into the trace buffer.  */
85
    UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_CLASS_STORAGE_UNIT_READY_TEST, storage, 0, 0, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0)
86
87
    /* Use a pointer for the CBW, easier to manipulate.  */
88
379
    cbw =  (UCHAR *) storage -> ux_host_class_storage_cbw;
89
90
    /* Get the Unit Ready Test Command Length.  */
91
#ifdef UX_HOST_CLASS_STORAGE_INCLUDE_LEGACY_PROTOCOL_SUPPORT
92
    if (storage -> ux_host_class_storage_interface -> ux_interface_descriptor.bInterfaceSubClass == UX_HOST_CLASS_STORAGE_SUBCLASS_UFI)
93
        command_length =  UX_HOST_CLASS_STORAGE_TEST_READY_COMMAND_LENGTH_UFI;
94
    else
95
        command_length =  UX_HOST_CLASS_STORAGE_TEST_READY_COMMAND_LENGTH_SBC;
96
#else
97
379
    command_length =  UX_HOST_CLASS_STORAGE_TEST_READY_COMMAND_LENGTH_SBC;
98
#endif
99
100
    /* Initialize the CBW for this command.  */
101
379
    _ux_host_class_storage_cbw_initialize(storage, 0, 0, command_length);
102
103
    /* Prepare the TEST UNIT READY command block.  */
104
379
    *(cbw + UX_HOST_CLASS_STORAGE_CBW_CB + UX_HOST_CLASS_STORAGE_TEST_READY_OPERATION) =  UX_HOST_CLASS_STORAGE_SCSI_TEST_READY;
105
106
#if defined(UX_HOST_STANDALONE)
107
108
    /* Prepare states.  */
109
    UX_HOST_CLASS_STORAGE_TRANS_STATE_RESET(storage);
110
    storage -> ux_host_class_storage_state_state = UX_HOST_CLASS_STORAGE_STATE_TRANSPORT;
111
    storage -> ux_host_class_storage_state_next = UX_HOST_CLASS_STORAGE_STATE_TEST_CHECK;
112
    status = UX_SUCCESS;
113
#else
114
115
    /* Send the command to transport layer.  */
116
379
    status =  _ux_host_class_storage_transport(storage, UX_NULL);
117
#endif
118
119
    /* Return completion status.  */
120
379
    return(status);
121
}