Shop OBEX P1 Docs P2 Docs Learn Events
Resolved: Does/should WAITX block interrupts? (yes!) — Parallax Forums

Resolved: Does/should WAITX block interrupts? (yes!)

mindrobotsmindrobots Posts: 6,506
edited 2015-10-29 18:33 in Propeller 2
The interrupt system is awesome...more on that later.

While playing, I came up with this little test program:
con
main_led	=	0
isr_led		=	1

dat
		orgh	0

		org

start
		setb	dirb,#main_led
		setb	dirb,#isr_led
		getcnt	isrticks
		addct1	isrticks,isr_wait
		mov	ijmp1,#isr
		setint1	#1

blink		
		notb	outb,#main_led		'flip its output state
		waitx	main_wait		'wait that many clocks
		jmp	#blink		'do it again
isr
		notb	outb,#isr_led
		addct1	isrticks,isr_wait
		reti1


' works as expected with main wait shorter than ISR wait
isr_wait	long	25_000_000
main_wait	long	5_000_000

' comment above and uncomment below to see 
' main wait longer than ISR wait
'isr_wait	long	5_000_000
'main_wait	long	25_000_000

isrticks	res	1

as it is above, it sets up INT1 on CT1 with a 1/2 second blinking LED1, the main routine has a 1/10th second loop based on a WAITX. That works just fine and shows the expected results. (and makes you realize how much cooler Propeller2 interrupts are than the ones the other kids have!) When you look at the blinking lights, and realize it is a Propeller and WHY the lights are blinking...it kind of sends a thrill through your body!

If you comment out the first set of main_wait and isr_wait and uncomment the second set so the ISR gets triggered every 1/10th and the main loop sits on a 1/2 second WAITX, things don't work as expected UNLESS the WAITX is supposed to blocks all interrupts (effectively a STALLI).

Is that expected behavior (may be documented in the P2 threads) or is it an unexpected result? Either way works, it just needs to be documented in its final form.

(I'm really liking 16 cogs, hubexec, 512KB HUB AND interrupts and events........and debug! :) )

Comments

  • Yes, WAITX is a blocking instruction. It is not using the counters. However, using addct2/waitct2 for the main loop won't help you either. waitct2 would also block the ISR. To get around that, you would either need to use pollct2 in the main loop, or else set both of them up as ISRs and use WAITINT in a tight loop in the main loop.
  • Thanks! Once you know it is blocking, the options to get around it are wonderfully amazing.

    Time to play!
Sign In or Register to comment.