Title: NetBurner 5282 MCF5282 ColdFire MicroController Interrupt System
1NetBurner 5282MCF5282 ColdFire
MicroControllerInterrupt System
2 MCF5282 Interrupt System
Software Main Program Interrupt
Service Routine (ISR) Hardware Device
that can initiate an Interrupt (e.g. an A/D
Converter) Edge Port Module (EPORT) Chap
11 MCF5282 Users Manual Contains
the interrupt support control register data
Arbitrates interrupt requests,
Interrupt Control Module(s) Chap 10 MCF5282
Users Manual Provides the
equivalent of the TRAP functionality, and
Provides CPU with ISR address Support
functions SetIntc( ) Sets up the Interrupt
Control Module INTERRUPT macro Provides the
messy code for the service routine
3SR - Status Register
4Stack
(SP)-4 --gt Register storage begins here
------------ (SP) --gt
Format/Offset 7,6,5,41111,3,2,1,0vector
(?) (SP)2 --gt SR - Status Register (SP)6
--gt PC - Program Counter
------------ (SP)10 --gt Top of Stack before
TRAP - - - - -
- - - - - High Memory
5Procedure for Interrupt handling Application
Review your system architecture and determine
which interrupt level (1-7) is appropriate. Level
1 is the lowest priority, level 7 is the highest.
Use caution with level 7, since it is unique in
that it is a non-maskable interrupt. If you use
level 7, the ISR cannot call any uCOS functions,
or use the INTERRUPT( ) macro. Write an
Interrupt Service Routine (ISR). If you are using
IRQ1 6, use the INTERRUPT( ) macro to make
coding the ISR easier. If you are using the level
7 unmaskable IRQ, then you must write the program
code to save and restore the CPU registers.
Call the SetIntc( ) function to set up the
interrupt vector, level and priority. The
function should be called prior to any interrupts
occurring.
6Set up 5282 Controller
extern C / This function sets up the 5282
interrupt controller / void SetIntc(int intc,
long func, int vector, int level, int prio)
7INTERRUPT macro
INTERRUPT macro is provided in the header
include ltcfinter.hgt You can add some unique
functionality to it.
8NetBurner Hardware
9Example program IRQ Pushbuttom activates IRQ1
include "predef.h" include ltstdio.hgt include
ltctype.hgt include ltstartnet.hgt include
ltautoupdate.hgt include ltdhcpclient.hgt include
lt../mod5282/system/sim5282.hgt include
ltcfinter.hgt / An interrupt setup helper defined
in bsp.c / extern "C" void SetIntc(int
intc,long func, int vector, int level,int prio )
/ Function sets up the 5282 interrupt
controller / OS_SEM IrqPostSem / Semaphore
to communicate between the IRQ1 pin ISR and the
main application / / Declare our interrupt
procedure.... name our_irq1_pin_isr
masking level (The value of the ColdFire SR
during the interrupt use 0x2700 to mask
all interrupts. 0x2500 to mask levels
1-5 etc... 0x2100 to mask level 1 /
INTERRUPT(out_irq1_pin_isr, 0x2100 ) /
WARNING WARNING WARNING Only a very
limited set of RTOS functions can be called from
within an interrupt service routine.
Basically, only OS POST functions and LED
functions should be used. No I/O (read,
write or printf may be called), since they can
block. / sim.eport.epfr0x02 / Clear
the interrupt edge 0 0 0 0 0 0 1 0 /
OSSemPost(IrqPostSem)
10Example program IRQ Pushbuttom activates IRQ1
(cont)
extern "C" void UserMain(void pd)
void putdisp(unsigned short w) / Helper
function to display a decimal number / void
PutDispDecimal(WORD val, BOOL blank_zero )
WORD w w (val / 1000) 0x1000 if ((w
0) (blank_zero)) w 0xF000 w ((val
/ 100) 10) 0x0100 if (w 0xF000) w
0xFF00 w ((val / 10) 10) 0x0010 if
(w 0xFF00) w 0xFFF0 w ((val ) 10)
0x0001 putdisp(w)
11Example program IRQ Pushbuttom activates IRQ1
(cont)
void UserMain(void pd) InitializeStack()
if (EthernetIP0)GetDHCPAddress()
OSChangePrio(MAIN_PRIO) EnableAutoUpdate()
DWORD isr_count0 / Count how many times the
switch was hit / / Initialize the semaphore
we are using / OSSemInit(IrqPostSem,0)
/ First set up the Eport module to use IRQ1 as
a falling-edge active IRQ pin (See the 5282
UM chapter 11). Set the pin assignment
register irq1 pin falling edge sensitive. /
sim.eport.eppar0x0008 / 00 00 00 00 00 00
10 00 see table 11-3 in UM /
sim.eport.epddr0x0 / All edge port pins
as inputs / sim.eport.epier 0x0002 /
Enable IRQ1 only 0 0 0 0 0 0 1 0 / / Now
enable the actual interrupt controller. See users
manual chapter 10 for more information. We
are going to use the BSP helper function declared
above and implemented in BSP.c /
SetIntc(0, / The first interrupt controller /
(long)out_irq1_pin_isr, / Our
interrupt function / 1, / The vector
number from the users manual table 10-13 /
1, / Set this to priority 1 but any value
from 1 to 6 would be valid./
1 / The priority within the gross
levels see chapter 10, any
value from 0 to 7 is ok / )
iprintf("Application started\n")
iprintf("Press the IRQ button on the development
board.\n") while (1)
OSSemPend(IrqPostSem,0 / Wait forever /)
PutDispDecimal(isr_count,true)
iprintf("The interrupt Switch was hit ld
times\r\n", isr_count)
12Example of Level 7 Interrupt Service Routine
/ The extern directive is only needed if you are
creating this code in a .cpp file If you are
crating a .c file, do not include the extern
section./ extern "C" void NMI_C_Part()
// The part of the ISR written in C/C void
NMI_ASM_Part() // The part of the ISR written in
Assembly / The "Function_Holder()" is just a
place holder so we can create some inline
assembly language code. / void
Function_Holder() __asm__ (" .global
NMI_ASM_Part") // export the label for
ASM part __asm__ (" .extern NMI_C_Part")
// label for the C part of the ISR
__asm__ (NMI_ASM_Part) //
label for the assembly part of the ISR __asm__
(" move.w 0x2700,sr ") // set the
IRQ mask to mask all __asm__ (" lea
-60(a7),a7 ") // make space on
the system stack __asm__ (" movem.l
d0-d7/a0-a6,(a7) ") // save all registers
__asm__ (" jsr NMI_C_Part ") __asm__ ("
movem.l (a7),d0-d7/a0-a6 ") __asm__ ("
lea 60(a7),a7 ") __asm__ (" rte") /
This is the C/C part of the ISR that is called
from the assembly code / void NMI_C_Part()
// Your C/C application code goes here
13Edge Port Module (From MCF5282 Users Manual)
14Interrupt Control Module (From MCF5282 Users
Manual)
etc.
15Edge Port Module Names and Addresses(From
Header File include lt../mod5282/system/sim5282
.hgt)
define MBASE 0x40000000 / Module Base
Address/ . . typedef struct / edge port
module / vuword eppar /
130000-gt130001 eport pin assignment register /
vubyte epddr / 130002-gt130002 eport
data direction register / vubyte epier
/ 130003-gt130003 eport interrupt enable
register / vubyte epdr /
130004-gt130004 eport data register /
vubyte eppdr / 130005-gt130005 eport pin
data register / vubyte epfr /
130006-gt130006 eport flag register /
eportstruct . .
16Edge Port Module
17Flag Register
18Pin Assignment Register
19Data Direction Register
20Interrupt Enable Register