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
|
/**
* @file spi.c
* @brief This file contains the function implementations for the
* Serial Peripheral Interface (SPIMSS) peripheral module.
*/
/* *****************************************************************************
* Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the name of Maxim Integrated
* Products, Inc. shall not be used except as stated in the Maxim Integrated
* Products, Inc. Branding Policy.
*
* The mere transfer of this software does not imply any licenses
* of trade secrets, proprietary technology, copyrights, patents,
* trademarks, maskwork rights, or any other form of intellectual
* property whatsoever. Maxim Integrated Products, Inc. retains all
* ownership rights.
*
* $Date: 2018-10-17 14:16:30 -0500 (Wed, 17 Oct 2018) $
* $Revision: 38560 $
*
**************************************************************************** */
/* **** Includes **** */
#include "spi.h"
#include "mxc_sys.h"
#include "spimss.h"
#include "spi17y.h"
/**
* @ingroup spi
* @{
*/
/***** Definitions *****/
/***** Functions *****/
/* ************************************************************************ */
int SPI_Init(spi_type spi_name, unsigned mode, unsigned freq)
{
sys_cfg_spimss_t spimss_cfg;
sys_cfg_spi17y_t spi17y_cfg;
int error = E_NO_ERROR;
if (spi_name == SPI0A) {
spi17y_cfg.map = MAP_A;
error = SPI17Y_Init(MXC_SPI17Y, mode, freq, &spi17y_cfg);
} else if(spi_name == SPI1A) {
spimss_cfg.map = MAP_A;
error = SPIMSS_Init(MXC_SPIMSS, mode, freq, &spimss_cfg);
} else if(spi_name == SPI1B) {
spimss_cfg.map = MAP_B;
error = SPIMSS_Init(MXC_SPIMSS, mode, freq, &spimss_cfg);
} else {
return E_BAD_PARAM;
}
return error;
}
/* ************************************************************************ */
int SPI_MasterTransAsync(spi_type spi_name, spi_req_t *req)
{
int error = E_NO_ERROR;
if (spi_name == SPI0A) {
error = SPI17Y_MasterTransAsync(MXC_SPI17Y, (spi17y_req_t *) req);
} else if((spi_name == SPI1A) || (spi_name == SPI1B)) {
error = SPIMSS_MasterTransAsync(MXC_SPIMSS, (spimss_req_t *) req);
} else {
return E_BAD_PARAM;
}
return error;
}
/* ************************************************************************ */
int SPI_MasterTrans(spi_type spi_name, spi_req_t *req)
{
int error = E_NO_ERROR;
if (spi_name == SPI0A) {
error = SPI17Y_MasterTrans(MXC_SPI17Y, (spi17y_req_t *) req);
} else if((spi_name == SPI1A) || (spi_name == SPI1B)) {
error = SPIMSS_MasterTrans(MXC_SPIMSS, (spimss_req_t *) req);
} else {
return E_BAD_PARAM;
}
return error;
}
/* ************************************************************************ */
int SPI_SlaveTrans(spi_type spi_name, spi_req_t *req)
{
int error = E_NO_ERROR;
if (spi_name == SPI0A) {
error = SPI17Y_SlaveTrans(MXC_SPI17Y, (spi17y_req_t *) req);
} else if ((spi_name == SPI1A) || (spi_name == SPI1B)) {
error = SPIMSS_SlaveTrans(MXC_SPIMSS, (spimss_req_t *) req);
} else {
return E_BAD_PARAM;
}
return error;
}
/* ************************************************************************ */
int SPI_SlaveTransAsync(spi_type spi_name, spi_req_t *req)
{
int error = E_NO_ERROR;
if (spi_name == SPI0A) {
error = SPI17Y_SlaveTransAsync(MXC_SPI17Y, (spi17y_req_t *) req);
} else if ((spi_name == SPI1A) || (spi_name == SPI1B)) {
error = SPIMSS_SlaveTransAsync(MXC_SPIMSS, (spimss_req_t *) req);
} else {
return E_BAD_PARAM;
}
return error;
}
/* ************************************************************************ */
int SPI_Shutdown(spi_type spi_name)
{
int error = E_NO_ERROR;
if (spi_name == SPI0A) {
error = SPI17Y_Shutdown(MXC_SPI17Y);
} else if ((spi_name == SPI1A) || (spi_name == SPI1B)) {
error = SPIMSS_Shutdown(MXC_SPIMSS);
} else {
return E_BAD_PARAM;
}
return error;
}
/* ************************************************************************ */
int SPI_AbortAsync(spi_type spi_name, spi_req_t *req)
{
int error = E_NO_ERROR;
if (spi_name == SPI0A) {
error = SPI17Y_AbortAsync((spi17y_req_t *) req);
} else if ((spi_name == SPI1A) || (spi_name == SPI1B)) {
error = SPIMSS_AbortAsync((spimss_req_t *) req);
} else {
return E_BAD_PARAM;
}
return error;
}
/* ************************************************************************ */
int SPI_Handler(spi_type spi_name)
{
if (spi_name == SPI0A) {
SPI17Y_Handler(MXC_SPI17Y);
} else if ((spi_name == SPI1A) || (spi_name == SPI1B)) {
SPIMSS_Handler(MXC_SPIMSS);
} else {
return E_BAD_PARAM;
}
return E_NO_ERROR;
}
// *****************************************************************************
int SPI_Enable(spi_type spi_name)
{
if (spi_name == SPI0A) {
SPI17Y_Enable(MXC_SPI17Y);
} else if ((spi_name == SPI1A) || (spi_name == SPI1B)) {
return E_NOT_SUPPORTED;
} else {
return E_BAD_PARAM;
}
return E_NO_ERROR;
}
// *****************************************************************************
int SPI_Disable(spi_type spi_name)
{
if (spi_name == SPI0A) {
SPI17Y_Disable(MXC_SPI17Y);
} else if ((spi_name == SPI1A) || (spi_name == SPI1B)) {
return E_NOT_SUPPORTED;
} else {
return E_BAD_PARAM;
}
return E_NO_ERROR;
}
// *****************************************************************************
int SPI_Clear_fifo(spi_type spi_name)
{
if (spi_name == SPI0A) {
SPI17Y_Clear_fifo(MXC_SPI17Y);
} else if ((spi_name == SPI1A) || (spi_name == SPI1B)) {
return E_NOT_SUPPORTED;
} else {
return E_BAD_PARAM;
}
return E_NO_ERROR;
}
/**@} end of group spi */
|