Skip to content

Commit

Permalink
Reformatted with new clang-format rules
Browse files Browse the repository at this point in the history
  • Loading branch information
bsutherland333 committed Dec 15, 2023
1 parent f3dd157 commit 71952b4
Show file tree
Hide file tree
Showing 42 changed files with 1,990 additions and 2,710 deletions.
247 changes: 75 additions & 172 deletions boards/airbourne/airbourne_board.cpp

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions boards/airbourne/airbourne_board.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class AirbourneBoard : public Board
VCP vcp_;
UART uart1_;
UART uart3_;
Serial *current_serial_; // A pointer to the serial stream currently in use.
Serial * current_serial_; // A pointer to the serial stream currently in use.
I2C int_i2c_;
I2C ext_i2c_;
SPI spi1_;
Expand Down Expand Up @@ -98,7 +98,7 @@ class AirbourneBoard : public Board
};
SerialDevice secondary_serial_device_ = SERIAL_DEVICE_VCP;

RC_BASE *rc_ = nullptr;
RC_BASE * rc_ = nullptr;

std::function<void()> imu_callback_;

Expand Down Expand Up @@ -132,7 +132,7 @@ class AirbourneBoard : public Board

// serial
void serial_init(uint32_t baud_rate, uint32_t dev) override;
void serial_write(const uint8_t *src, size_t len) override;
void serial_write(const uint8_t * src, size_t len) override;
uint16_t serial_bytes_available() override;
uint8_t serial_read() override;
void serial_flush() override;
Expand All @@ -142,7 +142,7 @@ class AirbourneBoard : public Board
uint16_t num_sensor_errors() override;

bool new_imu_data() override;
bool imu_read(float accel[3], float *temperature, float gyro[3], uint64_t *time_us) override;
bool imu_read(float accel[3], float * temperature, float gyro[3], uint64_t * time_us) override;
void imu_not_responding_error() override;

bool mag_present() override;
Expand All @@ -151,11 +151,11 @@ class AirbourneBoard : public Board

bool baro_present() override;
void baro_update() override;
void baro_read(float *pressure, float *temperature) override;
void baro_read(float * pressure, float * temperature) override;

bool diff_pressure_present() override;
void diff_pressure_update() override;
void diff_pressure_read(float *diff_pressure, float *temperature) override;
void diff_pressure_read(float * diff_pressure, float * temperature) override;

bool sonar_present() override;
void sonar_update() override;
Expand Down Expand Up @@ -188,8 +188,8 @@ class AirbourneBoard : public Board

// non-volatile memory
void memory_init() override;
bool memory_read(void *dest, size_t len) override;
bool memory_write(const void *src, size_t len) override;
bool memory_read(void * dest, size_t len) override;
bool memory_write(const void * src, size_t len) override;

// LEDs
void led0_on() override;
Expand All @@ -202,8 +202,8 @@ class AirbourneBoard : public Board

// Backup Data
void backup_memory_init() override;
bool backup_memory_read(void *dest, size_t len) override;
void backup_memory_write(const void *src, size_t len) override;
bool backup_memory_read(void * dest, size_t len) override;
void backup_memory_write(const void * src, size_t len) override;
void backup_memory_clear(size_t len) override;
};

Expand Down
172 changes: 78 additions & 94 deletions boards/airbourne/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,105 +37,92 @@

#include "rosflight.h"

rosflight_firmware::ROSflight* rosflight_ptr = nullptr; // used to access firmware in case of a hard fault
void write_backup_data(const rosflight_firmware::StateManager::BackupData::DebugInfo& debug)
rosflight_firmware::ROSflight * rosflight_ptr =
nullptr; // used to access firmware in case of a hard fault
void write_backup_data(const rosflight_firmware::StateManager::BackupData::DebugInfo & debug)
{
if (rosflight_ptr != nullptr)
{
rosflight_ptr->state_manager_.write_backup_data(debug);
}
if (rosflight_ptr != nullptr) { rosflight_ptr->state_manager_.write_backup_data(debug); }
}

