 /**    
  *******************************************************************************************************
  * @file    fm33lg0xx_fl_divas.h
  * @author  FMSH Application Team
  * @brief   Head file of DIVAS FL Module
  *******************************************************************************************************
  * @attention
  *
  * Copyright (c) 2022, SHANGHAI FUDAN MICROELECTRONICS GROUP CO., LTD.(FUDAN MICROELECTRONICS./ FUDAN MICRO.)    
  * All rights reserved.    
  *    
  * Processor:                   FM33LG0xxA    
  * http:                        http://www.fmdevelopers.com.cn/    
  *    
  * Redistribution and use in source and binary forms, with or without    
  * modification, are permitted provided that the following conditions are met    
  *    
  * 1. Redistributions of source code must retain the above copyright notice,    
  *    this list of conditions and the following disclaimer.    
  *    
  * 2. Redistributions in binary form must reproduce the above copyright notice,    
  *    this list of conditions and the following disclaimer in the documentation    
  *    and/or other materials provided with the distribution.    
  *    
  * 3. Neither the name of the copyright holder nor the names of its contributors    
  *    may be used to endorse or promote products derived from this software    
  *    without specific prior written permission.    
  *    
  * 4. To provide the most up-to-date information, the revision of our documents     
  *    on the World Wide Web will be the most Current. Your printed copy may be      
  *    an earlier revision. To verify you have the latest information avaliable,    
  *    refer to: http://www.fmdevelopers.com.cn/.    
  *    
  * THIS SOFTWARE IS PROVIDED BY FUDAN MICRO "AS IS" AND ANY EXPRESSED     
  * ORIMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES     
  * OF MERCHANTABILITY NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE    
  * ARE DISCLAIMED.IN NO EVENT SHALL FUDAN MICRO OR ITS CONTRIBUTORS BE LIABLE     
  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL     
  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS     
  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER    
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,     
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISINGIN ANY WAY OUT OF THE     
  * USE OF THIS SOFTWARE, EVEN IF ADVISED OFTHE POSSIBILITY OF SUCH DAMAGE.    
 */    



/* Define to prevent recursive inclusion---------------------------------------------------------------*/
#ifndef __FM33LG0XX_FL_DIVAS_H
#define __FM33LG0XX_FL_DIVAS_H

