blob: e93d45c65e7dc2242930caf62d5252fda27f0fcc (
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
|
/***************************************************************************
* 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 */
/** */
/** Device CCID Class */
/** */
/**************************************************************************/
/**************************************************************************/
#define UX_SOURCE_CODE
/* Include necessary system files. */
#include "ux_api.h"
#include "ux_device_class_ccid.h"
#include "ux_device_stack.h"
#if defined(UX_DEVICE_STANDALONE)
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _ux_device_class_ccid_notify_task_run PORTABLE C */
/* 6.2.1 */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* This function is the background task of the CCID. */
/* */
/* It's for standalone mode. */
/* */
/* INPUT */
/* */
/* ccid Pointer to CCID class */
/* */
/* OUTPUT */
/* */
/* State machine status */
/* UX_STATE_EXIT Device not configured */
/* UX_STATE_IDLE No streaming transfer running */
/* UX_STATE_WAIT Streaming transfer running */
/* */
/* CALLS */
/* */
/* */
/* CALLED BY */
/* */
/* USBX Device Stack */
/* */
/**************************************************************************/
UINT _ux_device_class_ccid_notify_task_run(UX_DEVICE_CLASS_CCID *ccid)
{
UX_INTERRUPT_SAVE_AREA
UX_SLAVE_DEVICE *device;
UX_DEVICE_CLASS_CCID_SLOT *slot;
UX_SLAVE_ENDPOINT *endpoint;
UX_SLAVE_TRANSFER *transfer;
UCHAR *buffer;
ULONG length;
UCHAR icc_mask;
INT immediate_state = UX_TRUE;
UINT status;
/* Get the pointer to the device. */
device = &_ux_system_slave -> ux_system_slave_device;
/* Check if the device is configured. */
if (device -> ux_slave_device_state != UX_DEVICE_CONFIGURED)
return(UX_STATE_EXIT);
/* Interrupt IN endpoint get (it's optional so it's OK not found). */
endpoint = ccid -> ux_device_class_ccid_endpoint_notify;
if (endpoint == UX_NULL)
return(UX_STATE_IDLE);
transfer = &endpoint -> ux_slave_endpoint_transfer_request;
/* Process states. */
while(immediate_state)
{
/* Check states. */
switch(ccid -> ux_device_class_ccid_notify_state)
{
case UX_DEVICE_CLASS_CCID_NOTIFY_IDLE:
return(UX_STATE_IDLE);
case UX_DEVICE_CLASS_CCID_NOTIFY_LOCK:
/* Wait until status locked. */
UX_DISABLE
if (ccid -> ux_device_class_ccid_flags & UX_DEVICE_CLASS_CCID_FLAG_LOCK)
{
UX_RESTORE
return(UX_STATE_WAIT);
}
ccid -> ux_device_class_ccid_flags |= UX_DEVICE_CLASS_CCID_FLAG_LOCK;
UX_RESTORE
/* Next: check if there is notification pending. */
ccid -> ux_device_class_ccid_notify_state = UX_DEVICE_CLASS_CCID_NOTIFY_START;
/* Fall through. */
case UX_DEVICE_CLASS_CCID_NOTIFY_START:
/* Check slot notifications (optimized for only one slot). */
/* Get slot. */
slot = ccid -> ux_device_class_ccid_slots;
/* Build slot change/hardware error message. */
buffer = transfer -> ux_slave_transfer_request_data_pointer;
length = 0;
/* By default no message. */
buffer[UX_DEVICE_CLASS_CCID_OFFSET_MESSAGE_TYPE] = 0;
/* Check hardware error notification. */
if (slot -> ux_device_class_ccid_slot_flags &
UX_DEVICE_CLASS_CCID_FLAG_NOTIFY_HW_ERROR)
{
slot -> ux_device_class_ccid_slot_flags &=
(UCHAR)~UX_DEVICE_CLASS_CCID_FLAG_NOTIFY_HW_ERROR;
buffer[UX_DEVICE_CLASS_CCID_OFFSET_MESSAGE_TYPE] =
UX_DEVICE_CLASS_CCID_RDR_TO_PC_HARDWARE_ERROR;
buffer[UX_DEVICE_CLASS_CCID_OFFSET_HW_ERROR_SLOT] = 0;
buffer[UX_DEVICE_CLASS_CCID_OFFSET_HW_ERROR_SEQ] =
slot -> ux_device_class_ccid_slot_hw_error_seq;
buffer[UX_DEVICE_CLASS_CCID_OFFSET_HW_ERROR_CODE] =
slot -> ux_device_class_ccid_slot_hw_error;
length = 4;
}
/* Check slot change notification. */
else if (slot -> ux_device_class_ccid_slot_flags &
UX_DEVICE_CLASS_CCID_FLAG_NOTIFY_CHANGE)
{
slot -> ux_device_class_ccid_slot_flags &=
(UCHAR)~UX_DEVICE_CLASS_CCID_FLAG_NOTIFY_CHANGE;
/* Message type. */
buffer[UX_DEVICE_CLASS_CCID_OFFSET_MESSAGE_TYPE] =
UX_DEVICE_CLASS_CCID_RDR_TO_PC_NOTIFY_SLOT_CHANGE;
/* Slot state bit. */
icc_mask = (UCHAR)((slot -> ux_device_class_ccid_slot_icc_status ==
UX_DEVICE_CLASS_CCID_SLOT_STATUS_ICC_NOT_PRESENT) ?
0u : 1u);
/* Slot change bit. */
icc_mask |= 0x02u;
/* Save slot state and change. */
buffer[UX_DEVICE_CLASS_CCID_OFFSET_SLOT_ICC_STATE] = icc_mask;
length = 2;
}
/* Unlock status. */
ccid -> ux_device_class_ccid_flags &= ~UX_DEVICE_CLASS_CCID_FLAG_LOCK;
/* Check message to see if there is message to send. */
if (buffer[UX_DEVICE_CLASS_CCID_OFFSET_MESSAGE_TYPE] == 0)
{
/* There is no pending meesage, -> idle. */
ccid -> ux_device_class_ccid_notify_state = UX_DEVICE_CLASS_CCID_NOTIFY_IDLE;
return(UX_STATE_IDLE);
}
/* There is message to send. */
UX_SLAVE_TRANSFER_STATE_RESET(transfer);
transfer -> ux_slave_transfer_request_requested_length = length;
ccid -> ux_device_class_ccid_notify_state = UX_DEVICE_CLASS_CCID_NOTIFY_WAIT;
/* Fall through. */
case UX_DEVICE_CLASS_CCID_NOTIFY_WAIT:
length = transfer -> ux_slave_transfer_request_requested_length;
status = _ux_device_stack_transfer_run(transfer, length, length);
/* Error/success (done) case. */
if (status <= UX_STATE_NEXT)
{
/* Transfer done, check if there is pending message. */
ccid -> ux_device_class_ccid_notify_state = UX_DEVICE_CLASS_CCID_NOTIFY_LOCK;
return(UX_STATE_WAIT);
}
/* Wait transfer. */
return(UX_STATE_WAIT);
default:
break;
}
}
/* Unhandled state. */
return(UX_STATE_EXIT);
}
#endif
|