OSDN Git Service

V4.0
[fast-forth/master.git] / MSP430-FORTH / BOOT.f
1
2 ; --------
3 ; BOOT.f
4 ; --------
5 \
6 \ TARGET SELECTION ( = the name of \INC\target.pat file without the extension)
7 \ MSP_EXP430FR5739  MSP_EXP430FR5969    MSP_EXP430FR5994    MSP_EXP430FR6989
8 \ MSP_EXP430FR4133  CHIPSTICK_FR2433    MSP_EXP430FR2433    MSP_EXP430FR2355
9 \ LP_MSP430FR2476
10 \
11 \ from scite editor : copy your target selection in (shift+F8) parameter 1:
12 \
13 \ or, from windows explorer:
14 \ drag and drop this file onto SendSourceFileToTarget.bat
15 \ then select your TARGET when asked.
16 \
17 \ SYSRSTIV decimal/hex values for MSP430FR5994 (device specific)
18 \ ----------------------------------------------------------
19 \ #00 $00 No interrupt pending
20 \ #02 $02 Brownout (BOR)
21 \ #04 $04 RSTIFG RST/NMI (BOR)
22 \ #06 $06 PMMSWBOR software BOR (BOR)
23 \ #08 $08 LPMx.5 wake up (BOR)
24 \ #10 $0A violation memory protected areas (BOR)
25 \ #12 $0C Reserved
26 \ #14 $0E SVSHIFG SVSH event (BOR)
27 \ #16 $10 Reserved
28 \ #18 $12 Reserved
29 \ #20 $14 PMMSWPOR software POR (POR)
30 \ #22 $16 WDTIFG watchdog timeout (PUC)
31 \ #24 $18 WDTPW password violation (PUC)
32 \ #26 $1A FRCTLPW password violation (PUC)
33 \ #28 $1C Uncorrectable FRAM bit error detection (PUC)
34 \ #30 $1E Peripheral area fetch (PUC)
35 \ #32 $20 PMMPW PMM password violation (PUC)
36 \ #34 $22 MPUPW MPU password violation (PUC)
37 \ #36 $24 CSPW CS password violation (PUC)
38 \ #38 $26 MPUSEGIPIFG encapsulated IP memory segment violation (PUC)
39 \ #40 $28 MPUSEGIIFG information memory segment violation (PUC)
40 \ #42 $2A MPUSEG1IFG segment 1 memory violation (PUC)
41 \ #44 $2C MPUSEG2IFG segment 2 memory violation (PUC)
42 \ #46 $2E MPUSEG3IFG segment 3 memory violation (PUC)
43 \
44 \ emulated SYSRSTIV values added by FastForth
45 \ -------------------------------------------
46 \ -n SYS            : BOR + Deep Reset --> WARM display #-1  
47 \ <SW1+RESET>       : BOR + Deep Reset --> WARM display #-1
48 \ SYS               : NO PUC -->  -->  --> WARM display #0
49 \ n SYS  (n odd )   : NO PUC -->  -->  --> WARM display #n (odd)
50 \ n SYS  (n even )  : BOR    -->  -->  --> WARM display #n (even)
51 \ <RESET>           : BOR    -->  -->  --> WARM display #4
52 \
53 \ note
54 \ ------------------------------------------------------------------------------
55 \ When BOOT.4TH is called by the FastForth bootstrap, the SYSRSTIV (hardware or
56 \ emulated value) is on the Top Of paramater Stack -TOS- ready to test.
57 \ ------------------------------------------------------------------------------
58 \ to enable bootstrap: BOOT
59 \ to disable bootstrap: UNBOOT
60 \ ------------------------------------------------------------------------------
61 \
62 \ it's an example:
63
64 ; ------------------------------------------------------------------
65 ; first we download the set of definitions we need (from CORE_ANS.f)
66 ; ------------------------------------------------------------------
67
68     [UNDEFINED] DUP [IF]
69 \ https://forth-standard.org/standard/core/DUP
70 \ DUP      x -- x x      duplicate top of stack
71     CODE DUP
72 BW1 SUB #2,PSP      \ 2  push old TOS..
73     MOV TOS,0(PSP)  \ 3  ..onto stack
74     MOV @IP+,PC     \ 4
75     ENDCODE
76
77 \ https://forth-standard.org/standard/core/qDUP
78 \ ?DUP     x -- 0 | x x    DUP if nonzero
79     CODE ?DUP
80     CMP #0,TOS      \ 2  test for TOS nonzero
81     0<> ?GOTO BW1    \ 2
82     MOV @IP+,PC     \ 4
83     ENDCODE
84     [THEN]
85
86     [UNDEFINED] DROP [IF]
87 \ https://forth-standard.org/standard/core/DROP
88 \ DROP     x --          drop top of stack
89     CODE DROP
90     MOV @PSP+,TOS   \ 2
91     MOV @IP+,PC     \ 4
92     ENDCODE
93     [THEN]
94
95     [UNDEFINED] = [IF]
96 \ https://forth-standard.org/standard/core/Equal
97 \ =      x1 x2 -- flag         test x1=x2
98     CODE =
99     SUB @PSP+,TOS   \ 2
100     SUB #1,TOS      \ 1 borrow (clear cy) if TOS was 0
101     SUBC TOS,TOS    \ 1 TOS=-1 if borrow was set
102     MOV @IP+,PC
103     ENDCODE
104     [THEN]
105
106     [UNDEFINED] + [IF]
107 \ https://forth-standard.org/standard/core/Plus
108 \ +       n1/u1 n2/u2 -- n3/u3     add n1+n2
109     CODE +
110     ADD @PSP+,TOS
111     MOV @IP+,PC
112     ENDCODE
113     [THEN]
114
115     [UNDEFINED] EXECUTE [IF]
116 \ https://forth-standard.org/standard/core/EXECUTE
117 \ EXECUTE   i*x xt -- j*x   execute Forth word at 'xt'
118     CODE EXECUTE
119     PUSH TOS                \ 3 push xt
120     MOV @PSP+,TOS           \ 2
121     MOV @RSP+,PC            \ 4 xt --> PC
122     ENDCODE
123     [THEN]
124
125 ; --------------------------
126 ; end of definitions we need
127 ; --------------------------
128
129 ; ------------------------------------------------------------------------------
130 ; WARNING !
131 ; ------------------------------------------------------------------------------
132 ; it is not recommended here to compile then execute a definition
133 ; because the risk of crushing thereafter.
134 ; Interpreting mode as below is required:
135 ; ------------------------------------------------------------------------------
136
137     DUP 6 =                 \ TOS = SYS value
138     [IF]                    \ if <RESET> | 6 SYS
139         DROP                \
140         RST_RET             \ remove definitions above
141         LOAD" SD_TEST.4TH"  \ load a file to test the SD_Card driver
142     [ELSE]                  \ else
143         ' SYS $0E + EXECUTE \ TOS2WARM address, does same as n SYS (n odd)
144     [THEN]                  \ then