# File: downlink_v04.src
#
program "%Z% MODULE: %M% RELEASE: %R%.%L% CREATED: %G% %U%"
source "/mdisw/cfl/flight/src/downlink_v04_1.src"
descr "Loads IP queue instructions"
#
# DSBQUE                ; Disable Queue
tcblock mbipldin 0x0154 
#
#=======================================================
#
#
#;
#; 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 mbipcmd 0x0091 0x10D6   0x0140 0x11D3 0x0001 
#    GOTO &COMMON_CODE
tcblock mbipcmd 0x0091 0x10D9   0x0156 0x10E0 
#
#QSR_DL_2PAGE::
#    SETREG $IPRL_DL_NPAGE 2
tcblock mbipcmd 0x0091 0x10DB   0x0140 0x11D3 0x0002 
#    GOTO &COMMON_CODE
tcblock mbipcmd 0x0091 0x10DE   0x0156 0x10E0 
#
#COMMON_CODE:
#    SETREG   $IPRL_DL_CHECKED 0				;Initialized the "waited alrea
tcblock mbipcmd 0x0091 0x10E0   0x0140 0x11E7 0x0000 
#
#    BRANCHIF  R3075  &DONE				;if no VC = 0 then don't bother
tcblock mbipcmd 0x0091 0x10E3   0x015A 0x0C03 0x11D5 
#
#    SETREGS $IPRL_DL_DLPAGE_LST 2 0x4000 0x4800		;pages 8 and 9 a
tcblock mbipcmd 0x0091 0x10E6   0x01B2 0x11D4 0x0002 0x4000 \
                                0x4800 
#    BRANCHEQ  R33    0   &USE_PRIMARY_LST
tcblock mbipcmd 0x0091 0x10EB   0x01AE 0x0021 0x0000 0x10F4 
#    SETREGS $IPRL_DL_DLPAGE_LST 2 0x6000 0x6800		;pages 12 and 13
tcblock mbipcmd 0x0091 0x10EF   0x01B2 0x11D4 0x0002 0x6000 \
                                0x6800 
