# File: downlink_v05.src
#
program "%Z% MODULE: %M% RELEASE: %R%.%L% CREATED: %G% %U%"
source "/mdisw/cfl/flight/src/downlink_v05.src"
descr "Loads IP queue instructions"
#=======================================================
#
#
#;
#; FILE:    downlink.ips
#; PURPOSE: To dowlink a single data product in page 8 or two prod
#;	   When on the redundant side, use pages 12 and 13.
#; METHOD:  
#;	Input:	$IPRL_DL_PARAM		- high word of page to downlink
#;		$IPRL_DL_PARAM+1	- OPTIONAL high word of second page to downli
#; HISTORY: Written 25-Aug-95 by M.Morrison
#;	   30-Aug-95 (MDM) - Changed the name and allowed either of the
#;			     two pages to be downlinked 
#;	    7-Sep-95 (MDM) - Changes to make it work
#;	   18-Sep-95 (MDM) - More changes to get it to work
#;	   18-Oct-95 (MDM) - Moved how 550 word math is done
#;			   - Called subroutine to check if the previous downlink is f
#;			     and to abort it if it is not finished
#;			   - Fixed up how HRDINIT work is done (in other routines)
#;	   26-Oct-95 (MDM) - Corrected error where I was looking at R30
#;			     instead of R3075 (DEP Reg 3) to see if VC mode was activ
#;          16-Nov-95 (MDM) - Removed all debug statements
#;	   29-Jan-96 (MDM) - Added setting of R26 before savemode call 
#;			     start downlink
#;			   - Added SAVEMODE instruction after call to RESET_TLM.  It
#;			     only takes effect if RESET_TLM found a problem and set R
#;			   - Corrected the re-try logic
#;			   - Added a wait between the SAVEMODE and retry
#;
#QSR_DL_1PAGE::
#    SETREG $IPRL_DL_NPAGE 1
tcblock mbipmacl 0x0DA0    0x0140 0x11D3 0x0001 
#    GOTO &COMMON_CODE
tcblock mbipmacl 0x0DA3    0x0156 0x0DAA 
#
#QSR_DL_2PAGE::
#    SETREG $IPRL_DL_NPAGE 2
tcblock mbipmacl 0x0DA5    0x0140 0x11D3 0x0002 
#    GOTO &COMMON_CODE
tcblock mbipmacl 0x0DA8    0x0156 0x0DAA 
#
#COMMON_CODE:
#    SETREG   $IPRL_DL_CHECKED 0				;Initialized the "waited alrea
tcblock mbipmacl 0x0DAA    0x0140 0x11E7 0x0000 
#
#    BRANCHIF  R3075  &DONE				;if no VC = 0 then don't bother
tcblock mbipmacl 0x0DAD    0x015A 0x0C03 0x0E9F 
#
#    SETREGS $IPRL_DL_DLPAGE_LST 2 0x4000 0x4800		;pages 8 and 9 a
tcblock mbipmacl 0x0DB0    0x01B2 0x11D4 0x0002 0x4000 \
                                0x4800 
#    BRANCHEQ  R33    0   &USE_PRIMARY_LST
tcblock mbipmacl 0x0DB5    0x01AE 0x0021 0x0000 0x0DBE 
#    SETREGS $IPRL_DL_DLPAGE_LST 2 0x6000 0x6800		;pages 12 and 13
tcblock mbipmacl 0x0DB9    0x01B2 0x11D4 0x0002 0x6000 \
                                0x6800 
