Shop OBEX P1 Docs P2 Docs Learn Events
RESOLVED: v4 FPGA bug?? Not handling non-aligned HUB execution — Parallax Forums

RESOLVED: v4 FPGA bug?? Not handling non-aligned HUB execution

mindrobotsmindrobots Posts: 6,506
edited 2015-11-09 21:48 in Propeller 2
***ISSUE HAS BEEN RESOLVED WITH FIX IN V4 FPGA IMAGE ***


Chip,

This testing triggered from this post in the "FPGA Files" thread.

78RPM had a hub exec routine that started at $43d2 that was failing. I tried it with my smaller hub exec loop back test and found that it did not work on v4 with unaligned instructions but worked on v3 with unaligned instructions. To fix v4, we were able to put an ALIGNL before the instruction but in 78rpm's and probably OzPropDev's programs, that is impractical.

It looks like we lost unaligned hub exec in v4.

The program below works on v3 without the ALIGNL but only work on V4 with the ALIGNL.
con
	SYS_CLK = 50_000_000
	BAUD_RATE = 115_200

	RX_PIN = 63
	TX_PIN = 62

dat
	orgh	0



	org	0
	jmp	#@cog_entry

' these need to stay here (under org 0) so they are in COGRAM and get initialized
bit_time	long	SYS_CLK / BAUD_RATE
tx_char		res	1
timer		res	1
rx_char		res	1

' plenty of room to play in High HUBRAM (COG0 in HUBEXEC at this point)
		orgh	$4300
cog_entry
	setb	outb, #TX_PIN
	setb	dirb, #TX_PIN

'*******************************************************
'********* TEST CODE - PUT YOUR CODE HERE **************
' ***** try some input/output
loopback

		call	#@rcv_char
		mov	tx_char, rx_char
		call	#@send_char
		jmp	#@loopback

'********* TEST CODE - REPLACE WITH YOUR CODE ***********
'********************************************************
	


'*******************************************************************************
' Get one character from the input port.
' Input none
' Changes parm, temp, temp1, temp2
' Output parm
'*******************************************************************************
		orgh	$43d2   ' this works with v3 FPGA image
'		ALIGNL          ' needed with _v4 FPGA image
rcv_char                  
		setedg	#%0_10_000000 | RX_PIN		'select negative edge on p63

		polledg				'clear edge detector
		waitedg				'wait for start bit

		waitx	bit_time		'wait for middle of 1st data bit

		rep	@.rep,#8		'ready for 8 bits
		testb	inb,#RX_PIN	wc	'sample rx
		rcr	rx_char,#1		'rotate bit into byte
		waitx	bit_time	'wait for middle of nth data bit
.rep
		shr	rx_char,#32-8		'justify received byte
		ret


'*******************************************************************************
' Output a single character to the tx_pin.
' executes in COG mode
' Input: txchar - character to be sent
' Changes parm, temp1, temp2
' Output none             
'*******************************************************************************

send_char	setb	tx_char,#8
		shl	tx_char,#1
		getct	timer

		rep	@.txrep,#10
		testb	tx_char,#0 wz
		setbnz	outb,#TX_PIN
		addct1	timer,bit_time
		waitct1
		shr	tx_char,#1
.txrep
		ret

