Select one of the symbols to view example projects that use it.
 
Outline
...
...
...
...
#define UX_SOURCE_CODE
#include "ux_api.h"
#include "ux_host_class_hid.h"
#include "ux_host_stack.h"
UX_HOST_CLASS_HID_MAX_CLIENTS_mem_alloc_ovf32
...
...
_ux_host_class_hid_client_register(UCHAR *, UINT (*)(struct UX_HOST_CLASS_HID_CLIENT_COMMAND_STRUCT *))
Files
loading...
CodeScopeSTM32 Libraries and Samplesusbxcommon/usbx_host_classes/src/ux_host_class_hid_client_register.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/**************************************************************************/ /* */ /* Copyright (c) Microsoft Corporation. All rights reserved. */ /* */ /* This software is licensed under the Microsoft Software License */ /* Terms for Microsoft Azure RTOS. Full text of the license can be */ /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ /* and in the root directory of this software. */ /* */... /**************************************************************************/ ... /**************************************************************************/ /**************************************************************************/ /** */ /** USBX Component */ /** */ /** HID Class */ /** */... /**************************************************************************/ /**************************************************************************/ /* Include necessary system files. */ #define UX_SOURCE_CODE #include "ux_api.h" #include "ux_host_class_hid.h" #include "ux_host_stack.h" UX_COMPILE_TIME_ASSERT(!UX_OVERFLOW_CHECK_MULC_ULONG(UX_HOST_CLASS_HID_MAX_CLIENTS, sizeof(UX_HOST_CLASS_HID_CLIENT)), UX_HOST_CLASS_HID_MAX_CLIENTS_mem_alloc_ovf) ... /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _ux_host_class_hid_client_register PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function registers a USB HID client to the HID class. The */ /* mechanism is similar to the USB stack class registration. The Class */ /* must specify an entry point for the USB stack to send commands */ /* such as: */ /* */ /* UX_HOST_CLASS_COMMAND_QUERY */ /* UX_HOST_CLASS_COMMAND_ACTIVATE */ /* UX_HOST_CLASS_COMMAND_DESTROY */ /* */ /* Note: The C string of hid_client_name must be NULL-terminated and */ /* the length of it (without the NULL-terminator itself) must be no */ /* larger than UX_HOST_CLASS_HID_MAX_CLIENT_NAME_LENGTH. */ /* */ /* INPUT */ /* */ /* hid_client_name Name of HID client */ /* hid_client_handler Handler for HID client */ /* */ /* OUTPUT */ /* */ /* Completion Status */ /* */ /* CALLS */ /* */ /* _ux_host_stack_class_get Get class */ /* _ux_utility_memory_allocate Allocate memory block */ /* _ux_utility_memory_copy Copy memory block */ /* _ux_utility_string_length_check Check C string and return */ /* length if null-terminated */ /* */ /* CALLED BY */ /* */ /* Application */ /* HID Class */ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ /* verified memset and memcpy */ /* cases, */ /* resulting in version 6.1 */ /* */... /**************************************************************************/ UINT _ux_host_class_hid_client_register(UCHAR *hid_client_name, UINT (*hid_client_handler)(struct UX_HOST_CLASS_HID_CLIENT_COMMAND_STRUCT *)) { UX_HOST_CLASS *class; ULONG hid_client_index; UINT status; UX_HOST_CLASS_HID_CLIENT *hid_client; UINT client_name_length = 0; /* If trace is enabled, insert this event into the trace buffer. */ UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_CLASS_HID_CLIENT_REGISTER, hid_client_name, 0, 0, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0) /* Get the length of the client name (exclude null-terminator). */ status = _ux_utility_string_length_check(hid_client_name, &client_name_length, UX_HOST_CLASS_HID_MAX_CLIENT_NAME_LENGTH); if (status) return(status); /* We need to locate our class container. */ status = _ux_host_stack_class_get(_ux_system_host_class_hid_name, &class); /* If we cannot get the class container, it means the HID class was not registered. */ if (status != UX_SUCCESS) return(status); /* From the class container, we get the client pointer which has the list of HID clients. If the pointer is NULL, the client list was not assigned. *//* ... */ if (class -> ux_host_class_client == UX_NULL) { /* Allocate memory for the class client. * Allocate size overflow static checked outside the function. *//* ... */ class -> ux_host_class_client = _ux_utility_memory_allocate(UX_NO_ALIGN, UX_REGULAR_MEMORY, sizeof(UX_HOST_CLASS_HID_CLIENT)*UX_HOST_CLASS_HID_MAX_CLIENTS); /* Check for successful allocation. */ if (class -> ux_host_class_client == UX_NULL) return(UX_MEMORY_INSUFFICIENT); }if (class -> ux_host_class_client == UX_NULL) { ... } /* De-reference the client pointer into a HID client array pointer. */ hid_client = (UX_HOST_CLASS_HID_CLIENT *) class -> ux_host_class_client; /* We need to parse the HID client handler table to find an empty spot. */ for (hid_client_index = 0; hid_client_index < UX_HOST_CLASS_HID_MAX_CLIENTS; hid_client_index++) { /* Check if this HID client is already used. */ if (hid_client -> ux_host_class_hid_client_status == UX_UNUSED) { /* We have found a free container for the HID client. Copy the name (with null-terminator). */ _ux_utility_memory_copy(hid_client -> ux_host_class_hid_client_name, hid_client_name, client_name_length + 1); /* Use case of memcpy is verified. */ /* Memorize the handler address of this client. */ hid_client -> ux_host_class_hid_client_handler = hid_client_handler; /* Mark it as being in use. */ hid_client -> ux_host_class_hid_client_status = UX_USED; /* Return successful completion. */ return(UX_SUCCESS); }if (hid_client -> ux_host_class_hid_client_status == UX_UNUSED) { ... } else { /* Do a sanity check to make sure the handler is not already installed by mistake. To verify this, we simple check for the handler entry point. *//* ... */ if (hid_client -> ux_host_class_hid_client_handler == hid_client_handler) { /* Error trap. */ _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_ALREADY_INSTALLED); /* If trace is enabled, insert this event into the trace buffer. */ UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_ALREADY_INSTALLED, hid_client_name, 0, 0, UX_TRACE_ERRORS, 0, 0) return(UX_HOST_CLASS_ALREADY_INSTALLED); }if (hid_client -> ux_host_class_hid_client_handler == hid_client_handler) { ... } }else { ... } /* Try the next class. */ hid_client++; }for (hid_client_index = 0; hid_client_index < UX_HOST_CLASS_HID_MAX_CLIENTS; hid_client_index++) { ... } /* Error trap. */ _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_MEMORY_ARRAY_FULL); /* If trace is enabled, insert this event into the trace buffer. */ UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_MEMORY_ARRAY_FULL, hid_client_name, 0, 0, UX_TRACE_ERRORS, 0, 0) /* No more entries in the class table. */ return(UX_MEMORY_ARRAY_FULL); }{ ... }