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