?? rtc_stopwatch_wake.asm
字號(hào):
/*****************************************************************************
** **
** Name: Real-Time Clock Wake From Deep Sleep Using Stop-Watch **
** **
******************************************************************************
(C) Copyright 2004 - Analog Devices, Inc. All rights reserved.
File Name: RTC_stopwatch_wake.asm
Date Modified: 12/10/04 Rev 1.0
Software: VisualDSP++4.0
Hardware: ADSP-BF537 EZ-KIT Board
Special Connections: None
Purpose: Demonstrate RTC wake-up from deep sleep mode using stopwatch
Then Use Real-Time Interrupts To Update LED Display
******************************************************************************/
#include <defBF537.h>
#define CLEAR_ALL_IRQS 0x807F // Clears ALL RTC Interrupts
#define MEF 0x0008 // Minutes Event Flag
#define HEF 0x0010 // Hours Event Flag
#define DEF 0x0020 // 24 Hours (Days) Event Flag
/************************************************************************************************/
/* GLOBAL & EXTERNAL DECLARATIONS */
/************************************************************************************************/
.GLOBAL _main;
/************************************************************************
* BLACKFIN CODE STARTS HERE *
************************************************************************/
.SECTION L1_code;
_main:
call Setup_Interrupt_Vectors;
call Blink_LEDs;
call GoTo_DeepSleepMode; // Go to Deep-Sleep for RTC Wake-Up
call Configure_RTC;
wait_forever:
jump wait_forever;
/************************************************************************
* INTERRUPT VECTORS USED (OVERWRITE DEFAULTS ASSIGNED IN STARTUP.ASM) *
************************************************************************/
Setup_Interrupt_Vectors:
P0.H = hi(EVT8);
P0.L = lo(EVT8);
R0.l = RTC_Interrupt1;
R0.h = RTC_Interrupt1; // Default Real Time Clock Handler (Int8)
[p0++] = R0;
R0.l = RTC_Interrupt2; // After Wake-Up, RTC is reconfigured to generate
R0.h = RTC_Interrupt2; // real-time IRQs for seconds, minutes, hours, days,
[p0] = R0; // which will require a separate ISR (Int9)
RTS;
/****************************************************************************
* BLINK CODE *
****************************************************************************/
Blink_LEDs:
// set port f function enable register (need workaround)
p0.l = lo(PORTF_FER);
p0.h = hi(PORTF_FER);
r0.l = 0x0000;
r1 = w[p0] (z);
#if (__SILICON_REVISION__ < 0x0001)
ssync;
w[p0] = r0;
ssync;
w[p0] = r0;
ssync;
#else
w[p0] = r0;
#endif
// set PORT F direction register
p0.l = lo(PORTFIO_DIR);
p0.h = hi(PORTFIO_DIR);
r0.l = 0x0FC0;
w[p0] = r0;
ssync;
P3.H = hi(PORTFIO_SET);
P3.L = lo(PORTFIO_SET);
R0 = 0x0A80(z);
W[P3] = R0;
P3.H = hi(PORTFIO_TOGGLE);
P3.L = lo(PORTFIO_TOGGLE);
R0 = 0x0FC0(z);
P2.L = 0x0000;
P2.H = 0x0800;
p1.l = 0x0008;
p1.h = 0x0000;
// Toggle LEDs a few times
lsetup(repeat_start, repeat_end) LC0 = P1;
repeat_start: W[P3] = R0;
lsetup(loopstart, loopstart) LC1 = P2;
loopstart: nop;
repeat_end: nop;
RTS;
/****************************************************************************
* INTIALIZE RTC WAKE-UP AND GO TO DEEP SLEEP MODE *
****************************************************************************/
GoTo_DeepSleepMode:
P0.H = hi(SIC_IWR);
P0.L = lo(SIC_IWR);
R0 = 0x0008 (z); // enable only RTC interrupt for wake-up event
[P0] = R0;
P0.H = hi(RTC_PREN);
P0.L = lo(RTC_PREN);
R0=1; // enable pre-scalar for 1 Hz RTC
w[P0] = R0.l;
R0 = 0x8000(z); // mask for WRITE-COMPLETE bit in RTC_ISTAT
P0.L = lo(RTC_ISTAT);
Poll_WC:
R1 = w[P0](z);
R1 = R1 & R0; // wait for Write Complete
CC = AZ;
IF CC JUMP Poll_WC;
// RTC now operational at 1 Hz
P0.L = lo(RTC_SWCNT);
R1 = 0x0010(z);
w[P0] = R1.L; // set stop-watch to 16 seconds (will produce ~15 second delay)
P0.L = lo(RTC_ISTAT);
R1 = CLEAR_ALL_IRQS(z);
w[P0] = R1.L; // clear any pending RTC interrupts
P0.L = lo(RTC_ICTL);
R1 = 1;
w[P0] = R1.L; // enable Stop-Watch interrupt
P0.L = lo(RTC_ISTAT);
Poll_WC1:
R1 = w[P0](z);
R1 = R1 & R0; // wait for Write Complete
CC = AZ;
IF CC JUMP Poll_WC1;
// RTC now running with correct stop-watch count and interrupts configured
P1.H = hi(PLL_CTL);
P1.L = lo(PLL_CTL);
R1 = W[P1](z);
BITSET (R1, 5); // set PDWN (Power Down) Bit To Go To Deep Sleep
P2.H = hi(SIC_IMASK);
P2.L = lo(SIC_IMASK);
R0 = [P2];
BITSET (R0, 3);
[P2] = R0; // set RTC Interrupt in SIC_IMASK
P2.H = hi(IMASK);
P2.L = lo(IMASK);
R0 = [P2];
BITSET (R0, 8); // set RTC Interrupt (default is IVG8) in IMASK
[P2] = R0;
W[P1] = R1.L; // Go To Deep Sleep
CLI R0; // PLL Programming Sequence
IDLE;
STI R0;
RTS;
/************************************************************************
* SETUP REAL-TIME CLOCK FOR SEC, MIN, HR, DAY IRQs *
************************************************************************/
Configure_RTC:
P2.H = hi(SIC_IMASK);
P2.L = lo(SIC_IMASK);
R0 = 0;
[P2] = R0; // Clear SIC_IMASK
P3.H = hi(PORTFIO_CLEAR);
P3.L = lo(PORTFIO_CLEAR);
R0 = 0x0FC0(z);
W[P3] = R0; // clear LEDs
R0 = 0;
P0.H = hi(SIC_IAR0); // Must re-assign RTC Interrupt to new EVT
P0.L = lo(SIC_IAR0); // Default RTC IAR is 0x1 = IVG8
R7.H = 0x0000; // Set RTC IAR to 0x2 = IVG9
R7.L = 0x2000; // Leave Other Fields Alone (All Are 0)
[P0] = R7; ssync; // RTC is now set to use IVG9
BITSET(R0, 9); // set IVG 9 in R0 (will enable IVG9 in IMASK on "STI R0;")
P0.H = hi(RTC_ISTAT);
P0.L = lo(RTC_ISTAT);
R7 = CLEAR_ALL_IRQS(z);
w[P0] = R7.L; // clear any pending interrupts
R7 = 0x8000(z);
Poll_WC2: R1 = w[P0](z);
R1 = R1 & R7; // wait for Write Complete
CC = AZ;
// IF CC JUMP Poll_WC2;
P0.L = lo(RTC_STAT);
R7 = 0;
[P0] = R7; ssync;
P0.L = lo(RTC_ISTAT);
R7 = 0x8000(z);
Poll_WC3: R1 = w[P0](z);
R1 = R1 & R7; // wait for Write Complete
CC = AZ;
IF CC JUMP Poll_WC3;
P0.L = lo(RTC_ICTL);
R7 = W[P0](z);
BITSET(R7, 2); // set seconds interrupt
BITSET(R7, 3); // set minutes interrupt
BITSET(R7, 4); // set hours interrupt
BITSET(R7, 5); // set day interrupt
W[P0] = R7.L; // reset ICTL w/ secs and mins enabled
ssync;
// RTC Interrupt Unmasked
P1.H = hi(SIC_IMASK);
P1.L = lo(SIC_IMASK);
R7.L = 0x0008;
W[p1] = r7.l; ssync;
STI R0; // Enable Interrupts
RTS;
/************************************************************************
* REAL-TIME CLOCK WAKE-UP INTERRUPT - CLEARS IRQ, CLEARS BYPASS IN PLL *
************************************************************************/
RTC_Interrupt1: // Real Time Clock Wake-Up Interrupt
P0.H = hi(PLL_CTL);
P0.L = lo(PLL_CTL);
R7 = w[p0](z); // BYPASS bit gets set coming from
BITCLR (R7, 8); // wake-up event. Must clear it to
w[p0] = R7; idle; // 0 to include the PLL
R7 = CLEAR_ALL_IRQS(z);
P0.H = hi(RTC_ISTAT);
P0.L = lo(RTC_ISTAT);
W[P0] = R7; ssync; // clear RTC IRQ
P0.L = lo(RTC_ICTL);
R7 = 0;
w[P0] = R7; ssync; // disable RTC interrupts
P0.L = lo(RTC_ISTAT);
Poll_WC_IRQ:
R1 = w[P0](z);
R1 = R1 & R0; // wait for Write Complete
CC = AZ;
IF CC JUMP Poll_WC_IRQ;
RTI;
/************************************************************************
* REAL-TIME CLOCK INTERRUPT - UPDATES LED DISPLAY *
* LED1 Toggles Every Second, LED2 Every Minute *
* LED3 Toggles Every Hour, LED4 Toggles Every Day *
************************************************************************/
RTC_Interrupt2: // Real Time Clock Interrupt
R0 = CLEAR_ALL_IRQS(z); // W1C all IRQ Bits
P0.H = hi(RTC_ISTAT);
P0.L = lo(RTC_ISTAT);
R1 = w[P0](z); // read IRQ Status
R7 = 0;
BITSET (R7,6); // always get a seconds interrupt, toggle LED1
Check_Minutes_IRQ:
R2 = MEF(z); // minutes event flag
R2 = R2 & R1; // check for minutes interrupt
CC = AZ; // if no minute interrupt, ISR complete
IF CC JUMP RTC_ISR_DONE;
BITSET (R7,7); // if minute interrupt, toggle LED2
Check_Hours_IRQ:
R2 = HEF(z); // hours event flag
R2 = R2 & R1; // check for hours interrupt
CC = AZ; // if no hour interrupt, ISR complete
IF CC JUMP RTC_ISR_DONE;
BITSET (R7,8); // if hour interrupt, toggle LED3
Check_Days_IRQ:
R2 = DEF(z); // day event flag
R2 = R2 & R1; // check for days interrupt
CC = AZ; // if no day interrupt, ISR complete
IF CC JUMP RTC_ISR_DONE;
BITSET (R7,9); // if day interrupt, toggle LED4
RTC_ISR_DONE:
P3.H = hi(PORTFIO_TOGGLE);
P3.L = lo(PORTFIO_TOGGLE);
W[P3] = R7; // Write Value to LEDs
W[p0] = R0.L; ssync; // clear IRQs
RTI;
_main.end: nop;
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -