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 /** Host 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_hcd_sim_host.h" 30 31 32 /**************************************************************************/ 33 /* */ 34 /* FUNCTION RELEASE */ 35 /* */ 36 /* _ux_hcd_sim_host_regular_td_obtain PORTABLE C */ 37 /* 6.1.10 */ 38 /* AUTHOR */ 39 /* */ 40 /* Chaoqiong Xiao, Microsoft Corporation */ 41 /* */ 42 /* DESCRIPTION */ 43 /* */ 44 /* This function obtains a free TD from the regular TD list. */ 45 /* */ 46 /* INPUT */ 47 /* */ 48 /* hcd_sim_host Pointer to host controller */ 49 /* */ 50 /* OUTPUT */ 51 /* */ 52 /* UX_HCD_SIM_HOST_TD * Pointer to host TD */ 53 /* */ 54 /* CALLS */ 55 /* */ 56 /* _ux_utility_memory_set Set memory block */ 57 /* _ux_utility_mutex_on Get mutex protection */ 58 /* _ux_utility_mutex_off Release mutex protection */ 59 /* */ 60 /* CALLED BY */ 61 /* */ 62 /* Host Simulator Controller Driver */ 63 /* */ 64 /* RELEASE HISTORY */ 65 /* */ 66 /* DATE NAME DESCRIPTION */ 67 /* */ 68 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ 69 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ 70 /* verified memset and memcpy */ 71 /* cases, */ 72 /* resulting in version 6.1 */ 73 /* 01-31-2022 Chaoqiong Xiao Modified comment(s), */ 74 /* added standalone support, */ 75 /* resulting in version 6.1.10 */ 76 /* */ 77 /**************************************************************************/ _ux_hcd_sim_host_regular_td_obtain(UX_HCD_SIM_HOST * hcd_sim_host)78UX_HCD_SIM_HOST_TD *_ux_hcd_sim_host_regular_td_obtain(UX_HCD_SIM_HOST *hcd_sim_host) 79 { 80 81 UX_HCD_SIM_HOST_TD *td; 82 ULONG td_index; 83 84 85 /* Get the mutex as this is a critical section. */ 86 _ux_host_mutex_on(&_ux_system -> ux_system_mutex); 87 88 /* Start the search from the beginning of the list. */ 89 td = hcd_sim_host -> ux_hcd_sim_host_td_list; 90 91 for (td_index = 0; td_index < _ux_system_host -> ux_system_host_max_td; td_index++) 92 { 93 94 /* Check the TD status, a free TD is marked with the UNUSED flag. */ 95 if (td -> ux_sim_host_td_status == UX_UNUSED) 96 { 97 98 /* The TD may have been used, so we reset all fields. */ 99 _ux_utility_memory_set(td, 0, sizeof(UX_HCD_SIM_HOST_TD)); /* Use case of memset is verified. */ 100 101 /* This TD is now marked as USED. */ 102 td -> ux_sim_host_td_status = UX_USED; 103 104 /* Release the mutex protection. */ 105 _ux_host_mutex_off(&_ux_system -> ux_system_mutex); 106 107 /* Return the TD pointer. */ 108 return(td); 109 } 110 111 /* Move to next TD. */ 112 td++; 113 } 114 115 /* There is no available TD in the TD list. */ 116 117 /* Release the mutex protection. */ 118 _ux_host_mutex_off(&_ux_system -> ux_system_mutex); 119 120 /* Return a NULL pointer. */ 121 return(UX_NULL); 122 } 123 124