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 /** Prolific 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_prolific.h"
30 #include "ux_host_stack.h"
31
32
33 /**************************************************************************/
34 /* */
35 /* FUNCTION RELEASE */
36 /* */
37 /* _ux_host_class_prolific_reception_start PORTABLE C */
38 /* 6.1 */
39 /* AUTHOR */
40 /* */
41 /* Chaoqiong Xiao, Microsoft Corporation */
42 /* */
43 /* DESCRIPTION */
44 /* */
45 /* This function starts a reception with the DLC modem. This mechanism */
46 /* allows for non blocking calls based on a packet orientated round */
47 /* robbin buffer. When a packet is fully or partially received, an */
48 /* application callback function is invoked and a new transfer request */
49 /* is rescheduled. */
50 /* */
51 /* INPUT */
52 /* */
53 /* prolific Pointer to prolific class */
54 /* prolific_reception Pointer to reception struct */
55 /* */
56 /* OUTPUT */
57 /* */
58 /* Completion Status */
59 /* */
60 /* CALLS */
61 /* */
62 /* _ux_host_stack_transfer_request Process transfer request */
63 /* */
64 /* CALLED BY */
65 /* */
66 /* Application */
67 /* */
68 /* RELEASE HISTORY */
69 /* */
70 /* DATE NAME DESCRIPTION */
71 /* */
72 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
73 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
74 /* resulting in version 6.1 */
75 /* */
76 /**************************************************************************/
_ux_host_class_prolific_reception_start(UX_HOST_CLASS_PROLIFIC * prolific,UX_HOST_CLASS_PROLIFIC_RECEPTION * prolific_reception)77 UINT _ux_host_class_prolific_reception_start (UX_HOST_CLASS_PROLIFIC *prolific,
78 UX_HOST_CLASS_PROLIFIC_RECEPTION *prolific_reception)
79 {
80
81 UX_TRANSFER *transfer_request;
82 UINT status;
83
84 /* If trace is enabled, insert this event into the trace buffer. */
85 UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_CLASS_PROLIFIC_RECEPTION_START, prolific, 0, 0, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0)
86
87 /* Ensure the instance is valid. */
88 if (prolific -> ux_host_class_prolific_state != UX_HOST_CLASS_INSTANCE_LIVE)
89 {
90
91 /* Error trap. */
92 _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_INSTANCE_UNKNOWN);
93
94 /* If trace is enabled, insert this event into the trace buffer. */
95 UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_INSTANCE_UNKNOWN, prolific, 0, 0, UX_TRACE_ERRORS, 0, 0)
96
97 return(UX_HOST_CLASS_INSTANCE_UNKNOWN);
98 }
99
100 /* Start by aligning the head and tail of buffers to the same address supplied by the application. */
101 prolific_reception -> ux_host_class_prolific_reception_data_head = prolific_reception -> ux_host_class_prolific_reception_data_buffer;
102 prolific_reception -> ux_host_class_prolific_reception_data_tail = prolific_reception -> ux_host_class_prolific_reception_data_buffer;
103
104 /* Get the pointer to the bulk in endpoint in the transfer_request. */
105 transfer_request = &prolific -> ux_host_class_prolific_bulk_in_endpoint -> ux_endpoint_transfer_request;
106
107 /* Initialize the transfer request. */
108 transfer_request -> ux_transfer_request_class_instance = (VOID *) prolific;
109 transfer_request -> ux_transfer_request_data_pointer = prolific_reception -> ux_host_class_prolific_reception_data_head;
110 transfer_request -> ux_transfer_request_requested_length = prolific_reception -> ux_host_class_prolific_reception_block_size;
111 transfer_request -> ux_transfer_request_completion_function = _ux_host_class_prolific_reception_callback;
112
113 /* Save the prolific reception structure in the prolific structure. */
114 prolific -> ux_host_class_prolific_reception = prolific_reception;
115
116 /* And declare we have a transfer in progress. */
117 prolific_reception -> ux_host_class_prolific_reception_state = UX_HOST_CLASS_PROLIFIC_RECEPTION_STATE_STARTED;
118
119 /* Arm a first transfer on the bulk in endpoint. There is a callback to this function so we return to the caller
120 right away. */
121 status = _ux_host_stack_transfer_request(transfer_request);
122
123 /* We do not know if the first transfer was successful yet. If the status is not OK, we need to stop the transfer
124 in progress flag. */
125 if (status != UX_SUCCESS)
126 prolific_reception -> ux_host_class_prolific_reception_state = UX_HOST_CLASS_PROLIFIC_RECEPTION_STATE_STOPPED;
127
128 return(status);
129 }
130
131
132 /**************************************************************************/
133 /* */
134 /* FUNCTION RELEASE */
135 /* */
136 /* _uxe_host_class_prolific_reception_start PORTABLE C */
137 /* 6.3.0 */
138 /* AUTHOR */
139 /* */
140 /* Chaoqiong Xiao, Microsoft Corporation */
141 /* */
142 /* DESCRIPTION */
143 /* */
144 /* This function checks errors in PROLIFIC reception function call. */
145 /* */
146 /* INPUT */
147 /* */
148 /* prolific Pointer to PROLIFIC class */
149 /* prolific_reception Pointer to reception struct */
150 /* */
151 /* OUTPUT */
152 /* */
153 /* Status */
154 /* */
155 /* CALLS */
156 /* */
157 /* _ux_host_class_prolific_reception_start */
158 /* PROLIFIC reception start */
159 /* */
160 /* CALLED BY */
161 /* */
162 /* Application */
163 /* */
164 /* RELEASE HISTORY */
165 /* */
166 /* DATE NAME DESCRIPTION */
167 /* */
168 /* 10-31-2023 Chaoqiong Xiao Initial Version 6.3.0 */
169 /* */
170 /**************************************************************************/
_uxe_host_class_prolific_reception_start(UX_HOST_CLASS_PROLIFIC * prolific,UX_HOST_CLASS_PROLIFIC_RECEPTION * prolific_reception)171 UINT _uxe_host_class_prolific_reception_start (UX_HOST_CLASS_PROLIFIC *prolific,
172 UX_HOST_CLASS_PROLIFIC_RECEPTION *prolific_reception)
173 {
174
175 /* Sanity checks. */
176 if ((prolific == UX_NULL) || (prolific_reception == UX_NULL))
177 return(UX_INVALID_PARAMETER);
178
179 /* Invoke PROLIFIC reception start function. */
180 return(_ux_host_class_prolific_reception_start(prolific, prolific_reception));
181 }
182