;:ts=8
	far	code
	far	data
;/*  TT8 specific includes  */
;
;#include        <TT8.h>                 /* Tattletale Model 8 Definitions */
;#include        <tat332.h>              /* 68332 Tattletale (7,8) Hardware Definitions */
;#include        <sim332.h>              /* 68332 System Integration Module Definitions */
;#include        <qsm332.h>              /* 68332 Queued Serial Module Definitions */
;#include        <tpu332.h>              /* 68332 Time Processing Unit Definitions */
;#include        <dio332.h>              /* 68332 Digital I/O Port Pin Definitions */
;#include        <tt8pic.h>              /* Model 8 PIC Parallel Slave Port Definitions */
;#include        <tt8lib.h>              /* definitions and prototypes for Model 8 library */
;
;/*  general C includes  */
;#include        <stdio.h>
;#include        <stdlib.h>
;#include		<math.h>
;
;//  includes for the data logger
;#include		"assert.h"
;#include		"memcheck.h"
;#include		"logger.h"
;#include		"science.h"
;#include		"engineer.h"
;#include		"logtime.h"
	dseg
	ds	0
_LATEST_LOGGER_TIME:
	ds.b	0
	dc.l	$ffffffff
	dc.l	$0000
	cseg
	dseg
	ds	0
_EARLIEST_LOGGER_TIME:
	ds.b	0
	dc.l	$0000
	dc.l	$0000
	cseg
;#include		"text_log.h"
;#include		"eeprom.h"
;#include		"misc.h"
;
;
;struct logger  {
;	time_tt logger_suspension_over;		//  tracks the time at which the logger
;										//  will be restarted from suspension
;} logger;
;
;
;
;//  logger_suspend 
;//
;//  Suspends the logger for the given length of time
;//
;int logger_suspend (long length)  {
# 40 'logger.c' 678929802
| .2
	xdef	_logger_suspend
_logger_suspend:
	link	a6,#.3
	movem.l	d2,-(sp)
	move.l	8(a6),d2
;	time_tt now;
;
;	ASSERT (length > 0);
~ ''
~ 1 2 8
~ secs 0 "L"
~ ticks 4 "l"
~ now -8 ":" 1
~~ length d2 "l"
^^^;/*	
;	if (length <= 0)  {
;		if (logger.logger_suspension_over.secs == 0)
;			printf ("The logger is already running.\n\n");
;			return -1;
;		}
;	
;		//  REVIEW - how do we convey an error if we can't restart
;		//  the logger?
;		//  restart the logger - but are we really stopped?
;		log_printf ("Restarted logger from logger_suspend()\n");
;		return logger_start ();
;	}
;*/	
;	if (length > MAX_SUSPENSION_TIME)
^^^^^^^^^^^^^^^;		return -1;
	cmp.l	#43200,d2
	ble	.10001
^	move.l	#-1,d0
.4
	movem.l	(sp)+,d2
	unlk	a6
	rts
;	
;	now = logger_time_get_time ();
.10001
^^	lea	-8(a6),a0
	move.l	a0,-(sp)
	jsr	_logger_time_get_time
	move.l	d0,a0
	move.l	(sp)+,a1
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
;	log_printf ("Suspending logger for %ld seconds @ %s", length, logger_time_get_string (&now));
^	pea	-8(a6)
	jsr	_logger_time_get_string
	add.w	#4,sp
	move.l	d0,-(sp)
	move.l	d2,-(sp)
	pea	.1+0
	jsr	_log_printf
;
;	logger_shutdown ();
^^	jsr	_logger_shutdown
;	logger.logger_suspension_over = logger_time_get_time ();
^	lea	_logger,a0
	lea	12(sp),sp
	move.l	a0,-(sp)
	jsr	_logger_time_get_time
	move.l	d0,a0
	move.l	(sp)+,a1
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
;	logger.logger_suspension_over.secs += length;
^	add.l	d2,_logger
;	
;	printf ("There are %ld bytes of RAM available for data buffers\n", mem_find_max_malloc());
^^	jsr	_mem_find_max_malloc
	move.l	d0,-(sp)
	pea	.1+39
	jsr	_printf
;	return 0;
^	move.l	#0,d0
	add.w	#8,sp
	bra	.4
;}																
^.2
.3	equ	-8
.1
	dc.b	83,117,115,112,101,110,100,105,110,103,32,108,111,103,103
	dc.b	101,114,32,102,111,114,32,37,108,100,32,115,101,99,111
	dc.b	110,100,115,32,64,32,37,115,0,84,104,101,114,101,32
	dc.b	97,114,101,32,37,108,100,32,98,121,116,101,115,32,111
	dc.b	102,32,82,65,77,32,97,118,97,105,108,97,98,108,101
	dc.b	32,102,111,114,32,100,97,116,97,32,98,117,102,102,101
	dc.b	114,115,10,0
	ds	0
