Download KLQRUG, Kinetis L Peripheral Module Quick Reference
Transcript
Chapter 5 Power Management Control (PMC/SMC/LLWU/RCM)
*
= 0x20 Request a hardware interrupt if LVDF = 1
* lvw_select = 0x00 Low trip point selected (VLVW = VLVW1)
*
= 0x01 Mid 1 trip point selected (VLVW = VLVW2)
*
= 0x10 Mid 2 trip point selected (VLVW = VLVW3)
*
= 0x11 High trip point selected (VLVW = VLVW4)
* lvw_int_enable = 0x00 Hardware interrupt disabled
*
= 0x20 Request a hardware interrupt if LVWF = 1
*/
void LVD_Initalize(unsigned char lvd_select,
unsigned char lvd_reset_enable,
unsigned char lvd_int_enable,
unsigned char lvw_select,
unsigned char lvw_int_enable){
/*enable LVD Reset ? LVD Interrupt.select high or low LVD */
PMC_LVDSC1 = PMC_LVDSC1_LVDACK_MASK |
(lvd_reset_enable) |
lvd_int_enable
|
PMC_LVDSC1_LVDV(lvd_select);
/* select LVW level 1,2,3 or 4 */
PMC_LVDSC2 = PMC_LVDSC2_LVWACK_MASK |
(lvw_int_enable) |
//LVW interrupt?
PMC_LVDSC2_LVWV(lvw_select);
/* if interrupts requested
clear pending flags in NVIC and enable interrupts */
if (((PMC_LVDSC1 & PMC_LVDSC1_LVDIE_MASK)
>>PMC_LVDSC1_LVDIE_SHIFT) |
((PMC_LVDSC2 & PMC_LVDSC2_LVWIE_MASK)
>>PMC_LVDSC2_LVWIE_SHIFT))
{
enable_irq(LVD_irq_no); // ready for this interrupt.
}
}
5.2.2.3 Interrupt code example and explanation
The LVD circuitry can be programmed to cause an interrupt. You should create a service
routine to clear the flags and react appropriately. An example of such an interrupt service
routine is given.
To clear a warning or detect interrupt flag two things must happen:
1. The VDD voltage must return to a nominal voltage above the threshold.
2. A write to the LVDACK bit must be done to clear the LVDF indicator or a write to
the LVWACK bit must be done to clear the LVWF indicator.
If the ACK bit is written and the voltage does not go back above the threshold, the
interrupt flag will not clear and the interrupt routine will be reentered.
void pmc_lvd_isr(void)
{
if (PMC_LVDSC1 &PMC_LVDSC1_LVDF_MASK){
printf("[LVD_isr]LV DETECT interrupt occurred");
}
if (PMC_LVDSC2 &PMC_LVDSC2_LVWF_MASK){
printf("[LVD_isr]LV WARNING interrupt occurred");
}
Kinetis L Peripheral Module Quick Reference, Rev. 0, 09/2012
Freescale Semiconductor, Inc.
45