Skip to content

Commit 27ea01c

Browse files
committed
Update demo_device_hid_mouse_rtos.c
1 parent 6dc0cf2 commit 27ea01c

File tree

9 files changed

+1038
-490
lines changed

9 files changed

+1038
-490
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: USBX Samples Thredx Test
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches: [ master ]
7+
pull_request:
8+
branches: [ master ]
9+
10+
jobs:
11+
samples_threadx_tests:
12+
permissions:
13+
contents: read
14+
issues: read
15+
checks: write
16+
pull-requests: write
17+
pages: write
18+
id-token: write
19+
20+
uses: eclipse-threadx/threadx/.github/workflows/regression_template.yml@master
21+
with:
22+
cmake_path: ./test/cmake/usbx_samples_threadx
23+
build_script: bash ./scripts/build_samples_threadx.sh all
24+
test_script: bash ./scripts/test_samples_threadx.sh all
25+
coverage_name: default_build_coverage
26+
skip_coverage: false

samples/demo_device_hid_mouse_rtos.c

Lines changed: 429 additions & 490 deletions
Large diffs are not rendered by default.

scripts/build_samples_threadx.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
bash $(dirname `realpath $0`)/../test/cmake/usbx_samples_threadx/run.sh build $@

scripts/test_samples_threadx.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
CTEST_PARALLEL_LEVEL=4 bash $(dirname `realpath $0`)/../test/cmake/usbx_samples_threadx/run.sh test $@
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
2+
cmake_policy(SET CMP0054 NEW)
3+
cmake_policy(SET CMP0057 NEW)
4+
cmake_policy(SET CMP0077 NEW)
5+
6+
project(usbx_samples_threadx_test LANGUAGES C)
7+
8+
# Reuse repository test user configuration.
9+
set(UX_USER_FILE ${CMAKE_CURRENT_LIST_DIR}/../usbx/ux_user.h)
10+
11+
set(BUILD_CONFIGURATIONS default_build_coverage)
12+
13+
set(CMAKE_CONFIGURATION_TYPES
14+
${BUILD_CONFIGURATIONS}
15+
CACHE STRING "list of supported configuration types" FORCE)
16+
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
17+
${CMAKE_CONFIGURATION_TYPES})
18+
list(GET CMAKE_CONFIGURATION_TYPES 0 BUILD_TYPE)
19+
if((NOT CMAKE_BUILD_TYPE) OR (NOT ("${CMAKE_BUILD_TYPE}" IN_LIST
20+
CMAKE_CONFIGURATION_TYPES)))
21+
set(CMAKE_BUILD_TYPE
22+
"${BUILD_TYPE}"
23+
CACHE STRING "Build Type of the project" FORCE)
24+
endif()
25+
26+
message(STATUS "Build for usbx sample ThreadX tests")
27+
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
28+
message(STATUS "Using toolchain file: ${CMAKE_TOOLCHAIN_FILE}.")
29+
30+
add_compile_options(
31+
-std=c99
32+
-ggdb
33+
-g3
34+
-gdwarf-2
35+
-fdiagnostics-color
36+
-DUX_USE_IO_INSTRUCTIONS
37+
-DNX_PHYSICAL_HEADER=20
38+
-DUX_DISABLE_ASSERT)
39+
40+
# Control if it's for 64 bit or 32 bit.
41+
if($ENV{ENABLE_64})
42+
message(STATUS "Building for 64bit")
43+
else()
44+
add_compile_options(-m32)
45+
add_link_options(-m32)
46+
message(STATUS "Building for 32bit")
47+
endif()
48+
49+
enable_testing()
50+
51+
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../../../ usbx)
52+
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/regression regression)
53+
54+
# Build ThreadX-related libs once and import them for tests.
55+
execute_process(COMMAND bash ${CMAKE_CURRENT_SOURCE_DIR}/run.sh build_libs)
56+
add_custom_target(build_libs ALL COMMAND bash ${CMAKE_CURRENT_SOURCE_DIR}/run.sh
57+
build_libs)
58+
59+
add_dependencies(usbx build_libs)
60+
target_include_directories(usbx PUBLIC ${CMAKE_BINARY_DIR}/../libs/inc)
61+
62+
add_library(threadx SHARED IMPORTED GLOBAL)
63+
add_library("azrtos::threadx" ALIAS threadx)
64+
set_target_properties(
65+
threadx PROPERTIES IMPORTED_LOCATION
66+
${CMAKE_BINARY_DIR}/../libs/threadx/libthreadx.so)
67+
68+
add_library(netxduo SHARED IMPORTED GLOBAL)
69+
add_library("azrtos::netxduo" ALIAS netxduo)
70+
set_target_properties(
71+
netxduo PROPERTIES IMPORTED_LOCATION
72+
${CMAKE_BINARY_DIR}/../libs/netxduo/libnetxduo.so)
73+
74+
add_library(filex SHARED IMPORTED GLOBAL)
75+
add_library("azrtos::filex" ALIAS filex)
76+
set_target_properties(
77+
filex PROPERTIES IMPORTED_LOCATION
78+
${CMAKE_BINARY_DIR}/../libs/filex/libfilex.so)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
2+
cmake_policy(SET CMP0057 NEW)
3+
4+
project(usbx_samples_threadx_regression LANGUAGES C)
5+
6+
get_filename_component(SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../regression_samples_threadx ABSOLUTE)
7+
get_filename_component(SAMPLE_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../../samples ABSOLUTE)
8+
9+
set(test_utility_files
10+
${SOURCE_DIR}/usbxtestcontrol.c)
11+
12+
add_library(test_utility ${test_utility_files})
13+
target_link_libraries(test_utility PUBLIC azrtos::usbx azrtos::threadx azrtos::netxduo azrtos::filex)
14+
target_compile_definitions(test_utility PUBLIC CTEST)
15+
16+
set(sample_test_case ${SOURCE_DIR}/usbx_hid_mouse_demo_device_rtos_test.c)
17+
set(sample_source_file ${SAMPLE_SOURCE_DIR}/demo_device_hid_mouse_rtos.c)
18+
set(test_name usbx_hid_mouse_demo_device_rtos_test)
19+
20+
add_executable(${test_name} ${sample_test_case} ${sample_source_file})
21+
target_link_libraries(${test_name} PRIVATE test_utility)
22+
target_compile_definitions(${test_name} PRIVATE DEMO_TEST EXTERNAL_MAIN)
23+
24+
add_test(default_build_coverage::${test_name} ${test_name})
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
cd $(dirname $0)
4+
5+
# Checkout externals.
6+
[ -d externals ] || mkdir ../../externals
7+
git clone https://github.com/eclipse-threadx/threadx.git ../../externals/threadx
8+
git clone https://github.com/eclipse-threadx/netxduo.git ../../externals/netxduo
9+
git clone https://github.com/eclipse-threadx/filex.git ../../externals/filex
10+
11+
# Add junit output for ctest generation.
12+
if ! grep -q "\-\-output\-junit \$1.xml" ../../externals/threadx/scripts/cmake_bootstrap.sh; then
13+
sed -i 's/ctest $parallel --timeout 1000 -O $1.txt/& --output-junit $1.xml/g' ../../externals/threadx/scripts/cmake_bootstrap.sh
14+
fi
15+
16+
[ -f .run.sh ] || ln -sf ../../externals/threadx/scripts/cmake_bootstrap.sh .run.sh
17+
./.run.sh $*
Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
/* Direct SIL regression test for samples/demo_device_hid_mouse_rtos.c */
2+
#include <stdio.h>
3+
#include "ux_api.h"
4+
#include "ux_host_class_hid.h"
5+
#include "ux_host_class_hid_mouse.h"
6+
7+
void test_control_return(UINT status);
8+
extern UINT ux_demo_init(VOID);
9+
10+
UX_HOST_CLASS_HID_MOUSE *mouse = UX_NULL;
11+
UX_HOST_CLASS_HID *hid_instance = UX_NULL;
12+
static UINT ux_host_event_callback(ULONG event, UX_HOST_CLASS *current_class, VOID *current_instance);
13+
14+
/* Ensure device-only demo compiles within the test. */
15+
#define UX_DEMO_STACK_SIZE 1024
16+
static UX_THREAD ux_demo_thread_host_simulation;
17+
static ULONG ux_simulation_thread_stack[UX_DEMO_STACK_SIZE / sizeof(ULONG)];
18+
static void tx_demo_thread_host_simulation_entry(ULONG arg);
19+
20+
void usbx_hid_mouse_demo_device_rtos_test_application_define(void *first_unused_memory)
21+
{
22+
UX_PARAMETER_NOT_USED(first_unused_memory);
23+
24+
UINT status;
25+
26+
printf("Running HID Mouse Demo Test............................ ");
27+
28+
29+
/* Initialize device side using the demo's API (creates its HID thread). */
30+
status = ux_demo_init();
31+
32+
if (status != UX_SUCCESS)
33+
{
34+
printf("Demo device init fail\n");
35+
test_control_return(1);
36+
}
37+
38+
/* Initialize host side. */
39+
status = ux_host_stack_initialize(ux_host_event_callback);
40+
41+
if (status != UX_SUCCESS)
42+
{
43+
printf("Host init fail\n");
44+
test_control_return(1);
45+
}
46+
47+
status = ux_host_stack_class_register(_ux_system_host_class_hid_name, ux_host_class_hid_entry);
48+
49+
if (status != UX_SUCCESS)
50+
{
51+
printf("Host HID reg fail\n");
52+
test_control_return(1);
53+
}
54+
55+
status = ux_host_class_hid_client_register(_ux_system_host_class_hid_client_mouse_name, ux_host_class_hid_mouse_entry);
56+
57+
if (status != UX_SUCCESS)
58+
{
59+
printf("Host mouse client reg fail\n");
60+
test_control_return(1);
61+
}
62+
63+
/* Register all the USB host controllers available in this system */
64+
status = ux_host_stack_hcd_register(_ux_system_host_hcd_simulator_name, ux_hcd_sim_host_initialize,0,0);
65+
66+
/* Check for error. */
67+
if (status != UX_SUCCESS)
68+
{
69+
70+
printf("Error on line %d, error code: %d\n", __LINE__, status);
71+
test_control_return(1);
72+
}
73+
74+
/* Create the main host simulation thread. */
75+
status = ux_utility_thread_create(&ux_demo_thread_host_simulation, "tx demo host simulation",
76+
tx_demo_thread_host_simulation_entry, 0, ux_simulation_thread_stack,
77+
UX_DEMO_STACK_SIZE, 20, 20, 1, UX_AUTO_START);
78+
79+
/* Check for error. */
80+
if (status != UX_SUCCESS)
81+
{
82+
83+
printf("Error on line %d, error code: %d\n", __LINE__, status);
84+
test_control_return(1);
85+
}
86+
87+
}
88+
89+
static void tx_demo_thread_host_simulation_entry(ULONG arg)
90+
{
91+
92+
UINT status;
93+
94+
ULONG cur_mouse_buttons = 0;
95+
SLONG cur_mouse_x_position = 0;
96+
SLONG cur_mouse_y_position = 0;
97+
SLONG cur_mouse_wheel_movement = 0;
98+
ULONG timeout_count = 0;
99+
100+
101+
while (1)
102+
{
103+
/* Start if the hid client is a mouse and connected */
104+
if ((mouse != NULL) &&
105+
(mouse -> ux_host_class_hid_mouse_state == (ULONG) UX_HOST_CLASS_INSTANCE_LIVE))
106+
{
107+
108+
status = ux_host_class_hid_mouse_buttons_get(mouse, &cur_mouse_buttons);
109+
if (status != UX_SUCCESS)
110+
{
111+
112+
printf("Error on line %d\n", __LINE__);
113+
test_control_return(1);
114+
}
115+
116+
status = ux_host_class_hid_mouse_position_get(mouse, &cur_mouse_x_position, &cur_mouse_y_position);
117+
if (status != UX_SUCCESS)
118+
{
119+
120+
printf("Error on line %d\n", __LINE__);
121+
test_control_return(1);
122+
}
123+
124+
status = ux_host_class_hid_mouse_wheel_get(mouse, &cur_mouse_wheel_movement);
125+
if (status != UX_SUCCESS)
126+
{
127+
128+
printf("Error on line %d\n", __LINE__);
129+
test_control_return(1);
130+
}
131+
132+
status = ux_host_class_hid_mouse_position_get(mouse, &cur_mouse_x_position, &cur_mouse_y_position);
133+
if (status != UX_SUCCESS)
134+
{
135+
136+
printf("Error on line %d\n", __LINE__);
137+
test_control_return(1);
138+
}
139+
140+
if ((cur_mouse_x_position != 0) || (cur_mouse_y_position != 0))
141+
{
142+
143+
printf("SUCCESS!\n");
144+
test_control_return(0);
145+
return;
146+
}
147+
148+
}
149+
else
150+
{
151+
timeout_count ++;
152+
if (timeout_count > 500)
153+
{
154+
155+
printf("Timeout waiting for HID mouse traffic\n");
156+
test_control_return(1);
157+
return;
158+
}
159+
ux_utility_delay_ms(MS_TO_TICK(10));
160+
}
161+
}
162+
163+
164+
}
165+
166+
static UINT ux_host_event_callback(ULONG event, UX_HOST_CLASS *current_class, VOID *current_instance)
167+
{
168+
UINT status = UX_SUCCESS;
169+
170+
/* Get current Hid Client */
171+
UX_HOST_CLASS_HID_CLIENT *client = (UX_HOST_CLASS_HID_CLIENT *)current_instance;
172+
173+
switch (event)
174+
{
175+
case UX_DEVICE_INSERTION:
176+
177+
/* Get current Hid Class */
178+
if (current_class -> ux_host_class_entry_function == ux_host_class_hid_entry)
179+
{
180+
if (hid_instance == UX_NULL)
181+
{
182+
/* Get current Hid Instance */
183+
hid_instance = (UX_HOST_CLASS_HID *)current_instance;
184+
}
185+
}
186+
187+
break;
188+
189+
case UX_DEVICE_REMOVAL:
190+
191+
/* Free HID Instance */
192+
if ((VOID*)hid_instance == current_instance)
193+
{
194+
hid_instance = UX_NULL;
195+
}
196+
197+
break;
198+
199+
case UX_HID_CLIENT_INSERTION:
200+
201+
/* Check the HID_client if this is a HID mouse device */
202+
if (client -> ux_host_class_hid_client_handler == ux_host_class_hid_mouse_entry)
203+
{
204+
/* Get current Hid Client */
205+
if (mouse == UX_NULL)
206+
{
207+
mouse = client -> ux_host_class_hid_client_local_instance;
208+
}
209+
}
210+
211+
212+
break;
213+
214+
case UX_HID_CLIENT_REMOVAL:
215+
216+
217+
if ((VOID*)mouse == client -> ux_host_class_hid_client_local_instance)
218+
{
219+
/* Clear hid mouse instance */
220+
mouse = UX_NULL;
221+
}
222+
223+
break;
224+
225+
case UX_DEVICE_CONNECTION:
226+
break;
227+
228+
case UX_DEVICE_DISCONNECTION:
229+
break;
230+
231+
default:
232+
break;
233+
}
234+
235+
return status;
236+
}
237+

0 commit comments

Comments
 (0)