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 Stack */ 19 /** */ 20 /**************************************************************************/ 21 /**************************************************************************/ 22 23 24 /* Include necessary system files. */ 25 26 #define UX_SOURCE_CODE 27 28 #include "ux_api.h" 29 #include "ux_host_stack.h" 30 31 32 /**************************************************************************/ 33 /* */ 34 /* FUNCTION RELEASE */ 35 /* */ 36 /* _ux_host_stack_class_instance_get PORTABLE C */ 37 /* 6.1 */ 38 /* AUTHOR */ 39 /* */ 40 /* Chaoqiong Xiao, Microsoft Corporation */ 41 /* */ 42 /* DESCRIPTION */ 43 /* */ 44 /* This function returns a class instance pointer for a specific */ 45 /* class. The instance of a class is not contained in the class code */ 46 /* to reduce the class complexity. Rather, each class instance is */ 47 /* attached to class container. */ 48 /* */ 49 /* INPUT */ 50 /* */ 51 /* class Pointer to class */ 52 /* class_index Index of class */ 53 /* class_instance Destination of class instance */ 54 /* pointer */ 55 /* */ 56 /* OUTPUT */ 57 /* */ 58 /* Completion Status */ 59 /* */ 60 /* CALLS */ 61 /* */ 62 /* None */ 63 /* */ 64 /* CALLED BY */ 65 /* */ 66 /* Application */ 67 /* USBX Components */ 68 /* */ 69 /* RELEASE HISTORY */ 70 /* */ 71 /* DATE NAME DESCRIPTION */ 72 /* */ 73 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ 74 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ 75 /* resulting in version 6.1 */ 76 /* */ 77 /**************************************************************************/ _ux_host_stack_class_instance_get(UX_HOST_CLASS * host_class,UINT class_index,VOID ** class_instance)78UINT _ux_host_stack_class_instance_get(UX_HOST_CLASS *host_class, UINT class_index, VOID **class_instance) 79 { 80 81 VOID **current_class_instance; 82 83 84 /* Start with the first class instance attached to the class container. */ 85 current_class_instance = host_class -> ux_host_class_first_instance; 86 87 /* Check if there are any instances attached. */ 88 if(current_class_instance == UX_NULL) 89 { 90 91 return(UX_HOST_CLASS_INSTANCE_UNKNOWN); 92 } 93 94 /* Traverse the list of the class instances until we found the right one. */ 95 while (class_index-- != 0) 96 { 97 98 /* Points to the next class instance. */ 99 current_class_instance = *current_class_instance; 100 101 /* Check if we have reached the end of the list of the class instances. */ 102 if (current_class_instance == UX_NULL) 103 { 104 105 return(UX_HOST_CLASS_INSTANCE_UNKNOWN); 106 } 107 } 108 109 /* Update the class instance pointer from the caller. */ 110 *class_instance = current_class_instance; 111 112 /* Return successful completion. */ 113 return(UX_SUCCESS); 114 } 115 116