#ifdef __cplusplus
extern "C" {
#endif
/* Includes -------------------------------------------------------------------------------------------*/
#include "fm33lg0xx_fl_def.h"
/** @addtogroup FM33LG0XX_FL_Driver
  * @{
  */

/** @defgroup DIVAS DIVAS 
  * @brief DIVAS FL driver
  * @{
  */

/* Exported types -------------------------------------------------------------------------------------*/
/** @defgroup DIVAS_FL_ES_INIT DIVAS Exported Init structures
  * @{
  */

/**
  * @brief FL DIVAS Init Sturcture definition
  */

/**
  * @}
  */
/* Exported constants ---------------------------------------------------------------------------------*/
/** @defgroup DIVAS_FL_Exported_Constants DIVAS Exported Constants
  * @{
  */
#define    FL_DIVAS_SR_BUSY_TIMEOUT                                (0xFFFU)

#define    DIVAS_SR_DIV0_Pos                                      (1U)
#define    DIVAS_SR_DIV0_Msk                                      (0x1U << DIVAS_SR_DIV0_Pos)
#define    DIVAS_SR_DIV0                                          DIVAS_SR_DIV0_Msk

#define    DIVAS_SR_BUSY_Pos                                      (0U)
#define    DIVAS_SR_BUSY_Msk                                      (0x1U << DIVAS_SR_BUSY_Pos)
#define    DIVAS_SR_BUSY                                          DIVAS_SR_BUSY_Msk

#define    DIVAS_CR_MODE_Pos                                      (0U)
#define    DIVAS_CR_MODE_Msk                                      (0x1U << DIVAS_CR_MODE_Pos)
#define    DIVAS_CR_MODE                                          DIVAS_CR_MODE_Msk






#define    FL_DIVAS_MODE_DIV                                      (0x0U << DIVAS_CR_MODE_Pos)
#define    FL_DIVAS_MODE_ROOT                                     (0x1U << DIVAS_CR_MODE_Pos)


/**
  * @}
  */
/* Exported functions ---------------------------------------------------------------------------------*/
/** @defgroup DIVAS_FL_Exported_Functions DIVAS Exported Functions
  * @{
  */

/**
  * @brief    Write Operator Register
  * @rmtoll   OPRD        FL_DIVAS_WriteOperand
  * @param    DIVASx DIVAS instance
  * @param    number
  * @retval   None
  */
__STATIC_INLINE void FL_DIVAS_WriteOperand(DIVAS_Type *DIVASx, uint32_t number)
{
    WRITE_REG(DIVASx->OPRD,(number << 0U));
}

/**
  * @brief    Read Operator Register
  * @rmtoll   OPRD        FL_DIVAS_ReadOperand
  * @param    DIVASx DIVAS instance
  * @retval
  */
__STATIC_INLINE int32_t FL_DIVAS_ReadOperand(DIVAS_Type *DIVASx)
{
    return (int32_t)(READ_REG(DIVASx->OPRD));
}

/**
  * @brief    Write 16bit Signed Dividend
  * @rmtoll   DIVSOR        FL_DIVAS_WriteDivisor
  * @param    DIVASx DIVAS instance
  * @param    number
  * @retval   None
  */
__STATIC_INLINE void FL_DIVAS_WriteDivisor(DIVAS_Type *DIVASx, uint32_t number)
{
    MODIFY_REG(DIVASx->DIVSOR, (0xffffU << 0U), (number << 0U));
}

/**
  * @brief    Read 16bit Signed Dividend
  * @rmtoll   DIVSOR        FL_DIVAS_ReadDivisor
  * @param    DIVASx DIVAS instance
  * @retval
  */
__STATIC_INLINE int32_t FL_DIVAS_ReadDivisor(DIVAS_Type *DIVASx)
{
    return (int32_t)(READ_BIT(DIVASx->DIVSOR, 0xffffU) >> 0U);
}

/**
  * @brief    Read 32bit Signed QUTO
  * @rmtoll   QUOT        FL_DIVAS_ReadQuotient
  * @param    DIVASx DIVAS instance
  * @retval
  */
__STATIC_INLINE int32_t FL_DIVAS_ReadQuotient(DIVAS_Type *DIVASx)
{
    return (int32_t)(READ_REG(DIVASx->QUOT));
}

/**
  * @brief    Read 16bit Signed Reminder
  * @rmtoll   REMD        FL_DIVAS_ReadResidue
  * @param    DIVASx DIVAS instance
  * @retval
  */
__STATIC_INLINE int16_t FL_DIVAS_ReadResidue(DIVAS_Type *DIVASx)
{
    return (int16_t)(READ_BIT(DIVASx->REMD, 0xffffU) >> 0U);
}

/**
  * @brief    Read 16bit Unsigned Square Root
  * @rmtoll   ROOT        FL_DIVAS_ReadRoot
  * @param    DIVASx DIVAS instance
  * @retval
  */
__STATIC_INLINE uint16_t FL_DIVAS_ReadRoot(DIVAS_Type *DIVASx)
{
    return (uint16_t)(READ_BIT(DIVASx->ROOT, 0xffffU) >> 0U);
}

/**
  * @brief    Get divided by 0 flag
  * @rmtoll   SR    DIV0    FL_DIVAS_IsActiveFlag_DividedZero
  * @param    DIVASx DIVAS instance
  * @retval   State of bit (1 or 0).
  */
__STATIC_INLINE uint32_t FL_DIVAS_IsActiveFlag_DividedZero(DIVAS_Type *DIVASx)
{
    return (uint32_t)(READ_BIT(DIVASx->SR, DIVAS_SR_DIV0_Msk) == (DIVAS_SR_DIV0_Msk));
}

/**
  * @brief    Get Busy flag
  * @rmtoll   SR    BUSY    FL_DIVAS_IsActiveFlag_Busy
  * @param    DIVASx DIVAS instance
  * @retval   State of bit (1 or 0).
  */
__STATIC_INLINE uint32_t FL_DIVAS_IsActiveFlag_Busy(DIVAS_Type *DIVASx)
{
    return (uint32_t)(READ_BIT(DIVASx->SR, DIVAS_SR_BUSY_Msk) == (DIVAS_SR_BUSY_Msk));
}

/**
  * @brief    Set Work Mode
  * @rmtoll   CR    MODE    FL_DIVAS_SetMode
  * @param    DIVASx DIVAS instance
  * @param    mode This parameter can be one of the following values:
  *           @arg @ref FL_DIVAS_MODE_DIV
  *           @arg @ref FL_DIVAS_MODE_ROOT
  * @retval   None
  */
__STATIC_INLINE void FL_DIVAS_SetMode(DIVAS_Type *DIVASx, uint32_t mode)
{
    MODIFY_REG(DIVASx->CR, DIVAS_CR_MODE_Msk, mode);
}

/**
  * @brief    Get Work Mode
  * @rmtoll   CR    MODE    FL_DIVAS_GetMode
  * @param    DIVASx DIVAS instance
  * @retval   Returned value can be one of the following values:
  *           @arg @ref FL_DIVAS_MODE_DIV
  *           @arg @ref FL_DIVAS_MODE_ROOT
  */
__STATIC_INLINE uint32_t FL_DIVAS_GetMode(DIVAS_Type *DIVASx)
{
    return (uint32_t)(READ_BIT(DIVASx->CR, DIVAS_CR_MODE_Msk));
}

/**
  * @}
  */

/** @defgroup DIVAS_FL_EF_Init Initialization and de-initialization functions
  * @{
  */
FL_ErrorStatus FL_DIVAS_DeInit(DIVAS_Type *DIVASx);
FL_ErrorStatus FL_DIVAS_Init(DIVAS_Type *DIVASx);
uint32_t FL_DIVAS_Hdiv_Calculation(DIVAS_Type *DIVASx, int32_t DivisorEnd, int16_t Divisor, int32_t *Quotient, int16_t *Residue);
uint32_t FL_DIVAS_Root_Calculation(DIVAS_Type *DIVASx, uint32_t Root, uint16_t *Result);

/**
  * @}
  */

/**
  * @}
  */

/**
  * @}
  */

#ifdef __cplusplus
}
#endif

#endif /* __FM33LG0XX_FL_DIVAS_H*/

/*************************Py_Code_Generator Version: 0.1-0.11-0.1 @ 2020-09-14*************************/
/*************************(C) COPYRIGHT Fudan Microelectronics **** END OF FILE*************************/
