1 /*
2 * Copyright 2021 NXP
3 * All rights reserved.
4 *
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9 #include "fsl_component_serial_manager.h"
10 #include "fsl_component_serial_port_internal.h"
11
12 #if (defined(SERIAL_PORT_TYPE_SPI) && (SERIAL_PORT_TYPE_SPI > 0U))
13 #include "fsl_adapter_spi.h"
14 #include "fsl_component_serial_port_spi.h"
15 #endif
16
17 /*******************************************************************************
18 * Definitions
19 ******************************************************************************/
20 #ifndef NDEBUG
21 #if (defined(DEBUG_CONSOLE_ASSERT_DISABLE) && (DEBUG_CONSOLE_ASSERT_DISABLE > 0U))
22 #undef assert
23 #define assert(n)
24 #else
25 /* MISRA C-2012 Rule 17.2 */
26 #undef assert
27 #define assert(n) \
28 while (!(n)) \
29 { \
30 ; \
31 }
32 #endif
33 #endif
34
35 #define SERIAL_PORT_SPI_RECEIVE_DATA_LENGTH 1U
36 #define SERIAL_MANAGER_BLOCK_OFFSET (12U)
37
38 typedef struct _serial_spi_master_send_state
39 {
40 uint8_t *buffer;
41 uint32_t length;
42 serial_manager_callback_t callback;
43 void *callbackParam;
44 } serial_spi_master_send_state_t;
45
46 typedef struct _serial_spi_master_recv_state
47 {
48 uint8_t *buffer;
49 uint32_t length;
50 serial_manager_callback_t callback;
51 void *callbackParam;
52 } serial_spi_master_recv_state_t;
53
54 typedef struct _serial_spi_master_state
55 {
56 HAL_SPI_MASTER_HANDLE_DEFINE(spiMasterHandleBuffer);
57 uint32_t configFlags;
58 #if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
59 serial_spi_master_send_state_t tx;
60 serial_spi_master_recv_state_t rx;
61 #endif
62 } serial_spi_master_state_t;
63
64 typedef struct _serial_spi_slave_send_state
65 {
66 uint8_t *buffer;
67 uint32_t length;
68 serial_manager_callback_t callback;
69 void *callbackParam;
70 } serial_spi_slave_send_state_t;
71
72 typedef struct _serial_spi_slave_recv_state
73 {
74 uint8_t *buffer;
75 uint32_t length;
76 serial_manager_callback_t callback;
77 void *callbackParam;
78 } serial_spi_slave_recv_state_t;
79
80 typedef struct _serial_spi_slave_state
81 {
82 HAL_SPI_SLAVE_HANDLE_DEFINE(spiSlaveHandleBuffer);
83 uint32_t configFlags;
84 #if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
85 serial_spi_slave_send_state_t tx;
86 serial_spi_slave_recv_state_t rx;
87 #endif
88 } serial_spi_slave_state_t;
89
90 /*******************************************************************************
91 * Prototypes
92 ******************************************************************************/
93
94 /*******************************************************************************
95 * Code
96 ******************************************************************************/
97 #if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
Serial_SpiMasterTxCallback(hal_spi_master_handle_t handle,hal_spi_status_t status,void * callbackParam)98 void Serial_SpiMasterTxCallback(hal_spi_master_handle_t handle, hal_spi_status_t status, void *callbackParam)
99 {
100 serial_spi_master_state_t *serialSpiMasterHandle;
101 serial_manager_callback_message_t msg;
102
103 if (NULL != callbackParam)
104 {
105 serialSpiMasterHandle = (serial_spi_master_state_t *)callbackParam;
106 if (NULL != serialSpiMasterHandle->tx.callback)
107 {
108 serial_manager_status_t serialManagerStatus = kStatus_SerialManager_Success;
109 msg.buffer = serialSpiMasterHandle->tx.buffer;
110 msg.length = serialSpiMasterHandle->tx.length;
111 if (NULL != serialSpiMasterHandle->tx.callback)
112 {
113 serialSpiMasterHandle->tx.callback(serialSpiMasterHandle->tx.callbackParam, &msg, serialManagerStatus);
114 }
115 }
116 }
117 }
118
Serial_SpiMasterRxCallback(hal_spi_master_handle_t handle,hal_spi_status_t status,void * callbackParam)119 void Serial_SpiMasterRxCallback(hal_spi_master_handle_t handle, hal_spi_status_t status, void *callbackParam)
120 {
121 serial_spi_master_state_t *serialSpiMasterHandle;
122 serial_manager_callback_message_t msg;
123
124 if (NULL != callbackParam)
125 {
126 serialSpiMasterHandle = (serial_spi_master_state_t *)callbackParam;
127 serial_manager_status_t serialManagerStatus = kStatus_SerialManager_Success;
128 msg.buffer = serialSpiMasterHandle->rx.buffer;
129 msg.length = serialSpiMasterHandle->rx.length;
130 if (NULL != serialSpiMasterHandle->rx.callback)
131 {
132 serialSpiMasterHandle->rx.callback(serialSpiMasterHandle->rx.callbackParam, &msg, serialManagerStatus);
133 }
134 }
135 }
136
Serial_SpiSlaveTxCallback(hal_spi_slave_handle_t handle,hal_spi_status_t status,void * callbackParam)137 void Serial_SpiSlaveTxCallback(hal_spi_slave_handle_t handle, hal_spi_status_t status, void *callbackParam)
138 {
139 serial_spi_slave_state_t *serialSpiSlaveHandle;
140 serial_manager_callback_message_t msg;
141
142 if (NULL != callbackParam)
143 {
144 serialSpiSlaveHandle = (serial_spi_slave_state_t *)callbackParam;
145 serial_manager_status_t serialManagerStatus = kStatus_SerialManager_Success;
146 msg.buffer = serialSpiSlaveHandle->tx.buffer;
147 msg.length = serialSpiSlaveHandle->tx.length;
148 if (NULL != serialSpiSlaveHandle->tx.callback)
149 {
150 serialSpiSlaveHandle->tx.callback(serialSpiSlaveHandle->tx.callbackParam, &msg, serialManagerStatus);
151 }
152 }
153 }
154
Serial_SpiSlaveRxCallback(hal_spi_slave_handle_t handle,hal_spi_status_t status,void * callbackParam)155 void Serial_SpiSlaveRxCallback(hal_spi_slave_handle_t handle, hal_spi_status_t status, void *callbackParam)
156 {
157 serial_spi_slave_state_t *serialSpiSlaveHandle;
158 serial_manager_callback_message_t msg;
159 if (NULL != callbackParam)
160 {
161 serialSpiSlaveHandle = (serial_spi_slave_state_t *)callbackParam;
162 serial_manager_status_t serialManagerStatus = kStatus_SerialManager_Success;
163 msg.buffer = serialSpiSlaveHandle->rx.buffer;
164 msg.length = serialSpiSlaveHandle->rx.length;
165 if (NULL != serialSpiSlaveHandle->rx.callback)
166 {
167 serialSpiSlaveHandle->rx.callback(serialSpiSlaveHandle->rx.callbackParam, &msg, serialManagerStatus);
168 }
169 }
170 }
171 #endif /* SERIAL_MANAGER_NON_BLOCKING_MODE */
Serial_SpiMasterInit(serial_handle_t serialHandle,void * serialConfig)172 serial_manager_status_t Serial_SpiMasterInit(serial_handle_t serialHandle, void *serialConfig)
173 {
174 serial_spi_master_state_t *serialSpiMasterHandle;
175 serial_spi_master_config_t *serialSpiMasterConfig;
176 #if (defined(HAL_SPI_MASTER_DMA_ENABLE) && (HAL_SPI_MASTER_DMA_ENABLE > 0U))
177 hal_spi_dma_config_t *spi_dma_config;
178 #endif
179
180 assert(serialHandle);
181 assert(serialConfig);
182 #if (defined(HAL_SPI_MASTER_DMA_ENABLE) && (HAL_SPI_MASTER_DMA_ENABLE > 0U))
183 assert((SERIAL_PORT_SPI_MASTER_HANDLE_SIZE - HAL_SPI_MASTER_DMA_HANDLE_SIZE) >= sizeof(serial_spi_master_state_t));
184 #else
185 assert(SERIAL_PORT_SPI_MASTER_HANDLE_SIZE >= sizeof(serial_spi_master_state_t));
186 #endif
187 serialSpiMasterHandle = (serial_spi_master_state_t *)serialHandle;
188 serialSpiMasterConfig = (serial_spi_master_config_t *)serialConfig;
189
190 if (kStatus_HAL_SpiSuccess !=
191 HAL_SpiMasterInit((hal_spi_master_handle_t)serialSpiMasterHandle->spiMasterHandleBuffer,
192 (const hal_spi_master_config_t *)serialSpiMasterConfig))
193 {
194 return kStatus_SerialManager_Error;
195 }
196 serialSpiMasterHandle->configFlags = serialSpiMasterConfig->configFlags;
197 #if (defined(HAL_SPI_MASTER_DMA_ENABLE) && (HAL_SPI_MASTER_DMA_ENABLE > 0U))
198 if (serialSpiMasterConfig->enableDMA == 1)
199 {
200 spi_dma_config = (hal_spi_dma_config_t *)serialSpiMasterConfig->dmaConfig;
201 HAL_SpiMasterDMAInit((hal_spi_master_handle_t)serialSpiMasterHandle->spiMasterHandleBuffer,
202 (uint8_t *)serialSpiMasterHandle->spiMasterHandleBuffer +
203 (SERIAL_PORT_SPI_MASTER_HANDLE_SIZE - HAL_SPI_MASTER_DMA_HANDLE_SIZE),
204 spi_dma_config);
205 }
206
207 #endif
208
209 #if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
210 #endif /* SERIAL_MANAGER_NON_BLOCKING_MODE */
211
212 return kStatus_SerialManager_Success;
213 }
214
Serial_SpiMasterDeinit(serial_handle_t serialHandle)215 serial_manager_status_t Serial_SpiMasterDeinit(serial_handle_t serialHandle)
216 {
217 serial_spi_master_state_t *serialSpiMasterHandle;
218
219 assert(serialHandle);
220
221 serialSpiMasterHandle = (serial_spi_master_state_t *)serialHandle;
222
223 (void)HAL_SpiMasterDeinit((hal_spi_master_handle_t)serialSpiMasterHandle->spiMasterHandleBuffer);
224
225 return kStatus_SerialManager_Success;
226 }
227
Serial_SpiSlaveInit(serial_handle_t serialHandle,void * serialConfig)228 serial_manager_status_t Serial_SpiSlaveInit(serial_handle_t serialHandle, void *serialConfig)
229 {
230 serial_spi_slave_state_t *serialSpiSlaveHandle;
231 serial_spi_slave_config_t *serialSpiSlaveConfig;
232 #if (defined(HAL_SPI_SLAVE_DMA_ENABLE) && (HAL_SPI_SLAVE_DMA_ENABLE > 0U))
233 hal_spi_dma_config_t *spi_dma_config;
234 #endif
235
236 assert(serialHandle);
237 assert(serialConfig);
238
239 #if (defined(HAL_SPI_SLAVE_DMA_ENABLE) && (HAL_SPI_SLAVE_DMA_ENABLE > 0U))
240 assert((SERIAL_PORT_SPI_SLAVE_HANDLE_SIZE - HAL_SPI_SLAVE_DMA_HANDLE_SIZE) >= sizeof(serial_spi_slave_state_t));
241 #else
242 assert(SERIAL_PORT_SPI_SLAVE_HANDLE_SIZE >= sizeof(serial_spi_slave_state_t));
243 #endif
244
245 serialSpiSlaveHandle = (serial_spi_slave_state_t *)serialHandle;
246 serialSpiSlaveConfig = (serial_spi_slave_config_t *)serialConfig;
247
248 if (kStatus_HAL_SpiSuccess != HAL_SpiSlaveInit((hal_spi_slave_handle_t)serialSpiSlaveHandle->spiSlaveHandleBuffer,
249 (hal_spi_slave_config_t *)serialSpiSlaveConfig))
250 {
251 return kStatus_SerialManager_Error;
252 }
253 serialSpiSlaveHandle->configFlags = serialSpiSlaveConfig->configFlags;
254 #if (defined(HAL_SPI_SLAVE_DMA_ENABLE) && (HAL_SPI_SLAVE_DMA_ENABLE > 0U))
255 if (serialSpiSlaveConfig->enableDMA == 1)
256 {
257 spi_dma_config = (hal_spi_dma_config_t *)serialSpiSlaveConfig->dmaConfig;
258 HAL_SpiSlaveDMAInit((hal_spi_slave_handle_t)serialSpiSlaveHandle->spiSlaveHandleBuffer,
259 (uint8_t *)serialSpiSlaveHandle->spiSlaveHandleBuffer +
260 (SERIAL_PORT_SPI_SLAVE_HANDLE_SIZE - HAL_SPI_SLAVE_DMA_HANDLE_SIZE),
261 spi_dma_config);
262 }
263
264 #endif
265
266 #if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
267 #endif /* SERIAL_MANAGER_NON_BLOCKING_MODE */
268
269 return kStatus_SerialManager_Success;
270 }
271
Serial_SpiSlaveDeinit(serial_handle_t serialHandle)272 serial_manager_status_t Serial_SpiSlaveDeinit(serial_handle_t serialHandle)
273 {
274 serial_spi_slave_state_t *serialSpiSlaveHandle;
275
276 assert(serialHandle);
277
278 serialSpiSlaveHandle = (serial_spi_slave_state_t *)serialHandle;
279
280 (void)HAL_SpiSlaveDeinit((hal_spi_slave_handle_t)serialSpiSlaveHandle->spiSlaveHandleBuffer);
281
282 return kStatus_SerialManager_Success;
283 }
284
285 #if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
286
Serial_SpiMasterWrite(serial_handle_t serialHandle,uint8_t * buffer,uint32_t length)287 serial_manager_status_t Serial_SpiMasterWrite(serial_handle_t serialHandle, uint8_t *buffer, uint32_t length)
288 {
289 serial_spi_master_state_t *serialSpiMasterHandle;
290 hal_spi_transfer_t mastetTransfer;
291
292 assert(serialHandle);
293 assert(buffer);
294 assert(length);
295 serialSpiMasterHandle = (serial_spi_master_state_t *)serialHandle;
296 serialSpiMasterHandle->tx.buffer = buffer;
297 serialSpiMasterHandle->tx.length = (size_t)length;
298
299 if (kStatus_HAL_SpiSuccess !=
300 HAL_SpiMasterTransferInstallCallback((hal_spi_master_handle_t)serialSpiMasterHandle->spiMasterHandleBuffer,
301 Serial_SpiMasterTxCallback, serialHandle))
302 {
303 return kStatus_SerialManager_Error;
304 }
305 serialSpiMasterHandle = (serial_spi_master_state_t *)serialHandle;
306 mastetTransfer.txData = buffer;
307 mastetTransfer.rxData = NULL;
308 mastetTransfer.dataSize = (size_t)length;
309 mastetTransfer.flags = serialSpiMasterHandle->configFlags;
310
311 return (serial_manager_status_t)HAL_SpiMasterTransferNonBlocking(
312 ((hal_spi_master_handle_t)&serialSpiMasterHandle->spiMasterHandleBuffer[0]), &mastetTransfer);
313 }
314
Serial_SpiSlaveWrite(serial_handle_t serialHandle,uint8_t * buffer,uint32_t length)315 serial_manager_status_t Serial_SpiSlaveWrite(serial_handle_t serialHandle, uint8_t *buffer, uint32_t length)
316 {
317 serial_spi_slave_state_t *serialSpiSlaveHandle;
318 hal_spi_transfer_t slaveTransfer;
319 assert(serialHandle);
320 assert(buffer);
321 assert(length);
322
323 serialSpiSlaveHandle = (serial_spi_slave_state_t *)serialHandle;
324 serialSpiSlaveHandle->tx.buffer = buffer;
325 serialSpiSlaveHandle->tx.length = (size_t)length;
326
327 if (kStatus_HAL_SpiSuccess !=
328 HAL_SpiSlaveTransferInstallCallback((hal_spi_slave_handle_t)serialSpiSlaveHandle->spiSlaveHandleBuffer,
329 Serial_SpiSlaveTxCallback, serialHandle))
330 {
331 return kStatus_SerialManager_Error;
332 }
333 slaveTransfer.txData = buffer;
334 slaveTransfer.rxData = NULL;
335 slaveTransfer.dataSize = (size_t)length;
336 slaveTransfer.flags = serialSpiSlaveHandle->configFlags;
337 return (serial_manager_status_t)HAL_SpiSlaveTransferNonBlocking(
338 ((hal_spi_slave_handle_t)&serialSpiSlaveHandle->spiSlaveHandleBuffer[0]), &slaveTransfer);
339 }
340
341 // read Serial_SpiMasterRead
Serial_SpiMasterRead(serial_handle_t serialHandle,uint8_t * buffer,uint32_t length)342 serial_manager_status_t Serial_SpiMasterRead(serial_handle_t serialHandle, uint8_t *buffer, uint32_t length)
343 {
344 serial_spi_master_state_t *serialSpiMasterHandle;
345 hal_spi_transfer_t masterReceiver;
346
347 assert(serialHandle);
348 assert(buffer);
349 assert(length);
350
351 serialSpiMasterHandle = (serial_spi_master_state_t *)serialHandle;
352
353 serialSpiMasterHandle->rx.buffer = buffer;
354 serialSpiMasterHandle->rx.length = (size_t)length;
355 if (kStatus_HAL_SpiSuccess !=
356 HAL_SpiMasterTransferInstallCallback((hal_spi_master_handle_t)serialSpiMasterHandle->spiMasterHandleBuffer,
357 Serial_SpiMasterRxCallback, serialHandle))
358 {
359 return kStatus_SerialManager_Error;
360 }
361
362 masterReceiver.txData = NULL;
363 masterReceiver.rxData = buffer;
364 masterReceiver.dataSize = (size_t)length;
365 masterReceiver.flags = serialSpiMasterHandle->configFlags;
366 return (serial_manager_status_t)HAL_SpiMasterTransferNonBlocking(
367 ((hal_spi_master_handle_t)&serialSpiMasterHandle->spiMasterHandleBuffer[0]), &masterReceiver);
368 }
369
Serial_SpiSlaveRead(serial_handle_t serialHandle,uint8_t * buffer,uint32_t length)370 serial_manager_status_t Serial_SpiSlaveRead(serial_handle_t serialHandle, uint8_t *buffer, uint32_t length)
371 {
372 serial_spi_slave_state_t *serialSpiSlaveHandle;
373 hal_spi_transfer_t slaveReceiver;
374
375 assert(serialHandle);
376 assert(buffer);
377 assert(length);
378
379 serialSpiSlaveHandle = (serial_spi_slave_state_t *)serialHandle;
380 serialSpiSlaveHandle->rx.buffer = buffer;
381 serialSpiSlaveHandle->rx.length = (size_t)length;
382
383 if (kStatus_HAL_SpiSuccess !=
384 HAL_SpiSlaveTransferInstallCallback((hal_spi_slave_handle_t)serialSpiSlaveHandle->spiSlaveHandleBuffer,
385 Serial_SpiSlaveRxCallback, serialHandle))
386 {
387 return kStatus_SerialManager_Error;
388 }
389 slaveReceiver.txData = NULL;
390 slaveReceiver.rxData = buffer;
391 slaveReceiver.dataSize = (size_t)length;
392 slaveReceiver.flags = serialSpiSlaveHandle->configFlags;
393 return (serial_manager_status_t)HAL_SpiSlaveTransferNonBlocking(
394 ((hal_spi_slave_handle_t)&serialSpiSlaveHandle->spiSlaveHandleBuffer[0]), &slaveReceiver);
395 }
396
397 #else /* SERIAL_MANAGER_NON_BLOCKING_MODE */
Serial_SpiMasterWrite(serial_handle_t serialHandle,uint8_t * buffer,uint32_t length)398 serial_manager_status_t Serial_SpiMasterWrite(serial_handle_t serialHandle, uint8_t *buffer, uint32_t length)
399 {
400 serial_spi_master_state_t *serialSpiMasterHandle;
401 hal_spi_transfer_t mastetTransfer;
402
403 assert(serialHandle);
404 assert(buffer);
405 assert(length);
406
407 serialSpiMasterHandle = (serial_spi_master_state_t *)serialHandle;
408
409 mastetTransfer.txData = buffer;
410 mastetTransfer.rxData = NULL;
411 mastetTransfer.dataSize = (size_t)length;
412 return (serial_manager_status_t)HAL_SpiMasterTransferBlocking(
413 ((hal_spi_master_handle_t)&serialSpiMasterHandle->spiMasterHandleBuffer[0]), &mastetTransfer);
414 }
415
Serial_SpiMasterRead(serial_handle_t serialHandle,uint8_t * buffer,uint32_t length)416 serial_manager_status_t Serial_SpiMasterRead(serial_handle_t serialHandle, uint8_t *buffer, uint32_t length)
417 {
418 serial_spi_master_state_t *serialSpiMasterHandle;
419 hal_spi_transfer_t masterReceiver;
420
421 assert(serialHandle);
422 assert(buffer);
423 assert(length);
424
425 serialSpiMasterHandle = (serial_spi_master_state_t *)serialHandle;
426 masterReceiver.txData = NULL;
427 masterReceiver.rxData = buffer;
428 masterReceiver.dataSize = (size_t)length;
429 return (serial_manager_status_t)HAL_SpiMasterTransferBlocking(
430 ((hal_spi_master_handle_t)&serialSpiMasterHandle->spiMasterHandleBuffer[0]), &masterReceiver);
431 }
432 #if 0
433 serial_manager_status_t Serial_SpiSlaveWrite(serial_handle_t serialHandle, uint8_t *buffer, uint32_t length)
434 {
435 serial_spi_master_state_t *serialSpiSlaveHandle;
436 hal_spi_transfer_t slaveTransfer;
437
438 assert(serialHandle);
439 assert(buffer);
440 assert(length);
441
442 serialSpiSlaveHandle = (serial_spi_master_state_t *)serialHandle;
443
444 slaveTransfer.txData = buffer;
445 slaveTransfer.rxData = NULL;
446 slaveTransfer.dataSize = (size_t)length;
447 return (serial_manager_status_t)HAL_SpiSlaveTransferBlocking(
448 ((hal_spi_master_handle_t)&serialSpiSlaveHandle->spiSlaveHandleBuffer[0]), &slaveTransfer);
449 }
450
451 serial_manager_status_t Serial_SpiSlaveRead(serial_handle_t serialHandle, uint8_t *buffer, uint32_t length)
452 {
453 serial_spi_master_state_t *serialSpiSlaveHandle;
454 hal_spi_transfer_t slaveReceiver;
455
456 assert(serialHandle);
457 assert(buffer);
458 assert(length);
459
460 serialSpiSlaveHandle = (serial_spi_master_state_t *)serialHandle;
461 slaveReceiver.txData = NULL;
462 slaveReceiver.rxData = buffer;
463 slaveReceiver.dataSize = (size_t)length;
464 return (serial_manager_status_t)HAL_SpiSlaveTransferBlocking(
465 ((hal_spi_master_handle_t)&serialSpiSlaveHandle->spiSlaveHandleBuffer[0]), &slaveReceiver);
466 }
467 #endif
468 #endif
469
470 #if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
471
Serial_SpiMasterInstallTxCallback(serial_handle_t serialHandle,serial_manager_callback_t callback,void * callbackParam)472 serial_manager_status_t Serial_SpiMasterInstallTxCallback(serial_handle_t serialHandle,
473 serial_manager_callback_t callback,
474 void *callbackParam)
475 {
476 serial_spi_master_state_t *serialSpiMasterHandle;
477
478 assert(serialHandle);
479
480 serialSpiMasterHandle = (serial_spi_master_state_t *)serialHandle;
481
482 serialSpiMasterHandle->tx.callback = callback;
483 serialSpiMasterHandle->tx.callbackParam = callbackParam;
484
485 return kStatus_SerialManager_Success;
486 }
487
Serial_SpiMasterInstallRxCallback(serial_handle_t serialHandle,serial_manager_callback_t callback,void * callbackParam)488 serial_manager_status_t Serial_SpiMasterInstallRxCallback(serial_handle_t serialHandle,
489 serial_manager_callback_t callback,
490 void *callbackParam)
491 {
492 serial_spi_master_state_t *serialSpiMasterHandle;
493
494 assert(serialHandle);
495
496 serialSpiMasterHandle = (serial_spi_master_state_t *)serialHandle;
497
498 serialSpiMasterHandle->rx.callback = callback;
499 serialSpiMasterHandle->rx.callbackParam = callbackParam;
500
501 return kStatus_SerialManager_Success;
502 }
503
Serial_SpiSlaveInstallTxCallback(serial_handle_t serialHandle,serial_manager_callback_t callback,void * callbackParam)504 serial_manager_status_t Serial_SpiSlaveInstallTxCallback(serial_handle_t serialHandle,
505 serial_manager_callback_t callback,
506 void *callbackParam)
507 {
508 serial_spi_slave_state_t *serialSpiSlaveHandle;
509
510 assert(serialHandle);
511
512 serialSpiSlaveHandle = (serial_spi_slave_state_t *)serialHandle;
513
514 serialSpiSlaveHandle->tx.callback = callback;
515 serialSpiSlaveHandle->tx.callbackParam = callbackParam;
516
517 return kStatus_SerialManager_Success;
518 }
519
Serial_SpiSlaveInstallRxCallback(serial_handle_t serialHandle,serial_manager_callback_t callback,void * callbackParam)520 serial_manager_status_t Serial_SpiSlaveInstallRxCallback(serial_handle_t serialHandle,
521 serial_manager_callback_t callback,
522 void *callbackParam)
523 {
524 serial_spi_slave_state_t *serialSpiSlaveHandle;
525
526 assert(serialHandle);
527
528 serialSpiSlaveHandle = (serial_spi_slave_state_t *)serialHandle;
529
530 serialSpiSlaveHandle->rx.callback = callback;
531 serialSpiSlaveHandle->rx.callbackParam = callbackParam;
532
533 return kStatus_SerialManager_Success;
534 }
535
Serial_SpiMasterCancelWrite(serial_handle_t serialHandle)536 serial_manager_status_t Serial_SpiMasterCancelWrite(serial_handle_t serialHandle)
537 {
538 serial_spi_master_state_t *serialSpiMaster;
539
540 assert(serialHandle);
541
542 serialSpiMaster = (serial_spi_master_state_t *)serialHandle;
543
544 if (kStatus_HAL_SpiSuccess !=
545 HAL_SpiMasterTransferAbort((hal_spi_master_handle_t)serialSpiMaster->spiMasterHandleBuffer))
546
547 {
548 return kStatus_SerialManager_Error;
549 }
550
551 return kStatus_SerialManager_Success;
552 }
553
Serial_SpiSlaveCancelWrite(serial_handle_t serialHandle)554 serial_manager_status_t Serial_SpiSlaveCancelWrite(serial_handle_t serialHandle)
555 {
556 serial_spi_slave_state_t *serialSpiSlave;
557
558 assert(serialHandle);
559
560 serialSpiSlave = (serial_spi_slave_state_t *)serialHandle;
561
562 if (kStatus_HAL_SpiSuccess !=
563 HAL_SpiSlaveTransferAbort((hal_spi_slave_handle_t)serialSpiSlave->spiSlaveHandleBuffer))
564
565 {
566 return kStatus_SerialManager_Error;
567 }
568
569 return kStatus_SerialManager_Success;
570 }
571
572 #endif
573