Shop OBEX P1 Docs P2 Docs Learn Events
Assembly-language use of Smart Pin repository? — Parallax Forums

Assembly-language use of Smart Pin repository?

I have tried to write a program that demonstrates how to set up and use a Smart-Pin repository:
' Simple I/O program for Propeller P2 EVAL board.  05-03-2020
con
	_clkfreq = 160_000_000
dat
	org	0	  	' Save program starting at cog RAM address 0
				' Use P12 as a Smart Pin

	wrpin	#jat,     #12	' Set repository mode for Smart Pin P12 [0000_0000_000_0000000000000_00_00001_0]
	
	wxpin  #Alpha,    #12	' Move Alpha to register X at P12
	
	rqpin	#Beta,    #12	' Read data from register at P12

	mov	dirb,    pins	' Set direction for P61..P59 as output (logic-1)
	mov 	outb, 	 Beta   ' Turn some LEDs on
.myloop	nop
jmp 	#.myloop	' infinite loop ends program. Optional

pins	long	$3F00_0000	' Set bits for pins P61..P56 as outputs (LEDs)
Alpha	long	$1500_0000	' LED-on pattern for LEDs, P61, P59, P57 on P2 EVAL Board
Beta	long	$2FFF_FFFF	' Set Beta to turn on only LED P60 if Beta not updated
jat	long	%0000_0000_000_0000000000000_00_00001_0		' Repository-mode bits

I want the program to set the P12 pin (or any pin) as a Smart Pin and then save the value in Alpha in the repository and then fetch the value into Beta. The result should light three of the LEDs on a P2 EVAL board. If Beta does not update, only one LED will turn on. However when the program runs, all six LEDs (P61..P56) light.

I'm new to assembly language on the Prop-2 so I appreciate any help. Thanks. --Jon

Comments

  • evanhevanh Posts: 15,916
    edited 2020-05-01 22:57
    The repo mode is the odd one out when it comes to WXPIN. DIR has to be high before the write works. Best guess is it's because the write will be direct to the Z register.

    EDIT: Oh, and reading further, WRPIN #jat and WXPIN #Alpha and RQPIN #Beta should be WRPIN jat and WXPIN Alpha and RQPIN Beta, without the "#".

  • Thanks for such a quick response. I'll follow your suggestion with the DIR setting. I always appreciate your help. --Jon
  • evanhevanh Posts: 15,916
    Try this:
    ' Simple I/O program for Propeller P2 EVAL board.  05-03-2020
    con
    	_clkfreq = 160_000_000
    dat
    	org	0	  	' Save program starting at cog RAM address 0
    				' Use P12 as a Smart Pin
    
    	wrpin	#%10,     #12	' Set repository mode for Smart Pin P12 [0000_0000_000_0000000000000_00_00001_0]
    	dirh	#12
    
    	wxpin  Alpha,    #12	' Move Alpha to register X at P12
    	
    	rqpin	Beta,    #12	' Read data from register at P12
    
    	mov	dirb,    pins	' Set direction for P61..P59 as output (logic-1)
    	mov 	outb, 	 Beta   ' Turn some LEDs on
    .myloop	nop
    jmp 	#.myloop	' infinite loop ends program. Optional
    
    pins	long	$3F00_0000	' Set bits for pins P61..P56 as outputs (LEDs)
    Alpha	long	$1500_0000	' LED-on pattern for LEDs, P61, P59, P57 on P2 EVAL Board
    Beta	long	$2FFF_FFFF	' Set Beta to turn on only LED P60 if Beta not updated
    
    
  • ozpropdevozpropdev Posts: 2,792
    edited 2020-05-01 23:09
    If you do a RDPIN straight after the wxpin you will miss the data before its latched.
    Try this.
    	wrpin	jat,     #12	' Set repository mode for Smart Pin P12 [0000_0000_000_0000000000000_00_00001_0]
    	dirh	#12
    
    	wxpin  Alpha,    #12	' Move Alpha to register X at P12
    
    here		testp	#12 wc	'is data available in repo?
    	if_nc	jmp	#here
    
    	rqpin	Beta,    #12	' Read data from register at P12
    
    	mov	dirb,    pins	' Set direction for P61..P59 as output (logic-1)
    	mov 	outb, 	 Beta   ' Turn some LEDs on
    .myloop	nop
    jmp 	#.myloop	' infinite loop ends program. Optional
    
    
  • evanhevanh Posts: 15,916
    That's what's called a gotcha. :)
  • IIRC you have to allow 5? clocks with smart pins for things lie AKPIN before you see the change with a TESTP etc.
  • I envision was a code editor that would notice things like writing to a pin and then immediately reading back, and do some kind of highlighting or graphics to indicate that it didn't get there yet, and thus it's probably not something you wanted to do.

    Or relatedly the cordic results falling off into oblivion. If you think of the vertical as a time scale, there could be some kind of signal ready graphical lines or hints. Just thinking out loud.

    Or again here flag the questionable use of # on a label that is unambiguously being used as a data register. Or hover over the label in the instruction and see an address value instead of the data pointed at.

    Code text editors are stuck in 1978. It's really time for some radical thinking.
  • ozpropdev wrote: »
    IIRC you have to allow 5? clocks with smart pins for things lie AKPIN before you see the change with a TESTP etc.
    From the docs under smart pins
    After WRPIN/WXPIN/WYPIN/RDPIN/AKPIN, it will take two clocks for IN to drop, before it can be polled again:

    So a 1 instruction spacer is all that is needed.
    	wxpin  Alpha,    #12	' Move Alpha to register X at P12
    	nop
    	rqpin	Beta,    #12	' Read data from register at P12
    
  • whicker, a good comment about an editor. Such an editor would need awareness of the assembly-language rules. A "code aware" editor.

    ozpropdev, appreciate your NOP addition.

    All: It might be good to have a list of all the Propeller-2 registers.
  • ElectrodudeElectrodude Posts: 1,657
    edited 2020-05-16 21:39
    I've long wanted to write a Spin compiler, or at least an assembler, based upon differential execution, which was invented for only redrawing the parts of GUIs that have changed. It would have a built-in editor, or would pretend to be a syntax highlighter inside another editor. Whenever you make any change, it will recompile just the parts that are necessary, which should be easy using DE. This would not only make compilation instantaneous (or, rather, amortized over your editing time), but it would allow the editor to be fully aware of the meaning of the source code.

    Unfortunately, it probably won't happen until I'm retired in several decades.
Sign In or Register to comment.