;
;
;
;
;
;//  logger_start ()
;//
;//	Reads the initialization table and sets the logger up as specified
;//  before calling the main data collection loop
;//
;int logger_start (void)  {
# 81
| .6
	xdef	_logger_start
_logger_start:
	link	a6,#.7
;	time_tt now;
;	
;	if (sci_logger_is_open())  {
~ now -8 ":" 1
^^^	jsr	_sci_logger_is_open
	tst.w	d0
	beq	.10002
;		//  REVIEW - should verify that the engineering logger is open
;		printf ("The logger is already running.\n");
^^	pea	.5+0
	jsr	_printf
;		return 0;
^	move.l	#0,d0
	add.w	#4,sp
.8
	unlk	a6
	rts
;	}
^;
;	now = logger_time_get_time ();
.10002
^^	lea	-8(a6),a0
	move.l	a0,-(sp)
	jsr	_logger_time_get_time
	move.l	d0,a0
	move.l	(sp)+,a1
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
;	log_printf ("Starting logger at %s", logger_time_get_string (&now));
^	pea	-8(a6)
	jsr	_logger_time_get_string
	add.w	#4,sp
	move.l	d0,-(sp)
	pea	.5+32
	jsr	_log_printf
;	log_printf ("There are %ld bytes of memory available\n", mem_find_max_malloc());
^	jsr	_mem_find_max_malloc
	move.l	d0,-(sp)
	pea	.5+54
	jsr	_log_printf
;	printf ("There are %ld bytes of memory available\n", mem_find_max_malloc());
^	jsr	_mem_find_max_malloc
	move.l	d0,-(sp)
	pea	.5+95
	jsr	_printf
;
;	if (logger_start_engineering () != 0)  {
^^	jsr	_logger_start_engineering
	tst.w	d0
	lea	24(sp),sp
	beq	.10003
;		printf ("Logger NOT started\n");
^	pea	.5+136
	jsr	_printf
;		return -1;
^	move.l	#-1,d0
	add.w	#4,sp
	bra	.8
;	}	
^;		
;	if (logger_start_science () != 0)  {
.10003
^^	jsr	_logger_start_science
	tst.w	d0
	beq	.10004
;		logger_shutdown_engineering ();
^	jsr	_logger_shutdown_engineering
;		printf ("Logger NOT started\n");
^	pea	.5+156
	jsr	_printf
;		return -1;
^	move.l	#-1,d0
	add.w	#4,sp
	bra	.8
;	}
^;		
;	//  when the logger is temporarily shutdown, then logger_suspension_over is
;	//  set to the new time at which the logger should be started.  If
;	//  logger_suspension_over.secs is 0, then the logger is already running
;	logger.logger_suspension_over.secs = 0;
.10004
^^^^^	clr.l	_logger
;	return 0;
^	move.l	#0,d0
	bra	.8
;}
^.6
.7	equ	-8
.5
	dc.b	84,104,101,32,108,111,103,103,101,114,32,105,115,32,97
	dc.b	108,114,101,97,100,121,32,114,117,110,110,105,110,103,46
	dc.b	10,0,83,116,97,114,116,105,110,103,32,108,111,103,103
	dc.b	101,114,32,97,116,32,37,115,0,84,104,101,114,101,32
	dc.b	97,114,101,32,37,108,100,32,98,121,116,101,115,32,111
	dc.b	102,32,109,101,109,111,114,121,32,97,118,97,105,108,97
	dc.b	98,108,101,10,0,84,104,101,114,101,32,97,114,101,32
	dc.b	37,108,100,32,98,121,116,101,115,32,111,102,32,109,101
	dc.b	109,111,114,121,32,97,118,97,105,108,97,98,108,101,10
	dc.b	0,76,111,103,103,101,114,32,78,79,84,32,115,116,97
	dc.b	114,116,101,100,10,0,76,111,103,103,101,114,32,78,79
	dc.b	84,32,115,116,97,114,116,101,100,10,0
	ds	0
