GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: core/src/ux_utility_descriptor_pack.c Lines: 22 22 100.0 %
Date: 2026-03-06 18:57:10 Branches: 9 9 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
/**   Utility                                                             */
19
/**                                                                       */
20
/**************************************************************************/
21
/**************************************************************************/
22
23
24
/* Include necessary system files.  */
25
26
#define UX_SOURCE_CODE
27
28
#include "ux_api.h"
29
30
31
/**************************************************************************/
32
/*                                                                        */
33
/*  FUNCTION                                               RELEASE        */
34
/*                                                                        */
35
/*    _ux_utility_descriptor_pack                         PORTABLE C      */
36
/*                                                           6.3.0        */
37
/*  AUTHOR                                                                */
38
/*                                                                        */
39
/*    Chaoqiong Xiao, Microsoft Corporation                               */
40
/*                                                                        */
41
/*  DESCRIPTION                                                           */
42
/*                                                                        */
43
/*    This function will pack an application structure into a USB         */
44
/*    descriptor.                                                         */
45
/*                                                                        */
46
/*  INPUT                                                                 */
47
/*                                                                        */
48
/*    descriptor                            Pointer to the unpacked       */
49
/*                                            descriptor                  */
50
/*    descriptor_structure                  Components of the descriptor  */
51
/*    descriptor_entries                    Number of entries in the      */
52
/*                                            descriptor                  */
53
/*    raw_descriptor                        Pointer to packed descriptor  */
54
/*                                                                        */
55
/*  OUTPUT                                                                */
56
/*                                                                        */
57
/*    None                                                                */
58
/*                                                                        */
59
/*  CALLS                                                                 */
60
/*                                                                        */
61
/*    _ux_utility_long_put                  Put 32-bit value              */
62
/*    _ux_utility_short_put                 Put 16-bit value              */
63
/*                                                                        */
64
/*  CALLED BY                                                             */
65
/*                                                                        */
66
/*    USBX Components                                                     */
67
/*                                                                        */
68
/**************************************************************************/
69
42
VOID  _ux_utility_descriptor_pack(UCHAR * descriptor, UCHAR * descriptor_structure,
70
                        UINT descriptor_entries, UCHAR * raw_descriptor)
71
{
72
73
    /* Loop on all the entries in this descriptor.  */
74
662
    while(descriptor_entries--)
75
    {
76
77
        /* Get the length of that component.  */
78
620
        switch(*descriptor_structure++)
79
        {
80
81
        /* Check the size then build the component from the source and
82
           insert it into the target descriptor.  */
83
453
        case 4:
84
85
            /* Increase address so it's aligned.  */
86
619
            while((ALIGN_TYPE)descriptor & 3u)
87
166
                descriptor++;
88
89
            /* Put the DW.  */
90
453
            _ux_utility_long_put(raw_descriptor, *((ULONG *) descriptor));
91
453
            raw_descriptor +=  4;
92
453
            descriptor += 4;
93
453
            break;
94
95
166
        case 2:
96
97
            /* Increase address so it's aligned.  */
98
167
            while((ALIGN_TYPE)descriptor & 1u)
99
1
                descriptor++;
100
101
            /* Put the Word.  */
102
166
            _ux_utility_short_put(raw_descriptor, (USHORT)*((USHORT *) descriptor));
103
166
            raw_descriptor += 2;
104
166
            descriptor += 2;
105
166
            break;
106
107
1
        default:
108
109
            /* Put the byte.  */
110
1
            *raw_descriptor =  (UCHAR) *((UCHAR *) descriptor);
111
1
            raw_descriptor++;
112
1
            descriptor++;
113
        }
114
    }
115
116
    /* Return to caller.  */
117
42
    return;
118
}