#USE_PRIMARY_LST:
#
#    COPYREG $IPRL_DL_DLPAGE_LST   $IPRL_TLM_PAGE
tcblock mbipcmd 0x0091 0x10F4   0x0142 0x11D4 0x1388 
#    CALLQUE $QSR_TLM_RESET				;check to see if there is something
tcblock mbipcmd 0x0091 0x10F7   0x01F8 0x0B80 
#    SAVEMODE						;abort if necessary
tcblock mbipcmd 0x0091 0x10F9   0x01E6 
#    COPYREG $IPRL_DL_DLPAGE_LST+1 $IPRL_TLM_PAGE	
tcblock mbipcmd 0x0091 0x10FA   0x0142 0x11D5 0x1388 
#    CALLQUE $QSR_TLM_RESET
tcblock mbipcmd 0x0091 0x10FD   0x01F8 0x0B80 
#    SAVEMODE
tcblock mbipcmd 0x0091 0x10FF   0x01E6 
#
#    SETREG  $IPRL_DL_LOOP 0				;first loop through
tcblock mbipcmd 0x0091 0x1100   0x0140 0x11D2 0x0000 
#    COPYREG $IPRL_DL_DLPAGE_LST $IPRL_DL_DLPAGE		;one downlink pa
tcblock mbipcmd 0x0091 0x1103   0x0142 0x11D4 0x11D6 
#    COPYREG $IPRL_DL_PARAM $IPRL_DL_INPAGE		;copy the input sourc
tcblock mbipcmd 0x0091 0x1106   0x0142 0x11D0 0x11D7 
#    SETREG  $IPRP_DL_NWORDS_PNTR $IPRL_DL_NWORDS	;where to save t
tcblock mbipcmd 0x0091 0x1109   0x0140 0x11D8 0x11D9 
#
#LOOP_CODE:
#    ;-------- decode the source page info
#    COPYREG  $IPRL_DL_INPAGE  $IPRL_HDECODE_PARAM  ;copy the sour
tcblock mbipcmd 0x0091 0x110C   0x0142 0x11D7 0x114A 
#    SETREG   $IPRL_HDECODE_PARAM+1 0x0000               ;there is
tcblock mbipcmd 0x0091 0x110F   0x0140 0x114B 0x0000 
#							;CAUTION: HDECODE copies the source params into the destin
#    CALLQUE  $QSR_DO_HDECODE                            ;decode t
tcblock mbipcmd 0x0091 0x1112   0x01F8 0x1010 
#
#    COPYRI2D $IPRP_HDECODE_ADDR $IPRL_HEAD_WORK 10	;copy the regi
tcblock mbipcmd 0x0091 0x1114   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 mbipcmd 0x0091 0x1118   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 mbipcmd 0x0091 0x111C   0x0146 0x11E0 0x1167 0x11E0 
#    SETREG   $IPRL_DL_COPY+2 0				;set the destination low word t
tcblock mbipcmd 0x0091 0x1120   0x0140 0x11E2 0x0000 
#    COPYREG  $IPRL_DL_DLPAGE $IPRL_DL_COPY+3 		;copy the high wor
tcblock mbipcmd 0x0091 0x1123   0x0142 0x11D6 0x11E3 
#    COPYRD2D $IPRL_HEAD_WORK+8 $IPRL_DL_COPY+4 3	;copy the number
tcblock mbipcmd 0x0091 0x1126   0x0144 0x115D 0x11E4 0x0003 
#    COPYRD2I $IPRL_DL_COPY+4  $IPRP_DL_NWORDS_PNTR 3	;copy how ma
tcblock mbipcmd 0x0091 0x112A   0x01AA 0x11E4 0x11D8 0x0003 
#    ADDADR   $IPRL_DL_COPY+4  $IPRL_POS_550W $IPRL_DL_COPY+4     
tcblock mbipcmd 0x0091 0x112E   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 mbipcmd 0x0091 0x1132   0x2146 0x1156 0x11D6 0x11DF 
#    BRANCHEQ $IPRL_DL_TEMP 0 &NO_COPY_NEEDED		;if data is already
tcblock mbipcmd 0x0091 0x1136   0x01AE 0x11DF 0x0000 0x113C 
#
#    _MOVBLKI $IPRL_DL_COPY				;move the data to the page
tcblock mbipcmd 0x0091 0x113A   0x8166 0x11E0 
#
#NO_COPY_NEEDED:
#    BRANCHEQ $IPRL_DL_NPAGE 1 &DL1PAGE
tcblock mbipcmd 0x0091 0x113C   0x01AE 0x11D3 0x0001 0x1184 
#
#    COPYREG  $IPRL_DL_DLPAGE_LST+1 $IPRL_DL_DLPAGE	;one downlink 
tcblock mbipcmd 0x0091 0x1140   0x0142 0x11D5 0x11D6 
#    COPYREG  $IPRL_DL_PARAM+1 $IPRL_DL_INPAGE		;copy the input so
tcblock mbipcmd 0x0091 0x1143   0x0142 0x11D1 0x11D7 
#    SETREG   $IPRP_DL_NWORDS_PNTR $IPRL_DL_NWORDS+3	;where to sav
tcblock mbipcmd 0x0091 0x1146   0x0140 0x11D8 0x11DC 
#
#    ADDREGD  $IPRL_DL_LOOP 1				;increment the loop counter
tcblock mbipcmd 0x0091 0x1149   0x01BC 0x11D2 0x0001 
#    BRANCHEQ $IPRL_DL_LOOP 1 &LOOP_CODE			;do the copy portion of
tcblock mbipcmd 0x0091 0x114C   0x01AE 0x11D2 0x0001 0x110C 
#
#
#    ;------------ Two page downlink command 
#DL2PAGE:
#    BRANCHEQ  $IPRL_HEAD_WORK+3 0 &DL2_RAW
tcblock mbipcmd 0x0091 0x1150   0x01AE 0x1158 0x0000 0x116C 
#
#DL2_COMP:					;--------------- Downlink 2 Pages in COMPRESSED mod
#    BRANCHEQ  R33    0   &DL2_COMP_PRIM
tcblock mbipcmd 0x0091 0x1154   0x01AE 0x0021 0x0000 0x1162 
#
#DL2_COMP_REDUN:
#    GETQADR  $IPRL_DL_QADDR_REDO
tcblock mbipcmd 0x0091 0x1158   0x015C 0x11E8 
#    START2HR 0x49 0x6000 0x6800 $IPRL_DL_NWORDS $IPRL_DL_NWORDS+3
tcblock mbipcmd 0x0091 0x115A   0x019A 0x0049 0x6000 0x6800 \
                                0x11D9 0x11DC 
