-
Notifications
You must be signed in to change notification settings - Fork 0
/
contract.h
322 lines (275 loc) · 6.63 KB
/
contract.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <sys/types.h>
#define REMOTEX_CONTRACT_VERSION 7
typedef enum __attribute__((packed))
{
GPIO_OpenAsOutput_c,
GPIO_OpenAsInput_c,
GPIO_SetValue_c,
GPIO_GetValue_c,
I2CMaster_Open_c,
I2CMaster_SetBusSpeed_c,
I2CMaster_SetTimeout_c,
I2CMaster_Write_c,
I2CMaster_WriteThenRead_c,
I2CMaster_Read_c,
I2CMaster_SetDefaultTargetAddress_c,
SPIMaster_Open_c,
SPIMaster_InitConfig_c,
SPIMaster_SetBusSpeed_c,
SPIMaster_SetMode_c,
SPIMaster_SetBitOrder_c,
SPIMaster_WriteThenRead_c,
SPIMaster_TransferSequential_c,
PWM_Open_c,
PWM_Apply_c,
ADC_Open_c,
ADC_GetSampleBitCount_c,
ADC_SetReferenceVoltage_c,
ADC_Poll_c,
Storage_OpenMutableFile_c,
Storage_DeleteMutableFile_c,
RemoteX_Write_c,
RemoteX_Read_c,
RemoteX_Lseek_c,
RemoteX_Close_c,
RemoteX_PlatformInformation_c,
UART_InitConfig_c,
UART_Open_c
} SOCKET_CMD;
typedef struct __attribute__((packed))
{
uint16_t block_length;
uint16_t response_length;
SOCKET_CMD cmd;
bool respond;
uint8_t contract_version;
int32_t err_no;
int32_t returns;
} CTX_HEADER;
typedef struct __attribute__((packed))
{
uint8_t flags;
uint16_t length;
} SPI_TransferConfig;
// Note the data block sent is variable length but not greater that 4096 and must be the last field in control block
typedef struct __attribute__((packed))
{
uint8_t data[4096];
} DATA_BLOCK;
typedef struct __attribute__((packed))
{
CTX_HEADER header;
int32_t gpioId;
uint8_t outputMode;
uint8_t initialValue;
} GPIO_OpenAsOutput_t;
typedef struct __attribute__((packed))
{
CTX_HEADER header;
int32_t gpioId;
} GPIO_OpenAsInput_t;
typedef struct __attribute__((packed))
{
CTX_HEADER header;
int32_t gpioFd;
uint8_t value;
} GPIO_SetValue_t;
typedef struct __attribute__((packed))
{
CTX_HEADER header;
int32_t gpioFd;
uint8_t outValue;
} GPIO_GetValue_t;
typedef struct __attribute__((packed))
{
CTX_HEADER header;
int32_t I2C_InterfaceId;
} I2CMaster_Open_t;
typedef struct __attribute__((packed))
{
CTX_HEADER header;
int32_t fd;
uint32_t speedInHz;
} I2CMaster_SetBusSpeed_t;
typedef struct __attribute__((packed))
{
CTX_HEADER header;
int32_t fd;
uint32_t timeoutInMs;
} I2CMaster_SetTimeout_t;
typedef struct __attribute__((packed))
{
CTX_HEADER header;
int32_t fd;
uint8_t address;
int32_t length;
DATA_BLOCK data_block; // Must be the last element in the struct
} I2CMaster_Write_t;
typedef struct __attribute__((packed))
{
CTX_HEADER header;
int32_t fd;
uint8_t address;
uint32_t lenWriteData;
uint32_t lenReadData;
DATA_BLOCK data_block; // Must be the last element in the struct
} I2CMaster_WriteThenRead_t;
typedef struct __attribute__((packed))
{
CTX_HEADER header;
int32_t fd;
uint8_t address;
uint32_t maxLength;
DATA_BLOCK data_block; // Must be the last element in the struct
} I2CMaster_Read_t;
typedef struct __attribute__((packed))
{
CTX_HEADER header;
int32_t fd;
uint8_t address;
} I2CMaster_SetDefaultTargetAddress_t;
typedef struct __attribute__((packed))
{
CTX_HEADER header;
uint32_t pwm;
} PWM_Open_t;
typedef struct __attribute__((packed))
{
CTX_HEADER header;
int32_t pwmFd;
uint32_t pwmChannel;
DATA_BLOCK data_block; // Must be the last element in the struct
} PWM_Apply_t;
typedef struct __attribute__((packed))
{
CTX_HEADER header;
uint32_t id;
} ADC_Open_t;
typedef struct __attribute__((packed))
{
CTX_HEADER header;
int32_t fd;
uint32_t channel;
} ADC_GetSampleBitCount_t;
typedef struct __attribute__((packed))
{
CTX_HEADER header;
int32_t fd;
uint32_t channel;
float referenceVoltage;
} ADC_SetReferenceVoltage_t;
typedef struct __attribute__((packed))
{
CTX_HEADER header;
int32_t fd;
uint32_t channel;
uint32_t outSampleValue;
} ADC_Poll_t;
typedef struct __attribute__((packed))
{
CTX_HEADER header;
int32_t interfaceId;
int32_t chipSelectId;
DATA_BLOCK data_block; // Must be the last element in the struct
} SPIMaster_Open_t;
typedef struct __attribute__((packed))
{
CTX_HEADER header;
DATA_BLOCK data_block; // Must be the last element in the struct
} SPIMaster_InitConfig_t;
typedef struct __attribute__((packed))
{
CTX_HEADER header;
int32_t fd;
uint32_t speedInHz;
} SPIMaster_SetBusSpeed_t;
typedef struct __attribute__((packed))
{
CTX_HEADER header;
int32_t fd;
uint32_t mode;
} SPIMaster_SetMode_t;
typedef struct __attribute__((packed))
{
CTX_HEADER header;
int32_t fd;
uint32_t order;
} SPIMaster_SetBitOrder_t;
typedef struct __attribute__((packed))
{
CTX_HEADER header;
int32_t fd;
uint32_t lenWriteData;
uint32_t lenReadData;
uint32_t order;
DATA_BLOCK data_block; // Must be the last element in the struct
} SPIMaster_WriteThenRead_t;
typedef struct __attribute__((packed))
{
CTX_HEADER header;
uint32_t transferCount;
uint32_t z__magicAndVersion;
} SPIMaster_InitTransfers_t;
typedef struct __attribute__((packed))
{
CTX_HEADER header;
int32_t fd;
uint32_t transferCount;
int32_t length;
DATA_BLOCK data_block; // Must be the last element in the struct
} SPIMaster_TransferSequential_t;
typedef struct __attribute__((packed))
{
CTX_HEADER header;
} Storage_OpenMutableFile_t;
typedef struct __attribute__((packed))
{
CTX_HEADER header;
} Storage_DeleteMutableFile_t;
typedef struct __attribute__((packed))
{
CTX_HEADER header;
int32_t fd;
int32_t length;
DATA_BLOCK data_block; // Must be the last element in the struct
} RemoteX_Write_t;
typedef struct __attribute__((packed))
{
CTX_HEADER header;
int32_t fd;
int32_t length;
DATA_BLOCK data_block; // Must be the last element in the struct
} RemoteX_Read_t;
typedef struct __attribute__((packed))
{
CTX_HEADER header;
int32_t fd;
off_t offset;
int32_t whence;
} RemoteX_Lseek_t;
typedef struct __attribute__((packed))
{
CTX_HEADER header;
int32_t fd;
} RemoteX_Close_t;
typedef struct __attribute__((packed))
{
CTX_HEADER header;
int32_t length;
DATA_BLOCK data_block; // Must be the last element in the struct
} RemoteX_PlatformInformation_t;
typedef struct __attribute__((packed))
{
CTX_HEADER header;
DATA_BLOCK data_block; // Must be the last element in the struct
} UART_InitConfig_t;
typedef struct __attribute__((packed))
{
CTX_HEADER header;
int32_t uartId;
DATA_BLOCK data_block; // Must be the last element in the struct
} UART_Open_t;