fsl_ftfx_utilities.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * The Clear BSD License
  3. * Copyright 2017-2018 NXP
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted (subject to the limitations in the
  8. * disclaimer below) provided that the following conditions are met:
  9. *
  10. * * Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. *
  13. * * Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. *
  17. * * Neither the name of the copyright holder nor the names of its
  18. * contributors may be used to endorse or promote products derived from
  19. * this software without specific prior written permission.
  20. *
  21. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
  22. * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
  23. * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
  24. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  25. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  26. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  27. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  28. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  29. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  30. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  31. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  32. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  33. * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. */
  36. #ifndef _FSL_FTFX_UTILITIES_H_
  37. #define _FSL_FTFX_UTILITIES_H_
  38. /*******************************************************************************
  39. * Definitions
  40. ******************************************************************************/
  41. /*! @brief Constructs the version number for drivers. */
  42. #if !defined(MAKE_VERSION)
  43. #define MAKE_VERSION(major, minor, bugfix) (((major) << 16) | ((minor) << 8) | (bugfix))
  44. #endif
  45. /*! @brief Constructs a status code value from a group and a code number. */
  46. #if !defined(MAKE_STATUS)
  47. #define MAKE_STATUS(group, code) ((((group)*100) + (code)))
  48. #endif
  49. /*! @brief Constructs the four character code for the Flash driver API key. */
  50. #if !defined(FOUR_CHAR_CODE)
  51. #define FOUR_CHAR_CODE(a, b, c, d) (((d) << 24) | ((c) << 16) | ((b) << 8) | ((a)))
  52. #endif
  53. /*! @brief Alignment(down) utility. */
  54. #if !defined(ALIGN_DOWN)
  55. #define ALIGN_DOWN(x, a) ((x) & (uint32_t)(-((int32_t)(a))))
  56. #endif
  57. /*! @brief Alignment(up) utility. */
  58. #if !defined(ALIGN_UP)
  59. #define ALIGN_UP(x, a) (-((int32_t)((uint32_t)(-((int32_t)(x))) & (uint32_t)(-((int32_t)(a))))))
  60. #endif
  61. /*! @brief bytes2word utility. */
  62. #define B1P4(b) (((uint32_t)(b)&0xFFU) << 24)
  63. #define B1P3(b) (((uint32_t)(b)&0xFFU) << 16)
  64. #define B1P2(b) (((uint32_t)(b)&0xFFU) << 8)
  65. #define B1P1(b) ((uint32_t)(b)&0xFFU)
  66. #define B2P3(b) (((uint32_t)(b)&0xFFFFU) << 16)
  67. #define B2P2(b) (((uint32_t)(b)&0xFFFFU) << 8)
  68. #define B2P1(b) ((uint32_t)(b)&0xFFFFU)
  69. #define B3P2(b) (((uint32_t)(b)&0xFFFFFFU) << 8)
  70. #define B3P1(b) ((uint32_t)(b)&0xFFFFFFU)
  71. #define BYTE2WORD_1_3(x, y) (B1P4(x) | B3P1(y))
  72. #define BYTE2WORD_2_2(x, y) (B2P3(x) | B2P1(y))
  73. #define BYTE2WORD_3_1(x, y) (B3P2(x) | B1P1(y))
  74. #define BYTE2WORD_1_1_2(x, y, z) (B1P4(x) | B1P3(y) | B2P1(z))
  75. #define BYTE2WORD_1_2_1(x, y, z) (B1P4(x) | B2P2(y) | B1P1(z))
  76. #define BYTE2WORD_2_1_1(x, y, z) (B2P3(x) | B1P2(y) | B1P1(z))
  77. #define BYTE2WORD_1_1_1_1(x, y, z, w) (B1P4(x) | B1P3(y) | B1P2(z) | B1P1(w))
  78. #endif /* _FSL_FTFX_UTILITIES_H_ */