#    GOTO &WAITING
tcblock mbipcmd 0x0091 0x1160   0x0156 0x11B0 
#
#DL2_COMP_PRIM:
#    GETQADR  $IPRL_DL_QADDR_REDO
tcblock mbipcmd 0x0091 0x1162   0x015C 0x11E8 
#    START2HR 0x49 0x4000 0x4800 $IPRL_DL_NWORDS $IPRL_DL_NWORDS+3
tcblock mbipcmd 0x0091 0x1164   0x019A 0x0049 0x4000 0x4800 \
                                0x11D9 0x11DC 
#    GOTO &WAITING
tcblock mbipcmd 0x0091 0x116A   0x0156 0x11B0 
#
#DL2_RAW:					;--------------- Downlink 2 Pages in RAW mode
#    BRANCHEQ  R33    0   &DL2_RAW_PRIM
tcblock mbipcmd 0x0091 0x116C   0x01AE 0x0021 0x0000 0x117A 
#
#DL2_RAW_REDUN:
#    GETQADR  $IPRL_DL_QADDR_REDO
tcblock mbipcmd 0x0091 0x1170   0x015C 0x11E8 
#    START2HR 0x4b 0x6000 0x6800 $IPRL_DL_NWORDS $IPRL_DL_NWORDS+3
tcblock mbipcmd 0x0091 0x1172   0x019A 0x004B 0x6000 0x6800 \
                                0x11D9 0x11DC 
#    GOTO &WAITING
tcblock mbipcmd 0x0091 0x1178   0x0156 0x11B0 
#
#DL2_RAW_PRIM:
#    GETQADR  $IPRL_DL_QADDR_REDO
tcblock mbipcmd 0x0091 0x117A   0x015C 0x11E8 
#    START2HR 0x4b 0x4000 0x4800 $IPRL_DL_NWORDS $IPRL_DL_NWORDS+3
tcblock mbipcmd 0x0091 0x117C   0x019A 0x004B 0x4000 0x4800 \
                                0x11D9 0x11DC 
