1 /* 2 * FreeRTOS V202212.00 3 * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 * this software and associated documentation files (the "Software"), to deal in 7 * the Software without restriction, including without limitation the rights to 8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 * the Software, and to permit persons to whom the Software is furnished to do so, 10 * subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be included in all 13 * copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 * 22 * https://www.FreeRTOS.org 23 * https://github.com/FreeRTOS 24 * 25 */ 26 #ifndef COMMON_DEMO_INCLUDE_H 27 #define COMMON_DEMO_INCLUDE_H 28 29 #include "demo_config.h" 30 31 /** 32 * @brief Utility macro to convert milliseconds to the fractions value of an SNTP timestamp. 33 * @note The fractions value MUST be less than 1000 as duration of seconds is not represented 34 * as fractions part of SNTP timestamp. 35 */ 36 #define MILLISECONDS_TO_SNTP_FRACTIONS( ms ) ( ms * 1000 * SNTP_FRACTION_VALUE_PER_MICROSECOND ) 37 38 /** 39 * @brief Type representing system time in Coordinated Universal Time (UTC) 40 * zone as time since 1st January 1970 00h:00m:00s. 41 * 42 * @note This demo uses RAM-based mathematical model to represent UTC time 43 * in system. 44 */ 45 typedef struct UTCTime 46 { 47 uint32_t secs; 48 uint32_t msecs; 49 } UTCTime_t; 50 51 /** 52 * @brief Utility function to print the system time as both UNIX time (i.e. 53 * time since 1st January 1970 00h:00m:00s) and human-readable time (in the 54 * YYYY-MM-DD dd:mm:ss format). 55 * 56 * @param[in] pTime The system time to be printed. 57 */ 58 void printTime( const UTCTime_t * pTime ); 59 60 /** 61 * @brief Initializes the system clock with the first second of the year (i.e. at midnight 62 * of 1st January) that is configured in the democonfigSYSTEM_START_YEAR config of 63 * demo_config.h file. 64 */ 65 void initializeSystemClock( void ); 66 67 /** 68 * @brief The demo function for an application to query wall-clock 69 * time as Coordinated Universal Time (UTC) from the system. 70 * 71 * @note This demo showcases a RAM-based mathematical model for 72 * representing current UTC time in the system. 73 * 74 * @param[out] pTime This will be populated with the current time 75 * in the system as total time since 1st January 1900 00h:00m:00s. 76 */ 77 void systemGetWallClockTime( UTCTime_t * pTime ); 78 79 /** 80 * @brief The task function for a sample application that queries 81 * system time periodically. 82 */ 83 void sampleAppTask( void * pvParameters ); 84 85 /** 86 * @brief The task function that represents a daemon SNTP client task 87 * that is responsible for periodically synchronizing system time with 88 * time servers from the list of configured time servers in 89 * democonfigLIST_OF_TIME_SERVERS. 90 * 91 * @note The usage of the coreSNTP library API is encapsulated within 92 * this task. The rest of the FreeRTOS tasks/application does not need 93 * to be aware of the SNTP client as they can query time from the 94 * @ref systemGetWallClockTime() function. 95 */ 96 void sntpTask( void * parameters ); 97 98 99 #endif /* ifndef COMMON_DEMO_INCLUDE_H */ 100