1 /* This tests the _ux_host_class_cdc_ecm_interrupt_notification function. */
2 
3 #include "usbx_ux_test_cdc_ecm.h"
4 
5 /* Define what the initial system looks like.  */
6 #ifdef CTEST
test_application_define(void * first_unused_memory)7 void test_application_define(void *first_unused_memory)
8 #else
9 void usbx_ux_host_class_cdc_ecm_interrupt_notification_test_application_define(void *first_unused_memory)
10 #endif
11 {
12 
13     /* Inform user.  */
14     printf("Running ux_host_class_cdc_ecm_interrupt_notification Test........... ");
15 
16     stepinfo("\n");
17 
18     ux_test_cdc_ecm_initialize(first_unused_memory);
19 }
20 
post_init_host()21 static void post_init_host()
22 {
23 
24 UX_HOST_CLASS_CDC_ECM   my_cdc_ecm;
25 UX_TRANSFER             transfer_request;
26 UCHAR                   transfer_request_data[16];
27 UX_ENDPOINT             endpoint;
28 ULONG                   notification_count;
29 
30     /** Test the class in shutdown mode. **/
31 
32     my_cdc_ecm.ux_host_class_cdc_ecm_state = UX_HOST_CLASS_INSTANCE_SHUTDOWN;
33     transfer_request.ux_transfer_request_class_instance = &my_cdc_ecm;
34     transfer_request.ux_transfer_request_completion_code = UX_SUCCESS;
35     _ux_host_class_cdc_ecm_interrupt_notification(&transfer_request);
36 
37     /** Test non-network connection message.  **/
38 
39     /* Create the action to ignore the transfer request. */
40     UX_TEST_ACTION action = {0};
41     action.usbx_function = UX_TEST_OVERRIDE_UX_HCD_SIM_HOST_ENTRY;
42     action.function = UX_HCD_TRANSFER_REQUEST;
43     action.req_action = UX_TEST_MATCH_EP;
44     action.req_ep_address = 0xff;
45     action.no_return = 0;
46     action.status = UX_SUCCESS;
47     ux_test_add_action_to_main_list(action);
48 
49     my_cdc_ecm.ux_host_class_cdc_ecm_state = UX_HOST_CLASS_INSTANCE_LIVE;
50     transfer_request_data[UX_HOST_CLASS_CDC_ECM_NPF_NOTIFICATION_TYPE] = (UCHAR)(UX_HOST_CLASS_CDC_ECM_NOTIFICATION_NETWORK_CONNECTION - 1);
51     endpoint.ux_endpoint_device = cdc_ecm_host->ux_host_class_cdc_ecm_device;
52     endpoint.ux_endpoint_descriptor.bEndpointAddress = 0xff;
53 
54     transfer_request.ux_transfer_request_class_instance = &my_cdc_ecm;
55     transfer_request.ux_transfer_request_data_pointer = transfer_request_data;
56     transfer_request.ux_transfer_request_endpoint = &endpoint;
57     transfer_request.ux_transfer_request_completion_code = UX_SUCCESS;
58 
59     _ux_host_class_cdc_ecm_interrupt_notification(&transfer_request);
60 
61     /** Test receiving LINK UP while link is already up. **/
62     ux_test_device_class_cdc_ecm_set_link_state(cdc_ecm_device, 1);
63 
64     /** Test receiving LINK UP while link is pending up. **/
65 
66     cdc_ecm_host->ux_host_class_cdc_ecm_link_state = UX_HOST_CLASS_CDC_ECM_LINK_STATE_PENDING_UP;
67 
68     /* Save the interrupt count so we know when the host has received the message. */
69     notification_count = cdc_ecm_host->ux_host_class_cdc_ecm_notification_count;
70 
71     ux_test_device_class_cdc_ecm_set_link_state(cdc_ecm_device, 1);
72 
73     /* Now wait for the host to receive it. Luckly, there's an increment count we can check! */
74     ux_test_wait_for_value_ulong(&cdc_ecm_host->ux_host_class_cdc_ecm_notification_count, notification_count + 1);
75 
76     cdc_ecm_host->ux_host_class_cdc_ecm_link_state = UX_HOST_CLASS_CDC_ECM_LINK_STATE_UP;
77 
78     /** Test receiving LINK DOWN while link is already down. **/
79 
80     /* Send the link down event. */
81     ux_test_device_class_cdc_ecm_set_link_state(cdc_ecm_device, 0);
82 
83     /* Wait for host to set the link to down. */
84     UX_TEST_CHECK_SUCCESS(ux_test_wait_for_value_ulong(&cdc_ecm_host->ux_host_class_cdc_ecm_link_state, 0));
85 
86     /* Save the interrupt count so we know when the host has received the message. */
87     notification_count = cdc_ecm_host->ux_host_class_cdc_ecm_notification_count;
88 
89     /* Send the link down event again. */
90     ux_test_device_class_cdc_ecm_set_link_state(cdc_ecm_device, 0);
91 
92     /* Now wait for the host to receive it. Luckly, there's an increment count we can check! */
93     ux_test_wait_for_value_ulong(&cdc_ecm_host->ux_host_class_cdc_ecm_notification_count, notification_count + 1);
94 
95     /** Test receiving LINK DOWN while link is pending down. **/
96 
97     cdc_ecm_host->ux_host_class_cdc_ecm_link_state = UX_HOST_CLASS_CDC_ECM_LINK_STATE_PENDING_DOWN;
98 
99     /* Save the interrupt count so we know when the host has received the message. */
100     notification_count = cdc_ecm_host->ux_host_class_cdc_ecm_notification_count;
101 
102     ux_test_device_class_cdc_ecm_set_link_state(cdc_ecm_device, 0);
103 
104     /* Now wait for the host to receive it. Luckly, there's an increment count we can check! */
105     ux_test_wait_for_value_ulong(&cdc_ecm_host->ux_host_class_cdc_ecm_notification_count, notification_count + 1);
106 
107     cdc_ecm_host->ux_host_class_cdc_ecm_link_state = UX_HOST_CLASS_CDC_ECM_LINK_STATE_DOWN;
108 }
109 
post_init_device()110 static void post_init_device()
111 {
112 }