BEGIN { print "; autogenerated - do not edit\n"; } \
next unless m/^(\w+)\s/; \
next if m/^\w+\s+(?:equ|udata|udata_acs)\s+/; \
- print " extern $$1\n" or die $$!; \
+ print " extern $$1\n" or die $$!; \
' <$< $o
%+morse.asm: $(CEBPIC)morse-generator morse.messages %+program.map
mov_lw value >> 8
mov_wf TBLPTRH
- if value > 0xffff
+ if value > 0xffff
mov_lw value >> 16
mov_wf TBLPTRU
- else
+ else
clr_f TBLPTRU
- endif
+ endif
endm
load_perpic_tblptr macro flash_map_base, perpic_entry_size
; and <port> is 0 1 2 3 4 5 6 7. Generally p<picno>_<subsystem>_<pin>
; are equ'd for this.
- radix hex
+ radix hex
p0_cdu_enable equ 5b
p0_rs232_fcin equ 4b
p0_booster_shutdown equ 2b
p0_spare0 equ 0a
p0_booster_dirn equ 0c
p0_booster_pwm equ 1c
- radix dec
+ radix dec
;
; LAT* may be subject to read-modify-write, see below
; FSR2 is used as readout pointer
- include common.inc
+ include common.inc
; I2C protocol is as follows:
;
max_messages equ 4
- udata_acs
+ udata_acs
unattendedl res 1 ; counts up; each det loop it is
unattendedh res 1 ; incremented by no. of bytes of pc in
;----------
backgroundloop_again macro backgroundloop_whatever
- local branchposition
+ local branchposition
inc_f_ifnz unattendedl
bra backgroundloop_whatever
mov_lw branchposition - backgroundloop_whatever
panic morse_DM
;======================================================================
- include final.inc
+ include final.inc
- extern detect_local_init
- extern detect_slave_init
- extern slave_add_short_message
- extern read_detection_head_master
- extern backgroundloop_master
- extern backgroundloop_reversers
- extern backgroundloop_detectors
+ extern detect_local_init
+ extern detect_slave_init
+ extern slave_add_short_message
+ extern read_detection_head_master
+ extern backgroundloop_master
+ extern backgroundloop_reversers
+ extern backgroundloop_detectors
;======================================================================
; TRACK POWER AND SHORT CIRCUIT
- include common.inc
+ include common.inc
settling_timeout equ 10000 ; us
retry_timeout equ 50000 ; us
persist_timeout equ 90000 ; us
- udata_acs
+ udata_acs
settling res 1 ; all counters are 0 if stopped
stop_wait res 1 ; or otherwise count down
retry_wait res 1
- code
+ code
;======================================================================
;
return
;======================================================================
- include final.inc
+ include final.inc
- extern command_power
- extern power_polarising_init
- extern power_polarising_tick
- extern power_polarising_begin
- extern power_polarising_settling
- extern power_fault_init
- extern power_fault_intrl
- extern power_fault_tick
- extern power_fault_tickdiv
- extern power_panichook
+ extern command_power
+ extern power_polarising_init
+ extern power_polarising_tick
+ extern power_polarising_begin
+ extern power_polarising_settling
+ extern power_fault_init
+ extern power_fault_intrl
+ extern power_fault_tick
+ extern power_fault_tickdiv
+ extern power_panichook
- include ../iwjpictest/syncwrite.inc
- include detect.inc
- include energy.fin
- include i2clib+panic.inc
- include mascan.fin
- include misc.fin
- include nmra-stream.fin
- include panic.fin
- include points.fin
- include program.fin
- include reverse.fin
- include routines-led.fin
- include serout.fin
- include tick.fin
- include variables+vars.fin
- include vectors.fin
+ include ../iwjpictest/syncwrite.inc
+ include detect.inc
+ include energy.fin
+ include i2clib+panic.inc
+ include mascan.fin
+ include misc.fin
+ include nmra-stream.fin
+ include panic.fin
+ include points.fin
+ include program.fin
+ include reverse.fin
+ include routines-led.fin
+ include serout.fin
+ include tick.fin
+ include variables+vars.fin
+ include vectors.fin
end
;
; See i2clib.asm for documentation of the interface to this file.
- include /usr/share/gputils/header/p18f458.inc
- radix dec
- include ../iwjpictest/insn-aliases.inc
+ include /usr/share/gputils/header/p18f458.inc
+ radix dec
+ include ../iwjpictest/insn-aliases.inc
- include ../iwjpictest/clockvaries.inc
- include panic.inc
- include morse+auto.inc
- include i2clib.incm
+ include ../iwjpictest/clockvaries.inc
+ include panic.inc
+ include morse+auto.inc
+ include i2clib.incm
;======================================================================
; NOTATION
;======================================================================
- include panic.fin
- include i2clib.inc
+ include panic.fin
+ include i2clib.inc
- end
+ end
; COMMON ADMINISTRATIVE ROUTINES
;--------------------
- extern i2cm_init
+ extern i2cm_init
;
; Initialises the i2c system for use by a master PIC. Must be called
; exactly once, which must be before any other i2c?_... function.
; State Not-in-use Idle (as master)
;--------------------
- extern i2cs_init
+ extern i2cs_init
;
; Initialises the i2c system for use by a slave PIC. Must be called
; exactly once, which must be before any other i2c?_... function.
; W slave number any
;--------------------
- extern i2cm_interrupt
- extern i2cm_interrupt_definite
- extern i2cs_interrupt
+ extern i2cm_interrupt
+ extern i2cm_interrupt_definite
+ extern i2cs_interrupt
;
; Must be called by the main program's interrupt handler;
; high-priority for the slave or low-priority for the master.
; `-------------------------------------'
;--------------------
- extern i2cmu_done
+ extern i2cmu_done
; Called to notify that the previous conversation with the slave has
; been finished as requested. The i2c system is now available and
; MASTER - WRITES (ie, transmission of data to the slave)
;--------------------
- extern i2cm_write_start
+ extern i2cm_write_start
;
; Requests that a slave be contacted for writing. When communication
; has been established, i2cmu_write_next_byte will be called.
; State Idle/Reading-Wait Writing-Setup
; W slave number any
- extern i2cmu_write_next_byte
+ extern i2cmu_write_next_byte
;
; Called to notify the main program that we are now ready to transmit
; a byte to the slave that we're currently talking to. This may be
; MASTER - READS (ie, reception of data from the slave)
;--------------------
- extern i2cm_read_start
+ extern i2cm_read_start
;
; Requests that a slave be contacted for reading. When communication
; has been established and the first byte received,
; State Idle/Reading-Wait Reading-Busy
; W slave number any
- extern i2cmu_read_got_byte
+ extern i2cmu_read_got_byte
;
; Called to notify the main program that a byte has been recieved from
; the slave PIC. The byte value is supplied. Communication with the
; State Reading Reading-Wait
; W data from slave
- extern i2cm_read_another
+ extern i2cm_read_another
;
; Requests that the communication with the slave continue and another
; byte be read. When this is complete, i2cmu_read_got_byte will be
; At call On return
; State Reading-Wait Reading-Busy
- extern i2cm_read_done
+ extern i2cm_read_done
;
; Requests that reading from the slave be terminated. When the
; conversation is finished and the bus and i2c controller are free
; SLAVE - WRITES (ie, reception of data from the master)
;--------------------
- extern i2csu_write_begin
+ extern i2csu_write_begin
;
; Called to notify the main program that the master PIC has selected this
; slave to talk to, for writing. There is no data at this stage; when
; State Idle Receiving Receiving
;--------------------
- extern i2csu_write_data
+ extern i2csu_write_data
;
; Called to notify the main program that the master PIC has
; transmitted a byte of data. Provides the byte we received.
; SLAVE - READS (ie, transmission of data to the master)
;--------------------
- extern i2csu_read_begin
+ extern i2csu_read_begin
;
; Called to notify the main program that the master PIC has selected
; this slave to talk to, for reading. The main program should invoke
; State Idle Transmit-Wait
;--------------------
- extern i2cs_read_data
+ extern i2cs_read_data
; Transmits the byte of data to the master
;
; Beforehand At call On return
; in i2clib.incm, which does the same thing.
;--------------------
- extern i2csu_read_another
+ extern i2csu_read_another
;
; Called to notify the main program that the master PIC has continued
; by asking for another byte of data. The main program should once
} elsif (m/^(\w*)\s+(?:equ)\b/) {
} elsif (m/^\s+extern\s+(\w+)\b/) {
mangle($1);
- print " extern $pfx$1;##\n" or die $!
+ print " extern $pfx$1;##\n" or die $!
unless $manglout;
} elsif (!$inmacro && defined $codesection) {
if (!s/^\;/;\#\#/) {
$l= '';
}
if (m/^\s+include\s+(\S+)\s+$/ && exists $mapinclude{$1}) {
- $l= " include $mapinclude{$1}\n";
+ $l= " include $mapinclude{$1}\n";
}
print $l or die $!
unless $manglout;
;======================================================================
; MASTER - SCANNING ETC.
- include common.inc
+ include common.inc
;----------------------------------------------------------------------
- udata_acs
+ udata_acs
; for reading and detection:
b res 1 ; byte just read
bc_f STATUS, Z ; yes, we want to write this byte
return ; from i2cmu_write_next_byte
- code
+ code
;----------------------------------------
i2cmu_write_next_byte
; add calls to getwritebyte_<foo> here:
bra mascan_init_loop
; we've read the whole flash table
- if slavetable == 0x400
+ if slavetable == 0x400
bt_f_if1 FSR0H, 0
bra mascan_bad_toomany
- endif
+ endif
clr_f POSTINC0 ; ste_slave
mov_lw (1<<stf_detect)|(1<<stf_sentinel)
goto serial_addbyte_another
;======================================================================
- include final.inc
+ include final.inc
- extern i2cm_intrl
- extern mascan_init
- extern loopback_read_byte
- extern i2c_needwrite
- extern i2c_consider_restartread
- extern i2c_getwritebyte_yes
+ extern i2cm_intrl
+ extern mascan_init
+ extern loopback_read_byte
+ extern i2c_needwrite
+ extern i2c_consider_restartread
+ extern i2c_getwritebyte_yes
;======================================================================
- include common.inc
- code
+ include common.inc
+ code
;======================================================================
; GENERALLY USEFUL ROUTINES
bra_nn init_bitnum2bit_loop
return
- include final.inc
+ include final.inc
- extern read_pic_no
- extern idlocs_init
- extern bitnum2bit_init
+ extern read_pic_no
+ extern idlocs_init
+ extern bitnum2bit_init
clock equ mclock ; this part runs really only on master
- include common.inc
+ include common.inc
- udata_acs
+ udata_acs
nmractrl res 1 ; state relevant to NMRA control
transmitbit equ 7 ; bit 7: 0/1 bit currently being transmitted
buffer2 res 16
buffer3 res 16
- code
+ code
;****************************************************************************
;****************************************************************************
- include final.inc
+ include final.inc
- extern nmra_init
- extern serial_init
- extern serial_interrupts_init
- extern nmra_serialrx_intrl
- extern nmra_restartmessage
+ extern nmra_init
+ extern serial_init
+ extern serial_interrupts_init
+ extern nmra_serialrx_intrl
+ extern nmra_restartmessage
;---------------------------------------------------------------------------
; reserved access bank locations
- udata_acs
+ udata_acs
psave_intcon res 1
psave_bsr res 1
;----------
panicd_serialrx_err
bs_f panicst, panicst_ferroerr
- bc_f RCSTA, RCEN ; disable } to clear FERR/OERR
- mov_fw RCREG ; read RCREG } (see PIC18FXX8 DS p182)
+ bc_f RCSTA, RCEN ; disable } to clear FERR/OERR
+ mov_fw RCREG ; read RCREG } (see PIC18FXX8 DS p182)
bs_f RCSTA, RCEN ; reenable }
panicd_serialrx_err_loop
bt_f_if0 PIR1, RCIF ; wait for a byte 0x01 to ack the overrun/error
- extern panic_routine
- extern panic_kill_hook
- extern panic_crashread_setpointer
- extern panic_crashread_commanded
- extern i2csu_write_panicd
- extern i2csu_read_begin_panicd
- extern i2csu_read_another_panicd
- extern command_crashed
- extern got_aargh
+ extern panic_routine
+ extern panic_kill_hook
+ extern panic_crashread_setpointer
+ extern panic_crashread_commanded
+ extern i2csu_write_panicd
+ extern i2csu_read_begin_panicd
+ extern i2csu_read_another_panicd
+ extern command_crashed
+ extern got_aargh
;======================================================================
; POINTS
- include common.inc
+ include common.inc
;======================================================================
; VARIABLES, HARDWARE, ETC
ptix2latbit equ 0x300 ; has to be a multiple of 0x100
ptix2latbit_section udata ptix2latbit
- res maxpoints * 2 ; LAT* and bit
+ res maxpoints * 2 ; LAT* and bit
; for unused point, 0x00 and 0x00
- udata_acs
+ udata_acs
pointslave res 1
pointmsg res 1
cducharging res 1
- udata 0x340
+ udata 0x340
slave2ptinfo res maxpics
slave2ptinfo_anypoints equ 0
pointed_already_charging panic morse_PQ
;======================================================================
- include final.inc
+ include final.inc
- extern command_point
- extern points_master_init
- extern point_local_do
- extern points_local_init
- extern points_local_intrl
- extern points_needwrite
- extern points_getwritebyte
- extern got_pointed
- extern cdu_init
- extern cdu_tickdiv
- extern cdu_on
- extern cdu_off
- extern cdu_panichook
+ extern command_point
+ extern points_master_init
+ extern point_local_do
+ extern points_local_init
+ extern points_local_intrl
+ extern points_needwrite
+ extern points_getwritebyte
+ extern got_pointed
+ extern cdu_init
+ extern cdu_tickdiv
+ extern cdu_on
+ extern cdu_off
+ extern cdu_panichook
;======================================================================
; MAIN PROGRAM AND GLUE
- include common.inc
- code
+ include common.inc
+ code
;======================================================================
; COMMON TO MASTER AND SLAVE
goto loopback_read_byte
;======================================================================
- include final.inc
+ include final.inc
- extern serialrx_generalmsg
- extern message_for_master
- extern master_interrupt_high_notnmra
+ extern serialrx_generalmsg
+ extern message_for_master
+ extern master_interrupt_high_notnmra
;======================================================================
; REVERSERS
- include common.inc
+ include common.inc
;----------------------------------------
; LOCAL REVERSERS - Variables
- udata_acs
+ udata_acs
maska res 1
maske res 1
polarity_cmds equ 0x5f
polarity_cmds_section udata polarity_cmds
- res maxpics
+ res maxpics
; Each byte is:
; 11RRRRRR reverse command for slave, waiting to write
; 00000001 this is not a reversers board
; v<n> is new reverse bit
return
- code
+ code
;----------
polarity_local_init
load_perpic_tblptr picno2revmasks, 2
return
;======================================================================
- include final.inc
+ include final.inc
- extern command_polarity
- extern polarity_local_do
- extern polarity_local_init
- extern polarity_master_init
- extern polarity_needwrite
- extern polarity_getwritebyte
+ extern command_polarity
+ extern polarity_local_do
+ extern polarity_local_init
+ extern polarity_master_init
+ extern polarity_needwrite
+ extern polarity_getwritebyte
;======================================================================
; SERIAL PORT - TRANSMISSION TO HOST
- include common.inc
- code
+ include common.inc
+ code
;----------------------------------------
serial_addbyte
; W byte to xmit to host trashed
goto serial_addbyte
;======================================================================
- include final.inc
+ include final.inc
- extern serial_addbyte
- extern serial_addbyte_another
- extern serialtx_intrl
- extern serialtxfc_init
- extern serialtxbuf_init
- extern portb_read
+ extern serial_addbyte
+ extern serial_addbyte_another
+ extern serialtx_intrl
+ extern serialtxfc_init
+ extern serialtxbuf_init
+ extern portb_read
; after tick_init, and after interrupts enabled,
; we call <foo>_tick every 1ms and <foo>_tickdiv every <tickdiv>ms.
- include common.inc
+ include common.inc
- udata_acs
+ udata_acs
tickdiv_count res 1
- code
+ code
;----------------------------------------
tick_init
; Timer 2 any used for tick
intrl_handled_nostack
;----------------------------------------------------------------------
- include final.inc
+ include final.inc
- extern tick_init
- extern tick_intrl
+ extern tick_init
+ extern tick_intrl
;======================================================================
- include pindata.inc
+ include pindata.inc
- udata_acs
+ udata_acs
picno res 1 ; from first idlocs byte
idloc1 res 1 ; from 2nd idlocs byte; bit 7 is master:
; each board actually present has an entry in this table
ste_szln2 equ 3
ste_size equ (1<<ste_szln2)
- res maxpics * ste_size
+ res maxpics * ste_size
; each entry is a number of bytes, at these offsets:
ste_slave equ 0 ; Gk slave number
stf_detect equ 7 ; Gk this is a detectors board
stf_sentinel equ 6 ; Gk sentinel slot at end of table
- include final.inc
+ include final.inc
;======================================================================
- extern vector_reset
- extern master_interrupt_low
- extern master_interrupt_high
- extern slave_interrupt_low
+ extern vector_reset
+ extern master_interrupt_low
+ extern master_interrupt_high
+ extern slave_interrupt_low
radix dec
include ../iwjpictest/insn-aliases.inc
- code
+ code
;----------------------------------------
serial_write_char
; W character undefined
return
;======================================================================
- include ../iwjpictest/syncwrite.inc
- end
+ include ../iwjpictest/syncwrite.inc
+ end
sub o_section ($$) {
my ($sec,$docstring) = @_;
o("\n;----------\n".
- " org $sec\n");
+ " org $sec\n");
o($docstring);
}
sub o_section_end_fill ($$$) {
} else {
o("\n");
}
- o(sprintf " fill %s, %d*(maxpics-%d)\n\n",
+ o(sprintf " fill %s, %d*(maxpics-%d)\n\n",
$fillvalue, $entrysize, $lastnumdone);
}
sub o_db ($;$) {
my ($ix,$every) = @_;
$every=16 unless defined $every;
- o(($every ? $ix % $every : $ix) ? ',' : "\n db ");
+ o(($every ? $ix % $every : $ix) ? ',' : "\n db ");
}
sub writeasm_sense {
"Detectors equ 0x80\n".
"Reversers equ 0x00\n\n");
for ($num=0; $num<@boardtype; $num++) {
- if (!defined $boardtype[$num]) { o(" dw 0\t\t\t\t; $num\n"); next; }
+ if (!defined $boardtype[$num]) { o(" dw 0\t\t\t\t; $num\n"); next; }
$base= $sensesbase[$num];
- o(sprintf " db SenseExists | 0x%02x, %12s | 0x%02x\t; %d\n",
+ o(sprintf " db SenseExists | 0x%02x, %12s | 0x%02x\t; %d\n",
$base >> 7, ucfirst($boardtype[$num]), $base & 0x7f, $num);
}
o_section_end_fill($num, 0, 2);
; or boards with no points are all-bits-0.
END
for ($num=0; $num<@boardtype; $num++) {
- if (!defined $boardtype[$num]) { o(" dw 0\t\t\t\t; $num"); next; }
+ if (!defined $boardtype[$num]) { o(" dw 0\t\t\t\t; $num"); next; }
die if $maxptixln2 < 4; # must be whole no. of 16-bit words
$elemsize= 1 << ($maxptixln2-3);
for ($byte=0; $byte < $elemsize; $byte++) {
; Index: 00Dppppp where D is 1 iff detectors board and p is pt ix
; Value: 0ppp0bbb where p is port num and b is bit num; or 0xff
END
- o(" radix hex\n");
+ o(" radix hex\n");
for ($typeix=0; $typeix<2; $typeix++) {
$type= qw(reversers detectors)[$typeix];
die $type unless $pin_info{$type};
}
o("\n");
}
- o(" radix dec\n\n");
+ o(" radix dec\n\n");
}
sub writeasm_reverse {
$pu->[1] =~ m/^([04])\,\d,(0x\w{2})$/ or die;
push @{ $portae[!!$1] }, $2;
}
- o(' db ');
+ o(' db ');
o(join(', ', map { @$_ ? join('|',@$_) : '0' } @portae));
o(sprintf " ; %d\n",$num);
}
close STDOUT or die $!;
open STDOUT, ">$basename+pindata.asm" or die $!;
o("; autogenerated - do not edit\n");
- o(" include pindata.inc\n".
- " radix dec\n".
+ o(" include pindata.inc\n".
+ " radix dec\n".
"ff equ 0xff\n");
$each= 10;
for $k (@objkinds) {
&{"writeasm_$k"}();
}
- o("\n end\n");
+ o("\n end\n");
}
mainread();
writeout();