TEMU  3.0
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 <stdint.h>
13 #include <stddef.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;
40 
41 typedef struct {
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);
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);
59 #define TEMU_SPI_SLAVE_DEV_IFACE_TYPE "temu::SpiSlaveDeviceIface"
60 
61 typedef struct {
63  temu_SpiSlaveDeviceIfaceRefArray SpiSlaveDevices;
64  temu_SpiMasterDeviceIfaceRef SpiMasterDevice;
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);
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),
97  1, // Number of elements (1 = scalar)
98  NULL, NULL, "eSpi master communication Iface");
100 
101  temu_addProperty(C, "spiSlaveDevices", offsetof(temu_SpiBus, SpiSlaveDevices),
102  teTY_IfaceRefArray, 1, NULL, NULL,
103  "eSPI slave devices");
104 
105  temu_addProperty(C, "currentChipNumber",
106  offsetof(temu_SpiBus, CurrentChipNum), teTY_U8,
107  1, // Number of elements (1 = scalar)
108  NULL, NULL, "Last chosen chip");
109 }
110 
111 #endif // !TEMU_BUS_SPI_H
temu_SpiMasterDeviceIfaceRef SpiMasterDevice
Definition: SPI.h:64
#define TEMU_IFACE_REFERENCE_TYPE(N)
Definition: Objsys.h:180
Interface reference.
Definition: Objsys.h:311
TEMU_API void temu_addProperty(temu_Class *Cls, const char *PropName, int Offset, temu_Type Typ, int Count, temu_PropWriter Wr, temu_PropReader Rd, const char *Doc)
Definition: SPI.h:41
Definition: SPI.h:36
Definition: SPI.h:61
uint8_t chipNum
Definition: SPI.h:38
Definition: SPI.h:46
temu_Object Super
Definition: SPI.h:42
uint8_t charLength
Definition: SPI.h:37
#define TEMU_SPI_MASTER_IFACE_TYPE
Definition: SPI.h:52
Definition: Objsys.h:435
TEMU_API void temu_requireInterface(temu_Class *Cls, const char *PropName, const char *IfaceType)
temu_SpiDevConfig DevParams
Definition: SPI.h:43
Definition: SPI.h:68
Definition: Objsys.h:82
8-bit fixed width unsigned integer
Definition: Objsys.h:294
temu_Object Super
Definition: SPI.h:62
temu_SpiSlaveDeviceIfaceRefArray SpiSlaveDevices
Definition: SPI.h:63
uint8_t CurrentChipNum
Definition: SPI.h:65
Definition: SPI.h:54
Dynamic object/interface array.
Definition: Objsys.h:312