1 /**
2  * @file 	mem_utils.h
3  * @brief 	memory utility functions
4  */
5 /******************************************************************************
6  *
7  * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by
8  * Analog Devices, Inc.),
9  * Copyright (C) 2023-2024 Analog Devices, Inc.
10  *
11  * Licensed under the Apache License, Version 2.0 (the "License");
12  * you may not use this file except in compliance with the License.
13  * You may obtain a copy of the License at
14  *
15  *     http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  *
23  ******************************************************************************/
24 
25 #ifndef LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32650_MEM_UTILS_H_
26 #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32650_MEM_UTILS_H_
27 
28 #include "mxc_device.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 /**
35  * @defgroup    mem_utils Memory Utility Functions
36  * @ingroup     devicelibs
37  * @{
38  */
39 /* **** Definitions **** */
40 
41 /* **** Global Data **** */
42 
43 /* **** Function Prototypes **** */
44 
45 /**
46  * @brief      32-bit wide memory copy.
47  *
48  * @param      dst   Pointer to the destination location
49  * @param      src   Pointer to the source location
50  * @param[in]  len   Number of bytes to copy which must be a multiple of 4.
51  * @note       This function assumes the destination and source are 32-bit
52  *             word aligned. A minimum of 1 word is copied (len = 4).
53  */
54 void memcpy32(uint32_t *dst, uint32_t *src, unsigned int len);
55 
56 /**
57  *
58  * @brief      Compares the first @c len bytes of src and @c dst and
59  *             returns #E_NO_ERROR if they match.
60  * @param      dst   Destination address
61  * @param      src   Source address
62  * @param[in]  len   Number of bytes to compare between the @c src and
63  *                   @c dst.
64  * @note       The compare is done 32-bits at a time and @c len should be
65  *             a multiple of 4 and any bytes beyond a multiple of 4 are
66  *             ignored. For example, the following call to memcmp32() only
67  *             compares the first 8 bytes (2 32-bit words) of @c dst and
68  *             @c src and would return 0 indicating the memory is the same.
69  *             @code
70  *                int retval;
71  *                int len = 11;
72  *                char src[len] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
73  *                char dst[len] = {0, 1, 2, 3, 4, 5, 6, 7, 0, 0, 0};
74  *
75  *                if (memcmp32(dst, src, len) != 0)
76  *                {
77  *                   printf("Memory compare failed\n");
78  *                }
79  *                else
80  *                {
81  *                   // memcmp32 passes even though the src and dst are
82  *                   // not identical starting at src[8] and dst[8]
83  *                   printf("memcmp32 passed.\n");
84  *                }
85  *             @endcode
86  *
87  * @retval     #E_NO_ERROR Contents of @c src and @c dst are equal
88  * @retval     #E_INVALID Memory is not equal
89  */
90 int memcmp32(uint32_t *dst, uint32_t *src, unsigned int len);
91 
92 /**@} end of group mem_utils */
93 
94 #ifdef __cplusplus
95 }
96 #endif
97 
98 #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32650_MEM_UTILS_H_
99