Skip to content

Commit bdec003

Browse files
committed
Add C header examples
1 parent d2cc64c commit bdec003

File tree

3 files changed

+209
-0
lines changed

3 files changed

+209
-0
lines changed

docs/gallery.rst

+16
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,22 @@ Input: `atxmega_spi.rdl <https://github.com/SystemRDL/PeakRDL/tree/main/examples
5050
Result: `atxmega_uvm_pkg.sv <https://github.com/SystemRDL/PeakRDL/blob/main/examples/atxmega_spi_uvm_pkg.sv>`_
5151

5252

53+
Generate C headers for software
54+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
55+
.. code-block:: bash
56+
57+
peakrdl c-header atxmega_spi.rdl -o atxmega_spi.h
58+
59+
# .. Or with bit-fields
60+
peakrdl c-header atxmega_spi.rdl -o atxmega_spi_bf.h --bitfields ltoh
61+
62+
63+
Input: `atxmega_spi.rdl <https://github.com/SystemRDL/PeakRDL/tree/main/examples/atxmega_spi.rdl>`_
64+
65+
Result: `atxmega_spi.h <https://github.com/SystemRDL/PeakRDL/blob/main/examples/atxmega_spi.h>`_ &
66+
`atxmega_spi_bf.h <https://github.com/SystemRDL/PeakRDL/blob/main/examples/atxmega_spi_bf.h>`_
67+
68+
5369
Convert to IP-XACT XML
5470
^^^^^^^^^^^^^^^^^^^^^^
5571
.. code-block:: bash

examples/atxmega_spi.h

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Generated by PeakRDL-cheader - A free and open-source header generator
2+
// https://github.com/SystemRDL/PeakRDL-cheader
3+
4+
#ifndef ATXMEGA_SPI_H
5+
#define ATXMEGA_SPI_H
6+
7+
#ifdef __cplusplus
8+
extern "C" {
9+
#endif
10+
11+
#include <stdint.h>
12+
#include <assert.h>
13+
14+
// Reg - atxmega_spi::CTRL
15+
#define ATXMEGA_SPI__CTRL__PRESCALER_bm 0x3
16+
#define ATXMEGA_SPI__CTRL__PRESCALER_bp 0
17+
#define ATXMEGA_SPI__CTRL__PRESCALER_bw 2
18+
#define ATXMEGA_SPI__CTRL__PRESCALER_reset 0x0
19+
#define ATXMEGA_SPI__CTRL__MODE_bm 0xc
20+
#define ATXMEGA_SPI__CTRL__MODE_bp 2
21+
#define ATXMEGA_SPI__CTRL__MODE_bw 2
22+
#define ATXMEGA_SPI__CTRL__MODE_reset 0x0
23+
#define ATXMEGA_SPI__CTRL__MASTER_bm 0x10
24+
#define ATXMEGA_SPI__CTRL__MASTER_bp 4
25+
#define ATXMEGA_SPI__CTRL__MASTER_bw 1
26+
#define ATXMEGA_SPI__CTRL__MASTER_reset 0x0
27+
#define ATXMEGA_SPI__CTRL__DORD_bm 0x20
28+
#define ATXMEGA_SPI__CTRL__DORD_bp 5
29+
#define ATXMEGA_SPI__CTRL__DORD_bw 1
30+
#define ATXMEGA_SPI__CTRL__DORD_reset 0x0
31+
#define ATXMEGA_SPI__CTRL__ENABLE_bm 0x40
32+
#define ATXMEGA_SPI__CTRL__ENABLE_bp 6
33+
#define ATXMEGA_SPI__CTRL__ENABLE_bw 1
34+
#define ATXMEGA_SPI__CTRL__ENABLE_reset 0x0
35+
#define ATXMEGA_SPI__CTRL__CLK2X_bm 0x80
36+
#define ATXMEGA_SPI__CTRL__CLK2X_bp 7
37+
#define ATXMEGA_SPI__CTRL__CLK2X_bw 1
38+
#define ATXMEGA_SPI__CTRL__CLK2X_reset 0x0
39+
40+
// Reg - atxmega_spi::INTCTRL
41+
#define ATXMEGA_SPI__INTCTRL__INTLVL_bm 0x3
42+
#define ATXMEGA_SPI__INTCTRL__INTLVL_bp 0
43+
#define ATXMEGA_SPI__INTCTRL__INTLVL_bw 2
44+
#define ATXMEGA_SPI__INTCTRL__INTLVL_reset 0x0
45+
46+
// Reg - atxmega_spi::STATUS
47+
#define ATXMEGA_SPI__STATUS__WRCOL_bm 0x40
48+
#define ATXMEGA_SPI__STATUS__WRCOL_bp 6
49+
#define ATXMEGA_SPI__STATUS__WRCOL_bw 1
50+
#define ATXMEGA_SPI__STATUS__WRCOL_reset 0x0
51+
#define ATXMEGA_SPI__STATUS__IF_bm 0x80
52+
#define ATXMEGA_SPI__STATUS__IF_bp 7
53+
#define ATXMEGA_SPI__STATUS__IF_bw 1
54+
#define ATXMEGA_SPI__STATUS__IF_reset 0x0
55+
56+
// Reg - atxmega_spi::DATA
57+
#define ATXMEGA_SPI__DATA__WDATA_bm 0xff
58+
#define ATXMEGA_SPI__DATA__WDATA_bp 0
59+
#define ATXMEGA_SPI__DATA__WDATA_bw 8
60+
#define ATXMEGA_SPI__DATA__RDATA_bm 0xff
61+
#define ATXMEGA_SPI__DATA__RDATA_bp 0
62+
#define ATXMEGA_SPI__DATA__RDATA_bw 8
63+
64+
// Addrmap - atxmega_spi
65+
typedef struct __attribute__ ((__packed__)) {
66+
uint8_t CTRL;
67+
uint8_t INTCTRL;
68+
uint8_t STATUS;
69+
uint8_t DATA;
70+
} atxmega_spi_t;
71+
72+
73+
static_assert(sizeof(atxmega_spi_t) == 0x4, "Packing error");
74+
75+
#ifdef __cplusplus
76+
}
77+
#endif
78+
79+
#endif /* ATXMEGA_SPI_H */

