Skip to content

Commit 1716bc0

Browse files
Merge pull request #17 from dcmid/multiple-nodes
Support for Multiple Nodes
2 parents 9679712 + 85af43e commit 1716bc0

7 files changed

Lines changed: 132 additions & 48 deletions

File tree

examples/export.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
from systemrdl import RDLCompiler
22
from peakrdl_halcpp import HalExporter
33

4-
rdlc = RDLCompiler()
5-
rdlc.compile_file("atxmega_spi.rdl")
4+
rdl_files = ["atxmega_spi.rdl", "regs_and_mem.rdl"]
65

7-
root = rdlc.elaborate()
8-
top_gen = root.children(unroll=True)
6+
for rdl_file in rdl_files:
7+
rdlc = RDLCompiler()
8+
rdlc.compile_file(rdl_file)
99

10-
top = None
11-
for top in top_gen:
12-
top = top
13-
assert top is not None
10+
root = rdlc.elaborate()
11+
top_gen = root.children(unroll=True)
1412

15-
exporter = HalExporter()
13+
top = None
14+
for top in top_gen:
15+
top = top
16+
assert top is not None
1617

17-
exporter.export(
18-
node=top,
19-
outdir="generated",
20-
)
18+
exporter = HalExporter()
2119

20+
exporter.export(
21+
node=top,
22+
outdir="generated",
23+
)

