TEMU  4.4
The Terma Emulator
SPI.h
Go to the documentation of this file.
1 //===------------------------------------------------------------*- C++ -*-===//
2 //
3 // TEMU: The Terma Emulator
4 // (c) Terma 2021
5 // Authors: Daria Vorotnikova <davo (at) terma.com>
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef TEMU_BUS_SPI_H
10 #define TEMU_BUS_SPI_H
11 #include <assert.h>
12 #include <stddef.h>
13 #include <stdint.h>
14 
15 #include "temu-c/Memory/Memory.h"
16 #include "temu-c/Models/Device.h"
17 #include "temu-c/Support/Logging.h"
18 #include "temu-c/Support/Objsys.h"
19 
20 #define teSPI_WRSR 0x01 // write status register
21 #define teSPI_WRITE 0x02 // write command
22 #define teSPI_READ 0x03 // read command
23 #define teSPI_WDI 0x04 // write disable
24 #define teSPI_STAT 0x05 // read status register
25 #define teSPI_WEN 0x06 // write enable
26 
27 // -------------------------
28 // This header contains names which include master/slave terminology. The TEMU
29 // project does not use such terms normally, however given that the hardware
30 // specification, this header deals with, use these terms they are reused here
31 // for consistency.
32 // Would the hardware specification change the terminology, the
33 // header will be updated in compliance with the TEMU version number policy.
34 // ------------------------
35 
36 typedef struct {
37  uint8_t charLength;
38  uint8_t chipNum;
39 } temu_SpiDevConfig;
40 
41 typedef struct {
43  temu_SpiDevConfig DevParams;
44 } temu_SpiSlaveDevice;
45 
46 typedef struct {
47  void (*send)(temu_Object *, uint8_t *Data, uint32_t size);
48  void (*raiseAlert)(temu_Object *, uint8_t chipNum);
49  void (*lowerAlert)(temu_Object *, uint8_t chipNum);
50 } temu_SpiMasterDeviceIface;
51 TEMU_IFACE_REFERENCE_TYPE(temu_SpiMasterDevice)
52 #define TEMU_SPI_MASTER_IFACE_TYPE "temu::SpiMasterDeviceIface"
53 
54 typedef struct {
55  void (*send)(temu_Object *, uint8_t *Data, uint32_t size, uint32_t configSize,
56  uint32_t responseSize);
57 } temu_SpiSlaveDeviceIface;
58 TEMU_IFACE_REFERENCE_TYPE(temu_SpiSlaveDevice)
59 #define TEMU_SPI_SLAVE_DEV_IFACE_TYPE "temu::SpiSlaveDeviceIface"
60 
61 typedef struct {
65  uint8_t CurrentChipNum;
66 } temu_SpiBus;
67 
68 typedef struct {
69  void (*raiseAlert)(temu_Object *, uint8_t chipNum);
70  void (*lowerAlert)(temu_Object *, uint8_t chipNum);
71  void (*sendToMaster)(temu_Object *, uint8_t *Data, uint32_t size);
72  void (*sendToSlave)(temu_Object *, uint8_t *Data, uint32_t size,
73  uint32_t configSize, uint8_t chipNum,
74  uint32_t responseSize);
75 } temu_SpiBusIface;
76 TEMU_IFACE_REFERENCE_TYPE(temu_SpiBus)
77 #define TEMU_SPI_BUS_IFACE_TYPE "temu::SpiBusIface"
78 
79 static inline void
80 temu_spiDeviceRegister(temu_Class *C)
81 {
82  temu_addProperty(C, "chipNumber",
83  offsetof(temu_SpiSlaveDevice, DevParams.chipNum), teTY_U8,
84  1, // Number of elements (1 = scalar)
85  NULL, NULL, "eSPI device chip id");
86  temu_addProperty(C, "charLength",
87  offsetof(temu_SpiSlaveDevice, DevParams.charLength), teTY_U8,
88  1, // Number of elements (1 = scalar)
89  NULL, NULL, "Character length in bits per character.");
90 }
91 
92 static inline void
93 temu_spiBusRegister(temu_Class *C)
94 {
95  temu_addProperty(C, "spiMasterDevice", offsetof(temu_SpiBus, SpiMasterDevice),
96  teTY_IfaceRef,
97  1, // Number of elements (1 = scalar)
98  NULL, NULL, "eSpi master communication Iface");
99  temu_requireInterface(C, "spiMasterDevice", TEMU_SPI_MASTER_IFACE_TYPE);
100 
101  temu_addProperty(C, "spiSlaveDevices", offsetof(temu_SpiBus, SpiSlaveDevices),
102  teTY_IfaceRefArray, 1, NULL, NULL, "eSPI slave devices");
103 
104  temu_addProperty(C, "currentChipNumber",
105  offsetof(temu_SpiBus, CurrentChipNum), teTY_U8,
106  1, // Number of elements (1 = scalar)
107  NULL, NULL, "Last chosen chip");
108 }
109 
110 typedef struct temu_SpiRomIface {
111  void (*getData)(void *obj, uint64_t offset, size_t *length, uint8_t **data);
112 } temu_SpiRomIface;
113 TEMU_IFACE_REFERENCE_TYPE(temu_SpiRom);
114 #define TEMU_SPI_ROM_IFACE_TYPE "temu::SpiRomIface"
115 
116 #endif // !TEMU_BUS_SPI_H
temu_SpiBusIface::sendToSlave
void(* sendToSlave)(temu_Object *, uint8_t *Data, uint32_t size, uint32_t configSize, uint8_t chipNum, uint32_t responseSize)
Definition: SPI.h:72
temu_SpiRomIface::getData
void(* getData)(void *obj, uint64_t offset, size_t *length, uint8_t **data)
Definition: SPI.h:111
temu_SpiRomIface
Definition: SPI.h:110
temu_SpiBus::Super
temu_Object Super
Definition: SPI.h:62
temu_SpiBusIface::sendToMaster
void(* sendToMaster)(temu_Object *, uint8_t *Data, uint32_t size)
Definition: SPI.h:71
TEMU_SPI_MASTER_IFACE_TYPE
#define TEMU_SPI_MASTER_IFACE_TYPE
Definition: SPI.h:52
temu_SpiBus::SpiSlaveDevices
temu_SpiSlaveDeviceIfaceRefArray SpiSlaveDevices
Definition: SPI.h:63
temu_SpiBus::CurrentChipNum
uint8_t CurrentChipNum
Definition: SPI.h:65
temu_SpiBusIface::raiseAlert
void(* raiseAlert)(temu_Object *, uint8_t chipNum)
Definition: SPI.h:69
temu_SpiBusIface::lowerAlert
void(* lowerAlert)(temu_Object *, uint8_t chipNum)
Definition: SPI.h:70
temu_SpiBus::SpiMasterDevice
temu_SpiMasterDeviceIfaceRef SpiMasterDevice
Definition: SPI.h:64
temu_SpiDevConfig::chipNum
uint8_t chipNum
Definition: SPI.h:38
temu_SpiMasterDeviceIface::send
void(* send)(temu_Object *, uint8_t *Data, uint32_t size)
Definition: SPI.h:47
temu_SpiSlaveDevice::Super
temu_Object Super
Definition: SPI.h:42
temu_SpiMasterDeviceIface::lowerAlert
void(* lowerAlert)(temu_Object *, uint8_t chipNum)
Definition: SPI.h:49
temu_SpiSlaveDevice::DevParams
temu_SpiDevConfig DevParams
Definition: SPI.h:43
temu_SpiDevConfig::charLength
uint8_t charLength
Definition: SPI.h:37
temu_SpiMasterDeviceIface::raiseAlert
void(* raiseAlert)(temu_Object *, uint8_t chipNum)
Definition: SPI.h:48
temu_SpiSlaveDeviceIface::send
void(* send)(temu_Object *, uint8_t *Data, uint32_t size, uint32_t configSize, uint32_t responseSize)
Definition: SPI.h:55