1 /*
2  * Copyright 2017-2020 NXP
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  *
7  */
8 
9 #ifndef FSL_FTFX_UTILITIES_H
10 #define FSL_FTFX_UTILITIES_H
11 
12 /*!
13  * @addtogroup ftfx_utilities
14  * @{
15  */
16 /*******************************************************************************
17  * Definitions
18  ******************************************************************************/
19 
20 /*! @brief Constructs the version number for drivers. */
21 #if !defined(MAKE_VERSION)
22 #define MAKE_VERSION(major, minor, bugfix) (((major) << 16) | ((minor) << 8) | (bugfix))
23 #endif
24 
25 /*! @brief Constructs a status code value from a group and a code number. */
26 #if !defined(MAKE_STATUS)
27 #define MAKE_STATUS(group, code) ((((group)*100) + (code)))
28 #endif
29 
30 /*! @brief Constructs the four character code for the Flash driver API key. */
31 #if !defined(FOUR_CHAR_CODE)
32 #define FOUR_CHAR_CODE(a, b, c, d) \
33     (((uint32_t)(d) << 24u) | ((uint32_t)(c) << 16u) | ((uint32_t)(b) << 8u) | ((uint32_t)(a)))
34 #endif
35 
36 //! @name Alignment macros
37 //@{
38 /*! @brief Alignment(down) utility. */
39 #if !defined(ALIGN_DOWN)
40 #define ALIGN_DOWN(x, a) (((uint32_t)(x)) & ~((uint32_t)(a)-1u))
41 #endif
42 
43 /*! @brief Alignment(up) utility. */
44 #if !defined(ALIGN_UP)
45 #define ALIGN_UP(x, a) ALIGN_DOWN((uint32_t)(x) + (uint32_t)(a)-1u, a)
46 #endif
47 //@}
48 
49 /*! @brief bytes2word utility. */
50 #define B1P4(b) (((uint32_t)(b)&0xFFU) << 24U)
51 #define B1P3(b) (((uint32_t)(b)&0xFFU) << 16U)
52 #define B1P2(b) (((uint32_t)(b)&0xFFU) << 8U)
53 #define B1P1(b) ((uint32_t)(b)&0xFFU)
54 #define B2P3(b) (((uint32_t)(b)&0xFFFFU) << 16U)
55 #define B2P2(b) (((uint32_t)(b)&0xFFFFU) << 8U)
56 #define B2P1(b) ((uint32_t)(b)&0xFFFFU)
57 #define B3P2(b) (((uint32_t)(b)&0xFFFFFFU) << 8U)
58 #define B3P1(b) ((uint32_t)(b)&0xFFFFFFU)
59 
60 #define BYTE2WORD_1_3(x, y)           (B1P4(x) | B3P1(y))
61 #define BYTE2WORD_2_2(x, y)           (B2P3(x) | B2P1(y))
62 #define BYTE2WORD_3_1(x, y)           (B3P2(x) | B1P1(y))
63 #define BYTE2WORD_1_1_2(x, y, z)      (B1P4(x) | B1P3(y) | B2P1(z))
64 #define BYTE2WORD_1_2_1(x, y, z)      (B1P4(x) | B2P2(y) | B1P1(z))
65 #define BYTE2WORD_2_1_1(x, y, z)      (B2P3(x) | B1P2(y) | B1P1(z))
66 #define BYTE2WORD_1_1_1_1(x, y, z, w) (B1P4(x) | B1P3(y) | B1P2(z) | B1P1(w))
67 
68 /*! @}*/
69 
70 #endif /* FSL_FTFX_UTILITIES_H */
71