📄 rtc.asm
字号:
/*****************************************************************************************************************
(C) Copyright 2001 - Analog Devices, Inc. All rights reserved.
File Name: rtc.asm
Date Modified: 12/20/01 CL Rev 0.1
Purpose: ADSP-BF535 EZ-Kit Lite Real Time Clock Example
Developed using the ADSP-BF535 EZ-KIT Lite Evaluation Platform
This program contains routines to initialize the
state of the ADSP-BF535 event controller. The real-time clock is programmed
to generate an interrupt every second and every minute.
LED 1 on the EZ-Kit blinks to indicate a seconds interrupt has been received and processed.
All of the LEDS are turned on when a minutes interrupt is received
************************************************************************************************/
#include <defBF535.h>
.section l2_bank0; // Sets location of example to the beginning of on-chip L2 memory
SETUP:
// Setup Event Vectors and Handlers
p0.l = EVT0 & 0xffff;
p0.h = EVT0 >> 16;
r0 = _EHANDLER (Z); // Emulation Handler (Int0)
r0.h = _EHANDLER;
[ P0 ++ ] = R0;
R0 = _RHANDLER (Z);
R0.H = _RHANDLER; // Reset Handler (Int1)
[ P0 ++ ] = R0;
R0 = _NHANDLER (Z);
R0.H = _NHANDLER; // NMI Handler (Int2)
[ P0 ++ ] = R0;
R0.L = _XHANDLER;
R0.H = _XHANDLER; // Exception Handler (Int3)
[ P0 ++ ] = R0;
[ P0 ++ ] = R0; // IVT4 isn't used
R0 = _HWHANDLER (Z);
R0.H = _HWHANDLER; // HW Error Handler (Int5)
[ P0 ++ ] = R0;
R0 = _THANDLER (Z);
R0.H = _THANDLER; // Timer Handler (Int6)
[ P0 ++ ] = R0;
R0 = _RTCHANDLER (Z);
R0.H = _RTCHANDLER; // IVG7 Handler
[ P0 ++ ] = R0;
R0 = _I8HANDLER (Z);
R0.H = _I8HANDLER; // IVG8 Handler
[ P0 ++ ] = R0;
R0 = _I9HANDLER (Z);
R0.H = _I9HANDLER; // IVG9 Handler
[ P0 ++ ] = R0;
R0 = _I10HANDLER (Z);
R0.H = _I10HANDLER;// IVG10 Handler
[ P0 ++ ] = R0;
R0 = _I11HANDLER (Z);
R0.H = _I11HANDLER;// IVG11 Handler
[ P0 ++ ] = R0;
R0 = _I12HANDLER (Z);
R0.H = _I12HANDLER;// IVG12 Handler
[ P0 ++ ] = R0;
R0 = _I13HANDLER (Z);
R0.H = _I13HANDLER;// IVG13 Handler
[ P0 ++ ] = R0;
R0 = _I14HANDLER (Z);
R0.H = _I14HANDLER;// IVG14 Handler
[ P0 ++ ] = R0;
R0 = _I15HANDLER (Z);
R0.H = _I15HANDLER;// IVG15 Handler
[ P0 ++ ] = R0;
P0.L = IMASK & 0xffff;
P0.H = IMASK >> 16;
R0 = [P0]; // Change this to unmask interrupts
BITSET(R0,7); // Set bit 7 of IMASK to enable RTC interrupt
W[ P0 ] = R0; // write to IMASK register
FLAGINIT:
P3.L = FIO_DIR & 0xffff; /*set PF0 and PF1 to be output*/
P3.H = FIO_DIR >> 16;
R6 = 0x000f(z);
W [ P3 ] = R6;
SSYNC;
/*clear PF0 and PF1 flags*/
P3.L = FIO_FLAG_C & 0xffff;
P3.H = FIO_FLAG_C >> 16;
W [ P3 ] = R6;
SSYNC;
//Check revision of silicon
//The polarity of SIC_IMASK changed between silicon revisions 0.1/0.2 and 1.0
P0.L = CHIPID & 0xffff;
P0.H = CHIPID >> 16;
R0 = [P0]; // Check the value of the CHIP_ID register
R1.H = 0xf000;
R1.L = 0x0000;
R1 = R1 & R0;
CC = AZ;
if !CC jump new; // if CHIP_ID is non-zero, a "1" in the SIC_IMASK reg enables an interrupt
old:
//Unmask the RTC Interrupt A in System Interrupt Mask Register
p3.l = SIC_IMASK & 0xffff;
p3.h = SIC_IMASK >> 16;
R6 = [p3];
BITCLR(R6,0); // clear bit 0 in rev 0.1/0.2 silicon to enable RTC interrupt
[ P3 ] = R6;
jump init_rtc;
new:
p3.l = SIC_IMASK & 0xffff;
p3.h = SIC_IMASK >> 16;
R6 = [p3];
BITSET(R6,0); // set bit 0 in rev 1.0 silicon to enable RTC interrupt
[ P3 ] = R6;
init_rtc:
//Get RTC CLK running fast for test
//This ensures that the pre-scalar is enabled
//As a result, the RTC runs at 1 Hz
p3.l = RTCFAST & 0xffff;
p3.h = RTCFAST >> 16;
R6.L = 0x0001;
W [ P3 ] = R6.L;
p0.l = RTCISTAT & 0xffff;
p0.h = RTCISTAT >> 16;
loop_sync: r0=[p0];
cc=bittst(r0,2);
if !cc jump loop_sync;
//set count value to 0
p3.l = RTCSTAT & 0xffff;
p3.h = RTCSTAT >> 16;
R6 = 0x0000(z);
[ P3 ] = R6;
p1.l = 0x93e0; // Ensure pending writes are complete
p1.h = 0x0004;
lsetup(begin1, end1) lc0=p1;
begin1: nop; nop;
end1: nop;
p0.l = RTCISTAT & 0xffff;
p0.h = RTCISTAT >> 16;
r6=0x803f(z); //Write "1" to clear alarm and event flags
W[p0]=r6;
//Enable the seconds interrupt
p3.l = RTCICTL & 0xffff;
p3.h = RTCICTL >> 16;
R6 = [p3];
BITSET(R6,2); // Enable seconds (1 Hz) interrupt
BITSET(R6,3); // Enable minutes interrupt
W[ P3 ] = R6;
/************************************************************/
// clear the pending reset interrupt (return to User mode) and
// set all other return regs to a known spot (except RETE)
nop;
r0.h = wait_here;
r0.l = wait_here;
reti = r0;
rets = r0;
retn = r0;
retx = r0;
nop;
rti; // return from supervisor mode to user mode!!
nop; // never executed
nop; // never executed
/************************************************************/
wait_here: jump wait_here;
// Handlers for Events
_EHANDLER: // Emulation Handler 0
RTE;
_RHANDLER: // Reset Handler 1
RTI;
_NHANDLER: // NMI Handler 2
RTN;
_XHANDLER: // Exception Handler 3
RTX;
_HWHANDLER: // HW Error Handler 5
RTI;
_THANDLER: // Timer Handler 6
RTI;
_RTCHANDLER: // IVG 7 Handler (RTC)
p2.l = 0xffff; // set counter to blink LED
p2.h = 0x000f;
//blink PF flag to indicate RTC interrupt occured
P4.L = FIO_FLAG_S & 0xffff;
P4.H = FIO_FLAG_S >> 16;
p0.l = RTCISTAT & 0xffff;
p0.h = RTCISTAT >> 16;
r0=[p0];
cc=bittst(r0,3); // Check if minutes event occurred
if !cc jump seconds;
r4 = 0x000f(z); // set all LEDs when minutes interrupt occurs
jump led_set;
seconds:
r4 = 0x0002(z); // set LED 1 only when a seconds interrupt occurs
led_set:
W[p4]=r4;
LSETUP(NOP_START_3, NOP_END_3) LC0=P2;
NOP_START_3:
NOP;NOP;NOP;NOP;NOP;
NOP;NOP;NOP;NOP;NOP;
NOP_END_3:
NOP;
P4.L = FIO_FLAG_C & 0xffff;
P4.H = FIO_FLAG_C >> 16;
W[p4]=r4;
LSETUP(NOP_START_4, NOP_END_4) LC1=P2;
NOP_START_4:
NOP;NOP;NOP;NOP;NOP;
NOP;NOP;NOP;NOP;NOP;
NOP_END_4:
NOP;
p3.L = RTCISTAT & 0xffff;
p3.H = RTCISTAT >> 16;
if !cc jump seconds_only; // check to see which interrupts to clear
r7.l = 0x000C; // Write "1" to clear seconds and minutes interrupt
r7.h = 0x0000;
jump clear_int;
seconds_only:
r7.l = 0x0004; // Write "1" to clear seconds interrupt
r7.h = 0x0000;
clear_int:
[p3] = r7;
ssync;
RTI;
_I8HANDLER: // IVG 8 Handler
RTI;
_I9HANDLER: // IVG 9 Handler
RTI;
_I10HANDLER: // IVG 10 Handler
RTI;
_I11HANDLER: // IVG 11 Handler
RTI;
_I12HANDLER: // IVG 12 Handler
RTI;
_I13HANDLER: // IVG 13 Handler
RTI;
_I14HANDLER:
RTI;
_I15HANDLER:
RTI;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -