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 /** Pictbridge Application */
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_pictbridge.h"
30 #include "ux_host_class_pima.h"
31
32
33 /**************************************************************************/
34 /* */
35 /* FUNCTION RELEASE */
36 /* */
37 /* _ux_pictbridge_dpshost_thread PORTABLE C */
38 /* 6.1.12 */
39 /* AUTHOR */
40 /* */
41 /* Chaoqiong Xiao, Microsoft Corporation */
42 /* */
43 /* DESCRIPTION */
44 /* */
45 /* This is the Pictbridge dpshost thread that receives and execute */
46 /* notifications from the dpsclient. */
47 /* */
48 /* INPUT */
49 /* */
50 /* pictbridge Pictbridge instance */
51 /* */
52 /* OUTPUT */
53 /* */
54 /* Completion Status */
55 /* */
56 /* CALLS */
57 /* */
58 /* */
59 /* CALLED BY */
60 /* */
61 /* user application */
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 /* 04-25-2022 Yajun Xia Modified comment(s), */
74 /* internal clean up, */
75 /* resulting in version 6.1.11 */
76 /* 07-29-2022 Chaoqiong Xiao Modified comment(s), */
77 /* cleared compile warning, */
78 /* used macros for RTOS calls, */
79 /* resulting in version 6.1.12 */
80 /* */
81 /**************************************************************************/
_ux_pictbridge_dpshost_thread(ULONG parameter)82 VOID _ux_pictbridge_dpshost_thread(ULONG parameter)
83 {
84
85 UX_PICTBRIDGE *pictbridge;
86 UX_PICTBRIDGE_EVENT *pictbridge_event;
87 ULONG actual_flags;
88 UINT status;
89
90 /* Cast the parameter passed in the thread into the pictbridge pointer. */
91 UX_THREAD_EXTENSION_PTR_GET(pictbridge, UX_PICTBRIDGE, parameter)
92
93 /* Loop forever waiting for changes signaled through the semaphore. */
94 while (1)
95 {
96
97 /* Wait for the semaphore to be put by the root hub or a regular hub. */
98 _ux_system_semaphore_get_norc(&pictbridge -> ux_pictbridge_notification_semaphore, UX_WAIT_FOREVER);
99
100 /* Check if there is an event. Normally there should be at least one since we got awaken. */
101 if (pictbridge -> ux_pictbridge_event_array_tail != pictbridge -> ux_pictbridge_event_array_head)
102 {
103
104 /* Get the current event tail. */
105 pictbridge_event = pictbridge -> ux_pictbridge_event_array_tail;
106
107 /* Compute the next entry in the event array. */
108 if ((pictbridge -> ux_pictbridge_event_array_tail + 1) == pictbridge -> ux_pictbridge_event_array_end)
109
110 /* Start at the beginning of the list. */
111 pictbridge -> ux_pictbridge_event_array_tail = pictbridge -> ux_pictbridge_event_array;
112 else
113
114 /* Point to the next entry in the event array. */
115 pictbridge -> ux_pictbridge_event_array_tail = pictbridge -> ux_pictbridge_event_array_tail + 1;
116
117 /* Analyze the event type. */
118 switch (pictbridge_event -> ux_pictbridge_event_code)
119 {
120
121 /* The DSC client is informing us that an object is ready. */
122 case UX_PICTBRIDGE_EC_OBJECT_ADDED :
123 case UX_PICTBRIDGE_EC_REQUEST_OBJECT_TRANSFER :
124
125 /* Check the state machine. */
126 if (pictbridge -> ux_pictbridge_host_client_state_machine != UX_PICTBRIDGE_STATE_MACHINE_IDLE)
127 {
128
129 /* Set the state machine to Client Request pending. */
130 pictbridge -> ux_pictbridge_host_client_state_machine |= UX_PICTBRIDGE_STATE_MACHINE_CLIENT_REQUEST_PENDING;
131
132 /* Wait for the host pending request to be completed. */
133 status = _ux_system_event_flags_get(&pictbridge -> ux_pictbridge_event_flags_group,
134 UX_PICTBRIDGE_EVENT_FLAG_STATE_MACHINE_READY,
135 UX_AND_CLEAR, &actual_flags, UX_PICTBRIDGE_EVENT_TIMEOUT);
136
137 /* Reset the state machine to not Host Request pending. */
138 pictbridge -> ux_pictbridge_host_client_state_machine &= (UINT)~UX_PICTBRIDGE_STATE_MACHINE_CLIENT_REQUEST_PENDING;
139
140 /* Check status. */
141 if (status != UX_SUCCESS)
142 break;
143
144 /* Status good means flag match, no need to check variable again, mark it unused. */
145 (void)actual_flags;
146 }
147
148 /* Change the state machine to client request being executed. */
149 pictbridge -> ux_pictbridge_host_client_state_machine |= UX_PICTBRIDGE_STATE_MACHINE_CLIENT_REQUEST;
150
151 /* Obtain the object and execute the XML request script. */
152 _ux_pictbridge_dpshost_object_get(pictbridge, pictbridge_event -> ux_pictbridge_event_parameter_1);
153
154 /* Do we have a pending client event ? */
155 if (pictbridge -> ux_pictbridge_host_client_state_machine & UX_PICTBRIDGE_STATE_MACHINE_CLIENT_REQUEST_PENDING)
156 {
157
158 /* Yes, so we need to set the event that advertise the completion of the host request. */
159 status = _ux_system_event_flags_set_rc(&pictbridge -> ux_pictbridge_event_flags_group,
160 UX_PICTBRIDGE_EVENT_FLAG_STATE_MACHINE_READY,
161 UX_AND);
162 /* Check status. */
163 if (status != UX_SUCCESS)
164 break;
165
166
167 }
168
169 /* Change state machine to idle. */
170 pictbridge -> ux_pictbridge_host_client_state_machine &= (UINT)~UX_PICTBRIDGE_STATE_MACHINE_CLIENT_REQUEST;
171
172 /* Check to see if we had a configureprint service request. */
173 if (pictbridge -> ux_pictbridge_input_request == UX_PICTBRIDGE_IR_GET_CAPABILITY)
174 {
175
176 /* Parse the tag code that was memorized during the input. */
177 if (pictbridge -> ux_pictbridge_input_tags & UX_PICTBRIDGE_IR_GC_CROPPINGS)
178
179 /* We did have a request, notify the camera of our status. */
180 _ux_pictbridge_dpshost_input_object_send(pictbridge, UX_PICTBRIDGE_IR_NOTIFY_DEVICE_STATUS);
181
182 }
183 break;
184
185 case UX_PICTBRIDGE_EC_START_JOB :
186
187 /* We have received an order to print one or more picture. */
188 _ux_pictbridge_dpshost_startjob(pictbridge);
189 break;
190
191 default :
192 break;
193 }
194 }
195 }
196 }
197
198