Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 

112 рядки
3.1 KiB

  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_I2C_FREERTOS_H__
  9. #define __FSL_I2C_FREERTOS_H__
  10. #include "FreeRTOS.h"
  11. #include "portable.h"
  12. #include "semphr.h"
  13. #include "fsl_i2c.h"
  14. /*!
  15. * @addtogroup i2c_freertos_driver I2C FreeRTOS Driver
  16. * @{
  17. */
  18. /*******************************************************************************
  19. * Definitions
  20. ******************************************************************************/
  21. /*! @name Driver version */
  22. /*@{*/
  23. /*! @brief I2C FreeRTOS driver version 2.0.8. */
  24. #define FSL_I2C_FREERTOS_DRIVER_VERSION (MAKE_VERSION(2, 0, 8))
  25. /*@}*/
  26. /*!
  27. * @cond RTOS_PRIVATE
  28. * @brief I2C FreeRTOS handle
  29. */
  30. typedef struct _i2c_rtos_handle
  31. {
  32. I2C_Type *base; /*!< I2C base address */
  33. i2c_master_handle_t drv_handle; /*!< A handle of the underlying driver, treated as opaque by the RTOS layer */
  34. status_t async_status; /*!< Transactional state of the underlying driver */
  35. SemaphoreHandle_t mutex; /*!< A mutex to lock the handle during a transfer */
  36. SemaphoreHandle_t semaphore; /*!< A semaphore to notify and unblock task when the transfer ends */
  37. #if (configSUPPORT_STATIC_ALLOCATION == 1)
  38. StaticSemaphore_t mutexBuffer; /*!< Statically allocated memory for mutex */
  39. StaticSemaphore_t semaphoreBuffer; /*!< Statically allocated memory for semaphore */
  40. #endif
  41. } i2c_rtos_handle_t;
  42. /*! \endcond */
  43. /*******************************************************************************
  44. * API
  45. ******************************************************************************/
  46. #if defined(__cplusplus)
  47. extern "C" {
  48. #endif
  49. /*!
  50. * @name I2C RTOS Operation
  51. * @{
  52. */
  53. /*!
  54. * @brief Initializes I2C.
  55. *
  56. * This function initializes the I2C module and the related RTOS context.
  57. *
  58. * @param handle The RTOS I2C handle, the pointer to an allocated space for RTOS context.
  59. * @param base The pointer base address of the I2C instance to initialize.
  60. * @param masterConfig The configuration structure to set-up I2C in master mode.
  61. * @param srcClock_Hz The frequency of an input clock of the I2C module.
  62. * @return status of the operation.
  63. */
  64. status_t I2C_RTOS_Init(i2c_rtos_handle_t *handle,
  65. I2C_Type *base,
  66. const i2c_master_config_t *masterConfig,
  67. uint32_t srcClock_Hz);
  68. /*!
  69. * @brief Deinitializes the I2C.
  70. *
  71. * This function deinitializes the I2C module and the related RTOS context.
  72. *
  73. * @param handle The RTOS I2C handle.
  74. */
  75. status_t I2C_RTOS_Deinit(i2c_rtos_handle_t *handle);
  76. /*!
  77. * @brief Performs the I2C transfer.
  78. *
  79. * This function performs the I2C transfer according to the data given in the transfer structure.
  80. *
  81. * @param handle The RTOS I2C handle.
  82. * @param transfer A structure specifying the transfer parameters.
  83. * @return status of the operation.
  84. */
  85. status_t I2C_RTOS_Transfer(i2c_rtos_handle_t *handle, i2c_master_transfer_t *transfer);
  86. /*!
  87. * @}
  88. */
  89. #if defined(__cplusplus)
  90. }
  91. #endif
  92. /*!
  93. * @}
  94. */
  95. #endif /* __FSL_I2C_FREERTOS_H__ */