1 /***************************************************************************
2  * Copyright (c) 2024 Microsoft Corporation
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the MIT License which is available at
6  * https://opensource.org/licenses/MIT.
7  *
8  * SPDX-License-Identifier: MIT
9  **************************************************************************/
10 
11 
12 /**************************************************************************/
13 /**************************************************************************/
14 /**                                                                       */
15 /** USBX Component                                                        */
16 /**                                                                       */
17 /**   Host Simulator Controller Driver                                    */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 #define UX_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 
27 #include "ux_api.h"
28 #include "ux_hcd_sim_host.h"
29 
30 #if !defined(UX_HOST_STANDALONE)
31 #include "tx_timer.h"
32 
33 
34 /**************************************************************************/
35 /*                                                                        */
36 /*  FUNCTION                                               RELEASE        */
37 /*                                                                        */
38 /*    _ux_hcd_sim_host_timer_function                     PORTABLE C      */
39 /*                                                           6.1.10       */
40 /*  AUTHOR                                                                */
41 /*                                                                        */
42 /*    Chaoqiong Xiao, Microsoft Corporation                               */
43 /*                                                                        */
44 /*  DESCRIPTION                                                           */
45 /*                                                                        */
46 /*     This function is the timer function of the simulator. It is        */
47 /*     invoked on a timer every tick.                                     */
48 /*                                                                        */
49 /*     It's for RTOS mode.                                                */
50 /*                                                                        */
51 /*  INPUT                                                                 */
52 /*                                                                        */
53 /*    hcd_sim_host_addr                     Address of host controller    */
54 /*                                                                        */
55 /*  OUTPUT                                                                */
56 /*                                                                        */
57 /*    None                                                                */
58 /*                                                                        */
59 /*  CALLS                                                                 */
60 /*                                                                        */
61 /*    _ux_utility_semaphore_put             Put semaphore                 */
62 /*                                                                        */
63 /*  CALLED BY                                                             */
64 /*                                                                        */
65 /*    ThreadX                                                             */
66 /*                                                                        */
67 /*  RELEASE HISTORY                                                       */
68 /*                                                                        */
69 /*    DATE              NAME                      DESCRIPTION             */
70 /*                                                                        */
71 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
72 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
73 /*                                            resulting in version 6.1    */
74 /*  01-31-2022     Chaoqiong Xiao           Modified comment(s),          */
75 /*                                            used macros to configure    */
76 /*                                            for RTOS mode compile,      */
77 /*                                            resulting in version 6.1.10 */
78 /*                                                                        */
79 /**************************************************************************/
_ux_hcd_sim_host_timer_function(ULONG hcd_sim_host_addr)80 VOID  _ux_hcd_sim_host_timer_function(ULONG hcd_sim_host_addr)
81 {
82 
83 UX_HCD_SIM_HOST     *hcd_sim_host;
84 UX_HCD              *hcd;
85 
86 
87     /* Setup pointer to simulator host structure.  */
88     UX_TIMER_EXTENSION_PTR_GET(hcd_sim_host, UX_HCD_SIM_HOST, hcd_sim_host_addr)
89 
90     /* Get the pointers to the generic HCD areas.  */
91     hcd =  hcd_sim_host -> ux_hcd_sim_host_hcd_owner;
92 
93     /* Increase the interrupt count. This indicates the controller is still alive.  */
94     hcd_sim_host -> ux_hcd_sim_host_interrupt_count++;
95 
96     /* Check if the controller is operational, if not, skip it.  */
97     if (hcd -> ux_hcd_status == UX_HCD_STATUS_OPERATIONAL)
98     {
99 
100         /* Wake up the thread for the controller transaction processing.  */
101         hcd -> ux_hcd_thread_signal++;
102         _ux_host_semaphore_put(&_ux_system_host -> ux_system_host_hcd_semaphore);
103     }
104 }
105 #endif
106