blob: 4e99aee6fafb60fbe3698e3d9e3209850c6ea97b (
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
|
/***************************************************************************
* 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 Audio Class */
/** */
/**************************************************************************/
/**************************************************************************/
#define UX_SOURCE_CODE
/* Include necessary system files. */
#include "ux_api.h"
#include "ux_device_class_audio.h"
#include "ux_device_stack.h"
#if defined(UX_DEVICE_STANDALONE)
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _ux_device_class_audio_tasks_run PORTABLE C */
/* 6.2.0 */
/* AUTHOR */
/* */
/* Yajun Xia, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* This function is the background task of the audio. */
/* */
/* It's for standalone mode. */
/* */
/* INPUT */
/* */
/* instance Pointer to audio 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 */
/* */
/* (ux_device_class_audio_stream_task_function) */
/* Run stream task */
/* (ux_device_class_audio_stream_feedback_task_function) */
/* Run stream feedback task */
/* */
/* CALLED BY */
/* */
/* USBX Device Stack */
/* */
/**************************************************************************/
UINT _ux_device_class_audio_tasks_run(VOID *instance)
{
UX_SLAVE_DEVICE *device;
UX_DEVICE_CLASS_AUDIO *audio;
UX_DEVICE_CLASS_AUDIO_STREAM *stream;
ULONG stream_index;
UINT status;
#if defined(UX_DEVICE_CLASS_AUDIO_INTERRUPT_SUPPORT)
ULONG interrupt_running_count = 0;
#endif
ULONG stream_running_count = 0;
#if defined(UX_DEVICE_CLASS_AUDIO_FEEDBACK_SUPPORT)
ULONG feedback_running_count = 0;
#endif
/* Get audio instance. */
audio = (UX_DEVICE_CLASS_AUDIO *) instance;
/* 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);
#if defined(UX_DEVICE_CLASS_AUDIO_INTERRUPT_SUPPORT)
/* Run audio status tasks. */
status = _ux_device_class_audio_interrupt_task_function(audio);
if (status == UX_STATE_EXIT)
return(status);
if (status == UX_STATE_WAIT)
interrupt_running_count++;
#endif
for (stream_index = 0;
stream_index < audio -> ux_device_class_audio_streams_nb;
stream_index ++)
{
stream = &audio -> ux_device_class_audio_streams[stream_index];
status = stream -> ux_device_class_audio_stream_task_function(stream);
if (status == UX_STATE_EXIT)
return(status);
if (status == UX_STATE_WAIT)
stream_running_count ++;
#if defined(UX_DEVICE_CLASS_AUDIO_FEEDBACK_SUPPORT)
if (stream -> ux_device_class_audio_stream_feedback_task_function != UX_NULL)
{
status = stream -> ux_device_class_audio_stream_feedback_task_function(stream);
if (status == UX_STATE_EXIT)
return(status);
if (status == UX_STATE_WAIT)
feedback_running_count ++;
}
#endif
}
if ((stream_running_count > 0)
#if defined(UX_DEVICE_CLASS_AUDIO_INTERRUPT_SUPPORT)
|| (interrupt_running_count > 0)
#endif
#if defined(UX_DEVICE_CLASS_AUDIO_FEEDBACK_SUPPORT)
|| (feedback_running_count > 0)
#endif
)
{
return UX_STATE_WAIT;
}
else
{
return UX_STATE_IDLE;
}
}
#endif
|