#USE_PRIMARY_LST:
#
#    COPYREG $IPRL_DL_DLPAGE_LST   $IPRL_TLM_PAGE
tcblock mbipmacl 0x0DBE    0x0142 0x11D4 0x1388 
#    CALLQUE $QSR_TLM_RESET				;check to see if there is something
tcblock mbipmacl 0x0DC1    0x01F8 0x0B80 
#    SAVEMODE						;abort if necessary
tcblock mbipmacl 0x0DC3    0x01E6 
#    COPYREG $IPRL_DL_DLPAGE_LST+1 $IPRL_TLM_PAGE	
tcblock mbipmacl 0x0DC4    0x0142 0x11D5 0x1388 
#    CALLQUE $QSR_TLM_RESET
tcblock mbipmacl 0x0DC7    0x01F8 0x0B80 
#    SAVEMODE
tcblock mbipmacl 0x0DC9    0x01E6 
#
#    SETREG  $IPRL_DL_LOOP 0				;first loop through
tcblock mbipmacl 0x0DCA    0x0140 0x11D2 0x0000 
#    COPYREG $IPRL_DL_DLPAGE_LST $IPRL_DL_DLPAGE		;one downlink pa
tcblock mbipmacl 0x0DCD    0x0142 0x11D4 0x11D6 
#    COPYREG $IPRL_DL_PARAM $IPRL_DL_INPAGE		;copy the input sourc
tcblock mbipmacl 0x0DD0    0x0142 0x11D0 0x11D7 
#    SETREG  $IPRP_DL_NWORDS_PNTR $IPRL_DL_NWORDS	;where to save t
tcblock mbipmacl 0x0DD3    0x0140 0x11D8 0x11D9 
#
#LOOP_CODE:
#    ;-------- decode the source page info
#    COPYREG  $IPRL_DL_INPAGE  $IPRL_HDECODE_PARAM  ;copy the sour
tcblock mbipmacl 0x0DD6    0x0142 0x11D7 0x114A 
#    SETREG   $IPRL_HDECODE_PARAM+1 0x0000               ;there is
tcblock mbipmacl 0x0DD9    0x0140 0x114B 0x0000 
#							;CAUTION: HDECODE copies the source params into the destin
#    CALLQUE  $QSR_DO_HDECODE                            ;decode t
tcblock mbipmacl 0x0DDC    0x01F8 0x1010 
#
#    COPYRI2D $IPRP_HDECODE_ADDR $IPRL_HEAD_WORK 10	;copy the regi
tcblock mbipmacl 0x0DDE    0x01AC 0x1151 0x1155 0x000A 
#
#    ;------- Copy the data to the downlink page (if necessary)
#
#    COPYRD2D $IPRL_HEAD_WORK $IPRL_DL_COPY 3		;copy the source pa
tcblock mbipmacl 0x0DE2    0x0144 0x1155 0x11E0 0x0003 
#    ;;ADDADR   $IPRL_DL_COPY $IPRL_NEG_550W $IPRL_DL_COPY  ;shift
#    REGADD   $IPRL_DL_COPY $IPRL_NEG_550W $IPRL_DL_COPY    ;shift
tcblock mbipmacl 0x0DE6    0x0146 0x11E0 0x1167 0x11E0 
#    SETREG   $IPRL_DL_COPY+2 0				;set the destination low word t
tcblock mbipmacl 0x0DEA    0x0140 0x11E2 0x0000 
#    COPYREG  $IPRL_DL_DLPAGE $IPRL_DL_COPY+3 		;copy the high wor
tcblock mbipmacl 0x0DED    0x0142 0x11D6 0x11E3 
#    COPYRD2D $IPRL_HEAD_WORK+8 $IPRL_DL_COPY+4 3	;copy the number
tcblock mbipmacl 0x0DF0    0x0144 0x115D 0x11E4 0x0003 
#    COPYRD2I $IPRL_DL_COPY+4  $IPRP_DL_NWORDS_PNTR 3	;copy how ma
tcblock mbipmacl 0x0DF4    0x01AA 0x11E4 0x11D8 0x0003 
#    ADDADR   $IPRL_DL_COPY+4  $IPRL_POS_550W $IPRL_DL_COPY+4     
tcblock mbipmacl 0x0DF8    0x0148 0x11E4 0x1165 0x11E4 
#
#
#    ;------- Check to see if a copy is even needed
#    REGSUB   $IPRL_HEAD_WORK+1 $IPRL_DL_DLPAGE $IPRL_DL_TEMP	;com
tcblock mbipmacl 0x0DFC    0x2146 0x1156 0x11D6 0x11DF 
#    BRANCHEQ $IPRL_DL_TEMP 0 &NO_COPY_NEEDED		;if data is already
tcblock mbipmacl 0x0E00    0x01AE 0x11DF 0x0000 0x0E06 
#
#    _MOVBLKI $IPRL_DL_COPY				;move the data to the page
tcblock mbipmacl 0x0E04    0x8166 0x11E0 
#
#NO_COPY_NEEDED:
#    BRANCHEQ $IPRL_DL_NPAGE 1 &DL1PAGE
tcblock mbipmacl 0x0E06    0x01AE 0x11D3 0x0001 0x0E4E 
#
#    COPYREG  $IPRL_DL_DLPAGE_LST+1 $IPRL_DL_DLPAGE	;one downlink 
tcblock mbipmacl 0x0E0A    0x0142 0x11D5 0x11D6 
#    COPYREG  $IPRL_DL_PARAM+1 $IPRL_DL_INPAGE		;copy the input so
tcblock mbipmacl 0x0E0D    0x0142 0x11D1 0x11D7 
#    SETREG   $IPRP_DL_NWORDS_PNTR $IPRL_DL_NWORDS+3	;where to sav
tcblock mbipmacl 0x0E10    0x0140 0x11D8 0x11DC 
#
#    ADDREGD  $IPRL_DL_LOOP 1				;increment the loop counter
tcblock mbipmacl 0x0E13    0x01BC 0x11D2 0x0001 
#    BRANCHEQ $IPRL_DL_LOOP 1 &LOOP_CODE			;do the copy portion of
tcblock mbipmacl 0x0E16    0x01AE 0x11D2 0x0001 0x0DD6 
#
#
#    ;------------ Two page downlink command 
#DL2PAGE:
#    BRANCHEQ  $IPRL_HEAD_WORK+3 0 &DL2_RAW
tcblock mbipmacl 0x0E1A    0x01AE 0x1158 0x0000 0x0E36 
#
#DL2_COMP:					;--------------- Downlink 2 Pages in COMPRESSED mod
#    BRANCHEQ  R33    0   &DL2_COMP_PRIM
tcblock mbipmacl 0x0E1E    0x01AE 0x0021 0x0000 0x0E2C 
#
#DL2_COMP_REDUN:
#    GETQADR  $IPRL_DL_QADDR_REDO
tcblock mbipmacl 0x0E22    0x015C 0x11E8 
#    START2HR 0x49 0x6000 0x6800 $IPRL_DL_NWORDS $IPRL_DL_NWORDS+3
tcblock mbipmacl 0x0E24    0x019A 0x0049 0x6000 0x6800 \
                                0x11D9 0x11DC 
