1 /*
2  * Copyright (c) 2016, Freescale Semiconductor, Inc.
3  * Copyright 2016-2019 NXP
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 #ifndef FSL_SPI_FREERTOS_H__
9 #define FSL_SPI_FREERTOS_H__
10 
11 #include "FreeRTOS.h"
12 #include "portable.h"
13 #include "semphr.h"
14 
15 #include "fsl_spi.h"
16 
17 /*!
18  * @addtogroup spi_freertos_driver
19  * @{
20  */
21 
22 /*! @file */
23 
24 /*******************************************************************************
25  * Definitions
26  ******************************************************************************/
27 
28 /*! @name Driver version */
29 /*! @{ */
30 /*! @brief SPI FreeRTOS driver version 2.1.0. */
31 #define FSL_SPI_FREERTOS_DRIVER_VERSION (MAKE_VERSION(2, 1, 0))
32 /*! @} */
33 
34 /*! @brief SPI FreeRTOS handle */
35 typedef struct _spi_rtos_handle
36 {
37     SPI_Type *base;                 /*!< SPI base address */
38     spi_master_handle_t drv_handle; /*!< Handle of the underlying driver, treated as opaque by the RTOS layer */
39     status_t async_status;
40     SemaphoreHandle_t mutex; /*!< Mutex to lock the handle during a trasfer */
41     SemaphoreHandle_t event; /*!< Semaphore to notify and unblock task when transfer ends */
42 } spi_rtos_handle_t;
43 
44 /*******************************************************************************
45  * API
46  ******************************************************************************/
47 
48 #if defined(__cplusplus)
49 extern "C" {
50 #endif
51 
52 /*!
53  * @name SPI RTOS Operation
54  * @{
55  */
56 
57 /*!
58  * @brief Initializes SPI.
59  *
60  * This function initializes the SPI module and related RTOS context.
61  *
62  * @param handle The RTOS SPI handle, the pointer to an allocated space for RTOS context.
63  * @param base The pointer base address of the SPI instance to initialize.
64  * @param masterConfig Configuration structure to set-up SPI in master mode.
65  * @param srcClock_Hz Frequency of input clock of the SPI module.
66  * @return status of the operation.
67  */
68 status_t SPI_RTOS_Init(spi_rtos_handle_t *handle,
69                        SPI_Type *base,
70                        const spi_master_config_t *masterConfig,
71                        uint32_t srcClock_Hz);
72 
73 /*!
74  * @brief Deinitializes the SPI.
75  *
76  * This function deinitializes the SPI module and related RTOS context.
77  *
78  * @param handle The RTOS SPI handle.
79  */
80 status_t SPI_RTOS_Deinit(spi_rtos_handle_t *handle);
81 
82 /*!
83  * @brief Performs SPI transfer.
84  *
85  * This function performs an SPI transfer according to data given in the transfer structure.
86  *
87  * @param handle The RTOS SPI handle.
88  * @param transfer Structure specifying the transfer parameters.
89  * @return status of the operation.
90  */
91 status_t SPI_RTOS_Transfer(spi_rtos_handle_t *handle, spi_transfer_t *transfer);
92 
93 /*!
94  * @}
95  */
96 
97 #if defined(__cplusplus)
98 }
99 #endif
100 
101 /*!
102  * @}
103  */
104 
105 #endif /* FSL_SPI_FREERTOS_H__ */
106