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_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 Sierra modem. This way */
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 /* swar Pointer to swar class */
54 /* swar_reception Pointer to reception struct */
55 /* */
56 /* OUTPUT */
57 /* */
58 /* Completion Status */
59 /* */
60 /* CALLS */
61 /* */
62 /* _ux_host_stack_class_instance_verify Verify the class instance */
63 /* _ux_host_stack_transfer_request Process transfer request */
64 /* */
65 /* CALLED BY */
66 /* */
67 /* Application */
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 /* */
77 /**************************************************************************/
_ux_host_class_swar_reception_start(UX_HOST_CLASS_SWAR * swar,UX_HOST_CLASS_SWAR_RECEPTION * swar_reception)78 UINT _ux_host_class_swar_reception_start (UX_HOST_CLASS_SWAR *swar,
79 UX_HOST_CLASS_SWAR_RECEPTION *swar_reception)
80 {
81
82 UX_TRANSFER *transfer_request;
83 UINT status;
84
85 /* If trace is enabled, insert this event into the trace buffer. */
86 UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_CLASS_SWAR_RECEPTION_START, swar, 0, 0, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0)
87
88 /* Ensure the instance is valid. */
89 if (_ux_host_stack_class_instance_verify(_ux_system_host_class_swar_name, (VOID *) swar) != UX_SUCCESS)
90 {
91
92 /* Error trap. */
93 _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_INSTANCE_UNKNOWN);
94
95 /* If trace is enabled, insert this event into the trace buffer. */
96 UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_INSTANCE_UNKNOWN, swar, 0, 0, UX_TRACE_ERRORS, 0, 0)
97
98 return(UX_HOST_CLASS_INSTANCE_UNKNOWN);
99 }
100
101 /* Start by aligning the head and tail of buffers to the same address supplied by the application. */
102 swar_reception -> ux_host_class_swar_reception_data_head = swar_reception -> ux_host_class_swar_reception_data_buffer;
103 swar_reception -> ux_host_class_swar_reception_data_tail = swar_reception -> ux_host_class_swar_reception_data_buffer;
104
105 /* Get the pointer to the bulk in endpoint in the transfer_request. */
106 transfer_request = &swar -> ux_host_class_swar_bulk_in_endpoint -> ux_endpoint_transfer_request;
107
108 /* Initialize the transfer request. */
109 transfer_request -> ux_transfer_request_class_instance = (VOID *) swar;
110 transfer_request -> ux_transfer_request_data_pointer = swar_reception -> ux_host_class_swar_reception_data_head;
111 transfer_request -> ux_transfer_request_requested_length = swar_reception -> ux_host_class_swar_reception_block_size;
112 transfer_request -> ux_transfer_request_completion_function = _ux_host_class_swar_reception_callback;
113
114 /* Save the acm reception structure in the acm structure. */
115 swar -> ux_host_class_swar_reception = swar_reception;
116
117 /* And declare we have a transfer in progress. */
118 swar_reception -> ux_host_class_swar_reception_state = UX_HOST_CLASS_SWAR_RECEPTION_STATE_STARTED;
119
120 /* Arm a first transfer on the bulk in endpoint. There is a callback to this function so we return to the caller
121 right away. */
122 status = _ux_host_stack_transfer_request(transfer_request);
123
124 /* We do not know if the first transfer was successful yet. If the status is not OK, we need to stop the transfer
125 in progress flag. */
126 if (status != UX_SUCCESS)
127 swar_reception -> ux_host_class_swar_reception_state = UX_HOST_CLASS_SWAR_RECEPTION_STATE_STOPPED;
128
129 return(status);
130 }
131
132