#    GOTO &WAITING
tcblock mbipmacl 0x0E2A    0x0156 0x0E7A 
#
#DL2_COMP_PRIM:
#    GETQADR  $IPRL_DL_QADDR_REDO
tcblock mbipmacl 0x0E2C    0x015C 0x11E8 
#    START2HR 0x49 0x4000 0x4800 $IPRL_DL_NWORDS $IPRL_DL_NWORDS+3
tcblock mbipmacl 0x0E2E    0x019A 0x0049 0x4000 0x4800 \
                                0x11D9 0x11DC 
#    GOTO &WAITING
tcblock mbipmacl 0x0E34    0x0156 0x0E7A 
#
#DL2_RAW:					;--------------- Downlink 2 Pages in RAW mode
#    BRANCHEQ  R33    0   &DL2_RAW_PRIM
tcblock mbipmacl 0x0E36    0x01AE 0x0021 0x0000 0x0E44 
#
#DL2_RAW_REDUN:
#    GETQADR  $IPRL_DL_QADDR_REDO
tcblock mbipmacl 0x0E3A    0x015C 0x11E8 
#    START2HR 0x4b 0x6000 0x6800 $IPRL_DL_NWORDS $IPRL_DL_NWORDS+3
tcblock mbipmacl 0x0E3C    0x019A 0x004B 0x6000 0x6800 \
                                0x11D9 0x11DC 
#    GOTO &WAITING
tcblock mbipmacl 0x0E42    0x0156 0x0E7A 
#
#DL2_RAW_PRIM:
#    GETQADR  $IPRL_DL_QADDR_REDO
tcblock mbipmacl 0x0E44    0x015C 0x11E8 
#    START2HR 0x4b 0x4000 0x4800 $IPRL_DL_NWORDS $IPRL_DL_NWORDS+3
tcblock mbipmacl 0x0E46    0x019A 0x004B 0x4000 0x4800 \
                                0x11D9 0x11DC 
