Skip to content

Commit

Permalink
AP_HAL_ChibiOS: raise internal error on FPE
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbarker committed Sep 28, 2019
1 parent 417d37f commit 0ebef0b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
6 changes: 6 additions & 0 deletions libraries/AP_HAL_ChibiOS/HAL_ChibiOS_Class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "hwdef/common/usbcfg.h"
#include "hwdef/common/stm32_util.h"
#include "hwdef/common/watchdog.h"
#include "hwdef/common/fpe.h"
#include <AP_BoardConfig/AP_BoardConfig.h>
#include <AP_InternalError/AP_InternalError.h>
#ifndef HAL_BOOTLOADER_BUILD
Expand Down Expand Up @@ -265,6 +266,11 @@ static void main_loop()
}
#endif
schedulerInstance.watchdog_pat();
#if !defined(HAL_BOOTLOADER_BUILD) && !defined(IOMCU_FW)
if (stm32_fpe_flags() != 0) {
AP::internalerror().error(AP_InternalError::error_t::fpe);
}
#endif
}
thread_running = false;
}
Expand Down
1 change: 1 addition & 0 deletions libraries/AP_HAL_ChibiOS/hwdef/common/chibios_board.mk
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ CSRC += $(HWDEF)/common/stubs.c \
$(HWDEF)/common/hrt.c \
$(HWDEF)/common/stm32_util.c \
$(HWDEF)/common/bouncebuffer.c \
$(HWDEF)/common/fpe.c \
$(HWDEF)/common/watchdog.c

# $(TESTSRC) \
Expand Down
26 changes: 26 additions & 0 deletions libraries/AP_HAL_ChibiOS/hwdef/common/fpe.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
FPE detection support
*/

#include "hal.h"
#include "fpe.h"

uint32_t stm32_fpe_flags(void)
{
// Flush to zero (IDC)
// Inexact result (IXC)
// Underflow (UFC)
// Overflow (OFC)
// Division by zero (DZC)
// Invalid operation (IOC)

// see page 14/31:
const uint32_t IOC = 1U << 0;
const uint32_t DZC = 1U << 1;
const uint32_t OFC = 1U << 2;
// const uint32_t UFC = 1U << 3;
// const uint32_t IXC = 1U << 4;
const uint32_t IDC = 1U << 7;

return __get_FPSCR() & (IOC|DZC|OFC|IDC);
}
9 changes: 9 additions & 0 deletions libraries/AP_HAL_ChibiOS/hwdef/common/fpe.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifdef __cplusplus
extern "C" {
#endif

uint32_t stm32_fpe_flags(void);

#ifdef __cplusplus
}
#endif

0 comments on commit 0ebef0b

Please sign in to comment.