/******************************************************************************
* Copyright (C) 2020, Huada Semiconductor Co., Ltd. All rights reserved.
*
* This software component is licensed by HDSC under BSD 3-Clause license
* (the "License"); You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*/
/*****************************************************************************/
/** \file hc32f460_interrupts.c
**
** A detailed description is available at
** @link InterruptGroup Interrupt description @endlink
**
** - 2018-10-12 CDT First version for Device Driver Library of interrupt.
**
******************************************************************************/
/*******************************************************************************
* Include files
******************************************************************************/
#include "hc32f460_interrupts.h"
#include "hc32f460_utility.h"
#if (DDL_INTERRUPTS_ENABLE == DDL_ON)
/**
*******************************************************************************
** \addtogroup InterruptGroup
******************************************************************************/
//@{
/*******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/*******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
/*! Parameter validity check for null pointer. */
#define IS_NULL_POINT(x) (NULL != (x))
/*! Max IRQ Handler. */
#define IRQ_NUM_MAX (128u)
/*******************************************************************************
* Global variable definitions (declared in header file with 'extern')
******************************************************************************/
/*******************************************************************************
* Local function prototypes ('static')
******************************************************************************/
/*******************************************************************************
* Local variable definitions ('static')
******************************************************************************/
/*******************************************************************************
* Function implementation - global ('extern') and local ('static')
******************************************************************************/
func_ptr_t IrqHandler[IRQ_NUM_MAX] = {NULL};
/**
*******************************************************************************
** \brief IRQ Registration
**
** param [in] pstcIrqRegiConf, IRQ registration
** configure structure
**
** retval Ok, IRQ register successfully.
** ErrorInvalidParameter, IRQ No. and
** Vector No. are not match.
** ErrorUninitialized, Make sure the
** Interrupt select register (INTSEL) is
** default value (0x1FFu) before setting.
**
*****************************************************************************/
en_result_t enIrqRegistration(const stc_irq_regi_conf_t *pstcIrqRegiConf)
{
// todo, assert ...
stc_intc_sel_field_t *stcIntSel;
en_result_t enRet = Ok;
//DDL_ASSERT(NULL != pstcIrqRegiConf->pfnCallback);
DDL_ASSERT(IS_NULL_POINT(pstcIrqRegiConf->pfnCallback));
/* IRQ032~127 whether out of range */
if (((((pstcIrqRegiConf->enIntSrc/32)*6 + 32) > pstcIrqRegiConf->enIRQn) || \
(((pstcIrqRegiConf->enIntSrc/32)*6 + 37) < pstcIrqRegiConf->enIRQn)) && \
(pstcIrqRegiConf->enIRQn >= 32))
{
enRet = ErrorInvalidParameter;
}
else
{
stcIntSel = (stc_intc_sel_field_t *)((uint32_t)(&M4_INTC->SEL0) + \
(4u * pstcIrqRegiConf->enIRQn));
if (0x1FFu == stcIntSel->INTSEL)
{
stcIntSel->INTSEL = pstcIrqRegiConf->enIntSrc;
IrqHandler[pstcIrqRegiConf->enIRQn] = pstcIrqRegiConf->pfnCallback;
}
else
{
enRet = ErrorUninitialized;
}
}
return enRet;
}
/**
*******************************************************************************
** \brief IRQ Resign
**
** param [in] enIRQn, IRQ enumunation (Int000_IRQn ~
** Int127_IRQn
**
** retval Ok, IRQ resign sucessfully.
** ErrorInvalidParameter, IRQ No. is out
** of range
**
*****************************************************************************/
en_result_t enIrqResign(IRQn_Type enIRQn)
{
stc_intc_sel_field_t *stcIntSel;
en_result_t enRet = Ok;
if ((enIRQn < Int000_IRQn) || (enIRQn > Int127_IRQn))
{
enRet = ErrorInvalidParameter;
}
else
{
stcIntSel = (stc_intc_sel_field_t *)((uint32_t)(&M4_INTC->SEL0) + (4ul * enIRQn));
stcIntSel->INTSEL = 0x1FFu;
IrqHandler[enIRQn] = NULL;
}
return enRet;
}
/**
*******************************************************************************
** \brief Share IRQ handler enable
**
** param [in] enIntSrc, interrupt souce, This parameter
** can be any value of @ref en_int_src_t
**
** retval Ok
**
******************************************************************************/
en_result_t enShareIrqEnable(en_int_src_t enIntSrc)
{
uint32_t *VSSELx;
//todo assert
VSSELx = (uint32_t *)(((uint32_t)&M4_INTC->VSSEL128) + (4u * (enIntSrc/32u)));
*VSSELx |= (uint32_t)(1ul << (enIntSrc & 0x1Fu));
return Ok;
}
/**
*******************************************************************************
** \brief Share IRQ handler disable
**
** param [in] enIntSrc, interrupt souce, This parameter
** can be any value of @ref en_int_src_t
**
** retval Ok
**
******************************************************************************/
en_result_t enShareIrqDisable(en_int_src_t enIntSrc)
{
uint32_t *VSSELx;
//todo assert
VSSELx = (uint32_t *)(((uint32_t)&M4_INTC->VSSEL128) + (4u * (enIntSrc/32u)));
*VSSELx &= ~(uint32_t)(1ul << (enIntSrc & 0x1Fu));
return Ok;
}
/**
*******************************************************************************
** \brief Enable stop mode wakeup source
**
** param [in] u32WakeupSrc, This parameter can be any
** composed value of @ref en_int_wkup_src_t
**
** retval Ok, corresponding wakeup source be enabled
** ErrorInvalidParameter, parameter with
** non-definition bits
**
******************************************************************************/
en_result_t enIntWakeupEnable(uint32_t u32WakeupSrc)
{
en_result_t enRet = Ok;
if (0ul != (u32WakeupSrc & 0xFD000000ul))
{
enRet = ErrorInvalidParameter;
}
else
{
M4_INTC->WUPEN |= u32WakeupSrc;
}
return enRet;
}
/**
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
收起资源包目录





































































































共 107 条
- 1
- 2










想当诸侯的小蚂蚁
- 粉丝: 19
- 资源: 6
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


安全验证
文档复制为VIP权益,开通VIP直接复制

评论1