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 /**************************************************************************/
15 /** */
16 /** USBX Component */
17 /** */
18 /** Host Sierra Wireless AR module class */
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_class_swar.h"
30 #include "ux_host_stack.h"
31
32
33 /**************************************************************************/
34 /* */
35 /* FUNCTION RELEASE */
36 /* */
37 /* _ux_host_class_swar_activate PORTABLE C */
38 /* 6.1.10 */
39 /* AUTHOR */
40 /* */
41 /* Chaoqiong Xiao, Microsoft Corporation */
42 /* */
43 /* DESCRIPTION */
44 /* */
45 /* This function calls the USBX stack to activate the class. */
46 /* */
47 /* INPUT */
48 /* */
49 /* command Dpump class command pointer */
50 /* */
51 /* OUTPUT */
52 /* */
53 /* Completion Status */
54 /* */
55 /* CALLS */
56 /* */
57 /* _ux_host_class_swar_configure Configure swar class */
58 /* _ux_host_class_swar_endpoints_get Get endpoints of swar */
59 /* _ux_host_stack_class_instance_create Create class instance */
60 /* _ux_host_stack_class_instance_destroy Destroy the class instance */
61 /* _ux_utility_memory_allocate Allocate memory block */
62 /* _ux_utility_memory_free Free memory block */
63 /* _ux_host_semaphore_create Create swar semaphore */
64 /* */
65 /* CALLED BY */
66 /* */
67 /* _ux_host_class_swar_entry Entry of swar class */
68 /* */
69 /* RELEASE HISTORY */
70 /* */
71 /* DATE NAME DESCRIPTION */
72 /* */
73 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
74 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
75 /* resulting in version 6.1 */
76 /* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
77 /* refined macros names, */
78 /* resulting in version 6.1.10 */
79 /* */
80 /**************************************************************************/
_ux_host_class_swar_activate(UX_HOST_CLASS_COMMAND * command)81 UINT _ux_host_class_swar_activate(UX_HOST_CLASS_COMMAND *command)
82 {
83
84 UX_DEVICE *device;
85 UX_HOST_CLASS_SWAR *swar;
86 UINT status;
87
88
89 /* The Sierra Wireless class is always activated by the device descriptor. */
90 device = (UX_DEVICE *) command -> ux_host_class_command_container;
91
92 /* Obtain memory for this class instance. */
93 swar = _ux_utility_memory_allocate(UX_NO_ALIGN, UX_REGULAR_MEMORY, sizeof(UX_HOST_CLASS_SWAR));
94 if (swar == UX_NULL)
95 return(UX_MEMORY_INSUFFICIENT);
96
97 /* Store the class container into this instance. */
98 swar -> ux_host_class_swar_class = command -> ux_host_class_command_class_ptr;
99
100 /* Store the device container into the swar class instance. */
101 swar -> ux_host_class_swar_device = device;
102
103 /* Store the instance in the device container, this is for the USBX stack
104 when it needs to invoke the class for deactivation. */
105 device -> ux_device_class_instance = (VOID *) swar;
106
107 /* Create this class instance. */
108 _ux_host_stack_class_instance_create(swar -> ux_host_class_swar_class, (VOID *) swar);
109
110 /* Configure the swar. */
111 status = _ux_host_class_swar_configure(swar);
112
113 /* Get the swar endpoint(s). We will need to search for Bulk Out and Bulk In endpoints on interface . */
114 if (status == UX_SUCCESS)
115 status = _ux_host_class_swar_endpoints_get(swar);
116
117 /* Create the semaphore to protect 2 threads from accessing the same swar instance. */
118 if (status == UX_SUCCESS)
119 {
120 status = _ux_host_semaphore_create(&swar -> ux_host_class_swar_semaphore, "ux_host_class_swar_semaphore", 1);
121 if (status != UX_SUCCESS)
122 status = UX_SEMAPHORE_ERROR;
123 }
124
125 /* Success things. */
126 if (status == UX_SUCCESS)
127 {
128
129 /* Mark the swar as live now. */
130 swar -> ux_host_class_swar_state = UX_HOST_CLASS_INSTANCE_LIVE;
131
132 /* If all is fine and the device is mounted, we may need to inform the application
133 if a function has been programmed in the system structure. */
134 if (_ux_system_host -> ux_system_host_change_function != UX_NULL)
135 {
136
137 /* Call system change function. */
138 _ux_system_host -> ux_system_host_change_function(UX_DEVICE_INSERTION, swar -> ux_host_class_swar_class, (VOID *) swar);
139 }
140
141 /* If trace is enabled, insert this event into the trace buffer. */
142 UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_CLASS_SWAR_ACTIVATE, swar, 0, 0, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0)
143
144 /* If trace is enabled, register this object. */
145 UX_TRACE_OBJECT_REGISTER(UX_TRACE_HOST_OBJECT_TYPE_INTERFACE, swar, 0, 0, 0)
146
147 /* Return success. */
148 return(UX_SUCCESS);
149 }
150
151 /* There was a problem during the configuration, so free the resources. */
152 /* The last resource, semaphore is not created or created error, no need to free. */
153 _ux_host_stack_class_instance_destroy(swar -> ux_host_class_swar_class, (VOID *) swar);
154 device -> ux_device_class_instance = UX_NULL;
155 _ux_utility_memory_free(swar);
156
157 /* Return completion status. */
158 return(status);
159 }
160
161