summaryrefslogtreecommitdiff
path: root/cortex_m/debug.h
blob: 8134829bd2ab8974c409df25b645df85439af95a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#pragma once

#include <stdint.h>

#include <mmio/mmio.h>

struct ITM_reg_t {
	union {
		volatile uint32_t u32;
		volatile uint16_t u16;
		volatile uint8_t u8;
	} STIM[256];
    uint32_t _reserved[640];
    volatile uint32_t TER[8];
    uint32_t _reserved2[8];
    volatile uint32_t TPR;
    uint32_t _reserved3[15];
    volatile uint32_t TCR;
    uint32_t _reserved4[76];
    volatile uint32_t LSR;

    // FIXME - only supports first 32 stimulus ports
    void stim_blocking(unsigned stim, uint8_t data) {
	    if (!(this->TER[0] & (1<<stim))) {
		    return;
	    }
	    while (!(this->STIM[stim].u8 & 1))
		    ;
	    this->STIM[stim].u8 = data;
    }
    void stim_blocking(unsigned stim, uint16_t data) {
	    if (!(this->TER[0] & (1<<stim))) {
		    return;
	    }
	    while (!(this->STIM[stim].u16 & 1))
		    ;
	    this->STIM[stim].u16 = data;
    }
    void stim_blocking(unsigned stim, uint32_t data) {
	    if (!(this->TER[0] & (1<<stim))) {
		    return;
	    }
	    while (!(this->STIM[stim].u32 & 1))
		    ;
	    this->STIM[stim].u32 = data;
    }
};

struct DWT_reg_t {
    volatile uint32_t CTRL;
    volatile uint32_t CYCCNT;
    volatile uint32_t CPICNT;
    volatile uint32_t EXCCNT;
    volatile uint32_t SLEEPCNT;
    volatile uint32_t LSUCNT;
    volatile uint32_t FOLDCNT;
    volatile uint32_t PCSR;
};

struct TPIU_reg_t {
    volatile uint32_t SSPSR;
    volatile uint32_t CSPSR;
    uint32_t _reserved[2];
    volatile uint32_t ACPR;
    uint32_t _reserved2[55];
    volatile uint32_t SPPR;
};

constexpr mmio_ptr<ITM_reg_t> ITM {0xe0000000};
constexpr mmio_ptr<DWT_reg_t> DWT {0xe0001000};
constexpr mmio_ptr<TPIU_reg_t> TPIU {0xe0040000};