├── Cfg └── Template │ └── clk_cfg.h ├── LICENSE ├── NOTICE ├── OS ├── uCOS-II │ └── clk_os.c └── uCOS-III │ └── clk_os.c ├── Source ├── clk.c └── clk.h └── readme.md /Cfg/Template/clk_cfg.h: -------------------------------------------------------------------------------- 1 | /* 2 | ********************************************************************************************************* 3 | * uC/Clk 4 | * Clock / Calendar 5 | * 6 | * Copyright 2005-2020 Silicon Laboratories Inc. www.silabs.com 7 | * 8 | * SPDX-License-Identifier: APACHE-2.0 9 | * 10 | * This software is subject to an open source license and is distributed by 11 | * Silicon Laboratories Inc. pursuant to the terms of the Apache License, 12 | * Version 2.0 available at www.apache.org/licenses/LICENSE-2.0. 13 | * 14 | ********************************************************************************************************* 15 | */ 16 | 17 | /* 18 | ********************************************************************************************************* 19 | * 20 | * CLOCK / CALENDAR CONFIGURATION FILE 21 | * 22 | * TEMPLATE 23 | * 24 | * Filename : clk_cfg.h 25 | * Version : V3.10.00 26 | ********************************************************************************************************* 27 | */ 28 | 29 | /* 30 | ********************************************************************************************************* 31 | * MODULE 32 | * Note(s) : (1) This configuration header file is protected from multiple pre-processor inclusion. 33 | ********************************************************************************************************* 34 | */ 35 | 36 | #ifndef CLK_CFG_H 37 | #define CLK_CFG_H 38 | 39 | 40 | /* 41 | ********************************************************************************************************* 42 | * CLOCK CONFIGURATION 43 | * 44 | * Note(s) : (1) Configure CLK_CFG_EXT_EN to enable/disable an externally-maintained clock : 45 | * 46 | * (a) When ENABLED, clock is maintained externally via hardware or another application 47 | * (see also 'clk.h Note #4'). 48 | * (b) When DISABLED, clock is maintained internally via software 49 | * (see also 'clk.h Note #3'). 50 | * 51 | * (2) (a) Configure CLK_CFG_SIGNAL_EN to enable/disable signaling of the internally-maintained 52 | * software clock : 53 | * 54 | * (1) When ENABLED, clock is signaled by application calls to Clk_SignalClk(). 55 | * (2) When DISABLED, clock is signaled by OS-dependent timing features. 56 | * 57 | * (b) CLK_CFG_SIGNAL_EN configuration is required only if CLK_CFG_EXT_EN is disabled. 58 | * 59 | * See also 'clk.h Note #3b'. 60 | * 61 | * (3) (a) Configure CLK_CFG_SIGNAL_FREQ_HZ to the number of times the application will signal 62 | * the clock every second. 63 | * 64 | * (b) CLK_CFG_SIGNAL_FREQ_HZ configuration is required only if CLK_CFG_SIGNAL_EN is enabled. 65 | * 66 | * (4) (a) Time zone is based on Coordinated Universal Time (UTC) & has valid values : 67 | * 68 | * (1) Between +|- 12 hours (+|- 43200 seconds) 69 | * (2) Multiples of 15 minutes 70 | * 71 | * (b) Time zone offset MUST be set in seconds. 72 | * 73 | * (c) Default values CAN be changed real-time by using an appropriate function. 74 | ********************************************************************************************************* 75 | */ 76 | 77 | /* Configure argument check feature : */ 78 | #define CLK_CFG_ARG_CHK_EN DEF_ENABLED 79 | /* DEF_DISABLED Argument checks DISABLED */ 80 | /* DEF_ENABLED Argument checks ENABLED */ 81 | 82 | 83 | /* Configure Clock string conversion features : */ 84 | #define CLK_CFG_STR_CONV_EN DEF_ENABLED 85 | /* DEF_DISABLED Clock string conversions DISABLED */ 86 | /* DEF_ENABLED Clock string conversions ENABLED */ 87 | 88 | 89 | /* Configure Clock NTP conversion features : */ 90 | #define CLK_CFG_NTP_EN DEF_ENABLED 91 | /* DEF_DISABLED NTP conversions DISABLED */ 92 | /* DEF_ENABLED NTP conversions ENABLED */ 93 | 94 | 95 | /* Configure Clock Unix conversion features : */ 96 | #define CLK_CFG_UNIX_EN DEF_ENABLED 97 | /* DEF_DISABLED Unix conversions DISABLED */ 98 | /* DEF_ENABLED Unix conversions ENABLED */ 99 | 100 | 101 | /* Configure External timestamp feature (see Note #1) : */ 102 | #define CLK_CFG_EXT_EN DEF_DISABLED 103 | /* DEF_DISABLED Software Clock maintained */ 104 | /* DEF_ENABLED External Clock maintained */ 105 | 106 | 107 | /* Configure Clock signal feature (see Note #2) : */ 108 | #define CLK_CFG_SIGNAL_EN DEF_DISABLED 109 | /* DEF_DISABLED Task time delayed */ 110 | /* DEF_ENABLED Signaled via application call ... */ 111 | /* ... to Clk_SignalClk() */ 112 | 113 | 114 | #define CLK_CFG_SIGNAL_FREQ_HZ 1000u /* Configure signal frequency (see Note #3). */ 115 | 116 | #define CLK_CFG_TZ_DFLT_SEC 0 /* Configure default time zone (see Note #4). */ 117 | 118 | 119 | /* 120 | ********************************************************************************************************* 121 | * TRACE / DEBUG CONFIGURATION 122 | ********************************************************************************************************* 123 | */ 124 | 125 | #ifndef TRACE_LEVEL_OFF 126 | #define TRACE_LEVEL_OFF 0 127 | #endif 128 | 129 | #ifndef TRACE_LEVEL_INFO 130 | #define TRACE_LEVEL_INFO 1 131 | #endif 132 | 133 | #ifndef TRACE_LEVEL_DBG 134 | #define TRACE_LEVEL_DBG 2 135 | #endif 136 | 137 | 138 | #define CLK_TRACE_LEVEL TRACE_LEVEL_OFF 139 | 140 | #define CLK_TRACE printf 141 | 142 | 143 | /* 144 | ********************************************************************************************************* 145 | * MODULE END 146 | * 147 | * Note(s) : (1) See 'clk_cfg.h MODULE'. 148 | ********************************************************************************************************* 149 | */ 150 | 151 | #endif 152 | 153 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | ATTENTION ALL USERS OF THIS REPOSITORY: 2 | 3 | The original work found in this repository is provided by Silicon Labs under the 4 | Apache License, Version 2.0. 5 | 6 | Any third party may contribute derivative works to the original work in which 7 | modifications are clearly identified as being licensed under: 8 | 9 | (1) the Apache License, Version 2.0 or a compatible open source license; or 10 | (2) under a proprietary license with a copy of such license deposited. 11 | 12 | All posted derivative works must clearly identify which license choice has been 13 | elected. 14 | 15 | No such posted derivative works will be considered to be a “Contribution” under 16 | the Apache License, Version 2.0. 17 | 18 | SILICON LABS MAKES NO WARRANTY WITH RESPECT TO ALL POSTED THIRD PARTY CONTENT 19 | AND DISCLAIMS ALL OTHER WARRANTIES OR LIABILITIES, INCLUDING ALL WARRANTIES OF 20 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE, OWNERSHIP, 21 | NON-INFRINGEMENT, AND NON-MISAPPROPRIATION. 22 | 23 | In the event a derivative work is desired to be submitted to Silicon Labs as a 24 | “Contribution” under the Apache License, Version 2.0, a “Contributor” must give 25 | written email notice to micrium@weston-embedded.com. Unless an email response in 26 | the affirmative to accept the derivative work as a “Contribution”, such email 27 | submission should be considered to have not been incorporated into the original 28 | work. 29 | -------------------------------------------------------------------------------- /OS/uCOS-II/clk_os.c: -------------------------------------------------------------------------------- 1 | /* 2 | ********************************************************************************************************* 3 | * uC/Clk 4 | * Clock / Calendar 5 | * 6 | * Copyright 2005-2020 Silicon Laboratories Inc. www.silabs.com 7 | * 8 | * SPDX-License-Identifier: APACHE-2.0 9 | * 10 | * This software is subject to an open source license and is distributed by 11 | * Silicon Laboratories Inc. pursuant to the terms of the Apache License, 12 | * Version 2.0 available at www.apache.org/licenses/LICENSE-2.0. 13 | * 14 | ********************************************************************************************************* 15 | */ 16 | 17 | /* 18 | ********************************************************************************************************* 19 | * 20 | * CLOCK / CALENDAR OPERATING SYSTEM LAYER 21 | * 22 | * Micrium uC/OS-II 23 | * 24 | * Filename : clk.c 25 | * Version : V3.10.00 26 | ********************************************************************************************************* 27 | * Note(s) : (1) Assumes uC/OS-II V2.86 (or more recent version) is included in the project build. 28 | * 29 | * (2) REQUIREs the following uC/OS-II feature to be ENABLED : 30 | * 31 | * ------ FEATURE ------ ------ MINIMUM CONFIGURATION FOR Clock/OS PORT ------ 32 | * 33 | * (a) Semaphores 34 | * (1) OS_SEM_EN Enabled 35 | * required only if CLK_CFG_SIGNAL_EN is DEF_ENABLED 36 | * 37 | * (b) OS Events OS_MAX_EVENTS >= 1 38 | * required only if CLK_CFG_SIGNAL_EN is DEF_ENABLED 39 | * (see 'OS OBJECT DEFINES') 40 | * 41 | * (3) Signal mode is higly recommended, because the time will drift when uC/OS-II time 42 | * delay is used. 43 | ********************************************************************************************************* 44 | */ 45 | 46 | /* 47 | ********************************************************************************************************* 48 | * INCLUDE FILES 49 | ********************************************************************************************************* 50 | */ 51 | 52 | #include "../../Source/clk.h" 53 | #include 54 | #include /* See this 'clk_os.c Note #1'. */ 55 | 56 | 57 | /* 58 | ********************************************************************************************************* 59 | * MODULE 60 | * 61 | * Note(s) : (1) See 'clk.h MODULE CONFIGURATION'. 62 | ********************************************************************************************************* 63 | */ 64 | 65 | #define MICRIUM_SOURCE 66 | #ifdef CLK_OS_MODULE_PRESENT 67 | 68 | 69 | /* 70 | ********************************************************************************************************* 71 | * LOCAL DEFINES 72 | ********************************************************************************************************* 73 | */ 74 | 75 | 76 | /* 77 | ********************************************************************************************************* 78 | * OS TASK/OBJECT NAME DEFINES 79 | ********************************************************************************************************* 80 | */ 81 | 82 | /* -------------------- TASK NAME --------------------- */ 83 | /* 1 2 */ 84 | /* 012345678901234567890 */ 85 | #define CLK_OS_TASK_NAME "RealTime Clk" 86 | #define CLK_OS_TASK_NAME_SIZE_MAX 13u /* Max of Clk task name size. */ 87 | 88 | 89 | /* --------------------- OBJ NAME --------------------- */ 90 | /* 1 2 */ 91 | /* 012345678901234567890 */ 92 | #define CLK_OS_SIGNAL_NAME "Clk Signal" 93 | #define CLK_OBJ_NAME_SIZE_MAX 11u /* Max of Clk obj name size. */ 94 | 95 | 96 | /* 97 | ********************************************************************************************************* 98 | * OS OBJECT DEFINES 99 | ********************************************************************************************************* 100 | */ 101 | 102 | #if (CLK_CFG_SIGNAL_EN == DEF_ENABLED) 103 | #define CLK_OS_NBR_SEM 1u 104 | #else 105 | #define CLK_OS_NBR_SEM 0u 106 | #endif 107 | 108 | #define CLK_OS_NBR_EVENTS CLK_OS_NBR_SEM 109 | 110 | 111 | /* 112 | ********************************************************************************************************* 113 | * LOCAL CONSTANTS 114 | ********************************************************************************************************* 115 | */ 116 | 117 | 118 | /* 119 | ********************************************************************************************************* 120 | * LOCAL DATA TYPES 121 | ********************************************************************************************************* 122 | */ 123 | 124 | 125 | /* 126 | ********************************************************************************************************* 127 | * LOCAL TABLES 128 | ********************************************************************************************************* 129 | */ 130 | 131 | 132 | /* 133 | ********************************************************************************************************* 134 | * LOCAL GLOBAL VARIABLES 135 | ********************************************************************************************************* 136 | */ 137 | 138 | /* -------------------- TASK STACK -------------------- */ 139 | static OS_STK Clk_OS_TaskStk[CLK_OS_CFG_TASK_STK_SIZE]; 140 | 141 | 142 | #if (CLK_CFG_SIGNAL_EN == DEF_ENABLED) /* ------------------- CLOCK SIGNAL ------------------- */ 143 | static OS_EVENT *Clk_OS_SignalPtr; /* Counting semaphore signals each second elapsed. */ 144 | #endif 145 | 146 | 147 | /* 148 | ********************************************************************************************************* 149 | * LOCAL FUNCTION PROTOTYPES 150 | ********************************************************************************************************* 151 | */ 152 | 153 | static void Clk_OS_Task(void *p_data); /* Clock task. */ 154 | 155 | 156 | /* 157 | ********************************************************************************************************* 158 | * DEFAULT CONFIGURATION 159 | ********************************************************************************************************* 160 | */ 161 | 162 | 163 | /* 164 | ********************************************************************************************************* 165 | * LOCAL CONFIGURATION ERRORS 166 | ********************************************************************************************************* 167 | */ 168 | 169 | /* See this 'clk_os.c Note #1'. */ 170 | #if (OS_VERSION < 286u) 171 | #error "OS_VERSION [SHOULD be >= V2.86]" 172 | #endif 173 | 174 | 175 | /* See this 'clk_os.c Note #2b'. */ 176 | #if (OS_MAX_EVENTS < CLK_OS_NBR_EVENTS) 177 | #error "OS_MAX_EVENTS illegally #define'd in 'os_cfg.h' " 178 | #error " [MUST be >= CLK_OS_NBR_EVENTS ]" 179 | #error " [ (see 'clk_os.c Note #2b')]" 180 | #endif 181 | 182 | 183 | 184 | #if (CLK_CFG_SIGNAL_EN == DEF_ENABLED) 185 | #if (OS_SEM_EN < 1u) /* See this 'clk_os.c Note #2a1'. */ 186 | #error "OS_SEM_EN illegally #define'd in 'os_cfg.h' " 187 | #error " [MUST be > 0u, (see 'clk_os.c Note #2a1')]" 188 | #endif 189 | #endif 190 | 191 | 192 | 193 | #ifndef CLK_OS_CFG_TASK_PRIO 194 | #error "CLK_OS_CFG_TASK_PRIO not #define'd in 'app_cfg.h'" 195 | #error " [MUST be >= 0u] " 196 | 197 | #elif (CLK_OS_CFG_TASK_PRIO < 0u) 198 | #error "CLK_OS_CFG_TASK_PRIO illegally #define'd in 'app_cfg.h'" 199 | #error " [MUST be >= 0u] " 200 | #endif 201 | 202 | 203 | #ifndef CLK_OS_CFG_TASK_STK_SIZE 204 | #error "CLK_OS_CFG_TASK_STK_SIZE not #define'd in 'app_cfg.h'" 205 | #error " [MUST be > 0u] " 206 | 207 | #elif (CLK_OS_CFG_TASK_STK_SIZE < 1u) 208 | #error "CLK_OS_CFG_TASK_STK_SIZE illegally #define'd in 'app_cfg.h'" 209 | #error " [MUST be > 0u] " 210 | #endif 211 | 212 | 213 | /* 214 | ********************************************************************************************************* 215 | ********************************************************************************************************* 216 | * CLOCK FUNCTIONS 217 | ********************************************************************************************************* 218 | ********************************************************************************************************* 219 | */ 220 | 221 | 222 | /* 223 | ********************************************************************************************************* 224 | * Clk_OS_Init() 225 | * 226 | * Description : (1) Perform Clock/OS initialization : 227 | * 228 | * (a) Implement Clock signal by creating a counting semaphore. 229 | * 230 | * (1) Initialize Clock signal to 0 tick by setting the semaphore count to 0. 231 | * 232 | * (b) Create Clock Task 233 | * 234 | * 235 | * Argument(s) : p_err Pointer to variable that will receive the return error code from this function : 236 | * 237 | * CLK_OS_ERR_NONE Clock OS initialization successful. 238 | * CLK_OS_ERR_INIT_SIGNAL Clock OS signal NOT successfully initialized. 239 | * CLK_OS_ERR_INIT_TASK Clock OS task NOT successfully initialized. 240 | * CLK_OS_ERR_INIT_NAME Clock OS name(s) NOT successfully initialized. 241 | * 242 | * Return(s) : DEF_OK, if NO error(s). 243 | * 244 | * DEF_FAIL, otherwise. 245 | * 246 | * Note(s) : none. 247 | ********************************************************************************************************* 248 | */ 249 | 250 | void Clk_OS_Init (CLK_ERR *p_err) 251 | { 252 | INT8U os_err; 253 | 254 | 255 | #if (CLK_CFG_SIGNAL_EN == DEF_ENABLED) /* ----------------- CREATE CLOCK SIGNAL ------------------ */ 256 | Clk_OS_SignalPtr = OSSemCreate((INT16U)0u); /* Create counting semaphore to signal each elapsed second. */ 257 | if (Clk_OS_SignalPtr == (OS_EVENT *)0) { 258 | *p_err = CLK_OS_ERR_INIT_SIGNAL; 259 | return; 260 | } 261 | 262 | #if (((OS_VERSION >= 288) && (OS_EVENT_NAME_EN > 0)) || \ 263 | ((OS_VERSION < 288) && (OS_EVENT_NAME_SIZE >= CLK_OBJ_NAME_SIZE_MAX))) 264 | OSEventNameSet((OS_EVENT *) Clk_OS_SignalPtr, 265 | (INT8U *) CLK_OS_SIGNAL_NAME, 266 | (INT8U *)&os_err); 267 | if (os_err != OS_ERR_NONE) { 268 | *p_err = CLK_OS_ERR_INIT_NAME; 269 | return; 270 | } 271 | #endif 272 | 273 | #endif 274 | 275 | 276 | /* ------------------ CREATE CLOCK TASK ------------------- */ 277 | #if (OS_TASK_CREATE_EXT_EN > 0u) 278 | 279 | #if (OS_STK_GROWTH == 1u) 280 | os_err = OSTaskCreateExt((void (*)(void *)) Clk_OS_Task, 281 | (void * ) 0, 282 | (OS_STK * )&Clk_OS_TaskStk[CLK_OS_CFG_TASK_STK_SIZE - 1u], 283 | (INT8U ) CLK_OS_CFG_TASK_PRIO, 284 | (INT16U ) CLK_OS_CFG_TASK_PRIO, /* Set task id same as task prio. */ 285 | (OS_STK * )&Clk_OS_TaskStk[0], 286 | (INT32U ) CLK_OS_CFG_TASK_STK_SIZE, 287 | (void * ) 0, 288 | (INT16U )(OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR)); 289 | #else 290 | os_err = OSTaskCreateExt((void (*)(void *)) Clk_OS_Task, 291 | (void * ) 0, 292 | (OS_STK * )&Clk_OS_TaskStk[0], 293 | (INT8U ) CLK_OS_CFG_TASK_PRIO, 294 | (INT16U ) CLK_OS_CFG_TASK_PRIO, /* Set task id same as task prio. */ 295 | (OS_STK * )&Clk_OS_TaskStk[CLK_OS_CFG_TASK_STK_SIZE - 1u], 296 | (INT32U ) CLK_OS_CFG_TASK_STK_SIZE, 297 | (void * ) 0, 298 | (INT16U )(OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR)); 299 | #endif 300 | 301 | #else 302 | 303 | #if (OS_STK_GROWTH == 1u) 304 | os_err = OSTaskCreate((void (*)(void *)) Clk_OS_Task, 305 | (void * ) 0, 306 | (OS_STK * )&Clk_OS_TaskStk[CLK_OS_CFG_TASK_STK_SIZE - 1u], 307 | (INT8U ) CLK_OS_CFG_TASK_PRIO); 308 | #else 309 | os_err = OSTaskCreate((void (*)(void *)) Clk_OS_Task, 310 | (void * ) 0, 311 | (OS_STK * )&Clk_OS_TaskStk[0], 312 | (INT8U ) CLK_OS_CFG_TASK_PRIO); 313 | #endif 314 | 315 | #endif 316 | 317 | if (os_err != OS_ERR_NONE) { 318 | *p_err = CLK_OS_ERR_INIT_TASK; 319 | return; 320 | } 321 | 322 | 323 | #if (((OS_VERSION >= 288u) && (OS_EVENT_NAME_EN > 0u)) || \ 324 | ((OS_VERSION < 288u) && (OS_EVENT_NAME_SIZE >= CLK_OS_TASK_NAME_SIZE_MAX))) 325 | OSTaskNameSet((INT8U ) CLK_OS_CFG_TASK_PRIO, 326 | (INT8U *) CLK_OS_TASK_NAME, 327 | (INT8U *)&os_err); 328 | if (os_err != OS_ERR_NONE) { 329 | *p_err = CLK_OS_ERR_INIT_NAME; 330 | return; 331 | } 332 | #endif 333 | 334 | 335 | *p_err = CLK_OS_ERR_NONE; 336 | } 337 | 338 | 339 | /* 340 | ********************************************************************************************************* 341 | * Clk_OS_Task() 342 | * 343 | * Description : OS-dependent shell task to schedule & run Clock Task handler. 344 | * 345 | * (1) Shell task's primary purpose is to schedule & run Clk_TaskHandler() forever; 346 | * (i.e. shell task should NEVER exit). 347 | * 348 | * 349 | * Argument(s) : p_data Pointer to task initialization data (required by uC/OS-III). 350 | * 351 | * Return(s) : none. 352 | * 353 | * Created by : Clk_OS_Init(). 354 | * 355 | * This function is an INTERNAL Clock function & MUST NOT be called by application function(s). 356 | * 357 | * Note(s) : (2) To prevent deadlocking any lower priority task(s), Clock Task SHOULD delay (for a brief) 358 | * time after task handler exits. 359 | ********************************************************************************************************* 360 | */ 361 | 362 | static void Clk_OS_Task (void *p_data) 363 | { 364 | (void)p_data; /* Prevent 'variable unused' compiler warning. */ 365 | 366 | while (DEF_ON) { 367 | Clk_TaskHandler(); 368 | OSTimeDly(1u); /* Dly for lower prio task(s) [see Note #2]. */ 369 | } 370 | } 371 | 372 | 373 | /* 374 | ********************************************************************************************************* 375 | * Clk_OS_Wait() 376 | * 377 | * Description : Wait for Clock signal to increment Clock timestamp. 378 | * 379 | * Argument(s) : p_err Pointer to variable that will receive the return error code from this function : 380 | * 381 | * CLK_OS_ERR_NONE Signal received. 382 | * CLK_OS_ERR_WAIT Signal NOT received. 383 | * 384 | * Return(s) : none. 385 | * 386 | * Note(s) : (1) Clock timestamp will drift when uC/OS-II time delay is used (see this 'clk_os.c Note #3'). 387 | ********************************************************************************************************* 388 | */ 389 | 390 | void Clk_OS_Wait (CLK_ERR *p_err) 391 | { 392 | #if (CLK_CFG_SIGNAL_EN == DEF_ENABLED) 393 | INT8U os_err; 394 | 395 | 396 | OSSemPend(Clk_OS_SignalPtr, /* Wait for one-sec signal ... */ 397 | 0u, /* ... without timeout. */ 398 | &os_err); 399 | if (os_err != OS_ERR_NONE) { 400 | *p_err = CLK_OS_ERR_WAIT; 401 | return; 402 | } 403 | #else 404 | OSTimeDlyHMSM(0u, 405 | 0u, 406 | 1u, /* Dly for one sec (see Note #1). */ 407 | 0u); 408 | #endif 409 | 410 | *p_err = CLK_OS_ERR_NONE; 411 | } 412 | 413 | 414 | /* 415 | ********************************************************************************************************* 416 | * Clk_OS_Signal() 417 | * 418 | * Description : Signal Clock module to increment timestamp. 419 | * 420 | * Argument(s) : p_err Pointer to variable that will receive the return error code from this function 421 | * 422 | * CLK_OS_ERR_NONE Clock module successfully signaled. 423 | * CLK_OS_ERR_SIGNAL Clock module NOT successfully signaled. 424 | * 425 | * Return(s) : none. 426 | * 427 | * Note(s) : (1) Clk_OS_Signal() MUST be called once per second. 428 | ********************************************************************************************************* 429 | */ 430 | 431 | #if (CLK_CFG_SIGNAL_EN == DEF_ENABLED) 432 | void Clk_OS_Signal (CLK_ERR *p_err) 433 | { 434 | INT8U os_err; 435 | 436 | 437 | os_err = OSSemPost(Clk_OS_SignalPtr); 438 | if (os_err != OS_ERR_NONE) { 439 | *p_err = CLK_OS_ERR_SIGNAL; 440 | return; 441 | } 442 | 443 | *p_err = CLK_OS_ERR_NONE; 444 | } 445 | #endif 446 | 447 | 448 | /* 449 | ********************************************************************************************************* 450 | * MODULE END 451 | * 452 | * Note(s) : (1) See 'clk.h MODULE CONFIGURATION'. 453 | ********************************************************************************************************* 454 | */ 455 | 456 | #endif /* End of Clk OS module include (see Note #1). */ 457 | 458 | -------------------------------------------------------------------------------- /OS/uCOS-III/clk_os.c: -------------------------------------------------------------------------------- 1 | /* 2 | ********************************************************************************************************* 3 | * uC/Clk 4 | * Clock / Calendar 5 | * 6 | * Copyright 2005-2020 Silicon Laboratories Inc. www.silabs.com 7 | * 8 | * SPDX-License-Identifier: APACHE-2.0 9 | * 10 | * This software is subject to an open source license and is distributed by 11 | * Silicon Laboratories Inc. pursuant to the terms of the Apache License, 12 | * Version 2.0 available at www.apache.org/licenses/LICENSE-2.0. 13 | * 14 | ********************************************************************************************************* 15 | */ 16 | 17 | /* 18 | ********************************************************************************************************* 19 | * 20 | * CLOCK / CALENDAR OPERATING SYSTEM LAYER 21 | * 22 | * Micrium uC/OS-III 23 | * 24 | * Filename : clk.c 25 | * Version : V3.10.00 26 | ********************************************************************************************************* 27 | * Note(s) : (1) Assumes uC/OS-III V3.01.0 (or more recent version) is included in the project build. 28 | * 29 | * (2) REQUIREs the following uC/OS-III feature to be ENABLED : 30 | * 31 | * ------ FEATURE ------ ------ MINIMUM CONFIGURATION FOR Clock/OS PORT ------ 32 | * 33 | * (a) Semaphores 34 | * (1) OS_CFG_SEM_EN Enabled 35 | * required only if CLK_CFG_SIGNAL_EN is DEF_ENABLED 36 | ********************************************************************************************************* 37 | */ 38 | 39 | /* 40 | ********************************************************************************************************* 41 | * INCLUDE FILES 42 | ********************************************************************************************************* 43 | */ 44 | 45 | #include "../../Source/clk.h" 46 | #include 47 | #include /* See this 'clk_os.c Note #1'. */ 48 | 49 | 50 | /* 51 | ********************************************************************************************************* 52 | * MODULE 53 | * 54 | * Note(s) : (1) See 'clk.h MODULE CONFIGURATION'. 55 | ********************************************************************************************************* 56 | */ 57 | 58 | #define MICRIUM_SOURCE 59 | #ifdef CLK_OS_MODULE_PRESENT 60 | 61 | 62 | /* 63 | ********************************************************************************************************* 64 | * LOCAL DEFINES 65 | ********************************************************************************************************* 66 | */ 67 | 68 | 69 | /* 70 | ********************************************************************************************************* 71 | * OS TASK/OBJECT NAME DEFINES 72 | ********************************************************************************************************* 73 | */ 74 | 75 | /* -------------------- TASK NAME --------------------- */ 76 | /* 1 2 */ 77 | /* 012345678901234567890 */ 78 | #define CLK_OS_TASK_NAME "RealTime Clk" 79 | 80 | /* --------------------- OBJ NAME --------------------- */ 81 | /* 1 2 */ 82 | /* 012345678901234567890 */ 83 | #define CLK_OS_SIGNAL_NAME "Clk Signal" 84 | 85 | 86 | /* 87 | ********************************************************************************************************* 88 | * OS OBJECT DEFINES 89 | ********************************************************************************************************* 90 | */ 91 | 92 | 93 | /* 94 | ********************************************************************************************************* 95 | * LOCAL CONSTANTS 96 | ********************************************************************************************************* 97 | */ 98 | 99 | 100 | /* 101 | ********************************************************************************************************* 102 | * LOCAL DATA TYPES 103 | ********************************************************************************************************* 104 | */ 105 | 106 | 107 | /* 108 | ********************************************************************************************************* 109 | * LOCAL TABLES 110 | ********************************************************************************************************* 111 | */ 112 | 113 | 114 | /* 115 | ********************************************************************************************************* 116 | * LOCAL GLOBAL VARIABLES 117 | ********************************************************************************************************* 118 | */ 119 | 120 | /* --------------------- TASK TCB --------------------- */ 121 | static OS_TCB Clk_OS_TaskTCB; 122 | 123 | /* -------------------- TASK STACK -------------------- */ 124 | static CPU_STK Clk_OS_TaskStk[CLK_OS_CFG_TASK_STK_SIZE]; 125 | 126 | 127 | #if (CLK_CFG_SIGNAL_EN == DEF_ENABLED) /* ------------------- CLOCK SIGNAL ------------------- */ 128 | static OS_SEM Clk_OS_SignalObj; /* Counting semaphore signals each second elapsed. */ 129 | #endif 130 | 131 | 132 | /* 133 | ********************************************************************************************************* 134 | * LOCAL FUNCTION PROTOTYPES 135 | ********************************************************************************************************* 136 | */ 137 | 138 | static void Clk_OS_Task(void *p_data); /* Clock task. */ 139 | 140 | 141 | /* 142 | ********************************************************************************************************* 143 | * DEFAULT CONFIGURATION 144 | ********************************************************************************************************* 145 | */ 146 | 147 | 148 | /* 149 | ********************************************************************************************************* 150 | * LOCAL CONFIGURATION ERRORS 151 | ********************************************************************************************************* 152 | */ 153 | 154 | /* See this 'clk_os.c Note #1'. */ 155 | #if (OS_VERSION < 3010u) 156 | #error "OS_VERSION [SHOULD be >= V3.01.0]" 157 | #endif 158 | 159 | 160 | 161 | #if (CLK_CFG_SIGNAL_EN == DEF_ENABLED) 162 | #if (OS_CFG_SEM_EN < 1u) /* See this 'clk_os.c Note #2a1'. */ 163 | #error "OS_CFG_SEM_EN illegally #define'd in 'os_cfg.h' " 164 | #error " [MUST be > 0u, (see 'clk_os.c Note #2a1')]" 165 | #endif 166 | #endif 167 | 168 | 169 | 170 | #ifndef CLK_OS_CFG_TASK_PRIO 171 | #error "CLK_OS_CFG_TASK_PRIO not #define'd in 'app_cfg.h'" 172 | #error " [MUST be >= 0u] " 173 | 174 | #elif (CLK_OS_CFG_TASK_PRIO < 0u) 175 | #error "CLK_OS_CFG_TASK_PRIO illegally #define'd in 'app_cfg.h'" 176 | #error " [MUST be >= 0u] " 177 | #endif 178 | 179 | 180 | #ifndef CLK_OS_CFG_TASK_STK_SIZE 181 | #error "CLK_OS_CFG_TASK_STK_SIZE not #define'd in 'app_cfg.h'" 182 | #error " [MUST be > 0u] " 183 | 184 | #elif (CLK_OS_CFG_TASK_STK_SIZE < 1u) 185 | #error "CLK_OS_CFG_TASK_STK_SIZE illegally #define'd in 'app_cfg.h'" 186 | #error " [MUST be > 0u] " 187 | #endif 188 | 189 | 190 | /* 191 | ********************************************************************************************************* 192 | ********************************************************************************************************* 193 | * CLOCK FUNCTIONS 194 | ********************************************************************************************************* 195 | ********************************************************************************************************* 196 | */ 197 | 198 | 199 | /* 200 | ********************************************************************************************************* 201 | * Clk_OS_Init() 202 | * 203 | * Description : (1) Perform Clock/OS initialization : 204 | * 205 | * (a) Implement Clock signal by creating a counting semaphore. 206 | * 207 | * (1) Initialize Clock signal to 0 tick by setting the semaphore count to 0. 208 | * 209 | * (b) Create Clock Task 210 | * 211 | * 212 | * Argument(s) : p_err Pointer to variable that will receive the return error code from this function : 213 | * 214 | * CLK_OS_ERR_NONE Clock OS initialization successful. 215 | * CLK_OS_ERR_INIT_SIGNAL Clock OS signal NOT successfully initialized. 216 | * CLK_OS_ERR_INIT_TASK Clock OS task NOT successfully initialized. 217 | * 218 | * Return(s) : DEF_OK, if NO error(s). 219 | * 220 | * DEF_FAIL, otherwise. 221 | * 222 | * Note(s) : none. 223 | ********************************************************************************************************* 224 | */ 225 | 226 | void Clk_OS_Init (CLK_ERR *p_err) 227 | { 228 | OS_ERR os_err; 229 | 230 | 231 | #if (CLK_CFG_SIGNAL_EN == DEF_ENABLED) /* ----------------- CREATE CLOCK SIGNAL ------------------ */ 232 | OSSemCreate((OS_SEM *)&Clk_OS_SignalObj, /* Create counting semaphore to signal each elapsed second. */ 233 | (CPU_CHAR *) CLK_OS_SIGNAL_NAME, 234 | (OS_SEM_CTR) 0u, 235 | (OS_ERR *)&os_err); 236 | if (os_err != OS_ERR_NONE) { 237 | *p_err = CLK_OS_ERR_INIT_SIGNAL; 238 | return; 239 | } 240 | #endif 241 | 242 | 243 | /* ------------------ CREATE CLOCK TASK ------------------- */ 244 | OSTaskCreate((OS_TCB *)&Clk_OS_TaskTCB, 245 | (CPU_CHAR *) CLK_OS_TASK_NAME, 246 | (OS_TASK_PTR ) Clk_OS_Task, 247 | (void *) 0, 248 | (OS_PRIO ) CLK_OS_CFG_TASK_PRIO, 249 | (CPU_STK *)&Clk_OS_TaskStk[0], 250 | (CPU_STK_SIZE)(CLK_OS_CFG_TASK_STK_SIZE / 10u), 251 | (CPU_STK_SIZE) CLK_OS_CFG_TASK_STK_SIZE, 252 | (OS_MSG_QTY ) 0u, 253 | (OS_TICK ) 0u, 254 | (void *) 0, 255 | (OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), 256 | (OS_ERR *)&os_err); 257 | if (os_err != OS_ERR_NONE) { 258 | *p_err = CLK_OS_ERR_INIT_TASK; 259 | return; 260 | } 261 | 262 | 263 | *p_err = CLK_OS_ERR_NONE; 264 | } 265 | 266 | 267 | /* 268 | ********************************************************************************************************* 269 | * Clk_OS_Task() 270 | * 271 | * Description : OS-dependent shell task to schedule & run Clock Task handler. 272 | * 273 | * (1) Shell task's primary purpose is to schedule & run Clk_TaskHandler() forever; 274 | * (i.e. shell task should NEVER exit). 275 | * 276 | * 277 | * Argument(s) : p_data Pointer to task initialization data (required by uC/OS-III). 278 | * 279 | * Return(s) : none. 280 | * 281 | * Created by : Clk_OS_Init(). 282 | * 283 | * This function is an INTERNAL Clock function & MUST NOT be called by application function(s). 284 | * 285 | * Note(s) : (2) To prevent deadlocking any lower priority task(s), Clock Task SHOULD delay (for a brief) 286 | * time after task handler exits. 287 | ********************************************************************************************************* 288 | */ 289 | 290 | static void Clk_OS_Task (void *p_data) 291 | { 292 | OS_ERR os_err; 293 | 294 | 295 | (void)p_data; /* Prevent 'variable unused' compiler warning. */ 296 | 297 | while (DEF_ON) { 298 | Clk_TaskHandler(); 299 | OSTimeDly((OS_TICK ) 1u, /* Dly for lower prio task(s) [see Note #2]. */ 300 | (OS_OPT ) OS_OPT_TIME_DLY, 301 | (OS_ERR *)&os_err); 302 | } 303 | } 304 | 305 | 306 | /* 307 | ********************************************************************************************************* 308 | * Clk_OS_Wait() 309 | * 310 | * Description : Wait for Clock signal to increment Clock timestamp. 311 | * 312 | * Argument(s) : p_err Pointer to variable that will receive the return error code from this function : 313 | * 314 | * CLK_OS_ERR_NONE Signal received. 315 | * CLK_OS_ERR_WAIT Signal NOT received. 316 | * 317 | * Return(s) : none. 318 | * 319 | * Note(s) : none. 320 | ********************************************************************************************************* 321 | */ 322 | 323 | void Clk_OS_Wait (CLK_ERR *p_err) 324 | { 325 | OS_ERR os_err; 326 | 327 | 328 | #if (CLK_CFG_SIGNAL_EN == DEF_ENABLED) 329 | OSSemPend((OS_SEM *)&Clk_OS_SignalObj, /* Wait for one-sec signal ... */ 330 | (OS_TICK ) 0u, /* ... without timeout. */ 331 | (OS_OPT ) OS_OPT_PEND_BLOCKING, 332 | (CPU_TS *) 0, 333 | (OS_ERR *)&os_err); 334 | #else 335 | OSTimeDlyHMSM(0u, 336 | 0u, 337 | 1u, /* Dly for one sec (see Note #1). */ 338 | 0u, 339 | OS_OPT_TIME_PERIODIC, 340 | &os_err); 341 | #endif 342 | 343 | if (os_err != OS_ERR_NONE) { 344 | *p_err = CLK_OS_ERR_WAIT; 345 | return; 346 | } 347 | 348 | *p_err = CLK_OS_ERR_NONE; 349 | } 350 | 351 | 352 | /* 353 | ********************************************************************************************************* 354 | * Clk_OS_Signal() 355 | * 356 | * Description : Signal Clock module to increment timestamp. 357 | * 358 | * Argument(s) : p_err Pointer to variable that will receive the return error code from this function 359 | * 360 | * CLK_OS_ERR_NONE Clock module successfully signaled. 361 | * CLK_OS_ERR_SIGNAL Clock module NOT successfully signaled. 362 | * 363 | * Return(s) : none. 364 | * 365 | * Note(s) : (1) Clk_OS_Signal() MUST be called once per second. 366 | ********************************************************************************************************* 367 | */ 368 | 369 | #if (CLK_CFG_SIGNAL_EN == DEF_ENABLED) 370 | void Clk_OS_Signal (CLK_ERR *p_err) 371 | { 372 | OS_ERR os_err; 373 | 374 | 375 | OSSemPost(&Clk_OS_SignalObj, 376 | OS_OPT_POST_1, 377 | &os_err); 378 | if (os_err != OS_ERR_NONE) { 379 | *p_err = CLK_OS_ERR_SIGNAL; 380 | return; 381 | } 382 | 383 | *p_err = CLK_OS_ERR_NONE; 384 | } 385 | #endif 386 | 387 | 388 | /* 389 | ********************************************************************************************************* 390 | * MODULE END 391 | * 392 | * Note(s) : (1) See 'clk.h MODULE CONFIGURATION'. 393 | ********************************************************************************************************* 394 | */ 395 | 396 | #endif /* End of Clk OS module include (see Note #1). */ 397 | 398 | -------------------------------------------------------------------------------- /Source/clk.h: -------------------------------------------------------------------------------- 1 | /* 2 | ********************************************************************************************************* 3 | * uC/Clk 4 | * Clock / Calendar 5 | * 6 | * Copyright 2005-2020 Silicon Laboratories Inc. www.silabs.com 7 | * 8 | * SPDX-License-Identifier: APACHE-2.0 9 | * 10 | * This software is subject to an open source license and is distributed by 11 | * Silicon Laboratories Inc. pursuant to the terms of the Apache License, 12 | * Version 2.0 available at www.apache.org/licenses/LICENSE-2.0. 13 | * 14 | ********************************************************************************************************* 15 | */ 16 | 17 | /* 18 | ********************************************************************************************************* 19 | * 20 | * CLOCK / CALENDAR 21 | * 22 | * Filename : clk.h 23 | * Version : V3.10.00 24 | ********************************************************************************************************* 25 | * Note(s) : (1) Assumes the following versions (or more recent) of software modules are included 26 | * in the project build : 27 | * 28 | * (a) uC/CPU V1.25 29 | * (b) uC/LIB V1.29 30 | * 31 | * 32 | * (2) (a) Clock module is based on Coordinated Universal Time (UTC) and supports the 33 | * following features : 34 | * 35 | * (1) Time zones 36 | * (2) Leap years 37 | * (3) Leap seconds 38 | * 39 | * (b) Clock module does NOT support Daylight (Savings) Time. If you want to handle 40 | * Daylight Time in your application, set time zone offset accordingly. 41 | * 42 | * (c) Timestamp and Coordinated Universal Time (UTC) related links : 43 | * 44 | * (1) http://www.timeanddate.com/time/aboututc.html 45 | * (2) http://www.allanstime.com/Publications/DWA/Science_Timekeeping/TheScienceOfTimekeeping.pdf 46 | * (3) http://www.cl.cam.ac.uk/~mgk25/time/metrologia-leapsecond.pdf 47 | * (4) http://www.navcen.uscg.gov/pdf/cgsicMeetings/45/29a%20UTCLeapSecond.ppt 48 | * 49 | * 50 | * (3) (a) Clock module implements a software-maintained clock/calendar when 'CLK_CFG_EXT_EN' 51 | * is disabled (see Note #4). 52 | * 53 | * (b) (1) Software-maintained clock/calendar is based on a periodic delay or timeout 54 | * when 'CLK_CFG_SIGNAL_EN' is disabled. 55 | * 56 | * (2) Software-maintained clock/calendar is based on a periodic signal or timer 57 | * when 'CLK_CFG_SIGNAL_EN' is enabled. 58 | * 59 | * (c) When software-maintained clock is enabled, Clock module's OS-dependent files and 60 | * respective OS-application configuration MUST be included in the build. 61 | * 62 | * 63 | * (4) (a) Clock module initializes, gets and sets its timestamp via an External timestamp 64 | * when 'CLK_CFG_EXT_EN' is enabled. 65 | * 66 | * (b) (1) External timestamp can be maintained either in : 67 | * 68 | * (A) Hardware (e.g. via a hardware clock chip) 69 | * (B) From another application (e.g. SNTPc) 70 | * 71 | * (2) External timestamp is accessed by application/BSP functions defined by the 72 | * developer that MUST follow the functional requirements of the particular 73 | * hardware/application(s). 74 | * 75 | * See also 'net.h Clk_ExtTS_Init()', 76 | * 'net.h Clk_ExtTS_Get()', 77 | * & 'net.h Clk_ExtTS_Set()'. 78 | ********************************************************************************************************* 79 | */ 80 | 81 | /* 82 | ********************************************************************************************************* 83 | * MODULE 84 | * 85 | * Note(s) : (1) This Clock module header file is protected from multiple pre-processor inclusion through 86 | * use of the Clock module present pre-processor macro definition. 87 | ********************************************************************************************************* 88 | */ 89 | 90 | #ifndef CLK_MODULE_PRESENT /* See Note #1. */ 91 | #define CLK_MODULE_PRESENT 92 | 93 | 94 | /* 95 | ********************************************************************************************************* 96 | * CLOCK VERSION NUMBER 97 | * 98 | * Note(s) : (1) (a) The Clock software version is denoted as follows : 99 | * 100 | * Vx.yy.zz 101 | * 102 | * where 103 | * V denotes 'Version' label 104 | * x denotes major software version revision number 105 | * yy denotes minor software version revision number 106 | * zz denotes sub-minor software version revision number 107 | * 108 | * (b) The Clock software version label #define is formatted as follows : 109 | * 110 | * ver = x.yyzz * 100 * 100 111 | * 112 | * where 113 | * ver denotes software version number scaled as an integer value 114 | * x.yyzz denotes software version number, where the unscaled integer 115 | * portion denotes the major version number & the unscaled 116 | * fractional portion denotes the (concatenated) minor 117 | * version numbers 118 | ********************************************************************************************************* 119 | */ 120 | 121 | #define CLK_VERSION 31000u /* See Note #1. */ 122 | 123 | 124 | /* 125 | ********************************************************************************************************* 126 | * EXTERNS 127 | ********************************************************************************************************* 128 | */ 129 | 130 | #ifdef CLK_MODULE 131 | #define CLK_EXT 132 | #else 133 | #define CLK_EXT extern 134 | #endif 135 | 136 | 137 | /* 138 | ********************************************************************************************************* 139 | * INCLUDE FILES 140 | * 141 | * Note(s) : (1) Clock module files are located in the following directories : 142 | * 143 | * (a) (1) \\clk_cfg.h 144 | * (2) \app_cfg.h See 'clk.h Note #3c' 145 | * 146 | * (b) (1) \\Source\clk.h 147 | * \clk.c 148 | * 149 | * (2) \\OS\\clk_os.c 150 | * 151 | * where 152 | * directory path for Your Product's Application 153 | * directory path for Clock module 154 | * directory name for specific operating system (OS) 155 | * 156 | * (2) CPU-configuration software files are located in the following directories : 157 | * 158 | * (a) \\cpu_def.h 159 | * 160 | * (b) \\\\cpu*.* 161 | * 162 | * where 163 | * directory path for common CPU-compiler software 164 | * directory name for specific processor (CPU) 165 | * directory name for specific compiler 166 | * 167 | * (3) NO compiler-supplied standard library functions are used by the Clock module. 168 | * 169 | * (a) Standard library functions are implemented in the custom library module(s) : 170 | * 171 | * \\lib*.* 172 | * 173 | * where 174 | * directory path for custom library software 175 | * 176 | * (4) Compiler MUST be configured to include as additional include path directories : 177 | * 178 | * (a) '\\' See Note #1a 179 | * 180 | * (b) '\\' directories See Note #1b 181 | * 182 | * (c) (1) '\\' See Note #2a 183 | * (2) '\\\\' See Note #2b 184 | * 185 | * (d) '\\' See Note #3a 186 | ********************************************************************************************************* 187 | */ 188 | 189 | #include /* CPU Configuration (see Note #2) */ 190 | #include /* CPU Core Library */ 191 | 192 | #include /* Standard Defines (see Note #3a) */ 193 | #include /* Standard String Library (see Note #3a) */ 194 | 195 | #include /* Clk Configuration File (see Note #1a) */ 196 | 197 | 198 | /* 199 | ********************************************************************************************************* 200 | * MODULE CONFIGURATION 201 | * 202 | * Note(s) : (1) (a) When the External timestamp is disabled, the Clock/Calendar is software- maintained 203 | * and 'clk_os.c' MUST be included in the project (see 'net.h Note #3c'). 204 | * 205 | * (b) When the External timestamp is enabled, the Clock/Calendar is externally maintained 206 | * and 'clk_os.c' does NOT need to be included in the project. 207 | ********************************************************************************************************* 208 | */ 209 | 210 | #if (CLK_CFG_EXT_EN != DEF_ENABLED) 211 | #define CLK_OS_MODULE_PRESENT /* See Note #1a. */ 212 | #endif 213 | 214 | 215 | /* 216 | ********************************************************************************************************* 217 | * DEFINES 218 | ********************************************************************************************************* 219 | */ 220 | 221 | 222 | /* 223 | ********************************************************************************************************* 224 | * CLOCK ERROR CODE DEFINES 225 | ********************************************************************************************************* 226 | */ 227 | 228 | #define CLK_ERR_NONE 0u /* No err. */ 229 | 230 | 231 | /* 232 | ********************************************************************************************************* 233 | * CLOCK-OS LAYER ERROR CODE DEFINES 234 | ********************************************************************************************************* 235 | */ 236 | 237 | #define CLK_OS_ERR_NONE 100u 238 | 239 | #define CLK_OS_ERR_INIT_TASK 101u 240 | #define CLK_OS_ERR_INIT_SIGNAL 102u 241 | #define CLK_OS_ERR_INIT_NAME 105u 242 | 243 | #define CLK_OS_ERR_WAIT 120u 244 | #define CLK_OS_ERR_SIGNAL 121u 245 | 246 | 247 | /* 248 | ********************************************************************************************************* 249 | * CLK STR FORMAT DEFINES 250 | ********************************************************************************************************* 251 | */ 252 | 253 | #define CLK_STR_FMT_YYYY_MM_DD_HH_MM_SS_UTC 1u /* Fmt date/time as "YYYY-MM-DD HH:MM:SS UTC+TZ" : */ 254 | /* ... "YYYY-MM-DD HH:MM:SS UTC+hh:mm" */ 255 | /* ... or "YYYY-MM-DD HH:MM:SS UTC-hh:mm". */ 256 | #define CLK_STR_FMT_YYYY_MM_DD_HH_MM_SS 2u /* Fmt date/time as "YYYY-MM-DD HH:MM:SS". */ 257 | #define CLK_STR_FMT_MM_DD_YY_HH_MM_SS 3u /* Fmt date/time as "MM-DD-YY HH:MM:SS". */ 258 | #define CLK_STR_FMT_YYYY_MM_DD 4u /* Fmt date/time as "YYYY-MM-DD". */ 259 | #define CLK_STR_FMT_MM_DD_YY 5u /* Fmt date/time as "MM-DD-YY". */ 260 | #define CLK_STR_FMT_DAY_MONTH_DD_YYYY 6u /* Fmt date/time as "Day Month DD, YYYY". */ 261 | #define CLK_STR_FMT_DAY_MONTH_DD_HH_MM_SS_YYYY 7u /* Fmt date/time as "Day Mon DD HH:MM:SS YYYY". */ 262 | #define CLK_STR_FMT_HH_MM_SS 8u /* Fmt date/time as "HH:MM:SS". */ 263 | #define CLK_STR_FMT_HH_MM_SS_AM_PM 9u /* Fmt date/time as "HH:MM:SS AM|PM". */ 264 | 265 | /* 1 2 3 */ 266 | /* 0123456789012345678901234567890 */ 267 | #define CLK_STR_FMT_YYYY_MM_DD_HH_MM_SS_UTC_LEN 30u /* Str len of fmt "YYYY-MM-DD HH:MM:SS UTC+TZ" : */ 268 | /* ... "YYYY-MM-DD HH:MM:SS UTC+hh:mm" */ 269 | /* ... or "YYYY-MM-DD HH:MM:SS UTC-hh:mm". */ 270 | #define CLK_STR_FMT_YYYY_MM_DD_HH_MM_SS_LEN 20u /* Str len of fmt "YYYY-MM-DD HH:MM:SS". */ 271 | #define CLK_STR_FMT_MM_DD_YY_HH_MM_SS_LEN 18u /* Str len of fmt "MM-DD-YY HH:MM:SS". */ 272 | #define CLK_STR_FMT_YYYY_MM_DD_LEN 11u /* Str len of fmt "YYYY-MM-DD". */ 273 | #define CLK_STR_FMT_MM_DD_YY_LEN 9u /* Str len of fmt "MM-DD-YY". */ 274 | #define CLK_STR_FMT_DAY_MONTH_DD_YYYY_MAX_LEN 29u /* Max str len of fmt "Day Month DD, YYYY". */ 275 | #define CLK_STR_FMT_DAY_MONTH_DD_HH_MM_SS_YYYY_LEN 25u /* Str len of fmt "Day Mon DD HH:MM:SS YYYY". */ 276 | #define CLK_STR_FMT_HH_MM_SS_LEN 9u /* Str len of fmt "HH:MM:SS". */ 277 | #define CLK_STR_FMT_HH_MM_SS_AM_PM_LEN 15u /* Str len of fmt "HH:MM:SS AM|PM". */ 278 | 279 | #define CLK_STR_FMT_MAX_LEN 30u /* Max str len of all clk str fmts. */ 280 | 281 | 282 | #define CLK_STR_DIG_YR_LEN 4u /* Str len of yr dig. */ 283 | #define CLK_STR_DIG_YR_TRUNC_LEN 2u /* Str len of trunc yr dig. */ 284 | #define CLK_STR_DIG_MONTH_LEN 2u /* Str len of mon dig. */ 285 | #define CLK_STR_DIG_DAY_LEN 2u /* Str len of day dig. */ 286 | #define CLK_STR_DIG_HR_LEN 2u /* Str len of hr dig. */ 287 | #define CLK_STR_DIG_MIN_LEN 2u /* Str len of min dig. */ 288 | #define CLK_STR_DIG_SEC_LEN 2u /* Str len of sec dig. */ 289 | #define CLK_STR_DIG_TZ_HR_LEN 2u /* Str len of tz hr dig. */ 290 | #define CLK_STR_DIG_TZ_MIN_LEN 2u /* Str len of tz min dig. */ 291 | #define CLK_STR_DIG_TZ_MAX_LEN 2u /* Max str len of tz digs. */ 292 | #define CLK_STR_DAY_OF_WK_MAX_LEN 9u /* Max str len of day of wk str (e.g. Wednesday). */ 293 | #define CLK_STR_DAY_OF_WK_TRUNC_LEN 3u /* Str len of day of wk trunc str. */ 294 | #define CLK_STR_MONTH_MAX_LEN 9u /* Max str len of month str (e.g. September). */ 295 | #define CLK_STR_MONTH_TRUNC_LEN 3u /* Str len of month trunc str. */ 296 | #define CLK_STR_AM_PM_LEN 2u /* Str len of am-pm str. */ 297 | 298 | 299 | /* 300 | ********************************************************************************************************* 301 | * CLOCK DEFINES 302 | * 303 | * Note(s) : (1) Year 2038 problem (e.g. Unix Millennium bug, Y2K38 or Y2.038K) may cause some computer 304 | * software to fail before or in the year 2038. The problem affects all software and 305 | * systems that both store time as a signed 32-bit integer and interpret this number as 306 | * the number of seconds since 00:00:00 UTC on 1970/01/1. 307 | * 308 | * There is no straightforward and general fix for this problem. Changing timestamp 309 | * datatype to an unsigned 32-bit integer have been chosen to avoid this problem. Thus 310 | * timestamp will be accurate until the year 2106, but dates before 1970 are not possible. 311 | ********************************************************************************************************* 312 | */ 313 | 314 | #define CLK_FIRST_MONTH_OF_YR 1u /* First month of a yr [1 to 12]. */ 315 | #define CLK_FIRST_DAY_OF_MONTH 1u /* First day of a month [1 to 31]. */ 316 | #define CLK_FIRST_DAY_OF_YR 1u /* First day of a yr [1 to 366]. */ 317 | #define CLK_FIRST_DAY_OF_WK 1u /* First day of a wk [1 to 7]. */ 318 | 319 | 320 | #define CLK_MONTH_PER_YR 12u 321 | #define CLK_HR_PER_HALF_DAY 12uL 322 | 323 | #define CLK_YR_NONE 0u 324 | 325 | #define CLK_MONTH_NONE 0u 326 | #define CLK_MONTH_JAN 1u 327 | #define CLK_MONTH_FEB 2u 328 | #define CLK_MONTH_MAR 3u 329 | #define CLK_MONTH_APR 4u 330 | #define CLK_MONTH_MAY 5u 331 | #define CLK_MONTH_JUN 6u 332 | #define CLK_MONTH_JUL 7u 333 | #define CLK_MONTH_AUG 8u 334 | #define CLK_MONTH_SEP 9u 335 | #define CLK_MONTH_OCT 10u 336 | #define CLK_MONTH_NOV 11u 337 | #define CLK_MONTH_DEC 12u 338 | 339 | #define CLK_DAY_NONE 0u 340 | #define CLK_DAY_OF_WK_NONE 0u 341 | #define CLK_DAY_OF_WK_SUN 1u 342 | #define CLK_DAY_OF_WK_MON 2u 343 | #define CLK_DAY_OF_WK_TUE 3u 344 | #define CLK_DAY_OF_WK_WED 4u 345 | #define CLK_DAY_OF_WK_THU 5u 346 | #define CLK_DAY_OF_WK_FRI 6u 347 | #define CLK_DAY_OF_WK_SAT 7u 348 | 349 | 350 | /* ------------------ CLK TS DEFINES ------------------ */ 351 | #define CLK_TS_SEC_MIN DEF_INT_32U_MIN_VAL 352 | #define CLK_TS_SEC_MAX DEF_INT_32U_MAX_VAL 353 | #define CLK_TS_SEC_NONE CLK_TS_SEC_MIN 354 | 355 | 356 | /* ------------------ CLK TZ DEFINES ------------------ */ 357 | #define CLK_TZ_MIN_PRECISION 15uL 358 | #define CLK_TZ_SEC_PRECISION (CLK_TZ_MIN_PRECISION * DEF_TIME_NBR_SEC_PER_MIN) 359 | #define CLK_TZ_SEC_MIN (-(CLK_HR_PER_HALF_DAY * DEF_TIME_NBR_SEC_PER_HR)) 360 | #define CLK_TZ_SEC_MAX (CLK_HR_PER_HALF_DAY * DEF_TIME_NBR_SEC_PER_HR) 361 | 362 | 363 | /* ----------------- CLK TICK DEFINES ----------------- */ 364 | #define CLK_TICK_NONE 0u 365 | 366 | 367 | /* ---------------- CLK EPOCH DEFINES ----------------- */ 368 | #define CLK_EPOCH_YR_START 2000u /* Clk epoch starts = 2000-01-01 00:00:00 UTC. */ 369 | #define CLK_EPOCH_YR_END 2136u /* ends = 2135-12-31 23:59:59 UTC. */ 370 | #define CLK_EPOCH_DAY_OF_WK 7u /* 2000-01-01 is Sat. */ 371 | 372 | 373 | /* -------------- NTP EPOCH DATE DEFINES -------------- */ 374 | #define CLK_NTP_EPOCH_YR_START 1900u /* NTP epoch starts = 1900-01-01 00:00:00 UTC. */ 375 | #define CLK_NTP_EPOCH_YR_END 2036u /* ends = 2035-12-31 23:59:59 UTC. */ 376 | #define CLK_NTP_EPOCH_DAY_OF_WK 2u /* 1900-01-01 is Mon. */ 377 | #define CLK_NTP_EPOCH_OFFSET_YR_CNT (CLK_EPOCH_YR_START - CLK_NTP_EPOCH_YR_START) 378 | 379 | /* Only 24 leap yrs because 1900 is NOT a leap yr. */ 380 | #define CLK_NTP_EPOCH_OFFSET_LEAP_DAY_CNT ((CLK_NTP_EPOCH_OFFSET_YR_CNT / 4u) - 1u) 381 | 382 | /* 100 yrs * 365 * 24 * 60 * 60 = 3153600000 */ 383 | /* + 24 leap days * 24 * 60 * 60 = 2073600 */ 384 | /* CLK_NTP_OFFSET_SEC = 3155673600 */ 385 | #define CLK_NTP_EPOCH_OFFSET_SEC ((CLK_NTP_EPOCH_OFFSET_YR_CNT * DEF_TIME_NBR_SEC_PER_YR ) + \ 386 | (CLK_NTP_EPOCH_OFFSET_LEAP_DAY_CNT * DEF_TIME_NBR_SEC_PER_DAY)) 387 | 388 | 389 | /* ------------- UNIX EPOCH DATE DEFINES -------------- */ 390 | /* See Note #1. */ 391 | #define CLK_UNIX_EPOCH_YR_START 1970u /* Unix epoch starts = 1970-01-01 00:00:00 UTC. */ 392 | #define CLK_UNIX_EPOCH_YR_END 2106u /* ends = 2105-12-31 23:59:59 UTC. */ 393 | #define CLK_UNIX_EPOCH_DAY_OF_WK 5u /* 1970-01-01 is Thu. */ 394 | #define CLK_UNIX_EPOCH_OFFSET_YR_CNT (CLK_EPOCH_YR_START - CLK_UNIX_EPOCH_YR_START) 395 | #define CLK_UNIX_EPOCH_OFFSET_LEAP_DAY_CNT (CLK_UNIX_EPOCH_OFFSET_YR_CNT / 4u) 396 | 397 | /* 30 yrs * 365 * 24 * 60 * 60 = 946080000 */ 398 | /* + 7 leap days * 24 * 60 * 60 = 604800 */ 399 | /* CLK_UNIX_OFFSET_SEC = 946684800 */ 400 | #define CLK_UNIX_EPOCH_OFFSET_SEC ((CLK_UNIX_EPOCH_OFFSET_YR_CNT * DEF_TIME_NBR_SEC_PER_YR ) + \ 401 | (CLK_UNIX_EPOCH_OFFSET_LEAP_DAY_CNT * DEF_TIME_NBR_SEC_PER_DAY)) 402 | 403 | 404 | /* 405 | ********************************************************************************************************* 406 | * DATA TYPES 407 | ********************************************************************************************************* 408 | */ 409 | 410 | /* 411 | ********************************************************************************************************* 412 | * CLOCK ERROR CODES DATA TYPE 413 | ********************************************************************************************************* 414 | */ 415 | 416 | typedef CPU_INT08U CLK_ERR; 417 | 418 | 419 | /* 420 | ********************************************************************************************************* 421 | * CLOCK FORMAT STRING DATA TYPE 422 | ********************************************************************************************************* 423 | */ 424 | 425 | typedef CPU_INT08U CLK_STR_FMT; 426 | 427 | 428 | /* 429 | ********************************************************************************************************* 430 | * CLOCK DATE DATA TYPES 431 | ********************************************************************************************************* 432 | */ 433 | 434 | typedef CPU_INT16U CLK_YR; 435 | typedef CPU_INT08U CLK_MONTH; 436 | typedef CPU_INT16U CLK_DAY; 437 | typedef CPU_INT32U CLK_NBR_DAYS; 438 | 439 | 440 | /* 441 | ********************************************************************************************************* 442 | * CLOCK TIME DATA TYPES 443 | ********************************************************************************************************* 444 | */ 445 | 446 | typedef CPU_INT08U CLK_HR; 447 | typedef CPU_INT08U CLK_MIN; 448 | typedef CPU_INT08U CLK_SEC; 449 | 450 | 451 | /* 452 | ********************************************************************************************************* 453 | * CLOCK TIMESTAMP DATA TYPE 454 | ********************************************************************************************************* 455 | */ 456 | 457 | typedef CPU_INT32U CLK_TS_SEC; 458 | 459 | 460 | /* 461 | ********************************************************************************************************* 462 | * CLOCK TIME ZONE DATA TYPE 463 | ********************************************************************************************************* 464 | */ 465 | 466 | typedef CPU_INT32S CLK_TZ_SEC; 467 | 468 | 469 | /* 470 | ********************************************************************************************************* 471 | * CLOCK PERIODIC TICK COUNTER DATA TYPE 472 | ********************************************************************************************************* 473 | */ 474 | 475 | typedef CPU_INT32U CLK_TICK_CTR; 476 | 477 | 478 | /* 479 | ********************************************************************************************************* 480 | * CLOCK DATE/TIME DATA TYPE 481 | * 482 | * Note(s) : (1) Same date/time structure is used for all epoch. Thus Year value ('Yr') should be a value 483 | * between the epoch start and end years. 484 | * 485 | * (2) Seconds value of 60 is valid to be compatible with leap second adjustment and the atomic 486 | * clock time stucture. 487 | * 488 | * (3) Time zone is based on Coordinated Universal Time (UTC) & has valid values : 489 | * 490 | * (a) Between +|- 12 hours (+|- 43200 seconds) 491 | * (b) Multiples of 15 minutes 492 | ********************************************************************************************************* 493 | */ 494 | 495 | typedef struct clk_date_time { 496 | CLK_YR Yr; /* Yr [epoch start to end yr), (see Note #1). */ 497 | CLK_MONTH Month; /* Month [ 1 to 12], (Jan to Dec). */ 498 | CLK_DAY Day; /* Day [ 1 to 31]. */ 499 | CLK_DAY DayOfWk; /* Day of wk [ 1 to 7], (Sun to Sat). */ 500 | CLK_DAY DayOfYr; /* Day of yr [ 1 to 366]. */ 501 | CLK_HR Hr; /* Hr [ 0 to 23]. */ 502 | CLK_MIN Min; /* Min [ 0 to 59]. */ 503 | CLK_SEC Sec; /* Sec [ 0 to 60], (see Note #2). */ 504 | CLK_TZ_SEC TZ_sec; /* TZ [ -43200 to 43200], (see Note #3). */ 505 | } CLK_DATE_TIME; 506 | 507 | 508 | /* 509 | ********************************************************************************************************* 510 | * FUNCTION PROTOTYPES 511 | ********************************************************************************************************* 512 | */ 513 | 514 | void Clk_Init (CLK_ERR *p_err); 515 | 516 | #ifdef CLK_OS_MODULE_PRESENT 517 | void Clk_TaskHandler (void); 518 | 519 | #if (CLK_CFG_SIGNAL_EN == DEF_ENABLED) 520 | void Clk_SignalClk (CLK_ERR *p_err); 521 | #endif 522 | #endif 523 | 524 | 525 | /* --------------- CLK TS GET & SET --------------- */ 526 | CLK_TS_SEC Clk_GetTS (void); /* Get clk TS. */ 527 | 528 | CPU_BOOLEAN Clk_SetTS (CLK_TS_SEC ts_sec); /* Set clk TS. */ 529 | 530 | 531 | 532 | /* --------------- CLK TZ GET & SET --------------- */ 533 | CLK_TZ_SEC Clk_GetTZ (void); /* Get clk TZ offset. */ 534 | 535 | CPU_BOOLEAN Clk_SetTZ (CLK_TZ_SEC tz_sec); /* Set clk TZ offset. */ 536 | 537 | 538 | 539 | /* ----------- CLK TS & DATE/TIME UTIL ------------ */ 540 | CPU_BOOLEAN Clk_GetDateTime (CLK_DATE_TIME *date_time); /* Get clk TS using a CLK_DATE_TIME struct. */ 541 | 542 | CPU_BOOLEAN Clk_SetDateTime (CLK_DATE_TIME *date_time); /* Set clk TS using a CLK_DATE_TIME struct. */ 543 | 544 | CPU_BOOLEAN Clk_TS_ToDateTime (CLK_TS_SEC ts_sec, 545 | CLK_TZ_SEC tz_sec, 546 | CLK_DATE_TIME *p_date_time); 547 | 548 | CPU_BOOLEAN Clk_DateTimeToTS (CLK_TS_SEC *p_ts_sec, 549 | CLK_DATE_TIME *date_time); 550 | 551 | CPU_BOOLEAN Clk_DateTimeMake (CLK_DATE_TIME *date_time, /* Make a date/time struct. */ 552 | CLK_YR yr, 553 | CLK_MONTH month, 554 | CLK_DAY day, 555 | CLK_HR hr, 556 | CLK_MIN min, 557 | CLK_SEC sec, 558 | CLK_TZ_SEC tz_sec); 559 | 560 | CPU_BOOLEAN Clk_IsDateTimeValid (CLK_DATE_TIME *p_date_time); 561 | 562 | 563 | /* ------------------ DATE UTIL ------------------- */ 564 | CLK_DAY Clk_GetDayOfWk (CLK_YR yr, 565 | CLK_MONTH month, 566 | CLK_DAY day); 567 | 568 | CLK_DAY Clk_GetDayOfYr (CLK_YR yr, 569 | CLK_MONTH month, 570 | CLK_DAY day); 571 | 572 | 573 | #if (CLK_CFG_STR_CONV_EN == DEF_ENABLED) /* ---------------- STR CONV UTIL ----------------- */ 574 | CPU_BOOLEAN Clk_DateTimeToStr (CLK_DATE_TIME *p_date_time, /* Conv a date/time struct to a str. */ 575 | CPU_INT08U fmt_nbr, 576 | CPU_CHAR *p_str, 577 | CPU_SIZE_T str_len); 578 | #endif 579 | 580 | 581 | 582 | #if (CLK_CFG_NTP_EN == DEF_ENABLED) 583 | /* --------------- NTP TS GET & SET --------------- */ 584 | CPU_BOOLEAN Clk_GetTS_NTP (CLK_TS_SEC *ts_sec_ntp); /* Get clk TS using NTP TS. */ 585 | 586 | CPU_BOOLEAN Clk_SetTS_NTP (CLK_TS_SEC ts_sec_ntp); /* Set clk TS using NTP TS. */ 587 | 588 | 589 | /* ----------- NTP TS & DATE/TIME UTIL ------------ */ 590 | CPU_BOOLEAN Clk_TS_ToTS_NTP (CLK_TS_SEC ts_sec, 591 | CLK_TS_SEC *p_ts_sec_ntp); 592 | 593 | CPU_BOOLEAN Clk_TS_NTP_ToTS (CLK_TS_SEC *p_ts_sec, 594 | CLK_TS_SEC ts_sec_ntp); 595 | 596 | CPU_BOOLEAN Clk_TS_NTP_ToDateTime (CLK_TS_SEC ts_ntp_sec, 597 | CLK_TZ_SEC tz_sec, 598 | CLK_DATE_TIME *p_date_time); 599 | 600 | CPU_BOOLEAN Clk_DateTimeToTS_NTP (CLK_TS_SEC *p_ts_ntp_sec, 601 | CLK_DATE_TIME *p_date_time); 602 | 603 | CPU_BOOLEAN Clk_NTP_DateTimeMake (CLK_DATE_TIME *p_date_time, 604 | CLK_YR yr, 605 | CLK_MONTH month, 606 | CLK_DAY day, 607 | CLK_HR hr, 608 | CLK_MIN min, 609 | CLK_SEC sec, 610 | CLK_TZ_SEC tz_sec); 611 | 612 | CPU_BOOLEAN Clk_IsNTP_DateTimeValid(CLK_DATE_TIME *p_date_time); 613 | 614 | #endif 615 | 616 | 617 | 618 | #if (CLK_CFG_UNIX_EN == DEF_ENABLED) 619 | /* -------------- UNIX TS GET & SET --------------- */ 620 | CPU_BOOLEAN Clk_GetTS_Unix (CLK_TS_SEC *ts_unix_sec); /* Get clk TS using Unix TS. */ 621 | 622 | CPU_BOOLEAN Clk_SetTS_Unix (CLK_TS_SEC ts_unix_sec); /* Set clk TS using Unix TS. */ 623 | 624 | 625 | /* ----------- UNIX TS & DATE/TIME UTIL ----------- */ 626 | CPU_BOOLEAN Clk_TS_ToTS_Unix (CLK_TS_SEC ts_sec, 627 | CLK_TS_SEC *p_ts_unix_sec); 628 | 629 | CPU_BOOLEAN Clk_TS_UnixToTS (CLK_TS_SEC *p_ts_sec, 630 | CLK_TS_SEC ts_unix_sec); 631 | 632 | CPU_BOOLEAN Clk_TS_UnixToDateTime (CLK_TS_SEC ts_unix_sec, 633 | CLK_TZ_SEC tz_sec, 634 | CLK_DATE_TIME *p_date_time); 635 | 636 | CPU_BOOLEAN Clk_DateTimeToTS_Unix (CLK_TS_SEC *p_ts_unix_sec, 637 | CLK_DATE_TIME *p_date_time); 638 | 639 | CPU_BOOLEAN Clk_UnixDateTimeMake (CLK_DATE_TIME *p_date_time, 640 | CLK_YR yr, 641 | CLK_MONTH month, 642 | CLK_DAY day, 643 | CLK_HR hr, 644 | CLK_MIN min, 645 | CLK_SEC sec, 646 | CLK_TZ_SEC tz_sec); 647 | 648 | CPU_BOOLEAN Clk_IsUnixDateTimeValid(CLK_DATE_TIME *p_date_time); 649 | 650 | #endif 651 | 652 | 653 | /* 654 | ********************************************************************************************************* 655 | * FUNCTION PROTOTYPES 656 | * RTOS INTERFACE FUNCTIONS 657 | * (see specific OS'S clk_os.c) 658 | ********************************************************************************************************* 659 | */ 660 | 661 | #ifdef CLK_OS_MODULE_PRESENT 662 | void Clk_OS_Init (CLK_ERR *p_err); 663 | 664 | void Clk_OS_Wait (CLK_ERR *p_err); 665 | 666 | void Clk_OS_Signal(CLK_ERR *p_err); 667 | #endif 668 | 669 | 670 | /* 671 | ********************************************************************************************************* 672 | * FUNCTION PROTOTYPES 673 | * DEFINED IN PRODUCT'S BSP 674 | ********************************************************************************************************* 675 | */ 676 | 677 | /* 678 | ********************************************************************************************************* 679 | * Clk_ExtTS_Init() 680 | * 681 | * Description : Initialize & start External timestamp timer. 682 | * 683 | * Argument(s) : none. 684 | * 685 | * Return(s) : none. 686 | * 687 | * Note(s) : (1) CLK_ExtTS_Init() is an application/BSP function that MUST be defined by the developer 688 | * if External timestamp is enabled. 689 | * 690 | * See 'clk_cfg.h CLK CONFIGURATION Note #1'. 691 | * 692 | * (2) (a) External timestamp values MUST be returned via 'CLK_TS_SEC' data type. 693 | * 694 | * (b) External timestamp values SHOULD be returned on the epoch of Clock module and 695 | * include the time zone offset. 696 | * 697 | * (3) (a) External timestamp SHOULD be an 'up' counter whose values increase at each second. 698 | * It's possible to use a 'down' counter, but a conversion MUST be applied when setting 699 | * and getting timestamp. 700 | * 701 | * (b) External timestamp COULD come from another application (e.g. by SNTPc). 702 | ********************************************************************************************************* 703 | */ 704 | 705 | #if (CLK_CFG_EXT_EN == DEF_ENABLED) 706 | void Clk_ExtTS_Init(void); 707 | #endif 708 | 709 | 710 | /* 711 | ********************************************************************************************************* 712 | * Clk_ExtTS_Get() 713 | * 714 | * Description : Get Clock module's timestamp from converted External timestamp. 715 | * 716 | * Argument(s) : none. 717 | * 718 | * Return(s) : Current Clock timestamp (in seconds, UTC+00). 719 | * 720 | * Note(s) : (1) Clk_ExtTS_Get() is an application/BSP function that MUST be defined by the developer 721 | * if External timestamp is enabled. 722 | * 723 | * See 'clk_cfg.h CLK CONFIGURATION Note #1' 724 | * 725 | * 726 | * (2) (a) Clock timestamp values MUST be returned via 'CLK_TS_SEC' data type. 727 | * 728 | * (b) (1) If the External timestamp has more bits than the 'CLK_TS_SEC' data type, 729 | * Clk_ExtTS_Get() MUST truncate the External timestamp's higher order bits 730 | * greater than the 'CLK_TS_SEC' data type. 731 | * 732 | * (2) If the External timestamp has less bits than the 'CLK_TS_SEC' data type, 733 | * Clk_ExtTS_Get() MUST pad the Clock timestamp's higher order bits with 734 | * 0 bits. 735 | * 736 | * 737 | * (3) (a) External timestamp values MUST be returned from the reference of the Clock 738 | * epoch start date/time. 739 | * 740 | * (b) External timestamp SHOULD start on midnight of January 1st of its epoch start 741 | * year. Otherwise, the equations to convert between External timestamp & Clock 742 | * timestamp MUST also include the External timestamp's epoch Day-of-Year, Hour, 743 | * Minute, & Second (see Note #4). 744 | * 745 | * (c) Returned Clock timestamp MUST be representable in Clock epoch. Thus equivalent 746 | * date of the External timestamp MUST be between : 747 | * 748 | * (1) >= CLK_EPOCH_YR_START 749 | * (2) < CLK_EPOCH_YR_END 750 | * 751 | * (d) If the External timestamp includes an (optional) external time zone, 752 | * Clk_ExtTS_Get() MUST subtract the external time zone offset from the 753 | * converted External timestamp. 754 | * 755 | * 756 | * (4) The Clock timestamp is calculated by one of the following equations (assuming 757 | * Note #3b) : 758 | * 759 | * (a) When External epoch start year is less than Clock epoch start year 760 | * ('CLK_EPOCH_YR_START') : 761 | * 762 | * Clock TS = External TS 763 | * - [(((Clock start year - External start year) * 365) + leap day count) 764 | * * seconds per day] 765 | * - External TZ 766 | * 767 | * Examples with a 32-bit External timestamp : 768 | * 769 | * (1) Valid equivalent date to convert is after Clock epoch start year : 770 | * 771 | * 2010 Oct 8, 11:11:11 UTC-05:00 772 | * External TS (in seconds) = 1286536271 773 | * External start year = 1970 774 | * Clock start year = 2000 775 | * Leap day count between External & Clock epoch start year = 7 776 | * External TZ (in seconds) = -18000 777 | * Clock TS (in seconds) = 339869471 778 | * 2010 Oct 8, 16:11:11 UTC 779 | * 780 | * This example successfully converts an External timestamp into a 781 | * representable Clock timestamp without underflowing. 782 | * 783 | * (2) Invalid equivalent date to convert is before Clock epoch start year : 784 | * 785 | * 1984 Oct 8, 11:11:11 UTC-05:00 786 | * External TS (in seconds) = 466081871 787 | * External start year = 1970 788 | * Clock start year = 2000 789 | * Leap day count between External & Clock epoch start year = 7 790 | * External TZ (in seconds) = -18000 791 | * Clock TS (in seconds) = -480584929 792 | * 793 | * This example underflows to a negative Clock timestamp since the 794 | * equivalent date to convert is incorrectly less than the Clock epoch 795 | * start year ('CLK_EPOCH_YR_START'). 796 | * 797 | * 798 | * (b) When External epoch start year is greater than Clock epoch start year 799 | * ('CLK_EPOCH_YR_START') : 800 | * 801 | * Clock TS = External TS 802 | * + [(((External start year - Clock start year) * 365) + leap day count) 803 | * * seconds per day] 804 | * - External TZ 805 | * 806 | * 807 | * Examples with a 32-bit External timestamp : 808 | * 809 | * (1) Valid equivalent date to convert is before Clock epoch end year : 810 | * 811 | * 2010 Oct 8, 11:11:11 UTC-05:00 812 | * External TS (in seconds) = 24232271 813 | * External start year = 2010 814 | * Clock end year = 2136 815 | * Leap day count between External & Clock epoch start year = 3 816 | * External TZ (in seconds) = -18000 817 | * Clock TS (in seconds) = 339869471 818 | * 2010 Oct 8, 16:11:11 UTC-05:00 819 | * 820 | * This example successfully converts an External timestamp into a 821 | * representable Clock timestamp without overflowing. 822 | * 823 | * (2) Invalid equivalent date to convert is after Clock epoch end year : 824 | * 825 | * 2140 Oct 8, 11:11:11 UTC-05:00 826 | * External TS (in seconds) = 4126677071 827 | * External start year = 2010 828 | * Clock end year = 2136 829 | * Leap day count between External & Clock epoch start year = 3 830 | * External TZ (in seconds) = -18000 831 | * Clock TS (in seconds) = 4442314271 832 | * 833 | * This example overflows the Clock timestamp (32-bit) 'CLK_TS_SEC' data 834 | * type with an equivalent date incorrectly greater than or equal to the 835 | * Clock epoch end year ('CLK_EPOCH_YR_END'). 836 | * 837 | * 838 | * (c) Where 839 | * 840 | * (1) Clock TS Converted Clock timestamp (in seconds, 841 | * from UTC+00) 842 | * (2) External TS External timestamp to convert (in seconds) 843 | * (3) Clock start year Clock epoch start year ('CLK_EPOCH_YR_START') 844 | * (4) Clock end year Clock epoch end year ('CLK_EPOCH_YR_END') 845 | * (5) External start year External timestamp epoch start year 846 | * (6) Leap day count Number of leap days between Clock epoch 847 | * start year & External epoch start year 848 | * (7) Seconds per day Number of seconds per day (86400) 849 | * (8) External TZ Time zone offset applied to External TS 850 | * (in seconds, from UTC+00) 851 | ********************************************************************************************************* 852 | */ 853 | 854 | #if (CLK_CFG_EXT_EN == DEF_ENABLED) 855 | CLK_TS_SEC Clk_ExtTS_Get(void); 856 | #endif 857 | 858 | 859 | /* 860 | ********************************************************************************************************* 861 | * Clk_ExtTS_Set() 862 | * 863 | * Description : Set External timestamp. 864 | * 865 | * Argument(s) : ts_sec Timestamp value to set (in seconds, UTC+00). 866 | * 867 | * Return(s) : DEF_OK, if External timestamp succesfully set. 868 | * 869 | * DEF_FAIL, otherwise. 870 | * 871 | * Note(s) : (1) CLK_ExtTS_Set() is an application/BSP function that MUST be defined by the developer 872 | * if External timestamp is enabled. 873 | * 874 | * See 'clk_cfg.h CLK CONFIGURATION Note #1'. 875 | * 876 | * (a) If External timestamp is provided by another application, it's possible that the 877 | * External timestamp may NOT be set (e.g. by SNTPc) in which case CLK_ExtTS_Set() 878 | * MUST ALWAYS return 'DEF_FAIL'. 879 | * 880 | * 881 | * (2) (a) External timestamp values are converted from Clock timestamp's 'CLK_TS_SEC' 882 | * data type. 883 | * 884 | * (b) (1) If the External timestamp has more bits than the 'CLK_TS_SEC' data type, 885 | * Clk_ExtTS_Set() MUST pad the External timestamp's higher order bits with 886 | * 0 bits. 887 | * 888 | * (2) If the External timestamp has less bits than the 'CLK_TS_SEC' data type, 889 | * Clk_ExtTS_Set() MUST truncate the Clock timestamp's higher order bits 890 | * greater than the External timestamp. 891 | * 892 | * 893 | * (3) (a) External timestamp values MUST be converted from the reference of the Clock 894 | * epoch start date/time. 895 | * 896 | * (b) External timestamp SHOULD start on midnight of January 1st of its epoch start 897 | * year. Otherwise, the equations to convert between External timestamp & Clock 898 | * timestamp MUST also include the External timestamp's epoch Day-of-Year, Hour, 899 | * Minute, & Second (see Note #4). 900 | * 901 | * (c) Converted External timestamp MUST be representable in External epoch. Thus 902 | * equivalent date of the External timestamp MUST be between : 903 | * 904 | * (1) External epoch start year 905 | * (2) External epoch end year 906 | * 907 | * (d) If the External timestamp includes an (optional) external time zone, 908 | * Clk_ExtTS_Set() MUST add the external time zone offset to the converted 909 | * External timestamp. 910 | * 911 | * 912 | * (4) The External timestamp is calculated by one of the following equations (assuming 913 | * Note #3b) : 914 | * 915 | * (a) When External epoch start year is less than Clock epoch start year 916 | * ('CLK_EPOCH_YR_START') : 917 | * 918 | * External TS = Clock TS 919 | * + [(((Clock start year - External start year) * 365) + leap day count) 920 | * * seconds per day] 921 | * + External TZ 922 | * 923 | * Examples with a 32-bit External timestamp : 924 | * 925 | * (1) Valid equivalent date to convert is before External epoch end year : 926 | * 927 | * 2010 Oct 8, 16:11:11 UTC 928 | * Clock TS (in seconds) = 339869471 929 | * External start year = 1970 930 | * External end year = 2106 931 | * Leap day count between External & Clock epoch start year = 7 932 | * External TZ (in seconds) = -18000 933 | * External TS (in seconds) = 1286536271 934 | * 2010 Oct 8, 11:11:11 UTC-05:00 935 | * 936 | * This example successfully converts an External timestamp into a 937 | * representable Clock timestamp without overflowing. 938 | * 939 | * (2) Invalid equivalent date to convert is after External epoch end year : 940 | * 941 | * 2120 Oct 8, 11:11:11 UTC 942 | * Clock TS (in seconds) = 3811144271 943 | * External start year = 1970 944 | * External end year = 2106 945 | * Leap day count between External & Clock epoch start year = 7 946 | * External TZ (in seconds) = -18000 947 | * External TS (in seconds) = 4757811071 948 | * 949 | * This example overflows the External (32-bit) timestamp with an equivalent 950 | * date incorrectly greater than or equal to the External epoch end year. 951 | * 952 | * 953 | * (b) When External epoch start year is greater than Clock epoch start year 954 | * ('CLK_EPOCH_YR_START') : 955 | * 956 | * External TS = Clock TS 957 | * - [(((External start year - Clock start year) * 365) + leap day count) 958 | * * seconds per day] 959 | * + External TZ 960 | * 961 | * 962 | * Examples with a 32-bit External timestamp : 963 | * 964 | * (1) Valid equivalent date to convert is after External epoch start year : 965 | * 966 | * 2010 Oct 8, 16:11:11 UTC 967 | * Clock TS (in seconds) = 339869471 968 | * External start year = 2010 969 | * Leap day count between External & Clock epoch start year = 3 970 | * External TZ (in seconds) = -18000 971 | * External TS (in seconds) = 24232271 972 | * 2010 Oct 8, 11:11:11 UTC-05:00 973 | * 974 | * This example successfully converts an External timestamp into a 975 | * representable Clock timestamp without underflowing. 976 | * 977 | * (2) Invalid equivalent date to convert is before External epoch start year : 978 | * 979 | * 2005 Oct 8, 11:11:11 UTC 980 | * Clock TS (in seconds) = 182085071 981 | * External start year = 2010 982 | * Leap day count between External & Clock epoch start year = 3 983 | * External TZ (in seconds) = -18000 984 | * External TS (in seconds) = -133552129 985 | * 986 | * This example underflows to a negative External timestamp since the 987 | * equivalent date to convert is incorrectly less than the External 988 | * epoch start year. 989 | * 990 | * 991 | * (c) where 992 | * 993 | * (1) Clock TS Clock timestamp (in seconds, from UTC+00) 994 | * (2) External TS Converted External timestamp (in seconds) 995 | * (3) Clock start year Clock epoch start year ('CLK_EPOCH_YR_START') 996 | * (4) External start year External timestamp epoch start year 997 | * (5) External end year External timestamp epoch end year 998 | * (6) Leap day count Number of leap days between Clock epoch 999 | * start year & External epoch start year 1000 | * (7) Seconds per day Number of seconds per day (86400) 1001 | * (8) External TZ Time zone offset applied to External TS 1002 | * (in seconds, from UTC+00) 1003 | ********************************************************************************************************* 1004 | */ 1005 | 1006 | #if (CLK_CFG_EXT_EN == DEF_ENABLED) 1007 | CPU_BOOLEAN Clk_ExtTS_Set(CLK_TS_SEC ts_sec); 1008 | #endif 1009 | 1010 | 1011 | /* 1012 | ********************************************************************************************************* 1013 | * TRACING 1014 | ********************************************************************************************************* 1015 | */ 1016 | 1017 | /* Trace level, default to TRACE_LEVEL_OFF. */ 1018 | #ifndef TRACE_LEVEL_OFF 1019 | #define TRACE_LEVEL_OFF 0 1020 | #endif 1021 | 1022 | #ifndef TRACE_LEVEL_INFO 1023 | #define TRACE_LEVEL_INFO 1 1024 | #endif 1025 | 1026 | #ifndef TRACE_LEVEL_DBG 1027 | #define TRACE_LEVEL_DBG 2 1028 | #endif 1029 | 1030 | #ifndef CLK_TRACE_LEVEL 1031 | #define CLK_TRACE_LEVEL TRACE_LEVEL_OFF 1032 | #endif 1033 | 1034 | #ifndef CLK_TRACE 1035 | #define CLK_TRACE printf 1036 | #endif 1037 | 1038 | #if ((defined(CLK_TRACE)) && \ 1039 | (defined(CLK_TRACE_LEVEL)) && \ 1040 | (CLK_TRACE_LEVEL >= TRACE_LEVEL_INFO)) 1041 | 1042 | #if (CLK_TRACE_LEVEL >= TRACE_LEVEL_LOG) 1043 | #define CLK_TRACE_LOG(msg) CLK_TRACE msg 1044 | #else 1045 | #define CLK_TRACE_LOG(msg) 1046 | #endif 1047 | 1048 | 1049 | #if (CLK_TRACE_LEVEL >= TRACE_LEVEL_DBG) 1050 | #define CLK_TRACE_DBG(msg) CLK_TRACE msg 1051 | #else 1052 | #define CLK_TRACE_DBG(msg) 1053 | #endif 1054 | 1055 | #define CLK_TRACE_INFO(msg) CLK_TRACE msg 1056 | 1057 | #else 1058 | #define CLK_TRACE_LOG(msg) 1059 | #define CLK_TRACE_DBG(msg) 1060 | #define CLK_TRACE_INFO(msg) 1061 | #endif 1062 | 1063 | 1064 | /* 1065 | ********************************************************************************************************* 1066 | * CONFIGURATION ERRORS 1067 | ********************************************************************************************************* 1068 | */ 1069 | 1070 | #ifndef CLK_CFG_ARG_CHK_EN 1071 | #error "CLK_CFG_ARG_CHK_EN not #define'd in 'clk_cfg.h'" 1072 | #error " [MUST be DEF_DISABLED] " 1073 | #error " [ || DEF_ENABLED ] " 1074 | #elif ((CLK_CFG_ARG_CHK_EN != DEF_ENABLED ) && \ 1075 | (CLK_CFG_ARG_CHK_EN != DEF_DISABLED)) 1076 | 1077 | #error "CLK_CFG_ARG_CHK_EN illegally #define'd in 'clk_cfg.h'" 1078 | #error " [MUST be DEF_DISABLED] " 1079 | #error " [ || DEF_ENABLED ] " 1080 | #endif 1081 | 1082 | 1083 | 1084 | #ifndef CLK_CFG_STR_CONV_EN 1085 | #error "CLK_CFG_STR_CONV_EN not #define'd in 'clk_cfg.h'" 1086 | #error " [MUST be DEF_DISABLED] " 1087 | #error " [ || DEF_ENABLED ] " 1088 | #elif ((CLK_CFG_STR_CONV_EN != DEF_ENABLED ) && \ 1089 | (CLK_CFG_STR_CONV_EN != DEF_DISABLED)) 1090 | #error "CLK_CFG_STR_CONV_EN illegally #define'd in 'clk_cfg.h'" 1091 | #error " [MUST be DEF_DISABLED] " 1092 | #error " [ || DEF_ENABLED ] " 1093 | #endif 1094 | 1095 | 1096 | 1097 | 1098 | #ifndef CLK_CFG_NTP_EN 1099 | #error "CLK_CFG_NTP_EN not #define'd in 'clk_cfg.h'" 1100 | #error " [MUST be DEF_DISABLED] " 1101 | #error " [ || DEF_ENABLED ] " 1102 | #elif ((CLK_CFG_NTP_EN != DEF_ENABLED ) && \ 1103 | (CLK_CFG_NTP_EN != DEF_DISABLED)) 1104 | #error "CLK_CFG_NTP_EN illegally #define'd in 'clk_cfg.h'" 1105 | #error " [MUST be DEF_DISABLED] " 1106 | #error " [ || DEF_ENABLED ] " 1107 | #endif 1108 | 1109 | 1110 | 1111 | #ifndef CLK_CFG_UNIX_EN 1112 | #error "CLK_CFG_UNIX_EN not #define'd in 'clk_cfg.h'" 1113 | #error " [MUST be DEF_DISABLED] " 1114 | #error " [ || DEF_ENABLED ] " 1115 | #elif ((CLK_CFG_UNIX_EN != DEF_ENABLED ) && \ 1116 | (CLK_CFG_UNIX_EN != DEF_DISABLED)) 1117 | #error "CLK_CFG_UNIX_EN illegally #define'd in 'clk_cfg.h'" 1118 | #error " [MUST be DEF_DISABLED] " 1119 | #error " [ || DEF_ENABLED ] " 1120 | #endif 1121 | 1122 | 1123 | 1124 | 1125 | #ifndef CLK_CFG_EXT_EN 1126 | #error "CLK_CFG_EXT_EN not #define'd in 'clk_cfg.h'" 1127 | #error " [MUST be DEF_DISABLED] " 1128 | #error " [ || DEF_ENABLED ] " 1129 | 1130 | #elif ((CLK_CFG_EXT_EN != DEF_ENABLED ) && \ 1131 | (CLK_CFG_EXT_EN != DEF_DISABLED)) 1132 | #error "CLK_CFG_EXT_EN illegally #define'd in 'clk_cfg.h'" 1133 | #error " [MUST be DEF_DISABLED] " 1134 | #error " [ || DEF_ENABLED ] " 1135 | 1136 | 1137 | #elif (CLK_CFG_EXT_EN != DEF_ENABLED) 1138 | 1139 | #ifndef CLK_CFG_SIGNAL_EN 1140 | #error "CLK_CFG_SIGNAL_EN not #define'd in 'clk_cfg.h'" 1141 | #error " [MUST be DEF_DISABLED] " 1142 | #error " [ || DEF_ENABLED ] " 1143 | 1144 | 1145 | #elif ((CLK_CFG_SIGNAL_EN != DEF_ENABLED ) && \ 1146 | (CLK_CFG_SIGNAL_EN != DEF_DISABLED)) 1147 | #error "CLK_CFG_SIGNAL_EN illegally #define'd in 'clk_cfg.h'" 1148 | #error " [MUST be DEF_DISABLED] " 1149 | #error " [ || DEF_ENABLED ] " 1150 | 1151 | 1152 | #elif (CLK_CFG_SIGNAL_EN == DEF_ENABLED) 1153 | 1154 | #ifndef CLK_CFG_SIGNAL_FREQ_HZ 1155 | #error "CLK_CFG_SIGNAL_FREQ_HZ not #define'd in 'clk_cfg.h'" 1156 | #error " [MUST be > 0] " 1157 | #elif (CLK_CFG_SIGNAL_FREQ_HZ < 1) 1158 | #error "CLK_CFG_SIGNAL_FREQ_HZ illegally #define'd in 'clk_cfg.h'" 1159 | #error " [MUST be > 0] " 1160 | #endif 1161 | 1162 | #endif 1163 | 1164 | #endif 1165 | 1166 | 1167 | 1168 | 1169 | #ifndef CLK_CFG_TZ_DFLT_SEC 1170 | #error "CLK_CFG_TZ_DFLT_SEC not #define'd in 'clk_cfg.h'" 1171 | #error " [MUST be >= CLK_TZ_SEC_MIN ]" 1172 | #error " [ && <= CLK_TZ_SEC_MAX ]" 1173 | #error " [ && multiple of CLK_TZ_SEC_PRECISION]" 1174 | #elif (( DEF_ABS(CLK_CFG_TZ_DFLT_SEC) > CLK_TZ_SEC_MAX) || \ 1175 | ((DEF_ABS(CLK_CFG_TZ_DFLT_SEC) % CLK_TZ_SEC_PRECISION) != 0u)) 1176 | #error "CLK_CFG_TZ_DFLT_SEC illegally #define'd in 'clk_cfg.h'" 1177 | #error " [MUST be >= CLK_TZ_SEC_MIN ]" 1178 | #error " [ && <= CLK_TZ_SEC_MAX ]" 1179 | #error " [ && multiple of CLK_TZ_SEC_PRECISION]" 1180 | 1181 | #endif 1182 | 1183 | 1184 | /* 1185 | ********************************************************************************************************* 1186 | * LIBRARY CONFIGURATION ERRORS 1187 | ********************************************************************************************************* 1188 | */ 1189 | 1190 | /* See 'clk.h Note #1a'. */ 1191 | #if (CPU_CORE_VERSION < 125u) 1192 | #error "CPU_CORE_VERSION [SHOULD be >= V1.25]" 1193 | #endif 1194 | 1195 | 1196 | /* See 'clk.h Note #1b'. */ 1197 | #if (LIB_VERSION < 129u) 1198 | #error "LIB_VERSION [SHOULD be >= V1.29]" 1199 | #endif 1200 | 1201 | 1202 | /* 1203 | ********************************************************************************************************* 1204 | * MODULE END 1205 | * 1206 | * Note(s) : (1) See 'clk.h MODULE'. 1207 | ********************************************************************************************************* 1208 | */ 1209 | 1210 | #endif /* End of CLK module include (see 'MODULE Note #1'). */ 1211 | 1212 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # uC/Clk 2 | 3 | µC/Clk is a module that implements a Year 2000 compliant clock/calendar module. The clock/calendar module offers the following features: 4 | 5 | * Maintains time in seconds starting from 2000/01/01 (January 1st, 2000) at 00:00:00 UTC until 2134/12/31 (December 31st, 2134) 23:59:59 UTC; but supports conversions to/from two other timestamps: 6 | 7 | * NTP (Network Time Protocol) timestamps, starting from 1900/01/01 (January 1st, 1900) at 00:00:00 UTC until 2034/12/31 (December 31st, 2034) 23:59:59 UTC; 8 | 9 | * Unix timestamps, starting from 1970/01/01 (January 1st, 1970) at 00:00:00 UTC until 2104/12/31 (December 31st, 2104) 23:59:59 UTC. 10 | 11 | * Allows your application to obtain timestamps to mark the occurrence of events. A µC/Clk timestamp is a copy of its internal timestamp. 12 | 13 | * Allows your application to get the current date and time into a structured data type named CLK_DATE_TIME containing Year, Month, Day, Day-of-Year, Day-of-Week, Hour, Minute, Second, and Timezone Offset. Can convert timestamps to dates/times or vice versa. 14 | 15 | * Allows your application to get and set the clock date/time using any of the supported timestamps or a CLK_DATE_TIME structure and allows conversion to/from all supported timestamps and the CLK_DATE_TIME structure. 16 | 17 | ## For the complete documentation, visit https://doc.micrium.com/display/ucos/ --------------------------------------------------------------------------------