/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / Expanding CircleOS's RTC to handle dates as well as time

Username:     
Password:     
             

Forum
  • Index
  •  » circleOS
  •  » Expanding CircleOS's RTC to handle dates as well as time

# 1   2007-10-21 14:13:58 Expanding CircleOS's RTC to handle dates as well as time

dalewheat
Member
From: Dallas TX USA
Registered: 2007-10-10
Posts: 43
Website

Expanding CircleOS's RTC to handle dates as well as time

Could anyone explain to me what would be involved with adding calendar support to CircleOS?  My understanding of the current capabilities makes me think that it only keeps up with the hours, minutes and seconds of a single day, and starts back over at zero at midnight.

If you can point me to the applicable areas of the CircleOS source code, I would like to add the rudiments of a POSIX-compliant time library to CircleOS.  This would be in furtherance of my current project to make a useful calendar application for the STM32 Primer.  I think it would also be of use to CircleOS developers in general, if I can keep the size and complexity to a minimum.

Thanks,

Dale Wheat

Offline

 

# 2   2007-10-24 10:08:33 Expanding CircleOS's RTC to handle dates as well as time

Francis
Administrator
From: France-Grenoble
Registered: 2007-07-09
Posts: 890

Re: Expanding CircleOS's RTC to handle dates as well as time

A "perpetual calendar" is not complex. The RTC module features a 32 bit counter for the seconds. With 32 bit, you can count up to 4294967296 seconds (49710 days, 136 years).
The first point is to define the zero time. It could be January 1st 2000 because the 2k year was "the exception of the exception" (it was  a bissextile year whilst the centuries are supposed not to be bissextile..). Then, with a few aritmetic operation, you can wirite the two functions "time2date()" and date2time() where "date" is a structiure containing both the date and the time, and "time" means the number of seconds since time-zero. That's all...
I implemented such a mechanism 20 years ago, but it was in 8051 assembler and I don't find the source files anymore. Sorry! I guess that you could probably find some source files on the web (searching for "perpetual calendar").

Offline

 

# 3   2007-10-25 01:48:19 Expanding CircleOS's RTC to handle dates as well as time

dalewheat
Member
From: Dallas TX USA
Registered: 2007-10-10
Posts: 43
Website

Re: Expanding CircleOS's RTC to handle dates as well as time

Francis,

That is exactly what I was thinking, as well.  "Unix" time is kept in the same manner, with 1 January 1970 marking the beginning of the "Unix epoch".

We already have all that machanism in place in the "time.h" header file that is included with the GCC compiler.  The problem lies in the inclusion of the vsprintf() function calls, etc., that get linked when the time functions from stdlib are used, because strftime() calls it.

What I was proposing was to include this functionality in CircleOS, with a decidedly limited implementation.  It appears that the RTC in CircleOS is already using a 32 bit value to keep track of seconds, so that part is already done for us.

If I can rough out the necessary library functions, can you merge them into the CircleOS, or show me how+where to do so?  I'm not wanting to implement everything, just enough to get a working calendar application working, without making up yet another arbitrary timekeeping standard.

Thanks,

Dale Wheat

Offline

 

# 4   2007-10-25 06:55:57 Expanding CircleOS's RTC to handle dates as well as time

Francis
Administrator
From: France-Grenoble
Registered: 2007-07-09
Posts: 890

Re: Expanding CircleOS's RTC to handle dates as well as time

We would be happy to add features to the CircleOS. I would say that we are waiting for such proposals..
The main limitation is the code size: it is important to keep the CircleOS size under the border of the 24KB to provide 8KB to the standard users to debug their application (the sum of the CircleOS + the debugged application must be less than 32KB).
At the moment we have +1KB free... This could be extended by removing some useless code (for example in mems.c). But we would like to add some other features too (such as a "double-tilt" detection to replace the button).

Now,  the missing functions for the calendar are pure algorithms: they could be also copied in the applications ... We could provide an additional dynamic library for the CircleOS as we link the applications with the STM32LIB when using the hardware peripherals.

Offline

 

# 5   2007-10-25 13:00:22 Expanding CircleOS's RTC to handle dates as well as time

dalewheat
Member
From: Dallas TX USA
Registered: 2007-10-10
Posts: 43
Website

Re: Expanding CircleOS's RTC to handle dates as well as time

Francis,

OK, that's good news!  I'll get to work right away on crafting some light-footprint routines for the basic time+calendar functionality.

To reduce complexity, I am intending to omit some of the more computationally-intensive aspects of our "modern" calendar, like leap-seconds and daylight saving time.  I am only targetting "real time" functions and do not intend to address "processor/task/kernel time" or  arbitrary timers.  To reduce size, I would like to eventually convert the routines, where possible, to optimized Thumb-2 assembly.

Wish me luck!

Thanks,

Dale Wheat

Offline

 

# 6   2007-10-25 13:20:42 Expanding CircleOS's RTC to handle dates as well as time

Francis
Administrator
From: France-Grenoble
Registered: 2007-07-09
Posts: 890

Re: Expanding CircleOS's RTC to handle dates as well as time

Thanks Dale.
Do not spend time by converting your routines in assembly (C is better). If we have to reduce the overall size, we could look at the other modules. At the moment we do not try to shrink further the footprint of the CircleOS (since we are under the 24KB border), but there are still some possibilities...
Good luck!

Offline

 

  • Index
  •  » circleOS
  •  » Expanding CircleOS's RTC to handle dates as well as time

Board footer