GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: core/src/ux_host_stack_class_unregister.c Lines: 12 12 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
/**   Host Stack                                                          */
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_stack.h"
30
31
32
/**************************************************************************/
33
/*                                                                        */
34
/*  FUNCTION                                               RELEASE        */
35
/*                                                                        */
36
/*    _ux_host_stack_class_unregister                     PORTABLE C      */
37
/*                                                           6.1          */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    Chaoqiong Xiao, Microsoft Corporation                               */
41
/*                                                                        */
42
/*  DESCRIPTION                                                           */
43
/*                                                                        */
44
/*    This function unregisters a USB class from the USB stack.           */
45
/*                                                                        */
46
/*    Note following steps must be done before host class unregister:     */
47
/*    All devices related to the class must be removed.                   */
48
/*                                                                        */
49
/*  INPUT                                                                 */
50
/*                                                                        */
51
/*    class_name                            Name of class                 */
52
/*    class_entry_function                  Entry function of the class   */
53
/*                                                                        */
54
/*  OUTPUT                                                                */
55
/*                                                                        */
56
/*    Completion Status                                                   */
57
/*    UX_SUCCESS                            Class unregistered            */
58
/*    UX_NO_CLASS_MATCH                     Class not found               */
59
/*                                                                        */
60
/*  CALLS                                                                 */
61
/*                                                                        */
62
/*    (class_entry_function)                Entry function of the class   */
63
/*                                                                        */
64
/*  CALLED BY                                                             */
65
/*                                                                        */
66
/*    Application                                                         */
67
/*    USBX Components                                                     */
68
/*                                                                        */
69
/**************************************************************************/
70
11
UINT  _ux_host_stack_class_unregister(UINT (*class_entry_function)(struct UX_HOST_CLASS_COMMAND_STRUCT *))
71
{
72
73
UX_HOST_CLASS           *class_inst;
74
UX_HOST_CLASS_COMMAND   class_command;
75
#if UX_MAX_CLASS_DRIVER > 1
76
ULONG                   class_index;
77
#endif
78
79
80
    /* If trace is enabled, insert this event into the trace buffer.  */
81
    UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_STACK_CLASS_UNREGISTER, class_entry_function, 0, 0, 0, UX_TRACE_HOST_STACK_EVENTS, 0, 0)
82
83
    /* Get first class.  */
84
11
    class_inst =  _ux_system_host -> ux_system_host_class_array;
85
86
#if UX_MAX_CLASS_DRIVER > 1
87
    /* We need to parse the class table to find right class instance.  */
88
23
    for (class_index = 0; class_index < _ux_system_host -> ux_system_host_max_class; class_index++)
89
    {
90
#endif
91
92
        /* Check if the class is expected.  */
93
22
        if (class_inst -> ux_host_class_entry_function == class_entry_function)
94
        {
95
96
            /* Initialize the class command with the generic parameters.  */
97
10
            class_command.ux_host_class_command_request =  UX_HOST_CLASS_COMMAND_DESTROY;
98
10
            class_command.ux_host_class_command_class_ptr = (VOID *)class_inst;
99
100
            /* Invoke command for class destroy.  */
101
10
            class_inst -> ux_host_class_entry_function(&class_command);
102
103
            /* Mark as free.  */
104
10
            class_inst -> ux_host_class_entry_function = UX_NULL;
105
10
            class_inst -> ux_host_class_status = UX_UNUSED;
106
107
            /* Class unregistered success.  */
108
10
            return(UX_SUCCESS);
109
        }
110
111
#if UX_MAX_CLASS_DRIVER > 1
112
        /* Move to the next class.  */
113
12
        class_inst ++;
114
    }
115
#endif
116
117
    /* No more entries in the class table.  */
118
1
    return(UX_NO_CLASS_MATCH);
119
}