📄 pwm.c
字号:
void
PWMGenIntUnregister(unsigned long ulBase, unsigned long ulGen)
{
unsigned long ulInt;
//
// Check the arguments.
//
ASSERT(ulBase == PWM_BASE);
ASSERT((ulGen == PWM_GEN_0) || (ulGen == PWM_GEN_1) ||
(ulGen == PWM_GEN_2));
//
// Get the interrupt number associated with the specified generator.
//
ulInt = INT_PWM0 + (ulGen >> 6) - 1;
//
// Disable the PWMx interrupt.
//
IntDisable(ulInt);
//
// Unregister the interrupt.handler.
//
IntUnregister(ulInt);
}
//*****************************************************************************
//
//! Registers an interrupt.handler for a fault condition detected in a PWM
//! module.
//!
//! \param ulBase is the base address of the PWM module.
//! \param pfIntHandler is a pointer to the function to be called when the PWM
//! fault interrupt occurs.
//!
//! This function will ensure that the interrupt.handler specified by
//! \e pfIntHandler is called when a fault interrupt is detected for the
//! selected PWM module. This function will also enable the PWM fault
//! interrupt in the NVIC; the PWM fault interrupt must also be enabled at the
//! module level using PWMIntEnable().
//!
//! \sa IntRegister() for important information about registering interrupt
//! handlers.
//!
//! \return None.
//
//*****************************************************************************
void
PWMFaultIntRegister(unsigned long ulBase, void (*pfIntHandler)(void))
{
//
// Check the arguments.
//
ASSERT(ulBase == PWM_BASE);
//
// Register the interrupt.handler, returning an error if one occurs.
//
IntRegister(INT_PWM_FAULT, pfIntHandler);
//
// Enable the PWM fault interrupt.
//
IntEnable(INT_PWM_FAULT);
}
//*****************************************************************************
//
//! Removes the PWM fault condition interrupt.handler.
//!
//! \param ulBase is the base address of the PWM module.
//!
//! This function will remove the interrupt.handler for a PWM fault interrupt
//! from the selected PWM module. This function will also disable the PWM
//! fault interrupt in the NVIC; the PWM fault interrupt must also be disabled
//! at the module level using PWMIntDisable().
//!
//! \sa IntRegister() for important information about registering interrupt
//! handlers.
//!
//! \return None.
//
//*****************************************************************************
void
PWMFaultIntUnregister(unsigned long ulBase)
{
//
// Check the arguments.
//
ASSERT(ulBase == PWM_BASE);
//
// Disable the PWM fault interrupt.
//
IntDisable(INT_PWM_FAULT);
//
// Unregister the interrupt.handler, returning an error if one occurs.
//
IntUnregister(INT_PWM_FAULT);
}
//*****************************************************************************
//
//! Enables interrupts and triggers for the specified PWM generator block.
//!
//! \param ulBase is the base address of the PWM module.
//! \param ulGen is the PWM generator to have interrupts and triggers enabled.
//! Must be one of \b PWM_GEN_0, \b PWM_GEN_1, or \b PWM_GEN_2.
//! \param ulIntTrig specifies the interrupts and triggers to be enabled.
//!
//! Unmasks the specified interrupt(s) and trigger(s) by setting the
//! specified bits of the interrupt/trigger enable register for the specified
//! PWM generator. The defined values for the bits are as follows:
//!
//! - PWM_INT_CNT_ZERO
//! - PWM_INT_CNT_LOAD
//! - PWM_INT_CMP_AU
//! - PWM_INT_CMP_AD
//! - PWM_INT_CMP_BU
//! - PWM_INT_CMP_BD
//! - PWM_TR_CNT_ZERO
//! - PWM_TR_CNT_LOAD
//! - PWM_TR_CMP_AU
//! - PWM_TR_CMP_AD
//! - PWM_TR_CMP_BU
//! - PWM_TR_CMP_BD
//!
//! \return None.
//
//*****************************************************************************
void
PWMGenIntTrigEnable(unsigned long ulBase, unsigned long ulGen,
unsigned long ulIntTrig)
{
//
// Check the arguments.
//
ASSERT(ulBase == PWM_BASE);
ASSERT((ulGen == PWM_GEN_0) || (ulGen == PWM_GEN_1) ||
(ulGen == PWM_GEN_2));
//
// Enable the specified interrupts/triggers.
//
HWREG(PWM_GEN_BADDR(ulBase, ulGen) + PWM_O_X_INTEN) |= ulIntTrig;
}
//*****************************************************************************
//
//! Disables interrupts for the specified PWM generator block.
//!
//! \param ulBase is the base address of the PWM module.
//! \param ulGen is the PWM generator to have interrupts and triggers disabled.
//! Must be one of \b PWM_GEN_0, \b PWM_GEN_1, or \b PWM_GEN_2.
//! \param ulIntTrig specifies the interrupts and triggers to be disabled.
//!
//! Masks the specified interrupt(s) and trigger(s) by clearing the
//! specified bits of the interrupt/trigger enable register for the specified
//! PWM generator. The defined values for the bits are as follows:
//!
//! - PWM_INT_CNT_ZERO
//! - PWM_INT_CNT_LOAD
//! - PWM_INT_CMP_AU
//! - PWM_INT_CMP_AD
//! - PWM_INT_CMP_BU
//! - PWM_INT_CMP_BD
//! - PWM_TR_CNT_ZERO
//! - PWM_TR_CNT_LOAD
//! - PWM_TR_CMP_AU
//! - PWM_TR_CMP_AD
//! - PWM_TR_CMP_BU
//! - PWM_TR_CMP_BD
//!
//! \return None.
//
//*****************************************************************************
void
PWMGenIntTrigDisable(unsigned long ulBase, unsigned long ulGen,
unsigned long ulIntTrig)
{
//
// Check the arguments.
//
ASSERT(ulBase == PWM_BASE);
ASSERT((ulGen == PWM_GEN_0) || (ulGen == PWM_GEN_1) ||
(ulGen == PWM_GEN_2));
//
// Disable the specified interrupts/triggers.
//
HWREG(PWM_GEN_BADDR(ulBase, ulGen) + PWM_O_X_INTEN) &= ~(ulIntTrig);
}
//*****************************************************************************
//
//! Gets interrupt status for the specified PWM generator block.
//!
//! \param ulBase is the base address of the PWM module.
//! \param ulGen is the PWM generator to query. Must be one of \b PWM_GEN_0,
//! \b PWM_GEN_1, or \b PWM_GEN_2.
//! \param bMasked specifies whether masked or raw interrupt status is
//! returned.
//!
//! If \e bMasked is set as \b true, then the masked interrupt status is
//! returned; otherwise, the raw interrupt status will be returned.
//!
//! \return Returns the contents of the interrupt status register, or the
//! contents of the raw interrupt status register, for the specified
//! PWM generator.
//
//*****************************************************************************
unsigned long
PWMGenIntStatus(unsigned long ulBase, unsigned long ulGen, tBoolean bMasked)
{
//
// Check the arguments.
//
ASSERT(ulBase == PWM_BASE);
ASSERT((ulGen == PWM_GEN_0) || (ulGen == PWM_GEN_1) ||
(ulGen == PWM_GEN_2));
//
// Compute the generator's base address.
//
ulGen = PWM_GEN_BADDR(ulBase, ulGen);
//
// Read and return the specified generator's raw or enabled interrupt
// status.
//
if(bMasked == true)
{
return(HWREG(ulGen + PWM_O_X_ISC));
}
else
{
return(HWREG(ulGen + PWM_O_X_RIS));
}
}
//*****************************************************************************
//
//! Clears the specified interrupt(s) for the specified PWM generator block.
//!
//! \param ulBase is the base address of the PWM module.
//! \param ulGen is the PWM generator to query. Must be one of \b PWM_GEN_0,
//! \b PWM_GEN_1, or \b PWM_GEN_2.
//! \param ulInts specifies the interrupts to be cleared.
//!
//! Clears the specified interrupt(s) by writing a 1 to the specified bits
//! of the interrupt status register for the specified PWM generator. The
//! defined values for the bits are as follows:
//!
//! - PWM_INT_CNT_ZERO
//! - PWM_INT_CNT_LOAD
//! - PWM_INT_CMP_AU
//! - PWM_INT_CMP_AD
//! - PWM_INT_CMP_BU
//! - PWM_INT_CMP_BD
//!
//! \return None.
//
//*****************************************************************************
void
PWMGenIntClear(unsigned long ulBase, unsigned long ulGen, unsigned long ulInts)
{
//
// Check the arguments.
//
ASSERT(ulBase == PWM_BASE);
ASSERT((ulGen == PWM_GEN_0) || (ulGen == PWM_GEN_1) ||
(ulGen == PWM_GEN_2));
//
// Clear the requested interrupts by writing ones to the specified bit
// of the module's interrupt enable register.
//
HWREG(PWM_GEN_BADDR(ulBase, ulGen) + PWM_O_X_ISC) = ulInts;
}
//*****************************************************************************
//
//! Enables generator and fault interrupts for a PWM module.
//!
//! \param ulBase is the base address of the PWM module.
//! \param ulGenFault contains the interrupts to be enabled. Must be a logical
//! OR of any of \b PWM_INT_GEN_0, \b PWM_INT_GEN_1, \b PWM_INT_GEN_2, or
//! \b PWM_INT_FAULT.
//!
//! Unmasks the specified interrupt(s) by setting the specified bits of
//! the interrupt enable register for the selected PWM module.
//!
//! \return None.
//
//*****************************************************************************
void
PWMIntEnable(unsigned long ulBase, unsigned long ulGenFault)
{
//
// Check the arguments.
//
ASSERT(ulBase == PWM_BASE);
//
// Read the module's interrupt enable register, and enable interrupts
// for the specified PWM generators.
//
HWREG(ulBase + PWM_O_INTEN) |= ulGenFault;
}
//*****************************************************************************
//
//! Disables generator and fault interrupts for a PWM module.
//!
//! \param ulBase is the base address of the PWM module.
//! \param ulGenFault contains the interrupts to be disabled. Must be a
//! logical OR of any of \b PWM_INT_GEN_0, \b PWM_INT_GEN_1, \b PWM_INT_GEN_2,
//! or \b PWM_INT_FAULT.
//!
//! Masks the specified interrupt(s) by clearing the specified bits of
//! the interrupt enable register for the selected PWM module.
//!
//! \return None.
//
//*****************************************************************************
void
PWMIntDisable(unsigned long ulBase, unsigned long ulGenFault)
{
//
// Check the arguments.
//
ASSERT(ulBase == PWM_BASE);
//
// Read the module's interrupt enable register, and disable interrupts
// for the specified PWM generators.
//
HWREG(ulBase + PWM_O_INTEN) &= ~(ulGenFault);
}
//*****************************************************************************
//
//! Clears the fault interrupt for a PWM module.
//!
//! \param ulBase is the base address of the PWM module.
//!
//! Clears the fault interrupt by writing to the appropriate bit of the
//! interrupt status register for the selected PWM module.
//!
//! \return None.
//
//*****************************************************************************
void
PWMFaultIntClear(unsigned long ulBase)
{
//
// Check the arguments.
//
ASSERT(ulBase == PWM_BASE);
//
// Write the only writeable bit in the module's interrupt register.
//
HWREG(ulBase + PWM_O_ISC) = PWM_INT_INTFAULT;
}
//*****************************************************************************
//
//! Gets the interrupt status for a PWM module.
//!
//! \param ulBase is the base address of the PWM module.
//! \param bMasked specifies whether masked or raw interrupt status is
//! returned.
//!
//! If \e bMasked is set as \b true, then the masked interrupt status is
//! returned; otherwise, the raw interrupt status will be returned.
//!
//! \return The current interrupt status, enumerated as a bit field of
//! \b PWM_INT_GEN_0, \b PWM_INT_GEN_1, \b PWM_INT_GEN_2, and \b PWM_INT_FAULT.
//!
//*****************************************************************************
unsigned long
PWMIntStatus(unsigned long ulBase, tBoolean bMasked)
{
//
// Check the arguments.
//
ASSERT(ulBase == PWM_BASE);
//
// Read and return either the module's raw or enabled interrupt status.
//
if(bMasked == true)
{
return(HWREG(ulBase + PWM_O_ISC));
}
else
{
return(HWREG(ulBase + PWM_O_RIS));
}
}
//*****************************************************************************
//
// Close the Doxygen group.
//! @}
//
//*****************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -