GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usbx_host_classes/src/ux_host_class_hid_remote_control_callback.c Lines: 16 16 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
/**   HID Remote Control 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_hid.h"
30
#include "ux_host_class_hid_remote_control.h"
31
#include "ux_host_stack.h"
32
33
34
/**************************************************************************/
35
/*                                                                        */
36
/*  FUNCTION                                               RELEASE        */
37
/*                                                                        */
38
/*    _ux_host_class_hid_remote_control_callback          PORTABLE C      */
39
/*                                                           6.1          */
40
/*  AUTHOR                                                                */
41
/*                                                                        */
42
/*    Chaoqiong Xiao, Microsoft Corporation                               */
43
/*                                                                        */
44
/*  DESCRIPTION                                                           */
45
/*                                                                        */
46
/*    This function is the callback mechanism for a report registration.  */
47
/*                                                                        */
48
/*  INPUT                                                                 */
49
/*                                                                        */
50
/*    callback                              Pointer to callback           */
51
/*                                                                        */
52
/*  OUTPUT                                                                */
53
/*                                                                        */
54
/*    None                                                                */
55
/*                                                                        */
56
/*  CALLS                                                                 */
57
/*                                                                        */
58
/*    None                                                                */
59
/*                                                                        */
60
/*  CALLED BY                                                             */
61
/*                                                                        */
62
/*    HID Remote Control Class                                            */
63
/*                                                                        */
64
/**************************************************************************/
65
546
VOID  _ux_host_class_hid_remote_control_callback(UX_HOST_CLASS_HID_REPORT_CALLBACK *callback)
66
{
67
68
UX_HOST_CLASS_HID_CLIENT            *hid_client;
69
UX_HOST_CLASS_HID_REMOTE_CONTROL    *remote_control_instance;
70
ULONG                               *array_head;
71
ULONG                               *array_tail;
72
ULONG                               *array_end;
73
ULONG                               *array_start;
74
ULONG                               *array_head_next;
75
76
77
    /* Get the HID client instance that issued the callback.  */
78
546
    hid_client = callback -> ux_host_class_hid_report_callback_client;
79
80
    /* Get the remote control local instance.  */
81
546
    remote_control_instance =  (UX_HOST_CLASS_HID_REMOTE_CONTROL *) hid_client -> ux_host_class_hid_client_local_instance;
82
83
    /* Load the remote control usage/value array info.  */
84
546
    array_start =  remote_control_instance -> ux_host_class_hid_remote_control_usage_array;
85
546
    array_end =    array_start + UX_HOST_CLASS_HID_REMOTE_CONTROL_USAGE_ARRAY_LENGTH;
86
546
    array_head =   remote_control_instance -> ux_host_class_hid_remote_control_usage_array_head;
87
546
    array_tail =   remote_control_instance -> ux_host_class_hid_remote_control_usage_array_tail;
88
89
    /* We have a single usage/value. We have to store it into the array. If the array overflows,
90
       there is no mechanism for flow control here so we ignore the usage/value until the
91
       applications makes more room in the array.  */
92
93
    /* Get position where next head will be.  */
94
546
    array_head_next =  array_head + 2;
95
96
    /* The head always points to where we will insert the next element. This
97
       is the reason for the wrap.  */
98
546
    if (array_head_next == array_end)
99
13
        array_head_next =  array_start;
100
101
    /* Do we have enough space to store the new usage?  */
102
546
    if (array_head_next != array_tail)
103
    {
104
105
        /* Yes, we have some space.  */
106
446
        *array_head =        callback -> ux_host_class_hid_report_callback_usage;
107
446
        *(array_head + 1) =  callback -> ux_host_class_hid_report_callback_value;
108
109
        /* Now update the array head.  */
110
446
        remote_control_instance -> ux_host_class_hid_remote_control_usage_array_head =  array_head_next;
111
    }
112
    else
113
    {
114
115
        /* If trace is enabled, insert this event into the trace buffer.  */
116
        UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_CLASS_HID_REMOTE_CONTROL_CALLBACK, hid_client, remote_control_instance, 0, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0)
117
118
        /* Notify application.  */
119
100
        _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_BUFFER_OVERFLOW);
120
    }
121
122
    /* Return to caller.  */
123
546
    return;
124
}
125