SystemC Library API Reference Manual
Reference documentation for the Simics SystemC Library.
 
Loading...
Searching...
No Matches
spi_master_simics_adapter.h
Go to the documentation of this file.
1/*
2 © 2019 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_MASTER_SIMICS_ADAPTER_H
15#define SIMICS_SYSTEMC_IFACE_SPI_MASTER_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 = SpiMasterInterface>
34 : public SimicsAdapter<serial_peripheral_interface_master_interface_t> {
35 public:
37 : SimicsAdapter<serial_peripheral_interface_master_interface_t>(
38 SERIAL_PERIPHERAL_INTERFACE_MASTER_INTERFACE, init_iface()) {
39 }
40
41 protected:
42 static void spi_response(conf_object_t *obj, int bits, dbuffer_t *payload) {
43 // According to reference manual, "bits defines the number of bits to
44 // send, while payload defines the data to transfer. The size of the
45 // payload buffer should be ceil(bits / 8) bytes."
46 bytes_t data = dbuffer_bytes(payload);
47 if ((bits + 7) / 8 != static_cast<int>(data.len)) {
48 SIM_LOG_ERROR(obj, 0,
49 "Mismatch of the payload buffer size (%lu) %s (%d)",
50 data.len, "with ceil(bits / 8)", (bits + 7) / 8);
51 }
52 adapter<TBase, TInterface>(obj)->spi_response(data.data, data.len);
53 }
54
55 private:
56 std::vector<std::string> description(conf_object_t *obj,
57 DescriptionType type) override {
58 return descriptionBase<TBase, TInterface>(obj, type);
59 }
60 serial_peripheral_interface_master_interface_t init_iface() {
61 serial_peripheral_interface_master_interface_t iface = {};
62 iface.spi_response = spi_response;
63 return iface;
64 }
65};
66
67} // namespace iface
68} // namespace systemc
69} // namespace simics
70
71#endif
Base class for mapping Simics interface to a C++ interface.
Definition: simics_adapter.h:45
Adapter for Simics serial_peripheral_interface_master interface.
Definition: spi_master_simics_adapter.h:34
SpiMasterSimicsAdapter()
Definition: spi_master_simics_adapter.h:36
static void spi_response(conf_object_t *obj, int bits, dbuffer_t *payload)
Definition: spi_master_simics_adapter.h:42
DescriptionType
Definition: description_interface.h:23
Definition: adapter.h:79