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 /**   Pictbridge Application                                              */
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_utility.h"
30 #include "ux_pictbridge.h"
31 
32 
33 /**************************************************************************/
34 /*                                                                        */
35 /*  FUNCTION                                               RELEASE        */
36 /*                                                                        */
37 /*    _ux_pictbridge_hexa_to_major_minor                  PORTABLE C      */
38 /*                                                           6.1          */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    Chaoqiong Xiao, Microsoft Corporation                               */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    This function translates an hexa value into an major.minor value    */
46 /*    (xx.xx).                                                            */
47 /*                                                                        */
48 /*    Note: the space of the output_buffer must be equal to or larger     */
49 /*    than 5 to fill all converted characters.                            */
50 /*                                                                        */
51 /*  INPUT                                                                 */
52 /*                                                                        */
53 /*    hexa_value                             Value to be translated       */
54 /*    output_buffer                          Where to store the result    */
55 /*                                                                        */
56 /*  OUTPUT                                                                */
57 /*                                                                        */
58 /*    Completion Status                                                   */
59 /*                                                                        */
60 /*  CALLS                                                                 */
61 /*                                                                        */
62 /*                                                                        */
63 /*  CALLED BY                                                             */
64 /*                                                                        */
65 /*    _ux_pictbridge_object_parse                                         */
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 /*                                            verified memset and memcpy  */
74 /*                                            cases,                      */
75 /*                                            resulting in version 6.1    */
76 /*                                                                        */
77 /**************************************************************************/
_ux_pictbridge_hexa_to_major_minor(ULONG hexa_value,UCHAR * output_buffer)78 UINT  _ux_pictbridge_hexa_to_major_minor(ULONG hexa_value, UCHAR *output_buffer)
79 {
80 
81 UCHAR                   hexa_major;
82 UCHAR                   hexa_minor;
83 UINT                    status;
84 
85 
86     /* Reset the output buffer.  */
87     _ux_utility_memory_set(output_buffer, 0, 5); /* Use case of memset is verified. */
88 
89     /* Isolate the major.  */
90     hexa_major = (UCHAR)(hexa_value >> 16);
91 
92     /* Isolate the minor.  */
93     hexa_minor = (UCHAR)(hexa_value & 0xFFFF);
94 
95     /* Insert the decimal value of the major.  */
96     status = _ux_pictbridge_hexa_to_decimal_string(hexa_major, output_buffer, UX_PICTBRIDGE_LEADING_ZERO_ON, 2);
97     if (status != UX_SUCCESS)
98         return(status);
99 
100     /* Update the address of the destination.  */
101     output_buffer += 2;
102 
103     /* Insert the '.' between major and minor.  */
104     *output_buffer++ = '.';
105 
106     /* Insert the decimal value of the minor.  */
107     status = _ux_pictbridge_hexa_to_decimal_string(hexa_minor, output_buffer, UX_PICTBRIDGE_LEADING_ZERO_ON, 2);
108     if (status != UX_SUCCESS)
109         return(status);
110 
111     /* Operation was successful.  */
112     return(UX_SUCCESS);
113 }
114 
115