1 /* 2 * Copyright (c) 2016, Freescale Semiconductor, Inc. 3 * Copyright 2016-2020 NXP 4 * All rights reserved. 5 * 6 * SPDX-License-Identifier: BSD-3-Clause 7 */ 8 #ifndef __FSL_ECSPI_FREERTOS_H__ 9 #define __FSL_ECSPI_FREERTOS_H__ 10 11 #include "FreeRTOS.h" 12 #include "portable.h" 13 #include "semphr.h" 14 15 #include "fsl_ecspi.h" 16 17 /*! 18 * @addtogroup ecspi_freertos_driver 19 * @{ 20 */ 21 22 /******************************************************************************* 23 * Definitions 24 ******************************************************************************/ 25 26 /*! @name Driver version */ 27 /*@{*/ 28 /*! @brief ECSPI FreeRTOS driver version. */ 29 #define FSL_ECSPI_FREERTOS_DRIVER_VERSION (MAKE_VERSION(2, 2, 0)) 30 /*@}*/ 31 32 /*! 33 * @cond RTOS_PRIVATE 34 * @brief ECSPI FreeRTOS handle 35 */ 36 typedef struct _ecspi_rtos_handle 37 { 38 ECSPI_Type *base; /*!< ECSPI base address */ 39 ecspi_master_handle_t drv_handle; /*!< Handle of the underlying driver, treated as opaque by the RTOS layer */ 40 status_t async_status; /*!< Transactional state of the underlying driver */ 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 #if (configSUPPORT_STATIC_ALLOCATION == 1) 44 StaticSemaphore_t mutexBuffer; /*!< Statically allocated memory for mutex */ 45 StaticSemaphore_t semaphoreBuffer; /*!< Statically allocated memory for event */ 46 #endif 47 } ecspi_rtos_handle_t; 48 /*! \endcond */ 49 50 /******************************************************************************* 51 * API 52 ******************************************************************************/ 53 54 #if defined(__cplusplus) 55 extern "C" { 56 #endif 57 58 /*! 59 * @name ECSPI RTOS Operation 60 * @{ 61 */ 62 63 /*! 64 * @brief Initializes ECSPI. 65 * 66 * This function initializes the ECSPI module and related RTOS context. 67 * 68 * @param handle The RTOS ECSPI handle, the pointer to an allocated space for RTOS context. 69 * @param base The pointer base address of the ECSPI instance to initialize. 70 * @param masterConfig Configuration structure to set-up ECSPI in master mode. 71 * @param srcClock_Hz Frequency of input clock of the ECSPI module. 72 * @return status of the operation. 73 */ 74 status_t ECSPI_RTOS_Init(ecspi_rtos_handle_t *handle, 75 ECSPI_Type *base, 76 const ecspi_master_config_t *masterConfig, 77 uint32_t srcClock_Hz); 78 79 /*! 80 * @brief Deinitializes the ECSPI. 81 * 82 * This function deinitializes the ECSPI module and related RTOS context. 83 * 84 * @param handle The RTOS ECSPI handle. 85 */ 86 status_t ECSPI_RTOS_Deinit(ecspi_rtos_handle_t *handle); 87 88 /*! 89 * @brief Performs ECSPI transfer. 90 * 91 * This function performs an ECSPI transfer according to data given in the transfer structure. 92 * 93 * @param handle The RTOS ECSPI handle. 94 * @param transfer Structure specifying the transfer parameters. 95 * @return status of the operation. 96 */ 97 status_t ECSPI_RTOS_Transfer(ecspi_rtos_handle_t *handle, ecspi_transfer_t *transfer); 98 99 /*! 100 * @} 101 */ 102 103 #if defined(__cplusplus) 104 } 105 #endif 106 107 /*! 108 * @} 109 */ 110 111 #endif /* __FSL_ECSPI_FREERTOS_H__ */ 112