Revision 8399aeae
| modules/DiWheelDrive_1-1/module.h | ||
|---|---|---|
| 153 | 153 |
*/ |
| 154 | 154 |
extern SPIConfig moduleHalSpiGyroscopeConfig; |
| 155 | 155 |
|
| 156 |
/** |
|
| 157 |
* @brief Real-Time Clock driver. |
|
| 158 |
*/ |
|
| 159 |
#define MODULE_HAL_RTC RTCD1 |
|
| 160 |
|
|
| 156 | 161 |
/** @} */ |
| 157 | 162 |
|
| 158 | 163 |
/*===========================================================================*/ |
| modules/LightRing_1-0/module.h | ||
|---|---|---|
| 86 | 86 |
*/ |
| 87 | 87 |
extern SPIConfig moduleHalSpiLightConfig; |
| 88 | 88 |
|
| 89 |
/** |
|
| 90 |
* @brief Real-Time Clock driver. |
|
| 91 |
*/ |
|
| 92 |
#define MODULE_HAL_RTC RTCD1 |
|
| 93 |
|
|
| 89 | 94 |
/** @} */ |
| 90 | 95 |
|
| 91 | 96 |
/*===========================================================================*/ |
| modules/PowerManagement_1-1/module.h | ||
|---|---|---|
| 138 | 138 |
*/ |
| 139 | 139 |
extern SerialConfig moduleHalProgIfConfig; |
| 140 | 140 |
|
| 141 |
/** |
|
| 142 |
* @brief Real-Time Clock driver. |
|
| 143 |
*/ |
|
| 144 |
#define MODULE_HAL_RTC RTCD1 |
|
| 145 |
|
|
| 141 | 146 |
/** @} */ |
| 142 | 147 |
|
| 143 | 148 |
/*===========================================================================*/ |
| os/core/core.mk | ||
|---|---|---|
| 35 | 35 |
$(AMIROOS_CORE_DIR)src/aos_shell.c \ |
| 36 | 36 |
$(AMIROOS_CORE_DIR)src/aos_system.c \ |
| 37 | 37 |
$(AMIROOS_CORE_DIR)src/aos_thread.c \ |
| 38 |
$(AMIROOS_CORE_DIR)src/aos_time.c \ |
|
| 38 | 39 |
$(AMIROOS_CORE_DIR)src/aos_timer.c \ |
| 39 | 40 |
$(AMIROOS_CORE_DIR)src/aos_unittest.c |
| 40 | 41 |
|
| os/core/inc/aos_shell.h | ||
|---|---|---|
| 65 | 65 |
#define AOS_SHELL_CONFIG_PROMPT_UPTIME (1 << 2) |
| 66 | 66 |
|
| 67 | 67 |
/** |
| 68 |
* @brief Shell prompt configuration to additionally print the date and time with the prompt. |
|
| 69 |
*/ |
|
| 70 |
#define AOS_SHELL_CONFIG_PROMPT_DATETIME (2 << 2) |
|
| 71 |
|
|
| 72 |
/** |
|
| 68 | 73 |
* @brief Shell prompt configuration to additionally print the system uptime with the prompt. |
| 69 | 74 |
*/ |
| 70 |
#define AOS_SHELL_CONFIG_MATCH_CASE (1 << 3)
|
|
| 75 |
#define AOS_SHELL_CONFIG_MATCH_CASE (1 << 4)
|
|
| 71 | 76 |
|
| 72 | 77 |
/** |
| 73 | 78 |
* @brief Shell I/O channel flag whether the channel is attached to a list. |
| os/core/inc/aos_system.h | ||
|---|---|---|
| 175 | 175 |
void aosSysStart(void); |
| 176 | 176 |
eventmask_t aosSysSsspStartupOsInitSyncCheck(event_listener_t* syncEvtListener); |
| 177 | 177 |
void aosSysGetUptimeX(aos_timestamp_t* ut); |
| 178 |
void aosSysGetDateTime(struct tm* dt); |
|
| 179 |
void aosSysSetDateTime(struct tm* dt); |
|
| 178 | 180 |
void aosSysShutdownInit(aos_shutdown_t shutdown); |
| 179 | 181 |
void aosSysStop(void); |
| 180 | 182 |
void aosSysDeinit(void); |
| os/core/inc/aos_time.h | ||
|---|---|---|
| 204 | 204 |
#define MILLENIUMS_PER_DECADE ((float)MILLENIUMS_PER_MILLENIUM / (float)DECADES_PER_MILLENIUM) |
| 205 | 205 |
#define MILLENIUMS_PER_CENTURY ((float)MILLENIUMS_PER_MILLENIUM / (float)CENTURIES_PER_MILLENIUM) |
| 206 | 206 |
|
| 207 |
#ifdef __cplusplus |
|
| 208 |
extern "C" {
|
|
| 209 |
#endif |
|
| 210 |
uint8_t aosTimeDayOfWeekFromDate(const uint16_t day, const uint8_t month, const uint16_t year); |
|
| 211 |
#ifdef __cplusplus |
|
| 212 |
} |
|
| 213 |
#endif |
|
| 214 |
|
|
| 207 | 215 |
#endif /* _AMIROOS_TIME_H_ */ |
| os/core/src/aos_shell.c | ||
|---|---|---|
| 241 | 241 |
{
|
| 242 | 242 |
aosDbgCheck(shell != NULL); |
| 243 | 243 |
|
| 244 |
// print the system uptime before prompt is configured |
|
| 245 |
if (shell->config & AOS_SHELL_CONFIG_PROMPT_UPTIME) {
|
|
| 246 |
// get current system uptime |
|
| 247 |
aos_timestamp_t uptime; |
|
| 248 |
aosSysGetUptime(&uptime); |
|
| 249 |
|
|
| 250 |
chprintf((BaseSequentialStream*)&shell->stream, "[%01u:%02u:%02u:%02u:%03u:%03u] ", |
|
| 251 |
(uint32_t)(uptime / MICROSECONDS_PER_DAY), |
|
| 252 |
(uint8_t)(uptime % MICROSECONDS_PER_DAY / MICROSECONDS_PER_HOUR), |
|
| 253 |
(uint8_t)(uptime % MICROSECONDS_PER_HOUR / MICROSECONDS_PER_MINUTE), |
|
| 254 |
(uint8_t)(uptime % MICROSECONDS_PER_MINUTE / MICROSECONDS_PER_SECOND), |
|
| 255 |
(uint16_t)(uptime % MICROSECONDS_PER_SECOND / MICROSECONDS_PER_MILLISECOND), |
|
| 256 |
(uint16_t)(uptime % MICROSECONDS_PER_MILLISECOND / MICROSECONDS_PER_MICROSECOND)); |
|
| 244 |
// print some time informattion before prompt if configured |
|
| 245 |
if (shell->config & (AOS_SHELL_CONFIG_PROMPT_UPTIME | AOS_SHELL_CONFIG_PROMPT_DATETIME)) {
|
|
| 246 |
// printf the system uptime |
|
| 247 |
if ((shell->config & (AOS_SHELL_CONFIG_PROMPT_UPTIME | AOS_SHELL_CONFIG_PROMPT_DATETIME)) == AOS_SHELL_CONFIG_PROMPT_UPTIME) {
|
|
| 248 |
// get current system uptime |
|
| 249 |
aos_timestamp_t uptime; |
|
| 250 |
aosSysGetUptime(&uptime); |
|
| 251 |
|
|
| 252 |
chprintf((BaseSequentialStream*)&shell->stream, "[%01u:%02u:%02u:%02u:%03u:%03u] ", |
|
| 253 |
(uint32_t)(uptime / MICROSECONDS_PER_DAY), |
|
| 254 |
(uint8_t)(uptime % MICROSECONDS_PER_DAY / MICROSECONDS_PER_HOUR), |
|
| 255 |
(uint8_t)(uptime % MICROSECONDS_PER_HOUR / MICROSECONDS_PER_MINUTE), |
|
| 256 |
(uint8_t)(uptime % MICROSECONDS_PER_MINUTE / MICROSECONDS_PER_SECOND), |
|
| 257 |
(uint16_t)(uptime % MICROSECONDS_PER_SECOND / MICROSECONDS_PER_MILLISECOND), |
|
| 258 |
(uint16_t)(uptime % MICROSECONDS_PER_MILLISECOND / MICROSECONDS_PER_MICROSECOND)); |
|
| 259 |
} |
|
| 260 |
else if ((shell->config & (AOS_SHELL_CONFIG_PROMPT_UPTIME | AOS_SHELL_CONFIG_PROMPT_DATETIME)) == AOS_SHELL_CONFIG_PROMPT_DATETIME) {
|
|
| 261 |
// get current RTC time |
|
| 262 |
struct tm dt; |
|
| 263 |
aosSysGetDateTime(&dt); |
|
| 264 |
chprintf((BaseSequentialStream*)&shell->stream, "[%02u-%02u-%04u|%02u:%02u:%02u] ", |
|
| 265 |
dt.tm_mday, |
|
| 266 |
dt.tm_mon + 1, |
|
| 267 |
dt.tm_year + 1900, |
|
| 268 |
dt.tm_hour, |
|
| 269 |
dt.tm_min, |
|
| 270 |
dt.tm_sec); |
|
| 271 |
} |
|
| 272 |
else {
|
|
| 273 |
aosDbgAssert(false); |
|
| 274 |
} |
|
| 257 | 275 |
} |
| 258 | 276 |
|
| 259 | 277 |
// print the actual prompt string |
| os/core/src/aos_system.c | ||
|---|---|---|
| 20 | 20 |
|
| 21 | 21 |
#include <amiroos.h> |
| 22 | 22 |
#include <amiroblt.h> |
| 23 |
#include <module.h> |
|
| 23 | 24 |
#include <string.h> |
| 25 |
#include <stdlib.h> |
|
| 24 | 26 |
#if (AMIROOS_CFG_TESTS_ENABLE == true) |
| 25 | 27 |
#include <ch_test.h> |
| 26 | 28 |
#endif |
| ... | ... | |
| 250 | 252 |
#endif |
| 251 | 253 |
_printSystemInfoLine(stream, "Architecture", SYSTEM_INFO_NAMEWIDTH, "%s\n", PORT_ARCHITECTURE_NAME); |
| 252 | 254 |
_printSystemInfoSeparator(stream, '-', SYSTEM_INFO_WIDTH); |
| 253 |
_printSystemInfoLine(stream, "AMiRo-OS" ,SYSTEM_INFO_NAMEWIDTH, "%u.%u.%u %s (SSSP %u.%u)\n", AMIROOS_VERSION_MAJOR, AMIROOS_VERSION_MINOR, AMIROOS_VERSION_PATCH, AMIROOS_RELEASE_TYPE, AOS_SYSTEM_SSSP_MAJOR, AOS_SYSTEM_SSSP_MINOR); |
|
| 254 |
_printSystemInfoLine(stream, "AMiRo-LLD" ,SYSTEM_INFO_NAMEWIDTH, "%u.%u.%u %s (periphAL %u.%u)\n", AMIRO_LLD_VERSION_MAJOR, AMIRO_LLD_VERSION_MINOR, AMIRO_LLD_VERSION_PATCH, AMIRO_LLD_RELEASE_TYPE, PERIPHAL_VERSION_MAJOR, PERIPHAL_VERSION_MINOR); |
|
| 255 |
_printSystemInfoLine(stream, "ChibiOS/RT" ,SYSTEM_INFO_NAMEWIDTH, "%u.%u.%u %s\n", CH_KERNEL_MAJOR, CH_KERNEL_MINOR, CH_KERNEL_PATCH, (CH_KERNEL_STABLE == 1) ? "stable" : "non-stable"); |
|
| 256 |
_printSystemInfoLine(stream, "ChibiOS/HAL",SYSTEM_INFO_NAMEWIDTH, "%u.%u.%u %s\n", CH_HAL_MAJOR, CH_HAL_MINOR, CH_HAL_PATCH, (CH_HAL_STABLE == 1) ? "stable" : "non-stable"); |
|
| 257 |
_printSystemInfoLine(stream, "build type",SYSTEM_INFO_NAMEWIDTH,"%s\n", (AMIROOS_CFG_DBG == true) ? "debug" : "release"); |
|
| 258 |
_printSystemInfoLine(stream, "Compiler" ,SYSTEM_INFO_NAMEWIDTH, "%s %u.%u.%u\n", "GCC", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); // TODO: support other compilers than GCC |
|
| 259 |
_printSystemInfoLine(stream, "Compiled" ,SYSTEM_INFO_NAMEWIDTH, "%s - %s\n", __DATE__, __TIME__); |
|
| 255 |
_printSystemInfoLine(stream, "AMiRo-OS" , SYSTEM_INFO_NAMEWIDTH, "%u.%u.%u %s (SSSP %u.%u)\n", AMIROOS_VERSION_MAJOR, AMIROOS_VERSION_MINOR, AMIROOS_VERSION_PATCH, AMIROOS_RELEASE_TYPE, AOS_SYSTEM_SSSP_MAJOR, AOS_SYSTEM_SSSP_MINOR);
|
|
| 256 |
_printSystemInfoLine(stream, "AMiRo-LLD" , SYSTEM_INFO_NAMEWIDTH, "%u.%u.%u %s (periphAL %u.%u)\n", AMIRO_LLD_VERSION_MAJOR, AMIRO_LLD_VERSION_MINOR, AMIRO_LLD_VERSION_PATCH, AMIRO_LLD_RELEASE_TYPE, PERIPHAL_VERSION_MAJOR, PERIPHAL_VERSION_MINOR);
|
|
| 257 |
_printSystemInfoLine(stream, "ChibiOS/RT" , SYSTEM_INFO_NAMEWIDTH, "%u.%u.%u %s\n", CH_KERNEL_MAJOR, CH_KERNEL_MINOR, CH_KERNEL_PATCH, (CH_KERNEL_STABLE == 1) ? "stable" : "non-stable");
|
|
| 258 |
_printSystemInfoLine(stream, "ChibiOS/HAL", SYSTEM_INFO_NAMEWIDTH, "%u.%u.%u %s\n", CH_HAL_MAJOR, CH_HAL_MINOR, CH_HAL_PATCH, (CH_HAL_STABLE == 1) ? "stable" : "non-stable");
|
|
| 259 |
_printSystemInfoLine(stream, "build type", SYSTEM_INFO_NAMEWIDTH,"%s\n", (AMIROOS_CFG_DBG == true) ? "debug" : "release");
|
|
| 260 |
_printSystemInfoLine(stream, "Compiler" , SYSTEM_INFO_NAMEWIDTH, "%s %u.%u.%u\n", "GCC", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); // TODO: support other compilers than GCC
|
|
| 261 |
_printSystemInfoLine(stream, "Compiled" , SYSTEM_INFO_NAMEWIDTH, "%s - %s\n", __DATE__, __TIME__);
|
|
| 260 | 262 |
_printSystemInfoSeparator(stream, '-', SYSTEM_INFO_WIDTH); |
| 261 | 263 |
if (BL_CALLBACK_TABLE_ADDRESS->magicNumber == BL_MAGIC_NUMBER) {
|
| 262 | 264 |
_printSystemInfoLine(stream, "AMiRo-BLT", SYSTEM_INFO_NAMEWIDTH, "%u.%u.%u %s (SSSP %u.%u)\n", BL_CALLBACK_TABLE_ADDRESS->vBootloader.major, BL_CALLBACK_TABLE_ADDRESS->vBootloader.minor, BL_CALLBACK_TABLE_ADDRESS->vBootloader.patch, |
| ... | ... | |
| 282 | 284 |
aosprintf("Bootloader incompatible or not available.\n");
|
| 283 | 285 |
} |
| 284 | 286 |
} |
| 287 |
_printSystemInfoSeparator(stream, '-', SYSTEM_INFO_WIDTH); |
|
| 288 |
struct tm dt; |
|
| 289 |
aosSysGetDateTime(&dt); |
|
| 290 |
_printSystemInfoLine(stream, "Date", SYSTEM_INFO_NAMEWIDTH, "%s %02u-%02u-%04u\n", (dt.tm_wday == 0) ? "Sunday" : (dt.tm_wday == 1) ? "Monday" : (dt.tm_wday == 2) ? "Tuesday" : (dt.tm_wday == 3) ? "Wednesday" : (dt.tm_wday == 4) ? "Thursday" : (dt.tm_wday == 5) ? "Friday" : "Saturday", |
|
| 291 |
dt.tm_mday, |
|
| 292 |
dt.tm_mon + 1, |
|
| 293 |
dt.tm_year + 1900); |
|
| 294 |
_printSystemInfoLine(stream, "Time", SYSTEM_INFO_NAMEWIDTH, "%02u:%02u:%02u\n", dt.tm_hour, dt.tm_min, dt.tm_sec); |
|
| 285 | 295 |
_printSystemInfoSeparator(stream, '=', SYSTEM_INFO_WIDTH); |
| 286 | 296 |
|
| 287 | 297 |
return; |
| ... | ... | |
| 326 | 336 |
retval = AOS_OK; |
| 327 | 337 |
} |
| 328 | 338 |
else if (strcmp(argv[3], "notime") == 0) {
|
| 329 |
aos.shell->config &= ~AOS_SHELL_CONFIG_PROMPT_UPTIME;
|
|
| 339 |
aos.shell->config &= ~(AOS_SHELL_CONFIG_PROMPT_UPTIME | AOS_SHELL_CONFIG_PROMPT_DATETIME);
|
|
| 330 | 340 |
retval = AOS_OK; |
| 331 | 341 |
} |
| 332 | 342 |
else if (strcmp(argv[3], "uptime") == 0) {
|
| 343 |
aos.shell->config &= ~AOS_SHELL_CONFIG_PROMPT_DATETIME; |
|
| 333 | 344 |
aos.shell->config |= AOS_SHELL_CONFIG_PROMPT_UPTIME; |
| 334 | 345 |
retval = AOS_OK; |
| 335 | 346 |
} |
| 347 |
else if (strcmp(argv[3], "date&time") == 0) {
|
|
| 348 |
aos.shell->config &= ~AOS_SHELL_CONFIG_PROMPT_UPTIME; |
|
| 349 |
aos.shell->config |= AOS_SHELL_CONFIG_PROMPT_DATETIME; |
|
| 350 |
retval = AOS_OK; |
|
| 351 |
} |
|
| 352 |
else {
|
|
| 353 |
chprintf(stream, "unknown option '%s'\n", argv[3]); |
|
| 354 |
return AOS_INVALID_ARGUMENTS; |
|
| 355 |
} |
|
| 336 | 356 |
} |
| 337 | 357 |
} |
| 338 | 358 |
// if the user wants to modify the string matching |
| ... | ... | |
| 355 | 375 |
chprintf(stream, "current shell configuration:\n"); |
| 356 | 376 |
chprintf(stream, " prompt text: %s\n", |
| 357 | 377 |
(aos.shell->prompt != NULL) ? aos.shell->prompt : "n/a"); |
| 378 |
char time[10]; |
|
| 379 |
switch (aos.shell->config & (AOS_SHELL_CONFIG_PROMPT_UPTIME | AOS_SHELL_CONFIG_PROMPT_DATETIME)) {
|
|
| 380 |
case AOS_SHELL_CONFIG_PROMPT_UPTIME: |
|
| 381 |
strcpy(time, "uptime"); break; |
|
| 382 |
case AOS_SHELL_CONFIG_PROMPT_DATETIME: |
|
| 383 |
strcpy(time, "date&time"); break; |
|
| 384 |
default: |
|
| 385 |
strcpy(time, "no time"); break; |
|
| 386 |
} |
|
| 358 | 387 |
chprintf(stream, " prompt style: %s, %s\n", |
| 359 | 388 |
(aos.shell->config & AOS_SHELL_CONFIG_PROMPT_MINIMAL) ? "minimal" : "text", |
| 360 |
(aos.shell->config & AOS_SHELL_CONFIG_PROMPT_UPTIME) ? "system uptime" : "no time");
|
|
| 389 |
time);
|
|
| 361 | 390 |
chprintf(stream, " input method: %s\n", |
| 362 | 391 |
(aos.shell->config & AOS_SHELL_CONFIG_INPUT_OVERWRITE) ? "replace" : "insert"); |
| 363 | 392 |
chprintf(stream, " text matching: %s\n", |
| ... | ... | |
| 365 | 394 |
retval = AOS_OK; |
| 366 | 395 |
} |
| 367 | 396 |
} |
| 397 |
// if the user wants to configure the date or time |
|
| 398 |
else if (strcmp(argv[1], "--date&time") == 0 && argc == 4) {
|
|
| 399 |
struct tm dt; |
|
| 400 |
aosSysGetDateTime(&dt); |
|
| 401 |
unsigned int val = atoi(argv[3]); |
|
| 402 |
if (strcmp(argv[2], "year") == 0) {
|
|
| 403 |
dt.tm_year = val - 1900; |
|
| 404 |
} |
|
| 405 |
else if (strcmp(argv[2], "month") == 0 && val <= 12) {
|
|
| 406 |
dt.tm_mon = val - 1; |
|
| 407 |
} |
|
| 408 |
else if (strcmp(argv[2], "day") == 0 && val <= 31) {
|
|
| 409 |
dt.tm_mday = val; |
|
| 410 |
} |
|
| 411 |
else if (strcmp(argv[2], "hour") == 0 && val < 24) {
|
|
| 412 |
dt.tm_hour = val; |
|
| 413 |
} |
|
| 414 |
else if (strcmp(argv[2], "minute") == 0 && val < 60) {
|
|
| 415 |
dt.tm_min = val; |
|
| 416 |
} |
|
| 417 |
else if (strcmp(argv[2], "second") == 0 && val < 60) {
|
|
| 418 |
dt.tm_sec = val; |
|
| 419 |
} |
|
| 420 |
else {
|
|
| 421 |
chprintf(stream, "unknown option '%s' or value '%s'\n", argv[2], argv[3]); |
|
| 422 |
return AOS_INVALID_ARGUMENTS; |
|
| 423 |
} |
|
| 424 |
dt.tm_wday = aosTimeDayOfWeekFromDate(dt.tm_mday, dt.tm_mon+1, dt.tm_year+1900) % 7; |
|
| 425 |
aosSysSetDateTime(&dt); |
|
| 426 |
|
|
| 427 |
// read and print new date and time |
|
| 428 |
aosSysGetDateTime(&dt); |
|
| 429 |
chprintf(stream, "date/time set to %02u:%02u:%02u @ %02u-%02u-%04u\n", |
|
| 430 |
dt.tm_hour, dt.tm_min, dt.tm_sec, |
|
| 431 |
dt.tm_mday, dt.tm_mon+1, dt.tm_year+1900); |
|
| 432 |
|
|
| 433 |
retval = AOS_OK; |
|
| 434 |
} |
|
| 368 | 435 |
} |
| 369 | 436 |
|
| 370 | 437 |
// print help, if required |
| ... | ... | |
| 376 | 443 |
chprintf(stream, " --shell [OPT [VAL]]\n"); |
| 377 | 444 |
chprintf(stream, " Set or retrieve shell configuration.\n"); |
| 378 | 445 |
chprintf(stream, " Possible OPTs and VALs are:\n"); |
| 379 |
chprintf(stream, " prompt text|minimal|uptime|notime\n"); |
|
| 446 |
chprintf(stream, " prompt text|minimal|uptime|date&time|notime\n");
|
|
| 380 | 447 |
chprintf(stream, " Configures the prompt.\n"); |
| 381 | 448 |
chprintf(stream, " match casesensitive|caseinsenitive\n"); |
| 382 | 449 |
chprintf(stream, " Configures string matching.\n"); |
| 450 |
chprintf(stream, " --date&time OPT VAL\n"); |
|
| 451 |
chprintf(stream, " Set the date/time value of OPT to VAL.\n"); |
|
| 452 |
chprintf(stream, " Possible OPTs are:\n"); |
|
| 453 |
chprintf(stream, " year\n"); |
|
| 454 |
chprintf(stream, " month\n"); |
|
| 455 |
chprintf(stream, " day\n"); |
|
| 456 |
chprintf(stream, " hour\n"); |
|
| 457 |
chprintf(stream, " minute\n"); |
|
| 458 |
chprintf(stream, " second\n"); |
|
| 383 | 459 |
} |
| 384 | 460 |
|
| 385 | 461 |
return (argc > 1 && strcmp(argv[1], "--help") == 0) ? AOS_OK : retval; |
| ... | ... | |
| 577 | 653 |
* |
| 578 | 654 |
* @param[in] par Generic parameter. |
| 579 | 655 |
*/ |
| 580 |
#include <module.h> |
|
| 581 | 656 |
static void _uptimeCallback(void* par) |
| 582 | 657 |
{
|
| 583 | 658 |
(void)par; |
| ... | ... | |
| 799 | 874 |
} |
| 800 | 875 |
|
| 801 | 876 |
/** |
| 877 |
* @brief retrieves the date and time from the MCU clock. |
|
| 878 |
* |
|
| 879 |
* @param[out] td The date and time. |
|
| 880 |
*/ |
|
| 881 |
void aosSysGetDateTime(struct tm* dt) |
|
| 882 |
{
|
|
| 883 |
aosDbgCheck(dt != NULL); |
|
| 884 |
|
|
| 885 |
RTCDateTime rtc; |
|
| 886 |
rtcGetTime(&MODULE_HAL_RTC, &rtc); |
|
| 887 |
rtcConvertDateTimeToStructTm(&rtc, dt, NULL); |
|
| 888 |
|
|
| 889 |
return; |
|
| 890 |
} |
|
| 891 |
|
|
| 892 |
/** |
|
| 893 |
* @brief set the date and time of the MCU clock. |
|
| 894 |
* |
|
| 895 |
* @param[in] dt The date and time to set. |
|
| 896 |
*/ |
|
| 897 |
void aosSysSetDateTime(struct tm* dt) |
|
| 898 |
{
|
|
| 899 |
aosDbgCheck(dt != NULL); |
|
| 900 |
|
|
| 901 |
RTCDateTime rtc; |
|
| 902 |
rtcConvertStructTmToDateTime(dt, 0, &rtc); |
|
| 903 |
rtcSetTime(&MODULE_HAL_RTC, &rtc); |
|
| 904 |
|
|
| 905 |
return; |
|
| 906 |
} |
|
| 907 |
|
|
| 908 |
/** |
|
| 802 | 909 |
* @brief Initializes/Acknowledges a system shutdown/restart request. |
| 803 | 910 |
* @note This functions should be called from the thread with highest priority. |
| 804 | 911 |
* |
| os/core/src/aos_time.c | ||
|---|---|---|
| 1 |
/* |
|
| 2 |
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform. |
|
| 3 |
Copyright (C) 2016..2018 Thomas Schöpping et al. |
|
| 4 |
|
|
| 5 |
This program is free software: you can redistribute it and/or modify |
|
| 6 |
it under the terms of the GNU General Public License as published by |
|
| 7 |
the Free Software Foundation, either version 3 of the License, or |
|
| 8 |
(at your option) any later version. |
|
| 9 |
|
|
| 10 |
This program is distributed in the hope that it will be useful, |
|
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 13 |
GNU General Public License for more details. |
|
| 14 |
|
|
| 15 |
You should have received a copy of the GNU General Public License |
|
| 16 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
| 17 |
*/ |
|
| 18 |
|
|
| 19 |
#include <aos_time.h> |
|
| 20 |
|
|
| 21 |
#include <aos_debug.h> |
|
| 22 |
#include <aos_system.h> |
|
| 23 |
|
|
| 24 |
/** |
|
| 25 |
* @brief Calculates the day of week from a specified date. |
|
| 26 |
* |
|
| 27 |
* @param[in] day The day of the date. |
|
| 28 |
* @param[in] month The month of the daste. |
|
| 29 |
* @param[in] year The year of the date. |
|
| 30 |
* |
|
| 31 |
* @return The day of week depending on the date represented in ISO format (1 = Monday to 7 = Sunday). |
|
| 32 |
*/ |
|
| 33 |
uint8_t aosTimeDayOfWeekFromDate(const uint16_t day, const uint8_t month, const uint16_t year) |
|
| 34 |
{
|
|
| 35 |
aosDbgCheck(day >= 1 && day <= 31); |
|
| 36 |
aosDbgCheck(month >= 1 && month <= 12); |
|
| 37 |
|
|
| 38 |
/* |
|
| 39 |
* Implementation of Zeller's congruence for Gregorian calender. |
|
| 40 |
* See https://en.wikipedia.org/wiki/Zeller%27s_congruence for details. |
|
| 41 |
*/ |
|
| 42 |
const uint32_t q = day; |
|
| 43 |
const uint32_t m = (month >= 3) ? month : month + 12; |
|
| 44 |
const uint32_t K = year % 100; |
|
| 45 |
const uint32_t J = year / 100; |
|
| 46 |
|
|
| 47 |
const uint32_t h = (q + ((13 * (m + 1)) / 5) + K + (K / 4) + (J / 4) - (2 * J)) % 7; |
|
| 48 |
|
|
| 49 |
return ((h + 5) % 7) + 1; |
|
| 50 |
} |
|
Also available in: Unified diff