1 /**************************************************************************/
2 /* */
3 /* Copyright (c) Microsoft Corporation. All rights reserved. */
4 /* */
5 /* This software is licensed under the Microsoft Software License */
6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */
7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
8 /* and in the root directory of this software. */
9 /* */
10 /**************************************************************************/
11
12 /**************************************************************************/
13 /** */
14 /** USBX Component */
15 /** */
16 /** Device CDC Class */
17 /** */
18 /**************************************************************************/
19 /**************************************************************************/
20
21 #define UX_SOURCE_CODE
22
23
24 /* Include necessary system files. */
25
26 #include "ux_api.h"
27 #include "ux_device_class_pima.h"
28 #include "ux_device_stack.h"
29
30
31 /**************************************************************************/
32 /* */
33 /* FUNCTION RELEASE */
34 /* */
35 /* _ux_device_class_pima_initialize PORTABLE C */
36 /* 6.1.12 */
37 /* AUTHOR */
38 /* */
39 /* Chaoqiong Xiao, Microsoft Corporation */
40 /* */
41 /* DESCRIPTION */
42 /* */
43 /* This function initializes the USB Pima device class */
44 /* */
45 /* INPUT */
46 /* */
47 /* command Pointer to pima command */
48 /* */
49 /* OUTPUT */
50 /* */
51 /* Completion Status */
52 /* */
53 /* CALLS */
54 /* */
55 /* _ux_utility_memory_allocate Allocate memory */
56 /* _ux_utility_memory_free Free memory */
57 /* _ux_device_thread_create Create thread */
58 /* */
59 /* CALLED BY */
60 /* */
61 /* USBX Source Code */
62 /* */
63 /* RELEASE HISTORY */
64 /* */
65 /* DATE NAME DESCRIPTION */
66 /* */
67 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
68 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
69 /* used UX prefix to refer to */
70 /* TX symbols instead of using */
71 /* them directly, */
72 /* resulting in version 6.1 */
73 /* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
74 /* refined macros names, */
75 /* added cancel callback, */
76 /* resulting in version 6.1.10 */
77 /* 04-25-2022 Chaoqiong Xiao Modified comment(s), */
78 /* fixed standalone compile, */
79 /* resulting in version 6.1.11 */
80 /* 07-29-2022 Chaoqiong Xiao Modified comment(s), */
81 /* fixed parameter/variable */
82 /* names conflict C++ keyword, */
83 /* resulting in version 6.1.12 */
84 /* */
85 /**************************************************************************/
_ux_device_class_pima_initialize(UX_SLAVE_CLASS_COMMAND * command)86 UINT _ux_device_class_pima_initialize(UX_SLAVE_CLASS_COMMAND *command)
87 {
88 #if defined(UX_DEVICE_STANDALONE)
89 UX_PARAMETER_NOT_USED(command);
90 return(UX_FUNCTION_NOT_SUPPORTED);
91 #else
92 UINT status;
93 UX_SLAVE_CLASS_PIMA *pima;
94 UX_SLAVE_CLASS_PIMA_PARAMETER *pima_parameter;
95 UX_SLAVE_CLASS *class_ptr;
96
97 /* Get the class container. */
98 class_ptr = command -> ux_slave_class_command_class_ptr;
99
100 /* Create an instance of the device pima class. */
101 pima = _ux_utility_memory_allocate(UX_NO_ALIGN, UX_REGULAR_MEMORY, sizeof(UX_SLAVE_CLASS_PIMA));
102
103 /* Check for successful allocation. */
104 if (pima == UX_NULL)
105 return(UX_MEMORY_INSUFFICIENT);
106
107 /* Save the address of the PIMA instance inside the PIMA container. */
108 class_ptr -> ux_slave_class_instance = (VOID *) pima;
109
110 /* Allocate some memory for the thread stack. */
111 class_ptr -> ux_slave_class_thread_stack =
112 _ux_utility_memory_allocate(UX_NO_ALIGN, UX_REGULAR_MEMORY, UX_THREAD_STACK_SIZE);
113
114 /* Check for successful allocation. */
115 if (class_ptr -> ux_slave_class_thread_stack == UX_NULL)
116 status = UX_MEMORY_INSUFFICIENT;
117 else
118 status = UX_SUCCESS;
119
120 /* This instance needs to be running in a different thread. So start
121 a new thread. We pass a pointer to the class to the new thread. This thread
122 does not start until we have a instance of the class. */
123 if (status == UX_SUCCESS)
124 {
125 status = _ux_device_thread_create(&class_ptr -> ux_slave_class_thread, "ux_slave_class_thread",
126 _ux_device_class_pima_thread,
127 (ULONG) (ALIGN_TYPE) class_ptr, (VOID *) class_ptr -> ux_slave_class_thread_stack,
128 UX_THREAD_STACK_SIZE, UX_THREAD_PRIORITY_CLASS,
129 UX_THREAD_PRIORITY_CLASS, UX_NO_TIME_SLICE, UX_DONT_START);
130
131 /* Check the creation of this thread. */
132 if (status != UX_SUCCESS)
133 status = UX_THREAD_ERROR;
134 }
135
136 UX_THREAD_EXTENSION_PTR_SET(&(class_ptr -> ux_slave_class_thread), class_ptr)
137
138 /* There is error, free resources and return error. */
139 if (status != UX_SUCCESS)
140 {
141
142 /* The last resource, thread is not created or created error,
143 no need to free. */
144
145 if (class_ptr -> ux_slave_class_thread_stack)
146 _ux_utility_memory_free(class_ptr -> ux_slave_class_thread_stack);
147
148 /* Detach instance and free memory. */
149 class_ptr -> ux_slave_class_instance = UX_NULL;
150 _ux_utility_memory_free(pima);
151
152 /* Return completion status. */
153 return(status);
154 }
155
156 /* Success, complete remaining settings. */
157
158 /* Get the pointer to the application parameters for the pima class. */
159 pima_parameter = command -> ux_slave_class_command_parameter;
160
161 /* Store all the application parameter information about the media. */
162 pima -> ux_device_class_pima_manufacturer = pima_parameter -> ux_device_class_pima_parameter_manufacturer;
163 pima -> ux_device_class_pima_model = pima_parameter -> ux_device_class_pima_parameter_model;
164 pima -> ux_device_class_pima_device_version = pima_parameter -> ux_device_class_pima_parameter_device_version;
165 pima -> ux_device_class_pima_serial_number = pima_parameter -> ux_device_class_pima_parameter_serial_number;
166
167 /* Store all the application parameter information about the storage. */
168 pima -> ux_device_class_pima_storage_id = pima_parameter -> ux_device_class_pima_parameter_storage_id;
169 pima -> ux_device_class_pima_storage_type = pima_parameter -> ux_device_class_pima_parameter_storage_type;
170 pima -> ux_device_class_pima_storage_file_system_type = pima_parameter -> ux_device_class_pima_parameter_storage_file_system_type;
171 pima -> ux_device_class_pima_storage_access_capability = pima_parameter -> ux_device_class_pima_parameter_storage_access_capability;
172 pima -> ux_device_class_pima_storage_max_capacity_low = pima_parameter -> ux_device_class_pima_parameter_storage_max_capacity_low;
173 pima -> ux_device_class_pima_storage_max_capacity_high = pima_parameter -> ux_device_class_pima_parameter_storage_max_capacity_high;
174 pima -> ux_device_class_pima_storage_free_space_low = pima_parameter -> ux_device_class_pima_parameter_storage_free_space_low;
175 pima -> ux_device_class_pima_storage_free_space_high = pima_parameter -> ux_device_class_pima_parameter_storage_free_space_high;
176 pima -> ux_device_class_pima_storage_free_space_image = pima_parameter -> ux_device_class_pima_parameter_storage_free_space_image;
177 pima -> ux_device_class_pima_storage_description = pima_parameter -> ux_device_class_pima_parameter_storage_description;
178 pima -> ux_device_class_pima_storage_volume_label = pima_parameter -> ux_device_class_pima_parameter_storage_volume_label;
179
180 /* Update device properties supported. */
181 pima -> ux_device_class_pima_device_properties_list = pima_parameter -> ux_device_class_pima_parameter_device_properties_list;
182
183 /* Update the capture formats supported list. */
184 pima -> ux_device_class_pima_supported_capture_formats_list = pima_parameter -> ux_device_class_pima_parameter_supported_capture_formats_list;
185
186 /* Update the image formats supported list. */
187 pima -> ux_device_class_pima_supported_image_formats_list = pima_parameter -> ux_device_class_pima_parameter_supported_image_formats_list;
188
189 #ifdef UX_PIMA_WITH_MTP_SUPPORT
190 /* Update the internal pima structure with the object properties. */
191 pima -> ux_device_class_pima_object_properties_list = pima_parameter -> ux_device_class_pima_parameter_object_properties_list;
192
193 #endif
194
195 /* Store the callback functions for request. */
196 pima -> ux_device_class_pima_cancel = pima_parameter -> ux_device_class_pima_parameter_cancel;
197
198 /* Store the callback functions for device. */
199 pima -> ux_device_class_pima_device_reset = pima_parameter -> ux_device_class_pima_parameter_device_reset;
200 pima -> ux_device_class_pima_device_prop_desc_get = pima_parameter -> ux_device_class_pima_parameter_device_prop_desc_get;
201 pima -> ux_device_class_pima_device_prop_value_get = pima_parameter -> ux_device_class_pima_parameter_device_prop_value_get;
202 pima -> ux_device_class_pima_device_prop_value_set = pima_parameter -> ux_device_class_pima_parameter_device_prop_value_set;
203
204 /* Store the callback functions for storage. */
205 pima -> ux_device_class_pima_storage_format = pima_parameter -> ux_device_class_pima_parameter_storage_format;
206 pima -> ux_device_class_pima_storage_info_get = pima_parameter -> ux_device_class_pima_parameter_storage_info_get;
207
208 /* Store the callback functions for objects. */
209 pima -> ux_device_class_pima_object_number_get = pima_parameter -> ux_device_class_pima_parameter_object_number_get;
210 pima -> ux_device_class_pima_object_handles_get = pima_parameter -> ux_device_class_pima_parameter_object_handles_get;
211 pima -> ux_device_class_pima_object_info_get = pima_parameter -> ux_device_class_pima_parameter_object_info_get;
212 pima -> ux_device_class_pima_object_data_get = pima_parameter -> ux_device_class_pima_parameter_object_data_get;
213 pima -> ux_device_class_pima_object_info_send = pima_parameter -> ux_device_class_pima_parameter_object_info_send;
214 pima -> ux_device_class_pima_object_data_send = pima_parameter -> ux_device_class_pima_parameter_object_data_send;
215 pima -> ux_device_class_pima_object_delete = pima_parameter -> ux_device_class_pima_parameter_object_delete;
216
217
218 #ifdef UX_PIMA_WITH_MTP_SUPPORT
219 /* Add the MTP specific callback functions. */
220 pima -> ux_device_class_pima_object_prop_desc_get = pima_parameter -> ux_device_class_pima_parameter_object_prop_desc_get;
221 pima -> ux_device_class_pima_object_prop_value_get = pima_parameter -> ux_device_class_pima_parameter_object_prop_value_get;
222 pima -> ux_device_class_pima_object_prop_value_set = pima_parameter -> ux_device_class_pima_parameter_object_prop_value_set;
223 pima -> ux_device_class_pima_object_references_get = pima_parameter -> ux_device_class_pima_parameter_object_references_get;
224 pima -> ux_device_class_pima_object_references_set = pima_parameter -> ux_device_class_pima_parameter_object_references_set;
225 #endif
226
227 /* Store the application owner. */
228 pima -> ux_device_class_pima_application = pima_parameter -> ux_device_class_pima_parameter_application;
229
230 /* Store the start and stop signals if needed by the application. */
231 pima -> ux_device_class_pima_instance_activate = pima_parameter -> ux_device_class_pima_instance_activate;
232 pima -> ux_device_class_pima_instance_deactivate = pima_parameter -> ux_device_class_pima_instance_deactivate;
233
234 /* Return completion status. */
235 return(status);
236 #endif
237 }
238
239