toutdram.s 2.71 KB

#include <rsp.h>
#include "mbi.h"
#include "tdmem_label.h"	
#include "tst_regs.h"


 ############################################################################
 #
 # Output coordination routines:
 #
 # We support two cases:
 #
 #	1.) output directly to RDP using DMEM as buffer. Requires
 #	    producer/consumer synchronization.
 #
 #	2.) output routed to DRAM. In this case, we use DMEM as
 #	    a temporary buffer, then DMA out to DRAM.
 #
 # Goals:
 #
 #	- small code size.
 #	- efficient and non-obtrusive
 #	- flexible, can easily route to DRAM or RDP.
 #
 # In order to do this, and make it transparent to the parts of the
 # code which do the writing, we implement an open/close interface.
 #
 # FUNCTION:	    OUTPUT TO RDP:		    OUTPUT TO DRAM:
 #-------------------------------------------------------------------------
 # open(size)	- wait for size avail in	- does nothing
 #		  ring buffer.
 #		- possibly handle wrap
 #		- wait for 'current' to get
 #		  out of the way
 #
 # close()	- advance CP0 pointer		- do DMA of cmd to DRAM
 #						- increment pointers
 #						- reset DMEM buffer
 #
 # In between the open() and close(), the ucode writes the data to DMEM.
 # (to either the RDP ring buffer or a temp buffer to be DMA'd)
 #
 ############################################################################

	#
	# These registers used by both routines.
	#
.name	dmemp, 		$20
.name	dramp, 		$19
.name	outsz, 		$18 # set by caller to max size to write
	
 ############################################################################
 #
 #
 #
		.ent	OutputOpen
	
OutputOpen:
		jr	return
		nop

		.end	OutputOpen
 #
 #
 #
 ############################################################################

	
		
 ############################################################################
 #
 #
 #
		.ent	OutputClose
	
OutputClose:
		lw	dramp, RSP_STATE_DRAM_OUTP(rsp_state)
		addi	dmemp, zero, RSP_OUTPUT_OFFSET
	
.name	outlen,		$17
		lw	outlen, (RSP_STATE_DRAM_OUT_LEN+4)(rsp_state)
		sub	outsz, outp, dmemp
		add	outlen, outlen, outsz
		sw	outlen, (RSP_STATE_DRAM_OUT_LEN+4)(rsp_state)
		addi	outsz, outsz, -1
.unname	outlen

	# DEBUG:
	# safety precaution, only do DMA if outsz >= 0
		bltz	outsz, OutputDone
		add	$21, zero, return
	# if outsz < 0, we will drop data on the floor

	OutputData:
		jal	DMAproc
		addi	$17, zero, 1	# set 'iswrite'
		jal	DMAwait
		nop

	# update pointers...
	# (dmemp gets trashed in DMAwait routine...)
	OutputDone:
		addi	outp, zero, RSP_OUTPUT_OFFSET
		add	dramp, dramp, outsz
		addi	dramp, dramp, 1
		jr	$21
		sw	dramp, RSP_STATE_DRAM_OUTP(rsp_state)
	
		.end	OutputClose
	
		nop
		nop
		nop
		nop
 #
 #
 #
 ############################################################################

.unname	outsz
.unname	dramp
.unname	dmemp