LPC2378 Updated VIC module

Download pre-release library modules and new examples to use with Astrobe for LPC2000. Forum members can also upload their own source code examples.
Post Reply
4GlCoder
Posts: 27
Joined: Fri Jul 22, 2011 2:47 pm

LPC2378 Updated VIC module

Post by 4GlCoder » Sat Nov 19, 2011 4:22 pm

While testing the CAN controllers I made some minor adjustments to this VIC.MOD source:

Code: Select all

MODULE VIC; (* Manage Vectored Interrupt Controller *)
IMPORT SYSTEM, LPC := LPC2378;
CONST
  (* Priorties of IRQ *)
  HighestPriority*=0H; NormalPriority*=7H; LowestPriority*=0FH;

  (* Available Interrupts on LPC2378 *)
  WDInt*=0; SWIOnly=1; DbgCommRX=2; DbgCommTX=3; Timer0*=4; Timer1*=5; Uart0*=6;
  Uart1*=7; Pwm1*=8; I2C0*=9; SSP0*=10; SSP1*=11; PLL*=12; RTC*=13;
  EInt0*=14; EInt1*=15; EInt3*=16; EInt4*=17; ADC0*=18; I2C1*=19;
  BOD*=20; Eth*=21; USB*=22; CAN*=23; MCI*=24; DMA*=25; Timer2*=26;
  Timer3*=27; Uart2*=28; Uart3*=29; I2C2*=30; I2S=31;

PROCEDURE* InstallHandler*(CONST intno, inth, prio : INTEGER);
VAR
  bitmask, select : SET;
  ofs : INTEGER;
BEGIN
  IF intno IN {0..31} THEN
    bitmask := SYSTEM.VAL(SET, LSL(1, intno));
    (* Configure the Vectored Interrupt Controller *) 
    SYSTEM.PUT(LPC.VICIntEnClr, bitmask);                 (* Disable interrupt to install *)
    SYSTEM.GET(LPC.VICIntSelect, select);
    SYSTEM.PUT(LPC.VICIntSelect, select - bitmask);       (* be sure to use IRQ, NOT FIQ *)
    ofs := LSL(intno, 2);
    SYSTEM.PUT(LPC.VICVectAddr0 + ofs , inth);
    SYSTEM.PUT(LPC.VICVectPriority0 + ofs, prio MOD 16);  (* mask off irrelevant bits *)
    (* Enable MCI interrupt *)
    SYSTEM.GET(LPC.VICIntEnable, select);
    SYSTEM.PUT(LPC.VICIntEnable, select + bitmask)
  ELSE
    ASSERT(FALSE) (* given bitno is not right *)
  END
END InstallHandler;

PROCEDURE* InstallHandler2*(CONST intno, inth, prio : INTEGER; fiq : BOOLEAN);
VAR
  bitmask, select : SET;
  ofs : INTEGER;
BEGIN
  IF intno IN {0..31} THEN
    bitmask := SYSTEM.VAL(SET, LSL(1, intno));
    (* Configure the Vectored Interrupt Controller *)  
    SYSTEM.PUT(LPC.VICIntEnClr, bitmask);             (* Disable interrupt to install *)
    SYSTEM.GET(LPC.VICIntSelect, select);
    IF fiq THEN
      SYSTEM.PUT(LPC.VICIntSelect, select + bitmask)  (* use FIQ *)
    ELSE 
      SYSTEM.PUT(LPC.VICIntSelect, select - bitmask)  (* use IRQ *)
    END;
    ofs := LSL(intno, 2);
    SYSTEM.PUT(LPC.VICVectAddr0 + ofs , inth);
    SYSTEM.PUT(LPC.VICVectPriority0 + ofs, prio MOD 16); (* mask off irrelevant bits *)
    (* Enable MCI interrupt *)
    SYSTEM.GET(LPC.VICIntEnable, select);
    SYSTEM.PUT(LPC.VICIntEnable, select + bitmask)
  ELSE
    ASSERT(FALSE) (* given bitno is not right *)
  END
END InstallHandler2;

PROCEDURE* UnInstallHandler*(CONST intno : INTEGER);
VAR
  bitmask, select : SET;
  va, ofs : INTEGER;
BEGIN
  IF intno IN {0..31} THEN
    bitmask := SYSTEM.VAL(SET, LSL(1, intno));
    (* Configure the Vectored Interrupt Controller *)
    SYSTEM.PUT(LPC.VICIntEnClr, bitmask);             (*Disable interrupt to install *)
    SYSTEM.GET(LPC.VICIntSelect, select);
    SYSTEM.PUT(LPC.VICIntSelect, select - bitmask);   (* default is IRQ *)
    ofs := LSL(intno, 2);
    SYSTEM.PUT(LPC.VICVectAddr0 + ofs , 0); 
    SYSTEM.PUT(LPC.VICVectPriority0 + ofs, LowestPriority); (* default prio *)
    (* Enable MCI interrupt *)
  ELSE
    ASSERT(FALSE) (* given bitno is not right *)
  END
END UnInstallHandler;

END VIC.
Hope that helps ...

Post Reply