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