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_new_device_get PORTABLE C */ |
37 |
|
|
/* 6.1.12 */ |
38 |
|
|
/* AUTHOR */ |
39 |
|
|
/* */ |
40 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
41 |
|
|
/* */ |
42 |
|
|
/* DESCRIPTION */ |
43 |
|
|
/* */ |
44 |
|
|
/* This function obtains a free device container for the new device. */ |
45 |
|
|
/* */ |
46 |
|
|
/* INPUT */ |
47 |
|
|
/* */ |
48 |
|
|
/* None */ |
49 |
|
|
/* */ |
50 |
|
|
/* OUTPUT */ |
51 |
|
|
/* */ |
52 |
|
|
/* UX_DEVICE pointer */ |
53 |
|
|
/* */ |
54 |
|
|
/* CALLS */ |
55 |
|
|
/* */ |
56 |
|
|
/* _ux_utility_memory_set Set memory to a value */ |
57 |
|
|
/* */ |
58 |
|
|
/* CALLED BY */ |
59 |
|
|
/* */ |
60 |
|
|
/* USBX Components */ |
61 |
|
|
/* */ |
62 |
|
|
/**************************************************************************/ |
63 |
|
1547 |
UX_DEVICE *_ux_host_stack_new_device_get(VOID) |
64 |
|
|
{ |
65 |
|
|
|
66 |
|
|
#if UX_MAX_DEVICES > 1 |
67 |
|
|
ULONG container_index; |
68 |
|
|
#endif |
69 |
|
|
UX_DEVICE *device; |
70 |
|
|
#if defined(UX_HOST_STANDALONE) |
71 |
|
|
UX_DEVICE *enum_next; |
72 |
|
|
#endif |
73 |
|
|
|
74 |
|
|
/* Start with the first device. */ |
75 |
|
1547 |
device = _ux_system_host -> ux_system_host_device_array; |
76 |
|
|
|
77 |
|
|
#if UX_MAX_DEVICES > 1 |
78 |
|
|
/* Reset the container index. */ |
79 |
|
1547 |
container_index = 0; |
80 |
|
|
|
81 |
|
|
/* Search the list until the end. */ |
82 |
✓✓ |
1653 |
while (container_index++ < _ux_system_host -> ux_system_host_max_devices) |
83 |
|
|
#endif |
84 |
|
|
{ |
85 |
|
|
|
86 |
|
|
/* Until we have found an unused entry. */ |
87 |
✓✓ |
1648 |
if (device -> ux_device_handle == UX_UNUSED) |
88 |
|
|
{ |
89 |
|
|
|
90 |
|
|
#if defined(UX_HOST_STANDALONE) |
91 |
|
|
|
92 |
|
|
/* Reset the entire entry except enum link. */ |
93 |
|
|
enum_next = device -> ux_device_enum_next; |
94 |
|
|
_ux_utility_memory_set(device, 0, sizeof(UX_DEVICE)); /* Use case of memset is verified. */ |
95 |
|
|
device -> ux_device_enum_next = enum_next; |
96 |
|
|
#else |
97 |
|
|
|
98 |
|
|
/* Reset the entire entry. */ |
99 |
|
1542 |
_ux_utility_memory_set(device, 0, sizeof(UX_DEVICE)); /* Use case of memset is verified. */ |
100 |
|
|
#endif |
101 |
|
|
|
102 |
|
|
/* This entry is now used. */ |
103 |
|
1542 |
device -> ux_device_handle = UX_USED; |
104 |
|
|
|
105 |
|
|
/* Return the device pointer. */ |
106 |
|
1542 |
return(device); |
107 |
|
|
} |
108 |
|
|
#if UX_MAX_DEVICES > 1 |
109 |
|
|
|
110 |
|
|
/* Move to the next device entry. */ |
111 |
|
106 |
device++; |
112 |
|
|
#endif |
113 |
|
|
} |
114 |
|
|
|
115 |
|
|
/* No unused devices, return NULL. */ |
116 |
|
5 |
return(UX_NULL); |
117 |
|
|
} |
118 |
|
|
|