blob: afe475515ebf3c4d67e5178da9b337878759e844 [file] [log] [blame]
// Copyright 2021 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/*
* Retry device handler.
*/
#include "hps/hal/retry.h"
#include <iostream>
#include <base/threading/thread.h>
namespace hps {
bool RetryDev::ReadDevice(uint8_t cmd, uint8_t* data, size_t len) {
for (int i = 0; i < this->retries_; i++) {
if (device_->Read(cmd, data, len)) {
// Success!
return true;
}
base::PlatformThread::Sleep(this->delay_);
}
return false;
}
bool RetryDev::WriteDevice(uint8_t cmd, const uint8_t* data, size_t len) {
for (int i = 0; i < this->retries_; i++) {
if (device_->Write(cmd, data, len)) {
// Success!
return true;
}
base::PlatformThread::Sleep(this->delay_);
}
return false;
}
} // namespace hps