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 /**   ACM CDC 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_cdc_acm.h"
30 #include "ux_host_stack.h"
31 
32 
33 #if defined(UX_HOST_STANDALONE)
34 /**************************************************************************/
35 /*                                                                        */
36 /*  FUNCTION                                               RELEASE        */
37 /*                                                                        */
38 /*    _ux_host_class_cdc_acm_transmission_callback        PORTABLE C      */
39 /*                                                           6.1.10       */
40 /*  AUTHOR                                                                */
41 /*                                                                        */
42 /*    Chaoqiong Xiao, Microsoft Corporation                               */
43 /*                                                                        */
44 /*  DESCRIPTION                                                           */
45 /*                                                                        */
46 /*    This function is the callback from the USBX transfer functions,     */
47 /*    it is called when a full or partial transfer has been done for a    */
48 /*    bulk in transfer. It calls back the application.                    */
49 /*                                                                        */
50 /*    It's for standalone mode.                                           */
51 /*                                                                        */
52 /*  INPUT                                                                 */
53 /*                                                                        */
54 /*    transfer_request                      Pointer to transfer request   */
55 /*                                                                        */
56 /*  OUTPUT                                                                */
57 /*                                                                        */
58 /*    None                                                                */
59 /*                                                                        */
60 /*  CALLS                                                                 */
61 /*                                                                        */
62 /*    _ux_host_stack_transfer_run           Process transfer request      */
63 /*                                                                        */
64 /*  CALLED BY                                                             */
65 /*                                                                        */
66 /*    Application                                                         */
67 /*                                                                        */
68 /*  RELEASE HISTORY                                                       */
69 /*                                                                        */
70 /*    DATE              NAME                      DESCRIPTION             */
71 /*                                                                        */
72 /*  01-31-2022     Chaoqiong Xiao           Initial Version 6.1.10        */
73 /*                                                                        */
74 /**************************************************************************/
_ux_host_class_cdc_acm_transmission_callback(UX_TRANSFER * transfer_request)75 VOID  _ux_host_class_cdc_acm_transmission_callback(UX_TRANSFER *transfer_request)
76 {
77 
78 UX_HOST_CLASS_CDC_ACM   *cdc_acm;
79 ULONG                   request_length;
80 VOID                    (*write_callback)(struct UX_HOST_CLASS_CDC_ACM_STRUCT *, UINT, ULONG);
81 
82     /* Get the class instance for this transfer request.  */
83     cdc_acm = (UX_HOST_CLASS_CDC_ACM *) transfer_request -> ux_transfer_request_class_instance;
84 
85     /* Check the state of the transfer.  If there is an error, we do not proceed with this report.  */
86     if (transfer_request -> ux_transfer_request_completion_code == UX_SUCCESS)
87     {
88 
89         /* Update write information.  */
90         cdc_acm -> ux_host_class_cdc_acm_write_count +=
91                         transfer_request -> ux_transfer_request_actual_length;
92 
93         /* Check if there is remaining.  */
94         request_length = cdc_acm -> ux_host_class_cdc_acm_write_length -
95                                  cdc_acm -> ux_host_class_cdc_acm_write_count;
96         if (request_length > 0)
97         {
98 
99             /* Program the maximum authorized length for this transfer_request.  */
100             if (request_length > transfer_request -> ux_transfer_request_maximum_length)
101                 request_length =  transfer_request -> ux_transfer_request_maximum_length;
102 
103             /* Update buffer pointer and request length.  */
104             transfer_request -> ux_transfer_request_data_pointer +=
105                         transfer_request -> ux_transfer_request_actual_length;
106             transfer_request -> ux_transfer_request_requested_length = request_length;
107             UX_TRANSFER_STATE_RESET(transfer_request);
108 
109             /* Arm another transfer.  */
110             _ux_host_stack_transfer_run(transfer_request);
111 
112             /* There is no status to be reported back to the stack.  */
113             return;
114         }
115     }
116 
117     /* There is error, or total things done, set state to idle.  */
118     cdc_acm -> ux_host_class_cdc_acm_write_state = UX_STATE_RESET;
119 
120     /* Clear callback for blocking mode.  */
121     write_callback = cdc_acm -> ux_host_class_cdc_acm_write_callback;
122     cdc_acm -> ux_host_class_cdc_acm_write_callback = UX_NULL;
123 
124     /* We need to report this transfer to the application.  */
125     if (write_callback)
126     {
127         write_callback(cdc_acm,
128                     transfer_request -> ux_transfer_request_completion_code,
129                     cdc_acm -> ux_host_class_cdc_acm_write_count);
130     }
131 
132     /* There is no status to be reported back to the stack.  */
133     return;
134 }
135 #endif
136