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