chiark / gitweb /
points wip
[trains.git] / detpic / common.inc
1 ;======================================================================
2 ; common.inc
3 ; common macros & equs etc.
4 ; generally include this at the top of each file.
5
6 ;----------------------------------------------------------------------
7 ; COMMON INCLUDES and BOILERPLATE
8         include         /usr/share/gputils/header/p18f458.inc
9         radix           dec 
10         include         panic.inc
11         include         morse+auto.inc
12         include         ../iwjpictest/insn-aliases.inc
13 clock equ -1
14         include         ../iwjpictest/clockvaries.inc
15         include         variables+vars.inc
16
17 ;----------------------------------------------------------------------
18 ; Common conventions for function register notation:
19
20 ;                       Master                  Slave
21 ; Registers etc.
22 ;   W                   Trashed                 Trashed
23 ;   STATUS              Trashed                 Trashed
24 ;   BSR                 Not used                Not used
25 ;   t                   Low ISR                 Low ISR
26 ;   TBLPTR*,TABLAT      Low ISR                 Low ISR
27 ;   FSR0                Low ISR                 Low ISR
28 ;   FSR1                Low ISR                 High ISR (detect)
29 ;   FSR2                Low ISR                 High ISR (detect)
30 ;
31 ; Trashed       May be trashed by any routine anywhere.  Saved
32 ;               during every ISR entry/exit.
33 ;
34 ; Low ISR       May be used/traashed by any routine run in low-priority
35 ;               interrupt, or any routine run during initialisation.
36 ;               May therefore not be used in background loop with
37 ;               interrupts enabled.  May not be used by high-priority
38 ;               ISR (unless explicitly saved).
39 ;
40 ; High ISR      May be used/trashed by any routine run in high-priority
41 ;               interrupt, or any routine run during initialisation.
42 ;               May therefore not be used elsewhere with interrupts
43 ;               enabled.
44 ;
45 ;               Only the routines specially noted as intended to
46 ;               be called from the High ISR are safe.
47 ;
48 ; ... (subsystem)
49 ;               Register is reserved for use by this subsystem, which
50 ;               is allowed to expect the value to be preserved.
51 ;               Anything else which uses it must save and restore (and
52 ;               may also need to disable interrupts, depending on its
53 ;               relative status).
54 ;
55 ; Not High      May be used by any routine not running in high-priority
56 ;               interrupt.  Not saved by high-priority interrupt
57 ;               entry/exit, so any high-priority interrupt routine which
58 ;               uses this register must save and restore it.
59 ;
60 ; A routine which is allowed to trash a register may document that it
61 ; saves that register for the benefit of its callers.
62 ;
63 ; General-purpose hardware allocation:
64 ;
65 ;                       Master                  Slave
66 ;  Timer 0              nmra                    Disabled
67 ;  Timer 2              -                       -
68 ;  Timer 1              1ms tick, int. low      1ms tick, int. low
69 ;  CCP1                 1ms tick, int. low      1ms tick, int. low
70 ;  Timer 3              point fire timer        point fire timer
71 ;  ECCP                 -                       -
72
73 ;----------------------------------------------------------------------
74 ; MACROS
75
76 ;----------------------------------------------------------------------
77 ; PINSPECS stuff
78 ;
79 ; A PINSPEC is a constant 0x<bit><port> where <port> is a b c d e
80 ; and <port> is 0 1 2 3 4 5 6 7.  Generally p<picno>_<subsystem>_<pin>
81 ; are equ'd for this.
82
83  radix hex
84 p0_cdu_enable           equ     5b
85 p0_rs232_fcin           equ     4b
86 p0_booster_shutdown     equ     2b
87 p0_booster_overload     equ     1b
88 p0_booster_userfault    equ     0b
89 p0_spare2               equ     6d
90 p0_spare1               equ     5d
91 p0_rs232_fcout          equ     5c
92 pall_perpicled          equ     2d
93 pall_pt0reverse         equ     7b
94 p0_spare0               equ     0a
95 p0_booster_dirn         equ     0c
96 p0_booster_pwm          equ     1c
97  radix dec
98
99 pin_z   macro   pinspec
100         bs_f    TRISA + (TRISB-TRISA)*((pinspec-0xa) & 15), pinspec >> 4
101         endm
102
103 pin_nz  macro   pinspec
104         bc_f    TRISA + (TRISB-TRISA)*((pinspec-0xa) & 15), pinspec >> 4
105         endm
106
107 pin_vh  macro   pinspec
108         bs_f    LATA + (LATB-LATA)*((pinspec-0xa) & 15), pinspec >> 4
109         endm
110
111 pin_vl  macro   pinspec
112         bc_f    LATA + (LATB-LATA)*((pinspec-0xa) & 15), pinspec >> 4
113         endm
114
115 pin_h   macro   pinspec
116         pin_vh  pinspec
117         pin_nz  pinspec
118         endm
119
120 pin_l   macro   pinspec
121         pin_vl  pinspec
122         pin_nz  pinspec
123         endm
124
125 pin_ifh macro   pinspec
126         bt_f_if1 PORTA + (PORTB-PORTA)*((pinspec-0xa) & 15), pinspec >> 4
127         endm
128
129 pin_ifl macro   pinspec
130         bt_f_if0 PORTA + (PORTB-PORTA)*((pinspec-0xa) & 15), pinspec >> 4
131         endm
132
133 ;----------------------------------------------------------------------