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 /**   Slave 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_dcd_sim_slave.h"
29 #include "ux_hcd_sim_host.h"
30 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _ux_dcd_sim_slave_initialize                        PORTABLE C      */
37 /*                                                           6.1.6        */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Chaoqiong Xiao, Microsoft Corporation                               */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function initializes the USB simulation slave controller.      */
45 /*                                                                        */
46 /*  INPUT                                                                 */
47 /*                                                                        */
48 /*    None                                                                */
49 /*                                                                        */
50 /*  OUTPUT                                                                */
51 /*                                                                        */
52 /*    Completion Status                                                   */
53 /*                                                                        */
54 /*  CALLS                                                                 */
55 /*                                                                        */
56 /*    _ux_utility_memory_allocate           Allocate memory               */
57 /*                                                                        */
58 /*  CALLED BY                                                             */
59 /*                                                                        */
60 /*    Slave Simulator Controller Driver                                   */
61 /*                                                                        */
62 /*  RELEASE HISTORY                                                       */
63 /*                                                                        */
64 /*    DATE              NAME                      DESCRIPTION             */
65 /*                                                                        */
66 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
67 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
68 /*                                            resulting in version 6.1    */
69 /*  04-02-2021     Chaoqiong Xiao           Modified comment(s),          */
70 /*                                            added link with HCD,        */
71 /*                                            set device to full speed,   */
72 /*                                            resulting in version 6.1.6  */
73 /*                                                                        */
74 /**************************************************************************/
_ux_dcd_sim_slave_initialize(VOID)75 UINT  _ux_dcd_sim_slave_initialize(VOID)
76 {
77 
78 UX_SLAVE_DCD            *dcd;
79 UX_DCD_SIM_SLAVE        *dcd_sim_slave;
80 UX_HCD                  *hcd;
81 
82 
83     /* Get the pointer to the DCD.  */
84     dcd = &_ux_system_slave -> ux_system_slave_dcd;
85 
86     /* The controller initialized here is of Slave simulation type.  */
87     dcd -> ux_slave_dcd_controller_type =  UX_DCD_SIM_SLAVE_SLAVE_CONTROLLER;
88 
89     /* Allocate memory for this Slave simulation DCD instance.  */
90     dcd_sim_slave =  _ux_utility_memory_allocate(UX_NO_ALIGN, UX_REGULAR_MEMORY, sizeof(UX_DCD_SIM_SLAVE));
91 
92     /* Check if memory was properly allocated.  */
93     if(dcd_sim_slave == UX_NULL)
94         return(UX_MEMORY_INSUFFICIENT);
95 
96     /* Set the pointer to the Slave simulation DCD.  */
97     dcd -> ux_slave_dcd_controller_hardware =  (VOID *) dcd_sim_slave;
98 
99     /* Set the generic DCD owner for the Slave simulation DCD.  */
100     dcd_sim_slave -> ux_dcd_sim_slave_dcd_owner =  dcd;
101 
102     /* Initialize the function collector for this DCD.  */
103     dcd -> ux_slave_dcd_function =  _ux_dcd_sim_slave_function;
104 
105     /* Link the HCD (always first registered one) to DCD driver.  */
106     if (_ux_system_host)
107     {
108         hcd = _ux_system_host -> ux_system_host_hcd_array;
109         if (hcd)
110         {
111             dcd_sim_slave -> ux_dcd_sim_slave_hcd = (VOID *)hcd;
112         }
113     }
114 
115     /* Set system to full speed by default.  */
116     _ux_system_slave -> ux_system_slave_speed = UX_FULL_SPEED_DEVICE;
117 
118     /* Set the state of the controller to OPERATIONAL now.  */
119     dcd -> ux_slave_dcd_status =  UX_DCD_STATUS_OPERATIONAL;
120 
121     /* This operation completed with success. */
122     return(UX_SUCCESS);
123 }
124 
125