hdiv.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /**************************************************************************//**
  2. * @file DIV.h
  3. * @version V2.1
  4. * $Revision: 4 $
  5. * $Date: 14/01/28 10:49a $
  6. * @brief M051 Series DIV Driver Header File
  7. *
  8. * @note
  9. * Copyright (C) 2013 Nuvoton Technology Corp. All rights reserved.
  10. *
  11. ******************************************************************************/
  12. #ifndef __DIVIDER_H__
  13. #define __DIVIDER_H__
  14. /**
  15. * @brief Division function to calculate (x/y)
  16. *
  17. * @param[in] x the dividend of the division
  18. * @param[in] y the divisor of the division
  19. *
  20. * @return The result of (x/y)
  21. *
  22. * @details This is a division function to calculate x/y
  23. *
  24. */
  25. static __INLINE int32_t HDIV_Div(int32_t x, int16_t y)
  26. {
  27. uint32_t *p32;
  28. p32 = (uint32_t *)HDIV_BASE;
  29. *p32++ = x;
  30. *p32++ = y;
  31. return *p32;
  32. }
  33. /**
  34. * @brief To calculate the remainder of x/y, i.e., the result of x mod y.
  35. *
  36. * @param[in] x the dividend of the division
  37. * @param[in] y the divisor of the division
  38. *
  39. * @return The remainder of (x/y)
  40. *
  41. * @details This function is used to calculate the remainder of x/y.
  42. */
  43. static __INLINE int16_t HDIV_Mod(int32_t x, int16_t y)
  44. {
  45. uint32_t *p32;
  46. p32 = (uint32_t *)HDIV_BASE;
  47. *p32++ = x;
  48. *p32++ = y;
  49. return p32[1];
  50. }
  51. #endif