;
;
;
;
;//  logger_get_seconds_to_start
;//
;//	Returns non-zero if the logger is currently suspended
;//
;long logger_get_seconds_to_start (void)  {
# 120
| .10
	xdef	_logger_get_seconds_to_start
_logger_get_seconds_to_start:
	link	a6,#.11
;	time_tt now;
;
;	if (logger.logger_suspension_over.secs == 0)  {
~ now -8 ":" 1
^^^	tst.l	_logger
	bne	.10005
;		//  logger is not suspended, so it should be open
;		ASSERT (sci_logger_is_open () != 0);
^^;		return 0;
^	move.l	#0,d0
.12
	unlk	a6
	rts
;	}  else  {
^.10005
;		//  logger is suspended, so it shouldn't be open
;		ASSERT (sci_logger_is_open () == 0);
^^;
;		now = logger_time_get_time ();
^^	lea	-8(a6),a0
	move.l	a0,-(sp)
	jsr	_logger_time_get_time
	move.l	d0,a0
	move.l	(sp)+,a1
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
;		//  REVIEW
;		//  REVIEW
;		//  REVIEW
;		//  There appears to be a compiler bug which hurts the ASSERT that follows
;		//  Or else my brain isn't working.  The printf can print 600, and the
;		//  ASSERT can fail.  		
;		//  Follow this up later.  Check the assembly.
;//		printf ("Delta is %ld\n", (logger.logger_suspension_over.secs - now.secs));
;//		ASSERT ((logger.logger_suspension_over.secs - now.secs) > -1000L);
;		return (logger.logger_suspension_over.secs - now.secs);
^^^^^^^^^^	move.l	_logger,d0
	sub.l	-8(a6),d0
	bra	.12
;	}	
^;}
^.10
.11	equ	-8
;			
;
;
;
;//  logger_verify_suspension
;//
;//	Checks the suspension to determine if it has expired.  Restarts
;//  the logger if it has.  Also verifies that the expiration time is
;//  reasonable, defined as being within the maximum suspension time
;//  of the current time.  If it isn't reasonable, then this routine
;//  immediately restarts the logger
;//
;void logger_verify_suspension (void)  {
# 156
| .13
	xdef	_logger_verify_suspension
_logger_verify_suspension:
	link	a6,#.14
	movem.l	d2,-(sp)
;	time_tt now;
;	long delta;
;	
;	now = logger_time_get_time ();
~ now -8 ":" 1
~ delta d2 "l"
^^^^	lea	-8(a6),a0
	move.l	a0,-(sp)
	jsr	_logger_time_get_time
	move.l	d0,a0
	move.l	(sp)+,a1
	move.l	(a0)+,(a1)+
	move.l	(a0)+,(a1)+
;	delta = now.secs - logger.logger_suspension_over.secs;
^	move.l	-8(a6),d2
	sub.l	_logger,d2
;	//  if the delay is a legal length and unexpired, just return
;	if ((delta < 0) && (-1*delta <= MAX_SUSPENSION_TIME))
^^;		return;
	tst.l	d2
	bge	.10006
	move.l	d2,d0
	neg.l	d0
	cmp.l	#43200,d0
	bgt	.10006
^.15
	movem.l	(sp)+,d2
	unlk	a6
	rts
;
;	//  if the delay is an unreasonable value, log it and override it.
;	if (labs (delta) > MAX_SUSPENSION_TIME)  {
.10006
^^^	move.l	d2,-(sp)
	jsr	_labs
	cmp.l	#43200,d0
	add.w	#4,sp
	ble	.10007
;		log_printf ("Unreasonable large suspension time - overrode!\n");
^	pea	.9+0
	jsr	_log_printf
;	}
^;
;	log_printf ("Restarting logger at %s", logger_time_get_string (&now));
	add.w	#4,sp
.10007
^^	pea	-8(a6)
	jsr	_logger_time_get_string
	add.w	#4,sp
	move.l	d0,-(sp)
	pea	.9+48
	jsr	_log_printf
;	//  if we get here then either the inhibit expired, or the length is
;	//  unreasonable, and we should force its expiration
;	logger_start ();
^^^	jsr	_logger_start
;	return;
^	add.w	#8,sp
	bra	.15
;}
^.13
.14	equ	-8
.9
	dc.b	85,110,114,101,97,115,111,110,97,98,108,101,32,108,97
	dc.b	114,103,101,32,115,117,115,112,101,110,115,105,111,110,32
	dc.b	116,105,109,101,32,45,32,111,118,101,114,114,111,100,101
	dc.b	33,10,0,82,101,115,116,97,114,116,105,110,103,32,108
	dc.b	111,103,103,101,114,32,97,116,32,37,115,0
	ds	0
