Re: A92: Periodic events


[Prev][Next][Index][Thread]

Re: A92: Periodic events




>
> Can someone write a sample program illustrating how to use an interrupt
> to make something happen at a preset interval.
>


Ok, there's been quite a few requests of this nature, so here goes:
WARNING: This has not been tested, if it does not work let me know and I'll
    fix it.


main:
	move.w	$0700,d0		; Desired interrupt mask (disable all)
	trap	#1			; Set interrupt mask do desired mask
	move.w	d0,d7			; Save old mask (changed during trap)

	bclr	#2,$600001		; Turn off memory protect
	lea	my_Task(pc),a0		; Load address of task
	lea	old_Int(pc),a1		; Load address of jump to old interrupt
	move.l	($Auto_Int5),2(a1)	; Store address of old interrupt in
					;   self-modifying code (optimization)
	move.l	a0,($Auto_Int5)		; Store address of new interrupt vector

	move.w	d7,d0			; Load old mask
	trap	#1			; Restore interrupts

	... 				; Do main program
	; While in this section, periodic task will be running...
	...

	move.w	$0700,d0		; Disable interrupts (again)
	trap	#1

	lea	old_Int(pc),a1		; Load address of jump to old interrupt
	move.l	2(a1),($Auto_Int5)	; Restore interrupt vector

	move.w	d7,d0			; Load old mask
	trap	#1			; Restore interrupts (again)
	rts

my_Task:
	; This task will be run aproximately 20 times per second.
	; You MUST save and restore all registers used in this interrupt!

	movem.l	d0-d7/a0-a6,-(a7)	; Save all registers
					; This interrupt does not use any
					;   registers so this isn't needed,
					;   but shown for completeness..
	not.b	(tios::main_LCD)	; Blink some pixels in upper left of
LCD

	movem.l	(a7)+,d0-d7/a0-a6	; Restore registers (must match
					;   previous register list!!!)
	rte				; Return from exception


  Well, that should get you closer to the goal at least.  Let me know if it
needs tweaking.  $Auto_Int5 should be (I think) $74.  Also, I don't know if
tios::main_LCD is the actual name of the macro, look it up in TIOS.h...
  This program will blink the upper left line of pixels 20 times a second while
something is going on in the main program.  Just insert a flib::pause or
flig:getkey in there to see it in action.


--Bryan
bcturner@eos.ncsu.edu


Follow-Ups: References: