chiark / gitweb /
Merge and end branch-hostside-wip-2008-01-25 PROPERLY; cvs up -j branch-hostside...
[trains.git] / detpic / common.inc
index 116c007b16f46e551c0512ead9114bef0d24dd17..8fc7b7379d8a0a2560c47aeed0a7da7c45b1203a 100644 (file)
@@ -5,7 +5,7 @@
 
 ;----------------------------------------------------------------------
 ; COMMON INCLUDES and BOILERPLATE
-        include         /usr/share/gputils/header/p18f458.inc
+        include         p18f458.inc
         radix           dec 
        include         panic.inc
        include         morse+auto.inc
@@ -22,24 +22,25 @@ tickdiv_us equ tick_us * tickdiv
 ;----------------------------------------------------------------------
 ; Common conventions for function register notation:
 
-;                      Master                  Slave
+;                      Master                          Slave
 ; Registers etc.
-;   W                  Trashed                 Trashed
-;   STATUS             Trashed                 Trashed
-;   BSR                        Not used                Not used
-;   t,u,v              Low ISR                 Low ISR
-;   TBLPTR*,TABLAT     Low ISR                 Low ISR
-;   PROD*              Low ISR                 Low ISR
-;   FSR0               Low ISR                 Low ISR
-;   PCLATU             Always set to 0         Not used
-;   PCLATH             Low ISR                 Not used
-;   t_dolocal          Low ISR                 High ISR
-;   FSR1               Low ISR                 High ISR (detect[1])
-;   FSR2               High ISR (nmra[1])      High ISR (detect[1])
-;
-;   Main loop          detection scan          detection scan
-;   High ISR           NMRA output             I2C service
-;   Low ISRs           everything else         everything else
+;   W                  Trashed                         Trashed
+;   STATUS             Trashed                         Trashed
+;   BSR                        Not used                        Not used
+;   t,u,v              Low ISR                         Low ISR
+;   TBLPTR*,TABLAT     Low ISR                         Low ISR
+;   PROD*              Low ISR                         Low ISR
+;   FSR0               Low ISR                         Low ISR
+;   PCLATU             Always set to 0                 Not used
+;   PCLATH             Low ISR                         Not used
+;   t_dolocal          Low ISR                         High ISR
+;   FSR1               Low ISR                         High ISR (detect[1])
+;   FSR2               High ISR (nmra[1])              High ISR (detect[1])
+;   PORTB              Special read handling[2]        Used normally
+;
+;   Main loop          detection scan                  detection scan
+;   High ISR           NMRA output                     I2C service
+;   Low ISRs           everything else                 everything else
 ;
 ; Trashed      May be trashed by any routine anywhere.  Saved
 ;              during every ISR entry/exit.
@@ -78,6 +79,10 @@ tickdiv_us equ tick_us * tickdiv
 ;      detect_slave_init.  Likewise FSR2 is reserved exclusively
 ;      for the NMRA output ISR after nmra_init.
 ;
+;  [2]  On the master PIC we the interrupt-on-change feature of PORTB.
+;      This means that routines mustn't casually read PORTB.  Instead,
+;      they should call portb_read from serout.asm.
+;
 ; General-purpose hardware allocation:
 ;
 ;                      Master                  Slave
@@ -110,11 +115,11 @@ tickdiv_us equ tick_us * tickdiv
 ;
 ; <something>_intrl    Low ISR service routine.
 ;                      Checks for any relevant interrupt.
-;                      If not, just returns.
+;                      If not, just returns
 ;                      If found, services it and then does either
 ;                       intrl_handled or intrl_handled_nostack
 ;                       neither of which return; the latter is
-;                       faster but implies a promise 
+;                       faster but implies a promise
 ;
 ;----------------------------------------------------------------------
 ; MACROS
@@ -129,7 +134,7 @@ tickdiv_us equ tick_us * tickdiv
 ;  STATUS      any             trashed
 ;  all others  any             preserved
 
-  ifndef NDEBUG
+  ifdef DEBUG
 ;----------
 Dv macro  ; sorry, but assembler's dw directive isn't case-sensitive
 ;
@@ -366,4 +371,12 @@ pinlat_ifl macro   pinspec
        bt_f_if0 LATA + (LATB-LATA)*((pinspec-0xa) & 15), pinspec >> 4
        endm
 
+pin_inw_ifh macro      pinspec
+       bt_w_if1 pinspec >> 4
+       endm
+
+pin_inw_ifl    macro   pinspec
+       bt_w_if0 pinspec >> 4
+       endm
+
 ;----------------------------------------------------------------------