1 // Copyright 2021 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 15 // Configuration macros for the transfer module. 16 #pragma once 17 18 #include <cinttypes> 19 #include <limits> 20 21 #include "pw_chrono/system_clock.h" 22 23 // The default maximum number of times a transfer should retry sending a chunk 24 // when no response is received. This can later be configured per-transfer. 25 #ifndef PW_TRANSFER_DEFAULT_MAX_RETRIES 26 #define PW_TRANSFER_DEFAULT_MAX_RETRIES 3 27 #endif // PW_TRANSFER_DEFAULT_MAX_RETRIES 28 29 static_assert(PW_TRANSFER_DEFAULT_MAX_RETRIES > 0 && 30 PW_TRANSFER_DEFAULT_MAX_RETRIES <= 31 std::numeric_limits<uint8_t>::max()); 32 33 // The default amount of time, in milliseconds, to wait for a chunk to arrive 34 // before retrying. This can later be configured per-transfer. 35 #ifndef PW_TRANSFER_DEFAULT_TIMEOUT_MS 36 #define PW_TRANSFER_DEFAULT_TIMEOUT_MS 2000 37 #endif // PW_TRANSFER_DEFAULT_TIMEOUT_MS 38 39 static_assert(PW_TRANSFER_DEFAULT_TIMEOUT_MS > 0); 40 41 // The fractional position within a window at which a receive transfer should 42 // extend its window size to minimize the amount of time the transmitter 43 // spends blocked. 44 // 45 // For example, a divisor of 2 will extend the window when half of the 46 // requested data has been received, a divisor of three will extend at a third 47 // of the window, and so on. 48 #ifndef PW_TRANSFER_DEFAULT_EXTEND_WINDOW_DIVISOR 49 #define PW_TRANSFER_DEFAULT_EXTEND_WINDOW_DIVISOR 2 50 #endif // PW_TRANSFER_DEFAULT_EXTEND_WINDOW_DIVISOR 51 52 static_assert(PW_TRANSFER_DEFAULT_EXTEND_WINDOW_DIVISOR > 1); 53 54 namespace pw::transfer::cfg { 55 56 inline constexpr uint8_t kDefaultMaxRetries = PW_TRANSFER_DEFAULT_MAX_RETRIES; 57 inline constexpr chrono::SystemClock::duration kDefaultChunkTimeout = 58 std::chrono::milliseconds(PW_TRANSFER_DEFAULT_TIMEOUT_MS); 59 inline constexpr uint32_t kDefaultExtendWindowDivisor = 60 PW_TRANSFER_DEFAULT_EXTEND_WINDOW_DIVISOR; 61 62 } // namespace pw::transfer::cfg 63