Comments

  • And appears to hang in the rcv_char routine at WAITEDG - coming out of a low power mode?
  • Thanks! I forgot to add that to my draft before posting.
  • mindrobots wrote: »
    Thanks! I forgot to add that to my draft before posting.
    I'm in as well as long as the recent flurry of changes hasn't broken anything that PropGCC needs. I don't think they did but I haven't had the time to keep up with all of the changes to be sure. When a new instruction set document becomes available, I'll start again.

  • David Betz wrote: »
    mindrobots wrote: »
    Thanks! I forgot to add that to my draft before posting.
    I'm in as well as long as the recent flurry of changes hasn't broken anything that PropGCC needs. I don't think they did but I haven't had the time to keep up with all of the changes to be sure. When a new instruction set document becomes available, I'll start again.
    On a slightly off topic comment, I have some code passing arguments on the stack using ptrs which I can post in a seperate thread if you like. I use CONstants as the offsets to the arguments.
  • This guy is smaller and jumps past mis-alligned code to make sure it all gets loaded. IT kind of muddies that water a bit, though. The 'jmp back2cog' should be just as misaligned as the first instruction of the isr but it executes which the first instruction of the isr doesn't. At this point, I'm confused except the ALIGNL fixes it in both cases for v4. It also works fine in v3 without the ALIGNL.
    con
    main_led	=	0
    isr_led		=	1
    
    dat
    		orgh	0
    
    		org	0
    
    start
    		jmp	#@hubexec
    back2cog
    		setb	dirb,#main_led
    		setb	dirb,#isr_led
    		getct	isrticks
    		addct1	isrticks,isr_wait
    		loc	adra,#@isr
    		mov	ijmp1,adra
    		setint1	#1
    
    blink		
    		notb	outb,#main_led		'flip its output state
    		waitx	main_wait		' WAITX blocks interrupts
    		jmp	#blink		'do it again
    		
    
    isr_wait	long	50_000_000
    main_wait	long	5_000_000
    isrticks	long	0
    isr_in_hub	long	0
    
    		orgh	$402
    '		ALIGNL			' needed to work on V4 FPGA
    isr
    		notb	outb,#isr_led
    		addct1	isrticks, isr_wait
    		reti1
    
    hubexec		jmp	#back2cog
    

    *I would think I would go to the bad instruction (mis-aligned) in the isr and the program would just go off in the weeds never finding a properly aligned iret.
  • cgraceycgracey Posts: 14,133
    Try adding this one line to the end of any programs having trouble:

    long 0[16]

    The latest PNut.exe only downloads what data was emitted, as opposed to the whole hub image.

    Maybe there is a problem with the new WFBYTE flushing properly.

    By adding extra data, it will ensure that the data of importance is full downloaded.

    If that 'long 0[16]' works, see if 'byte 0' works, as well.
  • cgracey wrote: »
    Try adding this one line to the end of any programs having trouble:

    long 0[16]

    The latest PNut.exe only downloads what data was emitted, as opposed to the whole hub image.

    Maybe there is a problem with the new WFBYTE flushing properly.

    By adding extra data, it will ensure that the data of importance is full downloaded.

    If that 'long 0[16]' works, see if 'byte 0' works, as well.
    Neither work on my piece of code. What about that WAITEDG idea?
  • No change with 'long 0[16]' at the end of above test program.
  • As indicated by my puzzlement above,

    a JMP to a non-long aligned address works, a CALL/INT to a non-long aligned address does not work *BUT* somehow it figures out alignment with the next instruction fetch because when I insert a NOP as the first instruction of isr, it DOES work.
    		orgh	$402
    isr
    		nop                          ' it appears to skip this inst and get next non-aligned
    		notb	outb,#isr_led
    		addct1	isrticks, isr_wait
    		reti1
    
  • cgraceycgracey Posts: 14,133
    edited 2015-11-09 18:24
    I'm seeing the problem in the last example.

    If I make the 'hubexec jmp #back2cog' line at offset 3, nothing works.

    I must find out what I broke. This most likely has something to do with the modifications I just made to the FIFO code to get partial data to write ASAP. I'm looking into it now.

    Sorry about this. Hopefully, we'll get this squirt away in the next hour.
  • No worries. Glad we could narrow it down to a few lines of code.
  • cgraceycgracey Posts: 14,133
    I think I found the problem. I was letting RDFAST release one clock too early. I put it back the way it was and I'm recompiling now.
  • cgracey wrote: »
    I think I found the problem. I was letting RDFAST release one clock too early. I put it back the way it was and I'm recompiling now.

    My program does not use RDFAST unless:
                    loc     ptrb, #cog_start
                    setq    #(cog_end-cog_start)    ' thank you Searith
                    rdlong  0, PTRB 
    
    invokes RDFAST action?
  • I'm guessing RDFAST pieces are used in grabbing code for HUB exec. I don't use RDFAST either. The programs certainly use HUB exec.
  • cgraceycgracey Posts: 14,133
    That fixed it! Recompiling FPGA images now...
  • Chip, last time I did stuff like this, it was with mainframes the size of grocery store refrigerator cases...if we found something, it took several engineers, pages of schematics (yes, on paper) and a few feet of wire wrap and a trip INSIDE the computer! :)

    This is easier!
  • cgracey wrote: »
    That fixed it! Recompiling FPGA images now...

    Excellent!

    In future, may I ask you to issue Bug Request forms to the testers to give us a sporting chance? :smile: It is considered good engineering practice! You can obtain the next Bug Request number by:
    	getct	bug_request
    	getrnd	bug_request
    
  • You want us to REQUEST that Chip makes bugs??? :) That will really make his job fun!

    How about Bug Reports?? :)
  • It is a really simple system, it would help us if we knew in advance where to look for the bugs :smile: Every now and again, like today's hunt, he can throw in a goody! Every other company uses Bug Reports, we can be different.

    Of course, I should really follow my own advice and raise Requests when I encounter coding problems, rather than blame the hardware. However, as everyone here knows, my code is laughable pointless abysmal feature rich and perfect! (BwaHaHaHaHaHaHA!)
  • cgraceycgracey Posts: 14,133
    78rpm wrote: »
    cgracey wrote: »
    I think I found the problem. I was letting RDFAST release one clock too early. I put it back the way it was and I'm recompiling now.

    My program does not use RDFAST unless:
                    loc     ptrb, #cog_start
                    setq    #(cog_end-cog_start)    ' thank you Searith
                    rdlong  0, PTRB 
    
    invokes RDFAST action?

    Every branch into hub invokes a hidden RDFAST, though.
  • cgracey wrote: »
    78rpm wrote: »
    cgracey wrote: »
    I think I found the problem. I was letting RDFAST release one clock too early. I put it back the way it was and I'm recompiling now.

    My program does not use RDFAST unless:
                    loc     ptrb, #cog_start
                    setq    #(cog_end-cog_start)    ' thank you Searith
                    rdlong  0, PTRB 
    
    invokes RDFAST action?

    Every branch into hub invokes a hidden RDFAST, though.
    Okay, and that would also include hub *within* hub calls, which would need to fetch instructions, hence the problem.
  • V4B FPGA image fixes this problem. Target instruction works on any byte boundary now!

    Thanks, Chip!!
  • I replied on the FPGA Files thread as that was where the update message was posted, works for me too. Thank you!
  • cgraceycgracey Posts: 14,133
    I posted new files that properly differentiate the Terasic boards under PNut.exe.

    If anyone is using a DE2-115 or a DE0-Nano, they need the newer files.
Sign In or Register to comment.