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