utilities.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. / _____) _ | |
  3. ( (____ _____ ____ _| |_ _____ ____| |__
  4. \____ \| ___ | (_ _) ___ |/ ___) _ \
  5. _____) ) ____| | | || |_| ____( (___| | | |
  6. (______/|_____)_|_|_| \__)_____)\____)_| |_|
  7. (C)2013 Semtech
  8. Description: Helper functions implementation
  9. License: Revised BSD License, see LICENSE.TXT file include in the project
  10. Maintainer: Miguel Luis and Gregory Cristian
  11. */
  12. #ifndef __UTILITIES_H__
  13. #define __UTILITIES_H__
  14. /*!
  15. * \brief Returns the minimum value betwen a and b
  16. *
  17. * \param [IN] a 1st value
  18. * \param [IN] b 2nd value
  19. * \retval minValue Minimum value
  20. */
  21. #define MIN( a, b ) ( ( ( a ) < ( b ) ) ? ( a ) : ( b ) )
  22. /*!
  23. * \brief Returns the maximum value betwen a and b
  24. *
  25. * \param [IN] a 1st value
  26. * \param [IN] b 2nd value
  27. * \retval maxValue Maximum value
  28. */
  29. #define MAX( a, b ) ( ( ( a ) > ( b ) ) ? ( a ) : ( b ) )
  30. /*!
  31. * \brief Returns 2 raised to the power of n
  32. *
  33. * \param [IN] n power value
  34. * \retval result of raising 2 to the power n
  35. */
  36. #define POW2( n ) ( 1 << n )
  37. /*!
  38. * \brief Initializes the pseudo ramdom generator initial value
  39. *
  40. * \param [IN] seed Pseudo ramdom generator initial value
  41. */
  42. void srand1( uint32_t seed );
  43. /*!
  44. * \brief Computes a random number between min and max
  45. *
  46. * \param [IN] min range minimum value
  47. * \param [IN] max range maximum value
  48. * \retval random random value in range min..max
  49. */
  50. int32_t randr( int32_t min, int32_t max );
  51. /*!
  52. * \brief Copies size elements of src array to dst array
  53. *
  54. * \remark STM32 Standard memcpy function only works on pointers that are aligned
  55. *
  56. * \param [OUT] dst Destination array
  57. * \param [IN] src Source array
  58. * \param [IN] size Number of bytes to be copied
  59. */
  60. void memcpy1( uint8_t *dst, const uint8_t *src, uint16_t size );
  61. /*!
  62. * \brief Copies size elements of src array to dst array reversing the byte order
  63. *
  64. * \param [OUT] dst Destination array
  65. * \param [IN] src Source array
  66. * \param [IN] size Number of bytes to be copied
  67. */
  68. void memcpyr( uint8_t *dst, const uint8_t *src, uint16_t size );
  69. /*!
  70. * \brief Set size elements of dst array with value
  71. *
  72. * \remark STM32 Standard memset function only works on pointers that are aligned
  73. *
  74. * \param [OUT] dst Destination array
  75. * \param [IN] value Default value
  76. * \param [IN] size Number of bytes to be copied
  77. */
  78. void memset1( uint8_t *dst, uint8_t value, uint16_t size );
  79. /*!
  80. * \brief Converts a nibble to an hexadecimal character
  81. *
  82. * \param [IN] a Nibble to be converted
  83. * \retval hexChar Converted hexadecimal character
  84. */
  85. int8_t Nibble2HexChar( uint8_t a );
  86. #endif // __UTILITIES_H__