nu_hdiv.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /**************************************************************************//**
  2. * @file nu_hdiv.h
  3. * @version V1.00
  4. * $Revision: 1 $
  5. * $Date: 18/07/25 3:42p $
  6. * @brief M031 series Hardware Divider(HDIV) driver header file
  7. *
  8. * SPDX-License-Identifier: Apache-2.0
  9. * @copyright (C) 2018 Nuvoton Technology Corp. All rights reserved.
  10. ******************************************************************************/
  11. #ifndef __NU_HDIV_H__
  12. #define __NU_HDIV_H__
  13. #ifdef __cplusplus
  14. extern "C"
  15. {
  16. #endif
  17. /** @addtogroup Standard_Driver Standard Driver
  18. @{
  19. */
  20. /** @addtogroup HDIV_Driver HDIV Driver
  21. @{
  22. */
  23. /** @addtogroup HDIV_EXPORTED_FUNCTIONS HDIV Exported Functions
  24. @{
  25. */
  26. /**
  27. * @brief Division function to calculate (x/y)
  28. *
  29. * @param[in] x the dividend of the division
  30. * @param[in] y the divisor of the division
  31. *
  32. * @return The result of (x/y)
  33. *
  34. * @details This is a division function to calculate x/y
  35. *
  36. */
  37. static __INLINE int32_t HDIV_Div(int32_t x, int16_t y)
  38. {
  39. uint32_t *p32;
  40. p32 = (uint32_t *)HDIV_BASE;
  41. *p32++ = x;
  42. *p32++ = y;
  43. return *p32;
  44. }
  45. /**
  46. * @brief To calculate the remainder of x/y, i.e., the result of x mod y.
  47. *
  48. * @param[in] x the dividend of the division
  49. * @param[in] y the divisor of the division
  50. *
  51. * @return The remainder of (x/y)
  52. *
  53. * @details This function is used to calculate the remainder of x/y.
  54. */
  55. static __INLINE int16_t HDIV_Mod(int32_t x, int16_t y)
  56. {
  57. uint32_t *p32;
  58. p32 = (uint32_t *)HDIV_BASE;
  59. *p32++ = x;
  60. *p32++ = y;
  61. return p32[1];
  62. }
  63. /*@}*/ /* end of group HDIV_EXPORTED_FUNCTIONS */
  64. /*@}*/ /* end of group HDIV_Driver */
  65. /*@}*/ /* end of group Standard_Driver */
  66. #ifdef __cplusplus
  67. }
  68. #endif
  69. #endif //__NU_HDIV_H__
  70. /*** (C) COPYRIGHT 2016 Nuvoton Technology Corp. ***/