*+morse.asm
*+clocks.inc
+*+externs.fin
*.cod
*.hex
*.lst
CEBPIC= ../cebpic/
PICNOS= 0 1 2
+FILES= variables vectors \
+ panic routines-led i2clib+panic \
+ misc detect points serout \
+ syncwrite mascan energy \
+ reverse nmra-stream tick
+
PROGRAMS= program
-OBJS_program= variables.o vectors.o \
- panic.o routines-led.o i2clib+panic.o \
- misc.o detect.o points.o serout.o \
- syncwrite.o mascan.o energy.o \
- reverse.o nmra-stream.o tick.o
+OBJS_program= $(addsuffix .o, $(FILES))
XCODEN_program= morse
XCODE1_program= ours+pindata
-INCLUDES= \
- ../iwjpictest/clockvaries.inc \
- common.inc \
- detect.inc \
- energy.fin \
- final.inc \
- i2clib+panic.inc \
- i2clib.incm \
- misc.fin \
- mascan.fin \
- nmra-stream.fin \
- panic.fin \
- panic.inc \
- pindata.inc \
- points.fin \
- program+clocks.inc \
- program.fin \
- reverse.fin \
- routines-led.fin \
- serout.fin \
- tick.fin \
- vectors.fin \
+INCLUDES= \
+ common.inc \
+ panic.inc \
+ ../iwjpictest/clockvaries.inc \
+ pindata.inc \
+ program+clocks.inc \
+ i2clib.incm \
+ final.inc \
+ ../iwjpictest/syncwrite.inc \
+ i2clib+panic.inc \
+ program+externs.fin
VARSFILES= variables
SYNCWRITES= syncwrite.asm syncwritehex.asm
$(SYNCWRITES): %: ../iwjpictest/%
cp $< $@
+%+externs.fin: make-externs %.asm $(addsuffix .asm, $(FILES))
+ ./$+ >$@.new
+ diff -q $@ $@.new || mv -vf $@.new $@
+
i2clib+panic.%: make-panicworthy i2clib+panic.mangles i2clib.%
./$+ -Ii2clib.inc,i2clib+panic.inc $o
;----------------------------------------------------------------------
; MACROS
+@ macro
+ endm
+
;----------------------------------------
; For entering and leaving Low ISR, saving and restoring STATUS and W
; See above under <something>_intrl, and {master,slave}_interrupt_low
code
;----------
-detect_local_init
+detect_local_init @
mov_lw b'111' ; turn off comparator, or we can't use pins
mov_wf CMCON ; RD0-RD4 as digital inputs
mov_lw b'0110' ; turn off A/D except perhaps for pin
return
;----------
-detect_slave_init
+detect_slave_init @
mov_lfsr outbuf, 2
clr_f outmsg_end
goto reset_detectread
;----------------------------------------
-slave_add_short_message
+slave_add_short_message @
; Queues a message byte for transmission to the master.
; It will be transmitted as an extra message byte, when we are polled.
; W message unchanged
; on the left, above.
;----------
-backgroundloop_detectors
+backgroundloop_detectors @
rr_fw PORTB ; W xx xx xx xx 04 20 17 xx (now)
and_wff scanb ; b xx xx xx xx 04 20 17 xx (cumulative)
rl_fw PORTA ; W 19 09 12 15 18 xx xx xx (now)
bt_f_if0 PORTE,2 ; 02 (now)
bc_f buf0,4 ; buf0 MM zz zz 02 zz ss zz zz (cumulative)
endm
-backgroundloop_reversers
+backgroundloop_reversers @
backgroundloop_reversers_core
backgroundloop_again backgroundloop_reversers
; FOR MASTER
;----------
-backgroundloop_master
+backgroundloop_master @
backgroundloop_reversers_core
bra backgroundloop_master
;----------
-read_detection_head_master
+read_detection_head_master @
read_begin_calc_buf0_reversers
bra_n read_detection_head_master_badmore
set_f scana
+++ /dev/null
- 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
;----------------------------------------------------------------------
;--------------------
-power_polarising_init
+power_polarising_init @
clr_f settling
pin_h p0_booster_pwm
return
;--------------------
-power_polarising_begin
+power_polarising_begin @
pin_vl p0_booster_pwm
bc_f INTCON, TMR0IE ; disables NMRA interrupt
bs_f flags, flags_polarising
return
;--------------------
-power_polarising_settling
+power_polarising_settling @
; idempotent
tst_f_ifnz settling
return
return
;--------------------
-power_polarising_tick
+power_polarising_tick @
tst_f_ifnz settling
dec_f_ifnz settling ; decrement if not zero
return ; return if not dec'd, or if decrement didn't make zero
; (uses tickdiv) (uses tick)
;--------------------
-power_fault_init
+power_fault_init @
bs_f INTCON2, INTEDG1 ; rising edge
bc_f INTCON3, INT1IP
bc_f INTCON3, INT1IF
return
;--------------------
-command_power
+command_power @
bra_nc command_power_off
; command is ON:
goto cdu_off
;--------------------
-power_fault_intrl
+power_fault_intrl @
bt_f_if0 INTCON3, INT1IF
return
; we have a fault:
intrl_handled_nostack
;--------------------
-power_fault_tick
+power_fault_tick @
tst_f_ifnz retry_wait
dec_f_ifnz retry_wait
return
return
;--------------------
-power_fault_tickdiv
+power_fault_tickdiv @
tst_f_ifnz stop_wait
dec_f_ifnz stop_wait
return
return
;--------------------
-power_panichook
+power_panichook @
pin_vh p0_booster_shutdown
pin_vl p0_booster_pwm
pin_vh p0_booster_userfault
+++ /dev/null
- 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 program+externs.fin
end
;======================================================================
- include panic.fin
+ include program+externs.fin
include i2clib.inc
end
--- /dev/null
+#!/usr/bin/perl -n
+BEGIN { print "; autogenerated - do not edit\n; @ARGV\n;\n\n" or die $!; }
+next unless m/^(\w+)\s+\@\s*(?:\;.*)?$/;
+printf " extern %-40s ; %s\n", $1, $ARGV or die $!;
near_getwritebyteyes code
;----------------------------------------
-i2c_getwritebyte_yes
+i2c_getwritebyte_yes @
pop ; we don't care where we were in i2cmu_write_next_byte
bc_f STATUS, Z ; yes, we want to write this byte
return ; from i2cmu_write_next_byte
return
;----------------------------------------
-i2cm_intrl
+i2cm_intrl @
; handles i2c interrupt using i2cm_interrupt[_definite],
; according to the rules for <something>_intrl.
bt_f_if0 PIR1, SSPIF
bra nextslave_nowrite
;----------------------------------------
-i2c_needwrite
+i2c_needwrite @
; Informs mascan that we need to write to some slave.
; Some time after this, mascan will call getwritebyte_<everything>
; and this must yield at least one byte to write.
goto i2cm_write_start
;----------------------------------------
-i2c_consider_restartread
+i2c_consider_restartread @
bt_f_if0 cbyte, cbyte_halted
return
bra nextslave_nowrite
;======================================================================
; INITIALISATION
-mascan_init
+mascan_init @
mov_lw (slavetable + ste_flags + ste_size) & 0xff
; start with 1st actual slave
mov_wf cslot
near_gots code
;----------------------------------------
-process_got_extra
+process_got_extra @
mov_fw b
-loopback_read_byte
+loopback_read_byte @
;...
; W message
xor_lw 0x00 ^ 0x20
+++ /dev/null
- extern i2cm_intrl
- extern mascan_init
- extern loopback_read_byte
- extern i2c_needwrite
- extern i2c_consider_restartread
- extern i2c_getwritebyte_yes
; GENERALLY USEFUL ROUTINES
;----------
-read_pic_no
+read_pic_no @
; read pic no from ID locations and return it
; W undefined pic number from ID loc 0
; status Z undefined 1 iff master PIC
return
;----------
-idlocs_init
+idlocs_init @
; read id locations and store in canonical place
; W undefined undefined
; picno undefined pic number (from 20000)
return
;----------
-bitnum2bit_init
+bitnum2bit_init @
; populate bitnum2bit
mov_lw 0x80
mov_lfsr bitnum2bit,0
+++ /dev/null
- extern read_pic_no
- extern idlocs_init
- extern bitnum2bit_init
;****************************************************************************
-serial_init
+serial_init @
; serial set-up
; initial config - TXSTA register p181
bc_fa TXSTA,6 ; p181, set 8-bit mode
;----------------------------------------------------------------------------
-nmra_init
+nmra_init @
; timer 0 set-up
; timer0 initial config for NMRA timer
bs_fa nmractrl,nextaction
bs_fa nmractrl,transmitbit
-nmra_restartmessage ; Entrypoint from power_polarising_tick, at end
+nmra_restartmessage @ ; Entrypoint from power_polarising_tick, at end
; of settle time. Goes back to beginning of
; current message (if any) and retransmits it.
; Also, enables booster PWM and Timer 0 interrupts.
;****************************************************************************
-nmra_serialrx_intrl
+nmra_serialrx_intrl @
bt_f_if0 PIR1,RCIF ; check whether serial recv interrupt bit set
return
master_interrupt_high_notnmra
panic morse_IH
-master_interrupt_high
+master_interrupt_high @
bt_f_if0 INTCON,TMR0IF ; check whether timer0 interrupt set
bra master_interrupt_high_notnmra
; timer0 interrupt
+++ /dev/null
- extern nmra_init
- extern serial_init
- extern serial_interrupts_init
- extern nmra_serialrx_intrl
- extern nmra_restartmessage
;****************************************************************************
-panic_routine
+panic_routine @
; switch off interrupts and power
; reconfigure timer0 for writing diagnostic msg to the LED
near_gots code
;----------
-got_aargh
+got_aargh @
panic morse_T
near_serialrx_table code 0x2100
;----------
-command_crashed
-panic_crashread_commanded
+command_crashed @
+panic_crashread_commanded @
bs_f panicst, panicst_acked ; since we were asked to
panic morse_E
+++ /dev/null
- 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
near_local_do code
;----------------------------------------
-point_local_do
+point_local_do @
; On slave, called during i2c receive, ie High ISR
; On master, called during serial receive, ie Low ISR
; W fire point msg undefined
points_section code
;----------------------------------------
-points_local_intrl
+points_local_intrl @
bt_f_if0 PIR2, TMR3IF
return
; OK, it's us, and we're done changing a point:
; LOCAL POINTS - INITIALISATION
;----------------------------------------
-points_local_init
+points_local_init @
; Initialises tables for points
; Clears TRIS* bits for all points and sets each pin to `not triggering'
; MASTER
;----------------------------------------------------------------------
-points_master_init
+points_master_init @
clr_f pointslave
clr_f pointmsg
return
;----------------------------------------------------------------------
-command_point
+command_point @
; FSR0 -> 1 0100 TTT O TTTTTTT
; ie 1010 0SSS
; OssT tttt
panic morse_PS
;----------
-points_needwrite
+points_needwrite @
rr_fw pointslave ; W = 000S SSss
bt_f_if1 STATUS, Z ; nothing ?
return
goto i2c_needwrite
;----------
-points_getwritebyte
+points_getwritebyte @
rr_fw pointslave
xor_wfw cwslave
bt_f_if0 STATUS, Z ; right slave ?
; CDU
;--------------------
-cdu_init
+cdu_init @
clr_f pointslave
clr_f pointmsg
;...
;-----
-cdu_off
-cdu_panichook
+cdu_off @
+cdu_panichook @
pin_l p0_cdu_enable
;...
;-----
return
;--------------------
-cdu_on
+cdu_on @
pin_h p0_cdu_enable
return
;--------------------
-cdu_tickdiv
+cdu_tickdiv @
pinlat_ifl p0_cdu_enable
return
near_gots code
;--------------------
-got_pointed
+got_pointed @
tst_f_ifnz cducharging
bra pointed_already_charging
+++ /dev/null
- 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
; COMMON TO MASTER AND SLAVE
;----------------------------------------
-vector_reset
+vector_reset @
set_f qqTRISA
set_f qqTRISB
return
;----------------------------------------
-panic_kill_hook
+panic_kill_hook @
call power_panichook
call cdu_panichook
return
;----------
-intrl_handled_routine
+intrl_handled_routine @
mov_ff isr_low_save_stkptr, STKPTR
intrl_handled_core
return
;----------------------------------------
-master_interrupt_low
+master_interrupt_low @
enter_interrupt_low
mov_ff INTCON, xdebug+0
mov_ff INTCON2, xdebug+1
serialrx_table_section code 0x2000
;--------------------
-serialrx_generalmsg
+serialrx_generalmsg @
;command_<something> has same calling convention:
;
; FSR0 -> start of message undefined
return
;----------------------------------------
-slave_interrupt_low
+slave_interrupt_low @
enter_interrupt_low
call points_local_intrl
panic morse_IL
; MASTER/SLAVE deviations
;----------
-message_for_master
+message_for_master @
; Either transmits the message to the master, or if we are the master,
; handles it as an incoming message from the notional `slave 0'.
; W message unchanged
+++ /dev/null
- extern serialrx_generalmsg
- extern message_for_master
- extern master_interrupt_high_notnmra
near_local_do code
;----------
-polarity_local_do
+polarity_local_do @
; On slave, called during i2c receive, ie High ISR
; On master, called during serial receive, ie Low ISR
; See common.inc !
code
;----------
-polarity_local_init
+polarity_local_init @
load_perpic_tblptr picno2revmasks, 2
tblrd_postinc_fixup
; MASTER
;----------
-command_polarity
+command_polarity @
; message format
; SS zz zz SS ZZ 2f 2e 2d g is board 2
; MM 2c 0f 0e 0d 0c 0b 0a board 0
panic morse_RL
;----------------------------------------------------------------------
-polarity_master_init
+polarity_master_init @
load_tblptr picno2revmasks
mov_lfsr polarity_cmds - 1, 0
polarity_bad_lastpicused panic morse_RG
;----------------------------------------------------------------------
-polarity_needwrite
+polarity_needwrite @
; needwrite_<something> will see if we need to talk to a slave
; if not it will simply return
; if we _do_, it will put the slave no. in W, and then pop
near_getwritebyteyes code
;----------------------------------------------------------------------
-polarity_getwritebyte
+polarity_getwritebyte @
; getwritebyte_<something> finds a byte to write to a particular
; slave. If we have something to write, puts the byte in W
; and does `goto getwritebyte_yes'. Otherwise simply returns.
+++ /dev/null
- extern command_polarity
- extern polarity_local_do
- extern polarity_local_init
- extern polarity_master_init
- extern polarity_needwrite
- extern polarity_getwritebyte
code
;----------------------------------------
-led_red
+led_red @
; makes the LED be red (or orange), no matter its previous state
; no RAM locations used or modified
; W is unchanged
return
;----------------------------------------
-led_green
+led_green @
; makes the LED be green (or blue), no matter its previous state
; no RAM locations used or modified
; W is unchanged
return
;----------------------------------------
-led_black
+led_black @
; makes the LED be black (off), no matter its previous state
; no RAM locations used or modified
; W is unchanged
+++ /dev/null
- extern led_green
- extern led_red
- extern led_black
addbyte_toomany panic morse_HB
;----------------------------------------
-serial_addbyte
+serial_addbyte @
; W byte to xmit to host trashed
; FSR0 any set for serial_addbyte_another
; outbuf, outmsg_* buffer not full adjusted appropriately
mov_ff outmsg_end, FSR0L
;...
;----------------------------------------
-serial_addbyte_another
+serial_addbyte_another @
; W byte to xmit to host trashed
; FSR0 from _addbyte[_another] updated for ..._another again
; outbuf, outmsg_* buffer not full adjusted appropriately
;...
;----------------------------------------
-portb_read
+portb_read @
;
; W undefined value from PORTB
; TXIE any enabled iff host allows us to xmit
goto led_red ; flow control forces us not to transmit
;----------------------------------------------------------------------
-serialtxfc_intrl
+serialtxfc_intrl @
bt_f_if0 INTCON, RBIF
return
; yes, it's us:
intrl_handled_nostack
;----------------------------------------------------------------------
-serialtxfc_init
+serialtxfc_init @
bc_f INTCON2, RBIP
bs_f INTCON, RBIE
rcall portb_read
; ACTUAL TRANSMISSION
;----------------------------------------------------------------------
-serialtx_intrl
+serialtx_intrl @
; are we ready to transmit ?
bt_f_if0 PIR1, TXIF
return
intrl_handled_nostack
;----------------------------------------------------------------------
-serialtxbuf_init
+serialtxbuf_init @
clr_f outmsg_end
clr_f outmsg_begin
mov_lw b'00001001'
+++ /dev/null
- extern serial_addbyte
- extern serial_addbyte_another
- extern serialtx_intrl
- extern serialtxfc_intrl
- extern serialtxfc_init
- extern serialtxbuf_init
- extern portb_read
code
;----------------------------------------
-tick_init
+tick_init @
; Timer 2 any used for tick
mov_lw tick_master_t2scale ; disable (in case already running)
mov_wf T2CON
return
;----------------------------------------
-tick_intrl
+tick_intrl @
bt_f_if0 PIR1, TMR2IF
return
; we have an interrupt
+++ /dev/null
- extern tick_init
- extern tick_intrl
+++ /dev/null
- extern vector_reset
- extern master_interrupt_low
- extern master_interrupt_high
- extern slave_interrupt_low