examples/generated/include/field_node.h

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,16 @@ namespace halcpp
2424
{
2525
public:
2626
/**
27-
* @brief
27+
* @brief Return the absolute address of the node.
2828
*
2929
*/
3030
static constexpr uint32_t get_abs_addr() { return PARENT_TYPE().get_abs_addr(); }
3131

32-
protected:
33-
using parent_type = PARENT_TYPE;
34-
using dataType = typename std::conditional<width <= 8, uint8_t,
35-
typename std::conditional<width <= 16, uint16_t, uint32_t>::type>::type;
36-
37-
static constexpr uint32_t start_bit = START_BIT;
38-
static constexpr uint32_t end_bit = END_BIT;
39-
static constexpr uint32_t width = END_BIT - START_BIT + 1;
32+
/**
33+
* @brief Return the width of the field noe.
34+
*
35+
*/
36+
static constexpr uint32_t get_width() { return width; }
4037

4138
/**
4239
* @brief Calculate the field mask.
@@ -58,6 +55,18 @@ namespace halcpp
5855
{
5956
return (((1u << (width)) - 1));
6057
}
58+
59+
60+
61+
protected:
62+
using parent_type = PARENT_TYPE;
63+
64+
static constexpr uint32_t start_bit = START_BIT;
65+
static constexpr uint32_t end_bit = END_BIT;
66+
static constexpr uint32_t width = END_BIT - START_BIT + 1;
67+
68+
using dataType = typename std::conditional<width <= 8, uint8_t,
69+
typename std::conditional<width <= 16, uint16_t, uint32_t>::type>::type;
6170
};
6271

6372
/**

examples/generated/include/halcpp_base.h

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,12 @@
33

44
#include <stdint.h>
55
#include <type_traits>
6+
#include "halcpp_utils.h"
67
#include "field_node.h"
78
#include "reg_node.h"
8-
#include "csr_reg_node.h"
9-
#include "reg_arr_node.h"
9+
#include "regfile_node.h"
10+
#include "array_nodes.h"
11+
#include "mem_node.h"
1012
#include "addrmap_node.h"
1113

12-
13-
template <uint32_t BASE, uint32_t SIZE, typename PARENT_TYPE>
14-
class MemNode {
15-
public:
16-
17-
static constexpr uint32_t base = BASE;
18-
static constexpr uint32_t size = SIZE;
19-
20-
inline uint32_t get(const uint32_t addr) { return PARENT_TYPE::get(addr + BASE); }
21-
inline void set(const uint32_t addr, uint32_t val) { PARENT_TYPE::set(addr + BASE, val); }
22-
static constexpr uint32_t get_abs_addr() { return PARENT_TYPE().get_abs_addr() + BASE; }
23-
constexpr uint32_t get_size() { return SIZE; }
24-
};
25-
2614
#endif
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Generated with PeakRD-halcpp : https://github.com/Risto97/PeakRDL-halcpp
2+
#ifndef __REGS_AND_MEM_HAL_H_
3+
#define __REGS_AND_MEM_HAL_H_
4+
5+
#include <stdint.h>
6+
#include "include/halcpp_base.h"
7+
8+
#if defined(__clang__)
9+
#pragma clang diagnostic ignored "-Wundefined-var-template"
10+
#endif
11+
12+
namespace regs_and_mem_nm
13+
{
14+
15+
16+
template <uint32_t BASE, uint32_t WIDTH, typename PARENT_TYPE>
17+
class CSR : public halcpp::RegRW<BASE, WIDTH, PARENT_TYPE>
18+
{
19+
public:
20+
using TYPE = CSR<BASE, WIDTH, PARENT_TYPE>;
21+
22+
static halcpp::FieldRW<0, 7, TYPE> ctrl;
23+
24+
using halcpp::RegRW<BASE, WIDTH, PARENT_TYPE>::operator=;
25+
};
26+
27+
28+
29+
template <uint32_t BASE, uint32_t WIDTH, typename PARENT_TYPE>
30+
class CSR2 : public halcpp::RegRW<BASE, WIDTH, PARENT_TYPE>
31+
{
32+
public:
33+
using TYPE = CSR2<BASE, WIDTH, PARENT_TYPE>;
34+
35+
static halcpp::FieldRW<0, 7, TYPE> ctrl;
36+
37+
using halcpp::RegRW<BASE, WIDTH, PARENT_TYPE>::operator=;
38+
};
39+
40+
41+
42+
template <uint32_t BASE, uint32_t SIZE, typename PARENT_TYPE>
43+
class MEM1 : public halcpp::MemNode<BASE, SIZE, PARENT_TYPE>
44+
{
45+
46+
};
47+
template <uint32_t BASE, uint32_t SIZE, typename PARENT_TYPE>
48+
class MEM2_T : public halcpp::MemNode<BASE, SIZE, PARENT_TYPE>
49+
{
50+
51+
};
52+
}
53+
54+
55+
template <uint32_t BASE, typename PARENT_TYPE=void>
56+
class REGS_AND_MEM_HAL : public AddrmapNode<BASE, PARENT_TYPE>
57+
{
58+
public:
59+
using TYPE = REGS_AND_MEM_HAL<BASE, PARENT_TYPE>;
60+
61+
static regs_and_mem_nm::CSR<0x0, 8, TYPE> csr;
62+
static regs_and_mem_nm::CSR2<0x4, 8, TYPE> csr2;
63+
static regs_and_mem_nm::MEM1<0x1000, 256, TYPE> mem1;
64+
static regs_and_mem_nm::MEM2_T<0x2000, 256, TYPE> mem2;
65+
};
66+
67+
#endif // !__REGS_AND_MEM_HAL_H_

examples/regs_and_mem.rdl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
addrmap regs_and_mem {
2+
name = "Registers and Memory Example";
3+
default regwidth = 32;
4+
5+
reg {
6+
field { sw=rw; hw=r; } ctrl[7:0];
7+
} csr @0x0;
8+
9+
reg {
10+
field { sw=rw; hw=r; } ctrl[7:0];
11+
} csr2 @0x4;
12+
13+
// anonymous definition of mem (SystemRDL 11.1.b)
14+
mem {
15+
memwidth = 32;
16+
mementries = 64;
17+
} external mem1 @0x1000;
18+
19+
// definitive definition of mem (SystemRDL 11.1.a)
20+
mem mem2_t {
21+
memwidth = 32;
22+
mementries = 64;
23+
};
24+
25+
external mem2_t mem2 @0x2000;
26+
};

src/peakrdl_halcpp/halnode.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -353,14 +353,6 @@ def __init__(self, node: MemNode):
353353

354354
self.bus_offset = 0
355355

356-
# Memory component instantiation is limited for simplicity
357-
if self.parent is not None:
358-
for c in self.parent.children():
359-
if isinstance(c, AddressableNode):
360-
assert c.inst == self.inst, (f"Addrmaps with anything else than "
361-
"one memory node is currently not allowed, "
362-
"it could be easily added")
363-
364356
@property
365357
def address_offset(self) -> int:
366358
"""Property adapted HalRegNode class."""

src/peakrdl_halcpp/templates/addrmap.h.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ namespace {{ halnode.orig_type_name }}_nm
127127
{# ======== 4. Generate the memory classes ======== #}
128128
{% for m in halnode.halchildren(children_type=HalMemNode, skip_buses=skip_buses, unique_orig_type=True) %}
129129
{{ m.get_template_line() }}
130-
class {{ m.parent.orig_type_name|upper }} : public halcpp::MemNode{{ m.get_cls_tmpl_params() }}
130+
class {{ m.orig_type_name|upper }} : public halcpp::MemNode{{ m.get_cls_tmpl_params() }}
131131
{
132132

133133
};
@@ -153,7 +153,7 @@ public:
153153
{% elif c.__class__.__name__ == "HalRegfileNode" %}
154154
static {{ halnode.orig_type_name }}_nm::{{ c.orig_type_name|upper }}<0x{{ "%0x"|format(c.address_offset|int) }}, TYPE> {{ c.inst_name }};
155155
{% elif c.__class__.__name__ == "HalMemNode" %}
156-
static {{ halnode.orig_type_name }}_nm::{{ c.parent.orig_type_name|upper }}<0x{{ "%0x"|format(c.address_offset|int) }}, {{ c.size }}, TYPE> {{ c.inst_name }};
156+
static {{ halnode.orig_type_name }}_nm::{{ c.orig_type_name|upper }}<0x{{ "%0x"|format(c.address_offset|int) }}, {{ c.size }}, TYPE> {{ c.inst_name }};
157157
{% else %}
158158
static {{ halutils.get_extern(c)|upper }}<0x{{ "%0x"|format(c.address_offset|int) }}, TYPE> {{ c.inst_name }};
159159
{% endif %}

0 commit comments

Comments
 (0)