xref: /aosp_15_r20/external/pigweed/pw_chrono_threadx/public/pw_chrono_threadx/config.h (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1 // Copyright 2020 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 // Configuration macros for the tokenizer module.
15 #pragma once
16 
17 #include "pw_polyfill/static_assert.h"
18 #include "tx_api.h"
19 
20 // For the ThreadX backend of the SystemClock, there is no way to determine the
21 // system timer's tick interval/frequency. By default most ports happen to be at
22 // 10ms intervals (i.e. 100Hz), however this can be tuned for different
23 // applications.
24 // The resulting clock period is defined in seconds = numerator / denominator.
25 // For example the default is configured to 1/100 seconds per clock tick.
26 #ifndef PW_CHRONO_THREADX_CFG_CLOCK_PERIOD_SECONDS_NUMERATOR
27 #define PW_CHRONO_THREADX_CFG_CLOCK_PERIOD_SECONDS_NUMERATOR 1
28 #endif  // PW_CHRONO_THREADX_CFG_CLOCK_PERIOD_SECONDS_NUMERATOR
29 #ifndef PW_CHRONO_THREADX_CFG_CLOCK_PERIOD_SECONDS_DENOMINATOR
30 #define PW_CHRONO_THREADX_CFG_CLOCK_PERIOD_SECONDS_DENOMINATOR 100
31 #endif  // PW_CHRONO_THREADX_CFG_CLOCK_PERIOD_SECONDS_DENOMINATOR
32 
33 static_assert(PW_CHRONO_THREADX_CFG_CLOCK_PERIOD_SECONDS_NUMERATOR >= 1,
34               "the numerator must be positive and cannot be fractional");
35 static_assert(PW_CHRONO_THREADX_CFG_CLOCK_PERIOD_SECONDS_DENOMINATOR >= 1,
36               "the denominator must be positive and cannot be fractional");
37 
38 // Because the SystemClock::now() implementation requires the user to invoke it
39 // more than once per overflow period, the max timeout is set to ensure that
40 // blocking indefinitely on a single primitive will meet this constraint with
41 // margin (i.e. more than twice per overflow).
42 #ifndef PW_CHRONO_THREADX_CFG_MAX_TIMEOUT
43 #define PW_CHRONO_THREADX_CFG_MAX_TIMEOUT ((TX_WAIT_FOREVER - 1) / 3)
44 #endif  // PW_CHRONO_THREADX_CFG_MAX_TIMEOUT
45 
46 static_assert((PW_CHRONO_THREADX_CFG_MAX_TIMEOUT > 0) &&
47                   (PW_CHRONO_THREADX_CFG_MAX_TIMEOUT <= (TX_WAIT_FOREVER - 1)),
48               "the timeout must be greater than 0 and less than the sentinel");
49