Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Commit

Permalink
Feature/tune uart params (#264)
Browse files Browse the repository at this point in the history
* Add tunable parameters for Windows
* Fix nrfutil in pipeline (Linux)
  • Loading branch information
kenr committed Mar 11, 2021
1 parent b630b06 commit 749578b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .azure-pipelines/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ jobs:
sudo apt-get update
sudo apt-get install ninja-build gcc-8 g++-8 clang-9 clang-format-9 clang-tidy-9 python3-pycurl python3-pip python3-certifi python3-setuptools libusb-1.0-0-dev libudev-dev
/usr/bin/python3 -m pip install -U pip
/usr/bin/python3 -m pip install nrfutil
/usr/bin/python3 -m pip install --ignore-installed nrfutil
chmod a+x $(System.ArtifactsDirectory)/nrftc
$(System.ArtifactsDirectory)/nrftc install arm-toolchain -a $(Agent.BuildDirectory)/toolchain -i armgcc:${{ parameters.ARMGCC_VERSION }} -e $(Agent.BuildDirectory)/tcenv.sh
cat $(Agent.BuildDirectory)/tcenv.sh
Expand Down
25 changes: 25 additions & 0 deletions src/common/transport/uart_transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ constexpr auto DELAY_BEFORE_READ_WRITE = std::chrono::milliseconds(200);
// if opening a UART port right after close.
constexpr auto DELAY_BEFORE_OPEN = std::chrono::milliseconds(200);

#if defined(_WIN32)
// Wait for 20ms for data before returning from a read
constexpr auto readTotalTimeoutConstant = 20;
#endif

struct UartTransport::impl : Transport
{
std::array<uint8_t, UartTransportBufferSize> readBuffer;
Expand Down Expand Up @@ -283,6 +288,26 @@ struct UartTransport::impl : Transport
}
#endif

#if defined(_WIN32)
::COMMTIMEOUTS timeouts;

// See
// https://docs.microsoft.com/en-us/windows/win32/api/winbase/ns-winbase-commtimeouts
// for documentation of these parameters
timeouts.ReadIntervalTimeout = MAXDWORD;
timeouts.ReadTotalTimeoutMultiplier = MAXDWORD;
timeouts.ReadTotalTimeoutConstant = readTotalTimeoutConstant;

timeouts.WriteTotalTimeoutMultiplier = 0;
timeouts.WriteTotalTimeoutConstant = 0;

if (!::SetCommTimeouts(serialPort->native_handle(), &timeouts))
{
const auto error = std::error_code(errno, std::system_category());
throw std::system_error(error, "Failed to set communication timeout parameters");
}
#endif

// Wait a bit before making the device available since there are problems
// if data is sent right after open.
//
Expand Down

0 comments on commit 749578b

Please sign in to comment.