RTC. Nop.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3614 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
parent
122eecfb5e
commit
124a432b0e
|
@ -12,7 +12,7 @@ ifeq ($(USE_OPT),)
|
||||||
# If all calls to a given function are integrated, and the function is declared static, then the function is normally not output as assembler code in its own right.
|
# If all calls to a given function are integrated, and the function is declared static, then the function is normally not output as assembler code in its own right.
|
||||||
# Enabled at level '-O3'.
|
# Enabled at level '-O3'.
|
||||||
|
|
||||||
USE_OPT = -O2 -ggdb -fomit-frame-pointer -falign-functions=16
|
USE_OPT = -O0 -ggdb -fomit-frame-pointer # -mhard-float #-falign-functions=16
|
||||||
#USE_OPT = -O1 -ggdb -fomit-frame-pointer -falign-functions=16 -fno-inline
|
#USE_OPT = -O1 -ggdb -fomit-frame-pointer -falign-functions=16 -fno-inline
|
||||||
#USE_OPT = -O2 -ggdb -fomit-frame-pointer -falign-functions=16 -fno-strict-aliasing
|
#USE_OPT = -O2 -ggdb -fomit-frame-pointer -falign-functions=16 -fno-strict-aliasing
|
||||||
#USE_OPT = -O3 -ggdb -fomit-frame-pointer -falign-functions=16
|
#USE_OPT = -O3 -ggdb -fomit-frame-pointer -falign-functions=16
|
||||||
|
@ -41,7 +41,7 @@ endif
|
||||||
|
|
||||||
# Enable this if you want to see the full log while compiling.
|
# Enable this if you want to see the full log while compiling.
|
||||||
ifeq ($(USE_VERBOSE_COMPILE),)
|
ifeq ($(USE_VERBOSE_COMPILE),)
|
||||||
USE_VERBOSE_COMPILE = no
|
USE_VERBOSE_COMPILE = yes
|
||||||
endif
|
endif
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
|
@ -120,28 +120,28 @@ void bcd2tm(struct tm *timp, uint32_t tv_time, uint32_t tv_date){
|
||||||
* Convert from classical format to STM32 BCD
|
* Convert from classical format to STM32 BCD
|
||||||
*/
|
*/
|
||||||
void tm2bcd(struct tm *timp, RTCTime *timespec){
|
void tm2bcd(struct tm *timp, RTCTime *timespec){
|
||||||
uint32_t p = 0; // temporal variable
|
uint32_t v = 0; // temporal variable
|
||||||
|
|
||||||
timespec->tv_date = 0;
|
timespec->tv_date = 0;
|
||||||
timespec->tv_time = 0;
|
timespec->tv_time = 0;
|
||||||
|
|
||||||
p = timp->tm_year - 100;
|
v = timp->tm_year - 100;
|
||||||
timespec->tv_date |= (((p / 10) & 0xF) << 20) | ((p % 10) << 16);
|
timespec->tv_date |= (((v / 10) & 0xF) << 20) | ((v % 10) << 16);
|
||||||
if (timp->tm_wday == 0)
|
if (timp->tm_wday == 0)
|
||||||
p = 7;
|
v = 7;
|
||||||
else
|
else
|
||||||
p = timp->tm_wday;
|
v = timp->tm_wday;
|
||||||
timespec->tv_date |= (p & 7) << 13;
|
timespec->tv_date |= (v & 7) << 13;
|
||||||
p = timp->tm_mon + 1;
|
v = timp->tm_mon + 1;
|
||||||
timespec->tv_date |= (((p / 10) & 1) << 12) | ((p % 10) << 8);
|
timespec->tv_date |= (((v / 10) & 1) << 12) | ((v % 10) << 8);
|
||||||
p = timp->tm_mday;
|
v = timp->tm_mday;
|
||||||
timespec->tv_date |= (((p / 10) & 3) << 4) | (p % 10);
|
timespec->tv_date |= (((v / 10) & 3) << 4) | (v % 10);
|
||||||
p = timp->tm_hour;
|
v = timp->tm_hour;
|
||||||
timespec->tv_time |= (((p / 10) & 3) << 20) | ((p % 10) << 16);
|
timespec->tv_time |= (((v / 10) & 3) << 20) | ((v % 10) << 16);
|
||||||
p = timp->tm_min;
|
v = timp->tm_min;
|
||||||
timespec->tv_time |= (((p / 10) & 7) << 12) | ((p % 10) << 8);
|
timespec->tv_time |= (((v / 10) & 7) << 12) | ((v % 10) << 8);
|
||||||
p = timp->tm_sec;
|
v = timp->tm_sec;
|
||||||
timespec->tv_time |= (((p / 10) & 7) << 4) | (p % 10);
|
timespec->tv_time |= (((v / 10) & 7) << 4) | (v % 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -162,11 +162,23 @@ int main(void){
|
||||||
bcd2tm(&timp, timespec.tv_time, timespec.tv_date);
|
bcd2tm(&timp, timespec.tv_time, timespec.tv_date);
|
||||||
unix_time = mktime(&timp);
|
unix_time = mktime(&timp);
|
||||||
|
|
||||||
|
if (unix_time == -1){// incorrect time in RTC cell
|
||||||
|
unix_time = 1000000000;
|
||||||
|
}
|
||||||
|
|
||||||
|
tm2bcd((localtime(&unix_time)), ×pec);
|
||||||
|
rtcSetTime(&RTCD1, ×pec);
|
||||||
|
|
||||||
while (TRUE){
|
while (TRUE){
|
||||||
chThdSleepMilliseconds(500);
|
rtcGetTime(&RTCD1, ×pec);
|
||||||
|
bcd2tm(&timp, timespec.tv_time, timespec.tv_date);
|
||||||
|
unix_time = mktime(&timp);
|
||||||
|
chThdSleepMilliseconds(1500);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue