##########################                                            ##-#
#                                                                     ##-#
# Assembled by checkpoint, 1.18.2 (23-Sep-99).                        ##-#
# (EDIT THE ORIGINAL SOURCE, NOT THIS FILE!)                          ##-#
# Date-assembled: Fri Jan 15 09:58:05 EST 2010                        ##-#
# Orig-source: /mdisw/cfl/flight/src/reset_v05.src                    ##-#
#                                                                     ##-#
##########################                                            ##-#
# File: reset.src
# HISTORY:
#	Written Sep-95 by M.Morrison
#	12-Dec-95 (MDM) - Added source and descr lines
#	24-Jan-96 (MDM) - Changed to DISable the queue, not enable it
#			- Added lines to clear the campaign flag
#	15-Feb-97 (MDM) - Added IP initialization
#
program "%Z% MODULE: %M% RELEASE: %R%.%L% CREATED: %G% %U%"
source "/mdisw/cfl/flight/src/q_reset_v05.src"
descr "Reset the DEP and IP to a known standby state"
#
                                                                      ##-#
#=#=#=#=#=#=#=#=#=#=# src ln 15.  (Open Log file)                     ##-#
if !GS9 = "" then                                                     ##-#
  display "Opening logfile from q_reset_v05"                          ##-#
  perf openlog                                                        ##-#
end if                                                                ##-#
write !GS9 "%s q_reset_v05:" !TIME                                    ##-#
writen !GS9 "Starting..."                                             ##-#
#=#=#=#=#=#=#=#=#=#=#+ src ln 15.  Block 0  Next line is #30          ##-#
 display "Running block 0 of q_reset_v05."                            ##-#
set !LI0 = getint(mktccnt)                                            ##-#
queue on ## Queue next 11 commands.                                   ##-#
# --- Stop Structure sequence
tcb mbsqend

# --- Reset all
tcb mbiprsal
tcb mbipcmd 5

# --- Do a SUBINIT
tcb mbipldin 0x11c

# --- Run the IP?
tcb mbiprun

# --- DISable the queue
tcb mbipldin 0x154

# --- Reset SCI5K status to 0
tcb mbdpmod 1

# --- Set VC channel to high rate
#TODO

# --- Set primary side for downlinking purposes (needed?)
tcb mbipldin 0x140 33 0
tcb mbipldin 0x140 61 0


# -- Set debugging statement on
tcblock mbipldin 0x140 4094      0

# --- Clear the campaign flag
tcblock mbsqreg  4     0            ## Disable Campaign Flag
queue off ## Synchronize w/ POCC                                      ##-#
tcblock mbsqreg 66     0            ## Disable Campaign Flag
#=#=#=#=#=#=#=#=#=#=#- src ln 47.  Block 0   Cmds:12   Total:12       ##-#
wait time 8 ## Wait for hk packet                                     ##-#
set !LI2 = !LI0 + 12                                                  ##-#
if !LI2 > 255 then                                                    ##-#
 set !LI1 = !LI2 - 256                                                ##-#
else                                                                  ##-#
 set !LI1 = !LI2                                                      ##-#
end if                                                                ##-#
set !LI2 = getint(mktccnt)                                            ##-#
if !LI1 <> !LI2 then                                                  ##-#
 write !GS9 "%s q_reset_v05:" !TIME                                   ##-#
 writen !GS9  "CMD CT ERR in block 0. cmd ctr: %d" !LI2               ##-#
 writen !GS9  "      (Sent 12 cmds; expected cmd ctr: %d)" !LI1       ##-#
 writen !GS9  "      Halted.  (restart at line 30)"                   ##-#
 display "ERR: q_reset_v05 blk 0: cmd ctr isnt %d. (CONT 30)" !LI1    ##-#
 halt                                                                 ##-#
 write !GS9 "%s q_reset_v05:" !TIME                                   ##-#
 writen !GS9  "Override.  Continuing past block 0..."                 ##-#
else                                                                  ##-#
 write !GS9 "%s q_reset_v05:" !TIME                                   ##-#
 writen !GS9  "Block 0 completed OK."                                 ##-#
display "Completed block 0 of q_reset_v05."                           ##-#
end if                                                                ##-#
#################### END of BLOCK 0 ####################              ##-#
write !GS9 "%s q_reset_v05:" !TIME                                    ##-#
writen !GS9 "Falling off the bottom."                                 ##-#