extern "C"
{
/* The prototype shows it is a naked function - in effect this is just an
extern "C" {
/* The prototype shows it is a naked function - in effect this is just an
assembly function. */
void HardFault_Handler(void) __attribute__((naked));
void HardFault_Handler(void) __attribute__((naked));

/* The fault handler implementation calls a function called
/* The fault handler implementation calls a function called
prvGetRegistersFromStack(). */
void HardFault_Handler(void)
{
__asm volatile(
" tst lr, #4 \n"
" ite eq \n"
" mrseq r0, msp \n"
" mrsne r0, psp \n"
" ldr r1, [r0, #24] \n"
" ldr r2, handler2_address_const \n"
" bx r2 \n"
" handler2_address_const: .word prvGetRegistersFromStack \n");
}

void prvGetRegistersFromStack(uint32_t* pulFaultStackAddress)
{
/* These are volatile to try and prevent the compiler/linker optimising them
void HardFault_Handler(void)
{
__asm volatile(" tst lr, #4 \n"
" ite eq \n"
" mrseq r0, msp \n"
" mrsne r0, psp \n"
" ldr r1, [r0, #24] \n"
" ldr r2, handler2_address_const \n"
" bx r2 \n"
" handler2_address_const: .word prvGetRegistersFromStack \n");
}

void prvGetRegistersFromStack(uint32_t * pulFaultStackAddress)
{
/* These are volatile to try and prevent the compiler/linker optimising them
away as the variables never actually get used. If the debugger won't show the
values of the variables, make them global my moving their declaration outside
of this function. */
volatile uint32_t r0;
volatile uint32_t r1;
volatile uint32_t r2;
volatile uint32_t r3;
volatile uint32_t r12;
volatile uint32_t lr; /* Link register. */
volatile uint32_t pc; /* Program counter. */
volatile uint32_t psr; /* Program status register. */

r0 = pulFaultStackAddress[0];
r1 = pulFaultStackAddress[1];
r2 = pulFaultStackAddress[2];
r3 = pulFaultStackAddress[3];

r12 = pulFaultStackAddress[4];
lr = pulFaultStackAddress[5];
pc = pulFaultStackAddress[6];
psr = pulFaultStackAddress[7];

/* When the following line is hit, the variables contain the register values. */

// save crash information to backup SRAM
rosflight_firmware::StateManager::BackupData::DebugInfo debug = {r0, r1, r2, r3, r12, lr, pc, psr};
write_backup_data(debug);

// reboot
NVIC_SystemReset();
}

void NMI_Handler()
{
while (1)
{
}
}

void MemManage_Handler()
{
while (1)
{
}
}

void BusFault_Handler()
{
while (1)
{
}
}

void UsageFault_Handler()
{
while (1)
{
}
}

void WWDG_IRQHandler()
{
while (1)
{
}
}
volatile uint32_t r0;
volatile uint32_t r1;
volatile uint32_t r2;
volatile uint32_t r3;
volatile uint32_t r12;
volatile uint32_t lr; /* Link register. */
volatile uint32_t pc; /* Program counter. */
volatile uint32_t psr; /* Program status register. */

r0 = pulFaultStackAddress[0];
r1 = pulFaultStackAddress[1];
r2 = pulFaultStackAddress[2];
r3 = pulFaultStackAddress[3];

r12 = pulFaultStackAddress[4];
lr = pulFaultStackAddress[5];
pc = pulFaultStackAddress[6];
psr = pulFaultStackAddress[7];

/* When the following line is hit, the variables contain the register values. */

// save crash information to backup SRAM
rosflight_firmware::StateManager::BackupData::DebugInfo debug = {r0, r1, r2, r3,
r12, lr, pc, psr};
write_backup_data(debug);

// reboot
NVIC_SystemReset();
}

void NMI_Handler()
{
while (1) {}
}

void MemManage_Handler()
{
while (1) {}
}

void BusFault_Handler()
{
while (1) {}
}

void UsageFault_Handler()
{
while (1) {}
}

void WWDG_IRQHandler()
{
while (1) {}
}
} // extern "C"

int main(void)
Expand All @@ -149,10 +136,7 @@ int main(void)
board.init_board();
firmware.init();

while (true)
{
firmware.run();
}
while (true) { firmware.run(); }

return 0;
}
Loading

0 comments on commit 71952b4

Please sign in to comment.