;
;
;
;//  logger_shutdown ()
;//
;//  Ensures that everything is shut down and powered off before quitting
;//  the logger completely
;//
;void logger_shutdown (void)  {
# 185
| .17
	xdef	_logger_shutdown
_logger_shutdown:
;	
;	//  if non-zero, we are already shut down, so do nothing.  The user
;	//  may adjust the wake up time.
;	if (logger.logger_suspension_over.secs != 0)
^^^^;		return;
	tst.l	_logger
	beq	.10008
^.18
	rts
;
;	//  a normal sequence of events would allow us to call the close
;	//  routines when the logger was already closed.  Make sure they
;	//  properly handle this
;	sci_logger_close ();
.10008
^^^^^	jsr	_sci_logger_close
;	eng_logger_close ();
^	jsr	_eng_logger_close
;	
;	//  when the logger is temporarily shutdown, then logger_suspension_over is
;	//  set to the new time at which the logger should be started.  It is 
;	//  the job of the routine which shut the logger down to set this variable
;	//  AFTER calling this shutdown routine.  This routine sets the seconds
;	//  non-zero so the rest of the program will know the logger is off, and
;	//  sets the seconds to a nonsensical value so that the fail safe routines
;	//  will restart the logger if the user doesn't properly init this variable
;	logger.logger_suspension_over.secs = 1;
^^^^^^^^^	move.l	#1,_logger
;}
^	bra	.18
.17
;
;
;
;
;//  logger_start_engineering
;//
;//  Starts up and inits the engineering data logger
;//
;int logger_start_engineering (void)  {
# 215
| .19
	xdef	_logger_start_engineering
_logger_start_engineering:
	movem.l	d2,-(sp)
;	int n;
;	
;	//  open the engineering logger; can't fail
;	eng_logger_open ();
~ n d2 "i"
^^^^	jsr	_eng_logger_open
;
;	//  initialize the engineering channels as needed
;	for (n = 0;  n < N_ENG_CHANNELS;  n++)  {
^^^	move.l	#0,d2
.10011
;		ASSERT (setup_data.eng_rate[n] >= 0);
^;		ASSERT (setup_data.eng_rate[n] < 1e6);
^;		if (eng_logger_channel_setup (n, setup_data.eng_rate[n]) < 0)  {
^	move.w	d2,d0
	ext.l	d0
	asl.l	#2,d0
	lea	_setup_data,a0
	move.l	(a0,d0.l),-(sp)
	move.w	d2,-(sp)
	jsr	_eng_logger_channel_setup
	tst.w	d0
	add.w	#6,sp
	bge	.10012
;			log_printf ("logger_start_engineering failed on channel %d.\n", n);
^	move.w	d2,-(sp)
	pea	.16+0
	jsr	_log_printf
;			printf ("Could not start engineering logger, channel %d.\n", n);
^	move.w	d2,-(sp)
	pea	.16+48
	jsr	_printf
;			return -1;
^	move.l	#-1,d0
	lea	12(sp),sp
.20
	movem.l	(sp)+,d2
	rts
;		}
^;		if (setup_data.eng_rate[n] > 0)
.10012
^;			printf ("Engineering channel %d will be recorded every %ld seconds.\n",
	move.w	d2,d0
	ext.l	d0
	asl.l	#2,d0
	lea	_setup_data,a0
	tst.l	(a0,d0.l)
	ble	.10013
^;													1+n, setup_data.eng_rate[n]);
	move.w	d2,d0
	ext.l	d0
	asl.l	#2,d0
	lea	_setup_data,a0
	move.l	(a0,d0.l),-(sp)
	move.w	d2,d0
	add.w	#1,d0
	move.w	d0,-(sp)
	pea	.16+97
	jsr	_printf
;	}
	lea	10(sp),sp
.10013
^^.10009
	add.w	#1,d2
	cmp.w	#4,d2
	blt	.10011
.10010
;	log_printf ("Engineering logger started.\n");
^	pea	.16+157
	jsr	_log_printf
;	return 0;
^	move.l	#0,d0
	add.w	#4,sp
	bra	.20
;}
^.19
.16
	dc.b	108,111,103,103,101,114,95,115,116,97,114,116,95,101,110
	dc.b	103,105,110,101,101,114,105,110,103,32,102,97,105,108,101
	dc.b	100,32,111,110,32,99,104,97,110,110,101,108,32,37,100
	dc.b	46,10,0,67,111,117,108,100,32,110,111,116,32,115,116
	dc.b	97,114,116,32,101,110,103,105,110,101,101,114,105,110,103
	dc.b	32,108,111,103,103,101,114,44,32,99,104,97,110,110,101
	dc.b	108,32,37,100,46,10,0,69,110,103,105,110,101,101,114
	dc.b	105,110,103,32,99,104,97,110,110,101,108,32,37,100,32
	dc.b	119,105,108,108,32,98,101,32,114,101,99,111,114,100,101
	dc.b	100,32,101,118,101,114,121,32,37,108,100,32,115,101,99
	dc.b	111,110,100,115,46,10,0,69,110,103,105,110,101,101,114
	dc.b	105,110,103,32,108,111,103,103,101,114,32,115,116,97,114
	dc.b	116,101,100,46,10,0
	ds	0
;
;
;
;void logger_shutdown_engineering (void)  {
# 240
| .22
	xdef	_logger_shutdown_engineering
_logger_shutdown_engineering:
;	eng_logger_close ();
^	jsr	_eng_logger_close
;}
^.23
	rts
