Skip to content

Commit e587f0e

Browse files
[DPI] SPI DPI renamed to SPI device DPI
This is useful for systems with both a SPI host and device. In those systems there will be a separate DPI emulating a device and a host respectively. The SPI DPI here is renamed as SPI device DPI because it emulates a device for the SPI host integrated in Sonata.
1 parent 3deebd8 commit e587f0e

11 files changed

Lines changed: 65 additions & 65 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ enum {
2222
};
2323

2424
void spi_flash::reset() {
25-
spidpi::reset();
25+
spidevicedpi::reset();
2626
bProgramming = false;
2727
bReading = false;
2828
bErasing = false;
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44

55
#include <string.h>
66

7-
#include "spidpi.hh"
7+
#include "spidevicedpi.hh"
88

99
// ----------------------- SPI Flash model ---------------------
10-
class spi_flash : public spidpi {
10+
class spi_flash : public spidevicedpi {
1111
public:
1212
spi_flash(unsigned dataW, // Number of data lines.
1313
unsigned oobInW, // Width of Out-Of-Band input data (bits).
1414
unsigned oobOutW, // Width of Out-Of-Band output data (bits).
1515
uint32_t jedec_id) : // The JEDEC ID of the flash device.
16-
spidpi(dataW, oobInW, oobOutW), jedec_id(jedec_id) {
16+
spidevicedpi(dataW, oobInW, oobOutW), jedec_id(jedec_id) {
1717
reset();
1818
}
1919

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ typedef enum {
7474
// --------
7575

7676
void spi_lcd::reset() {
77-
spidpi::reset();
77+
spidevicedpi::reset();
7878

7979
cmdLen = 0u;
8080
xEnd = xStart = 0u;
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66

77
#include <string>
88

9-
#include "spidpi.hh"
9+
#include "spidevicedpi.hh"
1010

1111
// -------------------- ST7735 LCD model --------------------
12-
class spi_lcd : public spidpi {
12+
class spi_lcd : public spidevicedpi {
1313
public:
1414
spi_lcd(unsigned dataW, // Number of data lines.
1515
unsigned oobInW, // Width of Out-Of-Band input data (bits).
1616
unsigned oobOutW) : // Width of Out-Of-Band output data (bits).
17-
spidpi(dataW, oobInW, oobOutW) {
17+
spidevicedpi(dataW, oobInW, oobOutW) {
1818
reset();
1919
}
2020

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ enum {
4545
static const bool kMustHaveSD = false;
4646

4747
void spi_microsd::reset() {
48-
spidpi::reset();
48+
spidevicedpi::reset();
4949
cmdBytes = 0u;
5050
responding = false;
5151
reading = false;
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44

55
#include <assert.h>
66
#include <stdio.h>
7-
#include "spidpi.hh"
7+
#include "spidevicedpi.hh"
88

99
// -------------------------- SPI microSD model -------------------------------
10-
class spi_microsd : public spidpi {
10+
class spi_microsd : public spidevicedpi {
1111
public:
1212
spi_microsd(unsigned dataW, // Number of data lines.
1313
unsigned oobInW, // Width of Out-Of-Band input data (bits).
1414
unsigned oobOutW, // Width of Out-Of-Band output data (bits).
1515
const char *sdFile, // Filename of the SD card image.
1616
bool log = false) : // Enable diagnostic logging?
17-
spidpi(dataW, oobInW, oobOutW, log) {
17+
spidevicedpi(dataW, oobInW, oobOutW, log) {
1818
assert(sdFile);
1919
logText("microSD model attempting to open image '%s'\n", sdFile);
2020
sd = fopen(sdFile, "r+b");
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "spi_lcd.hh"
1111
#include "spi_microsd.hh"
1212

13-
void spidpi::reset() {
13+
void spidevicedpi::reset() {
1414
// Write data to device (COPI).
1515
inByte = 0u;
1616
inBits = 0u;
@@ -23,7 +23,7 @@ void spidpi::reset() {
2323
// Sampling transition occurred on the SCK line.
2424
// - the function is supplied with the CS, the new COPI data for a write operation as well as the
2525
// Out-Of-Band input signals.
26-
void spidpi::sampleEdge(uint32_t cs, uint32_t copi, uint32_t oobIn) {
26+
void spidevicedpi::sampleEdge(uint32_t cs, uint32_t copi, uint32_t oobIn) {
2727
// Suppress traffic if CS is high because the current SPI model ignores CS.
2828
if ((cs & 1u)) {
2929
return;
@@ -41,7 +41,7 @@ void spidpi::sampleEdge(uint32_t cs, uint32_t copi, uint32_t oobIn) {
4141
// - the function is supplied with the CS, and the Out-Of-Band input signals.
4242
// - the result sets the Out-of-Band output signals (upper bits) and the CIPO data lines (LSBs) if
4343
// the device is producing read data.
44-
uint32_t spidpi::launchEdge(uint32_t cs, uint32_t oobIn) {
44+
uint32_t spidevicedpi::launchEdge(uint32_t cs, uint32_t oobIn) {
4545
unsigned cipo = 1;
4646
// Suppress traffic if CS is high because the current SPI model ignores CS.
4747
if (cs & 1u) {
@@ -61,13 +61,13 @@ uint32_t spidpi::launchEdge(uint32_t cs, uint32_t oobIn) {
6161
}
6262

6363
// Transition on one or more CS lines.
64-
void spidpi::csEdge(uint32_t cs, uint32_t oobIn) {
64+
void spidevicedpi::csEdge(uint32_t cs, uint32_t oobIn) {
6565
// Inform the appropriate device(s) of the change the CS line state.
6666
csChanged(!(cs & 1u), oobIn);
6767
}
6868

6969
// Logging utility function.
70-
void spidpi::logText(const char *fmt, ...) {
70+
void spidevicedpi::logText(const char *fmt, ...) {
7171
if (logging) {
7272
va_list va;
7373
va_start(va, fmt);
@@ -79,12 +79,12 @@ void spidpi::logText(const char *fmt, ...) {
7979
// Interface is using vanilla C, so these functions collect the object pointer.
8080
extern "C" {
8181
// SPI DPI initialisation.
82-
void *spidpi_create(const char *id, // Bus identification.
82+
void *spidevicedpi_create(const char *id, // Bus identification.
8383
unsigned ndevices, // Number of devices on bus (=number of selects).
8484
unsigned dataW, // Number of data lines.
8585
unsigned oobInW, // Width of Out-Of-Band input data (bits).
8686
unsigned oobOutW) { // Width of Out-Of-Band output data (bits).
87-
spidpi *ctx = nullptr;
87+
spidevicedpi *ctx = nullptr;
8888
// TODO: at present we attach only a single device to each SPI bus.
8989
assert(ndevices == 1u);
9090
// Attach the appropriate devices to this bus.
@@ -97,39 +97,39 @@ void *spidpi_create(const char *id, // Bus identification.
9797
} else if (!strcmp(id, "pmod_sf3")) {
9898
ctx = new spi_flash(dataW, oobInW, oobOutW, 0x20ba19);
9999
} else {
100-
ctx = new spidpi(dataW, oobInW, oobOutW, true);
100+
ctx = new spidevicedpi(dataW, oobInW, oobOutW, true);
101101
ctx->logText("Warning: SPI bus '%s' not recognised", id);
102102
}
103103
assert(ctx);
104104
return (void*)ctx;
105105
}
106106

107107
// SPI DPI finalisation.
108-
void spidpi_destroy(void *ctx_v) {
109-
spidpi *ctx = (spidpi*)ctx_v;
108+
void spidevicedpi_destroy(void *ctx_v) {
109+
spidevicedpi *ctx = (spidevicedpi*)ctx_v;
110110
assert(ctx);
111111
delete ctx;
112112
}
113113

114114
// Sampling transition on the SCK line.
115-
void spidpi_sampleEdge(void *ctx_v, uint32_t cs, uint32_t copi, uint32_t oobIn) {
116-
spidpi *ctx = (spidpi*)ctx_v;
115+
void spidevicedpi_sampleEdge(void *ctx_v, uint32_t cs, uint32_t copi, uint32_t oobIn) {
116+
spidevicedpi *ctx = (spidevicedpi*)ctx_v;
117117
assert(ctx);
118118
ctx->sampleEdge(cs, copi, oobIn);
119119
}
120120

121121
// Launch transition on the SCK line.
122-
uint32_t spidpi_launchEdge(void *ctx_v, uint32_t cs, uint32_t oobIn) {
123-
spidpi *ctx = (spidpi*)ctx_v;
122+
uint32_t spidevicedpi_launchEdge(void *ctx_v, uint32_t cs, uint32_t oobIn) {
123+
spidevicedpi *ctx = (spidevicedpi*)ctx_v;
124124
assert(ctx);
125125
return ctx->launchEdge(cs, oobIn);
126126
}
127127

128128
// Note: This interface is presently inadequate for modelling some devices because they will need
129129
// to know when the CS signal becomes deasserted, and there will not necessarily be a clock
130130
// assertion whilst CS is deasserted.
131-
void spidpi_csEdge(void *ctx_v, uint32_t cs, uint32_t oobIn) {
132-
spidpi *ctx = (spidpi*)ctx_v;
131+
void spidevicedpi_csEdge(void *ctx_v, uint32_t cs, uint32_t oobIn) {
132+
spidevicedpi *ctx = (spidevicedpi*)ctx_v;
133133
assert(ctx);
134134
return ctx->csEdge(cs, oobIn);
135135
}
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,28 @@
22
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
33
// SPDX-License-Identifier: Apache-2.0
44

5-
#ifndef __DV_DPI_SPIDPI_H_
6-
#define __DV_DPI_SPIDPI_H_
5+
#ifndef __DV_DPI_SPIDEVICEDPI_H_
6+
#define __DV_DPI_SPIDEVICEDPI_H_
77
#include <stdint.h>
88

99
// SPI DPI model - this model is supplied with all of the signals and information required to
1010
// support multiple devices on a single SPI bus, but presently the Sonata system employs only a
11-
// single device per bus. Therefore, at present, the SPI device models derive from `spidpi`
11+
// single device per bus. Therefore, at present, the SPI device models derive from `spidevicedpi`
1212
// directly.
1313
//
1414
// If multiple devices are required to share a single bus then a `spi_device` base class may be
15-
// introduced and an instance of `spidpi` will handling the mapping from `cs` line to `spi_device`
15+
// introduced and an instance of `spidevicedpi` will handling the mapping from `cs` line to `spi_device`
1616
// object.
17-
class spidpi {
17+
class spidevicedpi {
1818
public:
19-
spidpi(unsigned dataw, // Number of data lines.
19+
spidevicedpi(unsigned dataw, // Number of data lines.
2020
unsigned oobInw, // Width of Out-Of-Band input data (bits).
2121
unsigned oobOutw, // Width of Out-Of-Band output data (bits).
2222
bool log = false) {
2323
logging = log;
2424
reset();
2525
}
26-
virtual ~spidpi() { }
26+
virtual ~spidevicedpi() { }
2727

2828
// Sampling transition occurred on the SCK line.
2929
void sampleEdge(uint32_t cs, uint32_t copi, uint32_t oobIn);
@@ -71,4 +71,4 @@ private:
7171
// Most recent Out-Of-Band output data.
7272
uint32_t oobOut;
7373
};
74-
#endif // __DV_DPI_SPIDPI_H_
74+
#endif // __DV_DPI_SPIDEVICEDPI_H_
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// so the device launches data on the falling edge.
88
// - the SPI controller within the Sonata system does support other modes of operation but these
99
// are not presently required by the devices that are being simulated.
10-
module spidpi #(
10+
module spidevicedpi #(
1111
// Device identification.
1212
parameter string ID = "generic",
1313
// Number of SPI devices on the bus (= number of chip selects).
@@ -36,26 +36,26 @@ module spidpi #(
3636
chandle ctx;
3737

3838
// Note: The imported DPI-C functions use 'int unsigned' for their parameters rather than
39-
// parameterising their widths because the module `spidpi` is multiply-instantiated and that would
39+
// parameterising their widths because the module `spidevicedpi` is multiply-instantiated and that would
4040
// lead to Verilator complaining about multiple incompatible signatures for each imported function.
4141

4242
// SPI DPI initialisation; DPI model is supplied with the device identification string and the
4343
// properties of the physical connections.
4444
import "DPI-C" function
45-
chandle spidpi_create(input string name, // Device identification string.
45+
chandle spidevicedpi_create(input string name, // Device identification string.
4646
input int ndevices, // Number of devices on bus (= number of selects).
4747
input int dataW, // Number of data lines.
4848
input int oobIntW, // Width of Out-Of-Band input data (bits).
4949
input int oobOutW); // Width of Out-Of-Band output data (bits).
5050
// SPI DPI finalisation.
5151
import "DPI-C" function
52-
void spidpi_destroy(input chandle ctx);
52+
void spidevicedpi_destroy(input chandle ctx);
5353

5454
// Sampling transition occurred on the SCK line.
5555
// - the function is supplied with the new COPI data for a write operation as well as the
5656
// Out-Of-Band input signals.
5757
import "DPI-C" function
58-
void spidpi_sampleEdge(input chandle ctx,
58+
void spidevicedpi_sampleEdge(input chandle ctx,
5959
input int unsigned cs, // Chip Selects.
6060
input int unsigned copi, // Write data from controller.
6161
input int unsigned oob_in); // Out-Of-Band inputs.
@@ -65,43 +65,43 @@ import "DPI-C" function
6565
// - the result is used to set the new state of the Out-Of-Band output signals (upper bits) and the
6666
// read data line(s) to the controller (CIPO).
6767
import "DPI-C" function
68-
bit [OOB_OutW+DataW-1:0] spidpi_launchEdge(input chandle ctx,
68+
bit [OOB_OutW+DataW-1:0] spidevicedpi_launchEdge(input chandle ctx,
6969
input int unsigned cs, // Chip Selects.
7070
input int unsigned oob_in); // Out-Of-Band inputs.
7171

7272
// Report a transition on the CS lines; some devices need to be aware of deselection so that an
7373
// ongoing write/read operation may be terminated and a new command accepted.
7474
// - the function is supplied with the new state of the CS lines and the Out-Of-Band input signals.
7575
import "DPI-C" function
76-
void spidpi_csEdge(input chandle ctx,
76+
void spidevicedpi_csEdge(input chandle ctx,
7777
input int unsigned cs, // Chip Selects.
7878
input int unsigned oob_in); // Out-Of-Band inputs.
7979

8080
// Initialisation of DPI model.
8181
initial begin
82-
ctx = spidpi_create(ID, NDevices, DataW, OOB_InW, OOB_OutW);
82+
ctx = spidevicedpi_create(ID, NDevices, DataW, OOB_InW, OOB_OutW);
8383
end
8484
// Finalisation of DPI model.
8585
final begin
86-
spidpi_destroy(ctx);
86+
spidevicedpi_destroy(ctx);
8787
end
8888

8989
// Sampling of write data into the device (COPI).
9090
always_ff @(posedge sck or negedge rst_ni) begin
9191
// Do not invoke the device logic within reset
92-
if (rst_ni) spidpi_sampleEdge(ctx, 32'(cs), 32'(copi), 32'(oob_in));
92+
if (rst_ni) spidevicedpi_sampleEdge(ctx, 32'(cs), 32'(copi), 32'(oob_in));
9393
end
9494

9595
// Launching of read data from the device (CIPO).
9696
logic [OOB_OutW+DataW-1:0] out_q;
9797
always_ff @(negedge sck or negedge rst_ni) begin
9898
if (!rst_ni) out_q <= '0;
99-
else out_q <= spidpi_launchEdge(ctx, 32'(cs), 32'(oob_in));
99+
else out_q <= spidevicedpi_launchEdge(ctx, 32'(cs), 32'(oob_in));
100100
end
101101

102102
// Report transitions on the CS lines.
103103
always @(cs) begin
104-
spidpi_csEdge(ctx, 32'(cs), 32'(oob_in));
104+
spidevicedpi_csEdge(ctx, 32'(cs), 32'(oob_in));
105105
end
106106

107107
assign {oob_out, cipo} = out_q;

dv/verilator/top_verilator.sv

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -562,13 +562,13 @@ module top_verilator #(
562562
);
563563

564564
// SPI connection to flash.
565-
spidpi #(
565+
spidevicedpi #(
566566
.ID ("flash"),
567567
.NDevices (1),
568568
.DataW (1),
569569
.OOB_InW (2),
570570
.OOB_OutW (1)
571-
) u_spidpi_flash (
571+
) u_spidevicedpi_flash (
572572
.rst_ni (rst_ni),
573573

574574
.sck (appspi_clk),
@@ -581,13 +581,13 @@ module top_verilator #(
581581
);
582582

583583
// SPI connection to LCD.
584-
spidpi #(
584+
spidevicedpi #(
585585
.ID ("lcd"),
586586
.NDevices (1),
587587
.DataW (1),
588588
.OOB_InW (3),
589589
.OOB_OutW (1)
590-
) u_spidpi_lcd (
590+
) u_spidevicedpi_lcd (
591591
.rst_ni (rst_ni),
592592

593593
.sck (lcd_clk),
@@ -600,13 +600,13 @@ module top_verilator #(
600600
);
601601

602602
// SPI connection to microSD card.
603-
spidpi #(
603+
spidevicedpi #(
604604
.ID ("microsd"),
605605
.NDevices (1),
606606
.DataW (1),
607607
.OOB_InW (1),
608608
.OOB_OutW (1)
609-
) u_spidpi_microsd (
609+
) u_spidevicedpi_microsd (
610610
.rst_ni (rst_ni),
611611

612612
.sck (microsd_clk),
@@ -619,13 +619,13 @@ module top_verilator #(
619619
);
620620

621621
// SPI connection to PMOD SF3 flash via PMOD1 pins
622-
spidpi #(
622+
spidevicedpi #(
623623
.ID ("pmod_sf3"),
624624
.NDevices (1),
625625
.DataW (1),
626626
.OOB_InW (2),
627627
.OOB_OutW (1)
628-
) u_spidpi_pmod_sf3 (
628+
) u_spidevicedpi_pmod_sf3 (
629629
.rst_ni (rst_ni),
630630

631631
.sck (sck_pmod1_out),

0 commit comments

Comments
 (0)