初始版本
This commit is contained in:
@@ -0,0 +1,649 @@
|
||||
/******************************************************************************
|
||||
* Copyright (C) 2017, Huada Semiconductor Co.,Ltd All rights reserved.
|
||||
*
|
||||
* This software is owned and published by:
|
||||
* Huada Semiconductor Co.,Ltd ("HDSC").
|
||||
*
|
||||
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
|
||||
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
|
||||
*
|
||||
* This software contains source code for use with HDSC
|
||||
* components. This software is licensed by HDSC to be adapted only
|
||||
* for use in systems utilizing HDSC components. HDSC shall not be
|
||||
* responsible for misuse or illegal use of this software for devices not
|
||||
* supported herein. HDSC is providing this software "AS IS" and will
|
||||
* not be responsible for issues arising from incorrect user implementation
|
||||
* of the software.
|
||||
*
|
||||
* Disclaimer:
|
||||
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
|
||||
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
|
||||
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
|
||||
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
|
||||
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
|
||||
* WARRANTY OF NONINFRINGEMENT.
|
||||
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
|
||||
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
|
||||
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
|
||||
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
|
||||
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
|
||||
* SAVINGS OR PROFITS,
|
||||
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
|
||||
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
|
||||
* FROM, THE SOFTWARE.
|
||||
*
|
||||
* This software may be replicated in part or whole for the licensed use,
|
||||
* with the restriction that this Disclaimer and Copyright notice must be
|
||||
* included with each copy of this software, whether used in part or whole,
|
||||
* at all times.
|
||||
*/
|
||||
/******************************************************************************/
|
||||
/** \file adc.c
|
||||
**
|
||||
** ADC driver API.
|
||||
**
|
||||
** - 2017-06-28 Alex First Version
|
||||
**
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* Include files
|
||||
******************************************************************************/
|
||||
#include "adc.h"
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \addtogroup AdcGroup
|
||||
******************************************************************************/
|
||||
//@{
|
||||
|
||||
/******************************************************************************
|
||||
* Local pre-processor symbols/macros ('#define')
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* Global variable definitions (declared in header file with 'extern')
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* Local type definitions ('typedef')
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* Local function prototypes ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* Local variable definitions ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* Function implementation - global ('extern') and local ('static')
|
||||
*****************************************************************************/
|
||||
/**
|
||||
* \brief
|
||||
* 获取ADC中断状态
|
||||
*
|
||||
* \param [in] enAdcIrq ADC中断类型 @ref en_adc_irq_type_t
|
||||
*
|
||||
* \retval 中断标志
|
||||
*/
|
||||
boolean_t Adc_GetIrqStatus(en_adc_irq_type_t enAdcIrq)
|
||||
{
|
||||
if(M0P_ADC->IFR&enAdcIrq)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief
|
||||
* 获取ADC中断状态
|
||||
*
|
||||
* \param [in] enAdcIrq ADC中断类型 @ref en_adc_irq_type_t
|
||||
*
|
||||
* \retval Null
|
||||
*/
|
||||
void Adc_ClrIrqStatus(en_adc_irq_type_t enAdcIrq)
|
||||
{
|
||||
M0P_ADC->ICR &= ~(uint32_t)enAdcIrq;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief
|
||||
* ADC中断使能
|
||||
*
|
||||
* \param 无
|
||||
*
|
||||
* \retval 无
|
||||
*/
|
||||
void Adc_EnableIrq(void)
|
||||
{
|
||||
M0P_ADC->CR0_f.IE = 1u;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief
|
||||
* ADC中断禁止
|
||||
*
|
||||
* \param 无
|
||||
*
|
||||
* \retval 无
|
||||
*/
|
||||
void Adc_DisableIrq(void)
|
||||
{
|
||||
M0P_ADC->CR0_f.IE = 0u;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief
|
||||
* ADC初始化
|
||||
*
|
||||
* \param [in] pstcAdcCfg ADC配置指针
|
||||
*
|
||||
* \retval en_result_t Ok: 配置成功
|
||||
* \retval en_result_t ErrorInvalidParameter: 无效参数
|
||||
*/
|
||||
en_result_t Adc_Init(stc_adc_cfg_t* pstcAdcCfg)
|
||||
{
|
||||
if (NULL == pstcAdcCfg)
|
||||
{
|
||||
return ErrorInvalidParameter;
|
||||
}
|
||||
|
||||
M0P_ADC->CR0 = 0x1u; ///< ADC 使能
|
||||
delay10us(2);
|
||||
|
||||
M0P_ADC->CR0 |= (uint32_t)pstcAdcCfg->enAdcClkDiv |
|
||||
(uint32_t)pstcAdcCfg->enAdcRefVolSel |
|
||||
(uint32_t)pstcAdcCfg->enAdcOpBuf |
|
||||
(uint32_t)pstcAdcCfg->enAdcSampCycleSel |
|
||||
(uint32_t)pstcAdcCfg->enInRef;
|
||||
|
||||
M0P_ADC->CR1_f.MODE = pstcAdcCfg->enAdcMode;
|
||||
M0P_ADC->CR1_f.ALIGN = pstcAdcCfg->enAdcAlign;
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief
|
||||
* ADC单次转换外部中断触发源配置
|
||||
*
|
||||
* \param [in] enAdcTrigSel 触发源
|
||||
*
|
||||
* \retval en_result_t Null
|
||||
*/
|
||||
void Adc_SglExtTrigCfg(en_adc_trig_sel_t enAdcTrigSel, boolean_t bValue)
|
||||
{
|
||||
if(TRUE == bValue)
|
||||
{
|
||||
M0P_ADC->EXTTRIGGER0 |= (uint32_t)enAdcTrigSel;
|
||||
}
|
||||
else
|
||||
{
|
||||
M0P_ADC->EXTTRIGGER0 &= ~(uint32_t)enAdcTrigSel;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief
|
||||
* ADC顺序扫描转换外部中断触发源配置
|
||||
*
|
||||
* \param [in] enAdcTrigSel 触发源
|
||||
* \param [in] TRUE or FALSE
|
||||
*
|
||||
* \retval en_result_t Null
|
||||
*/
|
||||
void Adc_SqrExtTrigCfg(en_adc_trig_sel_t enAdcTrigSel, boolean_t bValue)
|
||||
{
|
||||
if(TRUE == bValue)
|
||||
{
|
||||
M0P_ADC->EXTTRIGGER0 |= (uint32_t)enAdcTrigSel;
|
||||
}
|
||||
else
|
||||
{
|
||||
M0P_ADC->EXTTRIGGER0 &= ~(uint32_t)enAdcTrigSel;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief
|
||||
* ADC插队扫描转换外部中断触发源配置
|
||||
*
|
||||
* \param [in] enAdcTrigSel 触发源
|
||||
* \param [in] TRUE or FALSE
|
||||
*
|
||||
* \retval en_result_t Null
|
||||
*/
|
||||
void Adc_JqrExtTrigCfg(en_adc_trig_sel_t enAdcTrigSel, boolean_t bValue)
|
||||
{
|
||||
if(TRUE == bValue)
|
||||
{
|
||||
M0P_ADC->EXTTRIGGER1 |= (uint32_t)enAdcTrigSel;
|
||||
}
|
||||
else
|
||||
{
|
||||
M0P_ADC->EXTTRIGGER1 &= ~(uint32_t)enAdcTrigSel;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief
|
||||
* ADC 单次转换开始
|
||||
*
|
||||
* \param 无
|
||||
*
|
||||
* \retval 无
|
||||
*/
|
||||
|
||||
void Adc_SGL_Start(void)
|
||||
{
|
||||
M0P_ADC->SGLSTART = 1u;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief
|
||||
* ADC 单次转换停止
|
||||
*
|
||||
* \param 无
|
||||
*
|
||||
* \retval 无
|
||||
*/
|
||||
void Adc_SGL_Stop(void)
|
||||
{
|
||||
M0P_ADC->SGLSTART = 0u;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief
|
||||
* ADC 单次转换一直转换开始
|
||||
*
|
||||
* \param 无
|
||||
*
|
||||
* \retval 无
|
||||
*/
|
||||
|
||||
void Adc_SGL_Always_Start(void)
|
||||
{
|
||||
M0P_ADC->ALLSTART = 1u;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief
|
||||
* ADC 单次转换一直转换停止
|
||||
*
|
||||
* \param 无
|
||||
*
|
||||
* \retval 无
|
||||
*/
|
||||
|
||||
void Adc_SGL_Always_Stop(void)
|
||||
{
|
||||
M0P_ADC->ALLSTART = 0u;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief
|
||||
* ADC 顺序扫描转换开始
|
||||
*
|
||||
* \param 无
|
||||
*
|
||||
* \retval 无
|
||||
*/
|
||||
|
||||
void Adc_SQR_Start(void)
|
||||
{
|
||||
M0P_ADC->SQRSTART = 1u;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief
|
||||
* ADC 顺序扫描转换停止
|
||||
*
|
||||
* \param 无
|
||||
*
|
||||
* \retval 无
|
||||
*/
|
||||
void Adc_SQR_Stop(void)
|
||||
{
|
||||
M0P_ADC->SQRSTART = 0u;
|
||||
}
|
||||
/**
|
||||
* \brief
|
||||
* ADC 插队扫描转换开始
|
||||
*
|
||||
* \param 无
|
||||
*
|
||||
* \retval 无
|
||||
*/
|
||||
|
||||
void Adc_JQR_Start(void)
|
||||
{
|
||||
M0P_ADC->JQRSTART = 1u;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief
|
||||
* ADC 插队扫描转换停止
|
||||
*
|
||||
* \param 无
|
||||
*
|
||||
* \retval 无
|
||||
*/
|
||||
void Adc_JQR_Stop(void)
|
||||
{
|
||||
M0P_ADC->JQRSTART = 0u;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief
|
||||
* ADC使能
|
||||
*
|
||||
* \param 无
|
||||
*
|
||||
* \retval 无
|
||||
*/
|
||||
void Adc_Enable(void)
|
||||
{
|
||||
M0P_ADC->CR0_f.EN = 1u;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief
|
||||
* ADC除能
|
||||
*
|
||||
* \param 无
|
||||
*
|
||||
* \retval 无
|
||||
*/
|
||||
void Adc_Disable(void)
|
||||
{
|
||||
M0P_ADC->CR0_f.EN = 0u;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief
|
||||
* 配置顺序扫描转换模式
|
||||
*
|
||||
* \param [in] pstcAdcCfg ADC配置指针
|
||||
* \param [in] pstcAdcNormCfg 连续转换模式配置指针
|
||||
*
|
||||
* \retval en_result_t Ok: 配置成功
|
||||
* \retval en_result_t ErrorInvalidParameter: 无效参数
|
||||
*/
|
||||
en_result_t Adc_SqrModeCfg(stc_adc_sqr_cfg_t* pstcAdcSqrCfg)
|
||||
{
|
||||
if ((NULL == pstcAdcSqrCfg) || (pstcAdcSqrCfg->u8SqrCnt > 16))
|
||||
{
|
||||
return ErrorInvalidParameter;
|
||||
}
|
||||
|
||||
M0P_ADC->CR1_f.RACCCLR = 0; //ADC转换结果累加寄存器(ADC_ResultAcc)清零
|
||||
M0P_ADC->CR1_f.RACCEN = pstcAdcSqrCfg->enResultAcc;
|
||||
M0P_ADC->CR1_f.DMASQR = pstcAdcSqrCfg->bSqrDmaTrig;
|
||||
|
||||
M0P_ADC->SQR2_f.CNT = pstcAdcSqrCfg->u8SqrCnt - 1;
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief
|
||||
* 配置插队扫描转换模式
|
||||
*
|
||||
* \param [in] pstcAdcCfg ADC配置指针
|
||||
* \param [in] pstcAdcNormCfg 扫描转换模式配置指针
|
||||
*
|
||||
* \retval en_result_t Ok: 配置成功
|
||||
* \retval en_result_t ErrorInvalidParameter: 无效参数
|
||||
*/
|
||||
en_result_t Adc_JqrModeCfg(stc_adc_jqr_cfg_t* pstcAdcJqrCfg)
|
||||
{
|
||||
if ((NULL == pstcAdcJqrCfg) || (pstcAdcJqrCfg->u8JqrCnt > 4))
|
||||
{
|
||||
return ErrorInvalidParameter;
|
||||
}
|
||||
|
||||
M0P_ADC->CR1_f.DMASQR = pstcAdcJqrCfg->bJqrDmaTrig;
|
||||
|
||||
M0P_ADC->JQR_f.CNT = pstcAdcJqrCfg->u8JqrCnt - 1;
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief
|
||||
* 配置单次转换通道
|
||||
*
|
||||
* \param [in]enstcAdcSampCh 转换通道
|
||||
*
|
||||
* \retval en_result_t Ok: 成功
|
||||
* \retval en_result_t ErrorInvalidParameter: 无效参数
|
||||
*/
|
||||
en_result_t Adc_CfgSglChannel( en_adc_samp_ch_sel_t enstcAdcSampCh)
|
||||
{
|
||||
M0P_ADC->CR0_f.SGLMUX = enstcAdcSampCh;
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief
|
||||
* 配置顺序扫描转换通道
|
||||
*
|
||||
* \param [in]enstcAdcSqrChMux 顺序扫描转换通道顺序
|
||||
* \param [in]enstcAdcSampCh 转换通道
|
||||
*
|
||||
* \retval en_result_t Ok: 成功
|
||||
* \retval en_result_t ErrorInvalidParameter: 无效参数
|
||||
*/
|
||||
en_result_t Adc_CfgSqrChannel(en_adc_sqr_chmux_t enstcAdcSqrChMux, en_adc_samp_ch_sel_t enstcAdcSampCh)
|
||||
{
|
||||
en_result_t enResult = Ok;
|
||||
|
||||
switch(enstcAdcSqrChMux)
|
||||
{
|
||||
case AdcSQRCH0MUX:
|
||||
M0P_ADC->SQR0_f.CH0MUX = enstcAdcSampCh;
|
||||
break;
|
||||
case AdcSQRCH1MUX:
|
||||
M0P_ADC->SQR0_f.CH1MUX = enstcAdcSampCh;
|
||||
break;
|
||||
case AdcSQRCH2MUX:
|
||||
M0P_ADC->SQR0_f.CH2MUX = enstcAdcSampCh;
|
||||
break;
|
||||
case AdcSQRCH3MUX:
|
||||
M0P_ADC->SQR0_f.CH3MUX = enstcAdcSampCh;
|
||||
break;
|
||||
case AdcSQRCH4MUX:
|
||||
M0P_ADC->SQR0_f.CH4MUX = enstcAdcSampCh;
|
||||
break;
|
||||
case AdcSQRCH5MUX:
|
||||
M0P_ADC->SQR0_f.CH5MUX = enstcAdcSampCh;
|
||||
break;
|
||||
case AdcSQRCH6MUX:
|
||||
M0P_ADC->SQR1_f.CH6MUX = enstcAdcSampCh;
|
||||
break;
|
||||
case AdcSQRCH7MUX:
|
||||
M0P_ADC->SQR1_f.CH7MUX = enstcAdcSampCh;
|
||||
break;
|
||||
case AdcSQRCH8MUX:
|
||||
M0P_ADC->SQR1_f.CH8MUX = enstcAdcSampCh;
|
||||
break;
|
||||
case AdcSQRCH9MUX:
|
||||
M0P_ADC->SQR1_f.CH9MUX = enstcAdcSampCh;
|
||||
break;
|
||||
case AdcSQRCH10MUX:
|
||||
M0P_ADC->SQR1_f.CH10MUX = enstcAdcSampCh;
|
||||
break;
|
||||
case AdcSQRCH11MUX:
|
||||
M0P_ADC->SQR1_f.CH11MUX = enstcAdcSampCh;
|
||||
break;
|
||||
case AdcSQRCH12MUX:
|
||||
M0P_ADC->SQR2_f.CH12MUX = enstcAdcSampCh;
|
||||
break;
|
||||
case AdcSQRCH13MUX:
|
||||
M0P_ADC->SQR2_f.CH13MUX = enstcAdcSampCh;
|
||||
break;
|
||||
case AdcSQRCH14MUX:
|
||||
M0P_ADC->SQR2_f.CH14MUX = enstcAdcSampCh;
|
||||
break;
|
||||
case AdcSQRCH15MUX:
|
||||
M0P_ADC->SQR2_f.CH15MUX = enstcAdcSampCh;
|
||||
break;
|
||||
default:
|
||||
enResult = ErrorInvalidParameter;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return enResult;
|
||||
}
|
||||
/**
|
||||
* \brief
|
||||
* 配置插队扫描转换通道
|
||||
*
|
||||
* \param [in]enstcAdcSqrChMux 插队扫描转换通道顺序
|
||||
* \param [in]enstcAdcSampCh 转换通道
|
||||
*
|
||||
* \retval en_result_t Ok: 成功
|
||||
* \retval en_result_t ErrorInvalidParameter: 无效参数
|
||||
*/
|
||||
en_result_t Adc_CfgJqrChannel(en_adc_jqr_chmux_t enstcAdcJqrChMux, en_adc_samp_ch_sel_t enstcAdcSampCh)
|
||||
{
|
||||
en_result_t enResult = Ok;
|
||||
|
||||
switch(enstcAdcJqrChMux)
|
||||
{
|
||||
case AdcJQRCH0MUX:
|
||||
M0P_ADC->JQR_f.CH0MUX = enstcAdcSampCh;
|
||||
break;
|
||||
case AdcJQRCH1MUX:
|
||||
M0P_ADC->JQR_f.CH1MUX = enstcAdcSampCh;
|
||||
break;
|
||||
case AdcJQRCH2MUX:
|
||||
M0P_ADC->JQR_f.CH2MUX = enstcAdcSampCh;
|
||||
break;
|
||||
case AdcJQRCH3MUX:
|
||||
M0P_ADC->JQR_f.CH3MUX = enstcAdcSampCh;
|
||||
break;
|
||||
default:
|
||||
enResult = ErrorInvalidParameter;
|
||||
break;
|
||||
}
|
||||
|
||||
return enResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief
|
||||
* 获取采样值
|
||||
*
|
||||
*
|
||||
* \retval en_result_t 采样值
|
||||
*/
|
||||
uint32_t Adc_GetSglResult(void)
|
||||
{
|
||||
return M0P_ADC->RESULT;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief
|
||||
* 获取采样值
|
||||
*
|
||||
* \param [in] enstcAdcSqrChMux 顺序扫描通道序号 @ref en_adc_sqr_chmux_t
|
||||
*
|
||||
* \retval en_result_t 采样值
|
||||
*/
|
||||
uint32_t Adc_GetSqrResult(en_adc_sqr_chmux_t enstcAdcSqrChMux)
|
||||
{
|
||||
volatile uint32_t *BaseSqrResultAddress = &(M0P_ADC->SQRRESULT0);
|
||||
|
||||
return *(BaseSqrResultAddress + enstcAdcSqrChMux);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief
|
||||
* 获取插队扫描采样值
|
||||
*
|
||||
* \param [in] enstcAdcJqrChMux 插队扫描通道序号@ref en_adc_jqr_chmux_t
|
||||
*
|
||||
* \retval en_result_t 采样值
|
||||
*/
|
||||
uint32_t Adc_GetJqrResult(en_adc_jqr_chmux_t enstcAdcJqrChMux)
|
||||
{
|
||||
volatile uint32_t *BaseJqrResultAddress = &(M0P_ADC->JQRRESULT0);
|
||||
|
||||
return *(BaseJqrResultAddress + enstcAdcJqrChMux);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief
|
||||
* 获取累加采样值
|
||||
*
|
||||
*
|
||||
* \retval en_result_t 累加采样结果
|
||||
*/
|
||||
uint32_t Adc_GetAccResult(void)
|
||||
{
|
||||
return M0P_ADC->RESULTACC;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief
|
||||
* 清零累加采样值
|
||||
*
|
||||
* \param 无
|
||||
*
|
||||
* \retval 无
|
||||
*/
|
||||
void Adc_ClrAccResult(void)
|
||||
{
|
||||
M0P_ADC->CR1_f.RACCCLR = 0u;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief
|
||||
* ADC比较使能(比较中断)
|
||||
*
|
||||
* \param [in] pstcAdcIrqCfg ADC比较配置 @ref stc_adc_threshold_cfg_t
|
||||
*
|
||||
* \retval 无
|
||||
*/
|
||||
|
||||
void Adc_ThresholdCfg(stc_adc_threshold_cfg_t* pstcAdcThrCfg)
|
||||
{
|
||||
M0P_ADC->HT = pstcAdcThrCfg->u32AdcHighThd;
|
||||
M0P_ADC->LT = pstcAdcThrCfg->u32AdcLowThd;
|
||||
|
||||
M0P_ADC->CR1_f.THCH = pstcAdcThrCfg->enSampChSel;
|
||||
|
||||
M0P_ADC->CR1_f.REGCMP = pstcAdcThrCfg->bAdcRegCmp;
|
||||
M0P_ADC->CR1_f.HTCMP = pstcAdcThrCfg->bAdcHtCmp;
|
||||
M0P_ADC->CR1_f.LTCMP = pstcAdcThrCfg->bAdcLtCmp;
|
||||
|
||||
}
|
||||
|
||||
|
||||
//@} // AdcGroup
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* EOF (not truncated)
|
||||
******************************************************************************/
|
||||
|
||||
+1657
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,206 @@
|
||||
/******************************************************************************
|
||||
*Copyright(C)2017, Huada Semiconductor Co.,Ltd All rights reserved.
|
||||
*
|
||||
* This software is owned and published by:
|
||||
* Huada Semiconductor Co.,Ltd("HDSC").
|
||||
*
|
||||
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
|
||||
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
|
||||
*
|
||||
* This software contains source code for use with HDSC
|
||||
* components. This software is licensed by HDSC to be adapted only
|
||||
* for use in systems utilizing HDSC components. HDSC shall not be
|
||||
* responsible for misuse or illegal use of this software for devices not
|
||||
* supported herein. HDSC is providing this software "AS IS" and will
|
||||
* not be responsible for issues arising from incorrect user implementation
|
||||
* of the software.
|
||||
*
|
||||
* Disclaimer:
|
||||
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
|
||||
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
|
||||
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
|
||||
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
|
||||
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
|
||||
* WARRANTY OF NONINFRINGEMENT.
|
||||
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
|
||||
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
|
||||
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
|
||||
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
|
||||
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
|
||||
* SAVINGS OR PROFITS,
|
||||
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
|
||||
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
|
||||
* FROM, THE SOFTWARE.
|
||||
*
|
||||
* This software may be replicated in part or whole for the licensed use,
|
||||
* with the restriction that this Disclaimer and Copyright notice must be
|
||||
* included with each copy of this software, whether used in part or whole,
|
||||
* at all times.
|
||||
*/
|
||||
|
||||
/** \file aes.c
|
||||
**
|
||||
** Common API of AES.
|
||||
** @link AesGroup Some description @endlink
|
||||
**
|
||||
** - 2019-04-16
|
||||
**
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Include files
|
||||
******************************************************************************/
|
||||
#include "aes.h"
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \addtogroup AesGroup
|
||||
******************************************************************************/
|
||||
//@{
|
||||
|
||||
/*******************************************************************************
|
||||
* Local pre-processor symbols/macros ('#define')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Global variable definitions (declared in header file with 'extern')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Local type definitions ('typedef')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Local variable definitions ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Local function prototypes ('static')
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Function implementation - global ('extern') and local ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* \brief
|
||||
* AES 加密
|
||||
*
|
||||
* \param [in] pstcAesCfg AES 配置结构体 @ref stc_aes_cfg_t
|
||||
*
|
||||
* \retval en_result_t Ok: 配置成功
|
||||
* \retval en_result_t ErrorInvalidParameter: 无效参数
|
||||
*/
|
||||
en_result_t AES_Encrypt(stc_aes_cfg_t* pstcAesCfg)
|
||||
{
|
||||
if (NULL == pstcAesCfg)
|
||||
{
|
||||
return ErrorInvalidParameter;
|
||||
}
|
||||
|
||||
M0P_AES->CR_f.KEYSIZE = pstcAesCfg->enKeyLen;
|
||||
|
||||
//Key cfg
|
||||
M0P_AES->KEY0 = pstcAesCfg->pu32Key[0];
|
||||
M0P_AES->KEY1 = pstcAesCfg->pu32Key[1];
|
||||
M0P_AES->KEY2 = pstcAesCfg->pu32Key[2];
|
||||
M0P_AES->KEY3 = pstcAesCfg->pu32Key[3];
|
||||
|
||||
if(AesKey192 == pstcAesCfg->enKeyLen)
|
||||
{
|
||||
M0P_AES->KEY4 = pstcAesCfg->pu32Key[4];
|
||||
M0P_AES->KEY5 = pstcAesCfg->pu32Key[5];
|
||||
}
|
||||
|
||||
if(AesKey256 == pstcAesCfg->enKeyLen)
|
||||
{
|
||||
M0P_AES->KEY4 = pstcAesCfg->pu32Key[4];
|
||||
M0P_AES->KEY5 = pstcAesCfg->pu32Key[5];
|
||||
M0P_AES->KEY6 = pstcAesCfg->pu32Key[6];
|
||||
M0P_AES->KEY7 = pstcAesCfg->pu32Key[7];
|
||||
}
|
||||
|
||||
//Data cfg
|
||||
M0P_AES->DATA0 = pstcAesCfg->pu32Plaintext[0];
|
||||
M0P_AES->DATA1 = pstcAesCfg->pu32Plaintext[1];
|
||||
M0P_AES->DATA2 = pstcAesCfg->pu32Plaintext[2];
|
||||
M0P_AES->DATA3 = pstcAesCfg->pu32Plaintext[3];
|
||||
|
||||
M0P_AES->CR_f.MODE = 0;//Encry
|
||||
M0P_AES->CR_f.START = 1;
|
||||
while(M0P_AES->CR_f.START == 1)
|
||||
{
|
||||
;
|
||||
}
|
||||
pstcAesCfg->pu32Cipher[0] = M0P_AES->DATA0;
|
||||
pstcAesCfg->pu32Cipher[1] = M0P_AES->DATA1;
|
||||
pstcAesCfg->pu32Cipher[2] = M0P_AES->DATA2;
|
||||
pstcAesCfg->pu32Cipher[3] = M0P_AES->DATA3;
|
||||
return Ok;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief
|
||||
* AES 解密
|
||||
*
|
||||
* \param [in] pstcAesCfg AES 配置结构体 @ref stc_aes_cfg_t
|
||||
*
|
||||
* \retval en_result_t Ok: 配置成功
|
||||
* \retval en_result_t ErrorInvalidParameter: 无效参数
|
||||
*/
|
||||
en_result_t AES_Decrypt(stc_aes_cfg_t* pstcAesCfg)
|
||||
{
|
||||
if (NULL == pstcAesCfg)
|
||||
{
|
||||
return ErrorInvalidParameter;
|
||||
}
|
||||
|
||||
M0P_AES->CR_f.KEYSIZE = pstcAesCfg->enKeyLen;
|
||||
|
||||
//Key cfg
|
||||
M0P_AES->KEY0 = pstcAesCfg->pu32Key[0];
|
||||
M0P_AES->KEY1 = pstcAesCfg->pu32Key[1];
|
||||
M0P_AES->KEY2 = pstcAesCfg->pu32Key[2];
|
||||
M0P_AES->KEY3 = pstcAesCfg->pu32Key[3];
|
||||
|
||||
if(AesKey192 == pstcAesCfg->enKeyLen)
|
||||
{
|
||||
M0P_AES->KEY4 = pstcAesCfg->pu32Key[4];
|
||||
M0P_AES->KEY5 = pstcAesCfg->pu32Key[5];
|
||||
}
|
||||
|
||||
if(AesKey256 == pstcAesCfg->enKeyLen)
|
||||
{
|
||||
M0P_AES->KEY4 = pstcAesCfg->pu32Key[4];
|
||||
M0P_AES->KEY5 = pstcAesCfg->pu32Key[5];
|
||||
M0P_AES->KEY6 = pstcAesCfg->pu32Key[6];
|
||||
M0P_AES->KEY7 = pstcAesCfg->pu32Key[7];
|
||||
}
|
||||
|
||||
//Data cfg
|
||||
M0P_AES->DATA0 = pstcAesCfg->pu32Cipher[0];
|
||||
M0P_AES->DATA1 = pstcAesCfg->pu32Cipher[1];
|
||||
M0P_AES->DATA2 = pstcAesCfg->pu32Cipher[2];
|
||||
M0P_AES->DATA3 = pstcAesCfg->pu32Cipher[3];
|
||||
|
||||
M0P_AES->CR_f.MODE = 1;//UnEncry
|
||||
M0P_AES->CR_f.START = 1;
|
||||
while(M0P_AES->CR_f.START == 1)
|
||||
{
|
||||
;
|
||||
}
|
||||
pstcAesCfg->pu32Plaintext[0] = M0P_AES->DATA0;
|
||||
pstcAesCfg->pu32Plaintext[1] = M0P_AES->DATA1;
|
||||
pstcAesCfg->pu32Plaintext[2] = M0P_AES->DATA2;
|
||||
pstcAesCfg->pu32Plaintext[3] = M0P_AES->DATA3;
|
||||
return Ok;
|
||||
}
|
||||
|
||||
//@} // AesGroup
|
||||
|
||||
/*******************************************************************************
|
||||
* EOF (not truncated)
|
||||
******************************************************************************/
|
||||
@@ -0,0 +1,143 @@
|
||||
/******************************************************************************
|
||||
*Copyright(C)2018, Huada Semiconductor Co.,Ltd All rights reserved.
|
||||
*
|
||||
* This software is owned and published by:
|
||||
* Huada Semiconductor Co.,Ltd("HDSC").
|
||||
*
|
||||
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
|
||||
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
|
||||
*
|
||||
* This software contains source code for use with HDSC
|
||||
* components. This software is licensed by HDSC to be adapted only
|
||||
* for use in systems utilizing HDSC components. HDSC shall not be
|
||||
* responsible for misuse or illegal use of this software for devices not
|
||||
* supported herein. HDSC is providing this software "AS IS" and will
|
||||
* not be responsible for issues arising from incorrect user implementation
|
||||
* of the software.
|
||||
*
|
||||
* Disclaimer:
|
||||
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
|
||||
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
|
||||
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
|
||||
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
|
||||
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
|
||||
* WARRANTY OF NONINFRINGEMENT.
|
||||
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
|
||||
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
|
||||
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
|
||||
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
|
||||
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
|
||||
* SAVINGS OR PROFITS,
|
||||
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
|
||||
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
|
||||
* FROM, THE SOFTWARE.
|
||||
*
|
||||
* This software may be replicated in part or whole for the licensed use,
|
||||
* with the restriction that this Disclaimer and Copyright notice must be
|
||||
* included with each copy of this software, whether used in part or whole,
|
||||
* at all times.
|
||||
*/
|
||||
|
||||
/** \file bgr.c
|
||||
**
|
||||
** Common API of bgr.
|
||||
** @link flashGroup Some description @endlink
|
||||
**
|
||||
** - 2018-05-08
|
||||
**
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Include files
|
||||
******************************************************************************/
|
||||
#include "bgr.h"
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \addtogroup FlashGroup
|
||||
******************************************************************************/
|
||||
//@{
|
||||
|
||||
/*******************************************************************************
|
||||
* Local pre-processor symbols/macros ('#define')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Global variable definitions (declared in header file with 'extern')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Local type definitions ('typedef')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Local variable definitions ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Local function prototypes ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Function implementation - global ('extern') and local ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief BGR 使能
|
||||
**
|
||||
**
|
||||
** \retval Null
|
||||
*****************************************************************************/
|
||||
void Bgr_BgrEnable(void)
|
||||
{
|
||||
M0P_BGR->CR |= 0x1u;
|
||||
|
||||
delay10us(2);
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief BGR 禁止
|
||||
**
|
||||
**
|
||||
** \retval Null
|
||||
*****************************************************************************/
|
||||
void Bgr_BgrDisable(void)
|
||||
{
|
||||
M0P_BGR->CR &= 0x2u;
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief BGR 温度传感器使能(需要先开启BGR)
|
||||
**
|
||||
**
|
||||
** \retval Null
|
||||
*****************************************************************************/
|
||||
void Bgr_TempSensorEnable(void)
|
||||
{
|
||||
M0P_BGR->CR |= 0x2u;
|
||||
|
||||
delay10us(2);
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief BGR 温度传感器禁止
|
||||
**
|
||||
**
|
||||
** \retval Null
|
||||
*****************************************************************************/
|
||||
void Bgr_TempSensorDisable(void)
|
||||
{
|
||||
M0P_BGR->CR &= 0x1u;
|
||||
}
|
||||
|
||||
|
||||
//@} // BgrGroup
|
||||
|
||||
/*******************************************************************************
|
||||
* EOF (not truncated)
|
||||
******************************************************************************/
|
||||
+1381
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,438 @@
|
||||
/******************************************************************************
|
||||
*Copyright(C)2017, Huada Semiconductor Co.,Ltd All rights reserved.
|
||||
*
|
||||
* This software is owned and published by:
|
||||
* Huada Semiconductor Co.,Ltd("HDSC").
|
||||
*
|
||||
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
|
||||
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
|
||||
*
|
||||
* This software contains source code for use with HDSC
|
||||
* components. This software is licensed by HDSC to be adapted only
|
||||
* for use in systems utilizing HDSC components. HDSC shall not be
|
||||
* responsible for misuse or illegal use of this software for devices not
|
||||
* supported herein. HDSC is providing this software "AS IS" and will
|
||||
* not be responsible for issues arising from incorrect user implementation
|
||||
* of the software.
|
||||
*
|
||||
* Disclaimer:
|
||||
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
|
||||
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
|
||||
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
|
||||
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
|
||||
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
|
||||
* WARRANTY OF NONINFRINGEMENT.
|
||||
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
|
||||
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
|
||||
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
|
||||
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
|
||||
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
|
||||
* SAVINGS OR PROFITS,
|
||||
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
|
||||
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
|
||||
* FROM, THE SOFTWARE.
|
||||
*
|
||||
* This software may be replicated in part or whole for the licensed use,
|
||||
* with the restriction that this Disclaimer and Copyright notice must be
|
||||
* included with each copy of this software, whether used in part or whole,
|
||||
* at all times.
|
||||
*/
|
||||
|
||||
/** \file crc.c
|
||||
**
|
||||
** Common API of crc.
|
||||
** @link crcGroup Some description @endlink
|
||||
**
|
||||
** - 2017-05-16
|
||||
**
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Include files
|
||||
******************************************************************************/
|
||||
#include "crc.h"
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \addtogroup CrcGroup
|
||||
******************************************************************************/
|
||||
//@{
|
||||
|
||||
/*******************************************************************************
|
||||
* Local pre-processor symbols/macros ('#define')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Global variable definitions (declared in header file with 'extern')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Local type definitions ('typedef')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Local variable definitions ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Local function prototypes ('static')
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Function implementation - global ('extern') and local ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief CRC16 编码(字节填充方式)
|
||||
**
|
||||
** 该函数主要用于生成CRC16编码.
|
||||
**
|
||||
** \param [in] pu8Data 待编码数据指针(字节方式输入)
|
||||
** \param [in] u32Len 待编码数据长度(字节数)
|
||||
**
|
||||
** \retval CRC16 CRC16编码值.
|
||||
*****************************************************************************/
|
||||
uint16_t CRC16_Get8(uint8_t* pu8Data, uint32_t u32Len)
|
||||
{
|
||||
uint32_t u32Index = 0;
|
||||
|
||||
M0P_CRC->CR_f.CR = 0;
|
||||
M0P_CRC->RESULT = 0xFFFF;
|
||||
for(u32Index = 0;u32Index<u32Len;u32Index++)
|
||||
{
|
||||
*((volatile uint8_t*)(&(M0P_CRC->DATA))) = pu8Data[u32Index];
|
||||
}
|
||||
|
||||
return (M0P_CRC->RESULT_f.RESULT);
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief CRC16 编码(半字填充方式)
|
||||
**
|
||||
** 该函数主要用于生成CRC16编码.
|
||||
**
|
||||
** \param [in] pu16Data 待编码数据指针(半字方式输入)
|
||||
** \param [in] u32Len 待编码数据长度(半字数)
|
||||
**
|
||||
** \retval CRC16 CRC16编码值.
|
||||
*****************************************************************************/
|
||||
uint16_t CRC16_Get16(uint16_t* pu16Data, uint32_t u32Len)
|
||||
{
|
||||
uint32_t u32Index = 0;
|
||||
|
||||
M0P_CRC->CR_f.CR = 0;
|
||||
M0P_CRC->RESULT_f.RESULT = 0xFFFF;
|
||||
for (u32Index=0; u32Index<u32Len; u32Index++)
|
||||
{
|
||||
*((volatile uint16_t*)(&(M0P_CRC->DATA))) = pu16Data[u32Index];
|
||||
}
|
||||
|
||||
return (M0P_CRC->RESULT_f.RESULT);
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief CRC16 编码(字填充方式)
|
||||
**
|
||||
** 该函数主要用于生成CRC16编码.
|
||||
**
|
||||
** \param [in] pu32Data 待编码数据指针(字方式输入)
|
||||
** \param [in] u32Len 待编码数据长度(字数)
|
||||
**
|
||||
** \retval CRC16 CRC16编码值.
|
||||
*****************************************************************************/
|
||||
uint16_t CRC16_Get32(uint32_t* pu32Data, uint32_t u32Len)
|
||||
{
|
||||
uint32_t u32Index = 0;
|
||||
|
||||
M0P_CRC->CR_f.CR = 0;
|
||||
M0P_CRC->RESULT_f.RESULT = 0xFFFF;
|
||||
for (u32Index=0; u32Index<u32Len; u32Index++)
|
||||
{
|
||||
M0P_CRC->DATA_f.DATA = pu32Data[u32Index];
|
||||
}
|
||||
|
||||
return (M0P_CRC->RESULT_f.RESULT);
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief CRC16 校验(字节填充方式)
|
||||
**
|
||||
** 该函数主要用于对数据及CRC16值进行校验.
|
||||
**
|
||||
** \param [in] pu8Data 待校验数据指针(字节方式输入)
|
||||
** \param [in] u32Len 待校验数据长度(字节数)
|
||||
** \param [in] u16CRC 待校验CRC16值
|
||||
**
|
||||
** \retval Ok CRC校验正确
|
||||
** \retval Error CRC校验错误
|
||||
*****************************************************************************/
|
||||
en_result_t CRC16_Check8(uint8_t* pu8Data, uint32_t u32Len, uint16_t u16CRC)
|
||||
{
|
||||
en_result_t enResult = Ok;
|
||||
uint32_t u32Index = 0;
|
||||
|
||||
M0P_CRC->CR_f.CR = 0;
|
||||
M0P_CRC->RESULT_f.RESULT = 0xFFFF;
|
||||
for (u32Index=0; u32Index<u32Len; u32Index++)
|
||||
{
|
||||
*((volatile uint8_t*)(&(M0P_CRC->DATA))) = pu8Data[u32Index];
|
||||
}
|
||||
|
||||
*((volatile uint8_t*)(&(M0P_CRC->DATA))) = (uint8_t)((((uint32_t)u16CRC)>>0)&0xFF);
|
||||
*((volatile uint8_t*)(&(M0P_CRC->DATA))) = (uint8_t)(((uint32_t)u16CRC>>8)&0xFF);
|
||||
|
||||
enResult = M0P_CRC->CR_f.FLAG ? Ok : Error;
|
||||
|
||||
return (enResult);
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief CRC16 校验(半字填充方式)
|
||||
**
|
||||
** 该函数主要用于对数据及CRC16值进行校验.
|
||||
**
|
||||
** \param [in] pu16Data 待校验数据指针(半字方式输入)
|
||||
** \param [in] u32Len 待校验数据长度(半字数)
|
||||
** \param [in] u16CRC 待校验CRC16值
|
||||
**
|
||||
** \retval Ok CRC校验正确
|
||||
** \retval Error CRC校验错误
|
||||
*****************************************************************************/
|
||||
en_result_t CRC16_Check16(uint16_t* pu16Data, uint32_t u32Len, uint16_t u16CRC)
|
||||
{
|
||||
en_result_t enResult = Ok;
|
||||
uint32_t u32Index = 0;
|
||||
|
||||
M0P_CRC->CR_f.CR = 0;
|
||||
M0P_CRC->RESULT_f.RESULT = 0xFFFF;
|
||||
for (u32Index=0; u32Index<u32Len; u32Index++)
|
||||
{
|
||||
*((volatile uint16_t*)(&(M0P_CRC->DATA))) = pu16Data[u32Index];
|
||||
}
|
||||
|
||||
*((volatile uint16_t*)(&(M0P_CRC->DATA))) = u16CRC;
|
||||
|
||||
enResult = M0P_CRC->CR_f.FLAG ? Ok : Error;
|
||||
|
||||
return (enResult);
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief CRC16 校验(字填充方式)
|
||||
**
|
||||
** 该函数主要用于对数据及CRC16值进行校验.
|
||||
**
|
||||
** \param [in] pu32Data 待校验数据指针(字方式输入)
|
||||
** \param [in] u32Len 待校验数据长度(字数)
|
||||
** \param [in] u16CRC 待校验CRC16值
|
||||
**
|
||||
** \retval Ok CRC校验正确
|
||||
** \retval Error CRC校验错误
|
||||
*****************************************************************************/
|
||||
en_result_t CRC16_Check32(uint32_t* pu32Data, uint32_t u32Len, uint16_t u16CRC)
|
||||
{
|
||||
en_result_t enResult = Ok;
|
||||
uint32_t u32Index = 0;
|
||||
|
||||
M0P_CRC->CR_f.CR = 0;
|
||||
M0P_CRC->RESULT_f.RESULT = 0xFFFFFFFFu;
|
||||
for (u32Index=0; u32Index<u32Len; u32Index++)
|
||||
{
|
||||
*((volatile uint32_t*)(&(M0P_CRC->DATA))) = pu32Data[u32Index];
|
||||
}
|
||||
|
||||
*((volatile uint16_t*)(&(M0P_CRC->DATA))) = ((uint16_t)u16CRC);
|
||||
|
||||
enResult = M0P_CRC->CR_f.FLAG ? Ok : Error;
|
||||
|
||||
return (enResult);
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief CRC16 编码(字节填充方式)
|
||||
**
|
||||
** 该函数主要用于生成CRC16编码.
|
||||
**
|
||||
** \param [in] pu8Data 待编码数据指针(字节方式输入)
|
||||
** \param [in] u32Len 待编码数据长度(字节数)
|
||||
**
|
||||
** \retval CRC16 CRC16编码值.
|
||||
*****************************************************************************/
|
||||
uint32_t CRC32_Get8(uint8_t* pu8Data, uint32_t u32Len)
|
||||
{
|
||||
uint32_t u32Index = 0;
|
||||
|
||||
M0P_CRC->CR_f.CR = 1;
|
||||
M0P_CRC->RESULT = 0xFFFFFFFFu;
|
||||
for(u32Index = 0;u32Index<u32Len;u32Index++)
|
||||
{
|
||||
*((volatile uint8_t*)(&(M0P_CRC->DATA))) = pu8Data[u32Index];
|
||||
}
|
||||
|
||||
return (M0P_CRC->RESULT_f.RESULT);
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief CRC16 编码(半字填充方式)
|
||||
**
|
||||
** 该函数主要用于生成CRC16编码.
|
||||
**
|
||||
** \param [in] pu16Data 待编码数据指针(半字方式输入)
|
||||
** \param [in] u32Len 待编码数据长度(半字数)
|
||||
**
|
||||
** \retval CRC16 CRC16编码值.
|
||||
*****************************************************************************/
|
||||
uint32_t CRC32_Get16(uint16_t* pu16Data, uint32_t u32Len)
|
||||
{
|
||||
uint32_t u32Index = 0;
|
||||
|
||||
M0P_CRC->CR_f.CR = 1;
|
||||
M0P_CRC->RESULT_f.RESULT = 0xFFFFFFFFu;
|
||||
for (u32Index=0; u32Index<u32Len; u32Index++)
|
||||
{
|
||||
*((volatile uint16_t*)(&(M0P_CRC->DATA))) = pu16Data[u32Index];
|
||||
}
|
||||
|
||||
return (M0P_CRC->RESULT_f.RESULT);
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief CRC16 编码(字填充方式)
|
||||
**
|
||||
** 该函数主要用于生成CRC16编码.
|
||||
**
|
||||
** \param [in] pu32Data 待编码数据指针(字方式输入)
|
||||
** \param [in] u32Len 待编码数据长度(字数)
|
||||
**
|
||||
** \retval CRC16 CRC16编码值.
|
||||
*****************************************************************************/
|
||||
uint32_t CRC32_Get32(uint32_t* pu32Data, uint32_t u32Len)
|
||||
{
|
||||
uint32_t u32Index = 0;
|
||||
|
||||
M0P_CRC->CR_f.CR = 1;
|
||||
M0P_CRC->RESULT_f.RESULT = 0xFFFFFFFFu;
|
||||
for (u32Index=0; u32Index<u32Len; u32Index++)
|
||||
{
|
||||
M0P_CRC->DATA_f.DATA = pu32Data[u32Index];
|
||||
}
|
||||
|
||||
return (M0P_CRC->RESULT_f.RESULT);
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief CRC16 校验(字节填充方式)
|
||||
**
|
||||
** 该函数主要用于对数据及CRC16值进行校验.
|
||||
**
|
||||
** \param [in] pu8Data 待校验数据指针(字节方式输入)
|
||||
** \param [in] u32Len 待校验数据长度(字节数)
|
||||
** \param [in] u16CRC 待校验CRC16值
|
||||
**
|
||||
** \retval Ok CRC校验正确
|
||||
** \retval Error CRC校验错误
|
||||
*****************************************************************************/
|
||||
en_result_t CRC32_Check8(uint8_t* pu8Data, uint32_t u32Len, uint32_t u32CRC)
|
||||
{
|
||||
en_result_t enResult = Ok;
|
||||
uint32_t u32Index = 0;
|
||||
|
||||
M0P_CRC->CR_f.CR = 1;
|
||||
M0P_CRC->RESULT_f.RESULT = 0xFFFFFFFFu;
|
||||
for (u32Index=0; u32Index<u32Len; u32Index++)
|
||||
{
|
||||
*((volatile uint8_t*)(&(M0P_CRC->DATA))) = pu8Data[u32Index];
|
||||
}
|
||||
|
||||
*((volatile uint8_t*)(&(M0P_CRC->DATA))) = (uint8_t)((u32CRC>>0)&0xFF);
|
||||
*((volatile uint8_t*)(&(M0P_CRC->DATA))) = (uint8_t)((u32CRC>>8)&0xFF);
|
||||
*((volatile uint8_t*)(&(M0P_CRC->DATA))) = (uint8_t)((u32CRC>>16)&0xFF);
|
||||
*((volatile uint8_t*)(&(M0P_CRC->DATA))) = (uint8_t)((u32CRC>>24)&0xFF);
|
||||
|
||||
enResult = M0P_CRC->CR_f.FLAG ? Ok : Error;
|
||||
|
||||
return (enResult);
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief CRC16 校验(半字填充方式)
|
||||
**
|
||||
** 该函数主要用于对数据及CRC16值进行校验.
|
||||
**
|
||||
** \param [in] pu16Data 待校验数据指针(半字方式输入)
|
||||
** \param [in] u32Len 待校验数据长度(半字数)
|
||||
** \param [in] u16CRC 待校验CRC16值
|
||||
**
|
||||
** \retval Ok CRC校验正确
|
||||
** \retval Error CRC校验错误
|
||||
*****************************************************************************/
|
||||
en_result_t CRC32_Check16(uint16_t* pu16Data, uint32_t u32Len, uint32_t u32CRC)
|
||||
{
|
||||
en_result_t enResult = Ok;
|
||||
uint32_t u32Index = 0;
|
||||
|
||||
M0P_CRC->CR_f.CR = 1;
|
||||
M0P_CRC->RESULT_f.RESULT = 0xFFFFFFFFu;
|
||||
for (u32Index=0; u32Index<u32Len; u32Index++)
|
||||
{
|
||||
*((volatile uint16_t*)(&(M0P_CRC->DATA))) = pu16Data[u32Index];
|
||||
}
|
||||
|
||||
*((volatile uint16_t*)(&(M0P_CRC->DATA))) = (uint16_t)((u32CRC>>0)&0xFFFF);
|
||||
*((volatile uint16_t*)(&(M0P_CRC->DATA))) = (uint16_t)((u32CRC>>16)&0xFFFF);
|
||||
|
||||
|
||||
enResult = M0P_CRC->CR_f.FLAG ? Ok : Error;
|
||||
|
||||
return (enResult);
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief CRC16 校验(字填充方式)
|
||||
**
|
||||
** 该函数主要用于对数据及CRC16值进行校验.
|
||||
**
|
||||
** \param [in] pu32Data 待校验数据指针(字方式输入)
|
||||
** \param [in] u32Len 待校验数据长度(字数)
|
||||
** \param [in] u16CRC 待校验CRC16值
|
||||
**
|
||||
** \retval Ok CRC校验正确
|
||||
** \retval Error CRC校验错误
|
||||
*****************************************************************************/
|
||||
en_result_t CRC32_Check32(uint32_t* pu32Data, uint32_t u32Len, uint32_t u32CRC)
|
||||
{
|
||||
en_result_t enResult = Ok;
|
||||
uint32_t u32Index = 0;
|
||||
|
||||
M0P_CRC->CR_f.CR = 1;
|
||||
M0P_CRC->RESULT_f.RESULT = 0xFFFFFFFFu;
|
||||
for (u32Index=0; u32Index<u32Len; u32Index++)
|
||||
{
|
||||
*((volatile uint32_t*)(&(M0P_CRC->DATA))) = pu32Data[u32Index];
|
||||
}
|
||||
|
||||
*((volatile uint32_t*)(&(M0P_CRC->DATA))) = u32CRC;
|
||||
|
||||
enResult = M0P_CRC->CR_f.FLAG ? Ok : Error;
|
||||
|
||||
return (enResult);
|
||||
}
|
||||
//@} // CrcGroup
|
||||
|
||||
/*******************************************************************************
|
||||
* EOF (not truncated)
|
||||
******************************************************************************/
|
||||
@@ -0,0 +1,253 @@
|
||||
/******************************************************************************
|
||||
* Copyright (C) 2019, Huada Semiconductor Co.,Ltd All rights reserved.
|
||||
*
|
||||
* This software is owned and published by:
|
||||
* Huada Semiconductor Co.,Ltd ("HDSC").
|
||||
*
|
||||
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
|
||||
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
|
||||
*
|
||||
* This software contains source code for use with HDSC
|
||||
* components. This software is licensed by HDSC to be adapted only
|
||||
* for use in systems utilizing HDSC components. HDSC shall not be
|
||||
* responsible for misuse or illegal use of this software for devices not
|
||||
* supported herein. HDSC is providing this software "AS IS" and will
|
||||
* not be responsible for issues arising from incorrect user implementation
|
||||
* of the software.
|
||||
*
|
||||
* Disclaimer:
|
||||
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
|
||||
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
|
||||
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
|
||||
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
|
||||
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
|
||||
* WARRANTY OF NONINFRINGEMENT.
|
||||
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
|
||||
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
|
||||
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
|
||||
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
|
||||
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
|
||||
* SAVINGS OR PROFITS,
|
||||
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
|
||||
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
|
||||
* FROM, THE SOFTWARE.
|
||||
*
|
||||
* This software may be replicated in part or whole for the licensed use,
|
||||
* with the restriction that this Disclaimer and Copyright notice must be
|
||||
* included with each copy of this software, whether used in part or whole,
|
||||
* at all times.
|
||||
*/
|
||||
/******************************************************************************/
|
||||
/** \file dac.c
|
||||
**
|
||||
** dac driver API.
|
||||
**
|
||||
** - 2019-04-10 First Version
|
||||
**
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* Include files
|
||||
******************************************************************************/
|
||||
#include "dac.h"
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \addtogroup AdcGroup
|
||||
******************************************************************************/
|
||||
//@{
|
||||
|
||||
/******************************************************************************
|
||||
* Local pre-processor symbols/macros ('#define')
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* Global variable definitions (declared in header file with 'extern')
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* Local type definitions ('typedef')
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* Local function prototypes ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* Local variable definitions ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* Function implementation - global ('extern') and local ('static')
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief 使能相关通道的DMA DMA_CR0中的DMAEN0
|
||||
**
|
||||
** @param NewState : TRUE 或者 FALSE
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Dac_DmaCmd(boolean_t NewState)
|
||||
{
|
||||
SetBit((uint32_t)(&(M0P_DAC->CR0)), 12, NewState);
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief 配置DAC的DMA下溢中断, DMA_CR0中的DMAUDRIE0
|
||||
**
|
||||
** @param NewState : TRUE 或者 FALSE
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Dac_DmaITCfg(boolean_t NewState)
|
||||
{
|
||||
SetBit((uint32_t)(&(M0P_DAC->CR0)), 13, NewState);
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief 获取DAC的DMA下溢中断标志位状态, DMA_SR中的DMAUDR0
|
||||
**
|
||||
** @param 无
|
||||
** \retval TRUE 或 FALSE
|
||||
**
|
||||
******************************************************************************/
|
||||
boolean_t Dac_GetITStatus(void)
|
||||
{
|
||||
return GetBit((uint32_t)(&(M0P_DAC->SR)), 13);
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief 配置DAC的使能与禁止, DMA_CR0中的EN0
|
||||
**
|
||||
** @param NewState : TRUE 或者 FALSE
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Dac_Cmd(boolean_t NewState)
|
||||
{
|
||||
SetBit((uint32_t)(&(M0P_DAC->CR0)), 0, NewState);
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief 软件触发寄存器,触发DAC转换 DMA_SWTRIGR中的SWTRIG0
|
||||
**
|
||||
** @param 无
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Dac_SoftwareTriggerCmd(void)
|
||||
{
|
||||
SetBit((uint32_t)(&(M0P_DAC->SWTRIGR)), 0, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief 初始化DAC0
|
||||
**
|
||||
** @param DAC_InitStruct : 用于初始化DAC0的结构体
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Dac_Init(stc_dac_cfg_t* DAC_InitStruct)
|
||||
{
|
||||
M0P_DAC->CR0_f.BOFF0 = DAC_InitStruct->boff_t;
|
||||
M0P_DAC->CR0_f.TEN0 = DAC_InitStruct->ten_t;
|
||||
M0P_DAC->CR0_f.TSEL0 = DAC_InitStruct->tsel_t;
|
||||
M0P_DAC->CR0_f.WAVE0 = DAC_InitStruct->wave_t;
|
||||
M0P_DAC->CR0_f.MAMP0 = DAC_InitStruct->mamp_t;
|
||||
M0P_DAC->CR0_f.SREF0 = DAC_InitStruct->sref_t;
|
||||
|
||||
if(DAC_InitStruct->align == DacLeftAlign)
|
||||
{
|
||||
M0P_DAC->DHR12L0_f.DHR0 = DAC_InitStruct->dhr12;
|
||||
}
|
||||
else if(DAC_InitStruct->align == DacRightAlign)
|
||||
{
|
||||
M0P_DAC->DHR12R0_f.DHR0 = DAC_InitStruct->dhr12;
|
||||
}
|
||||
else
|
||||
{
|
||||
M0P_DAC->DHR8R0_f.DHR0 = DAC_InitStruct->dhr8;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief 向DAC0的数据保持寄存器写数据
|
||||
**
|
||||
** @param DAC_Channel: Dac_0
|
||||
** @param DAC_Align : Right_Align 与Left_Align
|
||||
** @param DAC_Bit : Bit8 与Bit12
|
||||
** @param Data : 所要发送的数据
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Dac_SetChannelData(en_align_t DAC_Align, en_bitno_t DAC_Bit, uint16_t Data)
|
||||
{
|
||||
if(DAC_Align == DacRightAlign)
|
||||
{
|
||||
if(DAC_Bit == DacBit8)
|
||||
{
|
||||
M0P_DAC->DHR8R0_f.DHR0 = (uint8_t)Data;
|
||||
}
|
||||
else if(DAC_Bit == DacBit12)
|
||||
{
|
||||
M0P_DAC->DHR12R0_f.DHR0 = Data;
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if(DAC_Align == DacLeftAlign)
|
||||
{
|
||||
if(DAC_Bit == DacBit8)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if(DAC_Bit == DacBit12)
|
||||
{
|
||||
M0P_DAC->DHR12L0_f.DHR0 = Data;
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief 获取DAC数据输出寄存器DAC_DOR0
|
||||
**
|
||||
** @param 无
|
||||
** \retval DAC_DOR0的值
|
||||
**
|
||||
******************************************************************************/
|
||||
uint16_t Dac_GetDataOutputValue(void)
|
||||
{
|
||||
uint16_t tmp;
|
||||
|
||||
tmp = M0P_DAC->DOR0_f.DOR0;
|
||||
return tmp&0x0fff;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* EOF (not truncated)
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
@@ -0,0 +1,250 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (C) 2019, Huada Semiconductor Co.,Ltd All rights reserved.
|
||||
*
|
||||
* This software is owned and published by:
|
||||
* Huada Semiconductor Co.,Ltd ("HDSC").
|
||||
*
|
||||
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
|
||||
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
|
||||
*
|
||||
* This software contains source code for use with HDSC
|
||||
* components. This software is licensed by HDSC to be adapted only
|
||||
* for use in systems utilizing HDSC components. HDSC shall not be
|
||||
* responsible for misuse or illegal use of this software for devices not
|
||||
* supported herein. HDSC is providing this software "AS IS" and will
|
||||
* not be responsible for issues arising from incorrect user implementation
|
||||
* of the software.
|
||||
*
|
||||
* Disclaimer:
|
||||
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
|
||||
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
|
||||
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
|
||||
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
|
||||
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
|
||||
* WARRANTY OF NONINFRINGEMENT.
|
||||
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
|
||||
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
|
||||
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
|
||||
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
|
||||
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
|
||||
* SAVINGS OR PROFITS,
|
||||
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
|
||||
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
|
||||
* FROM, THE SOFTWARE.
|
||||
*
|
||||
* This software may be replicated in part or whole for the licensed use,
|
||||
* with the restriction that this Disclaimer and Copyright notice must be
|
||||
* included with each copy of this software, whether used in part or whole,
|
||||
* at all times.
|
||||
*/
|
||||
/******************************************************************************/
|
||||
/** \file ddl.c
|
||||
**
|
||||
** Common API of DDL.
|
||||
** @link ddlGroup Some description @endlink
|
||||
**
|
||||
** - 2019-03-03
|
||||
**
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
/* Include files */
|
||||
/******************************************************************************/
|
||||
#include "ddl.h"
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \addtogroup DDL Common Functions
|
||||
******************************************************************************/
|
||||
//@{
|
||||
|
||||
/******************************************************************************/
|
||||
/* Local pre-processor symbols/macros ('#define') */
|
||||
/******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
/* Global variable definitions (declared in header file with 'extern') */
|
||||
/******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
/* Local type definitions ('typedef') */
|
||||
/******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
/* Local variable definitions ('static') */
|
||||
/******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
/* Local function prototypes ('static') */
|
||||
/******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
/* Function implementation - global ('extern') and local ('static') */
|
||||
/******************************************************************************/
|
||||
#ifndef __DEBUG
|
||||
#define __DEBUG
|
||||
//#define __CC_ARM
|
||||
#endif
|
||||
|
||||
uint32_t Log2(uint32_t u32Val)
|
||||
{
|
||||
uint32_t u32V1 = 0;
|
||||
|
||||
if(0u == u32Val)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
while(u32Val > 1u)
|
||||
{
|
||||
u32V1++;
|
||||
u32Val /=2;
|
||||
}
|
||||
|
||||
return u32V1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief Memory clear function for DDL_ZERO_STRUCT()
|
||||
******************************************************************************/
|
||||
void ddl_memclr(void *pu8Address, uint32_t u32Count)
|
||||
{
|
||||
uint8_t *pu8Addr = (uint8_t *)pu8Address;
|
||||
|
||||
if(NULL == pu8Addr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
while (u32Count--)
|
||||
{
|
||||
*pu8Addr++ = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief delay1ms
|
||||
* delay approximately 1ms.
|
||||
* \param [in] u32Cnt
|
||||
* \retval void
|
||||
*/
|
||||
void delay1ms(uint32_t u32Cnt)
|
||||
{
|
||||
uint32_t u32end;
|
||||
|
||||
SysTick->LOAD = 0xFFFFFF;
|
||||
SysTick->VAL = 0;
|
||||
SysTick->CTRL = SysTick_CTRL_ENABLE_Msk | SysTick_CTRL_CLKSOURCE_Msk;
|
||||
|
||||
while(u32Cnt-- > 0)
|
||||
{
|
||||
SysTick->VAL = 0;
|
||||
u32end = 0x1000000 - SystemCoreClock/1000;
|
||||
while(SysTick->VAL > u32end)
|
||||
{
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
SysTick->CTRL = (SysTick->CTRL & (~SysTick_CTRL_ENABLE_Msk));
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief delay100us
|
||||
* delay approximately 100us.
|
||||
* \param [in] u32Cnt
|
||||
* \retval void
|
||||
*/
|
||||
void delay100us(uint32_t u32Cnt)
|
||||
{
|
||||
uint32_t u32end;
|
||||
|
||||
SysTick->LOAD = 0xFFFFFF;
|
||||
SysTick->VAL = 0;
|
||||
SysTick->CTRL = SysTick_CTRL_ENABLE_Msk | SysTick_CTRL_CLKSOURCE_Msk;
|
||||
|
||||
while(u32Cnt-- > 0)
|
||||
{
|
||||
SysTick->VAL = 0;
|
||||
|
||||
u32end = 0x1000000 - SystemCoreClock/10000;
|
||||
while(SysTick->VAL > u32end)
|
||||
{
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
SysTick->CTRL = (SysTick->CTRL & (~SysTick_CTRL_ENABLE_Msk));
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief delay10us
|
||||
* delay approximately 10us.
|
||||
* \param [in] u32Cnt
|
||||
* \retval void
|
||||
*/
|
||||
void delay10us(uint32_t u32Cnt)
|
||||
{
|
||||
uint32_t u32end;
|
||||
|
||||
SysTick->LOAD = 0xFFFFFF;
|
||||
SysTick->VAL = 0;
|
||||
SysTick->CTRL = SysTick_CTRL_ENABLE_Msk | SysTick_CTRL_CLKSOURCE_Msk;
|
||||
|
||||
while(u32Cnt-- > 0)
|
||||
{
|
||||
SysTick->VAL = 0;
|
||||
|
||||
u32end = 0x1000000 - SystemCoreClock/100000;
|
||||
while(SysTick->VAL > u32end)
|
||||
{
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
SysTick->CTRL = (SysTick->CTRL & (~SysTick_CTRL_ENABLE_Msk));
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief set register bit
|
||||
*
|
||||
* \param [in] addr
|
||||
* \param [in] offset
|
||||
* \retval void
|
||||
*/
|
||||
void SetBit(uint32_t addr, uint32_t offset, boolean_t bFlag)
|
||||
{
|
||||
if(TRUE == bFlag)
|
||||
{
|
||||
*((volatile uint32_t *)(addr)) |= ((1UL)<<(offset));
|
||||
}
|
||||
else
|
||||
{
|
||||
*((volatile uint32_t *)(addr)) &= (~(1UL<<(offset)));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief get register bit
|
||||
*
|
||||
* \param [in] addr
|
||||
* \param [in] offset
|
||||
* \retval void
|
||||
*/
|
||||
boolean_t GetBit(uint32_t addr, uint32_t offset)
|
||||
{
|
||||
return ((((*((volatile uint32_t *)(addr))) >> (offset)) & 1u) > 0) ? TRUE : FALSE;
|
||||
}
|
||||
//@} // DDL Functions
|
||||
|
||||
/******************************************************************************
|
||||
* EOF (not truncated)
|
||||
******************************************************************************/
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
/******************************************************************************
|
||||
*Copyright(C)2018, Huada Semiconductor Co.,Ltd All rights reserved.
|
||||
*
|
||||
* This software is owned and published by:
|
||||
* Huada Semiconductor Co.,Ltd("HDSC").
|
||||
*
|
||||
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
|
||||
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
|
||||
*
|
||||
* This software contains source code for use with HDSC
|
||||
* components. This software is licensed by HDSC to be adapted only
|
||||
* for use in systems utilizing HDSC components. HDSC shall not be
|
||||
* responsible for misuse or illegal use of this software for devices not
|
||||
* supported herein. HDSC is providing this software "AS IS" and will
|
||||
* not be responsible for issues arising from incorrect user implementation
|
||||
* of the software.
|
||||
*
|
||||
* Disclaimer:
|
||||
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
|
||||
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
|
||||
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
|
||||
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
|
||||
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
|
||||
* WARRANTY OF NONINFRINGEMENT.
|
||||
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
|
||||
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
|
||||
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
|
||||
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
|
||||
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
|
||||
* SAVINGS OR PROFITS,
|
||||
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
|
||||
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
|
||||
* FROM, THE SOFTWARE.
|
||||
*
|
||||
* This software may be replicated in part or whole for the licensed use,
|
||||
* with the restriction that this Disclaimer and Copyright notice must be
|
||||
* included with each copy of this software, whether used in part or whole,
|
||||
* at all times.
|
||||
*/
|
||||
|
||||
/** \file debug.c
|
||||
**
|
||||
** Common API of debug.
|
||||
** @link flashGroup Some description @endlink
|
||||
**
|
||||
** - 2018-05-08
|
||||
**
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Include files
|
||||
******************************************************************************/
|
||||
#include "debug.h"
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \addtogroup FlashGroup
|
||||
******************************************************************************/
|
||||
//@{
|
||||
|
||||
/*******************************************************************************
|
||||
* Local pre-processor symbols/macros ('#define')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Global variable definitions (declared in header file with 'extern')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Local type definitions ('typedef')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Local variable definitions ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Local function prototypes ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Function implementation - global ('extern') and local ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief 调试模式下模块功能计数使能
|
||||
**
|
||||
**
|
||||
** \retval TRUE or FALSE
|
||||
*****************************************************************************/
|
||||
en_result_t Debug_ActiveEnable(en_debug_module_active_t enModule)
|
||||
{
|
||||
M0P_DEBUG_ACTIVE->DEBUG_ACTIVE &= ~(uint32_t)enModule;
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief 调试模式下模块功能计数暂停
|
||||
**
|
||||
**
|
||||
** \retval TRUE or FALSE
|
||||
*****************************************************************************/
|
||||
en_result_t Debug_ActiveDisable(en_debug_module_active_t enModule)
|
||||
{
|
||||
M0P_DEBUG_ACTIVE->DEBUG_ACTIVE |= (uint32_t)enModule;
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
|
||||
//@} // BgrGroup
|
||||
|
||||
/*******************************************************************************
|
||||
* EOF (not truncated)
|
||||
******************************************************************************/
|
||||
@@ -0,0 +1,624 @@
|
||||
/******************************************************************************
|
||||
* Copyright (C) 2016, Huada Semiconductor Co.,Ltd All rights reserved.
|
||||
*
|
||||
* This software is owned and published by:
|
||||
* Huada Semiconductor Co.,Ltd ("HDSC").
|
||||
*
|
||||
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
|
||||
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
|
||||
*
|
||||
* This software contains source code for use with HDSC
|
||||
* components. This software is licensed by HDSC to be adapted only
|
||||
* for use in systems utilizing HDSC components. HDSC shall not be
|
||||
* responsible for misuse or illegal use of this software for devices not
|
||||
* supported herein. HDSC is providing this software "AS IS" and will
|
||||
* not be responsible for issues arising from incorrect user implementation
|
||||
* of the software.
|
||||
*
|
||||
* Disclaimer:
|
||||
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
|
||||
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
|
||||
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
|
||||
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
|
||||
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
|
||||
* WARRANTY OF NONINFRINGEMENT.
|
||||
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
|
||||
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
|
||||
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
|
||||
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
|
||||
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
|
||||
* SAVINGS OR PROFITS,
|
||||
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
|
||||
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
|
||||
* FROM, THE SOFTWARE.
|
||||
*
|
||||
* This software may be replicated in part or whole for the licensed use,
|
||||
* with the restriction that this Disclaimer and Copyright notice must be
|
||||
* included with each copy of this software, whether used in part or whole,
|
||||
* at all times.
|
||||
*/
|
||||
/******************************************************************************/
|
||||
/** \file dmac.c
|
||||
**
|
||||
** A detailed description is available at
|
||||
** @link DmacGroup Dmac description @endlink
|
||||
**
|
||||
** - 2018-03-09 1.0 Hongjh First version for Device Driver Library of Dmac.
|
||||
**
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Include files
|
||||
******************************************************************************/
|
||||
#include "dmac.h"
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \addtogroup DmacGroup
|
||||
******************************************************************************/
|
||||
//@{
|
||||
|
||||
/*******************************************************************************
|
||||
* Local type definitions ('typedef')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Local pre-processor symbols/macros ('#define')
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
/* DMA */
|
||||
/******************************************************************************/
|
||||
|
||||
/************** Bits definition for DMA_CONFBx(x=0~1) register *************/
|
||||
#define DMA_TRANSFER_WIDTH_Pos (26U) /*!< DMAC_CONFBx: ERR_IE Position */
|
||||
#define DMA_TRANSFER_WIDTH_Msk (0x03U << DMA_TRANSFER_WIDTH_Pos) /*!< DMAC_CONFBx: ERR_IE Mask 0x0C000000 */
|
||||
|
||||
/************** Bits definition for DMA_CONFBx(x=0~1) register *************/
|
||||
#define DMA_ERR_IE_Pos (20U) /*!< DMAC_CONFBx: ERR_IE Position */
|
||||
#define DMA_ERR_IE_Msk (0x01U << DMA_ERR_IE_Pos) /*!< DMAC_CONFBx: ERR_IE Mask 0x00000010 */
|
||||
|
||||
/************** Bits definition for DMA_CONFBx(x=0~1) register *************/
|
||||
#define DMA_FIS_IE_Pos (19U) /*!< DMAC_CONFBx: FIS_IE Position */
|
||||
#define DMA_FIS_IE_Msk (0x01U << DMA_FIS_IE_Pos) /*!< DMAC_CONFBx: FIS_IE Mask 0x00000010 */
|
||||
|
||||
/************** Bits definition for DMA_CONFBx(x=0~1) register *************/
|
||||
#define DMA_STAT_Pos (16U) /*!< DMAC_CONFBx: STAT Position */
|
||||
#define DMA_STAT_Msk (0x07U << DMA_STAT_Pos) /*!< DMAC_CONFBx: STAT Mask 0x00070000 */
|
||||
|
||||
/************** Bits definition for DMA_CONFBx(x=0~1) register *************/
|
||||
#define DMA_TRANSFER_RELOAD_Pos (0U) /*!< DMAC_CONFBx: MSK Position */
|
||||
#define DMA_TRANSFER_RELOAD_Msk (0x01U << DMA_TRANSFER_RELOAD_Pos) /*!< DMAC_CONFBx: MSK Mask 0x00000010 */
|
||||
|
||||
/************** Bits definition for DMA_CONFAx(x=0~1) register *************/
|
||||
#define DMA_CH_ENABLE_Pos (31U) /*!< DMAC_CONFAx: ENS Position */
|
||||
#define DMA_CH_ENABLE_Msk (0x01U << DMA_CH_ENABLE_Pos) /*!< DMAC_CONFAx: ENS Mask 0x80000000 */
|
||||
|
||||
/************** Bits definition for DMA_CONFAx(x=0~1) register *************/
|
||||
#define DMA_CH_PAUSE_Pos (30U) /*!< DMAC_CONFAx: PAS Position */
|
||||
#define DMA_CH_PAUSE_Msk (0x01U << DMA_CH_PAUSE_Pos) /*!< DMAC_CONFAx: PAS Mask 0x40000000 */
|
||||
|
||||
/************** Bits definition for DMA_CONFAx(x=0~1) register *************/
|
||||
#define DMA_SOFTWARE_START_Pos (29U) /*!< DMAC_CONFAx: ENS Position */
|
||||
#define DMA_SOFTWARE_START_Msk (0x01U << DMA_SOFTWARE_START_Pos) /*!< DMAC_CONFAx: ENS Mask 0x20000000 */
|
||||
|
||||
/************** Bits definition for DMA_CONFAx(x=0~1) register *************/
|
||||
#define DMA_TRI_SEL_Pos (22U) /*!< DMAC_CONFAx: TRISEL Position */
|
||||
#define DMA_TRI_SEL_Msk (0x7FU << DMA_TRI_SEL_Pos) /*!< DMAC_CONFAx: TRISEL Mask 0x1FC00000 */
|
||||
|
||||
/************** Bits definition for DMA_CONFAx(x=0~1) register *************/
|
||||
#define DMA_BC_SEL_Pos (16U) /*!< DMAC_CONFAx: TRISEL Position */
|
||||
#define DMA_BC_SEL_Msk (0x0FU << DMA_BC_SEL_Pos) /*!< DMAC_CONFAx: TRISEL Mask 0x000F0000 */
|
||||
|
||||
/************** Bits definition for DMA_CONFAx(x=0~1) register *************/
|
||||
#define DMA_TC_SEL_Pos (0U) /*!< DMAC_CONFAx: TRISEL Position */
|
||||
#define DMA_TC_SEL_Msk (0xFFFFU << DMA_TC_SEL_Pos) /*!< DMAC_CONFAx: TRISEL Mask 0x0000FFFF */
|
||||
|
||||
/************** Bits definition for DMA_CONF register *************/
|
||||
#define DMA_ENABLE_Pos (31U) /*!< DMAC_CONF: TRISEL Position */
|
||||
#define DMA_ENABLE_Msk (0x01U << DMA_ENABLE_Pos) /*!< DMAC_CONF: TRISEL Mask 0x80000000 */
|
||||
|
||||
/************** Bits definition for DMA_CONF register *************/
|
||||
#define DMA_PRIORITY_Pos (28U) /*!< DMAC_CONF: TRISEL Position */
|
||||
#define DMA_PRIORITY_Msk (0x01U << DMA_PRIORITY_Pos) /*!< DMAC_CONF: TRISEL Mask 0x10000000 */
|
||||
|
||||
|
||||
/*! Dmac通道参数有效性检查. */
|
||||
#define IS_VALID_CH(x) \
|
||||
( (DmaCh0 == (x)) || \
|
||||
(DmaCh1 == (x)))
|
||||
|
||||
/*! DMA 传输数据宽度,参数有效性检查. */
|
||||
#define IS_VALID_TRN_WIDTH(x) \
|
||||
( (DmaMsk8Bit == (x)) || \
|
||||
(DmaMsk16Bit == (x)) || \
|
||||
(DmaMsk32Bit == (x)))
|
||||
|
||||
/*! DMA源地址控制模式,参数有效性检查. */
|
||||
#define IS_VALID_SRC_ADDR_MODE(x) \
|
||||
( (DmaMskSrcAddrFix == (x)) || \
|
||||
(DmaMskSrcAddrInc == (x)))
|
||||
|
||||
/*! DMA目的地址控制模式,参数有效性检查. */
|
||||
#define IS_VALID_DST_ADDR_MODE(x) \
|
||||
( (DmaMskDstAddrFix == (x)) || \
|
||||
(DmaMskDstAddrInc == (x)))
|
||||
|
||||
/*! DMA 优先级, 参数有效性检查. */
|
||||
#define IS_VALID_PRIO_MODE(x) \
|
||||
( (DmaMskPriorityFix == (x)) || \
|
||||
(DmaMskPriorityLoop == (x)))
|
||||
|
||||
/*! DMA 传输模式,参数有效性检查. */
|
||||
#define IS_VALID_TRANSFER_MODE(x) \
|
||||
( (DmaMskOneTransfer == (x)) || \
|
||||
(DmaMskContinuousTransfer == (x)))
|
||||
|
||||
/*! 块传输大小,参数有效性检查. */
|
||||
#define IS_VALID_BLKSIZE(x) ((!((x) & ~(DMA_BC_SEL_Msk >> DMA_BC_SEL_Pos)))&&((x)>0))
|
||||
|
||||
/*! 块传输次数,参数有效性检查. */
|
||||
#define IS_VALID_TRNCNT(x) (!((x) & ~(DMA_TC_SEL_Msk >> DMA_TC_SEL_Pos)))
|
||||
|
||||
/*******************************************************************************
|
||||
* Global variable definitions (declared in header file with 'extern')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Local function prototypes ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Local variable definitions ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Function implementation - global ('extern') and local ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 初始化DMAC通道
|
||||
**
|
||||
** \param [in] enCh 指定通道.
|
||||
** \param [in] pstcCfg DMAC通道初始化配置结构体指针.
|
||||
**
|
||||
** \retval Ok 初始化成功.
|
||||
** \retval ErrorInvalidParameter pstcCfg是空指针.
|
||||
**
|
||||
** \note None
|
||||
**
|
||||
******************************************************************************/
|
||||
en_result_t Dma_InitChannel(en_dma_channel_t enCh, stc_dma_cfg_t* pstcCfg)
|
||||
{
|
||||
ASSERT(IS_VALID_CH(enCh));
|
||||
ASSERT(NULL != pstcCfg);
|
||||
ASSERT(IS_VALID_BLKSIZE(pstcCfg->u16BlockSize));
|
||||
ASSERT(IS_VALID_TRNCNT(pstcCfg->u16TransferCnt));
|
||||
ASSERT(IS_VALID_TRN_WIDTH(pstcCfg->enTransferWidth));
|
||||
ASSERT(IS_VALID_SRC_ADDR_MODE(pstcCfg->enSrcAddrMode));
|
||||
ASSERT(IS_VALID_DST_ADDR_MODE(pstcCfg->enDstAddrMode));
|
||||
ASSERT(IS_VALID_PRIO_MODE(pstcCfg->enPriority));
|
||||
ASSERT(IS_VALID_TRANSFER_MODE(pstcCfg->enTransferMode));
|
||||
|
||||
/* 检查通道值有效性和pstcCfg是否空指针 */
|
||||
if (NULL == pstcCfg)
|
||||
{
|
||||
return ErrorInvalidParameter;
|
||||
}
|
||||
|
||||
*(&M0P_DMAC->CONFB0+enCh) = 0;
|
||||
*(&M0P_DMAC->CONFB0+enCh) = (uint32_t)pstcCfg->enMode |
|
||||
(uint32_t)pstcCfg->enTransferWidth |
|
||||
(uint32_t)pstcCfg->enSrcAddrMode |
|
||||
(uint32_t)pstcCfg->enDstAddrMode |
|
||||
(uint32_t)pstcCfg->enSrcAddrReloadCtl |
|
||||
(uint32_t)pstcCfg->enDestAddrReloadCtl|
|
||||
(uint32_t)pstcCfg->enSrcBcTcReloadCtl |
|
||||
(uint32_t)pstcCfg->enTransferMode;
|
||||
|
||||
/*首先把TRI_SEL[6:0] BC[3:0] TC[15:0]这些位清零,然后再赋值*/
|
||||
*(&M0P_DMAC->CONFA0+enCh) &= ((uint32_t)~(DMA_TRI_SEL_Msk | DMA_BC_SEL_Msk | DMA_TC_SEL_Msk));
|
||||
*(&M0P_DMAC->CONFA0+enCh) |= (uint32_t)(pstcCfg->u16TransferCnt - 1) |
|
||||
((uint32_t)(pstcCfg->u16BlockSize - 1)<<16)|
|
||||
(uint32_t)(pstcCfg->enRequestNum<<22);
|
||||
|
||||
M0P_DMAC->CONF |= (uint32_t)(pstcCfg->enPriority);
|
||||
|
||||
*(&M0P_DMAC->SRCADR0+enCh) = (uint32_t)(pstcCfg->u32SrcAddress);
|
||||
*(&M0P_DMAC->DSTADR0+enCh) = (uint32_t)(pstcCfg->u32DstAddress);
|
||||
|
||||
return Ok;
|
||||
}
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief DMA模块使能函数,使能所有通道的操作,每个通道按照各自设置工作.
|
||||
**
|
||||
** \param None
|
||||
**
|
||||
** \retval None
|
||||
**
|
||||
** \note None
|
||||
**
|
||||
******************************************************************************/
|
||||
void Dma_Enable(void)
|
||||
{
|
||||
M0P_DMAC->CONF |= DMA_ENABLE_Msk;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief DMA模块功能禁止函数,所有通道禁止工作.
|
||||
**
|
||||
** \param None
|
||||
**
|
||||
** \retval None
|
||||
**
|
||||
** \note None
|
||||
**
|
||||
******************************************************************************/
|
||||
void Dma_Disable(void)
|
||||
{
|
||||
M0P_DMAC->CONF &= (~DMA_ENABLE_Msk);
|
||||
}
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 触发指定DMA通道软件传输功能.
|
||||
**
|
||||
** \param [输入] enCh 指定dma通道.
|
||||
**
|
||||
** \retval None
|
||||
**
|
||||
** \note None
|
||||
**
|
||||
******************************************************************************/
|
||||
void Dma_SwStart(en_dma_channel_t enCh)
|
||||
{
|
||||
*(&M0P_DMAC->CONFA0+enCh) |= DMA_SOFTWARE_START_Msk;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 停止指定DMA通道软件传输功能.
|
||||
**
|
||||
** \param [输入] enCh 指定dma通道.
|
||||
**
|
||||
** \retval None
|
||||
**
|
||||
** \note None
|
||||
**
|
||||
******************************************************************************/
|
||||
void Dma_SwStop(en_dma_channel_t enCh)
|
||||
{
|
||||
*(&M0P_DMAC->CONFA0+enCh) &= (~DMA_SOFTWARE_START_Msk);
|
||||
}
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 使能指定dma通道的(传输完成)中断.
|
||||
**
|
||||
** \param [输入] enCh 指定dma通道.
|
||||
**
|
||||
** \retval None
|
||||
**
|
||||
** \note None
|
||||
**
|
||||
******************************************************************************/
|
||||
void Dma_EnableChannelIrq(en_dma_channel_t enCh)
|
||||
{
|
||||
*(&M0P_DMAC->CONFB0+enCh) |= DMA_FIS_IE_Msk;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 禁用指定dma通道的(传输完成)中断.
|
||||
**
|
||||
** \param [输入] enCh 指定dma通道.
|
||||
**
|
||||
** \retval None
|
||||
**
|
||||
** \note None
|
||||
**
|
||||
******************************************************************************/
|
||||
void Dma_DisableChannelIrq(en_dma_channel_t enCh)
|
||||
{
|
||||
*(&M0P_DMAC->CONFB0+enCh) &= (~DMA_FIS_IE_Msk);
|
||||
}
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 使能指定dma通道的(传输错误)中断..
|
||||
**
|
||||
** \param [输入] enCh 指定dma通道.
|
||||
**
|
||||
** \retval None
|
||||
**
|
||||
** \note None
|
||||
**
|
||||
******************************************************************************/
|
||||
void Dma_EnableChannelErrIrq(en_dma_channel_t enCh)
|
||||
{
|
||||
*(&M0P_DMAC->CONFB0+enCh) |= DMA_ERR_IE_Msk;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 禁用指定dma通道的(传输错误)中断..
|
||||
**
|
||||
** \param [输入] enCh 指定dma通道.
|
||||
**
|
||||
** \retval None
|
||||
**
|
||||
** \note None
|
||||
**
|
||||
******************************************************************************/
|
||||
void Dma_DisableChannelErrIrq(en_dma_channel_t enCh)
|
||||
{
|
||||
*(&M0P_DMAC->CONFB0+enCh) &= (~DMA_ERR_IE_Msk);
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 使能指定dma通道
|
||||
**
|
||||
** \param [输入] enCh 指定dma通道.
|
||||
**
|
||||
** \retval None
|
||||
**
|
||||
** \note None
|
||||
**
|
||||
******************************************************************************/
|
||||
void Dma_EnableChannel(en_dma_channel_t enCh)
|
||||
{
|
||||
*(&M0P_DMAC->CONFA0+enCh) |= DMA_CH_ENABLE_Msk;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 禁用指定dma通道
|
||||
**
|
||||
** \param [输入] enCh 指定dma通道.
|
||||
**
|
||||
** \retval None
|
||||
**
|
||||
** \note None
|
||||
**
|
||||
******************************************************************************/
|
||||
void Dma_DisableChannel(en_dma_channel_t enCh)
|
||||
{
|
||||
*(&M0P_DMAC->CONFA0+enCh) &= (~DMA_CH_ENABLE_Msk);
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 设定指定通道的块(Block)尺寸
|
||||
**
|
||||
** \param [输入] enCh 指定通道
|
||||
** \param [输入] u16BlkSize 块(Block)尺寸.
|
||||
**
|
||||
** \retval None
|
||||
**
|
||||
** \note None
|
||||
**
|
||||
******************************************************************************/
|
||||
void Dma_SetBlockSize(en_dma_channel_t enCh, uint16_t u16BlkSize)
|
||||
{
|
||||
volatile uint32_t *pReg = (&M0P_DMAC->CONFA0+enCh);
|
||||
|
||||
*pReg = ((*pReg) & ((uint32_t)~DMA_BC_SEL_Msk)) | ((((uint32_t)u16BlkSize-1)&0x0f)<<DMA_BC_SEL_Pos);
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 设定指定通道块(Block)传输次数
|
||||
**
|
||||
** \param [in] enCh 指定通道.
|
||||
** \param [in] u16TrnCnt 块(Block)传输次数.
|
||||
**
|
||||
** \retval None
|
||||
**
|
||||
** \note None
|
||||
**
|
||||
******************************************************************************/
|
||||
void Dma_SetTransferCnt(en_dma_channel_t enCh, uint16_t u16TrnCnt)
|
||||
{
|
||||
volatile uint32_t *pReg = (&M0P_DMAC->CONFA0+enCh);
|
||||
|
||||
*pReg = ((*pReg)&((uint32_t)~DMA_TC_SEL_Msk))|(((uint32_t)(u16TrnCnt-1)<<DMA_TC_SEL_Pos));
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 允许指定通道可连续传输,即DMAC在传输完成时不清除CONFA:ENS位.
|
||||
**
|
||||
** \param [in] enCh 指定通道.
|
||||
**
|
||||
** \retval None
|
||||
**
|
||||
** \note None
|
||||
**
|
||||
******************************************************************************/
|
||||
void Dma_EnableContinusTranfer(en_dma_channel_t enCh)
|
||||
{
|
||||
*(&M0P_DMAC->CONFB0+enCh) |= DMA_TRANSFER_RELOAD_Msk;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 禁止指定通道连续传输,即DMAC在传输完成时清除.
|
||||
**
|
||||
** \param [输入] enCh 指定通道.
|
||||
**
|
||||
** \retval None
|
||||
**
|
||||
** \note None
|
||||
**
|
||||
******************************************************************************/
|
||||
void Dma_DisableContinusTranfer(en_dma_channel_t enCh)
|
||||
{
|
||||
*(&M0P_DMAC->CONFB0+enCh) &= (~DMA_TRANSFER_RELOAD_Msk);
|
||||
}
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 暂停所有dma通道.
|
||||
**
|
||||
** \param None
|
||||
**
|
||||
** \retval None.
|
||||
**
|
||||
** \note None
|
||||
**
|
||||
******************************************************************************/
|
||||
void Dma_HaltTranfer(void)
|
||||
{
|
||||
M0P_DMAC->CONF_f.HALT = 0x1;
|
||||
}
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 恢复(之前暂停的)所有dma通道.
|
||||
**
|
||||
** \param None
|
||||
**
|
||||
** \retval None
|
||||
**
|
||||
** \note None
|
||||
**
|
||||
******************************************************************************/
|
||||
void Dma_RecoverTranfer(void)
|
||||
{
|
||||
M0P_DMAC->CONF_f.HALT = 0x0;
|
||||
}
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 暂停指定dma通道.
|
||||
**
|
||||
** \param [输入] enCh 指定通道.
|
||||
**
|
||||
** \retval void
|
||||
**
|
||||
** \note None
|
||||
**
|
||||
******************************************************************************/
|
||||
void Dma_PauseChannelTranfer(en_dma_channel_t enCh)
|
||||
{
|
||||
*(&M0P_DMAC->CONFA0+enCh) |= DMA_CH_PAUSE_Msk;
|
||||
}
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 恢复(之前暂定的)指定dma通道.
|
||||
**
|
||||
** \param [输入] enCh 指定通道.
|
||||
**
|
||||
** \retval None
|
||||
**
|
||||
** \note None
|
||||
**
|
||||
******************************************************************************/
|
||||
void Dma_RecoverChannelTranfer(en_dma_channel_t enCh)
|
||||
{
|
||||
*(&M0P_DMAC->CONFA0+enCh) &= (~DMA_CH_PAUSE_Msk);
|
||||
}
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 设定指定通道传输数据宽度.
|
||||
**
|
||||
** \param [输入] enCh 指定dma通道.
|
||||
** \param [输入] enWidth 指定数据宽度.
|
||||
**
|
||||
** \retval None
|
||||
**
|
||||
** \note None
|
||||
**
|
||||
******************************************************************************/
|
||||
void Dma_SetTransferWidth(en_dma_channel_t enCh, en_dma_transfer_width_t enWidth)
|
||||
{
|
||||
volatile uint32_t *pReg = (&M0P_DMAC->CONFA0+enCh);
|
||||
|
||||
*pReg = ((*pReg)&((uint32_t)~DMA_TRANSFER_WIDTH_Msk))|((uint32_t)enWidth);
|
||||
}
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 设定dma通道优先级.
|
||||
**
|
||||
** \param [输入] enPrio 通道优先级设定参数.
|
||||
**
|
||||
** \retval None
|
||||
**
|
||||
** \note None
|
||||
**
|
||||
******************************************************************************/
|
||||
void Dma_SetChPriority(en_dma_priority_t enPrio)
|
||||
{
|
||||
M0P_DMAC->CONF = ((M0P_DMAC->CONF)&((uint32_t)~DMA_PRIORITY_Msk))|((uint32_t)enPrio);
|
||||
}
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 获取指定DMA通道的状态.
|
||||
**
|
||||
** \param [输入] enCh 指定dma通道.
|
||||
**
|
||||
** \retval en_dma_stat_t DMA传输当前状态
|
||||
**
|
||||
** \note None
|
||||
**
|
||||
******************************************************************************/
|
||||
en_dma_stat_t Dma_GetStat(en_dma_channel_t enCh)
|
||||
{
|
||||
return (en_dma_stat_t)((*(&M0P_DMAC->CONFB0+enCh)&(DMA_STAT_Msk))>>DMA_STAT_Pos);
|
||||
}
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 清除指定DMA通道的状态值.
|
||||
**
|
||||
** \param [输入] enCh 指定dma通道.
|
||||
**
|
||||
** \retval None
|
||||
**
|
||||
** \note None
|
||||
**
|
||||
******************************************************************************/
|
||||
void Dma_ClrStat(en_dma_channel_t enCh)
|
||||
{
|
||||
*(&M0P_DMAC->CONFB0+enCh) &= (~DMA_STAT_Msk);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 设定指定通道源地址
|
||||
**
|
||||
** \param [输入] enCh 指定dma通道.
|
||||
** \param [输入] u32Address 传输源地址.
|
||||
**
|
||||
** \retval None
|
||||
**
|
||||
** \note None
|
||||
**
|
||||
******************************************************************************/
|
||||
void Dma_SetSourceAddress(en_dma_channel_t enCh, uint32_t u32Address)
|
||||
{
|
||||
*(&M0P_DMAC->SRCADR0+enCh) = u32Address;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 设定指定通道目标地址.
|
||||
**
|
||||
** \param [输入] enCh 指定dma通道.
|
||||
** \param [输入] u32Address 传输目标地址.
|
||||
**
|
||||
** \retval None
|
||||
**
|
||||
** \note None
|
||||
**
|
||||
******************************************************************************/
|
||||
void Dma_SetDestinationAddress(en_dma_channel_t enCh, uint32_t u32Address)
|
||||
{
|
||||
*(&M0P_DMAC->DSTADR0+enCh) = u32Address;
|
||||
}
|
||||
|
||||
//@} // DmacGroup
|
||||
|
||||
/*******************************************************************************
|
||||
* EOF (not truncated)
|
||||
******************************************************************************/
|
||||
@@ -0,0 +1,696 @@
|
||||
/******************************************************************************
|
||||
*Copyright(C)2018, Huada Semiconductor Co.,Ltd All rights reserved.
|
||||
*
|
||||
* This software is owned and published by:
|
||||
* Huada Semiconductor Co.,Ltd("HDSC").
|
||||
*
|
||||
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
|
||||
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
|
||||
*
|
||||
* This software contains source code for use with HDSC
|
||||
* components. This software is licensed by HDSC to be adapted only
|
||||
* for use in systems utilizing HDSC components. HDSC shall not be
|
||||
* responsible for misuse or illegal use of this software for devices not
|
||||
* supported herein. HDSC is providing this software "AS IS" and will
|
||||
* not be responsible for issues arising from incorrect user implementation
|
||||
* of the software.
|
||||
*
|
||||
* Disclaimer:
|
||||
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
|
||||
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
|
||||
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
|
||||
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
|
||||
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
|
||||
* WARRANTY OF NONINFRINGEMENT.
|
||||
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
|
||||
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
|
||||
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
|
||||
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
|
||||
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
|
||||
* SAVINGS OR PROFITS,
|
||||
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
|
||||
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
|
||||
* FROM, THE SOFTWARE.
|
||||
*
|
||||
* This software may be replicated in part or whole for the licensed use,
|
||||
* with the restriction that this Disclaimer and Copyright notice must be
|
||||
* included with each copy of this software, whether used in part or whole,
|
||||
* at all times.
|
||||
*/
|
||||
|
||||
/** \file flash.c
|
||||
**
|
||||
** Common API of flash.
|
||||
** @link flashGroup Some description @endlink
|
||||
**
|
||||
** - 2018-05-08
|
||||
**
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Include files
|
||||
******************************************************************************/
|
||||
#include "flash.h"
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \addtogroup FlashGroup
|
||||
******************************************************************************/
|
||||
//@{
|
||||
|
||||
/*******************************************************************************
|
||||
* Local pre-processor symbols/macros ('#define')
|
||||
******************************************************************************/
|
||||
#define FLASH_END_ADDR (0x0001FFFFu)
|
||||
#define FLASH_BYPASS() M0P_FLASH->BYPASS = 0x5A5A;\
|
||||
M0P_FLASH->BYPASS = 0xA5A5;
|
||||
#define FLASH_IE_TRUE (0x03)
|
||||
#define FLASH_IE_FALSE (0x00)
|
||||
|
||||
#define FLASH_TIMEOUT_INIT (0xFFFFFFu)
|
||||
#define FLASH_TIMEOUT_PGM (0xFFFFFFu)
|
||||
#define FLASH_TIMEOUT_ERASE (0xFFFFFFu)
|
||||
|
||||
#define FLASH_LOCK_ALL (0u)
|
||||
#define FLASH_UNLOCK_ALL (0xFFFFFFFFu)
|
||||
/*******************************************************************************
|
||||
* Global variable definitions (declared in header file with 'extern')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Local type definitions ('typedef')
|
||||
******************************************************************************/
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief FLASH OP
|
||||
**
|
||||
** Flash 操作控制数据类型重定义
|
||||
******************************************************************************/
|
||||
typedef enum en_flash_op
|
||||
{
|
||||
Read = 0u, ///<读配置值
|
||||
Program = 1u, ///<编程配置值
|
||||
SectorErase = 2u, ///<扇区擦除配置值
|
||||
ChipErase = 3u, ///<全片擦除配置值
|
||||
} en_flash_op_t;
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief FLASH 编程时间参数配置
|
||||
**
|
||||
** FLASH编程时间参数配置数组定义 (4MHz)
|
||||
******************************************************************************/
|
||||
const uint32_t pu32PcgTimer4M[] = {
|
||||
0x20u, //Tnvs
|
||||
0x17u, //Tpgs
|
||||
0x1Bu, //Tprog
|
||||
0x4650u, //Tserase
|
||||
0x222E0u, //Tmerase
|
||||
0x18u, //Tprcv
|
||||
0xF0u, //Tsrcv
|
||||
0x3E8u //Tmrcv
|
||||
};
|
||||
/*******************************************************************************
|
||||
* Local variable definitions ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Local function prototypes ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Function implementation - global ('extern') and local ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief Flash中断标志获取
|
||||
**
|
||||
**
|
||||
** \param [in] enFlashIntType Flash中断类型
|
||||
**
|
||||
** \retval TRUE or FALSE
|
||||
*****************************************************************************/
|
||||
boolean_t Flash_GetIntFlag(en_flash_int_type_t enFlashIntType)
|
||||
{
|
||||
boolean_t bRetVal = FALSE;
|
||||
|
||||
if(M0P_FLASH->IFR & enFlashIntType)
|
||||
{
|
||||
bRetVal = TRUE;
|
||||
}
|
||||
|
||||
return bRetVal;
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief Flash中断标志清除
|
||||
**
|
||||
**
|
||||
** \param [in] enFlashIntType Flash中断类型
|
||||
**
|
||||
** \retval Ok or Error
|
||||
*****************************************************************************/
|
||||
en_result_t Flash_ClearIntFlag(en_flash_int_type_t enFlashIntType)
|
||||
{
|
||||
en_result_t enResult = Error;
|
||||
|
||||
M0P_FLASH->ICLR &= ~(uint32_t)enFlashIntType;
|
||||
enResult = Ok;
|
||||
|
||||
return enResult;
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief Flash中断使能
|
||||
**
|
||||
**
|
||||
** \param [in] enFlashIntType Flash中断类型
|
||||
**
|
||||
** \retval Ok or Error
|
||||
*****************************************************************************/
|
||||
en_result_t Flash_EnableIrq (en_flash_int_type_t enFlashIntType)
|
||||
{
|
||||
en_result_t enResult = Error;
|
||||
|
||||
FLASH_BYPASS();
|
||||
M0P_FLASH->CR_f.IE |= enFlashIntType;
|
||||
|
||||
enResult = Ok;
|
||||
|
||||
return enResult;
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief Flash中断禁止
|
||||
**
|
||||
**
|
||||
** \param [in] enFlashIntType Flash中断类型
|
||||
**
|
||||
** \retval Ok or Error
|
||||
*****************************************************************************/
|
||||
en_result_t Flash_DisableIrq(en_flash_int_type_t enFlashIntType)
|
||||
{
|
||||
en_result_t enResult = Error;
|
||||
|
||||
FLASH_BYPASS();
|
||||
M0P_FLASH->CR_f.IE &= ~(uint32_t)enFlashIntType;
|
||||
|
||||
enResult = Ok;
|
||||
|
||||
return enResult;
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief FLASH 初始化函数——中断服务程序、编程时间配置及低功耗模式
|
||||
**
|
||||
** 该函数用于配置中断服务函数、低功耗模式、根据系统时钟配置FLASH编程时间相关寄存器.
|
||||
**
|
||||
** \param [in] u8FreqCfg FLASH编程时钟频率配置(根据HCLK的频率选择配置值):
|
||||
** 1 - 4MHz;
|
||||
** 2 - 8MHz;
|
||||
** 4 - 16MHz;
|
||||
** 6 - 24MHz;
|
||||
** 8 - 32MHz;
|
||||
** 12 - 48MHz;
|
||||
** other - 无效值
|
||||
** \param [in] bDpstbEn TRUE - 当系统进入DeepSleep模式,FLASH进入低功耗模式;
|
||||
** FALSE - 当系统进入DeepSleep模式,FLASH不进入低功耗模式;
|
||||
**
|
||||
** \retval Ok 操作成功.
|
||||
** \retval ErrorInvalidParameter 参数无效.
|
||||
** \retval ErrorUninitialized 初始化失败。
|
||||
*****************************************************************************/
|
||||
en_result_t Flash_Init(uint8_t u8FreqCfg, boolean_t bDpstbEn)
|
||||
{
|
||||
uint32_t u32Index = 0;
|
||||
volatile uint32_t u32TimeOut = FLASH_TIMEOUT_INIT;
|
||||
en_result_t enResult = Ok;
|
||||
uint32_t u32PrgTimer[8] = {0};
|
||||
volatile uint32_t *pu32PrgTimerReg = (volatile uint32_t*)M0P_FLASH;
|
||||
|
||||
if ((1 != u8FreqCfg) && (2 != u8FreqCfg) &&
|
||||
(4 != u8FreqCfg) && (6 != u8FreqCfg) &&
|
||||
(8 != u8FreqCfg) && (12 != u8FreqCfg))
|
||||
{
|
||||
enResult = ErrorInvalidParameter;
|
||||
return (enResult);
|
||||
}
|
||||
|
||||
M0P_FLASH->CR_f.DPSTB_EN = bDpstbEn;
|
||||
|
||||
//flash时间参数配置值计算
|
||||
for(u32Index=0; u32Index<8; u32Index++)
|
||||
{
|
||||
u32PrgTimer[u32Index] = u8FreqCfg * pu32PcgTimer4M[u32Index];
|
||||
}
|
||||
|
||||
//flash时间参数寄存器配置
|
||||
for(u32Index=0; u32Index<8; u32Index++)
|
||||
{
|
||||
u32TimeOut = FLASH_TIMEOUT_INIT;
|
||||
while(pu32PrgTimerReg[u32Index] != u32PrgTimer[u32Index])
|
||||
{
|
||||
if(u32TimeOut--)
|
||||
{
|
||||
FLASH_BYPASS();
|
||||
pu32PrgTimerReg[u32Index] = u32PrgTimer[u32Index];
|
||||
}
|
||||
else
|
||||
{
|
||||
return ErrorUninitialized;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (enResult);
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief FLASH 字节写
|
||||
**
|
||||
** 用于向FLASH写入1字节数据.
|
||||
**
|
||||
** \param [in] u32Addr Flash地址
|
||||
** \param [in] u8Data 1字节数据
|
||||
**
|
||||
** \retval Ok 写入成功.
|
||||
** \retval ErrorInvalidParameter FLASH地址无效
|
||||
** \retval ErrorTimeout 操作超时
|
||||
*****************************************************************************/
|
||||
en_result_t Flash_WriteByte(uint32_t u32Addr, uint8_t u8Data)
|
||||
{
|
||||
en_result_t enResult = Ok;
|
||||
volatile uint32_t u32TimeOut = FLASH_TIMEOUT_PGM;
|
||||
|
||||
if (FLASH_END_ADDR < u32Addr)
|
||||
{
|
||||
enResult = ErrorInvalidParameter;
|
||||
return (enResult);
|
||||
}
|
||||
|
||||
//busy?
|
||||
u32TimeOut = FLASH_TIMEOUT_PGM;
|
||||
while (TRUE == M0P_FLASH->CR_f.BUSY)
|
||||
{
|
||||
if(0 == u32TimeOut--)
|
||||
{
|
||||
return ErrorTimeout;
|
||||
}
|
||||
}
|
||||
|
||||
//set OP
|
||||
u32TimeOut = FLASH_TIMEOUT_PGM;
|
||||
while(Program != M0P_FLASH->CR_f.OP)
|
||||
{
|
||||
if(u32TimeOut--)
|
||||
{
|
||||
FLASH_BYPASS();
|
||||
M0P_FLASH->CR_f.OP = Program;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ErrorTimeout;
|
||||
}
|
||||
}
|
||||
|
||||
//Flash 解锁
|
||||
Flash_UnlockAll();
|
||||
|
||||
//write data
|
||||
*((volatile uint8_t*)u32Addr) = u8Data;
|
||||
|
||||
//busy?
|
||||
u32TimeOut = FLASH_TIMEOUT_PGM;
|
||||
while (TRUE == M0P_FLASH->CR_f.BUSY)
|
||||
{
|
||||
if(0 == u32TimeOut--)
|
||||
{
|
||||
return ErrorTimeout;
|
||||
}
|
||||
}
|
||||
|
||||
//Flash 加锁
|
||||
Flash_LockAll();
|
||||
|
||||
return (enResult);
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief FLASH 半字写
|
||||
**
|
||||
** 用于向FLASH写入半字(2字节)数据.
|
||||
**
|
||||
** \param [in] u32Addr Flash地址
|
||||
** \param [in] u16Data 半字(2字节)数据
|
||||
**
|
||||
** \retval Ok 写入成功.
|
||||
** \retval ErrorInvalidParameter FLASH地址无效
|
||||
** \retval ErrorTimeout 操作超时
|
||||
*****************************************************************************/
|
||||
en_result_t Flash_WriteHalfWord(uint32_t u32Addr, uint16_t u16Data)
|
||||
{
|
||||
en_result_t enResult = Ok;
|
||||
volatile uint32_t u32TimeOut = FLASH_TIMEOUT_PGM;
|
||||
|
||||
if (FLASH_END_ADDR < u32Addr)
|
||||
{
|
||||
enResult = ErrorInvalidParameter;
|
||||
return (enResult);
|
||||
}
|
||||
|
||||
//busy?
|
||||
u32TimeOut = FLASH_TIMEOUT_PGM;
|
||||
while (TRUE == M0P_FLASH->CR_f.BUSY)
|
||||
{
|
||||
if(0 == u32TimeOut--)
|
||||
{
|
||||
return ErrorTimeout;
|
||||
}
|
||||
}
|
||||
|
||||
//set OP
|
||||
u32TimeOut = FLASH_TIMEOUT_PGM;
|
||||
while(Program != M0P_FLASH->CR_f.OP)
|
||||
{
|
||||
if(u32TimeOut--)
|
||||
{
|
||||
FLASH_BYPASS();
|
||||
M0P_FLASH->CR_f.OP = Program;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ErrorTimeout;
|
||||
}
|
||||
}
|
||||
|
||||
//Flash 解锁
|
||||
Flash_UnlockAll();
|
||||
|
||||
//write data
|
||||
*((volatile uint16_t*)u32Addr) = u16Data;
|
||||
|
||||
//busy?
|
||||
u32TimeOut = FLASH_TIMEOUT_PGM;
|
||||
while (TRUE == M0P_FLASH->CR_f.BUSY)
|
||||
{
|
||||
if(0 == u32TimeOut--)
|
||||
{
|
||||
return ErrorTimeout;
|
||||
}
|
||||
}
|
||||
|
||||
//Flash 加锁
|
||||
Flash_LockAll();
|
||||
|
||||
return (enResult);
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief FLASH 字写
|
||||
**
|
||||
** 用于向FLASH写入1个字的数据.
|
||||
**
|
||||
** \param [in] u32Addr Flash地址
|
||||
** \param [in] u32Data 1个字数据
|
||||
**
|
||||
** \retval Ok 写入成功.
|
||||
** \retval ErrorInvalidParameter FLASH地址无效
|
||||
** \retval ErrorTimeout 操作超时
|
||||
*****************************************************************************/
|
||||
en_result_t Flash_WriteWord(uint32_t u32Addr, uint32_t u32Data)
|
||||
{
|
||||
en_result_t enResult = Ok;
|
||||
volatile uint32_t u32TimeOut = FLASH_TIMEOUT_PGM;
|
||||
|
||||
if (FLASH_END_ADDR < u32Addr)
|
||||
{
|
||||
enResult = ErrorInvalidParameter;
|
||||
return (enResult);
|
||||
}
|
||||
|
||||
//busy?
|
||||
u32TimeOut = FLASH_TIMEOUT_PGM;
|
||||
while (TRUE == M0P_FLASH->CR_f.BUSY)
|
||||
{
|
||||
if(0 == u32TimeOut--)
|
||||
{
|
||||
return ErrorTimeout;
|
||||
}
|
||||
}
|
||||
|
||||
//Flash 解锁
|
||||
Flash_UnlockAll();
|
||||
|
||||
//set OP
|
||||
u32TimeOut = FLASH_TIMEOUT_PGM;
|
||||
while(Program != M0P_FLASH->CR_f.OP)
|
||||
{
|
||||
if(u32TimeOut--)
|
||||
{
|
||||
FLASH_BYPASS();
|
||||
M0P_FLASH->CR_f.OP = Program;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ErrorTimeout;
|
||||
}
|
||||
}
|
||||
|
||||
//write data
|
||||
*((volatile uint32_t*)u32Addr) = u32Data;
|
||||
|
||||
//busy?
|
||||
u32TimeOut = FLASH_TIMEOUT_PGM;
|
||||
while (TRUE == M0P_FLASH->CR_f.BUSY)
|
||||
{
|
||||
if(0 == u32TimeOut--)
|
||||
{
|
||||
return ErrorTimeout;
|
||||
}
|
||||
}
|
||||
|
||||
//Flash 加锁
|
||||
Flash_LockAll();
|
||||
|
||||
return (enResult);
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief FLASH 扇区擦除
|
||||
**
|
||||
** FLASH 扇区擦除.
|
||||
**
|
||||
** \param [in] u32SectorAddr 所擦除扇区内的地址
|
||||
**
|
||||
** \retval Ok 擦除成功.
|
||||
** \retval ErrorInvalidParameter FLASH地址无效
|
||||
** \retval ErrorTimeout 操作超时
|
||||
*****************************************************************************/
|
||||
en_result_t Flash_SectorErase(uint32_t u32SectorAddr)
|
||||
{
|
||||
en_result_t enResult = Ok;
|
||||
volatile uint32_t u32TimeOut = FLASH_TIMEOUT_ERASE;
|
||||
|
||||
if (FLASH_END_ADDR < u32SectorAddr)
|
||||
{
|
||||
enResult = ErrorInvalidParameter;
|
||||
return (enResult);
|
||||
}
|
||||
|
||||
//busy?
|
||||
u32TimeOut = FLASH_TIMEOUT_ERASE;
|
||||
while (TRUE == M0P_FLASH->CR_f.BUSY)
|
||||
{
|
||||
if(0 == u32TimeOut--)
|
||||
{
|
||||
return ErrorTimeout;
|
||||
}
|
||||
}
|
||||
|
||||
//Flash 解锁
|
||||
Flash_UnlockAll();
|
||||
|
||||
//set OP
|
||||
u32TimeOut = FLASH_TIMEOUT_ERASE;
|
||||
while(SectorErase != M0P_FLASH->CR_f.OP)
|
||||
{
|
||||
if(u32TimeOut--)
|
||||
{
|
||||
FLASH_BYPASS();
|
||||
M0P_FLASH->CR_f.OP = SectorErase;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ErrorTimeout;
|
||||
}
|
||||
}
|
||||
|
||||
//write data
|
||||
*((volatile uint8_t*)u32SectorAddr) = 0;
|
||||
|
||||
//busy?
|
||||
u32TimeOut = FLASH_TIMEOUT_ERASE;
|
||||
while (TRUE == M0P_FLASH->CR_f.BUSY)
|
||||
{
|
||||
if(0 == u32TimeOut--)
|
||||
{
|
||||
return ErrorTimeout;
|
||||
}
|
||||
}
|
||||
|
||||
//Flash 加锁
|
||||
Flash_LockAll();
|
||||
|
||||
return (enResult);
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief FLASH 全片擦除(该函数仅限RAM中运行!!!)
|
||||
**
|
||||
** FLASH 全片擦除.
|
||||
**
|
||||
**
|
||||
** \retval Ok 擦除成功.
|
||||
** \retval ErrorTimeout 操作超时
|
||||
**
|
||||
*****************************************************************************/
|
||||
en_result_t Flash_ChipErase(void)
|
||||
{
|
||||
en_result_t enResult = Ok;
|
||||
volatile uint32_t u32TimeOut = FLASH_TIMEOUT_ERASE;
|
||||
|
||||
//busy?
|
||||
u32TimeOut = FLASH_TIMEOUT_ERASE;
|
||||
while (TRUE == M0P_FLASH->CR_f.BUSY)
|
||||
{
|
||||
if(0 == u32TimeOut--)
|
||||
{
|
||||
return ErrorTimeout;
|
||||
}
|
||||
}
|
||||
|
||||
//set OP
|
||||
u32TimeOut = FLASH_TIMEOUT_ERASE;
|
||||
while(ChipErase != M0P_FLASH->CR_f.OP)
|
||||
{
|
||||
if(u32TimeOut--)
|
||||
{
|
||||
FLASH_BYPASS();
|
||||
M0P_FLASH->CR_f.OP = ChipErase;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ErrorTimeout;
|
||||
}
|
||||
}
|
||||
|
||||
//Flash 解锁
|
||||
Flash_UnlockAll();
|
||||
|
||||
//write data
|
||||
*((volatile uint8_t*)0) = 0;
|
||||
|
||||
//busy?
|
||||
u32TimeOut = FLASH_TIMEOUT_ERASE;
|
||||
while (TRUE == M0P_FLASH->CR_f.BUSY)
|
||||
{
|
||||
if(0 == u32TimeOut--)
|
||||
{
|
||||
return ErrorTimeout;
|
||||
}
|
||||
}
|
||||
|
||||
//Flash 加锁
|
||||
Flash_LockAll();
|
||||
|
||||
return (enResult);
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief FLASH 编程保护加锁
|
||||
**
|
||||
**
|
||||
** \retval Null
|
||||
*****************************************************************************/
|
||||
void Flash_LockAll(void)
|
||||
{
|
||||
FLASH_BYPASS();
|
||||
M0P_FLASH->SLOCK0 = FLASH_LOCK_ALL;
|
||||
FLASH_BYPASS();
|
||||
M0P_FLASH->SLOCK1 = FLASH_LOCK_ALL;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief FLASH 编程保护解锁
|
||||
**
|
||||
**
|
||||
** \retval Null
|
||||
*****************************************************************************/
|
||||
void Flash_UnlockAll(void)
|
||||
{
|
||||
|
||||
FLASH_BYPASS();
|
||||
M0P_FLASH->SLOCK0 = FLASH_UNLOCK_ALL;
|
||||
FLASH_BYPASS();
|
||||
M0P_FLASH->SLOCK1 = FLASH_UNLOCK_ALL;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief FLASH 读等待周期设置
|
||||
**
|
||||
** \param [in] enWaitCycle 插入FLASH读等待周期数枚举类型
|
||||
**
|
||||
** \retval Ok 解锁成功
|
||||
** \retval ErrorInvalidParameter 参数错误
|
||||
*****************************************************************************/
|
||||
en_result_t Flash_WaitCycle(en_flash_waitcycle_t enWaitCycle)
|
||||
{
|
||||
en_result_t enResult = Ok;
|
||||
|
||||
FLASH_BYPASS();
|
||||
M0P_FLASH->CR_f.WAIT = enWaitCycle;
|
||||
|
||||
return enResult;
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief FLASH LOCK 设置
|
||||
**
|
||||
** \param [in] enLock @ref en_flash_lock_t
|
||||
** \param [in] u32LockValue 32bits,对应bit=0:加锁,对应Sector不允许擦写;对应bit=1:解锁。
|
||||
** \note 加解锁范围Sector:[enLock*128 + i*4, enLock*128 + i*4+3]
|
||||
** (i表示u32LockValue的bit位置,0~31)
|
||||
** 例如:enLock = FlashLock1, u32LockValue = 0x00000002,
|
||||
** 则加解锁范围为:[Sector128,Sector131]
|
||||
** \retval Ok 解锁成功
|
||||
** \retval ErrorInvalidParameter 参数错误
|
||||
*****************************************************************************/
|
||||
en_result_t Flash_LockSet(en_flash_lock_t enLock, uint32_t u32LockValue)
|
||||
{
|
||||
FLASH_BYPASS();
|
||||
*((&M0P_FLASH->SLOCK0) + enLock) = u32LockValue;
|
||||
|
||||
return Ok;
|
||||
}
|
||||
//@} // FlashGroup
|
||||
|
||||
/*******************************************************************************
|
||||
* EOF (not truncated)
|
||||
******************************************************************************/
|
||||
@@ -0,0 +1,582 @@
|
||||
/******************************************************************************
|
||||
* Copyright (C) 2018, Huada Semiconductor Co.,Ltd All rights reserved.
|
||||
*
|
||||
* This software is owned and published by:
|
||||
* Huada Semiconductor Co.,Ltd ("HDSC").
|
||||
*
|
||||
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
|
||||
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
|
||||
*
|
||||
* This software contains source code for use with HDSC
|
||||
* components. This software is licensed by HDSC to be adapted only
|
||||
* for use in systems utilizing HDSC components. HDSC shall not be
|
||||
* responsible for misuse or illegal use of this software for devices not
|
||||
* supported herein. HDSC is providing this software "AS IS" and will
|
||||
* not be responsible for issues arising from incorrect user implementation
|
||||
* of the software.
|
||||
*
|
||||
* Disclaimer:
|
||||
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
|
||||
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
|
||||
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
|
||||
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
|
||||
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
|
||||
* WARRANTY OF NONINFRINGEMENT.
|
||||
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
|
||||
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
|
||||
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
|
||||
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
|
||||
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
|
||||
* SAVINGS OR PROFITS,
|
||||
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
|
||||
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
|
||||
* FROM, THE SOFTWARE.
|
||||
*
|
||||
* This software may be replicated in part or whole for the licensed use,
|
||||
* with the restriction that this Disclaimer and Copyright notice must be
|
||||
* included with each copy of this software, whether used in part or whole,
|
||||
* at all times.
|
||||
*/
|
||||
/******************************************************************************/
|
||||
/** \file Gpio.c
|
||||
**
|
||||
** GPIO driver API.
|
||||
** @link Driver Group Some description @endlink
|
||||
**
|
||||
** - 2018-04-22 1.0 Lux First version
|
||||
**
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Include files
|
||||
******************************************************************************/
|
||||
#include "gpio.h"
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \addtogroup GpioGroup
|
||||
******************************************************************************/
|
||||
//@{
|
||||
|
||||
/*******************************************************************************
|
||||
* Local pre-processor symbols/macros ('#define')
|
||||
******************************************************************************/
|
||||
#define IS_VALID_PIN(port,pin) ( )
|
||||
/*******************************************************************************
|
||||
* Global variable definitions (declared in header file with 'extern') *
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Local type definitions ('typedef')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Local function prototypes ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Local variable definitions ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Function implementation - global ('extern') and local ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief GPIO 初始化
|
||||
**
|
||||
** \param [in] enPort IO Port口
|
||||
** \param [in] enPin IO Pin脚
|
||||
** \param [in] pstcGpioCfg IO 配置结构体指针
|
||||
**
|
||||
** \retval Ok 设置成功
|
||||
** 其他值 设置失败
|
||||
******************************************************************************/
|
||||
en_result_t Gpio_Init(en_gpio_port_t enPort, en_gpio_pin_t enPin, stc_gpio_cfg_t *pstcGpioCfg)
|
||||
{
|
||||
//配置为默认值,GPIO功能
|
||||
SetBit((uint32_t)&M0P_GPIO->PAADS + enPort, enPin, FALSE);
|
||||
*((uint32_t*)(((uint32_t)(&(M0P_GPIO->PA00_SEL)) + enPort) + (((uint32_t)enPin)<<2))) = GpioAf0;
|
||||
|
||||
//默认输出值配置
|
||||
SetBit(((uint32_t)&M0P_GPIO->PAOUT + enPort), enPin, pstcGpioCfg->bOutputVal);
|
||||
//方向配置
|
||||
SetBit(((uint32_t)&M0P_GPIO->PADIR + enPort), enPin, (boolean_t)(pstcGpioCfg->enDir));
|
||||
//驱动能力配置
|
||||
SetBit(((uint32_t)&M0P_GPIO->PADR + enPort), enPin, (boolean_t)(pstcGpioCfg->enDrv));
|
||||
//上拉/下拉配置
|
||||
SetBit(((uint32_t)&M0P_GPIO->PAPU + enPort), enPin, (boolean_t)(pstcGpioCfg->enPu));
|
||||
SetBit(((uint32_t)&M0P_GPIO->PAPD + enPort), enPin, (boolean_t)(pstcGpioCfg->enPd));
|
||||
//开漏输出功能
|
||||
SetBit(((uint32_t)&M0P_GPIO->PAOD + enPort), enPin, (boolean_t)(pstcGpioCfg->enOD));
|
||||
|
||||
M0P_GPIO->CTRL2_f.AHB_SEL = pstcGpioCfg->enCtrlMode;
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief GPIO IO输入值获取
|
||||
**
|
||||
** \param [in] enPort IO Port口
|
||||
** \param [in] enPin IO Pin脚
|
||||
**
|
||||
** \retval boolean_t IO电平高低
|
||||
******************************************************************************/
|
||||
boolean_t Gpio_GetInputIO(en_gpio_port_t enPort, en_gpio_pin_t enPin)
|
||||
{
|
||||
return GetBit(((uint32_t)&M0P_GPIO->PAIN + enPort), enPin);
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief GPIO IO Port输入数据获取
|
||||
**
|
||||
** \param [in] enPort IO Port
|
||||
**
|
||||
** \retval boolean_t IO Port数据
|
||||
******************************************************************************/
|
||||
uint16_t Gpio_GetInputData(en_gpio_port_t enPort)
|
||||
{
|
||||
return (uint16_t)(*((uint32_t *)((uint32_t)&M0P_GPIO->PAIN + enPort)));
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief GPIO IO输出值写入
|
||||
**
|
||||
** \param [in] enPort IO Port口
|
||||
** \param [in] enPin IO Pin脚
|
||||
** \param [out] bVal 输出值
|
||||
**
|
||||
** \retval en_result_t Ok 设置成功
|
||||
** 其他值 设置失败
|
||||
******************************************************************************/
|
||||
en_result_t Gpio_WriteOutputIO(en_gpio_port_t enPort, en_gpio_pin_t enPin, boolean_t bVal)
|
||||
{
|
||||
SetBit(((uint32_t)&M0P_GPIO->PAOUT + enPort), enPin, bVal);
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief GPIO IO输出值获取
|
||||
**
|
||||
** \param [in] enPort IO Port口
|
||||
** \param [in] enPin IO Pin脚
|
||||
**
|
||||
** \retval boolean_t IO电平高低
|
||||
******************************************************************************/
|
||||
boolean_t Gpio_ReadOutputIO(en_gpio_port_t enPort, en_gpio_pin_t enPin)
|
||||
{
|
||||
return GetBit(((uint32_t)&M0P_GPIO->PAOUT + enPort), enPin);
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief GPIO IO Port设置,可同时设置一组Port中的多个PIN
|
||||
**
|
||||
** \param [in] enPort IO Port
|
||||
** \param [in] u16ValMsk 该Port的16个PIN掩码值,将需要设置的PIN对应的bit写1有效
|
||||
**
|
||||
** \retval boolean_t IO Port数据
|
||||
******************************************************************************/
|
||||
en_result_t Gpio_SetPort(en_gpio_port_t enPort, uint16_t u16ValMsk)
|
||||
{
|
||||
*((uint16_t*)(((uint32_t)&(M0P_GPIO->PABSET)) + enPort)) = u16ValMsk;
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief GPIO IO设置
|
||||
**
|
||||
** \param [in] enPort IO Port口
|
||||
** \param [in] enPin IO Pin脚
|
||||
**
|
||||
** \retval en_result_t Ok 设置成功
|
||||
** 其他值 设置失败
|
||||
******************************************************************************/
|
||||
en_result_t Gpio_SetIO(en_gpio_port_t enPort, en_gpio_pin_t enPin)
|
||||
{
|
||||
SetBit(((uint32_t)&M0P_GPIO->PABSET + enPort), enPin, TRUE);
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief GPIO IO Port清零,可同时清零一组Port中的多个PIN
|
||||
**
|
||||
** \param [in] enPort IO Port
|
||||
** \param [in] u16ValMsk 该Port的16个PIN掩码值,将需要清零的PIN对应的bit写1有效
|
||||
**
|
||||
** \retval boolean_t IO Port数据
|
||||
******************************************************************************/
|
||||
en_result_t Gpio_ClrPort(en_gpio_port_t enPort, uint16_t u16ValMsk)
|
||||
{
|
||||
*((uint16_t*)(((uint32_t)&(M0P_GPIO->PABCLR)) + enPort)) = u16ValMsk;
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief GPIO IO清零
|
||||
**
|
||||
** \param [in] enPort IO Port口
|
||||
** \param [in] enPin IO Pin脚
|
||||
**
|
||||
** \retval en_result_t Ok 设置成功
|
||||
** 其他值 设置失败
|
||||
******************************************************************************/
|
||||
en_result_t Gpio_ClrIO(en_gpio_port_t enPort, en_gpio_pin_t enPin)
|
||||
{
|
||||
SetBit(((uint32_t)&M0P_GPIO->PABCLR + enPort), enPin, TRUE);
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief GPIO IO Port置位/清零,可同时置位/清零一组Port中的多个PIN
|
||||
**
|
||||
** \param [in] enPort IO Port
|
||||
** \param [in] u32ValMsk 高16bits表示该Port的16个PIN置位掩码值,
|
||||
** 低16bits表示该Port的16个PIN清零掩码值,
|
||||
** 将需要设置的PIN对应的bit写1,同一个PIN的掩码同时为1,则该PIN清零。
|
||||
**
|
||||
** \retval en_result_t Ok 设置成功
|
||||
** 其他值 设置失败
|
||||
******************************************************************************/
|
||||
en_result_t Gpio_SetClrPort(en_gpio_port_t enPort, uint32_t u32ValMsk)
|
||||
{
|
||||
*((uint32_t*)(((uint32_t)&(M0P_GPIO->PABSETCLR)) + enPort)) = u32ValMsk;
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief GPIO IO配置为模拟功能模式
|
||||
**
|
||||
** \param [in] enPort IO Port口
|
||||
** \param [in] enPin IO Pin脚
|
||||
**
|
||||
** \retval Ok 设置成功
|
||||
** 其他值 设置失败
|
||||
******************************************************************************/
|
||||
en_result_t Gpio_SetAnalogMode(en_gpio_port_t enPort, en_gpio_pin_t enPin)
|
||||
{
|
||||
SetBit((uint32_t)&M0P_GPIO->PAADS + enPort, enPin, TRUE);
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief GPIO IO复用功能设置
|
||||
**
|
||||
** \param [in] enPort IO Port口
|
||||
** \param [in] enPin IO Pin脚
|
||||
** \param [in] enAf 复用功能枚举类型选择
|
||||
** \retval Ok 设置成功
|
||||
** 其他值 设置失败
|
||||
******************************************************************************/
|
||||
en_result_t Gpio_SetAfMode(en_gpio_port_t enPort, en_gpio_pin_t enPin, en_gpio_af_t enAf)
|
||||
{
|
||||
*((uint32_t*)(((uint32_t)(&(M0P_GPIO->PA00_SEL)) + enPort) + (((uint32_t)enPin)<<2))) = enAf;
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief GPIO IO复用功能设置
|
||||
**
|
||||
** \param [in] PinMux 复用功能宏定义
|
||||
** \retval Null
|
||||
**
|
||||
******************************************************************************/
|
||||
void Gpio_SetAfMode_Lite(GpioPinMux PinMux)
|
||||
{
|
||||
*((uint32_t*)(((uint32_t)(&(M0P_GPIO->PA00_SEL)) + ((PinMux>>16u)&0xFFFFu)) + (((uint32_t)((PinMux>>8u)&0xFFu))<<2))) = (uint32_t)(PinMux&0x7u);
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief GPIO IO中断使能
|
||||
**
|
||||
** \param [in] enPort IO Port口
|
||||
** \param [in] enPin IO Pin脚
|
||||
** \param [in] enType 中断使能类型
|
||||
**
|
||||
** \retval Ok 设置成功
|
||||
******************************************************************************/
|
||||
en_result_t Gpio_EnableIrq(en_gpio_port_t enPort, en_gpio_pin_t enPin, en_gpio_irqtype_t enType)
|
||||
{
|
||||
uint32_t u32PieAddr;
|
||||
|
||||
u32PieAddr = ((uint32_t)((&M0P_GPIO->PAHIE) + enType)) + enPort;
|
||||
|
||||
SetBit(u32PieAddr, enPin, TRUE);
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief GPIO IO中断关闭
|
||||
**
|
||||
** \param [in] enPort IO Port口
|
||||
** \param [in] enPin IO Pin脚
|
||||
** \param [in] enType 中断使能类型
|
||||
**
|
||||
** \retval Ok 设置成功
|
||||
******************************************************************************/
|
||||
en_result_t Gpio_DisableIrq(en_gpio_port_t enPort, en_gpio_pin_t enPin, en_gpio_irqtype_t enType)
|
||||
{
|
||||
uint32_t u32PieAddr;
|
||||
|
||||
u32PieAddr = ((uint32_t)((&M0P_GPIO->PAHIE) + enType)) + enPort;
|
||||
|
||||
SetBit(u32PieAddr, enPin, FALSE);
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief GPIO 获得IO中断状态
|
||||
**
|
||||
** \param [in] u8Port IO Port口
|
||||
** \param [in] u8Pin IO Pin脚
|
||||
**
|
||||
** \retval IO中断状态开关
|
||||
******************************************************************************/
|
||||
boolean_t Gpio_GetIrqStatus(en_gpio_port_t enPort, en_gpio_pin_t enPin)
|
||||
{
|
||||
return GetBit((uint32_t)&M0P_GPIO->PA_STAT + enPort, enPin);
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief GPIO 清除IO中断状态
|
||||
**
|
||||
** \param [in] u8Port IO Port口
|
||||
** \param [in] u8Pin IO Pin脚
|
||||
**
|
||||
** \retval Ok 设置成功
|
||||
******************************************************************************/
|
||||
en_result_t Gpio_ClearIrq(en_gpio_port_t enPort, en_gpio_pin_t enPin)
|
||||
{
|
||||
SetBit((uint32_t)&M0P_GPIO->PA_ICLR + enPort, enPin, FALSE);
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief GPIO 端口辅助功能配置——中断模式配置
|
||||
**
|
||||
** \param [in] enIrqMode 端口中断模式(深度休眠是否响应中断)
|
||||
**
|
||||
** \retval Ok 设置成功
|
||||
******************************************************************************/
|
||||
en_result_t Gpio_SfIrqModeCfg(en_gpio_sf_irqmode_t enIrqMode)
|
||||
{
|
||||
M0P_GPIO->CTRL0_f.IESEL = enIrqMode;
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief GPIO 端口辅助功能配置——IR输出极性配置
|
||||
**
|
||||
** \param [in] enIrPolMode IR输出极性配置枚举
|
||||
**
|
||||
** \retval Ok 设置成功
|
||||
******************************************************************************/
|
||||
en_result_t Gpio_SfIrPolCfg(en_gpio_sf_irpol_t enIrPolMode)
|
||||
{
|
||||
M0P_GPIO->CTRL1_f.IR_POL = enIrPolMode;
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief GPIO 端口辅助功能配置——HCLK输出配置
|
||||
**
|
||||
** \param [in] enGate HCLK输出使能
|
||||
** \param [in] enDiv 输出分频枚举值
|
||||
**
|
||||
** \retval Ok 设置成功
|
||||
******************************************************************************/
|
||||
en_result_t Gpio_SfHClkOutputCfg(en_gpio_sf_hclkout_g_t enGate, en_gpio_sf_hclkout_div_t enDiv)
|
||||
{
|
||||
M0P_GPIO->CTRL1_f.HCLK_EN = enGate;
|
||||
M0P_GPIO->CTRL1_f.HCLK_SEL = enDiv;
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief GPIO 端口辅助功能配置——PCLK输出配置
|
||||
**
|
||||
** \param [in] enGate PCLK输出使能
|
||||
** \param [in] enDiv 输出分频枚举值
|
||||
**
|
||||
** \retval Ok 设置成功
|
||||
******************************************************************************/
|
||||
en_result_t Gpio_SfPClkOutputCfg(en_gpio_sf_pclkout_g_t enGate, en_gpio_sf_pclkout_div_t enDiv)
|
||||
{
|
||||
M0P_GPIO->CTRL1_f.PCLK_EN = enGate;
|
||||
M0P_GPIO->CTRL1_f.PCLK_SEL = enDiv;
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief GPIO 端口辅助功能配置——外部时钟输入来源配置
|
||||
**
|
||||
** \param [in] enExtClk 外部时钟信号来源选择枚举
|
||||
**
|
||||
** \retval Ok 设置成功
|
||||
******************************************************************************/
|
||||
en_result_t Gpio_SfExtClkCfg(en_gpio_sf_ssn_extclk_t enExtClk)
|
||||
{
|
||||
M0P_GPIO->CTRL1_f.EXT_CLK_SEL = enExtClk;
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief GPIO 端口辅助功能配置——SSN 通道信号来源配置
|
||||
**
|
||||
** \param [in] enSpi SSN SPI通道选择枚举
|
||||
** \param [in] enSsn SSN 信号来源选择枚举
|
||||
**
|
||||
** \retval Ok 设置成功
|
||||
******************************************************************************/
|
||||
en_result_t Gpio_SfSsnCfg(en_gpio_sf_ssnspi_t enSpi, en_gpio_sf_ssn_extclk_t enSsn)
|
||||
{
|
||||
//SPI0
|
||||
if(enSpi == GpioSpi0)
|
||||
{
|
||||
M0P_GPIO->CTRL1_f.SSN0_SEL = enSsn;
|
||||
}
|
||||
//SPI1
|
||||
if(enSpi == GpioSpi1)
|
||||
{
|
||||
M0P_GPIO->CTRL2_f.SSN1_SEL = enSsn;
|
||||
}
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief GPIO 端口辅助功能配置——Timer 门控输入配置
|
||||
**
|
||||
** \param [in] enTimG Timer类型选择枚举
|
||||
** \param [in] enSf Timer互联功能选择枚举
|
||||
**
|
||||
** \retval Ok 设置成功
|
||||
******************************************************************************/
|
||||
en_result_t Gpio_SfTimGCfg(en_gpio_sf_tim_g_t enTimG, en_gpio_sf_t enSf)
|
||||
{
|
||||
if(enTimG&0x20u)
|
||||
{
|
||||
enTimG &= ~0x20u;
|
||||
M0P_GPIO->PCAS &= (uint32_t)(~(0x07U<<enTimG));
|
||||
M0P_GPIO->PCAS |= (uint32_t)(enSf<<enTimG);
|
||||
}
|
||||
else
|
||||
{
|
||||
M0P_GPIO->TIMGS &= (uint32_t)(~(0x07U<<enTimG));
|
||||
M0P_GPIO->TIMGS |= (uint32_t)(enSf<<enTimG);
|
||||
}
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief GPIO 端口辅助功能配置——Timer ETR选择配置
|
||||
**
|
||||
** \param [in] enTimE Timer类型选择枚举
|
||||
** \param [in] enSf Timer互联功能选择枚举
|
||||
**
|
||||
** \retval Ok 设置成功
|
||||
******************************************************************************/
|
||||
en_result_t Gpio_SfTimECfg(en_gpio_sf_tim_e_t enTimE, en_gpio_sf_t enSf)
|
||||
{
|
||||
if(enTimE&0x20u)
|
||||
{
|
||||
enTimE &= ~0x20u;
|
||||
M0P_GPIO->PCAS &= (uint32_t)(~(0x07U<<enTimE));
|
||||
M0P_GPIO->PCAS |= (uint32_t)(enSf<<enTimE);
|
||||
}
|
||||
else
|
||||
{
|
||||
M0P_GPIO->TIMES &= (uint32_t)(~(0x07U<<enTimE));
|
||||
M0P_GPIO->TIMES |= (uint32_t)(enSf<<enTimE);
|
||||
}
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief GPIO 端口辅助功能配置——Timer 捕获输入选择配置
|
||||
**
|
||||
** \param [in] enTimC Timer类型选择枚举
|
||||
** \param [in] enSf Timer互联功能选择枚举
|
||||
**
|
||||
** \retval Ok 设置成功
|
||||
******************************************************************************/
|
||||
en_result_t Gpio_SfTimCCfg(en_gpio_sf_tim_c_t enTimC, en_gpio_sf_t enSf)
|
||||
{
|
||||
M0P_GPIO->TIMCPS &= (uint32_t)(~(0x07u<<enTimC));
|
||||
M0P_GPIO->TIMCPS |= (uint32_t)(enSf<<enTimC);
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief GPIO 端口辅助功能配置——PCA 捕获输入选择配置
|
||||
**
|
||||
** \param [in] enPca PCA类型选择枚举
|
||||
** \param [in] enSf PCA互联功能选择枚举
|
||||
**
|
||||
** \retval Ok 设置成功
|
||||
******************************************************************************/
|
||||
en_result_t Gpio_SfPcaCfg(en_gpio_sf_pca_t enPca, en_gpio_sf_t enSf)
|
||||
{
|
||||
M0P_GPIO->PCAS &= (uint32_t)(~(0x07u<<enPca));
|
||||
M0P_GPIO->PCAS |= (uint32_t)(enSf<<enPca);
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
//@} // GpioGroup
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* EOF (not truncated)
|
||||
******************************************************************************/
|
||||
|
||||
@@ -0,0 +1,398 @@
|
||||
/*************************************************************************************
|
||||
* Copyright (C) 2017, Huada Semiconductor Co.,Ltd All rights reserved.
|
||||
*
|
||||
* This software is owned and published by:
|
||||
* Huada Semiconductor Co.,Ltd ("HDSC").
|
||||
*
|
||||
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
|
||||
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
|
||||
*
|
||||
* This software contains source code for use with HDSC
|
||||
* components. This software is licensed by HDSC to be adapted only
|
||||
* for use in systems utilizing HDSC components. HDSC shall not be
|
||||
* responsible for misuse or illegal use of this software for devices not
|
||||
* supported herein. HDSC is providing this software "AS IS" and will
|
||||
* not be responsible for issues arising from incorrect user implementation
|
||||
* of the software.
|
||||
*
|
||||
* Disclaimer:
|
||||
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
|
||||
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
|
||||
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
|
||||
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
|
||||
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
|
||||
* WARRANTY OF NONINFRINGEMENT.
|
||||
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
|
||||
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
|
||||
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
|
||||
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
|
||||
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
|
||||
* SAVINGS OR PROFITS,
|
||||
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
|
||||
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
|
||||
* FROM, THE SOFTWARE.
|
||||
*
|
||||
* This software may be replicated in part or whole for the licensed use,
|
||||
* with the restriction that this Disclaimer and Copyright notice must be
|
||||
* included with each copy of this software, whether used in part or whole,
|
||||
* at all times.
|
||||
*/
|
||||
/******************************************************************************/
|
||||
/** \file I2C.c
|
||||
**
|
||||
** WDT function driver API.
|
||||
** @link SampleGroup Some description @endlink
|
||||
**
|
||||
** - 2018-03-13 1.0 CJ First version for Device Driver Library of Module.
|
||||
**
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
/* Include files */
|
||||
/******************************************************************************/
|
||||
#include "i2c.h"
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \addtogroup I2cGroup
|
||||
******************************************************************************/
|
||||
//@{
|
||||
|
||||
/******************************************************************************/
|
||||
/* Local function prototypes ('static') */
|
||||
/******************************************************************************/
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief I2C设置波特率配置寄存器
|
||||
**
|
||||
** \param [in] u8Tm 波特率配置值
|
||||
**
|
||||
** \retval enRet 成功或失败
|
||||
**
|
||||
******************************************************************************/
|
||||
en_result_t I2C_SetBaud(M0P_I2C_TypeDef* I2Cx, uint8_t u8Tm)
|
||||
{
|
||||
en_result_t enRet = Error;
|
||||
|
||||
I2Cx->TM = u8Tm;
|
||||
|
||||
enRet = Ok;
|
||||
return enRet;
|
||||
}
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief I2C功能设置相关函数
|
||||
**
|
||||
** \param [in] enFunc功能参数
|
||||
**
|
||||
** \retval enRet 成功或失败
|
||||
**
|
||||
******************************************************************************/
|
||||
en_result_t I2C_SetFunc(M0P_I2C_TypeDef* I2Cx, en_i2c_func_t enFunc)
|
||||
{
|
||||
en_result_t enRet = Error;
|
||||
|
||||
SetBit((uint32_t)&I2Cx->CR, enFunc, TRUE);
|
||||
|
||||
enRet = Ok;
|
||||
return enRet;
|
||||
}
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief I2C功能清除相关函数
|
||||
**
|
||||
** \param [in] enFunc功能参数
|
||||
**
|
||||
** \retval enRet 成功或失败
|
||||
**
|
||||
******************************************************************************/
|
||||
en_result_t I2C_ClearFunc(M0P_I2C_TypeDef* I2Cx, en_i2c_func_t enFunc)
|
||||
{
|
||||
en_result_t enRet = Error;
|
||||
|
||||
SetBit((uint32_t)&I2Cx->CR, enFunc, FALSE);
|
||||
|
||||
enRet = Ok;
|
||||
return enRet;
|
||||
}
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief I2C获取中断标记函数
|
||||
**
|
||||
** \param 无
|
||||
**
|
||||
** \retval bIrq中断标记
|
||||
**
|
||||
******************************************************************************/
|
||||
boolean_t I2C_GetIrq(M0P_I2C_TypeDef* I2Cx)
|
||||
{
|
||||
if(I2Cx->CR&0x8)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief I2C清除中断标记函数
|
||||
**
|
||||
** \param 无
|
||||
**
|
||||
** \retval bIrq中断标记
|
||||
**
|
||||
******************************************************************************/
|
||||
en_result_t I2C_ClearIrq(M0P_I2C_TypeDef* I2Cx)
|
||||
{
|
||||
en_result_t enRet = Error;
|
||||
|
||||
I2Cx->CR &= ~0x8u;
|
||||
|
||||
enRet = Ok;
|
||||
return enRet;
|
||||
}
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief I2C获取相关状态
|
||||
**
|
||||
** \param 无
|
||||
**
|
||||
** \retval I2C状态
|
||||
**
|
||||
******************************************************************************/
|
||||
uint8_t I2C_GetState(M0P_I2C_TypeDef* I2Cx)
|
||||
{
|
||||
uint8_t u8State = 0;
|
||||
|
||||
u8State = I2Cx->STAT;
|
||||
|
||||
return u8State;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief 字节数据写函数
|
||||
**
|
||||
** \param u8Data写数据
|
||||
**
|
||||
** \retval 写数据是否成功
|
||||
**
|
||||
******************************************************************************/
|
||||
en_result_t I2C_WriteByte(M0P_I2C_TypeDef* I2Cx, uint8_t u8Data)
|
||||
{
|
||||
en_result_t enRet = Error;
|
||||
|
||||
I2Cx->DATA = u8Data;
|
||||
|
||||
enRet = Ok;
|
||||
return enRet;
|
||||
}
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief 字节数据读函数
|
||||
**
|
||||
** \param 无
|
||||
**
|
||||
** \retval 读取数据
|
||||
**
|
||||
******************************************************************************/
|
||||
uint8_t I2C_ReadByte(M0P_I2C_TypeDef* I2Cx)
|
||||
{
|
||||
uint8_t u8Data = 0;
|
||||
|
||||
u8Data = I2Cx->DATA;
|
||||
|
||||
return u8Data;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief I2C模块初始化
|
||||
**
|
||||
** \param pstcI2CCfg初始化配置结构体
|
||||
**
|
||||
** \retval 初始化是否成功
|
||||
**
|
||||
******************************************************************************/
|
||||
en_result_t I2C_Init(M0P_I2C_TypeDef* I2Cx, stc_i2c_cfg_t *pstcI2CCfg)
|
||||
{
|
||||
en_result_t enRet = Error;
|
||||
uint8_t u8Tm;
|
||||
|
||||
if(M0P_I2C0 == I2Cx)
|
||||
{
|
||||
M0P_RESET->PERI_RESET0 &= ~(uint32_t)0x10u;
|
||||
M0P_RESET->PERI_RESET0 |= (uint32_t)0x10u;
|
||||
}
|
||||
else
|
||||
{
|
||||
M0P_RESET->PERI_RESET0 &= ~(uint32_t)0x20u;
|
||||
M0P_RESET->PERI_RESET0 |= (uint32_t)0x20u;
|
||||
}
|
||||
|
||||
I2Cx->CR = 0;
|
||||
I2Cx->CR = pstcI2CCfg->enMode;
|
||||
|
||||
if((pstcI2CCfg->u32Baud<<4) > pstcI2CCfg->u32Pclk)
|
||||
{
|
||||
return Error;
|
||||
}
|
||||
|
||||
if(I2cMasterMode == pstcI2CCfg->enMode)
|
||||
{
|
||||
I2Cx->TMRUN = TRUE;
|
||||
///< Fsck = Fpclk/8*(Tm+1)
|
||||
u8Tm = ((pstcI2CCfg->u32Pclk / pstcI2CCfg->u32Baud) >> 3) - 1;
|
||||
if(9 > u8Tm)
|
||||
{
|
||||
I2C_SetFunc(I2Cx,I2cHlm_En);
|
||||
}
|
||||
enRet = I2C_SetBaud(I2Cx, u8Tm);
|
||||
}
|
||||
else
|
||||
{
|
||||
I2Cx->TMRUN = FALSE;
|
||||
pstcI2CCfg->u8SlaveAddr = (uint8_t)(((uint32_t)pstcI2CCfg->u8SlaveAddr<<1)|(pstcI2CCfg->bGc));
|
||||
I2Cx->ADDR = pstcI2CCfg->u8SlaveAddr;
|
||||
}
|
||||
|
||||
return enRet;
|
||||
}
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief I2C模块接收指定长度函数
|
||||
**
|
||||
** \param u8SlaveAddr从机设备地址,u8Addr从机内存地址,pu8Data读数据存放缓存,u32Len读数据长度
|
||||
**
|
||||
** \retval 读数据是否成功
|
||||
**
|
||||
******************************************************************************/
|
||||
boolean_t I2C_MasterReadData(M0P_I2C_TypeDef* I2CX,uint8_t u8SlaveAddr,uint8_t u8Addr,uint8_t *pu8Data,uint32_t u32Len)
|
||||
{
|
||||
boolean_t enRet = FALSE;
|
||||
uint8_t u8i=0,u8State;
|
||||
|
||||
I2C_SetFunc(I2CX,I2cStart_En);//开始
|
||||
|
||||
while(1)
|
||||
{
|
||||
while(0 == I2C_GetIrq(I2CX))//获取中断标记函数
|
||||
{;}
|
||||
u8State = I2C_GetState(I2CX);//获取i2c相关状态
|
||||
switch(u8State)
|
||||
{
|
||||
case 0x08: ///< 主设备向总线已发出了一个起始条件
|
||||
I2C_ClearFunc(I2CX,I2cStart_En);
|
||||
I2C_WriteByte(I2CX,(u8SlaveAddr << 1));
|
||||
break;
|
||||
case 0x18: ///< 主设备向总线已发出了一个从设备地址(写方向)并且接收到从设备的应答
|
||||
I2C_WriteByte(I2CX,u8Addr); ///< 发送从机内存地址
|
||||
break;
|
||||
case 0x28: ///< 已发送数据,接收到ACK, 此处是已发送从机内存地址u8Addr并接收到ACK
|
||||
I2C_SetFunc(I2CX,I2cStart_En); ///< 发送重复起始条件
|
||||
break;
|
||||
case 0x10: ///< 主设备向总线已发出了一个重复的起始条件
|
||||
I2C_ClearFunc(I2CX,I2cStart_En);
|
||||
I2C_WriteByte(I2CX,(u8SlaveAddr << 1) | 0x01);///< 发送SLA+R,开始从从机读取数据
|
||||
break;
|
||||
case 0x40: ///< 已发送SLA+R,并接收到ACK
|
||||
if(u32Len>1)
|
||||
{
|
||||
I2C_SetFunc(I2CX,I2cAck_En); ///< 使能主机应答功能
|
||||
}
|
||||
break;
|
||||
case 0x50: ///< 已接收数据字节,并已返回ACK信号
|
||||
pu8Data[u8i++] = I2C_ReadByte(I2CX);
|
||||
if(u8i==u32Len-1)
|
||||
{
|
||||
I2C_ClearFunc(I2CX,I2cAck_En); ///< 已接收到倒数第二个字节,关闭ACK应答功能
|
||||
}
|
||||
break;
|
||||
case 0x58: ///< 已接收到最后一个数据,NACK已返回
|
||||
pu8Data[u8i++] = I2C_ReadByte(I2CX);
|
||||
I2C_SetFunc(I2CX,I2cStop_En); ///< 发送停止条件
|
||||
break;
|
||||
case 0x38: ///< 在发送地址或数据时,仲裁丢失
|
||||
I2C_SetFunc(I2CX,I2cStart_En); ///< 当总线空闲时发起起始条件
|
||||
break;
|
||||
case 0x48: ///< 发送SLA+R后,收到一个NACK
|
||||
I2C_SetFunc(I2CX,I2cStop_En); ///< 发送停止条件
|
||||
I2C_SetFunc(I2CX,I2cStart_En); ///< 发送起始条件
|
||||
break;
|
||||
default:
|
||||
I2C_SetFunc(I2CX,I2cStart_En); ///< 其他错误状态,重新发送起始条件
|
||||
break;
|
||||
}
|
||||
I2C_ClearIrq(I2CX); ///< 清除中断状态标志位
|
||||
if(u8i==u32Len) ///< 数据全部读取完成,跳出while循环
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
enRet = TRUE;
|
||||
return enRet;
|
||||
}
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief I2C模块主机发送指定长度函数
|
||||
**
|
||||
** \param u8SlaveAddr从机设备地址,u8Addr从机内存地址,pu8Data写数据,u32Len写数据长度
|
||||
**
|
||||
** \retval 写数据是否成功
|
||||
**
|
||||
******************************************************************************/
|
||||
boolean_t I2C_MasterWriteData(M0P_I2C_TypeDef* I2CX,uint8_t u8SlaveAddr,uint8_t u8Addr,uint8_t *pu8Data,uint32_t u32Len)
|
||||
{
|
||||
boolean_t enRet = FALSE;
|
||||
uint8_t u8i=0,u8State, u8Flag=FALSE;
|
||||
I2C_SetFunc(I2CX,I2cStart_En);
|
||||
while(1)
|
||||
{
|
||||
while(0 == I2C_GetIrq(I2CX))
|
||||
{;}
|
||||
u8State = I2C_GetState(I2CX);
|
||||
switch(u8State)
|
||||
{
|
||||
case 0x08: ///< 已发送起始条件
|
||||
I2C_ClearFunc(I2CX,I2cStart_En);
|
||||
I2C_WriteByte(I2CX,(u8SlaveAddr << 1)); ///< 从设备地址发送
|
||||
break;
|
||||
case 0x18: ///< 已发送SLA+W,并接收到ACK
|
||||
I2C_WriteByte(I2CX,u8Addr); ///< 从设备内存地址发送
|
||||
break;
|
||||
case 0x28: ///< 上一次发送数据后接收到ACK
|
||||
if (u8i < u32Len)
|
||||
{
|
||||
I2C_WriteByte(I2CX,pu8Data[u8i++]); ///< 继续发送数据
|
||||
}else
|
||||
{
|
||||
I2C_SetFunc(I2CX,I2cStop_En); ///< 出停止条件
|
||||
u8Flag = TRUE;
|
||||
}
|
||||
break;
|
||||
case 0x38: ///< 上一次在SLA+读或写时丢失仲裁
|
||||
I2C_SetFunc(I2CX,I2cStart_En); ///< 当I2C总线空闲时发送起始条件
|
||||
break;
|
||||
case 0x30: ///< 已发送I2Cx_DATA中的数据,收到NACK,将传输一个STOP条件
|
||||
I2C_SetFunc(I2CX,I2cStop_En); ///< 发送停止条件
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
I2C_ClearIrq(I2CX); ///< 清除中断状态标志位
|
||||
|
||||
if(u8Flag == TRUE) ///< 数据发送完成
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
enRet = TRUE;
|
||||
return enRet;
|
||||
}
|
||||
//@} // I2cGroup
|
||||
@@ -0,0 +1,289 @@
|
||||
/******************************************************************************
|
||||
* Copyright (C) 2019, Huada Semiconductor Co.,Ltd All rights reserved.
|
||||
*
|
||||
* This software is owned and published by:
|
||||
* Huada Semiconductor Co.,Ltd ("HDSC").
|
||||
*
|
||||
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
|
||||
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
|
||||
*
|
||||
* This software contains source code for use with HDSC
|
||||
* components. This software is licensed by HDSC to be adapted only
|
||||
* for use in systems utilizing HDSC components. HDSC shall not be
|
||||
* responsible for misuse or illegal use of this software for devices not
|
||||
* supported herein. HDSC is providing this software "AS IS" and will
|
||||
* not be responsible for issues arising from incorrect user implementation
|
||||
* of the software.
|
||||
*
|
||||
* Disclaimer:
|
||||
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
|
||||
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
|
||||
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
|
||||
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
|
||||
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
|
||||
* WARRANTY OF NONINFRINGEMENT.
|
||||
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
|
||||
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
|
||||
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
|
||||
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
|
||||
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
|
||||
* SAVINGS OR PROFITS,
|
||||
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
|
||||
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
|
||||
* FROM, THE SOFTWARE.
|
||||
*
|
||||
* This software may be replicated in part or whole for the licensed use,
|
||||
* with the restriction that this Disclaimer and Copyright notice must be
|
||||
* included with each copy of this software, whether used in part or whole,
|
||||
* at all times.
|
||||
*/
|
||||
/******************************************************************************/
|
||||
/** \file lcd.c
|
||||
**
|
||||
** lcd driver API.
|
||||
**
|
||||
** - 2019-04-02 First Version
|
||||
**
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* Include files
|
||||
******************************************************************************/
|
||||
#include "lcd.h"
|
||||
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \addtogroup AdcGroup
|
||||
******************************************************************************/
|
||||
//@{
|
||||
|
||||
/******************************************************************************
|
||||
* Local pre-processor symbols/macros ('#define')
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* Global variable definitions (declared in header file with 'extern')
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* Local type definitions ('typedef')
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* Local function prototypes ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* Local variable definitions ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* Function implementation - global ('extern') and local ('static')
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief 获取LCD中断标志位INTF
|
||||
**
|
||||
** @param 无
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
boolean_t Lcd_GetItStatus(void)
|
||||
{
|
||||
return (((M0P_LCD->CR1)>>11)&0x01)? TRUE : FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief 清除中断标志位INTF
|
||||
**
|
||||
** @param 无
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Lcd_ClearItPendingBit(void)
|
||||
{
|
||||
SetBit((uint32_t)(&(M0P_LCD->INTCLR)), 10, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief 根据LCD显示模式获取端口配置
|
||||
**
|
||||
** \param pstcSegComPara:显示方式, stcSegCom获取端口参数
|
||||
**
|
||||
** \retval enRet 成功或失败
|
||||
**
|
||||
******************************************************************************/
|
||||
en_result_t Lcd_GetSegCom(stc_lcd_segcompara_t *pstcSegComPara,stc_lcd_segcom_t *pstcSegCom)
|
||||
{
|
||||
en_result_t enRet = Error;
|
||||
pstcSegCom->stc_seg32_51_com0_8_t.seg32_51_com0_8 = 0xffffffffu;
|
||||
pstcSegCom->u32Seg0_31 = 0xffffffffu;
|
||||
if(pstcSegComPara->u8MaxSeg>51)
|
||||
{
|
||||
return ErrorInvalidParameter;
|
||||
}
|
||||
switch(pstcSegComPara->LcdBiasSrc)
|
||||
{
|
||||
case LcdInResHighPower:
|
||||
case LcdInResLowPower:
|
||||
case LcdInResMidPower:
|
||||
pstcSegCom->stc_seg32_51_com0_8_t.segcom_bit.Mux = 1;
|
||||
break;
|
||||
case LcdExtCap:
|
||||
case LcdExtRes:
|
||||
pstcSegCom->stc_seg32_51_com0_8_t.segcom_bit.Mux = 0;
|
||||
pstcSegCom->stc_seg32_51_com0_8_t.segcom_bit.Seg32_35 = 0;
|
||||
break;
|
||||
default:
|
||||
return ErrorInvalidParameter;
|
||||
}
|
||||
switch(pstcSegComPara->LcdDuty)
|
||||
{
|
||||
case LcdStatic:
|
||||
pstcSegCom->stc_seg32_51_com0_8_t.segcom_bit.Com0_3 = (~1u)&0x0fu;
|
||||
break;
|
||||
case LcdDuty2:
|
||||
pstcSegCom->stc_seg32_51_com0_8_t.segcom_bit.Com0_3 = (~3u)&0x0fu;
|
||||
break;
|
||||
case LcdDuty3:
|
||||
pstcSegCom->stc_seg32_51_com0_8_t.segcom_bit.Com0_3 = (~7u)&0x0fu;
|
||||
break;
|
||||
case LcdDuty4:
|
||||
pstcSegCom->stc_seg32_51_com0_8_t.segcom_bit.Com0_3 = (~15u)&0x0fu;
|
||||
break;
|
||||
case LcdDuty6:
|
||||
pstcSegCom->stc_seg32_51_com0_8_t.segcom_bit.Com0_3 = 0;
|
||||
pstcSegCom->stc_seg32_51_com0_8_t.segcom_bit.Seg39Com4 = 0;
|
||||
pstcSegCom->stc_seg32_51_com0_8_t.segcom_bit.Seg38Com5 = 0;
|
||||
pstcSegCom->stc_seg32_51_com0_8_t.segcom_bit.Seg37Com6 = 1;
|
||||
pstcSegCom->stc_seg32_51_com0_8_t.segcom_bit.Seg36Com7 = 1;
|
||||
break;
|
||||
case LcdDuty8:
|
||||
pstcSegCom->stc_seg32_51_com0_8_t.segcom_bit.Com0_3 = 0;
|
||||
pstcSegCom->stc_seg32_51_com0_8_t.segcom_bit.Seg39Com4 = 0;
|
||||
pstcSegCom->stc_seg32_51_com0_8_t.segcom_bit.Seg38Com5 = 0;
|
||||
pstcSegCom->stc_seg32_51_com0_8_t.segcom_bit.Seg37Com6 = 0;
|
||||
pstcSegCom->stc_seg32_51_com0_8_t.segcom_bit.Seg36Com7 = 0;
|
||||
break;
|
||||
default:
|
||||
return ErrorInvalidParameter;
|
||||
}
|
||||
enRet = Ok;
|
||||
return enRet;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief LCD COMSEG端口配置,使用该函数之前需要先使能相应的Seg
|
||||
**
|
||||
** \param [in] pstcSegCom端口配置结构体
|
||||
**
|
||||
** \retval enRet 成功或失败
|
||||
**
|
||||
******************************************************************************/
|
||||
void Lcd_SetSegCom(stc_lcd_segcom_t *pstcSegCom)
|
||||
{
|
||||
M0P_LCD->POEN0 = pstcSegCom->u32Seg0_31;
|
||||
M0P_LCD->POEN1 = pstcSegCom->stc_seg32_51_com0_8_t.seg32_51_com0_8;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief LCD模块初始化函数
|
||||
**
|
||||
** \param stcLcdCfg配置初始化结构体
|
||||
**
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Lcd_Init(stc_lcd_cfg_t *pstcLcdCfg)
|
||||
{
|
||||
M0P_LCD->CR0_f.BSEL = pstcLcdCfg->LcdBiasSrc;
|
||||
M0P_LCD->CR0_f.DUTY = pstcLcdCfg->LcdDuty;
|
||||
M0P_LCD->CR0_f.BIAS = pstcLcdCfg->LcdBias;
|
||||
M0P_LCD->CR0_f.CPCLK = pstcLcdCfg->LcdCpClk;
|
||||
M0P_LCD->CR0_f.LCDCLK = pstcLcdCfg->LcdScanClk;
|
||||
M0P_LCD->CR1_f.MODE = pstcLcdCfg->LcdMode;
|
||||
M0P_LCD->CR1_f.CLKSRC = pstcLcdCfg->LcdClkSrc;
|
||||
M0P_LCD->CR0_f.EN = pstcLcdCfg->LcdEn;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief 液晶全显
|
||||
**
|
||||
** \param 无
|
||||
**
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Lcd_FullDisp(void)
|
||||
{
|
||||
uint8_t tmp;
|
||||
volatile uint32_t *ram = NULL;
|
||||
ram = &M0P_LCD->RAM0;
|
||||
for(tmp=0;tmp<16;tmp++)
|
||||
{
|
||||
*ram = 0xffffffffu;
|
||||
ram++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief 清屏
|
||||
**
|
||||
** \param 无
|
||||
**
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Lcd_ClearDisp(void)
|
||||
{
|
||||
uint8_t tmp;
|
||||
volatile uint32_t *ram = NULL;
|
||||
ram = &M0P_LCD->RAM0;
|
||||
for(tmp=0;tmp<16;tmp++)
|
||||
{
|
||||
*ram = 0;
|
||||
ram++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief LCD RAM 0-f寄存器设置函数
|
||||
**
|
||||
** \param u8Row RAM地址索引,范围:0-15,u8Data写入寄存器数值
|
||||
**
|
||||
** \retval enRet 成功或失败
|
||||
**
|
||||
******************************************************************************/
|
||||
en_result_t Lcd_WriteRam(uint8_t u8Row,uint32_t u32Data)
|
||||
{
|
||||
en_result_t enRet = Error;
|
||||
volatile uint32_t *ram = NULL;
|
||||
ram = (volatile uint32_t*)&M0P_LCD->RAM0;
|
||||
|
||||
if (u8Row > 15)
|
||||
{
|
||||
enRet = ErrorInvalidParameter;
|
||||
return enRet;
|
||||
}
|
||||
|
||||
ram += u8Row;
|
||||
*ram = u32Data;
|
||||
enRet = Ok;
|
||||
return enRet;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* EOF (not truncated)
|
||||
******************************************************************************/
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
/******************************************************************************
|
||||
*Copyright(C)2017, Huada Semiconductor Co.,Ltd All rights reserved.
|
||||
*
|
||||
* This software is owned and published by:
|
||||
* Huada Semiconductor Co.,Ltd("HDSC").
|
||||
*
|
||||
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
|
||||
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
|
||||
*
|
||||
* This software contains source code for use with HDSC
|
||||
* components. This software is licensed by HDSC to be adapted only
|
||||
* for use in systems utilizing HDSC components. HDSC shall not be
|
||||
* responsible for misuse or illegal use of this software for devices not
|
||||
* supported herein. HDSC is providing this software "AS IS" and will
|
||||
* not be responsible for issues arising from incorrect user implementation
|
||||
* of the software.
|
||||
*
|
||||
* Disclaimer:
|
||||
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
|
||||
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
|
||||
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
|
||||
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
|
||||
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
|
||||
* WARRANTY OF NONINFRINGEMENT.
|
||||
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
|
||||
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
|
||||
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
|
||||
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
|
||||
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
|
||||
* SAVINGS OR PROFITS,
|
||||
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
|
||||
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
|
||||
* FROM, THE SOFTWARE.
|
||||
*
|
||||
* This software may be replicated in part or whole for the licensed use,
|
||||
* with the restriction that this Disclaimer and Copyright notice must be
|
||||
* included with each copy of this software, whether used in part or whole,
|
||||
* at all times.
|
||||
*/
|
||||
|
||||
/** \file lpm.c
|
||||
**
|
||||
** Common API of lpm.
|
||||
** @link LpmGroup Some description @endlink
|
||||
**
|
||||
** - 2017-06-06
|
||||
**
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Include files
|
||||
******************************************************************************/
|
||||
#include "lpm.h"
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \addtogroup LpmGroup
|
||||
******************************************************************************/
|
||||
//@{
|
||||
|
||||
/*******************************************************************************
|
||||
* Local pre-processor symbols/macros ('#define')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Global variable definitions (declared in header file with 'extern')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Local type definitions ('typedef')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Local variable definitions ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Local function prototypes ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Function implementation - global ('extern') and local ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief 进入深度睡眠模式
|
||||
**
|
||||
** \input bOnExit - TRUE:当退出异常处理后,自动再次进入休眠;
|
||||
** FALSE:唤醒后不再自动进入休眠
|
||||
**
|
||||
** \retval NULL
|
||||
*****************************************************************************/
|
||||
void Lpm_GotoDeepSleep(boolean_t bOnExit)
|
||||
{
|
||||
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
|
||||
SCB->SCR |= 1u<<bOnExit;
|
||||
__WFI();
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief 进入普通睡眠模式
|
||||
**
|
||||
** \input bOnExit - TRUE:当退出异常处理后,自动再次进入休眠;
|
||||
** FALSE:唤醒后不再自动进入休眠
|
||||
**
|
||||
** \retval NULL
|
||||
*****************************************************************************/
|
||||
void Lpm_GotoSleep(boolean_t bOnExit)
|
||||
{
|
||||
SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;
|
||||
SCB->SCR |= 1u<<bOnExit;
|
||||
__WFI();
|
||||
}
|
||||
|
||||
//@} // LpmGroup
|
||||
|
||||
/*******************************************************************************
|
||||
* EOF (not truncated)
|
||||
******************************************************************************/
|
||||
@@ -0,0 +1,171 @@
|
||||
/******************************************************************************
|
||||
* Copyright (C) 2019, Huada Semiconductor Co.,Ltd All rights reserved.
|
||||
*
|
||||
* This software is owned and published by:
|
||||
* Huada Semiconductor Co.,Ltd ("HDSC").
|
||||
*
|
||||
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
|
||||
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
|
||||
*
|
||||
* This software contains source code for use with HDSC
|
||||
* components. This software is licensed by HDSC to be adapted only
|
||||
* for use in systems utilizing HDSC components. HDSC shall not be
|
||||
* responsible for misuse or illegal use of this software for devices not
|
||||
* supported herein. HDSC is providing this software "AS IS" and will
|
||||
* not be responsible for issues arising from incorrect user implementation
|
||||
* of the software.
|
||||
*
|
||||
* Disclaimer:
|
||||
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
|
||||
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
|
||||
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
|
||||
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
|
||||
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
|
||||
* WARRANTY OF NONINFRINGEMENT.
|
||||
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
|
||||
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
|
||||
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
|
||||
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
|
||||
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
|
||||
* SAVINGS OR PROFITS,
|
||||
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
|
||||
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
|
||||
* FROM, THE SOFTWARE.
|
||||
*
|
||||
* This software may be replicated in part or whole for the licensed use,
|
||||
* with the restriction that this Disclaimer and Copyright notice must be
|
||||
* included with each copy of this software, whether used in part or whole,
|
||||
* at all times.
|
||||
*/
|
||||
/******************************************************************************/
|
||||
/** \file lptim.c
|
||||
**
|
||||
** lptim driver API.
|
||||
** @link pcnt Group Some description @endlink
|
||||
**
|
||||
** - 2019-04-09 First Version
|
||||
**
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* Include files
|
||||
******************************************************************************/
|
||||
|
||||
#include "lptim.h"
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \addtogroup PCNTGroup
|
||||
******************************************************************************/
|
||||
//@{
|
||||
|
||||
/******************************************************************************
|
||||
* Local pre-processor symbols/macros ('#define')
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* Global variable definitions (declared in header file with 'extern')
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* Local type definitions ('typedef')
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* Local function prototypes ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* Local variable definitions ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief 定时器LPTIMx中断使能控制
|
||||
** @param Lptimx : LPTIM0 或LPTIM1
|
||||
** @param NewStatus : TRUE 或 FALSE
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Lptim_ConfIt(M0P_LPTIMER_TypeDef* Lptimx, boolean_t NewStatus)
|
||||
{
|
||||
SetBit((uint32_t)(&(Lptimx->CR)), 10, NewStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief 定时器LPTIMx的启动/停止控制
|
||||
** @param Lptimx : LPTIM0 或LPTIM1
|
||||
** @param NewStatus : TRUE 或 FALSE
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Lptim_Cmd(M0P_LPTIMER_TypeDef* Lptimx, boolean_t NewStatus)
|
||||
{
|
||||
SetBit((uint32_t)(&(Lptimx->CR)), 0, NewStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief 定时器LPTIMx的中断标志位获取
|
||||
** @param Lptimx : LPTIM0 或LPTIM1
|
||||
** \retval TRUE 或 FALSE
|
||||
**
|
||||
******************************************************************************/
|
||||
boolean_t Lptim_GetItStatus(M0P_LPTIMER_TypeDef* Lptimx)
|
||||
{
|
||||
return GetBit((uint32_t)(&(Lptimx->IFR)), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief 定时器LPTIMx的中断标志位清除
|
||||
** @param Lptimx : LPTIM0 或LPTIM1
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Lptim_ClrItStatus(M0P_LPTIMER_TypeDef* Lptimx)
|
||||
{
|
||||
SetBit((uint32_t)(&(Lptimx->ICLR)), 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief 定时器LPTIMx的初始化配置
|
||||
** @param Lptimx : LPTIM0 或LPTIM1
|
||||
** @param InitStruct : 初始化LPTIMx的结构体
|
||||
** \retval en_result_t类型数据
|
||||
**
|
||||
******************************************************************************/
|
||||
en_result_t Lptim_Init(M0P_LPTIMER_TypeDef* Lptimx, stc_lptim_cfg_t* InitStruct)
|
||||
{
|
||||
uint16_t u16TimeOut;
|
||||
u16TimeOut = 1000;
|
||||
Lptimx->CR_f.PRS = InitStruct->enPrs;
|
||||
Lptimx->CR_f.TCK_SEL = InitStruct->enTcksel;
|
||||
Lptimx->CR_f.GATE_P = InitStruct->enGatep;
|
||||
Lptimx->CR_f.GATE = InitStruct->enGate;
|
||||
Lptimx->CR_f.TOG_EN = InitStruct->enTogen;
|
||||
Lptimx->CR_f.CT = InitStruct->enCt;
|
||||
Lptimx->CR_f.MD = InitStruct->enMd;
|
||||
while(u16TimeOut--)
|
||||
{
|
||||
if(Lptimx->CR_f.WT_FLAG)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(u16TimeOut == 0)
|
||||
{
|
||||
return ErrorTimeout;
|
||||
}
|
||||
Lptimx->ARR_f.ARR = InitStruct->u16Arr;
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* EOF (not truncated)
|
||||
******************************************************************************/
|
||||
@@ -0,0 +1,409 @@
|
||||
/*************************************************************************************
|
||||
* Copyright (C) 2017, Huada Semiconductor Co.,Ltd All rights reserved.
|
||||
*
|
||||
* This software is owned and published by:
|
||||
* Huada Semiconductor Co.,Ltd ("HDSC").
|
||||
*
|
||||
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
|
||||
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
|
||||
*
|
||||
* This software contains source code for use with HDSC
|
||||
* components. This software is licensed by HDSC to be adapted only
|
||||
* for use in systems utilizing HDSC components. HDSC shall not be
|
||||
* responsible for misuse or illegal use of this software for devices not
|
||||
* supported herein. HDSC is providing this software "AS IS" and will
|
||||
* not be responsible for issues arising from incorrect user implementation
|
||||
* of the software.
|
||||
*
|
||||
* Disclaimer:
|
||||
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
|
||||
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
|
||||
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
|
||||
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
|
||||
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
|
||||
* WARRANTY OF NONINFRINGEMENT.
|
||||
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
|
||||
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
|
||||
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
|
||||
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
|
||||
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
|
||||
* SAVINGS OR PROFITS,
|
||||
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
|
||||
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
|
||||
* FROM, THE SOFTWARE.
|
||||
*
|
||||
* This software may be replicated in part or whole for the licensed use,
|
||||
* with the restriction that this Disclaimer and Copyright notice must be
|
||||
* included with each copy of this software, whether used in part or whole,
|
||||
* at all times.
|
||||
*/
|
||||
/******************************************************************************/
|
||||
/** \file lpuart.c
|
||||
**
|
||||
** LPUART function driver API.
|
||||
** @link SampleGroup Some description @endlink
|
||||
**
|
||||
** - 2017-05-17 1.0 CJ First version for Device Driver Library of Module.
|
||||
**
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
/* Include files */
|
||||
/******************************************************************************/
|
||||
#include "lpuart.h"
|
||||
/**
|
||||
******************************************************************************
|
||||
** \addtogroup LPUartGroup
|
||||
******************************************************************************/
|
||||
//@{
|
||||
/******************************************************************************/
|
||||
/* Local pre-processor symbols/macros ('#define') */
|
||||
/******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
/* Local function prototypes ('static') */
|
||||
/******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
/* Local variable definitions ('static') */
|
||||
/******************************************************************************/
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief LPUART通信中断使能函数设置
|
||||
**
|
||||
** \param [in] LPUARTx通道号,enIrqSel发送or接收中断使能
|
||||
**
|
||||
** \retval OK配置成功
|
||||
**\retval ErrorInvalidParameter配置失败
|
||||
******************************************************************************/
|
||||
en_result_t LPUart_EnableIrq(M0P_LPUART_TypeDef* LPUARTx, en_lpuart_irq_sel_t enIrqSel)
|
||||
{
|
||||
|
||||
SetBit((uint32_t)(&(LPUARTx->SCON)), enIrqSel, TRUE);
|
||||
|
||||
return Ok;
|
||||
}
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief LPUART通信中断禁止函数设置
|
||||
**
|
||||
** \param [in] LPUARTx通道号,enIrqSel发送or接收中断禁止
|
||||
**
|
||||
** \retval OK配置成功
|
||||
**\retval ErrorInvalidParameter配置失败
|
||||
******************************************************************************/
|
||||
en_result_t LPUart_DisableIrq(M0P_LPUART_TypeDef* LPUARTx, en_lpuart_irq_sel_t enIrqSel)
|
||||
{
|
||||
|
||||
SetBit((uint32_t)(&(LPUARTx->SCON)), enIrqSel, FALSE);
|
||||
|
||||
return Ok;
|
||||
}
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief lpuart通信时钟源选择
|
||||
**
|
||||
** \param [in] LPUARTx通道号,enClk 时钟源选项
|
||||
**
|
||||
** \retval Ok 设置成功
|
||||
**\retval ErrorInvalidParameter设置失败
|
||||
******************************************************************************/
|
||||
en_result_t LPUart_SelSclk(M0P_LPUART_TypeDef* LPUARTx, en_lpuart_sclksel_t enSclk)
|
||||
{
|
||||
ASSERT(IS_VALID_CLK(enSclk));
|
||||
|
||||
LPUARTx->SCON_f.SCLKSEL = enSclk;
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief LPUART通道多主机模式配置
|
||||
**
|
||||
** \param [in] LPUARTx通道号,stcMultiCfg多主机模式结构
|
||||
**
|
||||
** \retval OK配置成功
|
||||
**\retval ErrorInvalidParameter配置失败
|
||||
******************************************************************************/
|
||||
en_result_t LPUart_SetMultiMode(M0P_LPUART_TypeDef* LPUARTx, stc_lpuart_multimode_t* pstcMultiCfg)
|
||||
{
|
||||
|
||||
if(NULL != pstcMultiCfg)
|
||||
{
|
||||
LPUARTx->SCON_f.ADRDET = TRUE;
|
||||
LPUARTx->SADDR = pstcMultiCfg->u8SlaveAddr;
|
||||
LPUARTx->SADEN = pstcMultiCfg->u8SaddEn;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ErrorInvalidParameter;
|
||||
}
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief LPUART单线半双工模式使能
|
||||
**
|
||||
** \param [in] LPUARTx 通道号
|
||||
**
|
||||
** \retval Null
|
||||
******************************************************************************/
|
||||
void LPUart_HdModeEnable(M0P_LPUART_TypeDef* LPUARTx)
|
||||
{
|
||||
LPUARTx->SCON_f.HDSEL = TRUE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief LPUART单线半双工模式关闭
|
||||
**
|
||||
** \param [in] LPUARTx 通道号
|
||||
**
|
||||
** \retval Null
|
||||
******************************************************************************/
|
||||
void LPUart_HdModeDisable(M0P_LPUART_TypeDef* LPUARTx)
|
||||
{
|
||||
LPUARTx->SCON_f.HDSEL = FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief LPUART通道多机模式发送数据/地址帧配置TB8
|
||||
**
|
||||
** \param [in] LPUARTx 通道号
|
||||
** \param [in] TRUE-TB8为地址帧标志;FALSE-TB8为数据帧标志;
|
||||
**
|
||||
** \retval Null
|
||||
******************************************************************************/
|
||||
void LPUart_SetTb8(M0P_LPUART_TypeDef* LPUARTx, boolean_t bTB8Value)
|
||||
{
|
||||
LPUARTx->SCON_f.B8CONT = bTB8Value;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief 获取RB8数值
|
||||
**
|
||||
** \param [in] LPUARTx 通道号
|
||||
**
|
||||
** \retval RB8
|
||||
**\retval ErrorInvalidParameter配置失败
|
||||
******************************************************************************/
|
||||
boolean_t LPUart_GetRb8(M0P_LPUART_TypeDef* LPUARTx)
|
||||
{
|
||||
return (LPUARTx->SBUF_f.DATA8);
|
||||
}
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief LPUART通道多主机模式从机地址配置函数
|
||||
**
|
||||
** \param [in] LPUARTx 通道号,addr地址
|
||||
**
|
||||
** \retval OK配置成功
|
||||
**\retval ErrorInvalidParameter配置失败
|
||||
******************************************************************************/
|
||||
en_result_t LPUart_SetSaddr(M0P_LPUART_TypeDef* LPUARTx,uint8_t u8Addr)
|
||||
{
|
||||
LPUARTx->SADDR = u8Addr;
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief LPUART通道发送或接收等功能使能设置
|
||||
**
|
||||
** \param [in] u8Idx通道号,enFunc功能
|
||||
**
|
||||
** \retval OK配置成功
|
||||
**\retval ErrorInvalidParameter配置失败
|
||||
******************************************************************************/
|
||||
en_result_t LPUart_EnableFunc(M0P_LPUART_TypeDef* LPUARTx, en_lpuart_func_t enFunc)
|
||||
{
|
||||
SetBit((uint32_t)(&(LPUARTx->SCON)), enFunc, TRUE);
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief LPUART通道发送或接收等功能禁止设置
|
||||
**
|
||||
** \param [in] u8Idx通道号,enFunc功能
|
||||
**
|
||||
** \retval OK配置成功
|
||||
**\retval ErrorInvalidParameter配置失败
|
||||
******************************************************************************/
|
||||
en_result_t LPUart_DisableFunc(M0P_LPUART_TypeDef* LPUARTx, en_lpuart_func_t enFunc)
|
||||
{
|
||||
SetBit((uint32_t)(&(LPUARTx->SCON)), enFunc, FALSE);
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief LPUART通道通信状态获取
|
||||
**
|
||||
** \param [in] u8Idx通道号
|
||||
**
|
||||
** \retval 状态值
|
||||
******************************************************************************/
|
||||
uint8_t LPUart_GetIsr(M0P_LPUART_TypeDef* LPUARTx)
|
||||
{
|
||||
return (LPUARTx->ISR);
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief LPUART通道通信状态获取
|
||||
**
|
||||
** \param [in] u8Idx通道号,enStatus获取哪个状态
|
||||
**
|
||||
** \retval 状态值
|
||||
**\retval ErrorInvalidParameter获取失败
|
||||
******************************************************************************/
|
||||
boolean_t LPUart_GetStatus(M0P_LPUART_TypeDef* LPUARTx,en_lpuart_status_t enStatus)
|
||||
{
|
||||
boolean_t bStatus = FALSE;
|
||||
|
||||
ASSERT(IS_VALID_STATUS(enStatus));
|
||||
|
||||
bStatus = GetBit((uint32_t)(&(LPUARTx->ISR)), enStatus);
|
||||
|
||||
return bStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief LPUART通道通信状态全部清除
|
||||
**
|
||||
** \param [in] u8Idx通道号
|
||||
**
|
||||
** \retval OK
|
||||
******************************************************************************/
|
||||
en_result_t LPUart_ClrIsr(M0P_LPUART_TypeDef* LPUARTx)
|
||||
{
|
||||
LPUARTx->ICR = 0u;
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief LPUART通道通信状态清除
|
||||
**
|
||||
** \param [in] u8Idx通道号,enStatus清除哪个状态
|
||||
**
|
||||
** \retval 状态值
|
||||
**\retval ErrorInvalidParameter清除失败
|
||||
******************************************************************************/
|
||||
en_result_t LPUart_ClrStatus(M0P_LPUART_TypeDef* LPUARTx,en_lpuart_status_t enStatus)
|
||||
{
|
||||
ASSERT(IS_VALID_STATUS(enStatus));
|
||||
|
||||
SetBit((uint32_t)(&(LPUARTx->ICR)), enStatus, FALSE);
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief LPUART通道发送数据函数,查询方式调用此函数,中断方式发送不适用
|
||||
**
|
||||
** \param [in] u8Idx通道号,Data发送数据
|
||||
**
|
||||
** \retval Ok发送成功
|
||||
**\retval ErrorInvalidParameter发送失败
|
||||
******************************************************************************/
|
||||
en_result_t LPUart_SendData(M0P_LPUART_TypeDef* LPUARTx, uint8_t u8Data)
|
||||
{
|
||||
while(FALSE == LPUart_GetStatus(LPUARTx,LPUartTxe))
|
||||
{}
|
||||
LPUARTx->SBUF_f.DATA = u8Data;
|
||||
while(FALSE == LPUart_GetStatus(LPUARTx,LPUartTC))
|
||||
{}
|
||||
LPUart_ClrStatus(LPUARTx,LPUartTC);
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief LPUART通道发送数据函数,中断方式调用此函数
|
||||
**
|
||||
** \param [in] u8Idx通道号,Data发送数据
|
||||
**
|
||||
** \retval Ok发送成功
|
||||
**\retval ErrorInvalidParameter发送失败
|
||||
******************************************************************************/
|
||||
en_result_t LPUart_SendDataIt(M0P_LPUART_TypeDef* LPUARTx, uint8_t u8Data)
|
||||
{
|
||||
LPUARTx->SBUF_f.DATA = u8Data;
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief LPUART通道接收数据函数
|
||||
**
|
||||
** \param [in] u8Idx通道号
|
||||
**
|
||||
** \retval 接收数据
|
||||
**\retval ErrorInvalidParameter接收失败
|
||||
******************************************************************************/
|
||||
uint8_t LPUart_ReceiveData(M0P_LPUART_TypeDef* LPUARTx)
|
||||
{
|
||||
return (LPUARTx->SBUF_f.DATA);
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief LPUART通道初始化函数
|
||||
**
|
||||
** \param [in] u8Idx通道号,pstcCfg初始化结构体 @ref stc_lpuart_cfg_t
|
||||
**
|
||||
** \retval OK配置成功
|
||||
**\retval ErrorInvalidParameter配置失败
|
||||
******************************************************************************/
|
||||
en_result_t LPUart_Init(M0P_LPUART_TypeDef* LPUARTx,stc_lpuart_cfg_t* pstcCfg)
|
||||
{
|
||||
en_result_t enRet = Error;
|
||||
const uint32_t u32Over[3] = {0x4, 0x3, 0x2};
|
||||
uint16_t u16OverShift;
|
||||
float32_t f32Scnt=0;
|
||||
|
||||
if(NULL == pstcCfg)
|
||||
{
|
||||
return ErrorInvalidParameter;
|
||||
}
|
||||
|
||||
LPUARTx->SCON = 0;
|
||||
|
||||
LPUARTx->SCON = (uint32_t)pstcCfg->enStopBit |
|
||||
(uint32_t)pstcCfg->enMmdorCk |
|
||||
(uint32_t)pstcCfg->stcBaud.enSclkDiv |
|
||||
(uint32_t)pstcCfg->stcBaud.enSclkSel |
|
||||
(uint32_t)pstcCfg->enRunMode;
|
||||
|
||||
if((LPUartMskMode1 == pstcCfg->enRunMode) || (LPUartMskMode3 == pstcCfg->enRunMode))
|
||||
{
|
||||
u16OverShift = u32Over[pstcCfg->stcBaud.enSclkDiv/LPUartMsk8Or16Div];
|
||||
f32Scnt = (float32_t)(pstcCfg->stcBaud.u32Sclk)/(float32_t)(pstcCfg->stcBaud.u32Baud<<u16OverShift);
|
||||
LPUARTx->SCNT = (uint16_t)(float32_t)(f32Scnt + 0.5f);
|
||||
LPUart_EnableFunc(LPUARTx,LPUartRenFunc); ///<使能收发
|
||||
}
|
||||
|
||||
|
||||
|
||||
enRet = Ok;
|
||||
return enRet;
|
||||
}
|
||||
//@} // LPUartGroup
|
||||
@@ -0,0 +1,216 @@
|
||||
/******************************************************************************
|
||||
* Copyright (C) 2017, Huada Semiconductor Co.,Ltd All rights reserved.
|
||||
*
|
||||
* This software is owned and published by:
|
||||
* Huada Semiconductor Co.,Ltd ("HDSC").
|
||||
*
|
||||
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
|
||||
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
|
||||
*
|
||||
* This software contains source code for use with HDSC
|
||||
* components. This software is licensed by HDSC to be adapted only
|
||||
* for use in systems utilizing HDSC components. HDSC shall not be
|
||||
* responsible for misuse or illegal use of this software for devices not
|
||||
* supported herein. HDSC is providing this software "AS IS" and will
|
||||
* not be responsible for issues arising from incorrect user implementation
|
||||
* of the software.
|
||||
*
|
||||
* Disclaimer:
|
||||
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
|
||||
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
|
||||
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
|
||||
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
|
||||
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
|
||||
* WARRANTY OF NONINFRINGEMENT.
|
||||
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
|
||||
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
|
||||
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
|
||||
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
|
||||
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
|
||||
* SAVINGS OR PROFITS,
|
||||
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
|
||||
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
|
||||
* FROM, THE SOFTWARE.
|
||||
*
|
||||
* This software may be replicated in part or whole for the licensed use,
|
||||
* with the restriction that this Disclaimer and Copyright notice must be
|
||||
* included with each copy of this software, whether used in part or whole,
|
||||
* at all times.
|
||||
*/
|
||||
/******************************************************************************/
|
||||
/** \file lvd.c
|
||||
**
|
||||
** Low Voltage Detect driver API.
|
||||
** @link Lvd Group Some description @endlink
|
||||
**
|
||||
** - 2017-06-28 Alex First Version
|
||||
**
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* Include files
|
||||
******************************************************************************/
|
||||
#include "lvd.h"
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \addtogroup LvdGroup
|
||||
******************************************************************************/
|
||||
//@{
|
||||
|
||||
/******************************************************************************
|
||||
* Local pre-processor symbols/macros ('#define')
|
||||
******************************************************************************/
|
||||
|
||||
#define IS_VALID_INPUT(x) ( (x) <= LvdInputPB07 )
|
||||
|
||||
#define IS_VALID_THRESHOLD(x) ( (x) <= LvdTH3p3V )
|
||||
|
||||
#define IS_VALID_FILTER(x) ( (x) <= LvdFilter29ms )
|
||||
|
||||
#define IS_VALID_IRQTYPE(x) ( (x) <= LvdIrqFall )
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* Global variable definitions (declared in header file with 'extern') *
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* Local type definitions ('typedef')
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* Local function prototypes ('static')
|
||||
******************************************************************************/
|
||||
// static void LvdEnableNvic(void);
|
||||
// static void LvdDisableNvic(void);
|
||||
// static en_result_t LvdEnable(en_lvd_type_t enType, boolean_t bFlag);
|
||||
|
||||
/******************************************************************************
|
||||
* Local variable definitions ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* Function implementation - global ('extern') and local ('static')
|
||||
*****************************************************************************/
|
||||
/**
|
||||
* \brief
|
||||
* 使能LVD中断
|
||||
*
|
||||
* \param [in] enType LVD中断类型
|
||||
*
|
||||
* \retval en_result_t Ok: 设置成功
|
||||
* \retval en_result_t ErrorInvalidParameter: 无效类型
|
||||
*/
|
||||
void Lvd_EnableIrq(void)
|
||||
{
|
||||
M0P_LVD->CR_f.IE = TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief
|
||||
* 除能LVD中断
|
||||
*
|
||||
* \param 无
|
||||
*
|
||||
* \retval 无
|
||||
*/
|
||||
void Lvd_DisableIrq(void)
|
||||
{
|
||||
M0P_LVD->CR_f.IE = FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief
|
||||
* LVD初始化
|
||||
*
|
||||
* \param [in] pstcCfg LVD配置指针
|
||||
*
|
||||
* \retval 无
|
||||
*/
|
||||
void Lvd_Init(stc_lvd_cfg_t *pstcCfg)
|
||||
{
|
||||
M0P_LVD->CR = 0;
|
||||
|
||||
M0P_LVD->CR = (uint32_t)pstcCfg->enAct |
|
||||
(uint32_t)pstcCfg->enFilter |
|
||||
(uint32_t)pstcCfg->enFilterTime |
|
||||
(uint32_t)pstcCfg->enInputSrc |
|
||||
(uint32_t)pstcCfg->enIrqType |
|
||||
(uint32_t)pstcCfg->enThreshold;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief
|
||||
* 使能LVD
|
||||
*
|
||||
* \param 无
|
||||
*
|
||||
* \retval 无
|
||||
*
|
||||
*/
|
||||
void Lvd_Enable(void)
|
||||
{
|
||||
M0P_LVD->CR_f.LVDEN = 1u;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief
|
||||
* 除能LVD
|
||||
*
|
||||
* \param 无
|
||||
*
|
||||
* \retval 无
|
||||
*/
|
||||
void Lvd_Disable(void)
|
||||
{
|
||||
M0P_LVD->CR_f.LVDEN = 0u;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief
|
||||
* 获取LVD中断标志
|
||||
*
|
||||
* \param 无
|
||||
*
|
||||
* \retval boolean_t 中断标志
|
||||
*/
|
||||
boolean_t Lvd_GetIrqStat(void)
|
||||
{
|
||||
return M0P_LVD->IFR_f.INTF;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief
|
||||
* 清除LVD中断标志
|
||||
*
|
||||
* \param 无
|
||||
*
|
||||
* \retval 无
|
||||
*/
|
||||
void Lvd_ClearIrq(void)
|
||||
{
|
||||
M0P_LVD->IFR_f.INTF = 0u;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief
|
||||
* 获取Filter结果
|
||||
*
|
||||
* \param 无
|
||||
*
|
||||
* \retval boolean_t Fliter结果
|
||||
*/
|
||||
boolean_t Lvd_GetFilterResult(void)
|
||||
{
|
||||
return (boolean_t)M0P_LVD->IFR_f.FILTER;
|
||||
}
|
||||
//@} // LvdGroup
|
||||
|
||||
/******************************************************************************
|
||||
* EOF (not truncated)
|
||||
******************************************************************************/
|
||||
|
||||
@@ -0,0 +1,153 @@
|
||||
/******************************************************************************
|
||||
* Copyright (C) 2019, Huada Semiconductor Co.,Ltd All rights reserved.
|
||||
*
|
||||
* This software is owned and published by:
|
||||
* Huada Semiconductor Co.,Ltd ("HDSC").
|
||||
*
|
||||
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
|
||||
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
|
||||
*
|
||||
* This software contains source code for use with HDSC
|
||||
* components. This software is licensed by HDSC to be adapted only
|
||||
* for use in systems utilizing HDSC components. HDSC shall not be
|
||||
* responsible for misuse or illegal use of this software for devices not
|
||||
* supported herein. HDSC is providing this software "AS IS" and will
|
||||
* not be responsible for issues arising from incorrect user implementation
|
||||
* of the software.
|
||||
*
|
||||
* Disclaimer:
|
||||
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
|
||||
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
|
||||
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
|
||||
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
|
||||
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
|
||||
* WARRANTY OF NONINFRINGEMENT.
|
||||
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
|
||||
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
|
||||
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
|
||||
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
|
||||
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
|
||||
* SAVINGS OR PROFITS,
|
||||
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
|
||||
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
|
||||
* FROM, THE SOFTWARE.
|
||||
*
|
||||
* This software may be replicated in part or whole for the licensed use,
|
||||
* with the restriction that this Disclaimer and Copyright notice must be
|
||||
* included with each copy of this software, whether used in part or whole,
|
||||
* at all times.
|
||||
*/
|
||||
/******************************************************************************/
|
||||
/** \file opa.c
|
||||
**
|
||||
** opa driver API.
|
||||
** @link opa Group Some description @endlink
|
||||
**
|
||||
** - 2019-04-11 First Version
|
||||
**
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* Include files
|
||||
******************************************************************************/
|
||||
#include "opa.h"
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \addtogroup OPAGroup
|
||||
******************************************************************************/
|
||||
//@{
|
||||
|
||||
/******************************************************************************
|
||||
* Local pre-processor symbols/macros ('#define')
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* Global variable definitions (declared in header file with 'extern')
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* Local type definitions ('typedef')
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* Local function prototypes ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* Local variable definitions ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* Function implementation - global ('extern') and local ('static')
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief OPA 通道使能
|
||||
**
|
||||
** \param NewStatus : TRUE FALSE
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Opa_Cmd(boolean_t NewStatus)
|
||||
{
|
||||
SetBit((uint32_t)(&(M0P_OPA->CR0)), 0, NewStatus);
|
||||
}
|
||||
|
||||
void Opa_CmdBuf(boolean_t NewStatus)
|
||||
{
|
||||
SetBit((uint32_t)(&(M0P_OPA->CR0)), 2, NewStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief OPA零点校准配置
|
||||
**
|
||||
** \param InitZero :
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Opa_SetZero(stc_opa_zcfg_t* InitZero)
|
||||
{
|
||||
M0P_OPA->CR0_f.AZEN = InitZero->bAzen;
|
||||
M0P_OPA->CR1_f.CLK_SW_SET = InitZero->bClk_sw_set;
|
||||
M0P_OPA->CR1_f.AZ_PULSE = InitZero->bAz_pulse;
|
||||
M0P_OPA->CR1_f.TRIGGER = InitZero->bTrigger;
|
||||
M0P_OPA->CR1_f.ADCTR_EN = InitZero->bAdctr_en;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief 使能输出OUTX
|
||||
**
|
||||
** \param onex : en_opa_oenx_t定义的元素
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Opa_CmdOnex(en_opa_oenx_t onex, boolean_t NewState)
|
||||
{
|
||||
SetBit((uint32_t)(&(M0P_OPA->CR0)), onex, NewState); //使能OP3输出X使能
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief 配置校零相关的位
|
||||
**
|
||||
** \param CtrlBit : en_opa_set0ctrl_t定义的元素
|
||||
** \param NewState: TRUE 或 FALSE
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Opa_ZeroBitCtrl(en_opa_set0ctrl_t CtrlBit, boolean_t NewState)
|
||||
{
|
||||
SetBit((uint32_t)(&(M0P_OPA->CR1)), CtrlBit, NewState);
|
||||
}
|
||||
/******************************************************************************
|
||||
* EOF (not truncated)
|
||||
******************************************************************************/
|
||||
|
||||
@@ -0,0 +1,555 @@
|
||||
/******************************************************************************
|
||||
* Copyright (C) 2019, Huada Semiconductor Co.,Ltd All rights reserved.
|
||||
*
|
||||
* This software is owned and published by:
|
||||
* Huada Semiconductor Co.,Ltd ("HDSC").
|
||||
*
|
||||
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
|
||||
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
|
||||
*
|
||||
* This software contains source code for use with HDSC
|
||||
* components. This software is licensed by HDSC to be adapted only
|
||||
* for use in systems utilizing HDSC components. HDSC shall not be
|
||||
* responsible for misuse or illegal use of this software for devices not
|
||||
* supported herein. HDSC is providing this software "AS IS" and will
|
||||
* not be responsible for issues arising from incorrect user implementation
|
||||
* of the software.
|
||||
*
|
||||
* Disclaimer:
|
||||
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
|
||||
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
|
||||
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
|
||||
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
|
||||
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
|
||||
* WARRANTY OF NONINFRINGEMENT.
|
||||
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
|
||||
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
|
||||
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
|
||||
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
|
||||
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
|
||||
* SAVINGS OR PROFITS,
|
||||
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
|
||||
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
|
||||
* FROM, THE SOFTWARE.
|
||||
*
|
||||
* This software may be replicated in part or whole for the licensed use,
|
||||
* with the restriction that this Disclaimer and Copyright notice must be
|
||||
* included with each copy of this software, whether used in part or whole,
|
||||
* at all times.
|
||||
*/
|
||||
/******************************************************************************/
|
||||
/** \file pca.c
|
||||
**
|
||||
** pca driver API.
|
||||
** @link pcnt Group Some description @endlink
|
||||
**
|
||||
** - 2019-04-09 First Version
|
||||
**
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* Include files
|
||||
******************************************************************************/
|
||||
#include "pca.h"
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \addtogroup PCNTGroup
|
||||
******************************************************************************/
|
||||
//@{
|
||||
|
||||
/******************************************************************************
|
||||
* Local pre-processor symbols/macros ('#define')
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* Global variable definitions (declared in header file with 'extern')
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* Local type definitions ('typedef')
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* Local function prototypes ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* Local variable definitions ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief 获取中断源的标志位
|
||||
** @param IT_Src : 中断源标志位
|
||||
** \retval FALSE 或TRUE
|
||||
**
|
||||
******************************************************************************/
|
||||
boolean_t Pca_GetItStatus(en_pca_ccficlr_t It_Src)
|
||||
{
|
||||
return (((M0P_PCA->CCON)>>It_Src) & 1) > 0? TRUE : FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief 清除中断源的标志位
|
||||
** @param IT_Src : 中断源标志位
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Pca_ClrItStatus(en_pca_ccficlr_t It_Src)
|
||||
{
|
||||
M0P_PCA->ICLR &= ~(uint32_t)(1<<It_Src);
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief PCA 计数器运行控制 PCA_CCON CR控制位
|
||||
** @param NewStatus : TRUE 或 FALSE
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Pca_StartPca(boolean_t NewStatus)
|
||||
{
|
||||
SetBit((uint32_t)(&(M0P_PCA->CCON)), 6, NewStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief PCA 空闲模式IDLE下,PCA是否停止工作设置
|
||||
** @param NewStatus : TRUE 或 FALSE
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Pca_SetCidl(boolean_t NewStatus)
|
||||
{
|
||||
SetBit((uint32_t)(&(M0P_PCA->CMOD)), 7, NewStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief PCA 模块4的看门狗使能控制
|
||||
** @param NewStatus : TRUE 或 FALSE
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Pca_Set4Wdte(boolean_t NewStatus)
|
||||
{
|
||||
SetBit((uint32_t)(&(M0P_PCA->CMOD)), 6, NewStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief PCA 计数器中断控制PCA_CMOD中CFIE,对应的控制中断位PCA_CCON中的CF与PCA_ICLR中的CF
|
||||
** @param NewStatus : TRUE 或 FALSE
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Pca_ConfPcaIt(boolean_t NewStatus)
|
||||
{
|
||||
SetBit((uint32_t)(&(M0P_PCA->CMOD)), 0, NewStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief PCA 比较捕获中断使能控制 PCA_CCAPMx的CCIE
|
||||
** @param Modulex : pca_module0~4
|
||||
** @param NewStatus : TRUE 或 FALSE
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Pca_ConfModulexIt(en_pca_module_t Modulex, boolean_t NewStatus)
|
||||
{
|
||||
switch(Modulex)
|
||||
{
|
||||
case PcaModule0:
|
||||
SetBit((uint32_t)(&(M0P_PCA->CCAPM0)), 0, NewStatus);
|
||||
break;
|
||||
case PcaModule1:
|
||||
SetBit((uint32_t)(&(M0P_PCA->CCAPM1)), 0, NewStatus);
|
||||
break;
|
||||
case PcaModule2:
|
||||
SetBit((uint32_t)(&(M0P_PCA->CCAPM2)), 0, NewStatus);
|
||||
break;
|
||||
case PcaModule3:
|
||||
SetBit((uint32_t)(&(M0P_PCA->CCAPM3)), 0, NewStatus);
|
||||
break;
|
||||
case PcaModule4:
|
||||
SetBit((uint32_t)(&(M0P_PCA->CCAPM4)), 0, NewStatus);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief PCA 模块0的初始化
|
||||
** @param InitStruct : PCA初始化配置的结构体
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Pca_M0Init(stc_pcacfg_t* InitStruct)
|
||||
{
|
||||
M0P_PCA->CMOD_f.CPS = InitStruct->pca_clksrc;
|
||||
M0P_PCA->CMOD_f.CIDL = InitStruct->pca_cidl;
|
||||
M0P_PCA->CCAPM0_f.ECOM = InitStruct->pca_ecom;
|
||||
M0P_PCA->CCAPM0_f.CAPP = InitStruct->pca_capp;
|
||||
M0P_PCA->CCAPM0_f.CAPN = InitStruct->pca_capn;
|
||||
M0P_PCA->CCAPM0_f.MAT = InitStruct->pca_mat;
|
||||
M0P_PCA->CCAPM0_f.TOG = InitStruct->pca_tog;
|
||||
M0P_PCA->CCAPM0_f.PWM = InitStruct->pca_pwm;
|
||||
M0P_PCA->EPWM_f.EPWM = InitStruct->pca_epwm;
|
||||
if(InitStruct->pca_pwm == PcaPwm8bitEnable)
|
||||
{
|
||||
M0P_PCA->CCAP0L_f.CCAP0 = InitStruct->pca_ccapl;
|
||||
M0P_PCA->CCAP0H_f.CCAP0 = InitStruct->pca_ccaph;
|
||||
}
|
||||
else
|
||||
{
|
||||
M0P_PCA->CCAP0_f.CCAP0 = InitStruct->pca_ccap;
|
||||
}
|
||||
M0P_PCA->CARR_f.CARR = InitStruct->pca_carr;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief PCA 模块1的初始化
|
||||
** @param InitStruct : PCA初始化配置的结构体
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Pca_M1Init(stc_pcacfg_t* InitStruct)
|
||||
{
|
||||
M0P_PCA->CMOD_f.CPS = InitStruct->pca_clksrc;
|
||||
M0P_PCA->CMOD_f.CIDL = InitStruct->pca_cidl;
|
||||
M0P_PCA->CCAPM1_f.ECOM = InitStruct->pca_ecom;
|
||||
M0P_PCA->CCAPM1_f.CAPP = InitStruct->pca_capp;
|
||||
M0P_PCA->CCAPM1_f.CAPN = InitStruct->pca_capn;
|
||||
M0P_PCA->CCAPM1_f.MAT = InitStruct->pca_mat;
|
||||
M0P_PCA->CCAPM1_f.TOG = InitStruct->pca_tog;
|
||||
M0P_PCA->CCAPM1_f.PWM = InitStruct->pca_pwm;
|
||||
M0P_PCA->EPWM_f.EPWM = InitStruct->pca_epwm;
|
||||
if(InitStruct->pca_pwm == PcaPwm8bitEnable)
|
||||
{
|
||||
M0P_PCA->CCAP1L_f.CCAP1 = InitStruct->pca_ccapl;
|
||||
M0P_PCA->CCAP1H_f.CCAP1 = InitStruct->pca_ccaph;
|
||||
}
|
||||
else
|
||||
{
|
||||
M0P_PCA->CCAP1_f.CCAP1 = InitStruct->pca_ccap;
|
||||
}
|
||||
M0P_PCA->CARR_f.CARR = InitStruct->pca_carr;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief PCA 模块2的初始化
|
||||
** @param InitStruct : PCA初始化配置的结构体
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Pca_M2Init(stc_pcacfg_t* InitStruct)
|
||||
{
|
||||
M0P_PCA->CMOD_f.CPS = InitStruct->pca_clksrc;
|
||||
M0P_PCA->CMOD_f.CIDL = InitStruct->pca_cidl;
|
||||
M0P_PCA->CCAPM2_f.ECOM = InitStruct->pca_ecom;
|
||||
M0P_PCA->CCAPM2_f.CAPP = InitStruct->pca_capp;
|
||||
M0P_PCA->CCAPM2_f.CAPN = InitStruct->pca_capn;
|
||||
M0P_PCA->CCAPM2_f.MAT = InitStruct->pca_mat;
|
||||
M0P_PCA->CCAPM2_f.TOG = InitStruct->pca_tog;
|
||||
M0P_PCA->CCAPM2_f.PWM = InitStruct->pca_pwm;
|
||||
M0P_PCA->EPWM_f.EPWM = InitStruct->pca_epwm;
|
||||
if(InitStruct->pca_pwm == PcaPwm8bitEnable)
|
||||
{
|
||||
M0P_PCA->CCAP2L_f.CCAP2 = InitStruct->pca_ccapl;
|
||||
M0P_PCA->CCAP2H_f.CCAP2 = InitStruct->pca_ccaph;
|
||||
}
|
||||
else
|
||||
{
|
||||
M0P_PCA->CCAP2_f.CCAP2 = InitStruct->pca_ccap;
|
||||
}
|
||||
M0P_PCA->CARR_f.CARR = InitStruct->pca_carr;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief PCA 模块3的初始化
|
||||
** @param InitStruct : PCA初始化配置的结构体
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Pca_M3Init(stc_pcacfg_t* InitStruct)
|
||||
{
|
||||
M0P_PCA->CMOD_f.CPS = InitStruct->pca_clksrc;
|
||||
M0P_PCA->CMOD_f.CIDL = InitStruct->pca_cidl;
|
||||
M0P_PCA->CCAPM3_f.ECOM = InitStruct->pca_ecom;
|
||||
M0P_PCA->CCAPM3_f.CAPP = InitStruct->pca_capp;
|
||||
M0P_PCA->CCAPM3_f.CAPN = InitStruct->pca_capn;
|
||||
M0P_PCA->CCAPM3_f.MAT = InitStruct->pca_mat;
|
||||
M0P_PCA->CCAPM3_f.TOG = InitStruct->pca_tog;
|
||||
M0P_PCA->CCAPM3_f.PWM = InitStruct->pca_pwm;
|
||||
M0P_PCA->EPWM_f.EPWM = InitStruct->pca_epwm;
|
||||
if(InitStruct->pca_pwm == PcaPwm8bitEnable)
|
||||
{
|
||||
M0P_PCA->CCAP3L_f.CCAP3 = InitStruct->pca_ccapl;
|
||||
M0P_PCA->CCAP3H_f.CCAP3 = InitStruct->pca_ccaph;
|
||||
}
|
||||
else
|
||||
{
|
||||
M0P_PCA->CCAP3_f.CCAP3 = InitStruct->pca_ccap;
|
||||
}
|
||||
M0P_PCA->CARR_f.CARR = InitStruct->pca_carr;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief PCA 模块4的初始化
|
||||
** @param InitStruct : PCA初始化配置的结构体
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Pca_M4Init(stc_pcacfg_t* InitStruct)
|
||||
{
|
||||
M0P_PCA->CMOD_f.CPS = InitStruct->pca_clksrc;
|
||||
M0P_PCA->CMOD_f.CIDL = InitStruct->pca_cidl;
|
||||
M0P_PCA->CCAPM4_f.ECOM = InitStruct->pca_ecom;
|
||||
M0P_PCA->CCAPM4_f.CAPP = InitStruct->pca_capp;
|
||||
M0P_PCA->CCAPM4_f.CAPN = InitStruct->pca_capn;
|
||||
M0P_PCA->CCAPM4_f.MAT = InitStruct->pca_mat;
|
||||
M0P_PCA->CCAPM4_f.TOG = InitStruct->pca_tog;
|
||||
M0P_PCA->CCAPM4_f.PWM = InitStruct->pca_pwm;
|
||||
M0P_PCA->EPWM_f.EPWM = InitStruct->pca_epwm;
|
||||
if(InitStruct->pca_pwm == PcaPwm8bitEnable)
|
||||
{
|
||||
M0P_PCA->CCAP4L_f.CCAP4 = InitStruct->pca_ccapl;
|
||||
M0P_PCA->CCAP4H_f.CCAP4 = InitStruct->pca_ccaph;
|
||||
}
|
||||
else
|
||||
{
|
||||
M0P_PCA->CCAP4_f.CCAP4 = InitStruct->pca_ccap;
|
||||
}
|
||||
M0P_PCA->CARR_f.CARR = InitStruct->pca_carr;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief PCA 读取CNT寄存器的数值
|
||||
** @param 无
|
||||
** \retval CNT的低半字值
|
||||
**
|
||||
******************************************************************************/
|
||||
uint16_t Pca_GetCnt(void)
|
||||
{
|
||||
return (uint16_t)(M0P_PCA->CNT);
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief PCA 向CNT寄存器写入数值
|
||||
** @param cnt : 所要写入的数值
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Pca_SetCnt(uint16_t cnt)
|
||||
{
|
||||
if(GetBit((uint32_t)(&(M0P_PCA->CCON)), 6)==TRUE)
|
||||
{
|
||||
Pca_StartPca(FALSE);
|
||||
M0P_PCA->CNT_f.CNT = cnt;
|
||||
Pca_StartPca(TRUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
M0P_PCA->CNT_f.CNT = cnt;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief PCA 返回指定通道比较高速输出标志寄存器的值
|
||||
** @param Modulex : 通道号x=0、1、2、3、4
|
||||
** \retval TRUE 或 FALSE
|
||||
**
|
||||
******************************************************************************/
|
||||
boolean_t Pca_GetOut(en_pca_module_t Modulex)
|
||||
{
|
||||
return GetBit((uint32_t)(&(M0P_PCA->CCAPO)), Modulex);
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief PCA 设置比较捕获16位寄存器CCAPx数值
|
||||
** @param Modulex : 通道号x=0、1、2、3、4
|
||||
** @param Value: 所要设置的值
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Pca_SetCcap(en_pca_module_t Modulex, uint16_t Value)
|
||||
{
|
||||
switch(Modulex)
|
||||
{
|
||||
case 0:
|
||||
M0P_PCA->CCAP0_f.CCAP0 = Value;
|
||||
break;
|
||||
case 1:
|
||||
M0P_PCA->CCAP1_f.CCAP1 = Value;
|
||||
break;
|
||||
case 2:
|
||||
M0P_PCA->CCAP2_f.CCAP2 = Value;
|
||||
break;
|
||||
case 3:
|
||||
M0P_PCA->CCAP3_f.CCAP3 = Value;
|
||||
break;
|
||||
case 4:
|
||||
M0P_PCA->CCAP4_f.CCAP4 = Value;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief PCA 读取比较捕获16位寄存器CCAPx数值
|
||||
** @param Modulex : 通道号x=0、1、2、3、4
|
||||
** \retval CCAPx的值,x=0、1、2、3、4
|
||||
**
|
||||
******************************************************************************/
|
||||
uint16_t Pca_GetCcap(en_pca_module_t Modulex)
|
||||
{
|
||||
uint16_t tmp;
|
||||
switch(Modulex)
|
||||
{
|
||||
case 0:
|
||||
tmp = M0P_PCA->CCAP0_f.CCAP0;
|
||||
break;
|
||||
case 1:
|
||||
tmp = M0P_PCA->CCAP1_f.CCAP1;
|
||||
break;
|
||||
case 2:
|
||||
tmp = M0P_PCA->CCAP2_f.CCAP2;
|
||||
break;
|
||||
case 3:
|
||||
tmp = M0P_PCA->CCAP3_f.CCAP3;
|
||||
break;
|
||||
case 4:
|
||||
tmp = M0P_PCA->CCAP4_f.CCAP4;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief PCA 设置自动重装载寄存器数值
|
||||
** @param 无
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Pca_SetCarr(uint16_t Value)
|
||||
{
|
||||
M0P_PCA->CARR_f.CARR = Value;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief PCA 获取自动重装载寄存器数值
|
||||
** @param 无
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
uint16_t Pca_GetCarr(void)
|
||||
{
|
||||
return M0P_PCA->CARR_f.CARR;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief PCA 设置比较捕获寄存器的高8位和低8位
|
||||
** @param Modulex : 通道号x=0、1、2、3、4
|
||||
** @param ValueH : 要写入高8位的数值
|
||||
** @param ValueL : 要写入低8位的数值
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Pca_SetCcapHL(en_pca_module_t Modulex, uint8_t ValueH, uint8_t ValueL)
|
||||
{
|
||||
switch(Modulex)
|
||||
{
|
||||
case 0:
|
||||
M0P_PCA->CCAP0H_f.CCAP0 = ValueH;
|
||||
M0P_PCA->CCAP0L_f.CCAP0 = ValueL;
|
||||
break;
|
||||
case 1:
|
||||
M0P_PCA->CCAP1H_f.CCAP1 = ValueH;
|
||||
M0P_PCA->CCAP1L_f.CCAP1 = ValueL;
|
||||
break;
|
||||
case 2:
|
||||
M0P_PCA->CCAP2H_f.CCAP2 = ValueH;
|
||||
M0P_PCA->CCAP2L_f.CCAP2 = ValueL;
|
||||
break;
|
||||
case 3:
|
||||
M0P_PCA->CCAP3H_f.CCAP3 = ValueH;
|
||||
M0P_PCA->CCAP3L_f.CCAP3 = ValueL;
|
||||
break;
|
||||
case 4:
|
||||
M0P_PCA->CCAP4H_f.CCAP4 = ValueH;
|
||||
M0P_PCA->CCAP4L_f.CCAP4 = ValueL;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief PCA 读取比较捕获寄存器的高8位和低8位
|
||||
** @param Modulex : 通道号x=0、1、2、3、4
|
||||
** @param ValueH : CCAPx高8位的数值
|
||||
** @param ValueL : CCAPx低8位的数值
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Pca_GetCcapHL(en_pca_module_t Modulex, uint8_t *ValueH, uint8_t *ValueL)
|
||||
{
|
||||
switch(Modulex)
|
||||
{
|
||||
case 0:
|
||||
*ValueH = M0P_PCA->CCAP0H_f.CCAP0;
|
||||
*ValueL = M0P_PCA->CCAP0L_f.CCAP0;
|
||||
break;
|
||||
case 1:
|
||||
*ValueH = M0P_PCA->CCAP1H_f.CCAP1;
|
||||
*ValueL = M0P_PCA->CCAP1L_f.CCAP1;
|
||||
break;
|
||||
case 2:
|
||||
*ValueH = M0P_PCA->CCAP2H_f.CCAP2;
|
||||
*ValueL = M0P_PCA->CCAP2L_f.CCAP2;
|
||||
break;
|
||||
case 3:
|
||||
*ValueH = M0P_PCA->CCAP3H_f.CCAP3;
|
||||
*ValueL = M0P_PCA->CCAP3L_f.CCAP3;
|
||||
break;
|
||||
case 4:
|
||||
*ValueH = M0P_PCA->CCAP4H_f.CCAP4;
|
||||
*ValueL = M0P_PCA->CCAP4L_f.CCAP4;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
/******************************************************************************
|
||||
* EOF (not truncated)
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,316 @@
|
||||
/******************************************************************************
|
||||
* Copyright (C) 2019, Huada Semiconductor Co.,Ltd All rights reserved.
|
||||
*
|
||||
* This software is owned and published by:
|
||||
* Huada Semiconductor Co.,Ltd ("HDSC").
|
||||
*
|
||||
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
|
||||
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
|
||||
*
|
||||
* This software contains source code for use with HDSC
|
||||
* components. This software is licensed by HDSC to be adapted only
|
||||
* for use in systems utilizing HDSC components. HDSC shall not be
|
||||
* responsible for misuse or illegal use of this software for devices not
|
||||
* supported herein. HDSC is providing this software "AS IS" and will
|
||||
* not be responsible for issues arising from incorrect user implementation
|
||||
* of the software.
|
||||
*
|
||||
* Disclaimer:
|
||||
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
|
||||
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
|
||||
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
|
||||
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
|
||||
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
|
||||
* WARRANTY OF NONINFRINGEMENT.
|
||||
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
|
||||
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
|
||||
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
|
||||
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
|
||||
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
|
||||
* SAVINGS OR PROFITS,
|
||||
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
|
||||
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
|
||||
* FROM, THE SOFTWARE.
|
||||
*
|
||||
* This software may be replicated in part or whole for the licensed use,
|
||||
* with the restriction that this Disclaimer and Copyright notice must be
|
||||
* included with each copy of this software, whether used in part or whole,
|
||||
* at all times.
|
||||
*/
|
||||
/******************************************************************************/
|
||||
/** \file pcnt.c
|
||||
**
|
||||
** pcnt driver API.
|
||||
** @link pcnt Group Some description @endlink
|
||||
**
|
||||
** - 2019-04-08 First Version
|
||||
**
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* Include files
|
||||
******************************************************************************/
|
||||
#include "pcnt.h"
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \addtogroup PCNTGroup
|
||||
******************************************************************************/
|
||||
//@{
|
||||
|
||||
/******************************************************************************
|
||||
* Local pre-processor symbols/macros ('#define')
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* Global variable definitions (declared in header file with 'extern')
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* Local type definitions ('typedef')
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* Local function prototypes ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* Local variable definitions ('static')
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief PCNT的启动和停止控制
|
||||
** @param NewState : Run_Enable 或者 Run_Disable
|
||||
** @param NewState : FALSE或者TRUE
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
boolean_t Pcnt_Cmd(boolean_t NewState)
|
||||
{
|
||||
SetBit((uint32_t)(&(M0P_PCNT->RUN)), 0, NewState);
|
||||
return GetBit((uint32_t)(&(M0P_PCNT->RUN)), 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief 将BUF中的值同步到CNT
|
||||
** @param value : 要同步到TOP的数值
|
||||
** \retval ok 或 ErrorTimeout
|
||||
**
|
||||
******************************************************************************/
|
||||
en_result_t Pcnt_SetB2T(uint16_t value)
|
||||
{
|
||||
uint16_t u16TimeOut;
|
||||
|
||||
u16TimeOut = 1000;
|
||||
M0P_PCNT->BUF = value;
|
||||
M0P_PCNT->CMD_f.B2T = 1;
|
||||
|
||||
while(u16TimeOut--)
|
||||
{
|
||||
if(M0P_PCNT->SR2_f.B2T == FALSE)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(u16TimeOut == 0)
|
||||
{
|
||||
return ErrorTimeout;
|
||||
}
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief 将BUF中的值同步到CNT
|
||||
** @param value : 要同步到CNT的数值
|
||||
** \retval ok 或 ErrorTimeout
|
||||
**
|
||||
******************************************************************************/
|
||||
en_result_t Pcnt_SetB2C(uint16_t value)
|
||||
{
|
||||
uint16_t u16TimeOut;
|
||||
u16TimeOut = 1000;
|
||||
M0P_PCNT->BUF = value;
|
||||
M0P_PCNT->CMD_f.B2C = 1;
|
||||
|
||||
while(u16TimeOut--)
|
||||
{
|
||||
if(M0P_PCNT->SR2_f.B2C == FALSE)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(u16TimeOut == 0)
|
||||
{
|
||||
return ErrorTimeout;
|
||||
}
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief 将TOP中的值同步到CNT
|
||||
** @param value : 要同步到CNT的数值
|
||||
** \retval ok 或 ErrorTimeout
|
||||
**
|
||||
******************************************************************************/
|
||||
en_result_t Pcnt_SetT2C(void)
|
||||
{
|
||||
uint16_t u16TimeOut;
|
||||
u16TimeOut = 1000;
|
||||
M0P_PCNT->CMD_f.T2C = 1;
|
||||
while(u16TimeOut--)
|
||||
{
|
||||
if(M0P_PCNT->SR2_f.T2C == FALSE)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(u16TimeOut == 0)
|
||||
{
|
||||
return ErrorTimeout;
|
||||
}
|
||||
return Ok;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief 赋值BUF
|
||||
** @param value : 要赋值给BUF的数值
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Pcnt_SetBuf(uint16_t value)
|
||||
{
|
||||
M0P_PCNT->TOP_f.TOP = value;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief 初始化
|
||||
** @param start : 要同步到TOP的数值
|
||||
** @param end : 要同步到CNT的数值
|
||||
** \retval ok 或 ErrorTimeout
|
||||
**
|
||||
******************************************************************************/
|
||||
void Pcnt_Init(stc_pcnt_initstruct_t* InitStruct)
|
||||
{
|
||||
M0P_PCNT->CTRL_f.S1P = InitStruct->Pcnt_S1Sel;
|
||||
M0P_PCNT->CTRL_f.S0P = InitStruct->Pcnt_S0Sel;
|
||||
M0P_PCNT->CTRL_f.CLKSEL = InitStruct->Pcnt_Clk;
|
||||
M0P_PCNT->CTRL_f.MODE = InitStruct->Pcnt_Mode;
|
||||
if(InitStruct->Pcnt_Mode == PcntDoubleMode)//如果是双通道正交脉冲计数模式
|
||||
{
|
||||
M0P_PCNT->SR1_f.DIR = InitStruct->Pcnt_Dir;
|
||||
}
|
||||
else
|
||||
{
|
||||
M0P_PCNT->CTRL_f.DIR = InitStruct->Pcnt_Dir;
|
||||
}
|
||||
M0P_PCNT->FLT_f.EN = InitStruct->Pcnt_FltEn;
|
||||
M0P_PCNT->FLT_f.DEBTOP = InitStruct->Pcnt_DebTop;
|
||||
M0P_PCNT->FLT_f.CLKDIV = InitStruct->Pcnt_ClkDiv;
|
||||
M0P_PCNT->TOCR_f.EN = InitStruct->Pcnt_TocrEn;
|
||||
M0P_PCNT->TOCR_f.TH = InitStruct->Pcnt_TocrTh;
|
||||
|
||||
M0P_PCNT->DBG_f.DBG = InitStruct->Pcnt_Dbg;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief 配置中断源的使能
|
||||
** @param IT_Src : 中断源再PCNT_IEN内部的位位置
|
||||
** @param NewState : FALSE 或TRUE
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Pcnt_ItCfg(en_pcnt_itfce_t IT_Src, boolean_t NewState)
|
||||
{
|
||||
if(NewState == TRUE)
|
||||
{
|
||||
M0P_PCNT->IEN |= (uint32_t)(1<<IT_Src);
|
||||
}
|
||||
else if(NewState == FALSE)
|
||||
{
|
||||
M0P_PCNT->IEN &= ~(uint32_t)(1<<IT_Src);
|
||||
}
|
||||
else
|
||||
{
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief 获取中断源的标志位
|
||||
** @param IT_Src : 中断源标志位
|
||||
** \retval FALSE 或TRUE
|
||||
**
|
||||
******************************************************************************/
|
||||
boolean_t Pcnt_GetItStatus(en_pcnt_itfce_t IT_Src)
|
||||
{
|
||||
return ((M0P_PCNT->IFR >> IT_Src) & 1u) > 0 ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief 清除中断源的标志位
|
||||
** @param IT_Src : 中断源标志位
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Pcnt_ClrItStatus(en_pcnt_itfce_t IT_Src)
|
||||
{
|
||||
M0P_PCNT->ICR &= ~(uint32_t)(1<<(uint32_t)IT_Src);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief 获取PCNT_CNT寄存器的数值
|
||||
** @param 无
|
||||
** \retval PCNT_CNT数值
|
||||
**
|
||||
******************************************************************************/
|
||||
uint16_t Pcnt_GetCnt(void)
|
||||
{
|
||||
return (uint16_t)(M0P_PCNT->CNT);
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief 获取PCNT_TOP寄存器的数值
|
||||
** @param 无
|
||||
** \retval PCNT_TOP数值
|
||||
**
|
||||
******************************************************************************/
|
||||
uint16_t Pcnt_GetTop(void)
|
||||
{
|
||||
return (uint16_t)(M0P_PCNT->TOP);
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief 获取PCNT_BUF寄存器的数值
|
||||
** @param 无
|
||||
** \retval PCNT_BUF数值
|
||||
**
|
||||
******************************************************************************/
|
||||
uint16_t Pcnt_GetBuf(void)
|
||||
{
|
||||
return (uint16_t)(M0P_PCNT->BUF);
|
||||
}
|
||||
|
||||
//@} // Group
|
||||
/******************************************************************************
|
||||
* EOF (not truncated)
|
||||
******************************************************************************/
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
/******************************************************************************
|
||||
*Copyright(C)2018, Huada Semiconductor Co.,Ltd All rights reserved.
|
||||
*
|
||||
* This software is owned and published by:
|
||||
* Huada Semiconductor Co.,Ltd("HDSC").
|
||||
*
|
||||
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
|
||||
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
|
||||
*
|
||||
* This software contains source code for use with HDSC
|
||||
* components. This software is licensed by HDSC to be adapted only
|
||||
* for use in systems utilizing HDSC components. HDSC shall not be
|
||||
* responsible for misuse or illegal use of this software for devices not
|
||||
* supported herein. HDSC is providing this software "AS IS" and will
|
||||
* not be responsible for issues arising from incorrect user implementation
|
||||
* of the software.
|
||||
*
|
||||
* Disclaimer:
|
||||
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
|
||||
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
|
||||
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
|
||||
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
|
||||
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
|
||||
* WARRANTY OF NONINFRINGEMENT.
|
||||
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
|
||||
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
|
||||
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
|
||||
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
|
||||
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
|
||||
* SAVINGS OR PROFITS,
|
||||
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
|
||||
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
|
||||
* FROM, THE SOFTWARE.
|
||||
*
|
||||
* This software may be replicated in part or whole for the licensed use,
|
||||
* with the restriction that this Disclaimer and Copyright notice must be
|
||||
* included with each copy of this software, whether used in part or whole,
|
||||
* at all times.
|
||||
*/
|
||||
|
||||
/** \file ram.c
|
||||
**
|
||||
** Common API of ram.
|
||||
** @link RamGroup Some description @endlink
|
||||
**
|
||||
** - 2018-05-08
|
||||
**
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Include files
|
||||
******************************************************************************/
|
||||
#include "ram.h"
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \addtogroup ramGroup
|
||||
******************************************************************************/
|
||||
//@{
|
||||
|
||||
/*******************************************************************************
|
||||
* Local pre-processor symbols/macros ('#define')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Global variable definitions (declared in header file with 'extern')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Local type definitions ('typedef')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Local variable definitions ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Local function prototypes ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Function implementation - global ('extern') and local ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief Ram奇偶校验出错地址获取
|
||||
**
|
||||
**
|
||||
** \retval ERROR ADDRESS
|
||||
*****************************************************************************/
|
||||
uint32_t Ram_ErrAddrGet(void)
|
||||
{
|
||||
return M0P_RAM->ERRADDR;
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief Ram中断标志获取
|
||||
**
|
||||
**
|
||||
** \retval TRUE or FALSE
|
||||
*****************************************************************************/
|
||||
boolean_t Ram_GetIntFlag(void)
|
||||
{
|
||||
if(M0P_RAM->IFR & 0x1)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief Ram中断标志清除
|
||||
**
|
||||
**
|
||||
** \retval Null
|
||||
*****************************************************************************/
|
||||
void Ram_ClearIntFlag(void)
|
||||
{
|
||||
M0P_RAM->ICLR = 0u;
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief Ram中断使能
|
||||
**
|
||||
** \retval Null
|
||||
*****************************************************************************/
|
||||
void Ram_EnableIrq (void)
|
||||
{
|
||||
M0P_RAM->CR |= 0x2u;
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief ram中断禁止
|
||||
**
|
||||
** \retval Null
|
||||
*****************************************************************************/
|
||||
void Ram_DisableIrq(void)
|
||||
{
|
||||
M0P_RAM->CR &= 0x1;
|
||||
}
|
||||
|
||||
|
||||
//@} // RamGroup
|
||||
|
||||
/*******************************************************************************
|
||||
* EOF (not truncated)
|
||||
******************************************************************************/
|
||||
@@ -0,0 +1,184 @@
|
||||
/******************************************************************************
|
||||
*Copyright(C)2017, Huada Semiconductor Co.,Ltd All rights reserved.
|
||||
*
|
||||
* This software is owned and published by:
|
||||
* Huada Semiconductor Co.,Ltd("HDSC").
|
||||
*
|
||||
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
|
||||
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
|
||||
*
|
||||
* This software contains source code for use with HDSC
|
||||
* components. This software is licensed by HDSC to be adapted only
|
||||
* for use in systems utilizing HDSC components. HDSC shall not be
|
||||
* responsible for misuse or illegal use of this software for devices not
|
||||
* supported herein. HDSC is providing this software "AS IS" and will
|
||||
* not be responsible for issues arising from incorrect user implementation
|
||||
* of the software.
|
||||
*
|
||||
* Disclaimer:
|
||||
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
|
||||
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
|
||||
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
|
||||
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
|
||||
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
|
||||
* WARRANTY OF NONINFRINGEMENT.
|
||||
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
|
||||
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
|
||||
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
|
||||
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
|
||||
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
|
||||
* SAVINGS OR PROFITS,
|
||||
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
|
||||
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
|
||||
* FROM, THE SOFTWARE.
|
||||
*
|
||||
* This software may be replicated in part or whole for the licensed use,
|
||||
* with the restriction that this Disclaimer and Copyright notice must be
|
||||
* included with each copy of this software, whether used in part or whole,
|
||||
* at all times.
|
||||
*/
|
||||
|
||||
/** \file reset.c
|
||||
**
|
||||
** Common API of reset.
|
||||
** @link resetGroup Some description @endlink
|
||||
**
|
||||
** - 2017-05-04
|
||||
**
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Include files
|
||||
******************************************************************************/
|
||||
#include "reset.h"
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \addtogroup ResetGroup
|
||||
******************************************************************************/
|
||||
//@{
|
||||
|
||||
/*******************************************************************************
|
||||
* Local pre-processor symbols/macros ('#define')
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Global variable definitions (declared in header file with 'extern')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Local type definitions ('typedef')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Local variable definitions ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Local function prototypes ('static')
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Function implementation - global ('extern') and local ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 获取复位源类型.
|
||||
**
|
||||
** \param [out] enRstFlg @ref en_reset_flag_t
|
||||
**
|
||||
** \retval TRUE or FALSE
|
||||
******************************************************************************/
|
||||
boolean_t Reset_GetFlag(en_reset_flag_t enRstFlg)
|
||||
{
|
||||
if(M0P_RESET->RESET_FLAG&enRstFlg)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 清除复位源类型.
|
||||
**
|
||||
** \param [in] pstcFlag @ref en_reset_flag_t
|
||||
**
|
||||
** \retval Null
|
||||
******************************************************************************/
|
||||
void Reset_ClearFlag(en_reset_flag_t enRstFlg)
|
||||
{
|
||||
M0P_RESET->RESET_FLAG &= ~(uint32_t)enRstFlg;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 清除所有复位源类型.
|
||||
**
|
||||
** \param Null
|
||||
**
|
||||
** \retval Null
|
||||
******************************************************************************/
|
||||
void Reset_ClearFlagAll(void)
|
||||
{
|
||||
M0P_RESET->RESET_FLAG = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 所有模块进行一次复位.
|
||||
**
|
||||
**
|
||||
** \retval Null
|
||||
******************************************************************************/
|
||||
void Reset_RstPeripheralAll(void)
|
||||
{
|
||||
M0P_RESET->PERI_RESET0 = 0u;
|
||||
M0P_RESET->PERI_RESET0 = 0xFFFFFFFFu;
|
||||
M0P_RESET->PERI_RESET1 = 0u;
|
||||
M0P_RESET->PERI_RESET1 = 0xFFFFFFFFu;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 对外设源0模块进行一次复位.
|
||||
**
|
||||
** \param [in] enPeri @ref en_reset_peripheral0_t
|
||||
**
|
||||
** \retval Null
|
||||
******************************************************************************/
|
||||
void Reset_RstPeripheral0(en_reset_peripheral0_t enPeri)
|
||||
{
|
||||
M0P_RESET->PERI_RESET0 &= ~(uint32_t)enPeri;
|
||||
M0P_RESET->PERI_RESET0 |= (uint32_t)enPeri;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 对外设源1模块进行一次复位.
|
||||
**
|
||||
** \param [in] enPeri @ref en_reset_peripheral1_t
|
||||
**
|
||||
** \retval Null
|
||||
******************************************************************************/
|
||||
void Reset_RstPeripheral1(en_reset_peripheral1_t enPeri)
|
||||
{
|
||||
M0P_RESET->PERI_RESET1 &= ~(uint32_t)enPeri;
|
||||
M0P_RESET->PERI_RESET1 |= (uint32_t)enPeri;
|
||||
}
|
||||
|
||||
//@} // ResetGroup
|
||||
|
||||
/*******************************************************************************
|
||||
* EOF (not truncated)
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
@@ -0,0 +1,520 @@
|
||||
/*************************************************************************************
|
||||
* Copyright (C) 2019, Huada Semiconductor Co.,Ltd All rights reserved.
|
||||
*
|
||||
* This software is owned and published by:
|
||||
* Huada Semiconductor Co.,Ltd ("HDSC").
|
||||
*
|
||||
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
|
||||
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
|
||||
*
|
||||
* This software contains source code for use with HDSC
|
||||
* components. This software is licensed by HDSC to be adapted only
|
||||
* for use in systems utilizing HDSC components. HDSC shall not be
|
||||
* responsible for misuse or illegal use of this software for devices not
|
||||
* supported herein. HDSC is providing this software "AS IS" and will
|
||||
* not be responsible for issues arising from incorrect user implementation
|
||||
* of the software.
|
||||
*
|
||||
* Disclaimer:
|
||||
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
|
||||
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
|
||||
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
|
||||
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
|
||||
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
|
||||
* WARRANTY OF NONINFRINGEMENT.
|
||||
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
|
||||
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
|
||||
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
|
||||
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
|
||||
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
|
||||
* SAVINGS OR PROFITS,
|
||||
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
|
||||
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
|
||||
* FROM, THE SOFTWARE.
|
||||
*
|
||||
* This software may be replicated in part or whole for the licensed use,
|
||||
* with the restriction that this Disclaimer and Copyright notice must be
|
||||
* included with each copy of this software, whether used in part or whole,
|
||||
* at all times.
|
||||
*/
|
||||
/******************************************************************************/
|
||||
/** \file rtc.c
|
||||
**
|
||||
** RTC function driver API.
|
||||
** @link SampleGroup Some description @endlink
|
||||
**
|
||||
** - 2019-04-10 First version
|
||||
**
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
/* Include files */
|
||||
/******************************************************************************/
|
||||
#include "rtc.h"
|
||||
/**
|
||||
******************************************************************************
|
||||
** \addtogroup RtcGroup
|
||||
******************************************************************************/
|
||||
//@{
|
||||
|
||||
/******************************************************************************/
|
||||
/* Local pre-processor symbols/macros ('#define') */
|
||||
/******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
/* Local function prototypes ('const') */
|
||||
/******************************************************************************/
|
||||
const uint8_t Leap_Month_Base[] = {3,6,0,3,5,1,3,6,2,4,0,2};
|
||||
const uint8_t NonLeap_Month_Base[] = {4,0,0,3,5,1,3,6,2,4,0,2};
|
||||
const uint8_t Cnst_Month_Tbl[12]={0x31,0x28,0x31,0x30,0x31,0x30,0x31,0x31,0x30,0x31,0x30,0x31};
|
||||
/******************************************************************************/
|
||||
/* Local function prototypes ('static') */
|
||||
/******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
/* Local variable prototypes ('static') */
|
||||
/******************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* Function implementation - global ('extern') and local ('static')
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief RTC计数器的使能或停止
|
||||
**
|
||||
** @param NewState : TRUE 或 FALSE
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Rtc_Cmd(boolean_t NewState)
|
||||
{
|
||||
SetBit((uint32_t)(&(M0P_RTC->CR0)), 7, NewState);
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief RTC计数器启动等待函数,如启动RTC计数器后立即进入低功耗模式,
|
||||
** 进入低功耗模式之前需执行此函数,以确保RTC已启动完成
|
||||
**
|
||||
** @param NewState : TRUE 或 FALSE
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Rtc_StartWait(void)
|
||||
{
|
||||
M0P_RTC->CR1_f.WAIT = 1;
|
||||
while (M0P_RTC->CR1_f.WAITF != 1) //等待直到WAITF=1
|
||||
{
|
||||
;
|
||||
}
|
||||
M0P_RTC->CR1_f.WAIT = 0;
|
||||
while (M0P_RTC->CR1_f.WAITF != 0) //等待直到WAITF=0
|
||||
{
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief RTC的1Hz输出的使能或停止
|
||||
** @param pricision : RtcHz1selGeneralPricision 或 RtcHz1selHighPricision
|
||||
** @param NewState : Hz1o_Disable 或 HZ1o_Enable
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Rtc_Hz1Cmd(en_rtc_hz1sel_t pricision, boolean_t NewState)
|
||||
{
|
||||
SetBit((uint32_t)(&(M0P_RTC->CR0)), 6, pricision); //设置普通精度或者高精度1Hz输出
|
||||
SetBit((uint32_t)(&(M0P_RTC->CR0)), 5, NewState); //设置1Hz输出使能或禁止
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief 设置周期中断的类型(PRDSEL)及其所选类型的时间(PRDS或PRDX)
|
||||
**
|
||||
** @param pstCyc: 根据结构体的定义设置PRDSEL、PRDS与PRDX
|
||||
** \retval Ok、Error 或 ErrorInvalidParameter
|
||||
**
|
||||
******************************************************************************/
|
||||
en_result_t Rtc_SetCyc(stc_rtc_cyccfg_t* pstCyc)
|
||||
{
|
||||
en_result_t enRet = Error;
|
||||
M0P_RTC->CR0_f.PRDSEL = pstCyc->rtcPrdsel;
|
||||
if(pstCyc->rtcPrdsel == RtcPrds)
|
||||
{
|
||||
M0P_RTC->CR0_f.PRDS = pstCyc->rtcPrds;
|
||||
}
|
||||
else if(pstCyc->rtcPrdsel == RtcPrdx)
|
||||
{
|
||||
if(pstCyc->rtcPrdx>=64)
|
||||
{
|
||||
enRet = ErrorInvalidParameter;
|
||||
return enRet;
|
||||
}
|
||||
M0P_RTC->CR0_f.PRDX = pstCyc->rtcPrdx;
|
||||
}
|
||||
else
|
||||
{
|
||||
;
|
||||
}
|
||||
enRet = Ok;
|
||||
return enRet;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief RTC闹钟中断的使能或停止
|
||||
**
|
||||
** @param NewState : TRUE 或 FALSE
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Rtc_AlmIeCmd(boolean_t NewState)
|
||||
{
|
||||
SetBit((uint32_t)(&(M0P_RTC->CR1)), 3, 0); //清除周期中断标志位
|
||||
SetBit((uint32_t)(&(M0P_RTC->CR1)), 4, 0); //清除周期中断标志位
|
||||
SetBit((uint32_t)(&(M0P_RTC->CR1)), 6, NewState);
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief RTC闹钟的使能或停止
|
||||
**
|
||||
** @param NewState : Almen_Disable 或 Almen_Enable
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Rtc_AlmEnCmd(boolean_t NewState)
|
||||
{
|
||||
SetBit((uint32_t)(&(M0P_RTC->CR1)), 7, NewState);
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief 获取RTC闹钟中断状态位
|
||||
**
|
||||
** @param 无
|
||||
** \retval TRUE 或 FALSE
|
||||
**
|
||||
******************************************************************************/
|
||||
boolean_t Rtc_GetAlmfItStatus(void)
|
||||
{
|
||||
return GetBit((uint32_t)(&(M0P_RTC->CR1)), 4);
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief 清除RTC闹钟中断状态位
|
||||
**
|
||||
** @param 无
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Rtc_ClearAlmfItStatus(void)
|
||||
{
|
||||
SetBit((uint32_t)(&(M0P_RTC->CR1)), 4, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief 清除RTC周期中断状态位
|
||||
**
|
||||
** @param 无
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Rtc_ClearPrdfItStatus(void)
|
||||
{
|
||||
SetBit((uint32_t)(&(M0P_RTC->CR1)), 3, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief 获取RTC周期中断状态位
|
||||
**
|
||||
** @param 无
|
||||
** \retval TRUE 或 FALSE
|
||||
**
|
||||
******************************************************************************/
|
||||
boolean_t Rtc_GetPridItStatus(void)
|
||||
{
|
||||
return GetBit((uint32_t)(&(M0P_RTC->CR1)), 3);
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief 配置RTC的误差补偿寄存器
|
||||
**
|
||||
** @param CompValue:数值的范围为:32-256
|
||||
** @param NewStatus: RtcCompenDisable 或 RtcAmCompenEnable
|
||||
** \retval Ok ErrorInvalidParameter
|
||||
**
|
||||
******************************************************************************/
|
||||
en_result_t Rtc_CompCfg(uint16_t CompVlue, en_rtc_compen_t NewStatus)
|
||||
{
|
||||
en_result_t enRet = Error;
|
||||
if(CompVlue<=256)
|
||||
{
|
||||
M0P_RTC->COMPEN_f.EN = NewStatus;
|
||||
M0P_RTC->COMPEN_f.CR = CompVlue;
|
||||
}
|
||||
else
|
||||
{
|
||||
enRet = ErrorInvalidParameter;
|
||||
}
|
||||
return enRet;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief RTC根据日期计算周数
|
||||
**
|
||||
** \param pu8buf时间数据
|
||||
** \param u8limit_min最小值
|
||||
** \param u8limit_max最大值
|
||||
**
|
||||
** \retval Error 错误,Ok校验正确
|
||||
**
|
||||
******************************************************************************/
|
||||
en_result_t Check_BCD_Format(uint8_t u8data,uint8_t u8limit_min, uint8_t u8limit_max)
|
||||
{
|
||||
|
||||
if (((u8data & 0x0F) > 0x09) || ((u8data & 0xF0) > 0x90)
|
||||
||(u8data > u8limit_max) || (u8data < u8limit_min))
|
||||
{
|
||||
return Error;
|
||||
}
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief RTC 平、闰年检测
|
||||
**
|
||||
** \param u8year:年十进制低两位:0-99
|
||||
**
|
||||
** \retval 1:闰年 0:平年
|
||||
**
|
||||
******************************************************************************/
|
||||
uint8_t Rtc_CheckLeapYear(uint8_t u8year)
|
||||
{
|
||||
uint16_t tmp;
|
||||
tmp=2000+u8year;
|
||||
if((((tmp % 4)==0) && ((tmp % 100) !=0))|| ((tmp % 400) ==0))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief RTC根据年获取二月的天数
|
||||
**
|
||||
** \param [in] u8month月份,u8year年份
|
||||
**
|
||||
** \retval u8day天数:28或29
|
||||
**
|
||||
******************************************************************************/
|
||||
uint8_t Get_Month2_Day( uint8_t u8year)
|
||||
{
|
||||
uint8_t u8day = 0;
|
||||
|
||||
u8day = 28;
|
||||
if(Rtc_CheckLeapYear(u8year) == 1)
|
||||
{
|
||||
u8day++;
|
||||
}
|
||||
return u8day;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief RTC获取时间函数
|
||||
**
|
||||
** \param time: 用于存放读取自时间寄存器的时间数据,格式为BCD码格式
|
||||
**
|
||||
** \retval Ok 获取正常
|
||||
** \retval ErrorTimeout 时间溢出错误
|
||||
******************************************************************************/
|
||||
en_result_t Rtc_ReadDateTime(stc_rtc_time_t* time)
|
||||
{
|
||||
uint32_t u32TimeOut;
|
||||
ASSERT(NULL != pstcTimeDate);
|
||||
u32TimeOut = 1000;
|
||||
if(1 == M0P_RTC->CR0_f.START)
|
||||
{
|
||||
M0P_RTC->CR1_f.WAIT = 1;
|
||||
while(u32TimeOut--)
|
||||
{
|
||||
if(M0P_RTC->CR1_f.WAITF)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(u32TimeOut==0)
|
||||
{
|
||||
return ErrorTimeout;
|
||||
}
|
||||
}
|
||||
time->u8Second = M0P_RTC->SEC;
|
||||
time->u8Minute = M0P_RTC->MIN;
|
||||
if(1 == M0P_RTC->CR0_f.AMPM)
|
||||
{
|
||||
time->u8Hour = M0P_RTC->HOUR;
|
||||
}
|
||||
else
|
||||
{
|
||||
time->u8Hour = M0P_RTC->HOUR&0x1f;
|
||||
}
|
||||
time->u8Day = M0P_RTC->DAY;
|
||||
time->u8DayOfWeek = M0P_RTC->WEEK;
|
||||
time->u8Month = M0P_RTC->MON;
|
||||
time->u8Year = M0P_RTC->YEAR;
|
||||
|
||||
M0P_RTC->CR1_f.WAIT = 0;
|
||||
if(1 == M0P_RTC->CR0_f.START)
|
||||
{
|
||||
while(M0P_RTC->CR1_f.WAITF)
|
||||
{}
|
||||
}
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief 向RTC时间寄存器写入时间
|
||||
**
|
||||
** \param time: 存放时间的结构体,各个时间均为BCD码格式
|
||||
**
|
||||
** \retval ErrorTimeout 或 Ok
|
||||
**
|
||||
******************************************************************************/
|
||||
en_result_t Rtc_SetTime(stc_rtc_time_t* time)
|
||||
{
|
||||
en_result_t enRet = Ok;
|
||||
uint16_t u16TimeOut;
|
||||
u16TimeOut = 1000;
|
||||
if(M0P_RTC->CR0_f.START == 1)
|
||||
{
|
||||
M0P_RTC->CR1_f.WAIT = 1;
|
||||
while(--u16TimeOut)
|
||||
{
|
||||
if(M0P_RTC->CR1_f.WAITF)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(u16TimeOut==0)
|
||||
{
|
||||
return ErrorTimeout;
|
||||
}
|
||||
}
|
||||
M0P_RTC->SEC = time->u8Second;
|
||||
M0P_RTC->MIN = time->u8Minute;
|
||||
M0P_RTC->HOUR = time->u8Hour;
|
||||
M0P_RTC->DAY = time->u8Day;
|
||||
M0P_RTC->MON = time->u8Month;
|
||||
M0P_RTC->YEAR = time->u8Year;
|
||||
M0P_RTC->WEEK = time->u8DayOfWeek;
|
||||
|
||||
M0P_RTC->CR1_f.WAIT = 0;
|
||||
if(M0P_RTC->CR0_f.START == 1)
|
||||
{
|
||||
while(M0P_RTC->CR1_f.WAITF)
|
||||
{}
|
||||
}
|
||||
enRet = Ok;
|
||||
return enRet;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief RTC闹钟中断时间获取
|
||||
**
|
||||
** \param pstcAlarmTime:存放闹钟时间寄存器数据:秒 分 时 周
|
||||
**
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Rtc_GetAlarmTime(stc_rtc_alarmtime_t* pstcAlarmTime)
|
||||
{
|
||||
pstcAlarmTime->RtcAlarmSec = M0P_RTC->ALMSEC;
|
||||
pstcAlarmTime->RtcAlarmMinute = M0P_RTC->ALMMIN;
|
||||
pstcAlarmTime->RtcAlarmHour = M0P_RTC->ALMHOUR;
|
||||
pstcAlarmTime->RtcAlarmWeek = M0P_RTC->ALMWEEK;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief RTC闹钟设置
|
||||
**
|
||||
** \param [in] pstcAlarmTime闹钟时间:秒 分 时 周
|
||||
**
|
||||
** \retval Ok 设置正常
|
||||
**
|
||||
******************************************************************************/
|
||||
en_result_t Rtc_SetAlarmTime(stc_rtc_alarmtime_t* pstcAlarmTime)
|
||||
{
|
||||
en_result_t enRet = Ok;
|
||||
// ASSERT(NULL != pstcAlarmTime);
|
||||
Rtc_AlmEnCmd(FALSE); //闹钟禁止以后再设置闹钟时间
|
||||
enRet = Check_BCD_Format(pstcAlarmTime->RtcAlarmSec,0x00,0x59);
|
||||
if(M0P_RTC->CR0_f.AMPM == RtcAm)
|
||||
{
|
||||
enRet = Check_BCD_Format(pstcAlarmTime->RtcAlarmHour,0x00,0x12);
|
||||
}
|
||||
else
|
||||
{
|
||||
enRet = Check_BCD_Format(pstcAlarmTime->RtcAlarmHour,0x00,0x24);
|
||||
}
|
||||
if(enRet != Ok)
|
||||
{
|
||||
return enRet;
|
||||
}
|
||||
enRet = Check_BCD_Format(pstcAlarmTime->RtcAlarmMinute,0x00,0x59);
|
||||
if(enRet != Ok)
|
||||
{
|
||||
return enRet;
|
||||
}
|
||||
|
||||
if(enRet != Ok)
|
||||
{
|
||||
return enRet;
|
||||
}
|
||||
M0P_RTC->ALMSEC = pstcAlarmTime->RtcAlarmSec & 0x7f;
|
||||
M0P_RTC->ALMMIN = pstcAlarmTime->RtcAlarmMinute & 0x7f;
|
||||
M0P_RTC->ALMHOUR = pstcAlarmTime->RtcAlarmHour & 0x3f;
|
||||
M0P_RTC->ALMWEEK = pstcAlarmTime->RtcAlarmWeek;
|
||||
Rtc_AlmEnCmd(TRUE); //闹钟许可
|
||||
enRet = Ok;
|
||||
return enRet;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief 初始化RTC
|
||||
**
|
||||
** @param Rtc_InitStruct 存放stc_rtc_initstruct_t类型的结构体
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Rtc_Init(stc_rtc_initstruct_t* Rtc_InitStruct)
|
||||
{
|
||||
Rtc_Cmd(FALSE);
|
||||
M0P_RTC->CR0_f.AMPM = Rtc_InitStruct->rtcAmpm; //实时时钟小时的时制
|
||||
Rtc_SetCyc(&Rtc_InitStruct->rtcPrdsel); //设置周期中断的类型(PRDSEL)及其所选类型的时间(PRDS或PRDX)
|
||||
M0P_RTC->CR1_f.CKSEL = Rtc_InitStruct->rtcClksrc; //实时时钟RTC的时钟源
|
||||
Rtc_CompCfg(Rtc_InitStruct->rtcCompValue, Rtc_InitStruct->rtcCompen); //配置时钟误差补偿寄存器
|
||||
Rtc_SetTime(&Rtc_InitStruct->rtcTime); //设置初始时钟
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,363 @@
|
||||
/******************************************************************************
|
||||
* Copyright (C) 2016, Huada Semiconductor Co.,Ltd All rights reserved.
|
||||
*
|
||||
* This software is owned and published by:
|
||||
* Huada Semiconductor Co.,Ltd ("HDSC").
|
||||
*
|
||||
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
|
||||
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
|
||||
*
|
||||
* This software contains source code for use with HDSC
|
||||
* components. This software is licensed by HDSC to be adapted only
|
||||
* for use in systems utilizing HDSC components. HDSC shall not be
|
||||
* responsible for misuse or illegal use of this software for devices not
|
||||
* supported herein. HDSC is providing this software "AS IS" and will
|
||||
* not be responsible for issues arising from incorrect user implementation
|
||||
* of the software.
|
||||
*
|
||||
* Disclaimer:
|
||||
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
|
||||
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
|
||||
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
|
||||
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
|
||||
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
|
||||
* WARRANTY OF NONINFRINGEMENT.
|
||||
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
|
||||
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
|
||||
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
|
||||
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
|
||||
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
|
||||
* SAVINGS OR PROFITS,
|
||||
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
|
||||
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
|
||||
* FROM, THE SOFTWARE.
|
||||
*
|
||||
* This software may be replicated in part or whole for the licensed use,
|
||||
* with the restriction that this Disclaimer and Copyright notice must be
|
||||
* included with eaenCh copy of this software, whether used in part or whole,
|
||||
* at all times.
|
||||
*/
|
||||
/*****************************************************************************/
|
||||
/** \file spi.c
|
||||
**
|
||||
** SPI driver API.
|
||||
** @link Driver Group Some description @endlink
|
||||
**
|
||||
** - 2018-05-17 1.0 Devi First version for Device Driver Library of
|
||||
** Module.
|
||||
**
|
||||
*****************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* Include files
|
||||
*****************************************************************************/
|
||||
#include "spi.h"
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \addtogroup SpiGroup
|
||||
*****************************************************************************/
|
||||
//@{
|
||||
|
||||
/******************************************************************************
|
||||
* Local pre-processor symbols/macros ('#define')
|
||||
*****************************************************************************/
|
||||
|
||||
#define IS_VALID_STAT(x) ( SpiIf == (x)||\
|
||||
SpiSserr == (x)||\
|
||||
SpiBusy == (x)||\
|
||||
SpiMdf == (x)||\
|
||||
SpiTxe == (x)||\
|
||||
SpiRxne == (x))
|
||||
|
||||
|
||||
/******************************************************************************/
|
||||
/* Local function prototypes ('static') */
|
||||
/******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
/* Local variable prototypes ('static') */
|
||||
/******************************************************************************/
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief SPI 请求状态获取
|
||||
**
|
||||
** \param [in]SPIx 通道, enStatus 获取请求
|
||||
**
|
||||
** \retval 请求状态
|
||||
**
|
||||
******************************************************************************/
|
||||
boolean_t Spi_GetStatus(M0P_SPI_TypeDef* SPIx, en_spi_status_t enStatus)
|
||||
{
|
||||
ASSERT(IS_VALID_STAT(enStatus));
|
||||
|
||||
if(SPIx->STAT&enStatus)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief SPI中断清除
|
||||
**
|
||||
** \param [in]SPIx 通道选择
|
||||
**
|
||||
** \retval 请求状态
|
||||
**
|
||||
******************************************************************************/
|
||||
en_result_t Spi_ClearStatus(M0P_SPI_TypeDef* SPIx)
|
||||
{
|
||||
SPIx->ICLR = 0;
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief SPI 中断使能函数
|
||||
**
|
||||
** \param [in] SPIx 通道
|
||||
**
|
||||
** \retval Ok成功
|
||||
**
|
||||
******************************************************************************/
|
||||
en_result_t Spi_IrqEnable(M0P_SPI_TypeDef* SPIx)
|
||||
{
|
||||
SPIx->CR2 |= 0x4u;
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief SPI 中断禁止函数
|
||||
**
|
||||
** \param [in] enCh通道
|
||||
**
|
||||
** \retval Ok成功
|
||||
**
|
||||
******************************************************************************/
|
||||
en_result_t Spi_IrqDisable(M0P_SPI_TypeDef* SPIx)
|
||||
{
|
||||
SPIx->CR2 &= ~0x4u;
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief SPI 功能使能函数
|
||||
**
|
||||
** \param [in] SPIx 通道,enFunc功能
|
||||
**
|
||||
** \retval Ok初始化成功
|
||||
**
|
||||
******************************************************************************/
|
||||
en_result_t Spi_FuncEnable(M0P_SPI_TypeDef* SPIx, en_spi_func_t enFunc)
|
||||
{
|
||||
SPIx->CR2 |= enFunc;
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief SPI 功能禁止函数
|
||||
**
|
||||
** \param [in] SPIx 通道,enFunc功能
|
||||
**
|
||||
** \retval Ok初始化成功
|
||||
**
|
||||
******************************************************************************/
|
||||
en_result_t Spi_FuncDisable(M0P_SPI_TypeDef* SPIx, en_spi_func_t enFunc)
|
||||
{
|
||||
SPIx->CR2 &= ~(uint32_t)enFunc;
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief SPI 总体初始化函数
|
||||
**
|
||||
** \param [in] SPIx 通道
|
||||
** \param [in] pstcSpiCfg 初始化结构体
|
||||
**
|
||||
** \retval Ok初始化成功
|
||||
** \retval ErrorInvalidParameter 初始化错误
|
||||
******************************************************************************/
|
||||
en_result_t Spi_Init(M0P_SPI_TypeDef* SPIx, stc_spi_cfg_t *pstcSpiCfg)
|
||||
{
|
||||
ASSERT(NULL != pstcSpiCfg);
|
||||
|
||||
SPIx->CR = 0;
|
||||
|
||||
SPIx->SSN = TRUE;
|
||||
|
||||
SPIx->CR = (uint32_t)pstcSpiCfg->enSpiMode |
|
||||
(uint32_t)pstcSpiCfg->enPclkDiv |
|
||||
(uint32_t)pstcSpiCfg->enCPOL |
|
||||
(uint32_t)pstcSpiCfg->enCPHA |
|
||||
(uint32_t)0x40;
|
||||
|
||||
SPIx->STAT = 0x00;
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief SPI 配置主发送的电平
|
||||
**
|
||||
** \param [in] SPIx 通道选择,bFlag高低电平
|
||||
**
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Spi_SetCS(M0P_SPI_TypeDef* SPIx, boolean_t bFlag)
|
||||
{
|
||||
SPIx->SSN = bFlag;
|
||||
}
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief SPI 发送一字节函数
|
||||
**
|
||||
** \param [in] SPIx 通道选择,u8Data发送字节
|
||||
**
|
||||
** \retval Ok发送成功
|
||||
**
|
||||
******************************************************************************/
|
||||
en_result_t Spi_SendData(M0P_SPI_TypeDef* SPIx, uint8_t u8Data)
|
||||
{
|
||||
SPIx->DATA = u8Data;
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief SPI 读/写一字节函数
|
||||
**
|
||||
** \param [in] SPIx 通道选择
|
||||
** \param [in] u8Data 发送一字节数据
|
||||
**
|
||||
** \retval 接收一字节数据
|
||||
**
|
||||
******************************************************************************/
|
||||
uint8_t Spi_RWByte(M0P_SPI_TypeDef* SPIx, uint8_t u8Data)
|
||||
{
|
||||
uint16_t Dly = 0xffff;
|
||||
|
||||
while(FALSE == SPIx->STAT_f.TXE) {
|
||||
Dly--;
|
||||
if(Dly == 0)
|
||||
break;
|
||||
}
|
||||
Dly = 0xffff;
|
||||
SPIx->DATA = u8Data;
|
||||
while(FALSE == SPIx->STAT_f.RXNE) {
|
||||
Dly--;
|
||||
if(Dly == 0)
|
||||
break;
|
||||
}
|
||||
return SPIx->DATA;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief SPI 从机预准备第一字节数据
|
||||
**
|
||||
** \param [in] SPIx 通道选择
|
||||
** \param [in] u8Data 预准备第一字节数据
|
||||
**
|
||||
** \retval None
|
||||
**
|
||||
******************************************************************************/
|
||||
void Spi_Slave_DummyWriteData(M0P_SPI_TypeDef* SPIx, uint8_t u8Data)
|
||||
{
|
||||
while(FALSE == SPIx->STAT_f.TXE){;}
|
||||
SPIx->DATA = u8Data;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief SPI 连续发送多字节函数
|
||||
**
|
||||
** \param [in] SPIx 通道选择
|
||||
** \param [in] pu8Buf 发送数据指针
|
||||
**
|
||||
** \retval Ok发送成功
|
||||
**
|
||||
******************************************************************************/
|
||||
en_result_t Spi_SendBuf(M0P_SPI_TypeDef* SPIx, uint8_t* pu8Buf, uint32_t u32Len)
|
||||
{
|
||||
uint32_t u32Index=0;
|
||||
|
||||
for(u32Index=0; u32Index<u32Len; u32Index++)
|
||||
{
|
||||
while(FALSE == SPIx->STAT_f.TXE){;}
|
||||
SPIx->DATA = pu8Buf[u32Index];
|
||||
while(FALSE == SPIx->STAT_f.RXNE){;}
|
||||
pu8Buf[u32Index] = SPIx->DATA;
|
||||
}
|
||||
|
||||
while(FALSE == SPIx->STAT_f.TXE){;}
|
||||
while(TRUE == SPIx->STAT_f.BUSY){;}
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief SPI 接收一字节函数
|
||||
**
|
||||
** \param [in] SPIx接收通道
|
||||
**
|
||||
** \retval 接收一字节数据
|
||||
**
|
||||
******************************************************************************/
|
||||
uint8_t Spi_ReceiveData(M0P_SPI_TypeDef* SPIx)
|
||||
{
|
||||
return SPIx->DATA;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief SPI 连续接收多字节函数
|
||||
**
|
||||
** \param [in] SPIx 通道选择
|
||||
** \param [in] pu8Buf 发送数据指针
|
||||
**
|
||||
** \retval Ok发送成功
|
||||
**
|
||||
******************************************************************************/
|
||||
en_result_t Spi_ReceiveBuf(M0P_SPI_TypeDef* SPIx, uint8_t* pu8Buf, uint32_t u32Len)
|
||||
{
|
||||
uint32_t u32Index=0;
|
||||
|
||||
for(u32Index=0; u32Index<u32Len; u32Index++)
|
||||
{
|
||||
while(FALSE == SPIx->STAT_f.TXE){;}
|
||||
SPIx->DATA = 0x00;
|
||||
while(FALSE == SPIx->STAT_f.RXNE){;}
|
||||
pu8Buf[u32Index] = SPIx->DATA;
|
||||
}
|
||||
|
||||
while(TRUE == SPIx->STAT_f.BUSY){;}
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
//@} // SpiGroup
|
||||
/******************************************************************************
|
||||
* EOF (not truncated)
|
||||
*****************************************************************************/
|
||||
|
||||
@@ -0,0 +1,746 @@
|
||||
/******************************************************************************
|
||||
*Copyright(C)2018, Huada Semiconductor Co.,Ltd All rights reserved.
|
||||
*
|
||||
* This software is owned and published by:
|
||||
* Huada Semiconductor Co.,Ltd("HDSC").
|
||||
*
|
||||
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
|
||||
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
|
||||
*
|
||||
* This software contains source code for use with HDSC
|
||||
* components. This software is licensed by HDSC to be adapted only
|
||||
* for use in systems utilizing HDSC components. HDSC shall not be
|
||||
* responsible for misuse or illegal use of this software for devices not
|
||||
* supported herein. HDSC is providing this software "AS IS" and will
|
||||
* not be responsible for issues arising from incorrect user implementation
|
||||
* of the software.
|
||||
*
|
||||
* Disclaimer:
|
||||
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
|
||||
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
|
||||
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
|
||||
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
|
||||
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
|
||||
* WARRANTY OF NONINFRINGEMENT.
|
||||
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
|
||||
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
|
||||
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
|
||||
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
|
||||
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
|
||||
* SAVINGS OR PROFITS,
|
||||
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
|
||||
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
|
||||
* FROM, THE SOFTWARE.
|
||||
*
|
||||
* This software may be replicated in part or whole for the licensed use,
|
||||
* with the restriction that this Disclaimer and Copyright notice must be
|
||||
* included with each copy of this software, whether used in part or whole,
|
||||
* at all times.
|
||||
*/
|
||||
|
||||
/** \file sysctrl.c
|
||||
**
|
||||
** Common API of sysctrl.
|
||||
** @link SysctrlGroup Some description @endlink
|
||||
**
|
||||
** - 2018-04-22 Lux
|
||||
**
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Include files
|
||||
******************************************************************************/
|
||||
#include "sysctrl.h"
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \addtogroup SysctrlGroup
|
||||
******************************************************************************/
|
||||
//@{
|
||||
|
||||
/*******************************************************************************
|
||||
* Local pre-processor symbols/macros ('#define')
|
||||
******************************************************************************/
|
||||
#define CLK_TIMEOUT (1000000u)
|
||||
|
||||
#define IS_VALID_SRC(x) ( ClkRCH == (x)||\
|
||||
ClkXTH == (x)||\
|
||||
ClkRCL == (x)||\
|
||||
ClkXTL == (x) )
|
||||
|
||||
|
||||
#define IS_VALID_FUNC(x) ( ClkFuncWkupRCH == (x)||\
|
||||
ClkFuncXTHEn == (x)||\
|
||||
ClkFuncXTLEn == (x)||\
|
||||
ClkFuncXTLAWSON == (x)||\
|
||||
ClkFuncFaultEn == (x)||\
|
||||
ClkFuncRtcLPWEn == (x)||\
|
||||
ClkFuncLockUpEn == (x)||\
|
||||
ClkFuncRstPinIOEn == (x)||\
|
||||
ClkFuncSwdPinIOEn == (x) )
|
||||
|
||||
#define RC_TRIM_BASE_ADDR ((volatile uint16_t*) (0x00100C00ul))
|
||||
#define RCH_CR_TRIM_24M_VAL (*((volatile uint16_t*) (0x00100C00ul)))
|
||||
#define RCH_CR_TRIM_22_12M_VAL (*((volatile uint16_t*) (0x00100C02ul)))
|
||||
#define RCH_CR_TRIM_16M_VAL (*((volatile uint16_t*) (0x00100C04ul)))
|
||||
#define RCH_CR_TRIM_8M_VAL (*((volatile uint16_t*) (0x00100C06ul)))
|
||||
#define RCH_CR_TRIM_4M_VAL (*((volatile uint16_t*) (0x00100C08ul)))
|
||||
|
||||
#define RCL_CR_TRIM_38400_VAL (*((volatile uint16_t*) (0x00100C20ul)))
|
||||
#define RCL_CR_TRIM_32768_VAL (*((volatile uint16_t*) (0x00100C22ul)))
|
||||
|
||||
/*******************************************************************************
|
||||
* Global variable definitions (declared in header file with 'extern')
|
||||
******************************************************************************/
|
||||
extern uint32_t SystemCoreClock;
|
||||
/*******************************************************************************
|
||||
* Local type definitions ('typedef')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Local variable definitions ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Local function prototypes ('static')
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Function implementation - global ('extern') and local ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief SYSCTRL0\SYSCTRL1寄存器操作解锁
|
||||
**
|
||||
** \retval None
|
||||
******************************************************************************/
|
||||
static void _SysctrlUnlock(void)
|
||||
{
|
||||
M0P_SYSCTRL->SYSCTRL2 = 0x5A5A;
|
||||
M0P_SYSCTRL->SYSCTRL2 = 0xA5A5;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 系统时钟源使能
|
||||
** \param [in] enSource 目标时钟源
|
||||
** \param [in] bFlag 使能1-开/0-关
|
||||
** \retval Ok 设定成功
|
||||
** 其他 设定失败
|
||||
******************************************************************************/
|
||||
en_result_t Sysctrl_ClkSourceEnable(en_sysctrl_clk_source_t enSource, boolean_t bFlag)
|
||||
{
|
||||
en_result_t enRet = Ok;
|
||||
uint32_t u32Temp;
|
||||
|
||||
_SysctrlUnlock();
|
||||
bFlag = !!bFlag;
|
||||
|
||||
u32Temp = M0P_SYSCTRL->PERI_CLKEN0;
|
||||
switch (enSource)
|
||||
{
|
||||
case SysctrlClkRCH:
|
||||
M0P_SYSCTRL->SYSCTRL0_f.RCH_EN = bFlag;
|
||||
while(bFlag && (1 != M0P_SYSCTRL->RCH_CR_f.STABLE))
|
||||
{
|
||||
;
|
||||
}
|
||||
break;
|
||||
|
||||
case SysctrlClkXTH:
|
||||
M0P_SYSCTRL->PERI_CLKEN0_f.GPIO = TRUE;
|
||||
M0P_GPIO->PFADS |= 3u;
|
||||
M0P_SYSCTRL->SYSCTRL0_f.XTH_EN = bFlag;
|
||||
while(bFlag && (1 != M0P_SYSCTRL->XTH_CR_f.STABLE))
|
||||
{
|
||||
;
|
||||
}
|
||||
break;
|
||||
|
||||
case SysctrlClkRCL:
|
||||
|
||||
M0P_SYSCTRL->SYSCTRL0_f.RCL_EN = bFlag;
|
||||
while(bFlag && (1 != M0P_SYSCTRL->RCL_CR_f.STABLE))
|
||||
{
|
||||
;
|
||||
}
|
||||
break;
|
||||
|
||||
case SysctrlClkXTL:
|
||||
M0P_SYSCTRL->PERI_CLKEN0_f.GPIO = TRUE;
|
||||
M0P_GPIO->PCADS |= 0xC000;
|
||||
M0P_SYSCTRL->SYSCTRL0_f.XTL_EN = bFlag;
|
||||
while(bFlag && (1 != M0P_SYSCTRL->XTL_CR_f.STABLE))
|
||||
{
|
||||
;
|
||||
}
|
||||
break;
|
||||
|
||||
case SysctrlClkPLL:
|
||||
M0P_SYSCTRL->PERI_CLKEN0_f.ADC = TRUE;
|
||||
M0P_BGR->CR_f.BGR_EN = TRUE;
|
||||
delay10us(20);
|
||||
M0P_SYSCTRL->SYSCTRL0_f.PLL_EN = bFlag;
|
||||
while(bFlag && (1 != M0P_SYSCTRL->PLL_CR_f.STABLE))
|
||||
{
|
||||
;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
enRet = ErrorInvalidParameter;
|
||||
break;
|
||||
}
|
||||
M0P_SYSCTRL->PERI_CLKEN0 = u32Temp;
|
||||
|
||||
return enRet;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 外部高速晶振驱动配置
|
||||
** \param [in] enFreq 外部高速晶振频率范围选择
|
||||
** \param [in] enDriver 外部高速晶振驱动能力选择
|
||||
** \retval Ok 设定成功
|
||||
** 其他 设定失败
|
||||
******************************************************************************/
|
||||
en_result_t Sysctrl_XTHDriverCfg(en_sysctrl_xtal_driver_t enDriver)
|
||||
{
|
||||
en_result_t enRet = Ok;
|
||||
|
||||
M0P_SYSCTRL->XTH_CR_f.DRIVER = enDriver;
|
||||
|
||||
return enRet;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 外部低速晶振驱动配置
|
||||
** \param [in] enFreq 外部低速晶振频率范围选择
|
||||
** \param [in] enDriver 外部低速晶振驱动能力选择
|
||||
** \retval Ok 设定成功
|
||||
** 其他 设定失败
|
||||
******************************************************************************/
|
||||
en_result_t Sysctrl_XTLDriverCfg(en_sysctrl_xtl_amp_t enAmp, en_sysctrl_xtal_driver_t enDriver)
|
||||
{
|
||||
en_result_t enRet = Ok;
|
||||
|
||||
M0P_SYSCTRL->XTL_CR_f.AMP_SEL = enAmp;
|
||||
M0P_SYSCTRL->XTL_CR_f.DRIVER = enDriver;
|
||||
|
||||
return enRet;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 外部高速时钟稳定周期配置
|
||||
** \param [in] enCycle 外部高速时钟稳定周期设置
|
||||
** \retval Ok 设定成功
|
||||
** 其他 设定失败
|
||||
******************************************************************************/
|
||||
en_result_t Sysctrl_SetXTHStableTime(en_sysctrl_xth_cycle_t enCycle)
|
||||
{
|
||||
en_result_t enRet = Ok;
|
||||
M0P_SYSCTRL->XTH_CR_f.STARTUP = enCycle;
|
||||
return enRet;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 内部低速时钟稳定周期配置
|
||||
** \param [in] enCycle 内部低速时钟稳定周期设置
|
||||
** \retval Ok 设定成功
|
||||
** 其他 设定失败
|
||||
******************************************************************************/
|
||||
en_result_t Sysctrl_SetRCLStableTime(en_sysctrl_rcl_cycle_t enCycle)
|
||||
{
|
||||
en_result_t enRet = Ok;
|
||||
M0P_SYSCTRL->RCL_CR_f.STARTUP = enCycle;
|
||||
return enRet;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 外部低速时钟稳定周期配置
|
||||
** \param [in] enCycle 外部低速时钟稳定周期设置
|
||||
** \retval Ok 设定成功
|
||||
** 其他 设定失败
|
||||
******************************************************************************/
|
||||
en_result_t Sysctrl_SetXTLStableTime(en_sysctrl_xtl_cycle_t enCycle)
|
||||
{
|
||||
en_result_t enRet = Ok;
|
||||
M0P_SYSCTRL->XTL_CR_f.STARTUP = enCycle;
|
||||
return enRet;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief PLL稳定周期配置
|
||||
** \param [in] enCycle PLL稳定周期设置
|
||||
** \retval Ok 设定成功
|
||||
** 其他 设定失败
|
||||
******************************************************************************/
|
||||
en_result_t Sysctrl_SetPLLStableTime(en_sysctrl_pll_cycle_t enCycle)
|
||||
{
|
||||
en_result_t enRet = Ok;
|
||||
M0P_SYSCTRL->PLL_CR_f.STARTUP = enCycle;
|
||||
return enRet;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 时钟源切换,该函数执行后会开启新时钟源
|
||||
** \note 选择时钟源之前,需根据需要配置目标时钟源的频率/驱动参数/使能时钟源等
|
||||
** \param [in] enSource 新时钟源
|
||||
**
|
||||
** \retval Ok 设定成功
|
||||
** 其他 设定失败
|
||||
******************************************************************************/
|
||||
en_result_t Sysctrl_SysClkSwitch(en_sysctrl_clk_source_t enSource)
|
||||
{
|
||||
en_result_t enRet = Ok;
|
||||
|
||||
en_sysctrl_clk_source_t ClkNew = enSource;
|
||||
|
||||
_SysctrlUnlock();
|
||||
M0P_SYSCTRL->SYSCTRL0_f.CLKSW = ClkNew;
|
||||
|
||||
//更新Core时钟(HCLK)
|
||||
SystemCoreClockUpdate();
|
||||
|
||||
return enRet;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 获得系统时钟(HCLK)频率值
|
||||
** \retval uint32_t HCLK频率值
|
||||
**
|
||||
******************************************************************************/
|
||||
uint32_t Sysctrl_GetHClkFreq(void)
|
||||
{
|
||||
uint32_t u32Val = 0;
|
||||
const uint32_t u32hcr_tbl[] = { 4000000, 8000000, 16000000, 22120000, 24000000};
|
||||
const uint16_t u32lcr_tbl[] = { 32768, 38400};
|
||||
en_sysctrl_clk_source_t enSrc;
|
||||
uint16_t u16Trim[5] = {0};
|
||||
u16Trim[4] = RCH_CR_TRIM_24M_VAL;
|
||||
u16Trim[3] = RCH_CR_TRIM_22_12M_VAL;
|
||||
u16Trim[2] = RCH_CR_TRIM_16M_VAL;
|
||||
u16Trim[1] = RCH_CR_TRIM_8M_VAL;
|
||||
u16Trim[0] = RCL_CR_TRIM_38400_VAL;
|
||||
|
||||
//获取当前系统时钟
|
||||
enSrc = (en_sysctrl_clk_source_t)(M0P_SYSCTRL->SYSCTRL0_f.CLKSW);
|
||||
|
||||
switch (enSrc)
|
||||
{
|
||||
case SysctrlClkRCH:
|
||||
{
|
||||
|
||||
if((M0P_SYSCTRL->RCH_CR_f.TRIM) == (u16Trim[4]))
|
||||
{
|
||||
u32Val = u32hcr_tbl[4];
|
||||
}
|
||||
else if((M0P_SYSCTRL->RCH_CR_f.TRIM) == (u16Trim[3]))
|
||||
{
|
||||
u32Val = u32hcr_tbl[3];
|
||||
}
|
||||
else if((M0P_SYSCTRL->RCH_CR_f.TRIM) == (u16Trim[2]))
|
||||
{
|
||||
u32Val = u32hcr_tbl[2];
|
||||
}
|
||||
else if((M0P_SYSCTRL->RCH_CR_f.TRIM) == (u16Trim[1]))
|
||||
{
|
||||
u32Val = u32hcr_tbl[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
u32Val = u32hcr_tbl[0];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SysctrlClkXTH:
|
||||
u32Val = SYSTEM_XTH;
|
||||
break;
|
||||
case SysctrlClkRCL:
|
||||
{
|
||||
if(u16Trim[0] == (M0P_SYSCTRL->RCL_CR_f.TRIM))
|
||||
{
|
||||
u32Val = u32lcr_tbl[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
u32Val = u32lcr_tbl[0];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SysctrlClkXTL:
|
||||
u32Val = SYSTEM_XTL;
|
||||
break;
|
||||
case SysctrlClkPLL:
|
||||
{
|
||||
if (SysctrlPllRch == M0P_SYSCTRL->PLL_CR_f.REFSEL)
|
||||
{
|
||||
if(u16Trim[4] == M0P_SYSCTRL->RCH_CR_f.TRIM)
|
||||
{
|
||||
u32Val = u32hcr_tbl[4];
|
||||
}
|
||||
else if(u16Trim[3] == M0P_SYSCTRL->RCH_CR_f.TRIM)
|
||||
{
|
||||
u32Val = u32hcr_tbl[3];
|
||||
}
|
||||
else if(u16Trim[2] == M0P_SYSCTRL->RCH_CR_f.TRIM)
|
||||
{
|
||||
u32Val = u32hcr_tbl[2];
|
||||
}
|
||||
else if(u16Trim[1] == M0P_SYSCTRL->RCH_CR_f.TRIM)
|
||||
{
|
||||
u32Val = u32hcr_tbl[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
u32Val = u32hcr_tbl[0];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
u32Val = SYSTEM_XTH;
|
||||
}
|
||||
|
||||
u32Val = (u32Val * M0P_SYSCTRL->PLL_CR_f.DIVN);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
u32Val = 0u;
|
||||
break;
|
||||
}
|
||||
|
||||
u32Val = (u32Val >> M0P_SYSCTRL->SYSCTRL0_f.HCLK_PRS);
|
||||
|
||||
return u32Val;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 获得外设时钟(PCLK)频率值
|
||||
** \retval uint32_t PCLK频率值(Hz)
|
||||
**
|
||||
******************************************************************************/
|
||||
uint32_t Sysctrl_GetPClkFreq(void)
|
||||
{
|
||||
uint32_t u32Val = 0;
|
||||
|
||||
u32Val = Sysctrl_GetHClkFreq();
|
||||
u32Val = (u32Val >> (M0P_SYSCTRL->SYSCTRL0_f.PCLK_PRS));
|
||||
|
||||
return u32Val;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 时钟初始化函数
|
||||
** \param [in] pstcCfg 初始化配置参数
|
||||
** \retval Ok 设定成功
|
||||
** 其他 设定失败
|
||||
******************************************************************************/
|
||||
en_result_t Sysctrl_ClkInit(stc_sysctrl_clk_cfg_t *pstcCfg)
|
||||
{
|
||||
en_result_t enRet = Ok;
|
||||
|
||||
//系统时钟参数配置
|
||||
switch(pstcCfg->enClkSrc)
|
||||
{
|
||||
case SysctrlClkRCH:
|
||||
|
||||
break;
|
||||
case SysctrlClkXTH:
|
||||
Sysctrl_XTHDriverCfg(SysctrlXtalDriver3);
|
||||
Sysctrl_SetXTHStableTime(SysctrlXthStableCycle16384);
|
||||
break;
|
||||
case SysctrlClkRCL:
|
||||
Sysctrl_SetRCLStableTime(SysctrlRclStableCycle256);
|
||||
break;
|
||||
case SysctrlClkXTL:
|
||||
Sysctrl_XTLDriverCfg(SysctrlXtlAmp3, SysctrlXtalDriver3);
|
||||
Sysctrl_SetXTLStableTime(SysctrlXtlStableCycle16384);
|
||||
break;
|
||||
case SysctrlClkPLL:
|
||||
Sysctrl_SetPLLStableTime(SysctrlPllStableCycle16384);
|
||||
break;
|
||||
default:
|
||||
enRet = ErrorInvalidParameter;
|
||||
break;
|
||||
}
|
||||
|
||||
//时钟源使能
|
||||
Sysctrl_ClkSourceEnable(pstcCfg->enClkSrc, TRUE);
|
||||
|
||||
//时钟源切换
|
||||
Sysctrl_SysClkSwitch(pstcCfg->enClkSrc);
|
||||
|
||||
//时钟分频设置
|
||||
Sysctrl_SetHCLKDiv(pstcCfg->enHClkDiv);
|
||||
Sysctrl_SetPCLKDiv(pstcCfg->enPClkDiv);
|
||||
|
||||
return enRet;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 时钟去初始化函数
|
||||
** \param [in]
|
||||
** \retval Ok 设定成功
|
||||
** 其他 设定失败
|
||||
******************************************************************************/
|
||||
en_result_t Sysctrl_ClkDeInit(void)
|
||||
{
|
||||
en_result_t enRet = Ok;
|
||||
|
||||
//配置RCH为内部4Hz
|
||||
Sysctrl_SetRCHTrim(SysctrlRchFreq4MHz);
|
||||
|
||||
//时钟源使能
|
||||
Sysctrl_ClkSourceEnable(SysctrlClkRCH, TRUE);
|
||||
|
||||
//时钟源切换
|
||||
Sysctrl_SysClkSwitch(SysctrlClkRCH);
|
||||
|
||||
//其它时钟源使能关闭
|
||||
Sysctrl_ClkSourceEnable(SysctrlClkXTH, FALSE);
|
||||
Sysctrl_ClkSourceEnable(SysctrlClkRCL, FALSE);
|
||||
Sysctrl_ClkSourceEnable(SysctrlClkXTL, FALSE);
|
||||
Sysctrl_ClkSourceEnable(SysctrlClkPLL, FALSE);
|
||||
|
||||
//时钟分频设置
|
||||
Sysctrl_SetHCLKDiv(SysctrlHclkDiv1);
|
||||
Sysctrl_SetPCLKDiv(SysctrlPclkDiv1);
|
||||
|
||||
return enRet;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 内部高速时钟频率TRIM值加载
|
||||
** \param [in] enRCHFreq 设定的RCH目标频率值
|
||||
** \retval Ok 设定成功
|
||||
** 其他 设定失败或时钟未稳定
|
||||
******************************************************************************/
|
||||
en_result_t Sysctrl_SetRCHTrim(en_sysctrl_rch_freq_t enRCHFreq)
|
||||
{
|
||||
//加载RCH Trim值
|
||||
M0P_SYSCTRL->RCH_CR_f.TRIM = *(RC_TRIM_BASE_ADDR + enRCHFreq);
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 外部高速时钟频率范围设定
|
||||
** \param [in] enXTHFreq 设定的频率值
|
||||
** \retval Ok 设定成功
|
||||
** 其他 设定失败或时钟未稳定
|
||||
******************************************************************************/
|
||||
en_result_t Sysctrl_SetXTHFreq(en_sysctrl_xth_freq_t enXTHFreq)
|
||||
{
|
||||
en_result_t enRet = Ok;
|
||||
|
||||
M0P_SYSCTRL->XTH_CR_f.XTH_FSEL = enXTHFreq;
|
||||
|
||||
return enRet;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief PLL时钟配置
|
||||
** \param [in] pstcPLLCfg PLL配置结构体指针
|
||||
** \retval Ok 设定成功
|
||||
** 其他 设定失败或参数值不匹配
|
||||
******************************************************************************/
|
||||
en_result_t Sysctrl_SetPLLFreq(stc_sysctrl_pll_cfg_t *pstcPLLCfg)
|
||||
{
|
||||
en_result_t enRet = Ok;
|
||||
|
||||
uint16_t u16Trim[5] = {0};
|
||||
u16Trim[4] = RCH_CR_TRIM_24M_VAL;
|
||||
u16Trim[3] = RCH_CR_TRIM_22_12M_VAL;
|
||||
u16Trim[2] = RCH_CR_TRIM_16M_VAL;
|
||||
u16Trim[1] = RCH_CR_TRIM_8M_VAL;
|
||||
|
||||
////PLL最高时钟不能超过48MHz
|
||||
//RCH作为PLL输入
|
||||
if (SysctrlPllRch == pstcPLLCfg->enPllClkSrc)
|
||||
{
|
||||
if( ((u16Trim[4] == M0P_SYSCTRL->RCH_CR_f.TRIM) && (pstcPLLCfg->enPllMul > 2)) ||
|
||||
((u16Trim[3] == M0P_SYSCTRL->RCH_CR_f.TRIM) && (pstcPLLCfg->enPllMul > 2)) ||
|
||||
((u16Trim[2] == M0P_SYSCTRL->RCH_CR_f.TRIM) && (pstcPLLCfg->enPllMul > 3)) ||
|
||||
((u16Trim[1] == M0P_SYSCTRL->RCH_CR_f.TRIM) && (pstcPLLCfg->enPllMul > 6)))
|
||||
{
|
||||
return ErrorInvalidMode;
|
||||
}
|
||||
}
|
||||
else //XTH作为PLL输入
|
||||
{
|
||||
if ((SYSTEM_XTH * pstcPLLCfg->enPllMul) > 48*1000*1000)
|
||||
{
|
||||
return ErrorInvalidMode;
|
||||
}
|
||||
}
|
||||
|
||||
M0P_SYSCTRL->PLL_CR_f.FRSEL = pstcPLLCfg->enInFreq;
|
||||
M0P_SYSCTRL->PLL_CR_f.FOSC = pstcPLLCfg->enOutFreq;
|
||||
M0P_SYSCTRL->PLL_CR_f.DIVN = pstcPLLCfg->enPllMul;
|
||||
M0P_SYSCTRL->PLL_CR_f.REFSEL = pstcPLLCfg->enPllClkSrc;
|
||||
|
||||
return enRet;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 内部低速时钟频率TRIM值加载
|
||||
** \param [in] enRCLFreq 设定的RCL目标频率值
|
||||
** \retval Ok 设定成功
|
||||
** 其他 设定失败
|
||||
******************************************************************************/
|
||||
en_result_t Sysctrl_SetRCLTrim(en_sysctrl_rcl_freq_t enRCLFreq)
|
||||
{
|
||||
M0P_SYSCTRL->RCL_CR_f.TRIM = *(RC_TRIM_BASE_ADDR + enRCLFreq);
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 系统时钟(HCLK)分频设定
|
||||
** \param [in] enHCLKDiv 分频设定值
|
||||
** \retval Ok 设定成功
|
||||
** 其他 设定失败
|
||||
******************************************************************************/
|
||||
en_result_t Sysctrl_SetHCLKDiv(en_sysctrl_hclk_div_t enHCLKDiv)
|
||||
{
|
||||
_SysctrlUnlock();
|
||||
M0P_SYSCTRL->SYSCTRL0_f.HCLK_PRS = enHCLKDiv;
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 外设时钟(PCLK)分频设定
|
||||
** \param [in] enPCLKDiv 分频设定值
|
||||
** \retval Ok 设定成功
|
||||
** 其他 设定失败
|
||||
******************************************************************************/
|
||||
en_result_t Sysctrl_SetPCLKDiv(en_sysctrl_pclk_div_t enPCLKDiv)
|
||||
{
|
||||
_SysctrlUnlock();
|
||||
M0P_SYSCTRL->SYSCTRL0_f.PCLK_PRS = enPCLKDiv;
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
///<< for Sysctrl_SetPeripheralGate() & Sysctrl_GetPeripheralGate()
|
||||
static volatile boolean_t bDacPeriBac = FALSE;
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 设置外设时钟门控开关
|
||||
** \param [in] enPeripheral 目标外设
|
||||
** \param [in] bFlag 使能开关
|
||||
** \retval Ok 设定成功
|
||||
** 其他 设定失败
|
||||
******************************************************************************/
|
||||
en_result_t Sysctrl_SetPeripheralGate(en_sysctrl_peripheral_gate_t enPeripheral, boolean_t bFlag)
|
||||
{
|
||||
if(enPeripheral&0x20u)
|
||||
{
|
||||
enPeripheral &= ~0x20u;
|
||||
SetBit((uint32_t)(&(M0P_SYSCTRL->PERI_CLKEN1)), enPeripheral, bFlag);
|
||||
|
||||
if((SysctrlPeripheralDac & ~0x20u) == enPeripheral)
|
||||
{
|
||||
bDacPeriBac = bFlag;
|
||||
}
|
||||
else
|
||||
{
|
||||
SetBit((uint32_t)(&(M0P_SYSCTRL->PERI_CLKEN1)), (SysctrlPeripheralDac & ~0x20u), bDacPeriBac);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SetBit((uint32_t)(&(M0P_SYSCTRL->PERI_CLKEN0)), enPeripheral, bFlag);
|
||||
}
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 获得外设时钟门控开关状态
|
||||
** \param [in] enPeripheral 目标外设
|
||||
** \retval TRUE 开
|
||||
** FALSE 关
|
||||
******************************************************************************/
|
||||
boolean_t Sysctrl_GetPeripheralGate(en_sysctrl_peripheral_gate_t enPeripheral)
|
||||
{
|
||||
if(enPeripheral&0x20u)
|
||||
{
|
||||
if(SysctrlPeripheralDac == enPeripheral)
|
||||
{
|
||||
return bDacPeriBac;
|
||||
}
|
||||
else
|
||||
{
|
||||
enPeripheral &= ~0x20u;
|
||||
return GetBit((uint32_t)(&(M0P_SYSCTRL->PERI_CLKEN1)), enPeripheral);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
return GetBit((uint32_t)(&(M0P_SYSCTRL->PERI_CLKEN0)), enPeripheral);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 系统功能设定
|
||||
** \param [in] enFunc 系统功能枚举类型
|
||||
** \param [in] bFlag 1-开/0-关
|
||||
** \retval Ok 设定成功
|
||||
** 其他 设定失败
|
||||
******************************************************************************/
|
||||
en_result_t Sysctrl_SetFunc(en_sysctrl_func_t enFunc, boolean_t bFlag)
|
||||
{
|
||||
_SysctrlUnlock();
|
||||
SetBit((uint32_t)(&(M0P_SYSCTRL->SYSCTRL1)), enFunc, bFlag);
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief 设定RTC校准时钟频率
|
||||
** \param [in] enRtcAdj 校准频率值
|
||||
** \retval Ok 设定成功
|
||||
** 其他 设定失败
|
||||
******************************************************************************/
|
||||
en_result_t Sysctrl_SetRTCAdjustClkFreq(en_sysctrl_rtc_adjust_t enRtcAdj)
|
||||
{
|
||||
_SysctrlUnlock();
|
||||
M0P_SYSCTRL->SYSCTRL1_f.RTC_FREQ_ADJUST = enRtcAdj;
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
//@} // SysctrlGroup
|
||||
|
||||
/*******************************************************************************
|
||||
* EOF (not truncated)
|
||||
******************************************************************************/
|
||||
+1368
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,248 @@
|
||||
/******************************************************************************
|
||||
*Copyright(C)2017, Huada Semiconductor Co.,Ltd All rights reserved.
|
||||
*
|
||||
* This software is owned and published by:
|
||||
* Huada Semiconductor Co.,Ltd("HDSC").
|
||||
*
|
||||
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
|
||||
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
|
||||
*
|
||||
* This software contains source code for use with HDSC
|
||||
* components. This software is licensed by HDSC to be adapted only
|
||||
* for use in systems utilizing HDSC components. HDSC shall not be
|
||||
* responsible for misuse or illegal use of this software for devices not
|
||||
* supported herein. HDSC is providing this software "AS IS" and will
|
||||
* not be responsible for issues arising from incorrect user implementation
|
||||
* of the software.
|
||||
*
|
||||
* Disclaimer:
|
||||
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
|
||||
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
|
||||
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
|
||||
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
|
||||
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
|
||||
* WARRANTY OF NONINFRINGEMENT.
|
||||
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
|
||||
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
|
||||
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
|
||||
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
|
||||
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
|
||||
* SAVINGS OR PROFITS,
|
||||
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
|
||||
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
|
||||
* FROM, THE SOFTWARE.
|
||||
*
|
||||
* This software may be replicated in part or whole for the licensed use,
|
||||
* with the restriction that this Disclaimer and Copyright notice must be
|
||||
* included with each copy of this software, whether used in part or whole,
|
||||
* at all times.
|
||||
*/
|
||||
|
||||
/** \file trim.c
|
||||
**
|
||||
** Common API of trim.
|
||||
** @link trimGroup Some description @endlink
|
||||
**
|
||||
** - 2017-05-16
|
||||
**
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Include files
|
||||
******************************************************************************/
|
||||
#include "trim.h"
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \addtogroup TrimGroup
|
||||
******************************************************************************/
|
||||
//@{
|
||||
|
||||
/*******************************************************************************
|
||||
* Local pre-processor symbols/macros ('#define')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Global variable definitions (declared in header file with 'extern')
|
||||
******************************************************************************/
|
||||
#define IS_VALID_TRIMINT(x) (TrimStop == (x) ||\
|
||||
TrimCalCntOf == (x) ||\
|
||||
TrimXTLFault == (x) ||\
|
||||
TrimXTHFault == (x) ||\
|
||||
TrimPLLFault == (x))
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Local type definitions ('typedef')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Local variable definitions ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Local function prototypes ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Function implementation - global ('extern') and local ('static')
|
||||
******************************************************************************/
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief Trim中断标志获取
|
||||
**
|
||||
**
|
||||
** \param [in] enIntType 中断类型(RefStop、CalCntOf、XTAL32KFault、XTAL32MFault)
|
||||
**
|
||||
** \retval TRUE or FALSE
|
||||
*****************************************************************************/
|
||||
boolean_t Trim_GetIntFlag(en_trim_inttype_t enIntType)
|
||||
{
|
||||
ASSERT(IS_VALID_TRIMINT(enIntType));
|
||||
|
||||
if(M0P_CLK_TRIM->IFR&enIntType)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief Trim中断标志清除
|
||||
**
|
||||
**
|
||||
** \param [in] enIntType 中断类型(RefStop、CalCntOf、XTAL32KFault、XTAL32MFault)
|
||||
**
|
||||
** \retval Ok or Error
|
||||
*****************************************************************************/
|
||||
en_result_t Trim_ClearIntFlag(en_trim_inttype_t enIntType)
|
||||
{
|
||||
en_result_t enResult = Error;
|
||||
|
||||
ASSERT(IS_VALID_TRIMINT(enIntType));
|
||||
|
||||
M0P_CLK_TRIM->ICLR &= ~(uint32_t)enIntType;
|
||||
|
||||
return enResult;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief Trim中断使能
|
||||
**
|
||||
**
|
||||
**
|
||||
** \retval Null
|
||||
*****************************************************************************/
|
||||
void Trim_EnableIrq (void)
|
||||
{
|
||||
M0P_CLK_TRIM->CR_f.IE = TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief Trim中断禁止
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
** \retval Ok or Error
|
||||
*****************************************************************************/
|
||||
void Trim_DisableIrq(void)
|
||||
{
|
||||
M0P_CLK_TRIM->CR_f.IE = FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief Trim初始化配置
|
||||
**
|
||||
**
|
||||
** \param [in] pstcCfg Trim配置结构体指针
|
||||
**
|
||||
** \retval Ok or Error
|
||||
*****************************************************************************/
|
||||
en_result_t Trim_Init(stc_trim_cfg_t* pstcCfg)
|
||||
{
|
||||
en_result_t enResult = Error;
|
||||
|
||||
M0P_CLK_TRIM->CR = 0;
|
||||
|
||||
M0P_CLK_TRIM->CR = (uint32_t)pstcCfg->enCALCLK |
|
||||
(uint32_t)pstcCfg->enREFCLK |
|
||||
(uint32_t)pstcCfg->enMON;
|
||||
|
||||
M0P_CLK_TRIM->REFCON = pstcCfg->u32RefCon;
|
||||
M0P_CLK_TRIM->CALCON = pstcCfg->u32CalCon;
|
||||
|
||||
enResult = Ok;
|
||||
|
||||
return enResult;
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief Trim校准/监测启动运行
|
||||
**
|
||||
**
|
||||
**
|
||||
** \retval Null
|
||||
*****************************************************************************/
|
||||
void Trim_Run(void)
|
||||
{
|
||||
M0P_CLK_TRIM->CR_f.TRIM_START = TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief Trim校准/监测停止
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
** \retval Null
|
||||
*****************************************************************************/
|
||||
void Trim_Stop(void)
|
||||
{
|
||||
M0P_CLK_TRIM->CR_f.TRIM_START = FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief Trim参考计数器计数值获取
|
||||
**
|
||||
**
|
||||
** \retval u32Data 参考计数器计数值
|
||||
*****************************************************************************/
|
||||
uint32_t Trim_RefCntGet(void)
|
||||
{
|
||||
return (uint32_t)M0P_CLK_TRIM->REFCNT;
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief Trim校准计数器计数值获取
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
** \retval u32Data 校准计数器计数值
|
||||
*****************************************************************************/
|
||||
uint32_t Trim_CalCntGet(void)
|
||||
{
|
||||
return (uint32_t)M0P_CLK_TRIM->CALCNT;
|
||||
}
|
||||
|
||||
//@} // TrimGroup
|
||||
|
||||
/*******************************************************************************
|
||||
* EOF (not truncated)
|
||||
******************************************************************************/
|
||||
@@ -0,0 +1,191 @@
|
||||
/******************************************************************************
|
||||
*Copyright(C)2018, Huada Semiconductor Co.,Ltd All rights reserved.
|
||||
*
|
||||
* This software is owned and published by:
|
||||
* Huada Semiconductor Co.,Ltd("HDSC").
|
||||
*
|
||||
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
|
||||
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
|
||||
*
|
||||
* This software contains source code for use with HDSC
|
||||
* components. This software is licensed by HDSC to be adapted only
|
||||
* for use in systems utilizing HDSC components. HDSC shall not be
|
||||
* responsible for misuse or illegal use of this software for devices not
|
||||
* supported herein. HDSC is providing this software "AS IS" and will
|
||||
* not be responsible for issues arising from incorrect user implementation
|
||||
* of the software.
|
||||
*
|
||||
* Disclaimer:
|
||||
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
|
||||
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
|
||||
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
|
||||
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
|
||||
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
|
||||
* WARRANTY OF NONINFRINGEMENT.
|
||||
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
|
||||
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
|
||||
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
|
||||
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
|
||||
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
|
||||
* SAVINGS OR PROFITS,
|
||||
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
|
||||
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
|
||||
* FROM, THE SOFTWARE.
|
||||
*
|
||||
* This software may be replicated in part or whole for the licensed use,
|
||||
* with the restriction that this Disclaimer and Copyright notice must be
|
||||
* included with each copy of this software, whether used in part or whole,
|
||||
* at all times.
|
||||
*/
|
||||
|
||||
/** \file rng.c
|
||||
**
|
||||
** Common API of rng.
|
||||
** @link flashGroup Some description @endlink
|
||||
**
|
||||
** - 2018-05-08
|
||||
**
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Include files
|
||||
******************************************************************************/
|
||||
#include "trng.h"
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \addtogroup FlashGroup
|
||||
******************************************************************************/
|
||||
//@{
|
||||
|
||||
/*******************************************************************************
|
||||
* Local pre-processor symbols/macros ('#define')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Global variable definitions (declared in header file with 'extern')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Local type definitions ('typedef')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Local variable definitions ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Local function prototypes ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Function implementation - global ('extern') and local ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief 随机数初始化(上电第一次生成随机数)
|
||||
**
|
||||
**
|
||||
** \retval TRUE or FALSE
|
||||
*****************************************************************************/
|
||||
en_result_t Trng_Init(void)
|
||||
{
|
||||
//==>>生成64bits随机数(上电第一次)
|
||||
M0P_TRNG->CR_f.RNGCIR_EN = 1;
|
||||
//模式配置0
|
||||
M0P_TRNG->MODE_f.LOAD = 1;
|
||||
M0P_TRNG->MODE_f.FDBK = 1;
|
||||
M0P_TRNG->MODE_f.CNT = 6;
|
||||
//生成随机数0
|
||||
M0P_TRNG->CR_f.RNG_RUN = 1;
|
||||
while(M0P_TRNG->CR_f.RNG_RUN)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
//模式配置1
|
||||
M0P_TRNG->MODE_f.LOAD = 0;
|
||||
M0P_TRNG->MODE_f.FDBK = 0;
|
||||
M0P_TRNG->MODE_f.CNT = 4;
|
||||
//生成随机数1
|
||||
M0P_TRNG->CR_f.RNG_RUN = 1;
|
||||
while(M0P_TRNG->CR_f.RNG_RUN)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
//关闭随机源电路,节省功耗
|
||||
M0P_TRNG->CR_f.RNGCIR_EN = 0;
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief 生成随机数(非上电第一次生成随机数)
|
||||
**
|
||||
**
|
||||
** \retval TRUE or FALSE
|
||||
*****************************************************************************/
|
||||
en_result_t Trng_Generate(void)
|
||||
{
|
||||
//==>>生成64bits随机数(非上电第一次生成)
|
||||
M0P_TRNG->CR_f.RNGCIR_EN = 1;
|
||||
|
||||
//模式配置0
|
||||
M0P_TRNG->MODE_f.LOAD = 0;
|
||||
M0P_TRNG->MODE_f.FDBK = 1;
|
||||
M0P_TRNG->MODE_f.CNT = 6;
|
||||
//生成随机数0
|
||||
M0P_TRNG->CR_f.RNG_RUN = 1;
|
||||
while(M0P_TRNG->CR_f.RNG_RUN)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
//模式配置1
|
||||
M0P_TRNG->MODE_f.FDBK = 0;
|
||||
M0P_TRNG->MODE_f.CNT = 4;
|
||||
M0P_TRNG->MODE_f.CNT = 4;
|
||||
//生成随机数1
|
||||
M0P_TRNG->CR_f.RNG_RUN = 1;
|
||||
while(M0P_TRNG->CR_f.RNG_RUN)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
//关闭随机源电路,节省功耗
|
||||
M0P_TRNG->CR_f.RNGCIR_EN = 0;
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief 随机数获取
|
||||
**
|
||||
** \retval data0
|
||||
*****************************************************************************/
|
||||
uint32_t Trng_GetData0(void)
|
||||
{
|
||||
return M0P_TRNG->DATA0;
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************
|
||||
** \brief 随机数获取
|
||||
**
|
||||
** \retval data1
|
||||
*****************************************************************************/
|
||||
uint32_t Trng_GetData1(void)
|
||||
{
|
||||
return M0P_TRNG->DATA1;
|
||||
}
|
||||
|
||||
//@} // TrngGroup
|
||||
|
||||
/*******************************************************************************
|
||||
* EOF (not truncated)
|
||||
******************************************************************************/
|
||||
@@ -0,0 +1,405 @@
|
||||
/*************************************************************************************
|
||||
* Copyright (C) 2017, Huada Semiconductor Co.,Ltd All rights reserved.
|
||||
*
|
||||
* This software is owned and published by:
|
||||
* Huada Semiconductor Co.,Ltd ("HDSC").
|
||||
*
|
||||
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
|
||||
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
|
||||
*
|
||||
* This software contains source code for use with HDSC
|
||||
* components. This software is licensed by HDSC to be adapted only
|
||||
* for use in systems utilizing HDSC components. HDSC shall not be
|
||||
* responsible for misuse or illegal use of this software for devices not
|
||||
* supported herein. HDSC is providing this software "AS IS" and will
|
||||
* not be responsible for issues arising from incorrect user implementation
|
||||
* of the software.
|
||||
*
|
||||
* Disclaimer:
|
||||
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
|
||||
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
|
||||
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
|
||||
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
|
||||
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
|
||||
* WARRANTY OF NONINFRINGEMENT.
|
||||
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
|
||||
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
|
||||
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
|
||||
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
|
||||
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
|
||||
* SAVINGS OR PROFITS,
|
||||
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
|
||||
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
|
||||
* FROM, THE SOFTWARE.
|
||||
*
|
||||
* This software may be replicated in part or whole for the licensed use,
|
||||
* with the restriction that this Disclaimer and Copyright notice must be
|
||||
* included with each copy of this software, whether used in part or whole,
|
||||
* at all times.
|
||||
*/
|
||||
/******************************************************************************/
|
||||
/** \file uart.c
|
||||
**
|
||||
** UART function driver API.
|
||||
** @link SampleGroup Some description @endlink
|
||||
**
|
||||
** - 2017-05-17 1.0 CJ First version for Device Driver Library of Module.
|
||||
**
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
/* Include files */
|
||||
/******************************************************************************/
|
||||
#include "uart.h"
|
||||
/**
|
||||
******************************************************************************
|
||||
** \addtogroup UartGroup
|
||||
******************************************************************************/
|
||||
//@{
|
||||
/******************************************************************************/
|
||||
/* Local pre-processor symbols/macros ('#define') */
|
||||
/******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
/* Local function prototypes ('static') */
|
||||
/******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
/* Local variable definitions ('static') */
|
||||
/******************************************************************************/
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief UART通信中断使能函数设置
|
||||
**
|
||||
** \param [in] UARTx通道号,enIrqSel发送or接收中断使能
|
||||
**
|
||||
** \retval OK配置成功
|
||||
** \retval ErrorInvalidParameter配置失败
|
||||
******************************************************************************/
|
||||
en_result_t Uart_EnableIrq(M0P_UART_TypeDef* UARTx, en_uart_irq_sel_t enIrqSel)
|
||||
{
|
||||
SetBit((uint32_t)(&(UARTx->SCON)), enIrqSel, TRUE);
|
||||
|
||||
return Ok;
|
||||
}
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief UART通信中断禁止函数设置
|
||||
**
|
||||
** \param [in] UARTx通道号,enIrqSel发送or接收中断禁止
|
||||
**
|
||||
** \retval OK配置成功
|
||||
** \retval ErrorInvalidParameter配置失败
|
||||
******************************************************************************/
|
||||
en_result_t Uart_DisableIrq(M0P_UART_TypeDef* UARTx, en_uart_irq_sel_t enIrqSel)
|
||||
{
|
||||
SetBit((uint32_t)(&(UARTx->SCON)), enIrqSel, FALSE);
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief UART通道多主机模式配置
|
||||
**
|
||||
** \param [in] UARTx通道号,stcMultiCfg多主机模式结构
|
||||
**
|
||||
** \retval OK配置成功
|
||||
** \retval ErrorInvalidParameter配置失败
|
||||
******************************************************************************/
|
||||
en_result_t Uart_SetMultiMode(M0P_UART_TypeDef* UARTx, stc_uart_multimode_t* pstcMultiCfg)
|
||||
{
|
||||
if(NULL != pstcMultiCfg)
|
||||
{
|
||||
UARTx->SCON_f.ADRDET = TRUE;
|
||||
UARTx->SADDR = pstcMultiCfg->u8SlaveAddr;
|
||||
UARTx->SADEN = pstcMultiCfg->u8SaddEn;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
return ErrorInvalidParameter;
|
||||
}
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief UART单线半双工模式使能
|
||||
**
|
||||
** \param [in] UARTx 通道号
|
||||
**
|
||||
** \retval Null
|
||||
******************************************************************************/
|
||||
void Uart_HdModeEnable(M0P_UART_TypeDef* UARTx)
|
||||
{
|
||||
UARTx->SCON_f.HDSEL = TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief UART单线半双工模式关闭
|
||||
**
|
||||
** \param [in] UARTx 通道号
|
||||
**
|
||||
** \retval Null
|
||||
******************************************************************************/
|
||||
void Uart_HdModeDisable(M0P_UART_TypeDef* UARTx)
|
||||
{
|
||||
UARTx->SCON_f.HDSEL = FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief UART通道多机模式发送数据/地址帧配置TB8
|
||||
**
|
||||
** \param [in] UARTx 通道号
|
||||
** \param [in] TRUE-TB8为地址帧标志;FALSE-TB8为数据帧标志;
|
||||
**
|
||||
** \retval Null
|
||||
******************************************************************************/
|
||||
void Uart_SetTb8(M0P_UART_TypeDef* UARTx, boolean_t bTB8Value)
|
||||
{
|
||||
UARTx->SCON_f.B8CONT = bTB8Value;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief 获取RB8数值
|
||||
**
|
||||
** \param [in] UARTx通道号
|
||||
**
|
||||
** \retval RB8
|
||||
******************************************************************************/
|
||||
boolean_t Uart_GetRb8(M0P_UART_TypeDef* UARTx)
|
||||
{
|
||||
return (UARTx->SBUF_f.DATA8);
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief UART通道多主机模式从机地址配置函数
|
||||
**
|
||||
** \param [in] UARTx通道号,addr地址
|
||||
**
|
||||
** \retval OK配置成功
|
||||
** \retval ErrorInvalidParameter配置失败
|
||||
******************************************************************************/
|
||||
en_result_t Uart_SetSaddr(M0P_UART_TypeDef* UARTx,uint8_t u8Addr)
|
||||
{
|
||||
UARTx->SADDR = u8Addr;
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief UART通道发送或接收等功能使能设置
|
||||
**
|
||||
** \param [in] UARTx通道号,enFunc功能
|
||||
**
|
||||
** \retval OK配置成功
|
||||
** \retval ErrorInvalidParameter配置失败
|
||||
******************************************************************************/
|
||||
en_result_t Uart_EnableFunc(M0P_UART_TypeDef* UARTx, en_uart_func_t enFunc)
|
||||
{
|
||||
SetBit((uint32_t)(&(UARTx->SCON)), enFunc, TRUE);
|
||||
|
||||
return Ok;
|
||||
}
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief UART通道发送或接收等功能禁止设置
|
||||
**
|
||||
** \param [in] UARTx通道号,enFunc功能
|
||||
**
|
||||
** \retval OK配置成功
|
||||
** \retval ErrorInvalidParameter配置失败
|
||||
******************************************************************************/
|
||||
en_result_t Uart_DisableFunc(M0P_UART_TypeDef* UARTx, en_uart_func_t enFunc)
|
||||
{
|
||||
SetBit((uint32_t)(&(UARTx->SCON)), enFunc, FALSE);
|
||||
|
||||
return Ok;
|
||||
}
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief UART通道通信状态获取
|
||||
**
|
||||
** \param [in] UARTx通道号
|
||||
**
|
||||
** \retval 状态值
|
||||
******************************************************************************/
|
||||
uint8_t Uart_GetIsr(M0P_UART_TypeDef* UARTx)
|
||||
{
|
||||
return (UARTx->ISR);
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief UART通道通信状态获取
|
||||
**
|
||||
** \param [in] UARTx通道号,enStatus获取哪个状态
|
||||
**
|
||||
** \retval 状态值
|
||||
******************************************************************************/
|
||||
boolean_t Uart_GetStatus(M0P_UART_TypeDef* UARTx, en_uart_status_t enStatus)
|
||||
{
|
||||
boolean_t bStatus = FALSE;
|
||||
|
||||
|
||||
ASSERT(IS_VALID_STATUS(enStatus));
|
||||
|
||||
bStatus = GetBit((uint32_t)(&(UARTx->ISR)), enStatus);
|
||||
|
||||
return bStatus;
|
||||
}
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief UART通道通信状态清除
|
||||
**
|
||||
** \param [in] UARTx通道号
|
||||
**
|
||||
** \retval OK
|
||||
** \retval ErrorInvalidParameter清除失败
|
||||
******************************************************************************/
|
||||
en_result_t Uart_ClrIsr(M0P_UART_TypeDef* UARTx)
|
||||
{
|
||||
UARTx->ICR = 0u;
|
||||
return Ok;
|
||||
}
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief UART通道通信状态清除
|
||||
**
|
||||
** \param [in] UARTx通道号,enStatus清除哪个状态
|
||||
**
|
||||
** \retval OK
|
||||
** \retval ErrorInvalidParameter清除失败
|
||||
******************************************************************************/
|
||||
en_result_t Uart_ClrStatus(M0P_UART_TypeDef* UARTx,en_uart_status_t enStatus)
|
||||
{
|
||||
ASSERT(IS_VALID_STATUS(enStatus));
|
||||
|
||||
SetBit((uint32_t)(&(UARTx->ICR)), enStatus, FALSE);
|
||||
|
||||
return Ok;
|
||||
}
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief UART通道发送数据函数,查询方式调用此函数,中断方式发送不适用
|
||||
**
|
||||
** \param [in] UARTx通道号,Data发送数据
|
||||
**
|
||||
** \retval Ok发送成功
|
||||
** \retval ErrorInvalidParameter发送失败
|
||||
******************************************************************************/
|
||||
en_result_t Uart_SendDataPoll(M0P_UART_TypeDef* UARTx, uint8_t u8Data)
|
||||
{
|
||||
while(FALSE == Uart_GetStatus(UARTx,UartTxe))
|
||||
{}
|
||||
UARTx->SBUF_f.DATA = u8Data;
|
||||
while(FALSE == Uart_GetStatus(UARTx,UartTC))
|
||||
{}
|
||||
Uart_ClrStatus(UARTx,UartTC);
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief UART通道发送数据函数,中断方式调用此函数
|
||||
**
|
||||
** \param [in] UARTx通道号,Data发送数据
|
||||
**
|
||||
** \retval Ok发送成功
|
||||
** \retval ErrorInvalidParameter发送失败
|
||||
******************************************************************************/
|
||||
en_result_t Uart_SendDataIt(M0P_UART_TypeDef* UARTx, uint8_t u8Data)
|
||||
{
|
||||
UARTx->SBUF_f.DATA = u8Data;
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief UART通道接收数据函数
|
||||
**
|
||||
** \param [in] UARTx通道号
|
||||
**
|
||||
** \retval 接收数据
|
||||
******************************************************************************/
|
||||
uint8_t Uart_ReceiveData(M0P_UART_TypeDef* UARTx)
|
||||
{
|
||||
return (UARTx->SBUF_f.DATA);
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief UART通道初始化函数
|
||||
**
|
||||
** \param [in] UARTx通道号,pstcCfg初始化结构体 @ref stc_uart_cfg_t
|
||||
**
|
||||
** \retval OK配置成功
|
||||
** \retval ErrorInvalidParameter配置失败
|
||||
******************************************************************************/
|
||||
en_result_t Uart_Init(M0P_UART_TypeDef* UARTx, stc_uart_cfg_t* pstcCfg)
|
||||
{
|
||||
en_result_t enRet = Error;
|
||||
uint32_t u32Over[2] = {0x4, 0x3};
|
||||
uint16_t u16OverShift;
|
||||
float32_t f32Scnt=0;
|
||||
|
||||
if(NULL == pstcCfg)
|
||||
{
|
||||
return ErrorInvalidParameter;
|
||||
}
|
||||
|
||||
UARTx->SCON = 0;
|
||||
|
||||
UARTx->SCON = (uint32_t)pstcCfg->enStopBit |
|
||||
(uint32_t)pstcCfg->enMmdorCk |
|
||||
(uint32_t)pstcCfg->stcBaud.enClkDiv |
|
||||
(uint32_t)pstcCfg->enRunMode;
|
||||
|
||||
if((UartMskMode1 == pstcCfg->enRunMode) || (UartMskMode3 == pstcCfg->enRunMode))
|
||||
{
|
||||
u16OverShift = u32Over[pstcCfg->stcBaud.enClkDiv/UartMsk8Or16Div];
|
||||
f32Scnt = (float32_t)(pstcCfg->stcBaud.u32Pclk)/(float32_t)(pstcCfg->stcBaud.u32Baud<<u16OverShift);
|
||||
UARTx->SCNT = (uint16_t)(float32_t)(f32Scnt + 0.5f);
|
||||
Uart_EnableFunc(UARTx,UartRenFunc); ///<使能收发
|
||||
}
|
||||
|
||||
|
||||
|
||||
enRet = Ok;
|
||||
return enRet;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief UART发送字符串
|
||||
**
|
||||
** \param [in] UARTx通道号,SendDataString要发送的字符串
|
||||
**
|
||||
** \retval
|
||||
** \retval
|
||||
******************************************************************************/
|
||||
void USART_SendString(M0P_UART_TypeDef* USARTx,uint16_t Len, uint8_t *SendDataString)
|
||||
{
|
||||
int i = 0;
|
||||
while(i < Len) //字符串结束符
|
||||
{
|
||||
Uart_SendDataPoll(USARTx,SendDataString[i]); //每次发送字符串的一个字符
|
||||
//Uart_ClrStatus(USARTx, UartTC); //发送字符后清空标志位
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//@} // UartGroup
|
||||
+298
@@ -0,0 +1,298 @@
|
||||
/******************************************************************************
|
||||
* Copyright (C) 2019, Huada Semiconductor Co.,Ltd All rights reserved.
|
||||
*
|
||||
* This software is owned and published by:
|
||||
* Huada Semiconductor Co.,Ltd ("HDSC").
|
||||
*
|
||||
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
|
||||
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
|
||||
*
|
||||
* This software contains source code for use with HDSC
|
||||
* components. This software is licensed by HDSC to be adapted only
|
||||
* for use in systems utilizing HDSC components. HDSC shall not be
|
||||
* responsible for misuse or illegal use of this software for devices not
|
||||
* supported herein. HDSC is providing this software "AS IS" and will
|
||||
* not be responsible for issues arising from incorrect user implementation
|
||||
* of the software.
|
||||
*
|
||||
* Disclaimer:
|
||||
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
|
||||
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
|
||||
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
|
||||
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
|
||||
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
|
||||
* WARRANTY OF NONINFRINGEMENT.
|
||||
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
|
||||
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
|
||||
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
|
||||
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
|
||||
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
|
||||
* SAVINGS OR PROFITS,
|
||||
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
|
||||
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
|
||||
* FROM, THE SOFTWARE.
|
||||
*
|
||||
* This software may be replicated in part or whole for the licensed use,
|
||||
* with the restriction that this Disclaimer and Copyright notice must be
|
||||
* included with each copy of this software, whether used in part or whole,
|
||||
* at all times.
|
||||
*/
|
||||
/******************************************************************************/
|
||||
/** \file vc.c
|
||||
**
|
||||
** voltage comparator driver API.
|
||||
** @link VC Group Some description @endlink
|
||||
**
|
||||
** - 2019-04-10 First Version
|
||||
**
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* Include files
|
||||
******************************************************************************/
|
||||
#include "vc.h"
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \addtogroup VcGroup
|
||||
******************************************************************************/
|
||||
//@{
|
||||
|
||||
/******************************************************************************
|
||||
* Local pre-processor symbols/macros ('#define')
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* Global variable definitions (declared in header file with 'extern')
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* Local type definitions ('typedef')
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* Local function prototypes ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* Local variable definitions ('static')
|
||||
******************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* Function implementation - global ('extern') and local ('static')
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief 配置VC中断触发方式
|
||||
**
|
||||
** @param Channelx : VcChannelx x=0、1、2
|
||||
** @param enSel : VcIrqRise、VcIrqFall、VcIrqHigh
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Vc_CfgItType(en_vc_channel_t Channelx, en_vc_irq_sel_t ItType)
|
||||
{
|
||||
stc_vc_vc0_cr_field_t *stcVcnCr;
|
||||
switch(Channelx)
|
||||
{
|
||||
case VcChannel0:
|
||||
stcVcnCr = (stc_vc_vc0_cr_field_t*)&M0P_VC->VC0_CR_f;
|
||||
break;
|
||||
case VcChannel1:
|
||||
stcVcnCr = (stc_vc_vc0_cr_field_t*)&M0P_VC->VC1_CR_f;
|
||||
break;
|
||||
case VcChannel2:
|
||||
stcVcnCr = (stc_vc_vc0_cr_field_t*)&M0P_VC->VC2_CR_f;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
switch (ItType)
|
||||
{
|
||||
case VcIrqNone:
|
||||
stcVcnCr->RISING = 0u;
|
||||
stcVcnCr->FALLING = 0u;
|
||||
stcVcnCr->LEVEL = 0u;
|
||||
break;
|
||||
case VcIrqRise:
|
||||
stcVcnCr->RISING = 1u;
|
||||
break;
|
||||
case VcIrqFall:
|
||||
stcVcnCr->FALLING = 1u;
|
||||
break;
|
||||
case VcIrqHigh:
|
||||
stcVcnCr->LEVEL = 1u;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief VC 中断使能与禁止
|
||||
**
|
||||
** @param Channelx : VcChannelx x=0、1、2
|
||||
** @param NewStatus : TRUE 或 FALSE
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Vc_ItCfg(en_vc_channel_t Channelx, boolean_t NewStatus)
|
||||
{
|
||||
switch(Channelx)
|
||||
{
|
||||
case VcChannel0:
|
||||
SetBit((uint32_t)(&(M0P_VC->VC0_CR)), 15, NewStatus);
|
||||
break;
|
||||
case VcChannel1:
|
||||
SetBit((uint32_t)(&(M0P_VC->VC1_CR)), 15, NewStatus);
|
||||
break;
|
||||
case VcChannel2:
|
||||
SetBit((uint32_t)(&(M0P_VC->VC2_CR)), 15, NewStatus);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief VC 比较结果获取,包含中断标志位和滤波结果
|
||||
**
|
||||
** @param Result : 所要读取的结果
|
||||
** \retval TRUE 或 FALSE
|
||||
**
|
||||
******************************************************************************/
|
||||
boolean_t Vc_GetItStatus(en_vc_ifr_t Result)
|
||||
{
|
||||
boolean_t bFlag;
|
||||
bFlag = GetBit((uint32_t)(&(M0P_VC->IFR)), Result);
|
||||
return bFlag;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief VC 清除中断标志位
|
||||
**
|
||||
** @param NewStatus : Vc0_Intf、Vc1_Intf、Vc2_Intf
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Vc_ClearItStatus(en_vc_ifr_t NewStatus)
|
||||
{
|
||||
SetBit((uint32_t)(&(M0P_VC->IFR)), NewStatus, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief VC 配置DAC相关的内容 VC_CR中 VC_REF2P5_SEL VC_DIV_EN VC_DIV
|
||||
**
|
||||
** @param pstcDacCfg :
|
||||
** \retval Ok 或 ErrorInvalidParameter
|
||||
**
|
||||
******************************************************************************/
|
||||
en_result_t Vc_DacInit(stc_vc_dac_cfg_t *pstcDacCfg)
|
||||
{
|
||||
if (NULL == pstcDacCfg)
|
||||
{
|
||||
return ErrorInvalidParameter;
|
||||
}
|
||||
|
||||
M0P_VC->CR_f.DIV_EN = pstcDacCfg->bDivEn;
|
||||
M0P_VC->CR_f.REF2P5_SEL = pstcDacCfg->enDivVref;
|
||||
|
||||
if (pstcDacCfg->u8DivVal < 0x40)
|
||||
{
|
||||
M0P_VC->CR_f.DIV = pstcDacCfg->u8DivVal;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ErrorInvalidParameter;
|
||||
}
|
||||
|
||||
return Ok;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief VC通道初始化
|
||||
**
|
||||
** @param pstcDacCfg :
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Vc_Init(stc_vc_channel_cfg_t *pstcChannelCfg)
|
||||
{
|
||||
if (VcChannel0 == pstcChannelCfg->enVcChannel)
|
||||
{
|
||||
M0P_VC->CR_f.VC0_HYS_SEL = pstcChannelCfg->enVcCmpDly;
|
||||
M0P_VC->CR_f.VC0_BIAS_SEL = pstcChannelCfg->enVcBiasCurrent;
|
||||
M0P_VC->VC0_CR_f.DEBOUNCE_TIME = pstcChannelCfg->enVcFilterTime;
|
||||
M0P_VC->VC0_CR_f.P_SEL = pstcChannelCfg->enVcInPin_P;
|
||||
M0P_VC->VC0_CR_f.N_SEL = pstcChannelCfg->enVcInPin_N;
|
||||
M0P_VC->VC0_CR_f.FLTEN = pstcChannelCfg->bFlten;
|
||||
M0P_VC->VC0_OUT_CFG = 1<<pstcChannelCfg->enVcOutCfg;
|
||||
}
|
||||
else if (VcChannel1 == pstcChannelCfg->enVcChannel)
|
||||
{
|
||||
M0P_VC->CR_f.VC1_HYS_SEL = pstcChannelCfg->enVcCmpDly;
|
||||
M0P_VC->CR_f.VC1_BIAS_SEL = pstcChannelCfg->enVcBiasCurrent;
|
||||
M0P_VC->VC1_CR_f.DEBOUNCE_TIME = pstcChannelCfg->enVcFilterTime;
|
||||
M0P_VC->VC1_CR_f.P_SEL = pstcChannelCfg->enVcInPin_P;
|
||||
M0P_VC->VC1_CR_f.N_SEL = pstcChannelCfg->enVcInPin_N;
|
||||
M0P_VC->VC1_CR_f.FLTEN = pstcChannelCfg->bFlten;
|
||||
M0P_VC->VC1_OUT_CFG = 1<<pstcChannelCfg->enVcOutCfg;
|
||||
}
|
||||
else if(VcChannel2 == pstcChannelCfg->enVcChannel)
|
||||
{
|
||||
M0P_VC->CR_f.VC2_HYS_SEL = pstcChannelCfg->enVcCmpDly;
|
||||
M0P_VC->CR_f.VC2_BIAS_SEL = pstcChannelCfg->enVcBiasCurrent;
|
||||
M0P_VC->VC2_CR_f.DEBOUNCE_TIME = pstcChannelCfg->enVcFilterTime;
|
||||
M0P_VC->VC2_CR_f.P_SEL = pstcChannelCfg->enVcInPin_P;
|
||||
M0P_VC->VC2_CR_f.N_SEL = pstcChannelCfg->enVcInPin_N;
|
||||
M0P_VC->VC2_CR_f.FLTEN = pstcChannelCfg->bFlten;
|
||||
M0P_VC->VC2_OUT_CFG = 1<<pstcChannelCfg->enVcOutCfg;
|
||||
}
|
||||
else
|
||||
{
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief VC 通道使能
|
||||
**
|
||||
** \param enChannel : 通道号VcChannel0 VcChannel1 VcChannel2
|
||||
** \param NewStatus : TRUE FALSE
|
||||
** \retval NewStatus : TRUE FALSE
|
||||
**
|
||||
******************************************************************************/
|
||||
void Vc_Cmd(en_vc_channel_t enChannel, boolean_t NewStatus)
|
||||
{
|
||||
switch(enChannel)
|
||||
{
|
||||
case VcChannel0:
|
||||
SetBit((uint32_t)(&(M0P_VC->VC0_CR)), 16, NewStatus);
|
||||
break;
|
||||
case VcChannel1:
|
||||
SetBit((uint32_t)(&(M0P_VC->VC1_CR)), 16, NewStatus);
|
||||
break;
|
||||
case VcChannel2:
|
||||
SetBit((uint32_t)(&(M0P_VC->VC2_CR)), 16, NewStatus);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//@} // VcGroup
|
||||
|
||||
/******************************************************************************
|
||||
* EOF (not truncated)
|
||||
******************************************************************************/
|
||||
|
||||
@@ -0,0 +1,203 @@
|
||||
/*************************************************************************************
|
||||
* Copyright (C) 2017, Huada Semiconductor Co.,Ltd All rights reserved.
|
||||
*
|
||||
* This software is owned and published by:
|
||||
* Huada Semiconductor Co.,Ltd ("HDSC").
|
||||
*
|
||||
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
|
||||
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
|
||||
*
|
||||
* This software contains source code for use with HDSC
|
||||
* components. This software is licensed by HDSC to be adapted only
|
||||
* for use in systems utilizing HDSC components. HDSC shall not be
|
||||
* responsible for misuse or illegal use of this software for devices not
|
||||
* supported herein. HDSC is providing this software "AS IS" and will
|
||||
* not be responsible for issues arising from incorrect user implementation
|
||||
* of the software.
|
||||
*
|
||||
* Disclaimer:
|
||||
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
|
||||
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
|
||||
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
|
||||
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
|
||||
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
|
||||
* WARRANTY OF NONINFRINGEMENT.
|
||||
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
|
||||
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
|
||||
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
|
||||
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
|
||||
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
|
||||
* SAVINGS OR PROFITS,
|
||||
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
|
||||
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
|
||||
* FROM, THE SOFTWARE.
|
||||
*
|
||||
* This software may be replicated in part or whole for the licensed use,
|
||||
* with the restriction that this Disclaimer and Copyright notice must be
|
||||
* included with each copy of this software, whether used in part or whole,
|
||||
* at all times.
|
||||
*/
|
||||
/******************************************************************************/
|
||||
/** \file wdt.c
|
||||
**
|
||||
** WDT function driver API.
|
||||
** @link WdtGroup Some description @endlink
|
||||
**
|
||||
** - 2017-05-17 1.0 CJ First version for Device Driver Library of Module.
|
||||
**
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
/* Include files */
|
||||
/******************************************************************************/
|
||||
#include "wdt.h"
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \defgroup WdtGroup
|
||||
**
|
||||
******************************************************************************/
|
||||
//@{
|
||||
|
||||
/******************************************************************************/
|
||||
/* Local function prototypes ('static') */
|
||||
/******************************************************************************/
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief WDT溢出时间设置函数
|
||||
**
|
||||
** \param [in] u8LoadValue 溢出时间
|
||||
**
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Wdt_WriteWdtLoad(uint8_t u8LoadValue)
|
||||
{
|
||||
M0P_WDT->CON_f.WOV = u8LoadValue;
|
||||
}
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief WDT初始化函数
|
||||
**
|
||||
** \param [in] enFunc @ref en_wdt_func_t
|
||||
** \param [in] enTime @ref en_wdt_time_t
|
||||
**
|
||||
** \retval Ok
|
||||
**
|
||||
******************************************************************************/
|
||||
en_result_t Wdt_Init(en_wdt_func_t enFunc, en_wdt_time_t enTime)
|
||||
{
|
||||
en_result_t enRet = Error;
|
||||
|
||||
Wdt_WriteWdtLoad(enTime);
|
||||
M0P_WDT->CON_f.WINT_EN = enFunc;
|
||||
enRet = Ok;
|
||||
return enRet;
|
||||
}
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief WDT复位及启动函数
|
||||
**
|
||||
** \param [in] 无
|
||||
**
|
||||
** \retval 无
|
||||
**
|
||||
******************************************************************************/
|
||||
void Wdt_Start(void)
|
||||
{
|
||||
M0P_WDT->RST = 0x1E;
|
||||
M0P_WDT->RST = 0xE1;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief WDT喂狗
|
||||
**
|
||||
** \param [in] 无
|
||||
**
|
||||
** \retval Ok
|
||||
**
|
||||
******************************************************************************/
|
||||
void Wdt_Feed(void)
|
||||
{
|
||||
M0P_WDT->RST = 0x1E;
|
||||
M0P_WDT->RST = 0xE1;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief WDT中断标志清除
|
||||
**
|
||||
** \param [in] 无
|
||||
**
|
||||
** \retval Ok
|
||||
**
|
||||
******************************************************************************/
|
||||
void Wdt_IrqClr(void)
|
||||
{
|
||||
M0P_WDT->RST = 0x1E;
|
||||
M0P_WDT->RST = 0xE1;
|
||||
}
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief WDT读取当前计数值函数
|
||||
**
|
||||
** \param [in] 无
|
||||
**
|
||||
** \retval 计数值
|
||||
**
|
||||
******************************************************************************/
|
||||
uint8_t Wdt_ReadWdtValue(void)
|
||||
{
|
||||
uint8_t u8Count;
|
||||
|
||||
u8Count = M0P_WDT->CON_f.WCNTL;
|
||||
|
||||
return u8Count;
|
||||
}
|
||||
/**
|
||||
******************************************************************************
|
||||
** \brief WDT读取当前运行状态
|
||||
**
|
||||
** \param [in] 无
|
||||
**
|
||||
** \retval 状态值
|
||||
**
|
||||
******************************************************************************/
|
||||
boolean_t Wdt_ReadwdtStatus(void)
|
||||
{
|
||||
if(M0P_WDT->CON&0x10u)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*******************************************************************************
|
||||
** \brief WDT 中断状态标记获取
|
||||
**
|
||||
**
|
||||
** \retval 中断状态
|
||||
******************************************************************************/
|
||||
boolean_t Wdt_GetIrqStatus(void)
|
||||
{
|
||||
if(M0P_WDT->CON&0x80u)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//@} // WdtGroup
|
||||
Reference in New Issue
Block a user