-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperipherals.h
83 lines (66 loc) · 2.19 KB
/
peripherals.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
#pragma once
#include <stdint.h>
#include <stdbool.h>
#include "contract.h"
#include <applibs/adc.h>
#include <applibs/gpio.h>
#include <applibs/i2c.h>
#include <applibs/log.h>
#include <applibs/pwm.h>
#include <applibs/spi.h>
#include <applibs/storage.h>
#include <applibs/uart.h>
#include <errno.h>
#include <unistd.h>
#define DEFINE_CMD(command, data, length) \
int command##_cmd(uint8_t *buf, ssize_t length) \
{ \
command##_t *data = (command##_t *)buf;
#define END_CMD \
data->header.err_no = errno; \
return 0; \
}
#define DECLARE_CMD(command) \
int command##_cmd(uint8_t *buf, ssize_t nread)
#define ADD_CMD(command) command##_cmd
#define CORE_BLOCK_SIZE(name) (int)(sizeof(name##_t) - sizeof(((name##_t *)0)->data_block))
#define VARIABLE_BLOCK_SIZE(name, length) (int)(sizeof(name##_t) - sizeof(((name##_t *)0)->data_block.data) + length)
#define NELEMS(x) (sizeof(x) / sizeof((x)[0]))
#define LEDGE_SIZE 128
int file_descriptor_ledger[LEDGE_SIZE];
void ledger_initialize(void);
void ledger_close(void);
DECLARE_CMD(GPIO_OpenAsOutput);
DECLARE_CMD(GPIO_OpenAsInput);
DECLARE_CMD(GPIO_SetValue);
DECLARE_CMD(GPIO_GetValue);
DECLARE_CMD(I2CMaster_Open);
DECLARE_CMD(I2CMaster_SetBusSpeed);
DECLARE_CMD(I2CMaster_SetTimeout);
DECLARE_CMD(I2CMaster_Write);
DECLARE_CMD(I2CMaster_WriteThenRead);
DECLARE_CMD(I2CMaster_Read);
DECLARE_CMD(I2CMaster_SetDefaultTargetAddress);
DECLARE_CMD(SPIMaster_Open);
DECLARE_CMD(SPIMaster_InitConfig);
DECLARE_CMD(SPIMaster_SetBusSpeed);
DECLARE_CMD(SPIMaster_SetMode);
DECLARE_CMD(SPIMaster_SetBitOrder);
DECLARE_CMD(SPIMaster_WriteThenRead);
DECLARE_CMD(SPIMaster_InitTransfers);
DECLARE_CMD(SPIMaster_TransferSequential);
DECLARE_CMD(PWM_Open);
DECLARE_CMD(PWM_Apply);
DECLARE_CMD(ADC_Open);
DECLARE_CMD(ADC_GetSampleBitCount);
DECLARE_CMD(ADC_SetReferenceVoltage);
DECLARE_CMD(ADC_Poll);
DECLARE_CMD(Storage_OpenMutableFile);
DECLARE_CMD(Storage_DeleteMutableFile);
DECLARE_CMD(RemoteX_Write);
DECLARE_CMD(RemoteX_Read);
DECLARE_CMD(RemoteX_Lseek);
DECLARE_CMD(RemoteX_Close);
DECLARE_CMD(RemoteX_PlatformInformation);
DECLARE_CMD(UART_InitConfig);
DECLARE_CMD(UART_Open);