GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usbx_device_classes/src/ux_device_class_hid_uninitialize.c Lines: 10 10 100.0 %
Date: 2026-03-06 18:57:10 Branches: 1 2 50.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
/** USBX Component                                                        */
16
/**                                                                       */
17
/**   Device HID 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_hid.h"
29
#include "ux_device_stack.h"
30
31
32
/**************************************************************************/
33
/*                                                                        */
34
/*  FUNCTION                                               RELEASE        */
35
/*                                                                        */
36
/*    _ux_device_class_hid_uninitialize                   PORTABLE C      */
37
/*                                                           6.x          */
38
/*  AUTHOR                                                                */
39
/*                                                                        */
40
/*    Chaoqiong Xiao, Microsoft Corporation                               */
41
/*                                                                        */
42
/*  DESCRIPTION                                                           */
43
/*                                                                        */
44
/*    This function uninitializes the USB HID device.                     */
45
/*                                                                        */
46
/*  INPUT                                                                 */
47
/*                                                                        */
48
/*    command                              Pointer to hid command         */
49
/*                                                                        */
50
/*  OUTPUT                                                                */
51
/*                                                                        */
52
/*    Completion Status                                                   */
53
/*                                                                        */
54
/*  CALLS                                                                 */
55
/*                                                                        */
56
/*    _ux_device_thread_delete             Remove storage thread.         */
57
/*    _ux_utility_memory_free              Free memory used by storage    */
58
/*    _ux_utility_event_flags_delete       Remove flag event structure    */
59
/*                                                                        */
60
/*                                                                        */
61
/*  CALLED BY                                                             */
62
/*                                                                        */
63
/*    USBX Source Code                                                    */
64
/*                                                                        */
65
/**************************************************************************/
66
158
UINT  _ux_device_class_hid_uninitialize(UX_SLAVE_CLASS_COMMAND *command)
67
{
68
69
UX_SLAVE_CLASS_HID                      *hid;
70
UX_SLAVE_CLASS                          *class_ptr;
71
72
73
    /* Get the class container.  */
74
158
    class_ptr =  command -> ux_slave_class_command_class_ptr;
75
76
    /* Get the class instance in the container.  */
77
158
    hid = (UX_SLAVE_CLASS_HID *) class_ptr -> ux_slave_class_instance;
78
79
80
    /* Sanity check.  */
81
158
    if (hid != UX_NULL)
82
    {
83
84
#if !defined(UX_DEVICE_STANDALONE)
85
86
      /* Remove HID thread.  */
87
158
      _ux_device_thread_delete(&class_ptr -> ux_slave_class_thread);
88
89
      /* Remove the thread used by HID.  */
90
158
      _ux_utility_memory_free(class_ptr -> ux_slave_class_thread_stack);
91
92
      /* Delete the event flag group for the hid class.  */
93
158
      _ux_device_event_flags_delete(&hid -> ux_device_class_hid_event_flags_group);
94
#endif
95
96
      /* Free memory for the array. */
97
#if (UX_DEVICE_ENDPOINT_BUFFER_OWNER == 1) && defined(UX_DEVICE_CLASS_HID_ZERO_COPY)
98
      _ux_utility_memory_free(hid -> ux_device_class_hid_event_array -> ux_device_class_hid_event_buffer);
99
#endif
100
158
      _ux_utility_memory_free(hid -> ux_device_class_hid_event_array);
101
102
#if defined(UX_DEVICE_CLASS_HID_INTERRUPT_OUT_SUPPORT)
103
104
#if !defined(UX_DEVICE_STANDALONE)
105
106
      /* Free read mutex.  */
107
      _ux_device_mutex_delete(&hid -> ux_device_class_hid_read_mutex);
108
#endif
109
110
      /* Uninitialize receiver.  */
111
      if (hid -> ux_device_class_hid_receiver)
112
        hid -> ux_device_class_hid_receiver ->
113
          ux_device_class_hid_receiver_uninitialize(hid -> ux_device_class_hid_receiver);
114
#endif
115
116
#if defined(UX_DEVICE_CLASS_HID_OWN_ENDPOINT_BUFFER)
117
      _ux_utility_memory_free(hid -> ux_device_class_hid_endpoint_buffer);
118
#endif
119
120
      /* Free the resources.  */
121
158
      _ux_utility_memory_free(hid);
122
    }
123
    /* Return completion status.  */
124
158
    return(UX_SUCCESS);
125
}