Setting Date/Time in Propeller C programs
iseries
Posts: 1,512
Since the Propeller doesn't have an operating system or real time clock how do I set the Data/Time so that when I write to the SD card the files show up with a more current date/time stamp. Also if I build a clock on one of the Cogs can I push the current date time to the time functions.
Mike
Mike

Comments
void dfs_setDefaultFileDateTime(struct tm* tm) { DefaultFileTime = (tm->tm_hour << 11) | (tm->tm_min << 5) | (tm->tm_sec >> 1); DefaultFileDate = ((tm->tm_year - 80) << 9) | ((tm->tm_mon + 1) << 5) | tm->tm_mday; }So you need to declare a tm struct, and initialize the struct with the date and time before calling dfs_setDefaultFileDateTime. The code would look something like this.#include <time.h> int main() { struct tm ts; ts.tm_year = 115; // year - 1900 ts.tm_mon = 2; ts.tm_mday = 2; ts.tm_hour = 11; ts.tm_min = 59; ts.tm_sec = 23; dfs_setDefaultFileDateTime(&ts); ... }http://www.ebay.com/sch/i.html?_odkw=DS1340+RTC&_sop=15&_from=R40|R40|R40|R40|R40|R40&_osacat=0&_from=R40&_trksid=p2045573.m570.l1313.TR0.TRC0.H0.XI2C+RTC&_nkw=I2C+RTC&_sacat=0
I want to be able to write time stamped entries to the SD card.
Mike
Here's an example of using the soft RTC in its own cog.
#include <stdio.h> #include <time.h> #include <sys/time.h> int main() { struct timeval tv; time_t currtime, lasttime; extern int (*_rtc_settime)(const struct timeval *tv); _rtc_start_timekeeping_cog(); tv.tv_usec = 0; tv.tv_sec = 1422915748; settimeofday(&tv, NULL); while (1) { if (time(&currtime) != lasttime) { lasttime = currtime; printf("%s\n", asctime(localtime(&currtime))); } } }Thank you
I thought there was a simpler answer other than reverse engineering the code.
But that only creates a show stopper. Adding the SD routine and the I/O routine along with the fwrite functions uses all the available memory and my program will no longer fit.
All for NOT.
Mike
Ray
By the numbers:
sd_mount = 10K
fopen/close/write = 2K
time/asctime/localtime = 3K
fprintf = 10K
That leave about 5K for my code which is using 7 cogs and tops out at 10K.
Together I'm at 32k.
spending 25K just to track status information is a little rich.
Mike