GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usbx_host_classes/src/ux_host_class_cdc_ecm_transmit_queue_clean.c Lines: 18 18 100.0 %
Date: 2026-03-06 18:57:10 Branches: 4 4 100.0 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 * Copyright (c) 2026-present Eclipse ThreadX contributors
4
 *
5
 * This program and the accompanying materials are made available under the
6
 * terms of the MIT License which is available at
7
 * https://opensource.org/licenses/MIT.
8
 *
9
 * SPDX-License-Identifier: MIT
10
 **************************************************************************/
11
12
13
/**************************************************************************/
14
/**************************************************************************/
15
/**                                                                       */
16
/** USBX Component                                                        */
17
/**                                                                       */
18
/**   CDC_ECM 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_ecm.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_ecm_transmit_queue_clean         PORTABLE C      */
39
/*                                                           6.1.11       */
40
/*  AUTHOR                                                                */
41
/*                                                                        */
42
/*    Chaoqiong Xiao, Microsoft Corporation                               */
43
/*                                                                        */
44
/*  DESCRIPTION                                                           */
45
/*                                                                        */
46
/*    This function cleans the transmit queue.                            */
47
/*                                                                        */
48
/*  INPUT                                                                 */
49
/*                                                                        */
50
/*    cdc_ecm                             CDC ECM instance                */
51
/*                                                                        */
52
/*  OUTPUT                                                                */
53
/*                                                                        */
54
/*    No return value                                                     */
55
/*                                                                        */
56
/*  CALLS                                                                 */
57
/*                                                                        */
58
/*    _ux_host_semaphore_get                Get bulk out semaphore        */
59
/*    _ux_host_stack_endpoint_transfer_abort Abort endpoint transfer      */
60
/*    nx_packet_transmit_release            Release NetX packet           */
61
/*                                                                        */
62
/*  CALLED BY                                                             */
63
/*                                                                        */
64
/*    CDC ECM thread and deactivation                                     */
65
/*                                                                        */
66
/**************************************************************************/
67
48
VOID  _ux_host_class_cdc_ecm_transmit_queue_clean(UX_HOST_CLASS_CDC_ECM *cdc_ecm)
68
{
69
70
UX_INTERRUPT_SAVE_AREA
71
72
NX_PACKET               *current_packet;
73
NX_PACKET               *next_packet;
74
75
    /* Disable interrupts while we check the write in process flag and
76
       set our own state.  */
77
48
    UX_DISABLE
78
79
    /* Is there a write in process?  */
80
48
    if (cdc_ecm -> ux_host_class_cdc_ecm_bulk_out_transfer_check_and_arm_in_process == UX_TRUE)
81
    {
82
83
        /* Wait for writes to complete. Note that once these writes complete,
84
           no more should occur since the link state is pending down.  */
85
86
        /* Mark this thread as suspended so it will be woken up.  */
87
1
        cdc_ecm -> ux_host_class_cdc_ecm_bulk_out_transfer_waiting_for_check_and_arm_to_finish =  UX_TRUE;
88
89
        /* Restore interrupts while we wait.  */
90
1
        UX_RESTORE
91
92
        /* Wait for write function to resume us.  */
93
1
        _ux_host_semaphore_get_norc(&cdc_ecm -> ux_host_class_cdc_ecm_bulk_out_transfer_waiting_for_check_and_arm_to_finish_semaphore, UX_WAIT_FOREVER);
94
95
        /* We're done waiting.  */
96
1
        cdc_ecm -> ux_host_class_cdc_ecm_bulk_out_transfer_waiting_for_check_and_arm_to_finish =  UX_FALSE;
97
    }
98
    else
99
    {
100
101
        /* No writes are in process. Restore interrupts and go on to free
102
           the xmit queue.  */
103
47
        UX_RESTORE
104
    }
105
106
    /* Abort transfers on the bulk out endpoint. Note we need to do this
107
       before accessing the queue since the transmission callback might
108
       modify it.  */
109
48
    _ux_host_stack_transfer_request_abort(&cdc_ecm -> ux_host_class_cdc_ecm_bulk_out_endpoint -> ux_endpoint_transfer_request);
110
111
    /* Get the first packet.  */
112
48
    current_packet =  cdc_ecm -> ux_host_class_cdc_ecm_xmit_queue_head;
113
114
    /* We need to free the packets that will not be sent.  */
115
60
    while (current_packet != UX_NULL)
116
    {
117
118
        /* We must get the next packet before releasing the current packet
119
           because nxe_packet_transmit_release sets the pointer we pass
120
           to null.  */
121
12
        next_packet =  current_packet -> nx_packet_queue_next;
122
123
        /* Free the packet. First do some housekeeping.  */
124
12
        current_packet -> nx_packet_prepend_ptr =  current_packet -> nx_packet_prepend_ptr + UX_HOST_CLASS_CDC_ECM_ETHERNET_SIZE;
125
12
        current_packet -> nx_packet_length =  current_packet -> nx_packet_length - UX_HOST_CLASS_CDC_ECM_ETHERNET_SIZE;
126
127
        /* And ask Netx to release it.  */
128
12
        nx_packet_transmit_release(current_packet);
129
130
        /* Next packet becomes the current one.  */
131
12
        current_packet =  next_packet;
132
    }
133
134
    /* Clear the queue.  */
135
48
    cdc_ecm -> ux_host_class_cdc_ecm_xmit_queue_head =  UX_NULL;
136
48
}
137
#endif