GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usbx_host_classes/src/ux_host_class_hub_interrupt_endpoint_start.c Lines: 21 21 100.0 %
Date: 2026-03-06 18:57:10 Branches: 8 8 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
/**  HUB 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_hub.h"
30
#include "ux_host_stack.h"
31
32
33
/**************************************************************************/
34
/*                                                                        */
35
/*  FUNCTION                                               RELEASE        */
36
/*                                                                        */
37
/*    _ux_host_class_hub_interrupt_endpoint_start         PORTABLE C      */
38
/*                                                           6.1.12       */
39
/*  AUTHOR                                                                */
40
/*                                                                        */
41
/*    Chaoqiong Xiao, Microsoft Corporation                               */
42
/*                                                                        */
43
/*  DESCRIPTION                                                           */
44
/*                                                                        */
45
/*    This function search for the handle of the only interrupt endpoint  */
46
/*    in the default alternate setting of the HUB interface. The          */
47
/*    interrupt endpoint should always be there. When it is located, the  */
48
/*    first transfer for this endpoint is made. The HUB will report status*/
49
/*    changes on this pipe.                                               */
50
/*                                                                        */
51
/*  INPUT                                                                 */
52
/*                                                                        */
53
/*    hub                                   Pointer to HUB class          */
54
/*                                                                        */
55
/*  OUTPUT                                                                */
56
/*                                                                        */
57
/*    Completion Status                                                   */
58
/*                                                                        */
59
/*  CALLS                                                                 */
60
/*                                                                        */
61
/*    _ux_host_stack_interface_endpoint_get Get endpoint of interface     */
62
/*    _ux_host_stack_transfer_request       Process transfer request      */
63
/*    _ux_utility_memory_allocate           Allocate memory block         */
64
/*                                                                        */
65
/*  CALLED BY                                                             */
66
/*                                                                        */
67
/*    HUB Class                                                           */
68
/*                                                                        */
69
/**************************************************************************/
70
48
UINT  _ux_host_class_hub_interrupt_endpoint_start(UX_HOST_CLASS_HUB *hub)
71
{
72
73
UINT            status;
74
UX_TRANSFER     *transfer_request;
75
76
77
    /* Search the interrupt endpoint. It is attached to the interface container.  */
78
48
    status =  _ux_host_stack_interface_endpoint_get(hub -> ux_host_class_hub_interface, 0, &hub -> ux_host_class_hub_interrupt_endpoint);
79
80
    /* Check completion status.  */
81
48
    if (status != UX_SUCCESS)
82
3
        return(status);
83
84
    /* Do a sanity check on the nature of the endpoint. Must be interrupt and its direction must be IN.  */
85
45
    if (((hub -> ux_host_class_hub_interrupt_endpoint -> ux_endpoint_descriptor.bEndpointAddress & UX_ENDPOINT_DIRECTION) == UX_ENDPOINT_IN) &&
86
42
        ((hub -> ux_host_class_hub_interrupt_endpoint -> ux_endpoint_descriptor.bmAttributes & UX_MASK_ENDPOINT_TYPE) == UX_INTERRUPT_ENDPOINT))
87
    {
88
89
        /* The endpoint is correct, fill in the transfer_request with the length requested for this endpoint.  */
90
39
        transfer_request =  &hub -> ux_host_class_hub_interrupt_endpoint -> ux_endpoint_transfer_request;
91
39
        transfer_request -> ux_transfer_request_requested_length = transfer_request -> ux_transfer_request_packet_length;
92
39
        transfer_request -> ux_transfer_request_actual_length =  0;
93
94
        /* Set timeout - wait forever.  */
95
39
        transfer_request -> ux_transfer_request_timeout_value = UX_WAIT_FOREVER;
96
97
        /* Since this transfer_request has a callback, we need the HUB instance to be stored in the transfer request.  */
98
39
        transfer_request -> ux_transfer_request_class_instance =  (VOID *) hub;
99
100
        /* This transfer request always has the IN direction.  */
101
39
        hub -> ux_host_class_hub_interrupt_endpoint -> ux_endpoint_transfer_request.ux_transfer_request_type =  UX_REQUEST_IN;
102
103
        /* Interrupt transactions have a completion routine.  */
104
39
        transfer_request -> ux_transfer_request_completion_function =  _ux_host_class_hub_transfer_request_completed;
105
106
        /* Obtain a buffer for this transaction. The buffer will always be reused.  */
107
39
        transfer_request -> ux_transfer_request_data_pointer =  _ux_utility_memory_allocate(UX_SAFE_ALIGN, UX_CACHE_SAFE_MEMORY,
108
                                                                transfer_request -> ux_transfer_request_requested_length);
109
110
        /* Check the memory pointer.  */
111
39
        if (transfer_request -> ux_transfer_request_data_pointer == UX_NULL)
112
        {
113
114
            /* Clear the interrupt endpoint.  */
115
3
            hub -> ux_host_class_hub_interrupt_endpoint = UX_NULL;
116
117
            /* Return error.  */
118
3
            return(UX_MEMORY_INSUFFICIENT);
119
        }
120
121
        /* Send the request to the stack.   */
122
36
        status =  _ux_host_stack_transfer_request(transfer_request);
123
124
        /* Return completion status.  */
125
36
        return(status);
126
    }
127
128
    /* Error trap. */
129
6
    _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_HUB, UX_ENDPOINT_HANDLE_UNKNOWN);
130
131
    /* If trace is enabled, insert this event into the trace buffer.  */
132
    UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_ENDPOINT_HANDLE_UNKNOWN, hub -> ux_host_class_hub_interrupt_endpoint, 0, 0, UX_TRACE_ERRORS, 0, 0)
133
134
    /* Return error.  */
135
6
    return(UX_ENDPOINT_HANDLE_UNKNOWN);
136
}