SystemC Library API Reference Manual
Reference documentation for the Simics SystemC Library.
 
Loading...
Searching...
No Matches
spi_slave_simics_adapter.h
Go to the documentation of this file.
1// -*- mode: C++; c-file-style: "virtutech-c++" -*-
2
3/*
4 © 2025 Intel Corporation
5
6 This software and the related documents are Intel copyrighted materials, and
7 your use of them is governed by the express license under which they were
8 provided to you ("License"). Unless the License provides otherwise, you may
9 not use, modify, copy, publish, distribute, disclose or transmit this software
10 or the related documents without Intel's prior written permission.
11
12 This software and the related documents are provided as is, with no express or
13 implied warranties, other than those that are expressly stated in the License.
14*/
15
16#ifndef SIMICS_SYSTEMC_IFACE_SPI_SLAVE_SIMICS_ADAPTER_H
17#define SIMICS_SYSTEMC_IFACE_SPI_SLAVE_SIMICS_ADAPTER_H
18
19#include <simics/devs/serial-peripheral-interface.h>
22
23#include <simics/base/types.h>
24#include <simics/util/dbuffer.h>
25
26#include <string>
27#include <vector>
28
29namespace simics {
30namespace systemc {
31namespace iface {
32
34template<typename TBase, typename TInterface = SpiSlaveInterface>
36 : public SimicsAdapter<serial_peripheral_interface_slave_interface_t> {
37 public:
39 : SimicsAdapter<serial_peripheral_interface_slave_interface_t>(
40 SERIAL_PERIPHERAL_INTERFACE_SLAVE_INTERFACE, init_iface()) {
41 }
42
43 protected:
44 static void spi_request(conf_object_t *obj, int first, int last,
45 int bits, dbuffer_t *payload) {
46 // According to reference manual, "bits defines the number of bits to
47 // send, while payload defines the data to transfer. The size of the
48 // payload buffer should be ceil(bits / 8) bytes."
49 bytes_t data = dbuffer_bytes(payload);
50 if ((bits + 7) / 8 != static_cast<int>(data.len)) {
51 SIM_LOG_ERROR(obj, 0,
52 "Mismatch of the payload buffer size (%lu) %s (%d)",
53 data.len, "with ceil(bits / 8)", (bits + 7) / 8);
54 }
55 adapter<TBase, TInterface>(obj)->spi_request(first, last,
56 data.data, data.len);
57 }
58
59 static void connect_master(conf_object_t *obj, conf_object_t *master,
60 const char *port,
61 serial_peripheral_interface_flags_t flags) {
62 adapter<TBase, TInterface>(obj)->connect_master(master, port, flags);
63 }
64
65 static void disconnect_master(conf_object_t *obj, conf_object_t *master) {
66 adapter<TBase, TInterface>(obj)->disconnect_master(master);
67 }
68
69 private:
70 std::vector<std::string> description(conf_object_t *obj,
71 DescriptionType type) {
72 return descriptionBase<TBase, TInterface>(obj, type);
73 }
74 serial_peripheral_interface_slave_interface_t init_iface() {
75 serial_peripheral_interface_slave_interface_t iface = {};
76 iface.spi_request = spi_request;
77 iface.connect_master = connect_master;
78 iface.disconnect_master = disconnect_master;
79 return iface;
80 }
81};
82
83} // namespace iface
84} // namespace systemc
85} // namespace simics
86
87#endif
Base class for mapping Simics interface to a C++ interface.
Definition: simics_adapter.h:47
Adapter for Simics serial_peripheral_interface_slave interface.
Definition: spi_slave_simics_adapter.h:36
static void spi_request(conf_object_t *obj, int first, int last, int bits, dbuffer_t *payload)
Definition: spi_slave_simics_adapter.h:44
static void connect_master(conf_object_t *obj, conf_object_t *master, const char *port, serial_peripheral_interface_flags_t flags)
Definition: spi_slave_simics_adapter.h:59
static void disconnect_master(conf_object_t *obj, conf_object_t *master)
Definition: spi_slave_simics_adapter.h:65
SpiSlaveSimicsAdapter()
Definition: spi_slave_simics_adapter.h:38
DescriptionType
Definition: description_interface.h:25
Definition: adapter.h:80