1 /**************************************************************************/ 2 /* */ 3 /* Copyright (c) Microsoft Corporation. All rights reserved. */ 4 /* */ 5 /* This software is licensed under the Microsoft Software License */ 6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */ 7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ 8 /* and in the root directory of this software. */ 9 /* */ 10 /**************************************************************************/ 11 12 13 /**************************************************************************/ 14 /**************************************************************************/ 15 /** */ 16 /** USBX Component */ 17 /** */ 18 /** Slave Simulator Controller Driver */ 19 /** */ 20 /**************************************************************************/ 21 /**************************************************************************/ 22 23 #define UX_SOURCE_CODE 24 25 26 /* Include necessary system files. */ 27 28 #include "ux_api.h" 29 #include "ux_dcd_sim_slave.h" 30 #include "ux_hcd_sim_host.h" 31 32 33 /**************************************************************************/ 34 /* */ 35 /* FUNCTION RELEASE */ 36 /* */ 37 /* _ux_dcd_sim_slave_initialize PORTABLE C */ 38 /* 6.1.6 */ 39 /* AUTHOR */ 40 /* */ 41 /* Chaoqiong Xiao, Microsoft Corporation */ 42 /* */ 43 /* DESCRIPTION */ 44 /* */ 45 /* This function initializes the USB simulation slave controller. */ 46 /* */ 47 /* INPUT */ 48 /* */ 49 /* None */ 50 /* */ 51 /* OUTPUT */ 52 /* */ 53 /* Completion Status */ 54 /* */ 55 /* CALLS */ 56 /* */ 57 /* _ux_utility_memory_allocate Allocate memory */ 58 /* */ 59 /* CALLED BY */ 60 /* */ 61 /* Slave Simulator Controller Driver */ 62 /* */ 63 /* RELEASE HISTORY */ 64 /* */ 65 /* DATE NAME DESCRIPTION */ 66 /* */ 67 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ 68 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ 69 /* resulting in version 6.1 */ 70 /* 04-02-2021 Chaoqiong Xiao Modified comment(s), */ 71 /* added link with HCD, */ 72 /* set device to full speed, */ 73 /* resulting in version 6.1.6 */ 74 /* */ 75 /**************************************************************************/ _ux_dcd_sim_slave_initialize(VOID)76UINT _ux_dcd_sim_slave_initialize(VOID) 77 { 78 79 UX_SLAVE_DCD *dcd; 80 UX_DCD_SIM_SLAVE *dcd_sim_slave; 81 UX_HCD *hcd; 82 83 84 /* Get the pointer to the DCD. */ 85 dcd = &_ux_system_slave -> ux_system_slave_dcd; 86 87 /* The controller initialized here is of Slave simulation type. */ 88 dcd -> ux_slave_dcd_controller_type = UX_DCD_SIM_SLAVE_SLAVE_CONTROLLER; 89 90 /* Allocate memory for this Slave simulation DCD instance. */ 91 dcd_sim_slave = _ux_utility_memory_allocate(UX_NO_ALIGN, UX_REGULAR_MEMORY, sizeof(UX_DCD_SIM_SLAVE)); 92 93 /* Check if memory was properly allocated. */ 94 if(dcd_sim_slave == UX_NULL) 95 return(UX_MEMORY_INSUFFICIENT); 96 97 /* Set the pointer to the Slave simulation DCD. */ 98 dcd -> ux_slave_dcd_controller_hardware = (VOID *) dcd_sim_slave; 99 100 /* Set the generic DCD owner for the Slave simulation DCD. */ 101 dcd_sim_slave -> ux_dcd_sim_slave_dcd_owner = dcd; 102 103 /* Initialize the function collector for this DCD. */ 104 dcd -> ux_slave_dcd_function = _ux_dcd_sim_slave_function; 105 106 /* Link the HCD (always first registered one) to DCD driver. */ 107 if (_ux_system_host) 108 { 109 hcd = _ux_system_host -> ux_system_host_hcd_array; 110 if (hcd) 111 { 112 dcd_sim_slave -> ux_dcd_sim_slave_hcd = (VOID *)hcd; 113 } 114 } 115 116 /* Set system to full speed by default. */ 117 _ux_system_slave -> ux_system_slave_speed = UX_FULL_SPEED_DEVICE; 118 119 /* Set the state of the controller to OPERATIONAL now. */ 120 dcd -> ux_slave_dcd_status = UX_DCD_STATUS_OPERATIONAL; 121 122 /* This operation completed with success. */ 123 return(UX_SUCCESS); 124 } 125 126