mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-09-28 21:17:33 +00:00
Fix indentation. Update doxygen comments
This commit is contained in:
@@ -7,23 +7,23 @@
|
||||
|
||||
namespace sta
|
||||
{
|
||||
STA_WEAK
|
||||
void assert_failed(const char * expr, const char * file, uint32_t line)
|
||||
{
|
||||
// printf("%s:%d: Assertion failed: %s", file, line, expr)
|
||||
STA_DEBUG_PRINT(file);
|
||||
STA_DEBUG_PRINT(':');
|
||||
STA_DEBUG_PRINT(line);
|
||||
STA_DEBUG_PRINT(": Assertion failed: ");
|
||||
STA_DEBUG_PRINTLN(expr);
|
||||
}
|
||||
STA_WEAK
|
||||
void assert_failed(const char * expr, const char * file, uint32_t line)
|
||||
{
|
||||
// printf("%s:%d: Assertion failed: %s", file, line, expr)
|
||||
STA_DEBUG_PRINT(file);
|
||||
STA_DEBUG_PRINT(':');
|
||||
STA_DEBUG_PRINT(line);
|
||||
STA_DEBUG_PRINT(": Assertion failed: ");
|
||||
STA_DEBUG_PRINTLN(expr);
|
||||
}
|
||||
|
||||
STA_WEAK
|
||||
void assert_halt()
|
||||
{
|
||||
STA_BKPT();
|
||||
while (true);
|
||||
}
|
||||
STA_WEAK
|
||||
void assert_halt()
|
||||
{
|
||||
STA_BKPT();
|
||||
while (true);
|
||||
}
|
||||
} // namespace sta
|
||||
|
||||
|
||||
|
@@ -4,19 +4,19 @@
|
||||
|
||||
namespace sta
|
||||
{
|
||||
AtomicMutex::AtomicMutex()
|
||||
: lock_{ATOMIC_FLAG_INIT}
|
||||
{}
|
||||
AtomicMutex::AtomicMutex()
|
||||
: lock_{ATOMIC_FLAG_INIT}
|
||||
{}
|
||||
|
||||
void AtomicMutex::acquire()
|
||||
{
|
||||
while (lock_.test_and_set());
|
||||
}
|
||||
void AtomicMutex::acquire()
|
||||
{
|
||||
while (lock_.test_and_set());
|
||||
}
|
||||
|
||||
void AtomicMutex::release()
|
||||
{
|
||||
lock_.clear();
|
||||
}
|
||||
void AtomicMutex::release()
|
||||
{
|
||||
lock_.clear();
|
||||
}
|
||||
} // namespace sta
|
||||
|
||||
|
||||
|
@@ -4,29 +4,29 @@
|
||||
|
||||
namespace sta
|
||||
{
|
||||
AtomicSignal::AtomicSignal()
|
||||
: signal_{false}
|
||||
{}
|
||||
AtomicSignal::AtomicSignal()
|
||||
: signal_{false}
|
||||
{}
|
||||
|
||||
void AtomicSignal::notify()
|
||||
{
|
||||
signal_.store(true);
|
||||
}
|
||||
void AtomicSignal::notify()
|
||||
{
|
||||
signal_.store(true);
|
||||
}
|
||||
|
||||
bool AtomicSignal::peek()
|
||||
{
|
||||
return signal_.load();
|
||||
}
|
||||
bool AtomicSignal::peek()
|
||||
{
|
||||
return signal_.load();
|
||||
}
|
||||
|
||||
bool AtomicSignal::test()
|
||||
{
|
||||
return signal_.exchange(false);
|
||||
}
|
||||
bool AtomicSignal::test()
|
||||
{
|
||||
return signal_.exchange(false);
|
||||
}
|
||||
|
||||
void AtomicSignal::wait()
|
||||
{
|
||||
while (!signal_.exchange(false));
|
||||
}
|
||||
void AtomicSignal::wait()
|
||||
{
|
||||
while (!signal_.exchange(false));
|
||||
}
|
||||
} // namespace sta
|
||||
|
||||
|
||||
|
@@ -3,24 +3,24 @@
|
||||
|
||||
namespace sta
|
||||
{
|
||||
bool operator ==(const CanId & lhs, const CanId & rhs)
|
||||
{
|
||||
return (lhs.sid == rhs.sid && lhs.eid == rhs.eid);
|
||||
}
|
||||
bool operator ==(const CanId & lhs, const CanId & rhs)
|
||||
{
|
||||
return (lhs.sid == rhs.sid && lhs.eid == rhs.eid);
|
||||
}
|
||||
|
||||
bool operator !=(const CanId & lhs, const CanId & rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
bool operator !=(const CanId & lhs, const CanId & rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
|
||||
bool operator ==(const CanFrameId & lhs, const CanFrameId & rhs)
|
||||
{
|
||||
return (lhs.format == rhs.format && lhs.sid == rhs.sid && lhs.eid == rhs.eid);
|
||||
}
|
||||
bool operator ==(const CanFrameId & lhs, const CanFrameId & rhs)
|
||||
{
|
||||
return (lhs.format == rhs.format && lhs.sid == rhs.sid && lhs.eid == rhs.eid);
|
||||
}
|
||||
|
||||
bool operator !=(const CanFrameId & lhs, const CanFrameId & rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
bool operator !=(const CanFrameId & lhs, const CanFrameId & rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
} // namespace sta
|
||||
|
132
src/can/iter.cpp
132
src/can/iter.cpp
@@ -5,91 +5,91 @@
|
||||
|
||||
namespace sta
|
||||
{
|
||||
CanPendingRxFifos::const_iterator::const_iterator(uint32_t rxFlags, uint8_t idx, uint8_t endIdx)
|
||||
: rxFlags_{rxFlags}, idx_{idx}, endIdx_{endIdx}
|
||||
{}
|
||||
CanPendingRxFifos::const_iterator::const_iterator(uint32_t rxFlags, uint8_t idx, uint8_t endIdx)
|
||||
: rxFlags_{rxFlags}, idx_{idx}, endIdx_{endIdx}
|
||||
{}
|
||||
|
||||
CanPendingRxFifos::const_iterator::const_iterator(const const_iterator & iter)
|
||||
: rxFlags_{iter.rxFlags_}, idx_{iter.idx_}, endIdx_{iter.endIdx_}
|
||||
{}
|
||||
CanPendingRxFifos::const_iterator::const_iterator(const const_iterator & iter)
|
||||
: rxFlags_{iter.rxFlags_}, idx_{iter.idx_}, endIdx_{iter.endIdx_}
|
||||
{}
|
||||
|
||||
|
||||
CanPendingRxFifos::const_iterator & CanPendingRxFifos::const_iterator::operator=(const const_iterator & iter)
|
||||
{
|
||||
rxFlags_ = iter.rxFlags_;
|
||||
idx_ = iter.idx_;
|
||||
endIdx_ = iter.endIdx_;
|
||||
CanPendingRxFifos::const_iterator & CanPendingRxFifos::const_iterator::operator=(const const_iterator & iter)
|
||||
{
|
||||
rxFlags_ = iter.rxFlags_;
|
||||
idx_ = iter.idx_;
|
||||
endIdx_ = iter.endIdx_;
|
||||
|
||||
return *this;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
bool CanPendingRxFifos::const_iterator::operator==(const const_iterator & iter) const
|
||||
{
|
||||
return (rxFlags_ == iter.rxFlags_) && (idx_ == iter.idx_) && (endIdx_ == iter.endIdx_);
|
||||
}
|
||||
bool CanPendingRxFifos::const_iterator::operator==(const const_iterator & iter) const
|
||||
{
|
||||
return (rxFlags_ == iter.rxFlags_) && (idx_ == iter.idx_) && (endIdx_ == iter.endIdx_);
|
||||
}
|
||||
|
||||
bool CanPendingRxFifos::const_iterator::operator!=(const const_iterator & iter) const
|
||||
{
|
||||
return !(*this == iter);
|
||||
}
|
||||
bool CanPendingRxFifos::const_iterator::operator!=(const const_iterator & iter) const
|
||||
{
|
||||
return !(*this == iter);
|
||||
}
|
||||
|
||||
|
||||
CanPendingRxFifos::const_iterator & CanPendingRxFifos::const_iterator::operator++()
|
||||
{
|
||||
while (idx_ < endIdx_)
|
||||
{
|
||||
++idx_;
|
||||
if (isRxPending())
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
CanPendingRxFifos::const_iterator & CanPendingRxFifos::const_iterator::operator++()
|
||||
{
|
||||
while (idx_ < endIdx_)
|
||||
{
|
||||
++idx_;
|
||||
if (isRxPending())
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
CanPendingRxFifos::const_iterator CanPendingRxFifos::const_iterator::operator++(int)
|
||||
{
|
||||
uint8_t oldIdx = idx_;
|
||||
CanPendingRxFifos::const_iterator CanPendingRxFifos::const_iterator::operator++(int)
|
||||
{
|
||||
uint8_t oldIdx = idx_;
|
||||
|
||||
while (idx_ < endIdx_)
|
||||
{
|
||||
++idx_;
|
||||
if (isRxPending())
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (idx_ < endIdx_)
|
||||
{
|
||||
++idx_;
|
||||
if (isRxPending())
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return const_iterator(rxFlags_, oldIdx, endIdx_);
|
||||
}
|
||||
return const_iterator(rxFlags_, oldIdx, endIdx_);
|
||||
}
|
||||
|
||||
CanPendingRxFifos::const_iterator::reference CanPendingRxFifos::const_iterator::operator*() const
|
||||
{
|
||||
STA_ASSERT_MSG(idx_ != endIdx_, "Dereferencing out-of-bounds iterator");
|
||||
CanPendingRxFifos::const_iterator::reference CanPendingRxFifos::const_iterator::operator*() const
|
||||
{
|
||||
STA_ASSERT_MSG(idx_ != endIdx_, "Dereferencing out-of-bounds iterator");
|
||||
|
||||
return idx_;
|
||||
}
|
||||
return idx_;
|
||||
}
|
||||
|
||||
bool CanPendingRxFifos::const_iterator::isRxPending() const
|
||||
{
|
||||
return ( (rxFlags_ >> idx_) & 0x1 );
|
||||
}
|
||||
bool CanPendingRxFifos::const_iterator::isRxPending() const
|
||||
{
|
||||
return ( (rxFlags_ >> idx_) & 0x1 );
|
||||
}
|
||||
|
||||
|
||||
|
||||
CanPendingRxFifos::CanPendingRxFifos(uint32_t rxFlags, uint8_t numFifos)
|
||||
: rxFlags_{rxFlags}, numFifos_{numFifos}
|
||||
{}
|
||||
CanPendingRxFifos::CanPendingRxFifos(uint32_t rxFlags, uint8_t numFifos)
|
||||
: rxFlags_{rxFlags}, numFifos_{numFifos}
|
||||
{}
|
||||
|
||||
CanPendingRxFifos::const_iterator CanPendingRxFifos::begin() const
|
||||
{
|
||||
return const_iterator(rxFlags_, 0, numFifos_);
|
||||
}
|
||||
CanPendingRxFifos::const_iterator CanPendingRxFifos::begin() const
|
||||
{
|
||||
return const_iterator(rxFlags_, 0, numFifos_);
|
||||
}
|
||||
|
||||
CanPendingRxFifos::const_iterator CanPendingRxFifos::end() const
|
||||
{
|
||||
return const_iterator(rxFlags_, numFifos_, numFifos_);
|
||||
}
|
||||
CanPendingRxFifos::const_iterator CanPendingRxFifos::end() const
|
||||
{
|
||||
return const_iterator(rxFlags_, numFifos_, numFifos_);
|
||||
}
|
||||
} // namespace sta
|
||||
|
@@ -16,14 +16,14 @@ using PlatformUART = sta::STM32UART;
|
||||
|
||||
namespace
|
||||
{
|
||||
// Create platform specific serial interface
|
||||
PlatformUART platformDebugSerial(&STA_DEBUG_SERIAL_UART);
|
||||
// Create platform specific serial interface
|
||||
PlatformUART platformDebugSerial(&STA_DEBUG_SERIAL_UART);
|
||||
}
|
||||
|
||||
namespace sta
|
||||
{
|
||||
// Create debug serial object using platform specific serial interface
|
||||
PrintableUART DebugSerial(&platformDebugSerial);
|
||||
// Create debug serial object using platform specific serial interface
|
||||
PrintableUART DebugSerial(&platformDebugSerial);
|
||||
} // namespace sta
|
||||
|
||||
|
||||
|
@@ -3,18 +3,18 @@
|
||||
|
||||
namespace sta
|
||||
{
|
||||
/**
|
||||
* @brief Dummy mutex implementation with no access control.
|
||||
*/
|
||||
class DummyMutex : public Mutex
|
||||
{
|
||||
public:
|
||||
void acquire() override {}
|
||||
void release() override {}
|
||||
};
|
||||
/**
|
||||
* @brief Dummy mutex implementation with no access control.
|
||||
*/
|
||||
class DummyMutex : public Mutex
|
||||
{
|
||||
public:
|
||||
void acquire() override {}
|
||||
void release() override {}
|
||||
};
|
||||
|
||||
static DummyMutex dummyMutex;
|
||||
static DummyMutex dummyMutex;
|
||||
|
||||
|
||||
Mutex * Mutex::ALWAYS_FREE = &dummyMutex;
|
||||
Mutex * Mutex::ALWAYS_FREE = &dummyMutex;
|
||||
} // namespace sta
|
||||
|
@@ -10,202 +10,202 @@
|
||||
|
||||
namespace sta
|
||||
{
|
||||
PrintableUART::PrintableUART(UART * intf)
|
||||
: intf_{intf}
|
||||
{
|
||||
STA_ASSERT(intf != nullptr);
|
||||
}
|
||||
PrintableUART::PrintableUART(UART * intf)
|
||||
: intf_{intf}
|
||||
{
|
||||
STA_ASSERT(intf != nullptr);
|
||||
}
|
||||
|
||||
|
||||
void PrintableUART::print(char c)
|
||||
{
|
||||
print(&c, 1);
|
||||
}
|
||||
void PrintableUART::print(char c)
|
||||
{
|
||||
print(&c, 1);
|
||||
}
|
||||
|
||||
void PrintableUART::print(bool b)
|
||||
{
|
||||
print(b ? "true" : "false");
|
||||
}
|
||||
void PrintableUART::print(bool b)
|
||||
{
|
||||
print(b ? "true" : "false");
|
||||
}
|
||||
|
||||
void PrintableUART::print(double d)
|
||||
{
|
||||
char buffer[64];
|
||||
snprintf(buffer, sizeof(buffer), "%f", d);
|
||||
print(buffer);
|
||||
}
|
||||
void PrintableUART::print(double d)
|
||||
{
|
||||
char buffer[64];
|
||||
snprintf(buffer, sizeof(buffer), "%f", d);
|
||||
print(buffer);
|
||||
}
|
||||
|
||||
void PrintableUART::print(uint8_t num, IntegerBase base /* = IntegerBase::DEC */)
|
||||
{
|
||||
printBase(num, base, "%" PRIu8, sizeof(num));
|
||||
}
|
||||
void PrintableUART::print(uint8_t num, IntegerBase base /* = IntegerBase::DEC */)
|
||||
{
|
||||
printBase(num, base, "%" PRIu8, sizeof(num));
|
||||
}
|
||||
|
||||
void PrintableUART::print(uint16_t num, IntegerBase base /* = IntegerBase::DEC */)
|
||||
{
|
||||
printBase(num, base, "%" PRIu16, sizeof(num));
|
||||
}
|
||||
void PrintableUART::print(uint16_t num, IntegerBase base /* = IntegerBase::DEC */)
|
||||
{
|
||||
printBase(num, base, "%" PRIu16, sizeof(num));
|
||||
}
|
||||
|
||||
void PrintableUART::print(uint32_t num, IntegerBase base /* = IntegerBase::DEC */)
|
||||
{
|
||||
printBase(num, base, "%" PRIu32, sizeof(num));
|
||||
}
|
||||
void PrintableUART::print(uint32_t num, IntegerBase base /* = IntegerBase::DEC */)
|
||||
{
|
||||
printBase(num, base, "%" PRIu32, sizeof(num));
|
||||
}
|
||||
|
||||
void PrintableUART::print(size_t num, IntegerBase base /* = IntegerBase::DEC */)
|
||||
{
|
||||
printBase(num, base, "%z", sizeof(num));
|
||||
}
|
||||
void PrintableUART::print(size_t num, IntegerBase base /* = IntegerBase::DEC */)
|
||||
{
|
||||
printBase(num, base, "%z", sizeof(num));
|
||||
}
|
||||
|
||||
void PrintableUART::print(const char * str)
|
||||
{
|
||||
print(str, strlen(str));
|
||||
}
|
||||
void PrintableUART::print(const char * str)
|
||||
{
|
||||
print(str, strlen(str));
|
||||
}
|
||||
|
||||
void PrintableUART::print(const char * str, size_t length)
|
||||
{
|
||||
intf_->write(reinterpret_cast<const uint8_t *>(str), length);
|
||||
}
|
||||
void PrintableUART::print(const char * str, size_t length)
|
||||
{
|
||||
intf_->write(reinterpret_cast<const uint8_t *>(str), length);
|
||||
}
|
||||
|
||||
|
||||
void PrintableUART::println()
|
||||
{
|
||||
print("\r\n", 2);
|
||||
}
|
||||
void PrintableUART::println()
|
||||
{
|
||||
print("\r\n", 2);
|
||||
}
|
||||
|
||||
void PrintableUART::println(char c)
|
||||
{
|
||||
print(&c, 1);
|
||||
println();
|
||||
}
|
||||
void PrintableUART::println(char c)
|
||||
{
|
||||
print(&c, 1);
|
||||
println();
|
||||
}
|
||||
|
||||
void PrintableUART::println(bool b)
|
||||
{
|
||||
print(b);
|
||||
println();
|
||||
}
|
||||
void PrintableUART::println(bool b)
|
||||
{
|
||||
print(b);
|
||||
println();
|
||||
}
|
||||
|
||||
void PrintableUART::println(double d)
|
||||
{
|
||||
print(d);
|
||||
println();
|
||||
}
|
||||
void PrintableUART::println(double d)
|
||||
{
|
||||
print(d);
|
||||
println();
|
||||
}
|
||||
|
||||
void PrintableUART::println(uint8_t num, IntegerBase base /* = IntegerBase::DEC */)
|
||||
{
|
||||
print(num, base);
|
||||
println();
|
||||
}
|
||||
void PrintableUART::println(uint8_t num, IntegerBase base /* = IntegerBase::DEC */)
|
||||
{
|
||||
print(num, base);
|
||||
println();
|
||||
}
|
||||
|
||||
void PrintableUART::println(uint16_t num, IntegerBase base /* = IntegerBase::DEC */)
|
||||
{
|
||||
print(num, base);
|
||||
println();
|
||||
}
|
||||
void PrintableUART::println(uint16_t num, IntegerBase base /* = IntegerBase::DEC */)
|
||||
{
|
||||
print(num, base);
|
||||
println();
|
||||
}
|
||||
|
||||
void PrintableUART::println(uint32_t num, IntegerBase base /* = IntegerBase::DEC */)
|
||||
{
|
||||
print(num, base);
|
||||
println();
|
||||
}
|
||||
void PrintableUART::println(uint32_t num, IntegerBase base /* = IntegerBase::DEC */)
|
||||
{
|
||||
print(num, base);
|
||||
println();
|
||||
}
|
||||
|
||||
void PrintableUART::println(size_t num, IntegerBase base /* = IntegerBase::DEC */)
|
||||
{
|
||||
print(num, base);
|
||||
println();
|
||||
}
|
||||
void PrintableUART::println(size_t num, IntegerBase base /* = IntegerBase::DEC */)
|
||||
{
|
||||
print(num, base);
|
||||
println();
|
||||
}
|
||||
|
||||
void PrintableUART::println(const char * str)
|
||||
{
|
||||
println(str, strlen(str));
|
||||
}
|
||||
void PrintableUART::println(const char * str)
|
||||
{
|
||||
println(str, strlen(str));
|
||||
}
|
||||
|
||||
void PrintableUART::println(const char * str, size_t length)
|
||||
{
|
||||
print(str, length);
|
||||
println();
|
||||
}
|
||||
void PrintableUART::println(const char * str, size_t length)
|
||||
{
|
||||
print(str, length);
|
||||
println();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void PrintableUART::printBase(uintmax_t num, IntegerBase base, const char * fmt, size_t size)
|
||||
{
|
||||
switch (base)
|
||||
{
|
||||
case IntegerBase::DEC:
|
||||
printDec(num, fmt);
|
||||
break;
|
||||
void PrintableUART::printBase(uintmax_t num, IntegerBase base, const char * fmt, size_t size)
|
||||
{
|
||||
switch (base)
|
||||
{
|
||||
case IntegerBase::DEC:
|
||||
printDec(num, fmt);
|
||||
break;
|
||||
|
||||
case IntegerBase::BIN:
|
||||
// Digits in base 2 = size in bytes * 8
|
||||
printBin(num, size * 8);
|
||||
break;
|
||||
case IntegerBase::BIN:
|
||||
// Digits in base 2 = size in bytes * 8
|
||||
printBin(num, size * 8);
|
||||
break;
|
||||
|
||||
case IntegerBase::HEX:
|
||||
// Digits in base 16 = size in bytes * 2
|
||||
printHex(num, size * 2);
|
||||
break;
|
||||
case IntegerBase::HEX:
|
||||
// Digits in base 16 = size in bytes * 2
|
||||
printHex(num, size * 2);
|
||||
break;
|
||||
|
||||
default:
|
||||
print("<invalid_base>");
|
||||
}
|
||||
}
|
||||
default:
|
||||
print("<invalid_base>");
|
||||
}
|
||||
}
|
||||
|
||||
void PrintableUART::printDec(uintmax_t num, const char * fmt)
|
||||
{
|
||||
char buffer[64];
|
||||
snprintf(buffer, sizeof(buffer), fmt, static_cast<uint32_t>(num));
|
||||
print(buffer);
|
||||
}
|
||||
void PrintableUART::printDec(uintmax_t num, const char * fmt)
|
||||
{
|
||||
char buffer[64];
|
||||
snprintf(buffer, sizeof(buffer), fmt, static_cast<uint32_t>(num));
|
||||
print(buffer);
|
||||
}
|
||||
|
||||
void PrintableUART::printBin(uintmax_t value, size_t digits)
|
||||
{
|
||||
// Need 8 digits for every byte
|
||||
char buffer[sizeof(value) * 8];
|
||||
void PrintableUART::printBin(uintmax_t value, size_t digits)
|
||||
{
|
||||
// Need 8 digits for every byte
|
||||
char buffer[sizeof(value) * 8];
|
||||
|
||||
// Check bounds
|
||||
if (digits > sizeof(buffer))
|
||||
{
|
||||
print("<bin_value_too_big>");
|
||||
return;
|
||||
}
|
||||
// Nothing to do
|
||||
if (digits == 0)
|
||||
return;
|
||||
// Check bounds
|
||||
if (digits > sizeof(buffer))
|
||||
{
|
||||
print("<bin_value_too_big>");
|
||||
return;
|
||||
}
|
||||
// Nothing to do
|
||||
if (digits == 0)
|
||||
return;
|
||||
|
||||
for (size_t i = 0; i < digits; ++i)
|
||||
{
|
||||
// Convert bit to '0' or '1'
|
||||
// First digit in buffer is MSB in value, so shift from high to low
|
||||
buffer[i] = '0' + ((value >> (digits - 1 - i)) & 0x1);
|
||||
}
|
||||
for (size_t i = 0; i < digits; ++i)
|
||||
{
|
||||
// Convert bit to '0' or '1'
|
||||
// First digit in buffer is MSB in value, so shift from high to low
|
||||
buffer[i] = '0' + ((value >> (digits - 1 - i)) & 0x1);
|
||||
}
|
||||
|
||||
print(buffer, digits);
|
||||
}
|
||||
print(buffer, digits);
|
||||
}
|
||||
|
||||
void PrintableUART::printHex(uintmax_t value, size_t digits)
|
||||
{
|
||||
// Need 2 digits for every byte
|
||||
char buffer[sizeof(value) * 2];
|
||||
void PrintableUART::printHex(uintmax_t value, size_t digits)
|
||||
{
|
||||
// Need 2 digits for every byte
|
||||
char buffer[sizeof(value) * 2];
|
||||
|
||||
// Check bounds
|
||||
if (digits > sizeof(buffer))
|
||||
{
|
||||
print("<hex_value_too_big>");
|
||||
return;
|
||||
}
|
||||
// Nothing to do
|
||||
if (digits == 0)
|
||||
return;
|
||||
// Check bounds
|
||||
if (digits > sizeof(buffer))
|
||||
{
|
||||
print("<hex_value_too_big>");
|
||||
return;
|
||||
}
|
||||
// Nothing to do
|
||||
if (digits == 0)
|
||||
return;
|
||||
|
||||
for (size_t i = 0; i < digits; ++i)
|
||||
{
|
||||
// Convert 4 bits to hex
|
||||
// First digit in buffer is 4 MSBs in value, so shift from high to low
|
||||
uint8_t hex = ((value >> ((digits - 1 - i) * 4)) & 0xF);
|
||||
if (hex > 9)
|
||||
buffer[i] = 'A' + (hex - 10);
|
||||
else
|
||||
buffer[i] = '0' + hex;
|
||||
}
|
||||
for (size_t i = 0; i < digits; ++i)
|
||||
{
|
||||
// Convert 4 bits to hex
|
||||
// First digit in buffer is 4 MSBs in value, so shift from high to low
|
||||
uint8_t hex = ((value >> ((digits - 1 - i) * 4)) & 0xF);
|
||||
if (hex > 9)
|
||||
buffer[i] = 'A' + (hex - 10);
|
||||
else
|
||||
buffer[i] = '0' + hex;
|
||||
}
|
||||
|
||||
print(buffer, digits);
|
||||
}
|
||||
print(buffer, digits);
|
||||
}
|
||||
} // namespace sta
|
||||
|
@@ -7,167 +7,167 @@
|
||||
|
||||
namespace sta
|
||||
{
|
||||
STM32CanController::STM32CanController(CAN_HandleTypeDef * handle)
|
||||
: handle_{handle}
|
||||
{
|
||||
initFilters();
|
||||
}
|
||||
STM32CanController::STM32CanController(CAN_HandleTypeDef * handle)
|
||||
: handle_{handle}
|
||||
{
|
||||
initFilters();
|
||||
}
|
||||
|
||||
|
||||
void STM32CanController::enableRxInterrupts()
|
||||
{
|
||||
HAL_CAN_ActivateNotification(handle_,
|
||||
CAN_IT_RX_FIFO0_MSG_PENDING | CAN_IT_RX_FIFO1_MSG_PENDING
|
||||
);
|
||||
}
|
||||
void STM32CanController::enableRxInterrupts()
|
||||
{
|
||||
HAL_CAN_ActivateNotification(handle_,
|
||||
CAN_IT_RX_FIFO0_MSG_PENDING | CAN_IT_RX_FIFO1_MSG_PENDING
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void STM32CanController::start()
|
||||
{
|
||||
HAL_CAN_Start(handle_);
|
||||
}
|
||||
void STM32CanController::start()
|
||||
{
|
||||
HAL_CAN_Start(handle_);
|
||||
}
|
||||
|
||||
void STM32CanController::stop()
|
||||
{
|
||||
HAL_CAN_Stop(handle_);
|
||||
}
|
||||
void STM32CanController::stop()
|
||||
{
|
||||
HAL_CAN_Stop(handle_);
|
||||
}
|
||||
|
||||
|
||||
bool STM32CanController::sendFrame(const CanTxHeader & header, const uint8_t * payload)
|
||||
{
|
||||
STA_ASSERT_MSG(header.payloadLength <= 8, "CAN 2.0B payload size exceeded");
|
||||
bool STM32CanController::sendFrame(const CanTxHeader & header, const uint8_t * payload)
|
||||
{
|
||||
STA_ASSERT_MSG(header.payloadLength <= 8, "CAN 2.0B payload size exceeded");
|
||||
|
||||
CAN_TxHeaderTypeDef halHeader;
|
||||
CAN_TxHeaderTypeDef halHeader;
|
||||
|
||||
if (header.id.format == CanIdFormat::STD)
|
||||
{
|
||||
halHeader.StdId = header.id.sid & 0x7FF;
|
||||
halHeader.IDE = CAN_ID_STD;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Combine SID and EID
|
||||
halHeader.ExtId = ((header.id.sid & 0x7FF) << 18) | (header.id.eid & 0x3FFFF);
|
||||
halHeader.IDE = CAN_ID_EXT;
|
||||
}
|
||||
if (header.id.format == CanIdFormat::STD)
|
||||
{
|
||||
halHeader.StdId = header.id.sid & 0x7FF;
|
||||
halHeader.IDE = CAN_ID_STD;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Combine SID and EID
|
||||
halHeader.ExtId = ((header.id.sid & 0x7FF) << 18) | (header.id.eid & 0x3FFFF);
|
||||
halHeader.IDE = CAN_ID_EXT;
|
||||
}
|
||||
|
||||
halHeader.DLC = header.payloadLength;
|
||||
halHeader.DLC = header.payloadLength;
|
||||
|
||||
uint32_t mailbox; // Don't care
|
||||
return (HAL_OK == HAL_CAN_AddTxMessage(handle_, &halHeader, const_cast<uint8_t *>(payload), &mailbox));
|
||||
}
|
||||
uint32_t mailbox; // Don't care
|
||||
return (HAL_OK == HAL_CAN_AddTxMessage(handle_, &halHeader, const_cast<uint8_t *>(payload), &mailbox));
|
||||
}
|
||||
|
||||
bool STM32CanController::receiveFrame(uint8_t fifo, CanRxHeader * header, uint8_t * payload)
|
||||
{
|
||||
// Check if message is available
|
||||
if (HAL_CAN_GetRxFifoFillLevel(handle_, fifo) == 0)
|
||||
return false;
|
||||
bool STM32CanController::receiveFrame(uint8_t fifo, CanRxHeader * header, uint8_t * payload)
|
||||
{
|
||||
// Check if message is available
|
||||
if (HAL_CAN_GetRxFifoFillLevel(handle_, fifo) == 0)
|
||||
return false;
|
||||
|
||||
// Retrieve message
|
||||
CAN_RxHeaderTypeDef halHeader;
|
||||
HAL_CAN_GetRxMessage(handle_, fifo, &halHeader, payload);
|
||||
// Retrieve message
|
||||
CAN_RxHeaderTypeDef halHeader;
|
||||
HAL_CAN_GetRxMessage(handle_, fifo, &halHeader, payload);
|
||||
|
||||
if (halHeader.IDE == CAN_ID_STD)
|
||||
{
|
||||
header->id.format = CanIdFormat::STD;
|
||||
header->id.sid = halHeader.StdId;
|
||||
header->id.eid = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
header->id.format = CanIdFormat::EXT;
|
||||
// Separate SID and EID
|
||||
header->id.sid = (halHeader.ExtId >> 18);
|
||||
header->id.eid = halHeader.ExtId & 0x3FFFF;
|
||||
}
|
||||
// No conversion required for CAN 2B standard
|
||||
header->payloadLength = halHeader.DLC;
|
||||
header->timestamp = halHeader.Timestamp;
|
||||
header->filter = halHeader.FilterMatchIndex;
|
||||
if (halHeader.IDE == CAN_ID_STD)
|
||||
{
|
||||
header->id.format = CanIdFormat::STD;
|
||||
header->id.sid = halHeader.StdId;
|
||||
header->id.eid = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
header->id.format = CanIdFormat::EXT;
|
||||
// Separate SID and EID
|
||||
header->id.sid = (halHeader.ExtId >> 18);
|
||||
header->id.eid = halHeader.ExtId & 0x3FFFF;
|
||||
}
|
||||
// No conversion required for CAN 2B standard
|
||||
header->payloadLength = halHeader.DLC;
|
||||
header->timestamp = halHeader.Timestamp;
|
||||
header->filter = halHeader.FilterMatchIndex;
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32_t STM32CanController::getRxFifoFlags()
|
||||
{
|
||||
//
|
||||
return (HAL_CAN_GetRxFifoFillLevel(handle_, CAN_RX_FIFO0) != 0)
|
||||
| (HAL_CAN_GetRxFifoFillLevel(handle_, CAN_RX_FIFO1) != 0) << 1;
|
||||
}
|
||||
uint32_t STM32CanController::getRxFifoFlags()
|
||||
{
|
||||
//
|
||||
return (HAL_CAN_GetRxFifoFillLevel(handle_, CAN_RX_FIFO0) != 0)
|
||||
| (HAL_CAN_GetRxFifoFillLevel(handle_, CAN_RX_FIFO1) != 0) << 1;
|
||||
}
|
||||
|
||||
|
||||
void STM32CanController::configureFilter(uint8_t idx, const CanFilter & filter, bool active /* = false */)
|
||||
{
|
||||
CAN_FilterTypeDef * config = &filters_[idx];
|
||||
void STM32CanController::configureFilter(uint8_t idx, const CanFilter & filter, bool active /* = false */)
|
||||
{
|
||||
CAN_FilterTypeDef * config = &filters_[idx];
|
||||
|
||||
if (filter.type == CanFilterIdFormat::STD)
|
||||
{
|
||||
config->FilterIdHigh = 0;
|
||||
config->FilterIdLow = filter.obj.sid & 0x7FF;
|
||||
config->FilterMaskIdHigh = 0;
|
||||
config->FilterMaskIdLow = filter.mask.sid & 0x7FF;
|
||||
}
|
||||
else
|
||||
{
|
||||
config->FilterIdHigh = ((filter.obj.sid & 0x7FF) << 2) | ((filter.obj.eid >> 16) & 0x3);
|
||||
config->FilterIdLow = filter.obj.eid & 0xFFFF;
|
||||
config->FilterMaskIdHigh = ((filter.mask.sid & 0x7FF) << 2) | ((filter.mask.eid >> 16) & 0x3);
|
||||
config->FilterMaskIdLow = filter.mask.eid & 0xFFFF;
|
||||
}
|
||||
if (filter.type == CanFilterIdFormat::STD)
|
||||
{
|
||||
config->FilterIdHigh = 0;
|
||||
config->FilterIdLow = filter.obj.sid & 0x7FF;
|
||||
config->FilterMaskIdHigh = 0;
|
||||
config->FilterMaskIdLow = filter.mask.sid & 0x7FF;
|
||||
}
|
||||
else
|
||||
{
|
||||
config->FilterIdHigh = ((filter.obj.sid & 0x7FF) << 2) | ((filter.obj.eid >> 16) & 0x3);
|
||||
config->FilterIdLow = filter.obj.eid & 0xFFFF;
|
||||
config->FilterMaskIdHigh = ((filter.mask.sid & 0x7FF) << 2) | ((filter.mask.eid >> 16) & 0x3);
|
||||
config->FilterMaskIdLow = filter.mask.eid & 0xFFFF;
|
||||
}
|
||||
|
||||
config->FilterFIFOAssignment = filter.fifo;
|
||||
config->FilterActivation = (active ? CAN_FILTER_ENABLE : CAN_FILTER_DISABLE);
|
||||
config->FilterFIFOAssignment = filter.fifo;
|
||||
config->FilterActivation = (active ? CAN_FILTER_ENABLE : CAN_FILTER_DISABLE);
|
||||
|
||||
HAL_CAN_ConfigFilter(handle_, config);
|
||||
}
|
||||
HAL_CAN_ConfigFilter(handle_, config);
|
||||
}
|
||||
|
||||
void STM32CanController::enableFilter(uint8_t idx)
|
||||
{
|
||||
CAN_FilterTypeDef * config = &filters_[idx];
|
||||
void STM32CanController::enableFilter(uint8_t idx)
|
||||
{
|
||||
CAN_FilterTypeDef * config = &filters_[idx];
|
||||
|
||||
config->FilterActivation = CAN_FILTER_ENABLE;
|
||||
config->FilterActivation = CAN_FILTER_ENABLE;
|
||||
|
||||
HAL_CAN_ConfigFilter(handle_, config);
|
||||
}
|
||||
HAL_CAN_ConfigFilter(handle_, config);
|
||||
}
|
||||
|
||||
void STM32CanController::disableFilter(uint8_t idx)
|
||||
{
|
||||
CAN_FilterTypeDef * config = &filters_[idx];
|
||||
void STM32CanController::disableFilter(uint8_t idx)
|
||||
{
|
||||
CAN_FilterTypeDef * config = &filters_[idx];
|
||||
|
||||
config->FilterActivation = CAN_FILTER_DISABLE;
|
||||
config->FilterActivation = CAN_FILTER_DISABLE;
|
||||
|
||||
HAL_CAN_ConfigFilter(handle_, config);
|
||||
}
|
||||
HAL_CAN_ConfigFilter(handle_, config);
|
||||
}
|
||||
|
||||
void STM32CanController::clearFilters()
|
||||
{
|
||||
for (uint32_t i = 0; i < MAX_FILTER_COUNT; ++i)
|
||||
{
|
||||
CAN_FilterTypeDef * config = &filters_[i];
|
||||
void STM32CanController::clearFilters()
|
||||
{
|
||||
for (uint32_t i = 0; i < MAX_FILTER_COUNT; ++i)
|
||||
{
|
||||
CAN_FilterTypeDef * config = &filters_[i];
|
||||
|
||||
// Only disable active filters
|
||||
if (config->FilterActivation == CAN_FILTER_ENABLE)
|
||||
{
|
||||
config->FilterActivation = CAN_FILTER_DISABLE;
|
||||
HAL_CAN_ConfigFilter(handle_, config);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Only disable active filters
|
||||
if (config->FilterActivation == CAN_FILTER_ENABLE)
|
||||
{
|
||||
config->FilterActivation = CAN_FILTER_DISABLE;
|
||||
HAL_CAN_ConfigFilter(handle_, config);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void STM32CanController::initFilters()
|
||||
{
|
||||
for (uint32_t i = 0; i < MAX_FILTER_COUNT; ++i)
|
||||
{
|
||||
CAN_FilterTypeDef * config = &filters_[i];
|
||||
void STM32CanController::initFilters()
|
||||
{
|
||||
for (uint32_t i = 0; i < MAX_FILTER_COUNT; ++i)
|
||||
{
|
||||
CAN_FilterTypeDef * config = &filters_[i];
|
||||
|
||||
config->FilterBank = i;
|
||||
config->FilterMode = CAN_FILTERMODE_IDMASK;
|
||||
config->FilterScale = CAN_FILTERSCALE_32BIT;
|
||||
config->FilterActivation = CAN_FILTER_DISABLE;
|
||||
config->SlaveStartFilterBank = MAX_FILTER_COUNT;
|
||||
}
|
||||
}
|
||||
config->FilterBank = i;
|
||||
config->FilterMode = CAN_FILTERMODE_IDMASK;
|
||||
config->FilterScale = CAN_FILTERSCALE_32BIT;
|
||||
config->FilterActivation = CAN_FILTER_DISABLE;
|
||||
config->SlaveStartFilterBank = MAX_FILTER_COUNT;
|
||||
}
|
||||
}
|
||||
} // namespace sta
|
||||
|
||||
|
||||
@@ -177,31 +177,31 @@ namespace sta
|
||||
|
||||
namespace sta
|
||||
{
|
||||
STM32CanController CanBus(&STA_STM32_CAN_GLOBAL);
|
||||
STM32CanController CanBus(&STA_STM32_CAN_GLOBAL);
|
||||
|
||||
STA_WEAK
|
||||
void CanBus_RxPendingCallback()
|
||||
{}
|
||||
STA_WEAK
|
||||
void CanBus_RxPendingCallback()
|
||||
{}
|
||||
} // namespace sta
|
||||
|
||||
|
||||
extern "C"
|
||||
{
|
||||
void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)
|
||||
{
|
||||
if (hcan == &STA_STM32_CAN_GLOBAL)
|
||||
{
|
||||
sta::CanBus_RxPendingCallback();
|
||||
}
|
||||
}
|
||||
void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)
|
||||
{
|
||||
if (hcan == &STA_STM32_CAN_GLOBAL)
|
||||
{
|
||||
sta::CanBus_RxPendingCallback();
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_CAN_RxFifo1MsgPendingCallback(CAN_HandleTypeDef *hcan)
|
||||
{
|
||||
if (hcan == &STA_STM32_CAN_GLOBAL)
|
||||
{
|
||||
sta::CanBus_RxPendingCallback();
|
||||
}
|
||||
}
|
||||
void HAL_CAN_RxFifo1MsgPendingCallback(CAN_HandleTypeDef *hcan)
|
||||
{
|
||||
if (hcan == &STA_STM32_CAN_GLOBAL)
|
||||
{
|
||||
sta::CanBus_RxPendingCallback();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // STA_STM32_CAN_GLOBAL
|
||||
|
@@ -10,10 +10,10 @@
|
||||
|
||||
namespace sta
|
||||
{
|
||||
void delayMs(uint32_t ms)
|
||||
{
|
||||
HAL_Delay(ms);
|
||||
}
|
||||
void delayMs(uint32_t ms)
|
||||
{
|
||||
HAL_Delay(ms);
|
||||
}
|
||||
} // namespace sta
|
||||
|
||||
|
||||
@@ -27,46 +27,46 @@ namespace sta
|
||||
|
||||
namespace sta
|
||||
{
|
||||
uint32_t gDelayUsMul = 1;
|
||||
uint32_t gDelayUsMul = 1;
|
||||
|
||||
void delayUs(uint32_t us)
|
||||
{
|
||||
__HAL_TIM_SET_COUNTER(&STA_STM32_DELAY_US_TIM, 0);
|
||||
while (__HAL_TIM_GET_COUNTER(&STA_STM32_DELAY_US_TIM) < us * gDelayUsMul);
|
||||
}
|
||||
void delayUs(uint32_t us)
|
||||
{
|
||||
__HAL_TIM_SET_COUNTER(&STA_STM32_DELAY_US_TIM, 0);
|
||||
while (__HAL_TIM_GET_COUNTER(&STA_STM32_DELAY_US_TIM) < us * gDelayUsMul);
|
||||
}
|
||||
|
||||
|
||||
bool isValidDelayUsTIM()
|
||||
{
|
||||
// Get PCLK multiplier for TIM clock
|
||||
uint32_t pclkMul = 1;
|
||||
switch (STA_STM32_DELAY_US_TIM.Init.ClockDivision)
|
||||
{
|
||||
case TIM_CLOCKDIVISION_DIV1:
|
||||
pclkMul = 1;
|
||||
break;
|
||||
case TIM_CLOCKDIVISION_DIV2:
|
||||
pclkMul = 2;
|
||||
break;
|
||||
case TIM_CLOCKDIVISION_DIV4:
|
||||
pclkMul = 4;
|
||||
break;
|
||||
default:
|
||||
STA_ASSERT(false);
|
||||
STA_UNREACHABLE();
|
||||
}
|
||||
bool isValidDelayUsTIM()
|
||||
{
|
||||
// Get PCLK multiplier for TIM clock
|
||||
uint32_t pclkMul = 1;
|
||||
switch (STA_STM32_DELAY_US_TIM.Init.ClockDivision)
|
||||
{
|
||||
case TIM_CLOCKDIVISION_DIV1:
|
||||
pclkMul = 1;
|
||||
break;
|
||||
case TIM_CLOCKDIVISION_DIV2:
|
||||
pclkMul = 2;
|
||||
break;
|
||||
case TIM_CLOCKDIVISION_DIV4:
|
||||
pclkMul = 4;
|
||||
break;
|
||||
default:
|
||||
STA_ASSERT(false);
|
||||
STA_UNREACHABLE();
|
||||
}
|
||||
|
||||
// Calculate TIM clock frequency
|
||||
uint32_t clkFreq = pclkMul * STA_STM32_GET_HANDLE_PCLK_FREQ_FN(STA_STM32_DELAY_US_TIM)();
|
||||
// Calculate update frequency based on prescaler value
|
||||
uint32_t prescaler = (STA_STM32_DELAY_US_TIM.Init.Prescaler) ? STA_STM32_DELAY_US_TIM.Init.Prescaler : 1;
|
||||
uint32_t updateFreq = clkFreq / prescaler;
|
||||
// Calculate TIM clock frequency
|
||||
uint32_t clkFreq = pclkMul * STA_STM32_GET_HANDLE_PCLK_FREQ_FN(STA_STM32_DELAY_US_TIM)();
|
||||
// Calculate update frequency based on prescaler value
|
||||
uint32_t prescaler = (STA_STM32_DELAY_US_TIM.Init.Prescaler) ? STA_STM32_DELAY_US_TIM.Init.Prescaler : 1;
|
||||
uint32_t updateFreq = clkFreq / prescaler;
|
||||
|
||||
gDelayUsMul = updateFreq / 1000000;
|
||||
gDelayUsMul = updateFreq / 1000000;
|
||||
|
||||
// TIM must have at least microsecond precision (>= 1 MHz frequency)
|
||||
return (updateFreq >= 1000000);
|
||||
}
|
||||
// TIM must have at least microsecond precision (>= 1 MHz frequency)
|
||||
return (updateFreq >= 1000000);
|
||||
}
|
||||
} // namespace sta
|
||||
|
||||
#endif // STA_STM32_DELAY_US_TIM
|
||||
|
@@ -7,76 +7,76 @@
|
||||
|
||||
namespace sta
|
||||
{
|
||||
STM32GpioPin::STM32GpioPin(GPIO_TypeDef * port, uint16_t pin)
|
||||
: port_{port}, pin_{pin}
|
||||
{
|
||||
STA_ASSERT(port != nullptr);
|
||||
}
|
||||
STM32GpioPin::STM32GpioPin(GPIO_TypeDef * port, uint16_t pin)
|
||||
: port_{port}, pin_{pin}
|
||||
{
|
||||
STA_ASSERT(port != nullptr);
|
||||
}
|
||||
|
||||
void STM32GpioPin::setState(GpioPinState state)
|
||||
{
|
||||
HAL_GPIO_WritePin(port_, pin_, (state == GpioPinState::LOW) ? GPIO_PIN_RESET : GPIO_PIN_SET);
|
||||
}
|
||||
void STM32GpioPin::setState(GpioPinState state)
|
||||
{
|
||||
HAL_GPIO_WritePin(port_, pin_, (state == GpioPinState::LOW) ? GPIO_PIN_RESET : GPIO_PIN_SET);
|
||||
}
|
||||
|
||||
GPIO_TypeDef * STM32GpioPin::getPort() const
|
||||
{
|
||||
return port_;
|
||||
}
|
||||
GPIO_TypeDef * STM32GpioPin::getPort() const
|
||||
{
|
||||
return port_;
|
||||
}
|
||||
|
||||
uint16_t STM32GpioPin::getPin() const
|
||||
{
|
||||
return pin_;
|
||||
}
|
||||
uint16_t STM32GpioPin::getPin() const
|
||||
{
|
||||
return pin_;
|
||||
}
|
||||
|
||||
uint8_t STM32GpioPin::getPortIndex() const
|
||||
{
|
||||
return GPIO_GET_INDEX(port_);
|
||||
}
|
||||
uint8_t STM32GpioPin::getPortIndex() const
|
||||
{
|
||||
return GPIO_GET_INDEX(port_);
|
||||
}
|
||||
|
||||
|
||||
bool isInterruptEdge(const STM32GpioPin & gpioPin, InterruptEdge edge)
|
||||
{
|
||||
uint32_t pin = gpioPin.getPin();
|
||||
bool isInterruptEdge(const STM32GpioPin & gpioPin, InterruptEdge edge)
|
||||
{
|
||||
uint32_t pin = gpioPin.getPin();
|
||||
|
||||
for (uint32_t i = 0; i < 8 * sizeof(pin); ++i)
|
||||
{
|
||||
uint32_t ioPos = 1U << i;
|
||||
if (pin & ioPos)
|
||||
{
|
||||
// Check input mode
|
||||
uint32_t mode = (gpioPin.getPort()->MODER >> (2U * i)) & GPIO_MODE;
|
||||
if (mode != MODE_INPUT)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (uint32_t i = 0; i < 8 * sizeof(pin); ++i)
|
||||
{
|
||||
uint32_t ioPos = 1U << i;
|
||||
if (pin & ioPos)
|
||||
{
|
||||
// Check input mode
|
||||
uint32_t mode = (gpioPin.getPort()->MODER >> (2U * i)) & GPIO_MODE;
|
||||
if (mode != MODE_INPUT)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Is EXTI configured?
|
||||
if (EXTI->IMR & ioPos)
|
||||
{
|
||||
bool rising = (EXTI->RTSR & ioPos);
|
||||
bool falling = (EXTI->FTSR & ioPos);
|
||||
// Is EXTI configured?
|
||||
if (EXTI->IMR & ioPos)
|
||||
{
|
||||
bool rising = (EXTI->RTSR & ioPos);
|
||||
bool falling = (EXTI->FTSR & ioPos);
|
||||
|
||||
switch (edge)
|
||||
{
|
||||
case InterruptEdge::RISING:
|
||||
return rising;
|
||||
switch (edge)
|
||||
{
|
||||
case InterruptEdge::RISING:
|
||||
return rising;
|
||||
|
||||
case InterruptEdge::FALLING:
|
||||
return falling;
|
||||
case InterruptEdge::FALLING:
|
||||
return falling;
|
||||
|
||||
case InterruptEdge::BOTH:
|
||||
return rising && falling;
|
||||
case InterruptEdge::BOTH:
|
||||
return rising && falling;
|
||||
|
||||
default:
|
||||
STA_ASSERT(false);
|
||||
STA_UNREACHABLE();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
default:
|
||||
STA_ASSERT(false);
|
||||
STA_UNREACHABLE();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} // namespace sta
|
||||
|
||||
|
||||
|
@@ -15,14 +15,14 @@
|
||||
|
||||
namespace sta
|
||||
{
|
||||
void initHAL()
|
||||
{
|
||||
void initHAL()
|
||||
{
|
||||
#ifdef STA_STM32_DELAY_US_TIM
|
||||
// Validate TIM used for delayUs
|
||||
extern bool isValidDelayUsTIM();
|
||||
STA_ASSERT(isValidDelayUsTIM());
|
||||
// Start timer base
|
||||
HAL_TIM_Base_Start(&STA_STM32_DELAY_US_TIM);
|
||||
// Validate TIM used for delayUs
|
||||
extern bool isValidDelayUsTIM();
|
||||
STA_ASSERT(isValidDelayUsTIM());
|
||||
// Start timer base
|
||||
HAL_TIM_Base_Start(&STA_STM32_DELAY_US_TIM);
|
||||
#endif // STA_STM32_DELAY_US_TIM
|
||||
}
|
||||
}
|
||||
} // namespace sta
|
||||
|
@@ -6,19 +6,19 @@
|
||||
|
||||
namespace sta
|
||||
{
|
||||
STM32UART::STM32UART(UART_HandleTypeDef * handle)
|
||||
: handle_{handle}
|
||||
{
|
||||
STA_ASSERT(handle != nullptr);
|
||||
}
|
||||
STM32UART::STM32UART(UART_HandleTypeDef * handle)
|
||||
: handle_{handle}
|
||||
{
|
||||
STA_ASSERT(handle != nullptr);
|
||||
}
|
||||
|
||||
|
||||
void STM32UART::write(const uint8_t * buffer, size_t size)
|
||||
{
|
||||
STA_ASSERT(buffer != nullptr);
|
||||
void STM32UART::write(const uint8_t * buffer, size_t size)
|
||||
{
|
||||
STA_ASSERT(buffer != nullptr);
|
||||
|
||||
HAL_UART_Transmit(handle_, const_cast<uint8_t *>(buffer), size, HAL_MAX_DELAY);
|
||||
}
|
||||
HAL_UART_Transmit(handle_, const_cast<uint8_t *>(buffer), size, HAL_MAX_DELAY);
|
||||
}
|
||||
} // namespace sta
|
||||
|
||||
|
||||
|
30
src/uart.cpp
30
src/uart.cpp
@@ -9,21 +9,21 @@
|
||||
|
||||
namespace sta
|
||||
{
|
||||
void UART::write(uint8_t value)
|
||||
{
|
||||
// TODO Handle endian-ness
|
||||
write(&value, 1);
|
||||
}
|
||||
void UART::write(uint8_t value)
|
||||
{
|
||||
// TODO Handle endian-ness
|
||||
write(&value, 1);
|
||||
}
|
||||
|
||||
void UART::write(uint16_t value)
|
||||
{
|
||||
// TODO Handle endian-ness
|
||||
write(reinterpret_cast<uint8_t *>(&value), sizeof(value));
|
||||
}
|
||||
void UART::write(uint16_t value)
|
||||
{
|
||||
// TODO Handle endian-ness
|
||||
write(reinterpret_cast<uint8_t *>(&value), sizeof(value));
|
||||
}
|
||||
|
||||
void UART::write(uint32_t value)
|
||||
{
|
||||
// TODO Handle endian-ness
|
||||
write(reinterpret_cast<uint8_t *>(&value), sizeof(value));
|
||||
}
|
||||
void UART::write(uint32_t value)
|
||||
{
|
||||
// TODO Handle endian-ness
|
||||
write(reinterpret_cast<uint8_t *>(&value), sizeof(value));
|
||||
}
|
||||
} // namespace sta
|
||||
|
Reference in New Issue
Block a user