Dear AmForth Developers, 

I've been playing with AMForth version 6.1 and have used the 
example\date-time.frt file. I expanded this task with new code as I understand 
a clock/calendar system. However, I'm now incline to use 
common\lib\forth2012\facility\date-and-time.frt that tracks time and date in 
two (2) 2variable registers. The solution seems simpler but also brings up 
other questions. 

Question: 
[1] Is anyone using the date-and-time.frt code with more updated code? At least 
code that tracks leapyear or whether a month is 31 days or 30 days. Also, how 
would you handle time date interpretation on register rollover for the 
date-and-time.frt? 
[2] Lastly, how do you assign a task a time execution to run every 1 second? I 
included a 1000 ms delay in my code for the task but I would like to see if 
this can be added at the task level initialization or execution on @tick for 
Timer0. 

Any hints or examples are appreciated. 

Regards, 
Franklin Amador 

**********************common\lib\forth2012\facility\date-and-time.frt 
code************************************* 


\ uses timer interrrupt module to call 
\ a background task every second. 

\ holds the ever increasing time ticks 
\ unfortunatly, a day has more seconds 
\ a 16bit variable can store. 
2variable time \ the seconds of the current day 
2variable date \ a day number 

\ a background task 
: next-second 
time 2@ 1. d+ 2dup 
86399. d> if 
2drop 0. 
1. date d+! 
then 
time 2! 
; 

: dateinit 
0. time 2! 
0. date 2! 
; 

\ simple world. Every month has 30 days 
: time&date ( -- sec min hour day month year ) 
date 2@ 365 um/mod 30 /mod ( -- day month year ) 
time 2@ 24 um/mod 60 /mod ( -- sec min hour ) 
; 
********************** example\date-time.frt 
code************************************* 


\ create task space 
$20 $20 0 task: t:date&time 

variable seconds 
\ runs every second 
: job-date&time 
1 seconds +! 
\ more code for minute/hour/day... 
0 \ flag for an endless loop 
; 

\ set up the task 
: setup-date&time 
t:date&time task-init \ create TCB in RAM 
0 seconds ! \ more code for minutes etc 
t:date&time tcb>tid activate 
\ code from here is executed as task, later on 
['] job-date&time every-second 
; 

\ setup and start the task "date/time" 
: turnkey-date&time 
onlytask \ set up multitasker 
6 timer0.init timer0.start \ 16 MHz quartz 
\ insert task into task list 
setup-date&time t:date&time tcb>tid alsotask 
multi \ start multitasking 
; 

*********************updated code**************************************** 

\ create task space $20 $20 0 task: t:date&time variable seconds variable 
minutes variable hours variable day variable month variable year : reset.clock 
( -- ) 0 seconds ! 0 minutes ! 0 hours ! 1 days ! 1 month ! 2016 year ! ; : 
day.month ( -- ) 1 days ! 1 month +! ; : check.days ( day -- ) days @ u< if 
day.month then ; : leapyear ( -- ) year @ 4 mod 0= year @ 100 mod 0= and year @ 
400 mod 0= or if 29 check.days else 28 check.days then ; \ runs every second : 
job-date&time begin 1 seconds +! seconds @ 59 > if 0 seconds ! 1 minutes +! 
then minutes @ 59 > if 0 minutes ! 1 hours +! then hours @ 24 > if 0 hours ! 1 
day +! then month @ case 0 of reset.clock endof 1 of 31 check.days endof 2 of 
leapyear endof 3 of 31 check.days endof 4 of 30 check.days endof 5 of 31 
check.days endof 6 of 30 check.days endof 7 of 31 check.days endof 8 of 31 
check.days endof 9 of 30 check.days endof 10 of 31 check.days endof 11 of 30 
check.days endof 12 of 31 check.days endof 13 of 1 month ! 1 year +! endof e
 ndcase 1000 ms again ; \ set up the task : setup-date&time t:date&time tcb>tid 
activate \ words after this line are run in new task job-date&time ; \ setup 
and start the task "date/time" : datetime-turnkey t:date&time task-init \ 
create TCB in RAM 0 seconds ! \ more code for minutes etc 131 timer0.ini 
timer0.start \ 8 MHz quartz \ 6 timer0.init timer0.start \ 16 MHz quartz \ 
insert task into task list setup-date&time \ activate tasks job onlytask 
t:date&time tcb>tid alsotask multi \ start multitasking ; 


Copyright (c) 2016 Franklin Amador - All Rights Reserved - 
This message is intended for the addressed recipient(s) only. If you have 
received this, and are not the intended recipient(s), please contact the 
sender/author immediately and delete this message and any attachments. 

This communication and any documents or files attached constitutes an 
electronic communication subject to the Electronic Communication Privacy Act, 
18 USCA 2510. This communication is confidential, subject to copyright 
protection and may contain information that is non-public, legally privileged 
and sensitive in nature. Further, to be considered under the law privileged, 
proprietary, intellectual property and exempt from disclosure under applicable 
law. Unlawful or unintended interception, use, dissemination, distribution, or 
copying of this communication, documents, files, attachments and, or excerpts 
of this communication is strictly prohibited, without the express written 
permission of the sender/author or the intended recipient(s), as authorized, in 
writing by the sender/author. Information herein or attached, is subject to the 
terms and conditions of any duly executed Proprietary Information Agreement 
(PIA) between the sender/author and the intended recipient(s) and hereby deeme
 d "Proprietary Information". 

Electronic transmission cannot be guaranteed to be secure or error free as 
information could be intercepted, corrupted, lost, destroyed, arrive late, 
incomplete, or contain viruses. The sender/author therefore does not accept 
liability for errors or omissions in the content of this message or 
attachments, which may arise as a result of e-mail transmission. 

If verification is required, please contact the sender/author and request a 
hard copy. 



------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
Francisco, CA to explore cutting-edge tech and listen to tech luminaries
present their vision of the future. This family event has something for
everyone, including kids. Get more information and register today.
http://sdm.link/attshape
_______________________________________________
Amforth-devel mailing list for http://amforth.sf.net/
Amforth-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/amforth-devel

Reply via email to