fsl_lpi2c_freertos.h 2.8 KB

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