forked from projectara/gbsim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathi2s.c
167 lines (148 loc) · 4.78 KB
/
i2s.c
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
/*
* Greybus Simulator
*
* Copyright 2014, 2015 Google Inc.
* Copyright 2014, 2015 Linaro Ltd.
*
* Provided under the three clause BSD license found in the LICENSE file.
*/
#include <fcntl.h>
#include <pthread.h>
#include <libsoc_gpio.h>
#include <linux/fs.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
#include "gbsim.h"
#define CONFIG_COUNT_MAX 20
int i2s_mgmt_handler(uint16_t cport_id, uint16_t hd_cport_id, void *rbuf,
size_t rsize, void *tbuf, size_t tsize)
{
struct gb_operation_msg_hdr *oph;
struct op_msg *op_req = rbuf;
struct op_msg *op_rsp;
struct gb_i2s_mgmt_configuration *conf;
size_t payload_size;
uint16_t message_size;
uint8_t result = PROTOCOL_STATUS_SUCCESS;
op_rsp = (struct op_msg *)tbuf;
oph = (struct gb_operation_msg_hdr *)&op_req->header;
switch (oph->type) {
case GB_I2S_MGMT_TYPE_PROTOCOL_VERSION:
payload_size = sizeof(struct gb_protocol_version_response);
op_rsp->pv_rsp.major = GREYBUS_VERSION_MAJOR;
op_rsp->pv_rsp.minor = GREYBUS_VERSION_MINOR;
break;
case GB_I2S_MGMT_TYPE_GET_SUPPORTED_CONFIGURATIONS:
payload_size = sizeof(struct gb_i2s_mgmt_get_supported_configurations_response) +
sizeof(struct gb_i2s_mgmt_configuration) * CONFIG_COUNT_MAX;
op_rsp->i2s_mgmt_get_sup_conf_rsp.config_count = 1;
conf = &op_rsp->i2s_mgmt_get_sup_conf_rsp.config[0];
conf->sample_frequency = htole32(48000);
conf->num_channels = 2;
conf->bytes_per_channel = 2;
conf->byte_order = GB_I2S_MGMT_BYTE_ORDER_LE;
conf->spatial_locations = htole32(
GB_I2S_MGMT_SPATIAL_LOCATION_FL |
GB_I2S_MGMT_SPATIAL_LOCATION_FR);
conf->ll_protocol = htole32(GB_I2S_MGMT_PROTOCOL_I2S);
conf->ll_mclk_role = GB_I2S_MGMT_ROLE_MASTER;
conf->ll_bclk_role = GB_I2S_MGMT_ROLE_MASTER;
conf->ll_wclk_role = GB_I2S_MGMT_ROLE_MASTER;
conf->ll_wclk_polarity = GB_I2S_MGMT_POLARITY_NORMAL;
conf->ll_wclk_change_edge = GB_I2S_MGMT_EDGE_FALLING;
conf->ll_wclk_tx_edge = GB_I2S_MGMT_EDGE_RISING;
conf->ll_wclk_rx_edge = GB_I2S_MGMT_EDGE_FALLING;
conf->ll_data_offset = 1;
break;
case GB_I2S_MGMT_TYPE_SET_CONFIGURATION:
payload_size = 0;
break;
case GB_I2S_MGMT_TYPE_SET_SAMPLES_PER_MESSAGE:
payload_size = 0;
break;
case GB_I2S_MGMT_TYPE_SET_START_DELAY:
payload_size = 0;
break;
case GB_I2S_MGMT_TYPE_ACTIVATE_CPORT:
payload_size = 0;
break;
case GB_I2S_MGMT_TYPE_DEACTIVATE_CPORT:
payload_size = 0;
break;
default:
gbsim_error("i2s mgmt operation type %02x not supported\n", oph->type);
return -EINVAL;
}
message_size = sizeof(struct gb_operation_msg_hdr) + payload_size;
return send_response(op_rsp, hd_cport_id, message_size, oph, result);
}
int i2s_data_handler(uint16_t cport_id, uint16_t hd_cport_id, void *rbuf,
size_t rsize, void *tbuf, size_t tsize)
{
struct gb_operation_msg_hdr *oph;
struct op_msg *op_req = rbuf;
struct op_msg *op_rsp;
size_t payload_size;
uint16_t message_size;
uint8_t result = PROTOCOL_STATUS_SUCCESS;
op_rsp = (struct op_msg *)tbuf;
oph = (struct gb_operation_msg_hdr *)&op_req->header;
switch (oph->type) {
case GB_I2S_DATA_TYPE_PROTOCOL_VERSION:
payload_size = sizeof(struct gb_protocol_version_response);
op_rsp->pv_rsp.major = GREYBUS_VERSION_MAJOR;
op_rsp->pv_rsp.minor = GREYBUS_VERSION_MINOR;
break;
case GB_I2S_DATA_TYPE_SEND_DATA:
payload_size = 0;
break;
default:
gbsim_error("i2s data operation type %02x not supported\n", oph->type);
return -EINVAL;
}
message_size = sizeof(struct gb_operation_msg_hdr) + payload_size;
return send_response(op_rsp, hd_cport_id, message_size, oph, result);
}
char *i2s_mgmt_get_operation(uint8_t type)
{
switch (type) {
case GB_I2S_MGMT_TYPE_PROTOCOL_VERSION:
return "GB_I2S_MGMT_TYPE_PROTOCOL_VERSION";
case GB_I2S_MGMT_TYPE_GET_SUPPORTED_CONFIGURATIONS:
return "GB_I2S_MGMT_TYPE_GET_SUPPORTED_CONFIGURATIONS";
case GB_I2S_MGMT_TYPE_SET_CONFIGURATION:
return "GB_I2S_MGMT_TYPE_SET_CONFIGURATION";
case GB_I2S_MGMT_TYPE_SET_SAMPLES_PER_MESSAGE:
return "GB_I2S_MGMT_TYPE_SET_SAMPLES_PER_MESSAGE";
case GB_I2S_MGMT_TYPE_GET_PROCESSING_DELAY:
return "GB_I2S_MGMT_TYPE_GET_PROCESSING_DELAY";
case GB_I2S_MGMT_TYPE_SET_START_DELAY:
return "GB_I2S_MGMT_TYPE_SET_START_DELAY";
case GB_I2S_MGMT_TYPE_ACTIVATE_CPORT:
return "GB_I2S_MGMT_TYPE_ACTIVATE_CPORT";
case GB_I2S_MGMT_TYPE_DEACTIVATE_CPORT:
return "GB_I2S_MGMT_TYPE_DEACTIVATE_CPORT";
case GB_I2S_MGMT_TYPE_REPORT_EVENT:
return "GB_I2S_MGMT_TYPE_REPORT_EVENT";
default:
return "(Unknown operation)";
}
}
char *i2s_data_get_operation(uint8_t type)
{
switch (type) {
case GB_I2S_DATA_TYPE_PROTOCOL_VERSION:
return "GB_I2S_DATA_TYPE_PROTOCOL_VERSION";
case GB_I2S_DATA_TYPE_SEND_DATA:
return "GB_I2S_DATA_TYPE_SEND_DATA";
default:
return "(Unknown operation)";
}
}
void i2s_init(void)
{
}