Shop Learn
Detecting avualable smart pins on FPGA — Parallax Forums

Detecting avualable smart pins on FPGA

Hi All
I needed to detect what FPGA board my code is running on to automatically switch from bit bang serial to smart pin serial if available.
Also because my code uses the push buttons and these are mapped differently too.
Now I don't have to build different versions for different boards, a lot easier to manage.
'Detect available smart pins on FPGA

'Returns total number of available smart pins
'and a 64 bit mask indicating active smart pins.

dat		org

sp_detect	rep	@search,#64		'test all 64 pins
		mov	dirx,#dira
		testb	smart_pin,#5 wc		'pin 0..31 or pin 32..63?
		setbc	dirx,#0			'dira/dirb select
		wrpin	#%11_0,smart_pin	'long repository mode
		altd	dirx,#0			'set port
		setb	0-0,smart_pin		'enable smart pin
		mov	pattern,##$c0ffee00
		add	pattern,smart_pin	'unique pattern
		wxpin	pattern,smart_pin	'write long to smart pin
		nop				'allow time for smart pin write (needed!)
		rdpin	response,smart_pin	'get long from smart pin repository
		cmp	response,pattern wz	'valid response?
	if_e	add	available,#1
		shr	mask_msb,#1 wc		'build valid smart pin mask
		rcr	mask_lsb,#1
		setbz	mask_msb,#31
		wrpin	#0,smart_pin		'disable smart pin
		altd	dirx,#0			'set port
		clrb	0-0,smart_pin		'reset smart pin
		add	smart_pin,#1		'next smart pin
		or	dirb,##$ffff		'show result on leds (P123-A9/DE2-115)
		mov	outb,available
done		jmp	#done

pattern		long	0
dirx		long	0
response	long	0
mask_lsb	long	0
mask_msb	long	0
smart_pin	long	0
available	long	0


Sign In or Register to comment.