#    GOTO &WAITING
tcblock mbipmacl 0x0E4C    0x0156 0x0E7A 
#
#    ;------------ One page downlink command section
#DL1PAGE:
#    BRANCHEQ  $IPRL_HEAD_WORK+3 0 &DL1_RAW
tcblock mbipmacl 0x0E4E    0x01AE 0x1158 0x0000 0x0E66 
#
#DL1_COMP:					;--------------- Downlink 1 Page in COMPRESSED mode
#    BRANCHEQ  R33    0   &DL1_COMP_PRIM
tcblock mbipmacl 0x0E52    0x01AE 0x0021 0x0000 0x0E5E 
#
#DL1_COMP_REDUN:
#    GETQADR  $IPRL_DL_QADDR_REDO
tcblock mbipmacl 0x0E56    0x015C 0x11E8 
#    START1HR 0x01 0x6000 $IPRL_DL_NWORDS
tcblock mbipmacl 0x0E58    0x0174 0x0001 0x6000 0x11D9 
#    GOTO &WAITING
tcblock mbipmacl 0x0E5C    0x0156 0x0E7A 
#
#DL1_COMP_PRIM:
#    GETQADR  $IPRL_DL_QADDR_REDO
tcblock mbipmacl 0x0E5E    0x015C 0x11E8 
#    START1HR 0x01 0x4000 $IPRL_DL_NWORDS
tcblock mbipmacl 0x0E60    0x0174 0x0001 0x4000 0x11D9 
#    GOTO &WAITING
tcblock mbipmacl 0x0E64    0x0156 0x0E7A 
#
#DL1_RAW:					;--------------- Downlink 1 Page in RAW mode
#    BRANCHEQ  R33    0   &DL1_RAW_PRIM
tcblock mbipmacl 0x0E66    0x01AE 0x0021 0x0000 0x0E72 
#
#DL1_RAW_REDUN:
#    GETQADR  $IPRL_DL_QADDR_REDO
tcblock mbipmacl 0x0E6A    0x015C 0x11E8 
#    START1HR 0x03 0x6000 $IPRL_DL_NWORDS
tcblock mbipmacl 0x0E6C    0x0174 0x0003 0x6000 0x11D9 
#    GOTO &WAITING
tcblock mbipmacl 0x0E70    0x0156 0x0E7A 
#
#DL1_RAW_PRIM:
#    GETQADR  $IPRL_DL_QADDR_REDO
tcblock mbipmacl 0x0E72    0x015C 0x11E8 
#    START1HR 0x03 0x4000 $IPRL_DL_NWORDS
tcblock mbipmacl 0x0E74    0x0174 0x0003 0x4000 0x11D9 
#    GOTO &WAITING
tcblock mbipmacl 0x0E78    0x0156 0x0E7A 
#
#WAITING:					;-------------- Check to see that the downlink actua
#    BRANCHEQ $IPRL_DL_CHECKED 1 &DONE		;already did the wait once
tcblock mbipmacl 0x0E7A    0x01AE 0x11E7 0x0001 0x0E9F 
#    SETREG   $IPRL_DL_CHECKED 1
tcblock mbipmacl 0x0E7E    0x0140 0x11E7 0x0001 
#
#    SETREG  R143 16
tcblock mbipmacl 0x0E81    0x0140 0x008F 0x0010 
#    PURGELST R136				;wait 82 msec before checking the page
tcblock mbipmacl 0x0E84    0x0190 0x0088 
#
#    BRANCHEQ  R33    0   &CHECK_PRIM
tcblock mbipmacl 0x0E86    0x01AE 0x0021 0x0000 0x0E8F 
#
#CHECK_REDUN:
#    BRANCHNR 0x6000 &DONE			;The page got busy ==> all ok
tcblock mbipmacl 0x0E8A    0x01A6 0x6000 0x0E9F 
#    GOTO &PROBLEM
tcblock mbipmacl 0x0E8D    0x0156 0x0E94 
#
#CHECK_PRIM:
#    BRANCHNR 0x4000 &DONE			;The page got busy ==> all ok
tcblock mbipmacl 0x0E8F    0x01A6 0x4000 0x0E9F 
#    GOTO &PROBLEM
tcblock mbipmacl 0x0E92    0x0156 0x0E94 
#
#PROBLEM:
#    SETREG  R26 1
tcblock mbipmacl 0x0E94    0x0140 0x001A 0x0001 
#    SAVEMODE					;save the state, throw an error and reset the IP
tcblock mbipmacl 0x0E97    0x01E6 
#
#    SETREG  R143 16
tcblock mbipmacl 0x0E98    0x0140 0x008F 0x0010 
#    PURGELST R136				;wait 82 msec before retrying
tcblock mbipmacl 0x0E9B    0x0190 0x0088 
#
#    GOTOREG $IPRL_DL_QADDR_REDO			;Go back and issue the command 
tcblock mbipmacl 0x0E9D    0x0158 0x11E8 
#
#DONE:
#    RTNQUE
tcblock mbipmacl 0x0E9F    0x01FA 
#=======================================================
#
return
#
#=======================================================