.22
;
;
;
;
;//  logger_start_science
;//
;//  Starts up and inits the science data logger
;//
;int logger_start_science (void)  {
# 251
| .24
	xdef	_logger_start_science
_logger_start_science:
	movem.l	d2/d3/d4,-(sp)
;	int n;
;
;//	//  don't open science logger unless at least one channel is active
;//	if (setup_data.science_chans != 0)  {
;		if (sci_logger_open ())  {
~ n d4 "i"
^^^^^	jsr	_sci_logger_open
	tst.w	d0
	beq	.10014
;			log_printf ("Could not open the science data logger.\n");
^	pea	.21+0
	jsr	_log_printf
;			return -1;
^	move.l	#-1,d0
	add.w	#4,sp
.25
	movem.l	(sp)+,d2/d3/d4
	rts
;		}
^;		if (sci_logger_set_conversion_rate (setup_data.science_rate) < 0)  {
.10014
^	move.l	_setup_data+16,-(sp)
	jsr	_sci_logger_set_conversion_rate
	jsr	.Ptst#
	add.w	#4,sp
	bge	.10015
;			printf ("Illegal conversion rate; it MUST be reset before collecting any data.\n");
^	pea	.21+41
	jsr	_printf
;			printf ("Default value currently in use.\n");
^	pea	.21+112
	jsr	_printf
;			log_printf ("Illegal conversion rate; it MUST be reset before collecting any data.\n");
^	pea	.21+145
	jsr	_log_printf
;		}
^;		if (sci_logger_set_averaging (setup_data.science_n_to_average) != 0)  {
	lea	12(sp),sp
.10015
^	move.w	_setup_data+76,-(sp)
	jsr	_sci_logger_set_averaging
	tst.w	d0
	add.w	#2,sp
	beq	.10016
;			printf ("Illegal value for science data averaging.  Please reset.\n");
^	pea	.21+216
	jsr	_printf
;			printf ("Default value currently in use.\n");
^	pea	.21+274
	jsr	_printf
;			log_printf ("Illegal value for science data averaging.  Please reset.\n");
^	pea	.21+307
	jsr	_log_printf
;		}
^;		if (sci_logger_activate_chans (setup_data.science_chans) != 0)  {
	lea	12(sp),sp
.10016
^	move.w	_setup_data+36,-(sp)
	jsr	_sci_logger_activate_chans
	tst.w	d0
	add.w	#2,sp
	beq	.10017
;			printf ("Could not activate channels 0x%02X.\n", setup_data.science_chans);
^	move.w	_setup_data+36,-(sp)
	pea	.21+365
	jsr	_printf
;			log_printf ("Could not activate channels 0x%02X.\n", setup_data.science_chans);
^	move.w	_setup_data+36,-(sp)
	pea	.21+402
	jsr	_log_printf
;			sci_logger_close ();
^	jsr	_sci_logger_close
;			return -1;
^	move.l	#-1,d0
	lea	12(sp),sp
	bra	.25
;		}
^;		sci_logger_set_STA_time (setup_data.t_STA);
.10017
^	move.l	_setup_data+40,-(sp)
	jsr	_sci_logger_set_STA_time
;		sci_logger_set_LTA_time (setup_data.t_LTA);
^	move.l	_setup_data+44,-(sp)
	jsr	_sci_logger_set_LTA_time
;		sci_logger_set_pre_event (setup_data.pre_event_time);
^	move.l	_setup_data+68,-(sp)
	jsr	_sci_logger_set_pre_event
;		sci_logger_set_post_event (setup_data.post_event_time);
^	move.l	_setup_data+64,-(sp)
	jsr	_sci_logger_set_post_event
;		for (n = 0;  n < N_SCI_CHANNELS;  n++)  {
^	move.l	#0,d4
	lea	16(sp),sp
.10020
;			//  somewhat confusing in that the channel numbers are offset
;			//  from 0, while the index is not
;			sci_logger_set_gain (n, setup_data.science_gain[n]);
^^^	move.w	d4,d0
	ext.l	d0
	asl.l	#2,d0
	lea	_setup_data+20,a0
	move.l	d0,a1
	add.l	a0,a1
	move.l	(a1),-(sp)
	move.w	d4,-(sp)
	jsr	_sci_logger_set_gain
;			sci_logger_set_trigger_level (n, setup_data.trigger_level[n]);
^	move.w	d4,d0
	ext.l	d0
	asl.l	#2,d0
	lea	_setup_data+48,a0
	move.l	d0,a1
	add.l	a0,a1
	move.l	(a1),-(sp)
	move.w	d4,-(sp)
	jsr	_sci_logger_set_trigger_level
;		}	
^	lea	12(sp),sp
.10018
	add.w	#1,d4
	cmp.w	#4,d4
	blt	.10020
.10019
;//	}  else
;//		log_printf ("There are no science channels active.\n");
;#ifdef CREATE_DIRS
;	sci_logger_setup_partition ();
^^^^	jsr	_sci_logger_setup_partition
;	logger_disk_power_disk_off ();
^	jsr	_logger_disk_power_disk_off
;#endif	
;	sci_logger_start_data ();
^^	jsr	_sci_logger_start_data
;	log_printf ("Science logger started.\n");
^	pea	.21+439
	jsr	_log_printf
;	return 0;
^	move.l	#0,d0
	add.w	#4,sp
	bra	.25
;}
^.24
.21
	dc.b	67,111,117,108,100,32,110,111,116,32,111,112,101,110,32
	dc.b	116,104,101,32,115,99,105,101,110,99,101,32,100,97,116
	dc.b	97,32,108,111,103,103,101,114,46,10,0,73,108,108,101
	dc.b	103,97,108,32,99,111,110,118,101,114,115,105,111,110,32
	dc.b	114,97,116,101,59,32,105,116,32,77,85,83,84,32,98
	dc.b	101,32,114,101,115,101,116,32,98,101,102,111,114,101,32
	dc.b	99,111,108,108,101,99,116,105,110,103,32,97,110,121,32
	dc.b	100,97,116,97,46,10,0,68,101,102,97,117,108,116,32
	dc.b	118,97,108,117,101,32,99,117,114,114,101,110,116,108,121
	dc.b	32,105,110,32,117,115,101,46,10,0,73,108,108,101,103
	dc.b	97,108,32,99,111,110,118,101,114,115,105,111,110,32,114
	dc.b	97,116,101,59,32,105,116,32,77,85,83,84,32,98,101
	dc.b	32,114,101,115,101,116,32,98,101,102,111,114,101,32,99
	dc.b	111,108,108,101,99,116,105,110,103,32,97,110,121,32,100
	dc.b	97,116,97,46,10,0,73,108,108,101,103,97,108,32,118
	dc.b	97,108,117,101,32,102,111,114,32,115,99,105,101,110,99
	dc.b	101,32,100,97,116,97,32,97,118,101,114,97,103,105,110
	dc.b	103,46,32,32,80,108,101,97,115,101,32,114,101,115,101
	dc.b	116,46,10,0,68,101,102,97,117,108,116,32,118,97,108
	dc.b	117,101,32,99,117,114,114,101,110,116,108,121,32,105,110
	dc.b	32,117,115,101,46,10,0,73,108,108,101,103,97,108,32
	dc.b	118,97,108,117,101,32,102,111,114,32,115,99,105,101,110
	dc.b	99,101,32,100,97,116,97,32,97,118,101,114,97,103,105
	dc.b	110,103,46,32,32,80,108,101,97,115,101,32,114,101,115
	dc.b	101,116,46,10,0,67,111,117,108,100,32,110,111,116,32
	dc.b	97,99,116,105,118,97,116,101,32,99,104,97,110,110,101
	dc.b	108,115,32,48,120,37,48,50,88,46,10,0,67,111,117
	dc.b	108,100,32,110,111,116,32,97,99,116,105,118,97,116,101
	dc.b	32,99,104,97,110,110,101,108,115,32,48,120,37,48,50
	dc.b	88,46,10,0,83,99,105,101,110,99,101,32,108,111,103
	dc.b	103,101,114,32,115,116,97,114,116,101,100,46,10,0
	ds	0
