Docsity

MCF5282 Microcontroller Interrupt System, Slides of Computer Programming

Partial preview of the text

Download MCF5282 Microcontroller Interrupt System and more Slides Computer Programming in PDF only on Docsity!

ColdFire MicroController

Interrupt System

NetBurner Mod5282 Memory Map

RTE Instruction

Stack

(SP)-4 --> Register storage begins here ^

(SP) --> Format/Offset {7,6,5,4}={1111},{3,2,1,0}=vector (?)

(SP)+2 --> SR - Status Register

(SP)+6 --> PC - Program Counter

(SP)+10 --> Top of Stack before TRAP

High Memory

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 User’s Manual}

Contains the interrupt support control register data

Arbitrates interrupt requests,

Interrupt Control Module(s) { Chap 10 – MCF5282 User’s 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

Procedure 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.

Interrupt Control Module (From: MCF5282 User’s Manual)

etc.

NetBurner Hardware

Example 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);

Example program – IRQ Pushbuttom activates IRQ1 (cont)

void UserMain(void * pd) { InitializeStack(); if (EthernetIP==0)GetDHCPAddress(); OSChangePrio(MAIN_PRIO); EnableAutoUpdate(); DWORD isr_count=0; /* 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.eppar=0x0008; / 00 00 00 00 00 00 10 00 see table 11-3 in UM / sim.eport.epddr=0x0; / 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); } } Docsity.com

INTERRUPT macro

INTERRUPT macro is provided in the header:

#include <cfinter.h>

You can add some unique functionality to it.

SR - Status Register

Edge Port Module

Flag Register