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