GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usbx_device_classes/src/ux_device_class_storage_deactivate.c Lines: 13 13 100.0 %
Date: 2026-03-06 18:57:10 Branches: 4 4 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
/**   Device Storage Class                                                */
19
/**                                                                       */
20
/**************************************************************************/
21
/**************************************************************************/
22
23
#define UX_SOURCE_CODE
24
25
26
/* Include necessary system files.  */
27
28
#include "ux_api.h"
29
#include "ux_device_class_storage.h"
30
#include "ux_device_stack.h"
31
32
33
/**************************************************************************/
34
/*                                                                        */
35
/*  FUNCTION                                               RELEASE        */
36
/*                                                                        */
37
/*    _ux_device_class_storage_deactivate                 PORTABLE C      */
38
/*                                                           6.1.12       */
39
/*  AUTHOR                                                                */
40
/*                                                                        */
41
/*    Chaoqiong Xiao, Microsoft Corporation                               */
42
/*                                                                        */
43
/*  DESCRIPTION                                                           */
44
/*                                                                        */
45
/*    This function deactivate an instance of the storage class.          */
46
/*                                                                        */
47
/*  INPUT                                                                 */
48
/*                                                                        */
49
/*    command                               Pointer to a class command    */
50
/*                                                                        */
51
/*  OUTPUT                                                                */
52
/*                                                                        */
53
/*    Completion Status                                                   */
54
/*                                                                        */
55
/*  CALLS                                                                 */
56
/*                                                                        */
57
/*    _ux_device_stack_transfer_all_request_abort Abort all transfers     */
58
/*                                                                        */
59
/*  CALLED BY                                                             */
60
/*                                                                        */
61
/*    Device Storage Class                                                */
62
/*                                                                        */
63
/**************************************************************************/
64
137
UINT  _ux_device_class_storage_deactivate(UX_SLAVE_CLASS_COMMAND *command)
65
{
66
67
UX_SLAVE_CLASS_STORAGE      *storage;
68
UX_SLAVE_ENDPOINT           *endpoint_in;
69
UX_SLAVE_ENDPOINT           *endpoint_out;
70
UX_SLAVE_CLASS              *class_ptr;
71
72
    /* Get the class container.  */
73
137
    class_ptr =  command -> ux_slave_class_command_class_ptr;
74
75
    /* Get the class instance in the container.  */
76
137
    storage = (UX_SLAVE_CLASS_STORAGE *)class_ptr -> ux_slave_class_instance;
77
78
#if defined(UX_DEVICE_STANDALONE)
79
80
    endpoint_in = storage -> ux_device_class_storage_ep_in;
81
    endpoint_out = storage -> ux_device_class_storage_ep_out;
82
    _ux_device_stack_transfer_all_request_abort(endpoint_in, UX_TRANSFER_BUS_RESET);
83
    _ux_device_stack_transfer_all_request_abort(endpoint_out, UX_TRANSFER_BUS_RESET);
84
    endpoint_out -> ux_slave_endpoint_transfer_request.ux_slave_transfer_request_data_pointer =
85
                                storage -> ux_device_class_storage_buffer[0];
86
    endpoint_in -> ux_slave_endpoint_transfer_request.ux_slave_transfer_request_data_pointer =
87
                                storage -> ux_device_class_storage_buffer[1];
88
#else
89
90
    /* Locate the endpoints.  */
91
137
    endpoint_in =  storage -> ux_slave_class_storage_interface -> ux_slave_interface_first_endpoint;
92
93
    /* Check the endpoint direction, if IN we have the correct endpoint.  */
94
137
    if ((endpoint_in -> ux_slave_endpoint_descriptor.bEndpointAddress & UX_ENDPOINT_DIRECTION) != UX_ENDPOINT_IN)
95
    {
96
97
        /* Wrong direction, we found the OUT endpoint first.  */
98
35
        endpoint_out =  endpoint_in;
99
100
        /* So the next endpoint has to be the IN endpoint.  */
101
35
        endpoint_in =  endpoint_out -> ux_slave_endpoint_next_endpoint;
102
    }
103
    else
104
    {
105
106
        /* We found the endpoint IN first, so next endpoint is OUT.  */
107
102
        endpoint_out =  endpoint_in -> ux_slave_endpoint_next_endpoint;
108
    }
109
110
    /* Terminate the transactions pending on the endpoints.  */
111
137
    _ux_device_stack_transfer_all_request_abort(endpoint_in, UX_TRANSFER_BUS_RESET);
112
137
    _ux_device_stack_transfer_all_request_abort(endpoint_out, UX_TRANSFER_BUS_RESET);
113
#endif
114
115
    /* If there is a deactivate function call it.  */
116
137
    if (storage -> ux_slave_class_storage_instance_deactivate != UX_NULL)
117
    {
118
119
        /* Invoke the application.  */
120
76
        storage -> ux_slave_class_storage_instance_deactivate(storage);
121
    }
122
123
    /* If trace is enabled, insert this event into the trace buffer.  */
124
    UX_TRACE_IN_LINE_INSERT(UX_TRACE_DEVICE_CLASS_STORAGE_DEACTIVATE, storage, 0, 0, 0, UX_TRACE_DEVICE_CLASS_EVENTS, 0, 0)
125
126
    /* If trace is enabled, register this object.  */
127
    UX_TRACE_OBJECT_UNREGISTER(storage);
128
129
    /* Return completion status.  */
130
137
    return(UX_SUCCESS);
131
}
132