mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-08-06 10:27:34 +00:00
Big assert / debug clean up
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#include <sta/bus/device.hpp>
|
||||
#include <sta/assert.hpp>
|
||||
#include <sta/debug/assert.hpp>
|
||||
|
||||
namespace sta
|
||||
{
|
||||
|
@@ -1,6 +1,6 @@
|
||||
#include <sta/bus/i2c/device.hpp>
|
||||
|
||||
#include <sta/assert.hpp>
|
||||
#include <sta/debug/assert.hpp>
|
||||
|
||||
|
||||
namespace sta
|
||||
|
@@ -1,6 +1,6 @@
|
||||
#include <sta/bus/interface.hpp>
|
||||
|
||||
#include <sta/assert.hpp>
|
||||
#include <sta/debug/assert.hpp>
|
||||
|
||||
namespace sta
|
||||
{
|
||||
|
@@ -1,6 +1,6 @@
|
||||
#include <sta/bus/spi/device.hpp>
|
||||
|
||||
#include <sta/assert.hpp>
|
||||
#include <sta/debug/assert.hpp>
|
||||
|
||||
|
||||
namespace sta
|
||||
|
@@ -1,6 +1,6 @@
|
||||
#include <sta/bus/spi/settings.hpp>
|
||||
|
||||
#include <sta/assert.hpp>
|
||||
#include <sta/debug/assert.hpp>
|
||||
#include <sta/lang.hpp>
|
||||
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
#include <sta/bus/can/iter.hpp>
|
||||
|
||||
#include <sta/assert.hpp>
|
||||
#include <sta/debug/assert.hpp>
|
||||
|
||||
|
||||
namespace sta
|
||||
|
@@ -1,22 +1,16 @@
|
||||
#include <sta/assert.hpp>
|
||||
#include <sta/debug/assert.hpp>
|
||||
#ifdef STA_ASSERT_ENABLED
|
||||
|
||||
// TODO: This will probably destroy some stuff when working with stm32!
|
||||
#ifdef STA_PRINTF_USE_STDLIB
|
||||
# include <sta/debug_printf.hpp>
|
||||
#else
|
||||
# include <sta/debug_serial.hpp>
|
||||
#endif
|
||||
|
||||
#include <sta/debug/debug.hpp>
|
||||
#include <sta/lang.hpp>
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
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);
|
@@ -1,10 +1,10 @@
|
||||
#include <sta/printable.hpp>
|
||||
#include <sta/debug/printing/printable.hpp>
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
|
||||
#include <sta/assert.hpp>
|
||||
#include <sta/debug/assert.hpp>
|
||||
#include <sta/lang.hpp>
|
||||
|
||||
namespace sta
|
20
src/debug/printing/printable_printf.cpp
Normal file
20
src/debug/printing/printable_printf.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include <sta/debug/printing/printable_printf.hpp>
|
||||
#include <sta/debug/assert.hpp>
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
namespace sta
|
||||
{
|
||||
PrintablePrintf::PrintablePrintf()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PrintablePrintf::print(const char * str, size_t length)
|
||||
{
|
||||
STA_ASSERT(str != nullptr);
|
||||
STA_ASSERT(length > 0);
|
||||
|
||||
printf("%.*s", length, str);
|
||||
}
|
||||
} // namespace sta
|
@@ -1,6 +1,6 @@
|
||||
#include <sta/printable_uart.hpp>
|
||||
#include <sta/debug/printing/printable_uart.hpp>
|
||||
|
||||
#include <sta/assert.hpp>
|
||||
#include <sta/debug/assert.hpp>
|
||||
#include <sta/printf.hpp>
|
||||
|
||||
#include <cinttypes>
|
@@ -1,30 +0,0 @@
|
||||
#include <sta/debug_serial.hpp>
|
||||
#ifdef STA_DEBUG_SERIAL_ENABLED
|
||||
|
||||
|
||||
#ifdef STA_PLATFORM_STM32
|
||||
|
||||
#include <sta/devices/stm32/bus/uart.hpp>
|
||||
|
||||
// #include <usart.h>
|
||||
|
||||
// Set platform UART alias
|
||||
using PlatformUART = sta::STM32UART;
|
||||
|
||||
#endif // STA_PLATFORM_STM32
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
// 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);
|
||||
} // namespace sta
|
||||
|
||||
|
||||
#endif // STA_DEBUG_SERIAL_ENABLED
|
@@ -2,7 +2,7 @@
|
||||
|
||||
#ifdef STA_PLATFORM_RASPI
|
||||
|
||||
#include <sta/assert.hpp>
|
||||
#include <sta/debug/assert.hpp>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <string.h>
|
||||
@@ -16,16 +16,16 @@
|
||||
|
||||
namespace sta
|
||||
{
|
||||
RaspiI2c::RaspiI2c(I2cNode node, Mutex * mutex, bool persistent_open)
|
||||
: I2c{mutex}, persistent_open_{persistent_open}
|
||||
RaspiI2C::RaspiI2C(I2CNode node, Mutex * mutex, bool persistent_open)
|
||||
: I2C{mutex}, persistent_open_{persistent_open}
|
||||
{
|
||||
// Safer version of malloc + strcpy
|
||||
i2cdev_ = strdup(node == I2cNode::DEV_1 ? "/dev/i2c-1" : "/dev/i2c-2");
|
||||
i2cdev_ = strdup(node == I2CNode::DEV_1 ? "/dev/i2c-1" : "/dev/i2c-2");
|
||||
|
||||
STA_ASSERT(i2cdev_ != nullptr);
|
||||
}
|
||||
|
||||
RaspiI2c::~RaspiI2c()
|
||||
RaspiI2C::~RaspiI2C()
|
||||
{
|
||||
if (i2cdev_ != NULL ) {
|
||||
free(i2cdev_);
|
||||
@@ -37,35 +37,35 @@ namespace sta
|
||||
}
|
||||
}
|
||||
|
||||
void RaspiI2c::transfer(uint8_t value)
|
||||
void RaspiI2C::transfer(uint8_t value)
|
||||
{
|
||||
STA_ASSERT(open_);
|
||||
|
||||
write(i2cfd_, &value, 1);
|
||||
}
|
||||
|
||||
void RaspiI2c::transfer16(uint16_t value)
|
||||
void RaspiI2C::transfer16(uint16_t value)
|
||||
{
|
||||
STA_ASSERT(open_);
|
||||
|
||||
write(i2cfd_, &value, 2);
|
||||
}
|
||||
|
||||
void RaspiI2c::transfer(const uint8_t * buffer, size_t size)
|
||||
void RaspiI2C::transfer(const uint8_t * buffer, size_t size)
|
||||
{
|
||||
STA_ASSERT(open_);
|
||||
|
||||
write(i2cfd_, buffer, size);
|
||||
}
|
||||
|
||||
void RaspiI2c::transfer(const uint8_t * txBuffer, uint8_t * rxBuffer, size_t size)
|
||||
void RaspiI2C::transfer(const uint8_t * txBuffer, uint8_t * rxBuffer, size_t size)
|
||||
{
|
||||
STA_ASSERT(open_);
|
||||
|
||||
// TODO: Is this even possible in i2c?
|
||||
}
|
||||
|
||||
void RaspiI2c::receive(uint8_t * buffer, size_t size)
|
||||
void RaspiI2C::receive(uint8_t * buffer, size_t size)
|
||||
{
|
||||
STA_ASSERT(open_);
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace sta
|
||||
}
|
||||
}
|
||||
|
||||
void RaspiI2c::fill(uint8_t value, size_t count)
|
||||
void RaspiI2C::fill(uint8_t value, size_t count)
|
||||
{
|
||||
STA_ASSERT(open_);
|
||||
|
||||
@@ -88,17 +88,9 @@ namespace sta
|
||||
delete [] buffer;
|
||||
}
|
||||
|
||||
void RaspiI2c::selectAddress(uint16_t address)
|
||||
void RaspiI2C::acquire()
|
||||
{
|
||||
if (ioctl(i2cfd_, I2C_SLAVE, address) < 0)
|
||||
{
|
||||
printf("Failed to send the slave address.");
|
||||
}
|
||||
}
|
||||
|
||||
void RaspiI2c::acquire()
|
||||
{
|
||||
I2c::acquire();
|
||||
I2C::acquire();
|
||||
|
||||
if (open_) {
|
||||
return;
|
||||
@@ -110,17 +102,17 @@ namespace sta
|
||||
STA_ASSERT(i2cfd_ >= 0);
|
||||
}
|
||||
|
||||
void RaspiI2c::release()
|
||||
void RaspiI2C::release()
|
||||
{
|
||||
if (!persistent_open_ && open_) {
|
||||
close(i2cfd_);
|
||||
}
|
||||
|
||||
I2c::release();
|
||||
I2C::release();
|
||||
}
|
||||
|
||||
RaspiI2cDevice::RaspiI2cDevice(I2c * intf, uint16_t address_10bit, Mutex* mutex, bool master, bool blocking)
|
||||
: I2cDevice { intf, address_10bit }
|
||||
RaspiI2CDevice::RaspiI2CDevice(RaspiI2C * intf, uint16_t address_10bit, Mutex* mutex, bool master, bool blocking)
|
||||
: I2CDevice { intf, address_10bit }
|
||||
{
|
||||
|
||||
}
|
||||
|
@@ -4,7 +4,7 @@
|
||||
|
||||
#include <sta/devices/raspi/gpio_pin.hpp>
|
||||
#include <sta/bus/spi/settings.hpp>
|
||||
#include <sta/assert.hpp>
|
||||
#include <sta/debug/assert.hpp>
|
||||
#include <sta/endian.hpp>
|
||||
#include <sta/lang.hpp>
|
||||
|
||||
|
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <sta/devices/raspi/hal.hpp>
|
||||
|
||||
#include <sta/assert.hpp>
|
||||
#include <sta/debug/assert.hpp>
|
||||
#include <sta/lang.hpp>
|
||||
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#include <sta/devices/raspi/gpio_pin.hpp>
|
||||
#ifdef STA_RASPI_GPIO_ENABLED
|
||||
|
||||
#include <sta/assert.hpp>
|
||||
#include <sta/debug/assert.hpp>
|
||||
#include <sta/lang.hpp>
|
||||
|
||||
namespace sta
|
||||
|
@@ -1,8 +1,10 @@
|
||||
#include <sta/devices/stm32/bus/i2c.hpp>
|
||||
|
||||
#include <sta/assert.hpp>
|
||||
#include <sta/debug/assert.hpp>
|
||||
#include <cstring>
|
||||
|
||||
#ifdef STA_PLATFORM_STM32
|
||||
|
||||
namespace sta
|
||||
{
|
||||
STM32I2C::STM32I2C(I2C_HandleTypeDef * handle, Mutex * mutex)
|
||||
@@ -126,3 +128,5 @@ namespace sta
|
||||
}
|
||||
|
||||
} // namespace sta
|
||||
|
||||
#endif // STA_PLATFORM_STM32
|
||||
|
@@ -1,6 +1,6 @@
|
||||
#include <sta/devices/stm32/init.hpp>
|
||||
|
||||
#include <sta/assert.hpp>
|
||||
#include <sta/debug/assert.hpp>
|
||||
|
||||
#ifdef STA_STM32_DELAY_US_TIM
|
||||
|
||||
|
Reference in New Issue
Block a user