Skip to content

Commit

Permalink
Add C header examples
Browse files Browse the repository at this point in the history
  • Loading branch information
amykyta3 committed Oct 18, 2023
1 parent d2cc64c commit bdec003
Show file tree
Hide file tree
Showing 3 changed files with 209 additions and 0 deletions.
16 changes: 16 additions & 0 deletions docs/gallery.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@ Input: `atxmega_spi.rdl <https://github.com/SystemRDL/PeakRDL/tree/main/examples
Result: `atxmega_uvm_pkg.sv <https://github.com/SystemRDL/PeakRDL/blob/main/examples/atxmega_spi_uvm_pkg.sv>`_


Generate C headers for software
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. code-block:: bash
peakrdl c-header atxmega_spi.rdl -o atxmega_spi.h
# .. Or with bit-fields
peakrdl c-header atxmega_spi.rdl -o atxmega_spi_bf.h --bitfields ltoh
Input: `atxmega_spi.rdl <https://github.com/SystemRDL/PeakRDL/tree/main/examples/atxmega_spi.rdl>`_

Result: `atxmega_spi.h <https://github.com/SystemRDL/PeakRDL/blob/main/examples/atxmega_spi.h>`_ &
`atxmega_spi_bf.h <https://github.com/SystemRDL/PeakRDL/blob/main/examples/atxmega_spi_bf.h>`_


Convert to IP-XACT XML
^^^^^^^^^^^^^^^^^^^^^^
.. code-block:: bash
Expand Down
79 changes: 79 additions & 0 deletions examples/atxmega_spi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Generated by PeakRDL-cheader - A free and open-source header generator
// https://github.com/SystemRDL/PeakRDL-cheader

#ifndef ATXMEGA_SPI_H
#define ATXMEGA_SPI_H

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>
#include <assert.h>

// Reg - atxmega_spi::CTRL
#define ATXMEGA_SPI__CTRL__PRESCALER_bm 0x3
#define ATXMEGA_SPI__CTRL__PRESCALER_bp 0
#define ATXMEGA_SPI__CTRL__PRESCALER_bw 2
#define ATXMEGA_SPI__CTRL__PRESCALER_reset 0x0
#define ATXMEGA_SPI__CTRL__MODE_bm 0xc
#define ATXMEGA_SPI__CTRL__MODE_bp 2
#define ATXMEGA_SPI__CTRL__MODE_bw 2
#define ATXMEGA_SPI__CTRL__MODE_reset 0x0
#define ATXMEGA_SPI__CTRL__MASTER_bm 0x10
#define ATXMEGA_SPI__CTRL__MASTER_bp 4
#define ATXMEGA_SPI__CTRL__MASTER_bw 1
#define ATXMEGA_SPI__CTRL__MASTER_reset 0x0
#define ATXMEGA_SPI__CTRL__DORD_bm 0x20
#define ATXMEGA_SPI__CTRL__DORD_bp 5
#define ATXMEGA_SPI__CTRL__DORD_bw 1
#define ATXMEGA_SPI__CTRL__DORD_reset 0x0
#define ATXMEGA_SPI__CTRL__ENABLE_bm 0x40
#define ATXMEGA_SPI__CTRL__ENABLE_bp 6
#define ATXMEGA_SPI__CTRL__ENABLE_bw 1
#define ATXMEGA_SPI__CTRL__ENABLE_reset 0x0
#define ATXMEGA_SPI__CTRL__CLK2X_bm 0x80
#define ATXMEGA_SPI__CTRL__CLK2X_bp 7
#define ATXMEGA_SPI__CTRL__CLK2X_bw 1
#define ATXMEGA_SPI__CTRL__CLK2X_reset 0x0

// Reg - atxmega_spi::INTCTRL
#define ATXMEGA_SPI__INTCTRL__INTLVL_bm 0x3
#define ATXMEGA_SPI__INTCTRL__INTLVL_bp 0
#define ATXMEGA_SPI__INTCTRL__INTLVL_bw 2
#define ATXMEGA_SPI__INTCTRL__INTLVL_reset 0x0

// Reg - atxmega_spi::STATUS
#define ATXMEGA_SPI__STATUS__WRCOL_bm 0x40
#define ATXMEGA_SPI__STATUS__WRCOL_bp 6
#define ATXMEGA_SPI__STATUS__WRCOL_bw 1
#define ATXMEGA_SPI__STATUS__WRCOL_reset 0x0
#define ATXMEGA_SPI__STATUS__IF_bm 0x80
#define ATXMEGA_SPI__STATUS__IF_bp 7
#define ATXMEGA_SPI__STATUS__IF_bw 1
#define ATXMEGA_SPI__STATUS__IF_reset 0x0

// Reg - atxmega_spi::DATA
#define ATXMEGA_SPI__DATA__WDATA_bm 0xff
#define ATXMEGA_SPI__DATA__WDATA_bp 0
#define ATXMEGA_SPI__DATA__WDATA_bw 8
#define ATXMEGA_SPI__DATA__RDATA_bm 0xff
#define ATXMEGA_SPI__DATA__RDATA_bp 0
#define ATXMEGA_SPI__DATA__RDATA_bw 8

// Addrmap - atxmega_spi
typedef struct __attribute__ ((__packed__)) {
uint8_t CTRL;
uint8_t INTCTRL;
uint8_t STATUS;
uint8_t DATA;
} atxmega_spi_t;


