forked from analogdevicesinc/msdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspi_me11.c
More file actions
334 lines (271 loc) · 8.51 KB
/
Copy pathspi_me11.c
File metadata and controls
334 lines (271 loc) · 8.51 KB
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
323
324
325
326
327
328
329
330
331
332
333
334
/******************************************************************************
*
* Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by
* Analog Devices, Inc.),
* Copyright (C) 2023-2024 Analog Devices, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
#include <stdio.h>
#include <stddef.h>
#include <stdint.h>
#include "mxc_device.h"
#include "mxc_assert.h"
#include "mxc_lock.h"
#include "mxc_sys.h"
#include "mxc_delay.h"
#include "spi_reva1.h"
#include "dma.h"
/* **** Functions **** */
int MXC_SPI_Init(mxc_spi_regs_t *spi, int masterMode, int quadModeUsed, int numSlaves,
unsigned ssPolarity, unsigned int hz)
{
int spi_num;
spi_num = MXC_SPI_GET_IDX(spi);
MXC_ASSERT(spi_num >= 0);
if (numSlaves > MXC_SPI_SS_INSTANCES) {
return E_BAD_PARAM;
}
// Check if frequency is too high
if (hz > PeripheralClock) {
return E_BAD_PARAM;
}
#ifndef MSDK_NO_GPIO_CLK_INIT
// Configure GPIO for spi
if (spi == MXC_SPI0) {
MXC_GCR->rst0 |= MXC_F_GCR_RST0_SPI0;
while (MXC_GCR->rst0 & MXC_F_GCR_RST0_SPI0) {}
MXC_GCR->pclk_dis0 &= ~(MXC_F_GCR_PCLK_DIS0_SPI0D);
MXC_GPIO_Config(&gpio_cfg_spi0);
} else {
return E_NO_DEVICE;
}
#endif
return MXC_SPI_RevA1_Init((mxc_spi_reva_regs_t *)spi, masterMode, quadModeUsed, numSlaves,
ssPolarity, hz);
}
int MXC_SPI_Shutdown(mxc_spi_regs_t *spi)
{
int spi_num;
spi_num = MXC_SPI_GET_IDX(spi);
MXC_ASSERT(spi_num >= 0);
MXC_SPI_RevA1_Shutdown((mxc_spi_reva_regs_t *)spi);
if (spi == MXC_SPI0) {
MXC_GCR->pclk_dis0 |= (MXC_F_GCR_PCLK_DIS0_SPI0D);
} else {
return E_INVALID;
}
return E_NO_ERROR;
}
int MXC_SPI_ReadyForSleep(mxc_spi_regs_t *spi)
{
return MXC_SPI_RevA1_ReadyForSleep((mxc_spi_reva_regs_t *)spi);
}
int MXC_SPI_GetPeripheralClock(mxc_spi_regs_t *spi)
{
if (spi == MXC_SPI0) {
return PeripheralClock;
} else {
return E_BAD_PARAM;
}
return E_NO_ERROR;
}
int MXC_SPI_SetFrequency(mxc_spi_regs_t *spi, unsigned int hz)
{
return MXC_SPI_RevA1_SetFrequency((mxc_spi_reva_regs_t *)spi, hz);
}
unsigned int MXC_SPI_GetFrequency(mxc_spi_regs_t *spi)
{
return MXC_SPI_RevA1_GetFrequency((mxc_spi_reva_regs_t *)spi);
}
int MXC_SPI_SetDataSize(mxc_spi_regs_t *spi, int dataSize)
{
return MXC_SPI_RevA1_SetDataSize((mxc_spi_reva_regs_t *)spi, dataSize);
}
int MXC_SPI_GetDataSize(mxc_spi_regs_t *spi)
{
return MXC_SPI_RevA1_GetDataSize((mxc_spi_reva_regs_t *)spi);
}
int MXC_SPI_SetSlave(mxc_spi_regs_t *spi, int ssIdx)
{
return MXC_SPI_RevA1_SetSlave((mxc_spi_reva_regs_t *)spi, ssIdx);
}
int MXC_SPI_GetSlave(mxc_spi_regs_t *spi)
{
return MXC_SPI_RevA1_GetSlave((mxc_spi_reva_regs_t *)spi);
}
int MXC_SPI_SetWidth(mxc_spi_regs_t *spi, mxc_spi_width_t spiWidth)
{
return MXC_SPI_RevA1_SetWidth((mxc_spi_reva_regs_t *)spi, spiWidth);
}
mxc_spi_width_t MXC_SPI_GetWidth(mxc_spi_regs_t *spi)
{
return (mxc_spi_width_t)MXC_SPI_RevA1_GetWidth((mxc_spi_reva_regs_t *)spi);
}
int MXC_SPI_SetMode(mxc_spi_regs_t *spi, mxc_spi_mode_t spiMode)
{
return MXC_SPI_RevA1_SetMode((mxc_spi_reva_regs_t *)spi, spiMode);
}
mxc_spi_mode_t MXC_SPI_GetMode(mxc_spi_regs_t *spi)
{
return MXC_SPI_RevA1_GetMode((mxc_spi_reva_regs_t *)spi);
}
int MXC_SPI_StartTransmission(mxc_spi_regs_t *spi)
{
return MXC_SPI_RevA1_StartTransmission((mxc_spi_reva_regs_t *)spi);
}
int MXC_SPI_GetActive(mxc_spi_regs_t *spi)
{
return MXC_SPI_RevA1_GetActive((mxc_spi_reva_regs_t *)spi);
}
int MXC_SPI_AbortTransmission(mxc_spi_regs_t *spi)
{
return MXC_SPI_RevA1_AbortTransmission((mxc_spi_reva_regs_t *)spi);
}
unsigned int MXC_SPI_ReadRXFIFO(mxc_spi_regs_t *spi, unsigned char *bytes, unsigned int len)
{
return MXC_SPI_RevA1_ReadRXFIFO((mxc_spi_reva_regs_t *)spi, bytes, len);
}
unsigned int MXC_SPI_GetRXFIFOAvailable(mxc_spi_regs_t *spi)
{
return MXC_SPI_RevA1_GetRXFIFOAvailable((mxc_spi_reva_regs_t *)spi);
}
unsigned int MXC_SPI_WriteTXFIFO(mxc_spi_regs_t *spi, unsigned char *bytes, unsigned int len)
{
return MXC_SPI_RevA1_WriteTXFIFO((mxc_spi_reva_regs_t *)spi, bytes, len);
}
unsigned int MXC_SPI_GetTXFIFOAvailable(mxc_spi_regs_t *spi)
{
return MXC_SPI_RevA1_GetTXFIFOAvailable((mxc_spi_reva_regs_t *)spi);
}
void MXC_SPI_ClearRXFIFO(mxc_spi_regs_t *spi)
{
MXC_SPI_RevA1_ClearRXFIFO((mxc_spi_reva_regs_t *)spi);
}
void MXC_SPI_ClearTXFIFO(mxc_spi_regs_t *spi)
{
MXC_SPI_RevA1_ClearTXFIFO((mxc_spi_reva_regs_t *)spi);
}
int MXC_SPI_SetRXThreshold(mxc_spi_regs_t *spi, unsigned int numBytes)
{
return MXC_SPI_RevA1_SetRXThreshold((mxc_spi_reva_regs_t *)spi, numBytes);
}
unsigned int MXC_SPI_GetRXThreshold(mxc_spi_regs_t *spi)
{
return MXC_SPI_RevA1_GetRXThreshold((mxc_spi_reva_regs_t *)spi);
}
int MXC_SPI_SetTXThreshold(mxc_spi_regs_t *spi, unsigned int numBytes)
{
return MXC_SPI_RevA1_SetTXThreshold((mxc_spi_reva_regs_t *)spi, numBytes);
}
unsigned int MXC_SPI_GetTXThreshold(mxc_spi_regs_t *spi)
{
return MXC_SPI_RevA1_GetTXThreshold((mxc_spi_reva_regs_t *)spi);
}
unsigned int MXC_SPI_GetFlags(mxc_spi_regs_t *spi)
{
return MXC_SPI_RevA1_GetFlags((mxc_spi_reva_regs_t *)spi);
}
void MXC_SPI_ClearFlags(mxc_spi_regs_t *spi)
{
MXC_SPI_RevA1_ClearFlags((mxc_spi_reva_regs_t *)spi);
}
unsigned int MXC_SPI_GetAndClearFlags(mxc_spi_regs_t *spi)
{
return MXC_SPI_RevA1_GetAndClearFlags((mxc_spi_reva_regs_t *)spi);
}
void MXC_SPI_EnableInt(mxc_spi_regs_t *spi, unsigned int mask)
{
MXC_SPI_RevA1_EnableInt((mxc_spi_reva_regs_t *)spi, mask);
}
void MXC_SPI_DisableInt(mxc_spi_regs_t *spi, unsigned int mask)
{
MXC_SPI_RevA1_DisableInt((mxc_spi_reva_regs_t *)spi, mask);
}
int MXC_SPI_MasterTransaction(mxc_spi_req_t *req)
{
return MXC_SPI_RevA1_MasterTransaction((mxc_spi_reva_req_t *)req);
}
int MXC_SPI_MasterTransactionAsync(mxc_spi_req_t *req)
{
return MXC_SPI_RevA1_MasterTransactionAsync((mxc_spi_reva_req_t *)req);
}
int MXC_SPI_MasterTransactionDMA(mxc_spi_req_t *req)
{
int reqselTx = -1;
int reqselRx = -1;
int spi_num;
spi_num = MXC_SPI_GET_IDX(req->spi);
MXC_ASSERT(spi_num >= 0);
switch (spi_num) {
case 0:
reqselTx = MXC_DMA_REQUEST_SPI0TX;
reqselRx = MXC_DMA_REQUEST_SPI0RX;
break;
case 1:
reqselTx = MXC_DMA_REQUEST_SPIMSSTX;
reqselRx = MXC_DMA_REQUEST_SPIMSSRX;
break;
default:
return E_BAD_PARAM;
}
return MXC_SPI_RevA1_MasterTransactionDMA((mxc_spi_reva_req_t *)req, reqselTx, reqselRx,
MXC_DMA);
}
int MXC_SPI_SlaveTransaction(mxc_spi_req_t *req)
{
return MXC_SPI_RevA1_SlaveTransaction((mxc_spi_reva_req_t *)req);
}
int MXC_SPI_SlaveTransactionAsync(mxc_spi_req_t *req)
{
return MXC_SPI_RevA1_SlaveTransactionAsync((mxc_spi_reva_req_t *)req);
}
int MXC_SPI_SlaveTransactionDMA(mxc_spi_req_t *req)
{
int reqselTx = -1;
int reqselRx = -1;
int spi_num;
spi_num = MXC_SPI_GET_IDX(req->spi);
MXC_ASSERT(spi_num >= 0);
switch (spi_num) {
case 0:
reqselTx = MXC_DMA_REQUEST_SPI0TX;
reqselRx = MXC_DMA_REQUEST_SPI0RX;
break;
case 1:
reqselTx = MXC_DMA_REQUEST_SPIMSSTX;
reqselRx = MXC_DMA_REQUEST_SPIMSSRX;
break;
default:
return E_BAD_PARAM;
}
return MXC_SPI_RevA1_SlaveTransactionDMA((mxc_spi_reva_req_t *)req, reqselTx, reqselRx,
MXC_DMA);
}
int MXC_SPI_SetDefaultTXData(mxc_spi_regs_t *spi, unsigned int defaultTXData)
{
return MXC_SPI_RevA1_SetDefaultTXData((mxc_spi_reva_regs_t *)spi, defaultTXData);
}
void MXC_SPI_AbortAsync(mxc_spi_regs_t *spi)
{
MXC_SPI_RevA1_AbortAsync((mxc_spi_reva_regs_t *)spi);
}
void MXC_SPI_AsyncHandler(mxc_spi_regs_t *spi)
{
MXC_SPI_RevA1_AsyncHandler((mxc_spi_reva_regs_t *)spi);
}
void MXC_SPI_HWSSControl(mxc_spi_regs_t *spi, int state)
{
MXC_SPI_RevA1_HWSSControl((mxc_spi_reva_regs_t *)spi, state);
}