GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usbx_device_classes/src/ux_device_class_storage_entry.c Lines: 24 24 100.0 %
Date: 2024-12-12 17:16:36 Branches: 9 9 100.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
/**   Device Storage Class                                                */
18
/**                                                                       */
19
/**************************************************************************/
20
/**************************************************************************/
21
22
#define UX_SOURCE_CODE
23
24
25
/* Include necessary system files.  */
26
27
#include "ux_api.h"
28
#include "ux_device_class_storage.h"
29
#include "ux_device_stack.h"
30
31
32
/**************************************************************************/
33
/*                                                                        */
34
/*  FUNCTION                                               RELEASE        */
35
/*                                                                        */
36
/*    _ux_device_class_storage_entry                      PORTABLE C      */
37
/*                                                           6.x          */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    Chaoqiong Xiao, Microsoft Corporation                               */
41
/*                                                                        */
42
/*  DESCRIPTION                                                           */
43
/*                                                                        */
44
/*    This function is the entry point of the device storage class. It    */
45
/*    will be called by the device stack enumeration module when the      */
46
/*    host has sent a SET_CONFIGURATION command and the storage interface */
47
/*    needs to be mounted.                                                */
48
/*                                                                        */
49
/*  INPUT                                                                 */
50
/*                                                                        */
51
/*    command                               Pointer to class command      */
52
/*                                                                        */
53
/*  OUTPUT                                                                */
54
/*                                                                        */
55
/*    Completion Status                                                   */
56
/*                                                                        */
57
/*  CALLS                                                                 */
58
/*                                                                        */
59
/*    _ux_device_class_storage_initialize   Initialize storage class      */
60
/*    _ux_device_class_storage_uninitialize Uninitialize storage class    */
61
/*    _ux_device_class_storage_activate     Activate storage class        */
62
/*    _ux_device_class_storage_deactivate   Deactivate storage class      */
63
/*    _ux_device_class_storage_control_request                            */
64
/*                                          Request control               */
65
/*                                                                        */
66
/*  CALLED BY                                                             */
67
/*                                                                        */
68
/*    Device Storage Class                                                */
69
/*                                                                        */
70
/*  RELEASE HISTORY                                                       */
71
/*                                                                        */
72
/*    DATE              NAME                      DESCRIPTION             */
73
/*                                                                        */
74
/*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
75
/*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
76
/*                                            resulting in version 6.1    */
77
/*  10-31-2023     Chaoqiong Xiao           Modified comment(s),          */
78
/*                                            added error checks support, */
79
/*                                            resulting in version 6.3.0  */
80
/*  xx-xx-xxxx     Mohamed ayed             Modified comment(s),          */
81
/*                                            fix typo,                   */
82
/*                                            remove extra spaces,        */
83
/*                                            resulting in version 6.x    */
84
/*                                                                        */
85
/**************************************************************************/
86
912
UINT  _ux_device_class_storage_entry(UX_SLAVE_CLASS_COMMAND *command)
87
{
88
89
UINT        status;
90
91
92
    /* The command request will tell us we need to do here, either a enumeration
93
       query, an activation or a deactivation.  */
94

912
    switch (command -> ux_slave_class_command_request)
95
    {
96
97
50
    case UX_SLAVE_CLASS_COMMAND_INITIALIZE:
98
99
        /* Call the init function of the Storage class.  */
100
#if defined(UX_DEVICE_CLASS_STORAGE_ENABLE_ERROR_CHECKING)
101
        status =  _uxe_device_class_storage_initialize(command);
102
#else
103
50
        status =  _ux_device_class_storage_initialize(command);
104
#endif
105
106
        /* Return the completion status.  */
107
50
        return(status);
108
109
40
    case UX_SLAVE_CLASS_COMMAND_UNINITIALIZE:
110
111
        /* Call the uninit function of the Storage class.  */
112
40
        status =  _ux_device_class_storage_uninitialize(command);
113
114
        /* Return the completion status.  */
115
40
        return(status);
116
117
118
140
    case UX_SLAVE_CLASS_COMMAND_QUERY:
119
120
        /* Check the CLASS definition in the interface descriptor. */
121
140
        if (command -> ux_slave_class_command_class == UX_SLAVE_CLASS_STORAGE_CLASS)
122
139
            return(UX_SUCCESS);
123
        else
124
1
            return(UX_NO_CLASS_MATCH);
125
126
139
    case UX_SLAVE_CLASS_COMMAND_ACTIVATE:
127
128
        /* The activate command is used when the host has sent a SET_CONFIGURATION command
129
           and this interface has to be mounted. Both Bulk endpoints have to be mounted
130
           and the storage thread needs to be activated.  */
131
139
        status =  _ux_device_class_storage_activate(command);
132
133
        /* Return the completion status.  */
134
139
        return(status);
135
136
136
    case UX_SLAVE_CLASS_COMMAND_DEACTIVATE:
137
138
        /* The deactivate command is used when the device has been extracted.
139
           The device endpoints have to be dismounted and the storage thread canceled.  */
140
136
        status =  _ux_device_class_storage_deactivate(command);
141
142
        /* Return the completion status.  */
143
136
        return(status);
144
145
406
    case UX_SLAVE_CLASS_COMMAND_REQUEST:
146
147
        /* The request command is used when the host sends a command on the control endpoint.  */
148
406
        status = _ux_device_class_storage_control_request(command);
149
150
        /* Return the completion status.  */
151
406
        return(status);
152
153
1
    default:
154
155
        /* Error trap. */
156
1
        _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_FUNCTION_NOT_SUPPORTED);
157
158
        /* If trace is enabled, insert this event into the trace buffer.  */
159
        UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_FUNCTION_NOT_SUPPORTED, 0, 0, 0, UX_TRACE_ERRORS, 0, 0)
160
161
        /* Return an error.  */
162
1
        return(UX_FUNCTION_NOT_SUPPORTED);
163
    }
164
}
165