static_assert(sizeof(atxmega_spi_t) == 0x4, "Packing error");

#ifdef __cplusplus
}
#endif

#endif /* ATXMEGA_SPI_H */
114 changes: 114 additions & 0 deletions examples/atxmega_spi_bf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// Generated by PeakRDL-cheader - A free and open-source header generator
// https://github.com/SystemRDL/PeakRDL-cheader

#ifndef ATXMEGA_SPI_BF_H
#define ATXMEGA_SPI_BF_H

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>
#include <assert.h>

// Reg - atxmega_spi::CTRL
#define ATXMEGA_SPI__CTRL__PRESCALER_bm 0x3
#define ATXMEGA_SPI__CTRL__PRESCALER_bp 0
#define ATXMEGA_SPI__CTRL__PRESCALER_bw 2
#define ATXMEGA_SPI__CTRL__PRESCALER_reset 0x0
#define ATXMEGA_SPI__CTRL__MODE_bm 0xc
#define ATXMEGA_SPI__CTRL__MODE_bp 2
#define ATXMEGA_SPI__CTRL__MODE_bw 2
#define ATXMEGA_SPI__CTRL__MODE_reset 0x0
#define ATXMEGA_SPI__CTRL__MASTER_bm 0x10
#define ATXMEGA_SPI__CTRL__MASTER_bp 4
#define ATXMEGA_SPI__CTRL__MASTER_bw 1
#define ATXMEGA_SPI__CTRL__MASTER_reset 0x0
#define ATXMEGA_SPI__CTRL__DORD_bm 0x20
#define ATXMEGA_SPI__CTRL__DORD_bp 5
#define ATXMEGA_SPI__CTRL__DORD_bw 1
#define ATXMEGA_SPI__CTRL__DORD_reset 0x0
#define ATXMEGA_SPI__CTRL__ENABLE_bm 0x40
#define ATXMEGA_SPI__CTRL__ENABLE_bp 6
#define ATXMEGA_SPI__CTRL__ENABLE_bw 1
#define ATXMEGA_SPI__CTRL__ENABLE_reset 0x0
#define ATXMEGA_SPI__CTRL__CLK2X_bm 0x80
#define ATXMEGA_SPI__CTRL__CLK2X_bp 7
#define ATXMEGA_SPI__CTRL__CLK2X_bw 1
#define ATXMEGA_SPI__CTRL__CLK2X_reset 0x0
typedef union {
struct __attribute__ ((__packed__)) {
uint8_t PRESCALER :2;
uint8_t MODE :2;
uint8_t MASTER :1;
uint8_t DORD :1;
uint8_t ENABLE :1;
uint8_t CLK2X :1;
} f;
uint8_t w;
} atxmega_spi__CTRL_t;

// Reg - atxmega_spi::INTCTRL
#define ATXMEGA_SPI__INTCTRL__INTLVL_bm 0x3
#define ATXMEGA_SPI__INTCTRL__INTLVL_bp 0
#define ATXMEGA_SPI__INTCTRL__INTLVL_bw 2
#define ATXMEGA_SPI__INTCTRL__INTLVL_reset 0x0
typedef union {
struct __attribute__ ((__packed__)) {
uint8_t INTLVL :2;
uint8_t :6;
} f;
uint8_t w;
} atxmega_spi__INTCTRL_t;

// Reg - atxmega_spi::STATUS
#define ATXMEGA_SPI__STATUS__WRCOL_bm 0x40
#define ATXMEGA_SPI__STATUS__WRCOL_bp 6
#define ATXMEGA_SPI__STATUS__WRCOL_bw 1
#define ATXMEGA_SPI__STATUS__WRCOL_reset 0x0
#define ATXMEGA_SPI__STATUS__IF_bm 0x80
#define ATXMEGA_SPI__STATUS__IF_bp 7
#define ATXMEGA_SPI__STATUS__IF_bw 1
#define ATXMEGA_SPI__STATUS__IF_reset 0x0
typedef union {
struct __attribute__ ((__packed__)) {
uint8_t :6;
uint8_t WRCOL :1;
uint8_t IF :1;
} f;
uint8_t w;
} atxmega_spi__STATUS_t;

// Reg - atxmega_spi::DATA
#define ATXMEGA_SPI__DATA__WDATA_bm 0xff
#define ATXMEGA_SPI__DATA__WDATA_bp 0
#define ATXMEGA_SPI__DATA__WDATA_bw 8
#define ATXMEGA_SPI__DATA__RDATA_bm 0xff
#define ATXMEGA_SPI__DATA__RDATA_bp 0
#define ATXMEGA_SPI__DATA__RDATA_bw 8
typedef union {
struct __attribute__ ((__packed__)) {
uint8_t RDATA :8;
} fr;
struct __attribute__ ((__packed__)) {
uint8_t WDATA :8;
} fw;
uint8_t w;
} atxmega_spi__DATA_t;

// Addrmap - atxmega_spi
typedef struct __attribute__ ((__packed__)) {
atxmega_spi__CTRL_t CTRL;
atxmega_spi__INTCTRL_t INTCTRL;
atxmega_spi__STATUS_t STATUS;
atxmega_spi__DATA_t DATA;
} atxmega_spi_t;


static_assert(sizeof(atxmega_spi_t) == 0x4, "Packing error");

#ifdef __cplusplus
}
#endif

#endif /* ATXMEGA_SPI_BF_H */

0 comments on commit bdec003

Please sign in to comment.