OSDN Git Service

v2.0 readme
[fast-forth/master.git] / MSP430_FORTH / RTC.f
1 ; --------------------
2 ; RTC.f
3 ; --------------------
4
5 \ ==============================================================================
6 \ routines RTC for MSP430fr5xxx and MSP430FR6xxx families only
7 \ your target must have a LF_XTAL 32768Hz
8 \ add a LF_XTAL line for your target in target.inc.
9 \ ==============================================================================
10
11
12 \ TARGET SELECTION (MSP430FR5xxx or MSP430FR6xxx only)
13 \ MSP_EXP430FR5739  MSP_EXP430FR5969    MSP_EXP430FR5994    MSP_EXP430FR6989
14 \ MY_MSP430FR5738_1 MY_MSP430FR5738     MY_MSP430FR5948     MY_MSP430FR5948_1   
15 \ JMJ_BOX
16
17
18 \ REGISTERS USAGE
19 \ R4 to R7 must be saved before use and restored after
20 \ scratch registers Y to S are free for use
21 \ under interrupt, IP is free for use
22
23 \ PUSHM order : PSP,TOS, IP,  S,  T,  W,  X,  Y, R7, R6, R5, R4
24 \ example : PUSHM IP,Y
25 \
26 \ POPM  order :  R4, R5, R6, R7,  Y,  X,  W,  T,  S, IP,TOS,PSP
27 \ example : POPM Y,IP
28
29 \ ASSEMBLER conditionnal usage after IF UNTIL WHILE : S< S>= U< U>= 0= 0<> 0>=
30 \ ASSEMBLER conditionnal usage before GOTO ?GOTO     : S< S>= U< U>= 0= 0<> <0 
31
32 \ FORTH conditionnal usage after IF UNTIL WHILE : 0= 0< = < > U<
33
34
35
36 \ use :
37 \ to set date, type : d m y DATE!
38 \ to view date, type DATE?
39 \ to set time, type : h m s TIME!, or h m TIME!
40 \ to view time, type TIME?
41  
42 \ allow to write a file on a SD_Card with a valid date and a valid time
43
44
45 PWR_STATE
46     \
47 [DEFINED] {RTC} [IF] {RTC} [THEN]     \ remove application
48     \
49 [DEFINED] ASM [IF]      \ security test
50     \
51 MARKER {RTC}
52     \
53 [UNDEFINED] MAX [IF]
54     \
55 CODE MAX    \    n1 n2 -- n3       signed maximum
56     CMP @PSP,TOS    \ n2-n1
57     S<  ?GOTO FW1   \ n2<n1
58 BW1 ADD #2,PSP
59     MOV @IP+,PC
60 ENDCODE
61     \
62 CODE MIN    \    n1 n2 -- n3       signed minimum
63     CMP @PSP,TOS     \ n2-n1
64     S<  ?GOTO BW1    \ n2<n1
65 FW1 MOV @PSP+,TOS
66     MOV @IP+,PC
67 ENDCODE
68     \
69 [THEN]  \ MAX
70     \
71
72 [UNDEFINED] U.R [IF]
73 : U.R                       \ u n --           display u unsigned in n width (n >= 2)
74   >R  <# 0 # #S #>  
75   R> OVER - 0 MAX SPACES TYPE
76 ;
77 [THEN]  \ U.R
78     \
79
80 CODE DATE?
81     SUB     #6,PSP
82     MOV     TOS,4(PSP)
83     BEGIN
84         BIT.B #RTCRDY,&RTCCTL1  \ test RTCRDY flag
85     0<> UNTIL                   \ wait until RTCRDY high
86     MOV     &RTCYEARL,2(PSP)    \ year
87     MOV.B   &RTCMON,TOS
88     MOV     TOS,0(PSP)          \ month
89     MOV.B   &RTCDAY,TOS         \ day
90 COLON
91     2 U.R $2F EMIT
92     2 U.R $2F EMIT . 
93 ;
94     \
95 : DATE!
96 DEPTH 2 > IF
97     HI2LO
98     MOV     TOS,&RTCYEARL   \ year
99     MOV.B   @PSP,&RTCMON    \ month     \ @PSP+ don't work because byte format !
100     MOV.B   2(PSP),&RTCDAY  \ day       \ @PSP+ don't work because byte format !
101     ADD     #4,PSP
102     MOV     @PSP+,TOS       \
103     LO2HI
104 THEN
105     ." we are on " DATE? 
106 ;
107     \
108 CODE TIME?
109     SUB     #6,PSP
110     MOV     TOS,4(PSP)      \ save TOS
111     BEGIN
112         BIT.B #RTCRDY,&RTCCTL1 \
113     0<> UNTIL               \ wait until RTCRDY high
114     MOV.B   &RTCSEC,TOS
115     MOV     TOS,2(PSP)      \ seconds
116     MOV.B   &RTCMIN,TOS
117     MOV     TOS,0(PSP)      \ minutes
118     MOV.B   &RTCHOUR,TOS    \ hours
119 COLON
120     2 U.R $3A EMIT 
121     2 U.R $3A EMIT 2 U.R 
122 ;
123     \
124 : TIME!
125 DEPTH 1 > IF
126     DEPTH 2 = IF 0 THEN     \ to allow "hour min TIME!" scheme
127     HI2LO
128     MOV     TOS,&RTCSEC     \ seconds
129     MOV.B   @PSP,&RTCMIN    \ minutes   \ @PSP+ don't work because byte format !
130     MOV.B   2(PSP),&RTCHOUR \ hours     \ @PSP+ don't work because byte format !
131     ADD     #4,PSP
132     MOV     @PSP+,TOS       \
133     LO2HI
134 THEN
135     ." it is " TIME? 
136 ;
137     \
138 CREATE ABUF 20 ALLOT
139     \
140 : GET_TIME
141     ECHO
142     CR CR ."    DATE (DMY): "
143 [DEFINED] LOAD" [IF]    \ ACCEPT is a dEFERed word and redirected to SD_ACCEPT!
144     ABUF ABUF 20 (ACCEPT) EVALUATE CR 3 SPACES DATE!
145     CR CR ."    TIME (HMS or HM): "
146     ABUF ABUF 20 (ACCEPT) EVALUATE CR 3 SPACES TIME!
147 [ELSE]                  \ ACCEPT is not a DEFERed word
148     ABUF ABUF 20 ACCEPT EVALUATE CR 3 SPACES DATE!
149     CR CR ."    TIME (HMS or HM): "
150     ABUF ABUF 20 ACCEPT EVALUATE CR 3 SPACES TIME!
151 [THEN]
152     CR
153     HI2LO
154     MOV #PSTACK,PSP \ to avoid stack empty error if lack of typed values.
155     MOV @RSP+,IP
156     MOV @IP+,PC
157 ENDCODE
158     \
159     \
160 [THEN]  \ ASM
161     \
162 PWR_HERE
163     \
164 GET_TIME