1 /***************************************************************************
2 * Copyright (c) 2024 Microsoft Corporation
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the MIT License which is available at
6 * https://opensource.org/licenses/MIT.
7 *
8 * SPDX-License-Identifier: MIT
9 **************************************************************************/
10
11
12 /**************************************************************************/
13 /**************************************************************************/
14 /** */
15 /** USBX Component */
16 /** */
17 /** Device Data Pump 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_dpump.h"
29
30
31 /**************************************************************************/
32 /* */
33 /* FUNCTION RELEASE */
34 /* */
35 /* _ux_device_class_dpump_initialize PORTABLE C */
36 /* 6.3.0 */
37 /* AUTHOR */
38 /* */
39 /* Chaoqiong Xiao, Microsoft Corporation */
40 /* */
41 /* DESCRIPTION */
42 /* */
43 /* This function initializes the USB dpump device. */
44 /* */
45 /* INPUT */
46 /* */
47 /* command Pointer to dpump command */
48 /* */
49 /* OUTPUT */
50 /* */
51 /* Completion Status */
52 /* */
53 /* CALLS */
54 /* */
55 /* _ux_utility_memory_allocate Allocate memory */
56 /* */
57 /* CALLED BY */
58 /* */
59 /* Device Data Pump Class */
60 /* */
61 /* RELEASE HISTORY */
62 /* */
63 /* DATE NAME DESCRIPTION */
64 /* */
65 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
66 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
67 /* resulting in version 6.1 */
68 /* 07-29-2022 Chaoqiong Xiao Modified comment(s), */
69 /* fixed parameter/variable */
70 /* names conflict C++ keyword, */
71 /* resulting in version 6.1.12 */
72 /* 10-31-2023 Chaoqiong Xiao Modified comment(s), */
73 /* added a new mode to manage */
74 /* endpoint buffer in classes, */
75 /* resulting in version 6.3.0 */
76 /* */
77 /**************************************************************************/
_ux_device_class_dpump_initialize(UX_SLAVE_CLASS_COMMAND * command)78 UINT _ux_device_class_dpump_initialize(UX_SLAVE_CLASS_COMMAND *command)
79 {
80
81 UX_SLAVE_CLASS_DPUMP *dpump;
82 UX_SLAVE_CLASS *class_ptr;
83 UX_SLAVE_CLASS_DPUMP_PARAMETER *dpump_parameter;
84
85 /* Get the class container. */
86 class_ptr = command -> ux_slave_class_command_class_ptr;
87
88 /* Create an instance of the device dpump class. */
89 dpump = _ux_utility_memory_allocate(UX_NO_ALIGN, UX_REGULAR_MEMORY, sizeof(UX_SLAVE_CLASS_DPUMP));
90
91 /* Check for successful allocation. */
92 if (dpump == UX_NULL)
93 return(UX_MEMORY_INSUFFICIENT);
94
95 /* Save the address of the DPUMP instance inside the DPUMP container. */
96 class_ptr -> ux_slave_class_instance = (VOID *) dpump;
97
98 #if UX_DEVICE_ENDPOINT_BUFFER_OWNER == 1
99 UX_ASSERT(!UX_DEVICE_CLASS_DPUMP_ENDPOINT_BUFFER_SIZE_CALC_OVERFLOW);
100 dpump -> ux_device_class_dpump_endpoint_buffer = _ux_utility_memory_allocate(
101 UX_NO_ALIGN, UX_CACHE_SAFE_MEMORY,
102 UX_DEVICE_CLASS_DPUMP_ENDPOINT_BUFFER_SIZE);
103 if (dpump -> ux_device_class_dpump_endpoint_buffer == UX_NULL)
104 {
105 _ux_utility_memory_free(dpump);
106 return(UX_MEMORY_INSUFFICIENT);
107 }
108 #endif
109
110 /* Get the pointer to the application parameters for the cdc class. */
111 dpump_parameter = command -> ux_slave_class_command_parameter;
112
113 /* Store the start and stop signals if needed by the application. */
114 dpump -> ux_slave_class_dpump_parameter.ux_slave_class_dpump_instance_activate = dpump_parameter -> ux_slave_class_dpump_instance_activate;
115 dpump -> ux_slave_class_dpump_parameter.ux_slave_class_dpump_instance_deactivate = dpump_parameter -> ux_slave_class_dpump_instance_deactivate;
116
117 /* Return completion status. */
118 return(UX_SUCCESS);
119 }
120
121
122