OSDN Git Service

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