;
;
;
;void logger_shutdown_science (void)  {
# 299
| .27
	xdef	_logger_shutdown_science
_logger_shutdown_science:
;	sci_logger_close ();
^	jsr	_sci_logger_close
;}
^.28
	rts
.27
;	
;
;
;void logger_set_clock_rate (long clock_rate)  {
# 305
| .29
	xdef	_logger_set_clock_rate
_logger_set_clock_rate:
	movem.l	d2/d3/d4/d5/d6/d7/a3,-(sp)
	move.l	32(sp),d4
;	long baud, temp, delta_clock;
;	float sci_rate;
;
;	//  find out what the current baud rate is
;	baud = SerGetBaud (0, 0);
~ baud d5 "l"
~ temp a3 "l"
~ delta_clock d6 "l"
~ sci_rate d7 "f"
~~ clock_rate d4 "l"
^^^^^	clr.l	-(sp)
	clr.l	-(sp)
	jsr	_SerGetBaud
	move.l	d0,d5
;	baud = 1200 * (int)((baud/1200.0) + 0.5);
^	move.l	d5,d0
	jsr	.Pflt#
	move.l	#$00000000,d3
	move.l	#$4092c000,d2
	jsr	.Pdiv#
	move.l	#$00000000,d3
	move.l	#$3fe00000,d2
	jsr	.Padd#
	jsr	.Pfix#
	muls.w	#1200,d0
	ext.l	d0
	move.l	d0,d5
;
;	//  Clock speed necessary is determined mainly by the rate at which
;	//  science data comes in.  In debug mode, always use 16 MHz
;	if (clock_rate < 0)  {
^^^^	tst.l	d4
	add.w	#8,sp
	bge	.10021
;#if defined(DEBUG) || defined (SIMULATE_DATA)
;		clock_rate = (long)16e6;
;#else
;		sci_rate = sci_logger_get_conversion_rate ();
^^^^	jsr	_sci_logger_get_conversion_rate
	jsr	.dtof#
	move.l	d0,d7
;		if (sci_rate < 65)
^;			clock_rate = (long)2.5E6;
	move.l	d7,d0
	move.l	#$42820000,d1
	jsr	.Fcmp#
	bge	.10022
^	move.l	#2500000,d4
;		else  {
	bra	.10023
.10022
^;			if (sci_rate < 129)
^;				clock_rate = (long)2.5e6;
	move.l	d7,d0
	move.l	#$43010000,d1
	jsr	.Fcmp#
	bge	.10024
^	move.l	#2500000,d4
;			else
	bra	.10025
.10024
;				clock_rate = (long)4.0e6;
^^	move.l	#4000000,d4
.10025
;		}
^.10023
;#endif	
;	}	
^^;	//  twiddle the clock rate as necessary to maintain the current baud rate
;	delta_clock = 1e5;
.10021
^^	move.l	#100000,d6
;	for (;;)  {
^.10028
;		SimSetFSys (clock_rate);
^	move.l	d4,-(sp)
	jsr	_SimSetFSys
;		temp = SerSetBaud (baud, 0);
^	clr.l	-(sp)
	move.l	d5,-(sp)
	jsr	_SerSetBaud
	move.l	d0,a3
;		if (fabs ((temp/(float)baud) - 1.0) < 0.045)
^;			break;
	move.l	a3,d0
	jsr	.Fflt#
	move.l	d0,-(sp)
	move.l	d5,d0
	jsr	.Fflt#
	move.l	d0,d1
	move.l	(sp)+,d0
	jsr	.Fdiv#
	jsr	.ftod#
	move.l	#$00000000,d3
	move.l	#$bff00000,d2
	jsr	.Padd#
	move.l	d1,-(sp)
	move.l	d0,-(sp)
	jsr	_fabs
	move.l	#$70a3d70a,d3
	move.l	#$3fa70a3d,d2
	jsr	.Pcmp#
	lea	20(sp),sp
	blt	.10027
;		if (clock_rate >= 16e6)
^^;			delta_clock *= -1;
	move.l	d4,d0
	jsr	.Pflt#
	move.l	#$00000000,d3
	move.l	#$416e8480,d2
	jsr	.Pcmp#
	blt	.10029
^	neg.l	d6
;		if (clock_rate < 1e6)  {
.10029
^	move.l	d4,d0
	jsr	.Pflt#
	move.l	#$00000000,d3
	move.l	#$412e8480,d2
	jsr	.Pcmp#
	bge	.10030
;			SimSetFSys (2.5e6);
^	pea	2500000
	jsr	_SimSetFSys
;			SerSetBaud (baud, 0);
^	clr.l	-(sp)
	move.l	d5,-(sp)
	jsr	_SerSetBaud
;			break;
^	lea	12(sp),sp
	bra	.10027
;		}	
^;		clock_rate += delta_clock;	
.10030
^	add.l	d6,d4
;	}
^.10026
	bra	.10028
.10027
;	return;
^.30
	movem.l	(sp)+,d2/d3/d4/d5/d6/d7/a3
	rts
;}	
^.29
;		
;		
;
# 349
|
~ _logger_disk_power_disk_off * "(i"
~ 'logger'
~ 2 1 8
~ logger_suspension_over 0 ":" 1
~ _logger * ":" 2
~ _mem_find_max_malloc * "(l"
~ 'setup_variables'
~ 3 13 82
~ eng_rate 0 "[4l"
~ science_rate 16 "f"
~ science_gain 20 "[4f"
~ science_chans 36 "i"
~ trigger_chans 38 "i"
~ t_STA 40 "f"
~ t_LTA 44 "f"
~ trigger_level 48 "[4f"
~ post_event_time 64 "f"
~ pre_event_time 68 "f"
~ min_disk_write 72 "l"
~ science_n_to_average 76 "i"
~ tick_offset 78 "l"
~ _setup_data * ":" 3
~ _log_printf * "(i"
~ 'text_log'
~ 4 5 1068
~ filename 0 "[32c"
~ data 32 "[1024c"
~ n_data 1056 "i"
~ n_filled 1058 "i"
~ oldest_data 1060 ":" 1
~ _logger_time_get_string * "(#c"
~ _logger_time_get_time * "(:" 1
~ EARLIEST_LOGGER_TIME _EARLIEST_LOGGER_TIME ":" 1
~ LATEST_LOGGER_TIME _LATEST_LOGGER_TIME ":" 1
~ _eng_logger_channel_setup * "(i"
~ _eng_logger_close * "(v"
~ _eng_logger_open * "(v"
~ _sci_logger_is_open * "(i"
~ _sci_logger_setup_partition * "(v"
~ _sci_logger_set_LTA_time * "(i"
~ _sci_logger_set_STA_time * "(i"
~ _sci_logger_set_post_event * "(i"
~ _sci_logger_set_pre_event * "(i"
~ _sci_logger_set_gain * "(i"
~ _sci_logger_set_trigger_level * "(v"
~ _sci_logger_activate_chans * "(i"
~ _sci_logger_get_conversion_rate * "(d"
~ _sci_logger_set_averaging * "(i"
~ _sci_logger_set_conversion_rate * "(d"
~ _sci_logger_start_data * "(v"
~ _sci_logger_close * "(v"
~ _sci_logger_open * "(i"
~ _logger_set_clock_rate * "(v"
~ _logger_get_seconds_to_start * "(l"
~ _logger_verify_suspension * "(v"
~ _logger_suspend * "(i"
~ _logger_shutdown_science * "(v"
~ _logger_start_science * "(i"
~ _logger_shutdown_engineering * "(v"
~ _logger_start_engineering * "(i"
~ _logger_shutdown * "(v"
~ _logger_start * "(i"
~ _fabs * "(d"
~ ''
~ 5 2 8
~ quot 0 "l"
~ rem 4 "l"
~ _labs * "(l"
~ ''
~ 6 2 4
~ quot 0 "i"
~ rem 2 "i"
~ ldiv_t ":" 5
~ div_t ":" 6
~ '__stdio'
~ 7 8 22
~ _bp 0 "#C"
~ _bend 4 "#C"
~ _buff 8 "#C"
~ _flags 12 "I"
~ _unit 14 "c"
~ _bytbuf 15 "C"
~ _buflen 16 "L"
~ _tmpnum 20 "I"
~ _printf * "(i"
~ FILE ":" 7
~ fpos_t "l"
~ va_list "#c"
~ ''
~ 8 13 46
~ libVersion 0 "l"
~ ramBase 4 "#c"
~ ramSize 8 "l"
~ ramWaits 12 "i"
~ flashBase 14 "#c"
~ flashSize 18 "l"
~ flashWaits 22 "i"
~ heapBot 24 "#v"
~ heapTop 28 "#v"
~ heapCur 32 "#v"
~ statusReg 36 "I"
~ vectorBase 38 "#v"
~ stackPtr 42 "#v"
~ infoAction "c"
~ TT8info ":" 8
~ UeeErr "c"
~ _SimSetFSys * "(l"
~ time_tt ":" 1
~ _SerSetBaud * "(l"
~ _SerGetBaud * "(l"
~ XmdmErr "c"
~ FlashErr "c"
~ ''
~ 9 4 24
~ eSR 0 "I"
~ ePC 2 "L"
~ vectofs 6 "I"
~ states 8 "[8I"
~ ''
~ 10 4 20
~ preamble 0 "[4I"
~ jump 8 "I"
~ target 10 "L"
~ postamble 14 "[3I"
~ ExcCFramePtr "#:" 10
~ ExcCFrame ":" 10
~ ExcStackFrame ":" 9
~ 'tm'
~ 11 10 20
~ tm_sec 0 "i"
~ tm_min 2 "i"
~ tm_hour 4 "i"
~ tm_mday 6 "i"
~ tm_mon 8 "i"
~ tm_year 10 "i"
~ tm_wday 12 "i"
~ tm_yday 14 "i"
~ tm_isdst 16 "i"
~ tm_hsec 18 "i"
~ time_t "L"
~ clock_t "L"
~ wchar_t "c"
~ ptrdiff_t "l"
~ size_t "L"
~ PSPErr "c"
~ _PRAM "[8I"
~ bool "c"
~ vfptr "#(v"
~ ptr "#c"
~ ulpv "#L"
~ ulong "L"
~ uspv "#I"
~ unsint "I"
~ ushort "I"
~ ucpv "#C"
~ uchar "C"
	xref	_logger_disk_power_disk_off
	xref	_mem_find_max_malloc
	xref	_log_printf
	xref	_logger_time_get_string
	xref	_logger_time_get_time
	xref	_eng_logger_channel_setup
	xref	_eng_logger_close
	xref	_eng_logger_open
	xref	_sci_logger_is_open
	xref	_sci_logger_setup_partition
	xref	_sci_logger_set_LTA_time
	xref	_sci_logger_set_STA_time
	xref	_sci_logger_set_post_event
	xref	_sci_logger_set_pre_event
	xref	_sci_logger_set_gain
	xref	_sci_logger_set_trigger_level
	xref	_sci_logger_activate_chans
	xref	_sci_logger_get_conversion_rate
	xref	_sci_logger_set_averaging
	xref	_sci_logger_set_conversion_rate
	xref	_sci_logger_start_data
	xref	_sci_logger_close
	xref	_sci_logger_open
	xref	_fabs
	xref	_labs
	xref	_printf
	xref	_SimSetFSys
	xref	_SerSetBaud
	xref	_SerGetBaud
	xref	.begin
	dseg
	global	_logger,8
	xref	_setup_data
	end
