fsl_io.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * The Clear BSD License
  3. * Copyright 2017 NXP
  4. * All rights reserved.
  5. *
  6. *
  7. * Redistribution and use in source and binary forms, with or without modification,
  8. * are permitted (subject to the limitations in the disclaimer below) provided
  9. * that the following conditions are met:
  10. *
  11. * o Redistributions of source code must retain the above copyright notice, this list
  12. * of conditions and the following disclaimer.
  13. *
  14. * o Redistributions in binary form must reproduce the above copyright notice, this
  15. * list of conditions and the following disclaimer in the documentation and/or
  16. * other materials provided with the distribution.
  17. *
  18. * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  24. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  25. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  26. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  27. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  28. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  29. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  30. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  32. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. */
  35. #ifndef _FSL_IO_H
  36. #define _FSL_IO_H
  37. #include "fsl_common.h"
  38. /*!
  39. * @addtogroup debugconsole
  40. * @{
  41. */
  42. /*******************************************************************************
  43. * Definitions
  44. ******************************************************************************/
  45. /*! @brief define a notify callback for IO
  46. * @param size , transfer data size.
  47. * @param rx, indicate a rx transfer is success.
  48. * @param tx, indicate a tx transfer is success.
  49. */
  50. typedef void (*notify)(size_t *size, bool rx, bool tx);
  51. /*! @brief State structure storing io. */
  52. typedef struct io_State
  53. {
  54. void *ioBase; /*!< Base of the IP register. */
  55. uint8_t ioType; /*!< device type */
  56. #ifdef DEBUG_CONSOLE_TRANSFER_NON_BLOCKING
  57. notify callBack; /*!< define the callback function for buffer */
  58. #endif
  59. } io_state_t;
  60. /*******************************************************************************
  61. * Prototypes
  62. ******************************************************************************/
  63. #if defined(__cplusplus)
  64. extern "C" {
  65. #endif /* __cplusplus */
  66. /*!
  67. * @brief io init function.
  68. *
  69. * Call this function to init IO.
  70. *
  71. * @param io configuration pointer
  72. * @param baudRate baud rate
  73. * @param clkSrcFreq clock freq
  74. * @param ringbuffer used to receive character
  75. */
  76. void IO_Init(io_state_t *io, uint32_t baudRate, uint32_t clkSrcFreq, uint8_t *ringBuffer);
  77. /*!
  78. * @brief Deinit IO.
  79. *
  80. * Call this function to Deinit IO.
  81. *
  82. * @return deinit status
  83. */
  84. status_t IO_Deinit(void);
  85. /*!
  86. * @brief io transfer function.
  87. *
  88. * Call this function to transfer log.
  89. * Print log:
  90. * @code
  91. * IO_Transfer(ch, size, true);
  92. * @endcode
  93. * Scanf log:
  94. * @code
  95. * IO_Transfer(ch, size, false);
  96. * @endcode
  97. *
  98. * @param ch transfer buffer pointer
  99. * @param size transfer size
  100. * @param tx indicate the transfer is TX or RX
  101. */
  102. status_t IO_Transfer(uint8_t *ch, size_t size, bool tx);
  103. /*!
  104. * @brief io wait idle.
  105. *
  106. * Call this function to wait the io idle
  107. *
  108. * @return Indicates whether wait idle was successful or not.
  109. */
  110. status_t IO_WaitIdle(void);
  111. #ifdef DEBUG_CONSOLE_TRANSFER_NON_BLOCKING
  112. /*!
  113. * @brief io try to receive one character.
  114. *
  115. * Call this function try to receive character
  116. * @param ch the address of char to receive
  117. * @return Indicates try getchar was successful or not.
  118. */
  119. status_t IO_TryReceiveCharacter(uint8_t *ch);
  120. #endif
  121. #if defined(__cplusplus)
  122. }
  123. #endif /* __cplusplus */
  124. /*! @} */
  125. #endif /* _FSL_IO_H */