#    GOTO &WAITING
tcblock mbipcmd 0x0091 0x1182   0x0156 0x11B0 
#
#    ;------------ One page downlink command section
#DL1PAGE:
#    BRANCHEQ  $IPRL_HEAD_WORK+3 0 &DL1_RAW
tcblock mbipcmd 0x0091 0x1184   0x01AE 0x1158 0x0000 0x119C 
#
#DL1_COMP:					;--------------- Downlink 1 Page in COMPRESSED mode
#    BRANCHEQ  R33    0   &DL1_COMP_PRIM
tcblock mbipcmd 0x0091 0x1188   0x01AE 0x0021 0x0000 0x1194 
#
#DL1_COMP_REDUN:
#    GETQADR  $IPRL_DL_QADDR_REDO
tcblock mbipcmd 0x0091 0x118C   0x015C 0x11E8 
#    START1HR 0x01 0x6000 $IPRL_DL_NWORDS
tcblock mbipcmd 0x0091 0x118E   0x0174 0x0001 0x6000 0x11D9 
#    GOTO &WAITING
tcblock mbipcmd 0x0091 0x1192   0x0156 0x11B0 
#
#DL1_COMP_PRIM:
#    GETQADR  $IPRL_DL_QADDR_REDO
tcblock mbipcmd 0x0091 0x1194   0x015C 0x11E8 
#    START1HR 0x01 0x4000 $IPRL_DL_NWORDS
tcblock mbipcmd 0x0091 0x1196   0x0174 0x0001 0x4000 0x11D9 
#    GOTO &WAITING
tcblock mbipcmd 0x0091 0x119A   0x0156 0x11B0 
#
#DL1_RAW:					;--------------- Downlink 1 Page in RAW mode
#    BRANCHEQ  R33    0   &DL1_RAW_PRIM
tcblock mbipcmd 0x0091 0x119C   0x01AE 0x0021 0x0000 0x11A8 
#
#DL1_RAW_REDUN:
#    GETQADR  $IPRL_DL_QADDR_REDO
tcblock mbipcmd 0x0091 0x11A0   0x015C 0x11E8 
#    START1HR 0x03 0x6000 $IPRL_DL_NWORDS
tcblock mbipcmd 0x0091 0x11A2   0x0174 0x0003 0x6000 0x11D9 
#    GOTO &WAITING
tcblock mbipcmd 0x0091 0x11A6   0x0156 0x11B0 
#
#DL1_RAW_PRIM:
#    GETQADR  $IPRL_DL_QADDR_REDO
tcblock mbipcmd 0x0091 0x11A8   0x015C 0x11E8 
#    START1HR 0x03 0x4000 $IPRL_DL_NWORDS
tcblock mbipcmd 0x0091 0x11AA   0x0174 0x0003 0x4000 0x11D9 
#    GOTO &WAITING
tcblock mbipcmd 0x0091 0x11AE   0x0156 0x11B0 
#
#WAITING:					;-------------- Check to see that the downlink actua
#    BRANCHEQ $IPRL_DL_CHECKED 1 &DONE		;already did the wait once
tcblock mbipcmd 0x0091 0x11B0   0x01AE 0x11E7 0x0001 0x11D5 
#    SETREG   $IPRL_DL_CHECKED 1
tcblock mbipcmd 0x0091 0x11B4   0x0140 0x11E7 0x0001 
#
#    SETREG  R143 16
tcblock mbipcmd 0x0091 0x11B7   0x0140 0x008F 0x0010 
#    PURGELST R136				;wait 82 msec before checking the page
tcblock mbipcmd 0x0091 0x11BA   0x0190 0x0088 
#
#    BRANCHEQ  R33    0   &CHECK_PRIM
tcblock mbipcmd 0x0091 0x11BC   0x01AE 0x0021 0x0000 0x11C5 
#
#CHECK_REDUN:
#    BRANCHNR 0x6000 &DONE			;The page got busy ==> all ok
tcblock mbipcmd 0x0091 0x11C0   0x01A6 0x6000 0x11D5 
#    GOTO &PROBLEM
tcblock mbipcmd 0x0091 0x11C3   0x0156 0x11CA 
#
#CHECK_PRIM:
#    BRANCHNR 0x4000 &DONE			;The page got busy ==> all ok
tcblock mbipcmd 0x0091 0x11C5   0x01A6 0x4000 0x11D5 
#    GOTO &PROBLEM
tcblock mbipcmd 0x0091 0x11C8   0x0156 0x11CA 
#
#PROBLEM:
#    SETREG  R26 1
tcblock mbipcmd 0x0091 0x11CA   0x0140 0x001A 0x0001 
#    SAVEMODE					;save the state, throw an error and reset the IP
tcblock mbipcmd 0x0091 0x11CD   0x01E6 
#
#    SETREG  R143 16
tcblock mbipcmd 0x0091 0x11CE   0x0140 0x008F 0x0010 
#    PURGELST R136				;wait 82 msec before retrying
tcblock mbipcmd 0x0091 0x11D1   0x0190 0x0088 
#
#    GOTOREG $IPRL_DL_QADDR_REDO			;Go back and issue the command 
tcblock mbipcmd 0x0091 0x11D3   0x0158 0x11E8 
#
#DONE:
#    RTNQUE
tcblock mbipcmd 0x0091 0x11D5   0x01FA 
#=======================================================
#
# ENBQUE                ; Enable Queue
tcblock mbipldin 0x0136
#
#
return
#
#=======================================================
