summaryrefslogtreecommitdiff
path: root/common/usbx_host_classes/src/ux_host_class_prolific_transfer_request_completed.c
blob: a19c94bad20134becc5d67efac3c575690e0f805 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/***************************************************************************
 * Copyright (c) 2024 Microsoft Corporation
 * Copyright (c) 2026-present Eclipse ThreadX contributors
 *
 * This program and the accompanying materials are made available under the
 * terms of the MIT License which is available at
 * https://opensource.org/licenses/MIT.
 *
 * SPDX-License-Identifier: MIT
 **************************************************************************/


/**************************************************************************/
/**************************************************************************/
/**                                                                       */
/** USBX Component                                                        */
/**                                                                       */
/**   PROLIFIC Class                                                      */
/**                                                                       */
/**************************************************************************/
/**************************************************************************/


/* Include necessary system files.  */

#define UX_SOURCE_CODE

#include "ux_api.h"
#include "ux_host_class_prolific.h"
#include "ux_host_stack.h"


/**************************************************************************/
/*                                                                        */
/*  FUNCTION                                               RELEASE        */
/*                                                                        */
/*    _ux_host_class_prolific_transfer_request_completed  PORTABLE C      */
/*                                                           6.1.9        */
/*  AUTHOR                                                                */
/*                                                                        */
/*    Chaoqiong Xiao, Microsoft Corporation                               */
/*                                                                        */
/*  DESCRIPTION                                                           */
/*                                                                        */
/*    This function is called by the completion thread when a transfer    */
/*    request has been completed either because the transfer is           */
/*    successful or there was an error.                                   */
/*                                                                        */
/*  INPUT                                                                 */
/*                                                                        */
/*    transfer_request                      Pointer to transfer request   */
/*                                                                        */
/*  OUTPUT                                                                */
/*                                                                        */
/*    None                                                                */
/*                                                                        */
/*  CALLS                                                                 */
/*                                                                        */
/*    _ux_host_stack_transfer_request       Transfer request              */
/*                                                                        */
/*  CALLED BY                                                             */
/*                                                                        */
/*    USBX stack                                                          */
/*                                                                        */
/**************************************************************************/
VOID  _ux_host_class_prolific_transfer_request_completed(UX_TRANSFER *transfer_request)
{

UX_HOST_CLASS_PROLIFIC                   *prolific;


    /* Get the class instance for this transfer request.  */
    prolific =  (UX_HOST_CLASS_PROLIFIC *) transfer_request -> ux_transfer_request_class_instance;

    /* Check the state of the transfer.  If there is an error, we do not proceed with this notification.  */
    if (transfer_request -> ux_transfer_request_completion_code != UX_SUCCESS)

        /* We do not proceed.  */
        return;

    /* Check if the class is in shutdown.  */
    if (prolific -> ux_host_class_prolific_state ==  UX_HOST_CLASS_INSTANCE_SHUTDOWN)

        /* We do not proceed.  */
        return;

    /* Increment the notification count.   */
    prolific -> ux_host_class_prolific_notification_count++;

    /* Look at what the the status is.  First ensure the length of our interrupt pipe data is correct.  */
    if (transfer_request -> ux_transfer_request_actual_length ==
                    transfer_request -> ux_transfer_request_requested_length)
    {

        /* Check if device is present.  */
        if ((*(transfer_request -> ux_transfer_request_data_pointer + UX_HOST_CLASS_PROLIFIC_DEVICE_STATE_OFFSET) &
                UX_HOST_CLASS_PROLIFIC_DEVICE_STATE_MASK) == 0)

            /* Device is not present.  */
            prolific -> ux_host_class_prolific_device_state =  UX_HOST_CLASS_PROLIFIC_DEVICE_NOT_PRESENT;

        else

            /* Device is present.  */
            prolific -> ux_host_class_prolific_device_state =  UX_HOST_CLASS_PROLIFIC_DEVICE_PRESENT;

        /* If there is a callback present, invoke it.  */
        if (prolific -> ux_host_class_prolific_device_status_change_callback != UX_NULL)

            /* There is a callback, send the status change to the application.  */
            prolific -> ux_host_class_prolific_device_status_change_callback(prolific, prolific -> ux_host_class_prolific_device_state);

    }

    /* Reactivate the PROLIFIC interrupt pipe.  */
    _ux_host_stack_transfer_request(transfer_request);

    /* Return to caller.  */
    return;
}