Skip to content

Commit d47da3d

Browse files
committed
finihed the class let's check if it works
1 parent 1a9d1c8 commit d47da3d

1 file changed

Lines changed: 36 additions & 16 deletions

File tree

Inc/HALAL/Services/DataWatchpointTrace/DataWatchpointTrace.hpp

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,50 @@
33
#include "C++Utilities/CppUtils.hpp"
44
#include "ErrorHandler/ErrorHandler.hpp"
55
#include "HALAL/Models/PinModel/Pin.hpp"
6+
#include "core_cm7.h"
7+
8+
#if !defined DWT_LSR_Present_Msk
9+
#define DWT_LSR_Present_Msk ITM_LSR_Present_Msk
10+
#endif
11+
#if !defined DWT_LSR_Access_Msk
12+
#define DWT_LSR_Access_Msk ITM_LSR_Access_Msk
13+
#endif
14+
#define DWT_LAR_KEY 0xC5ACCE55
15+
#define DEMCR_TRCENA 0x01000000
16+
#define DWT_CTRL_CYCCNTENA 0x00000001
617

7-
volatile unsigned int *DWT_CYCCNT;
8-
volatile unsigned int *DWT_CONTROL;
9-
volatile unsigned int *SCB_DEMCR;
10-
// habra que poner para hacerlo con traza y sin traza en un template
1118
class DataWatchpointTrace {
1219
public:
13-
static void reset_cnt() {
14-
DWT_CYCCNT = (unsigned int *)0xE0001004;
15-
DWT_CONTROL = (unsigned int *)0xE0001000;
16-
SCB_DEMCR = (unsigned int *)0xE000EDFC;
17-
*SCB_DEMCR |= 0x01000000; // enable DWT
18-
*DWT_CONTROL |= 1; // enable the counter
19-
*DWT_CYCCNT = 0; // reset counter
20+
static void start() {
21+
unlock_dwt();
22+
reset_cnt();
2023
}
2124
static unsigned int start_count() {
22-
*DWT_CONTROL |= 1; // enables the counter
23-
return *DWT_CYCCNT; // returns the current value of the counter
25+
DWT->CTRL |= DWT_CTRL_CYCCNTENA; // enables the counter
26+
DWT->CYCCNT = 0;
27+
return DWT->CYCCNT;
2428
}
2529
static unsigned int stop_count() {
26-
*DWT_CONTROL &= ~1; // disables the counter
27-
return *DWT_CYCCNT; // returns the current value of the counter
30+
DWT->CTRL &= ~DWT_CTRL_CYCCNTENA; // disable the counter
31+
return DWT->CYCCNT;
2832
}
2933
static unsigned int get_count() {
30-
return *DWT_CYCCNT; // returns the current value of the counter
34+
return DWT->CYCCNT; // returns the current value of the counter
35+
}
36+
37+
private:
38+
static void reset_cnt() {
39+
CoreDebug->DEMCR |= DEMCR_TRCENA;
40+
DWT->CYCCNT = 0; // reset the counter
41+
DWT->CTRL = 0;
42+
}
43+
44+
static void unlock_dwt() { // unlock the dwt
45+
uint32_t lsr = DWT->LSR;
46+
if ((lsr & DWT_LSR_Present_Msk) != 0) {
47+
if ((lsr & DWT_LSR_Access_Msk) != 0) {
48+
DWT->LAR = DWT_LAR_KEY;
49+
}
50+
}
3151
}
3252
};

0 commit comments

Comments
 (0)