examples/atxmega_spi_bf.h

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
// Generated by PeakRDL-cheader - A free and open-source header generator
2+
// https://github.com/SystemRDL/PeakRDL-cheader
3+
4+
#ifndef ATXMEGA_SPI_BF_H
5+
#define ATXMEGA_SPI_BF_H
6+
7+
#ifdef __cplusplus
8+
extern "C" {
9+
#endif
10+
11+
#include <stdint.h>
12+
#include <assert.h>
13+
14+
// Reg - atxmega_spi::CTRL
15+
#define ATXMEGA_SPI__CTRL__PRESCALER_bm 0x3
16+
#define ATXMEGA_SPI__CTRL__PRESCALER_bp 0
17+
#define ATXMEGA_SPI__CTRL__PRESCALER_bw 2
18+
#define ATXMEGA_SPI__CTRL__PRESCALER_reset 0x0
19+
#define ATXMEGA_SPI__CTRL__MODE_bm 0xc
20+
#define ATXMEGA_SPI__CTRL__MODE_bp 2
21+
#define ATXMEGA_SPI__CTRL__MODE_bw 2
22+
#define ATXMEGA_SPI__CTRL__MODE_reset 0x0
23+
#define ATXMEGA_SPI__CTRL__MASTER_bm 0x10
24+
#define ATXMEGA_SPI__CTRL__MASTER_bp 4
25+
#define ATXMEGA_SPI__CTRL__MASTER_bw 1
26+
#define ATXMEGA_SPI__CTRL__MASTER_reset 0x0
27+
#define ATXMEGA_SPI__CTRL__DORD_bm 0x20
28+
#define ATXMEGA_SPI__CTRL__DORD_bp 5
29+
#define ATXMEGA_SPI__CTRL__DORD_bw 1
30+
#define ATXMEGA_SPI__CTRL__DORD_reset 0x0
31+
#define ATXMEGA_SPI__CTRL__ENABLE_bm 0x40
32+
#define ATXMEGA_SPI__CTRL__ENABLE_bp 6
33+
#define ATXMEGA_SPI__CTRL__ENABLE_bw 1
34+
#define ATXMEGA_SPI__CTRL__ENABLE_reset 0x0
35+
#define ATXMEGA_SPI__CTRL__CLK2X_bm 0x80
36+
#define ATXMEGA_SPI__CTRL__CLK2X_bp 7
37+
#define ATXMEGA_SPI__CTRL__CLK2X_bw 1
38+
#define ATXMEGA_SPI__CTRL__CLK2X_reset 0x0
39+
typedef union {
40+
struct __attribute__ ((__packed__)) {
41+
uint8_t PRESCALER :2;
42+
uint8_t MODE :2;
43+
uint8_t MASTER :1;
44+
uint8_t DORD :1;
45+
uint8_t ENABLE :1;
46+
uint8_t CLK2X :1;
47+
} f;
48+
uint8_t w;
49+
} atxmega_spi__CTRL_t;
50+
51+
// Reg - atxmega_spi::INTCTRL
52+
#define ATXMEGA_SPI__INTCTRL__INTLVL_bm 0x3
53+
#define ATXMEGA_SPI__INTCTRL__INTLVL_bp 0
54+
#define ATXMEGA_SPI__INTCTRL__INTLVL_bw 2
55+
#define ATXMEGA_SPI__INTCTRL__INTLVL_reset 0x0
56+
typedef union {
57+
struct __attribute__ ((__packed__)) {
58+
uint8_t INTLVL :2;
59+
uint8_t :6;
60+
} f;
61+
uint8_t w;
62+
} atxmega_spi__INTCTRL_t;
63+
64+
// Reg - atxmega_spi::STATUS
65+
#define ATXMEGA_SPI__STATUS__WRCOL_bm 0x40
66+
#define ATXMEGA_SPI__STATUS__WRCOL_bp 6
67+
#define ATXMEGA_SPI__STATUS__WRCOL_bw 1
68+
#define ATXMEGA_SPI__STATUS__WRCOL_reset 0x0
69+
#define ATXMEGA_SPI__STATUS__IF_bm 0x80
70+
#define ATXMEGA_SPI__STATUS__IF_bp 7
71+
#define ATXMEGA_SPI__STATUS__IF_bw 1
72+
#define ATXMEGA_SPI__STATUS__IF_reset 0x0
73+
typedef union {
74+
struct __attribute__ ((__packed__)) {
75+
uint8_t :6;
76+
uint8_t WRCOL :1;
77+
uint8_t IF :1;
78+
} f;
79+
uint8_t w;
80+
} atxmega_spi__STATUS_t;
81+
82+
// Reg - atxmega_spi::DATA
83+
#define ATXMEGA_SPI__DATA__WDATA_bm 0xff
84+
#define ATXMEGA_SPI__DATA__WDATA_bp 0
85+
#define ATXMEGA_SPI__DATA__WDATA_bw 8
86+
#define ATXMEGA_SPI__DATA__RDATA_bm 0xff
87+
#define ATXMEGA_SPI__DATA__RDATA_bp 0
88+
#define ATXMEGA_SPI__DATA__RDATA_bw 8
89+
typedef union {
90+
struct __attribute__ ((__packed__)) {
91+
uint8_t RDATA :8;
92+
} fr;
93+
struct __attribute__ ((__packed__)) {
94+
uint8_t WDATA :8;
95+
} fw;
96+
uint8_t w;
97+
} atxmega_spi__DATA_t;
98+
99+
// Addrmap - atxmega_spi
100+
typedef struct __attribute__ ((__packed__)) {
101+
atxmega_spi__CTRL_t CTRL;
102+
atxmega_spi__INTCTRL_t INTCTRL;
103+
atxmega_spi__STATUS_t STATUS;
104+
atxmega_spi__DATA_t DATA;
105+
} atxmega_spi_t;
106+
107+
108+
static_assert(sizeof(atxmega_spi_t) == 0x4, "Packing error");
109+
110+
#ifdef __cplusplus
111+
}
112+
#endif
113+
114+
#endif /* ATXMEGA_SPI_BF_H */

0 commit comments

Comments
 (0)