aboutsummaryrefslogtreecommitdiff
path: root/src/cortexm.c
diff options
context:
space:
mode:
authorGareth McMullin2015-02-28 20:53:25 -0800
committerGareth McMullin2015-03-22 12:26:45 -0700
commitd6225eec763bd49ef3cb8edac5138df9e524a073 (patch)
tree7db158a0e0adf742238a69b9e7ec6d2cfcc0192d /src/cortexm.c
parentfa046601a54ddf2137048f11594ed7d72ede995a (diff)
Raise timeout exception when target is in WFI.
Ignore the exception when polling for halt, and report the exception to the user if halting the target fails. Remove old allow_timeout flag in DP struct that's no longer needed.
Diffstat (limited to 'src/cortexm.c')
-rw-r--r--src/cortexm.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/src/cortexm.c b/src/cortexm.c
index a129a3c..f20f282 100644
--- a/src/cortexm.c
+++ b/src/cortexm.c
@@ -29,6 +29,7 @@
* There are way too many magic numbers used here.
*/
#include "general.h"
+#include "exception.h"
#include "jtagtap.h"
#include "jtag_scan.h"
#include "adiv5.h"
@@ -467,12 +468,15 @@ cortexm_reset(struct target_s *target)
static void
cortexm_halt_request(struct target_s *target)
{
- ADIv5_AP_t *ap = adiv5_target_ap(target);
-
- ap->dp->allow_timeout = false;
- target_mem_write32(target, CORTEXM_DHCSR,
- CORTEXM_DHCSR_DBGKEY | CORTEXM_DHCSR_C_HALT |
- CORTEXM_DHCSR_C_DEBUGEN);
+ volatile struct exception e;
+ TRY_CATCH (e, EXCEPTION_TIMEOUT) {
+ target_mem_write32(target, CORTEXM_DHCSR, CORTEXM_DHCSR_DBGKEY |
+ CORTEXM_DHCSR_C_HALT |
+ CORTEXM_DHCSR_C_DEBUGEN);
+ }
+ if (e.type) {
+ gdb_out("Timeout sending interrupt, is target in WFI?\n");
+ }
}
static int
@@ -480,10 +484,16 @@ cortexm_halt_wait(struct target_s *target)
{
ADIv5_AP_t *ap = adiv5_target_ap(target);
struct cortexm_priv *priv = ap->priv;
- if (!(target_mem_read32(target, CORTEXM_DHCSR) & CORTEXM_DHCSR_S_HALT))
- return 0;
- ap->dp->allow_timeout = false;
+ uint32_t dhcsr = 0;
+ volatile struct exception e;
+ TRY_CATCH (e, EXCEPTION_TIMEOUT) {
+ /* If this times out because the target is in WFI then
+ * the target is still running. */
+ dhcsr = target_mem_read32(target, CORTEXM_DHCSR);
+ }
+ if (e.type || !(dhcsr & CORTEXM_DHCSR_S_HALT))
+ return 0;
/* We've halted. Let's find out why. */
uint32_t dfsr = target_mem_read32(target, CORTEXM_DFSR);
@@ -543,7 +553,6 @@ void cortexm_halt_resume(struct target_s *target, bool step)
}
target_mem_write32(target, CORTEXM_DHCSR, dhcsr);
- ap->dp->allow_timeout = true;
}
static int cortexm_fault_unwind(struct target_s *target)