I'm trying to convert interrupt code to use ASM but I'm not getting too far using ONASMINTERRUPT command with WKPINT interrupts. the error I get is "[TOKEN WKPINT_2]:unknown command".
Could someone look over this code and give me some advice.
Also... when do you use ASM{} versus BEGIN/END ASMSUB? Where do I put the Subroutine name and RTE?
Thanks
Code:
'Variables
'======================================================================
LOOPTIMER var long 'increments 256 times per second
SENCODER var slong
RTime var slong
cIndex var long
CAPTURE1 var slong
CAPTURE2 var slong
CAPTURE3 var slong
CAPTURE4 var slong
'======================================================================
'SetupTimerAndInterrupts
'======================================================================
PMR5.bit2 = 1 ' enables pin2 as WKP interrupt instead of normal I/O - Laser input
IEGR2.bit2 = 1 ' 0 = Pin2 will interrupt on a falling edge, 1 to interrupt on a rising edge.
TMA = (TMA & 0xf0) | 0x4 ' Sets TimerA to increment once every 256 clock cycles.
ONASMINTERRUPT TIMERAINT,HANDLE_TIMERA
ENABLE TIMERAINT ' enable timer interrupt
ONASMINTERRUPT WKPINT_2, LASERINTERRUPT ' Define interrupt action
ENABLE WKPINT_2 ' enable Laser Sensor interrupt
'======================================================================
' ASM version of TimerA handler...
' Increments TIMERCOUNT every 256 clock cycles
'======================================================================
HANDLE_TIMERA
asm{
push.l er0 ; Save work registers
bclr #6,@IRR1:8 ; clear the cooresponding bit in the interrupt pending mask
mov.l @LOOPTIMER,er0 ; increment "Loop timer clock" count
inc.l #1,er0
mov.l er0, @LOOPTIMER
;
pop.l er0
}
RESUME
'======================================================================
LASERINTERRUPT
'======================================================================
asm{ ; Mark as assembly code
push.l er1
bclr #2,@IWPR:8 ; clear the WKP2 bit in the interrupt pending mask
andc #0x7f,ccr ; allow other interrupts to happen
mov.l @CAPTURE3:32,er1 ; Move in CAPTURE3 count
mov.l er1,@CAPTURE4:32 ; move out to CAPTURE4 count
mov.l @CAPTURE2:32,er1 ; Move in CAPTURE2 count
mov.l er1,@CAPTURE3:32 ; move out to CAPTURE3 count
mov.l @CAPTURE1:32,er1 ; Move in CAPTURE1 count
mov.l er1,@CAPTURE2:32 ; move out to CAPTURE2 count
mov.l @SENCODER:32,er1 ; Move in current count
mov.l er1,@CAPTURE1:32 ; move out to CAPTURE1 count
mov.l @CINDEX:32,er1 ; Move in cindex
inc.l #1,er1 ; increment our count
mov.l er1,@CINDEX:32 ; move out to cindex count
pop.l er1 ; clean up
} ; Unmark assembly code
Resume
'======================================================================