Commit e8b7a373 authored by Christian Eichler's avatar Christian Eichler
Browse files

Only enable timer overflow detection if halt debugging is disables

In addition provide that information via command "inf"
parent cee52d31
......@@ -145,6 +145,11 @@ static void command_inf(char *arg) {
default: CDC_Device_SendString(&VirtualSerial_CDC_Interface, "e:v\r"); break;
}
if(timer_has_overflow_detection()) {
CDC_Device_SendString(&VirtualSerial_CDC_Interface, "o:ov e\r");
} else {
CDC_Device_SendString(&VirtualSerial_CDC_Interface, "o:ov d\r");
}
if(PREF->PCON & PREF_PCON_IBYP_Msk) {
CDC_Device_SendString(&VirtualSerial_CDC_Interface, "o:ic d\n");
......
......@@ -5,16 +5,32 @@
#define CYCCNT_LIMIT (UINT32_MAX)
#define CYCCNT_INT_COST 40
static uint32_t overflow_counter = 0;
static uint32_t overflow_counter = 0;
static bool overflow_detection = false;
void DebugMon_Handler() {
++overflow_counter;
}
void timer_init() {
bool timer_has_overflow_detection() {
return overflow_detection;
}
bool timer_enable_overflow_detection() {
if(CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) {
return false;
}
DWT->COMP0 = CYCCNT_LIMIT;
DWT->MASK0 = 2; // watch 4Bytes (uint32_t)
DWT->FUNCTION0 = DWT_FUNCTION_CYCMATCH_Msk | 0x4 /* watch DWT_CYCCNT */;
DWT->FUNCTION0 = DWT_FUNCTION_CYCMATCH_Msk | 0x4; // watch DWT_CYCCNT
overflow_detection = true;
return true;
}
void timer_init() {
timer_enable_overflow_detection();
DWT->CYCCNT = 0; // reset the counter
DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk | DWT_CTRL_CYCEVTENA_Msk;
......
#ifndef __TIMER_H
#define __TIMER_H
#include <stdbool.h>
#include <stdint.h>
void timer_init();
bool timer_enable_overflow_detection();
bool timer_has_overflow_detection();
void timer_start();
uint64_t timer_stop();
#endif /* __TIMER_H */
......@@ -151,6 +151,8 @@ static void resp_inf(bool success, char *resp) {
printf("Frequency: %.2f%cHz", freq_dbl, prefixes[idx]);
} else if(rem = strsw(resp, "ic ")) {
printf("Instruction Cache: Currently %s", ('e' == *rem) ? "enabled" : "disabled");
} else if(rem = strsw(resp, "ov ")) {
printf("Timer Overflow Detection: Currently %s", ('e' == *rem) ? "enabled" : "disabled");
} else {
printf("Unparsed: %s", resp);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment