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