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