dev_common.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /* ------------------------------------------
  2. * Copyright (c) 2016, Synopsys, Inc. All rights reserved.
  3. * Redistribution and use in source and binary forms, with or without modification,
  4. * are permitted provided that the following conditions are met:
  5. * 1) Redistributions of source code must retain the above copyright notice, this
  6. * list of conditions and the following disclaimer.
  7. * 2) Redistributions in binary form must reproduce the above copyright notice,
  8. * this list of conditions and the following disclaimer in the documentation and/or
  9. * other materials provided with the distribution.
  10. * 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may
  11. * be used to endorse or promote products derived from this software without
  12. * specific prior written permission.
  13. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  14. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  15. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  16. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  17. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  18. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  19. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  20. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  21. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  22. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. *
  24. * \version 2016.05
  25. * \date 2014-06-16
  26. * \author Huaqi Fang(Huaqi.Fang@synopsys.com)
  27. --------------------------------------------- */
  28. /**
  29. * \defgroup DEVICE_HAL_COMMON Common Device Layer Definitions
  30. * \ingroup DEVICE_HAL_DEF
  31. * \brief common definitions for device layer (\ref dev_common.h)
  32. *
  33. * @{
  34. *
  35. * \file
  36. * \brief header file to define common definitions for device layer
  37. * \details Here in this file provide definitions that need by other
  38. * devices in device layer
  39. */
  40. #ifndef _DEVICE_HAL_COMMON_H_
  41. #define _DEVICE_HAL_COMMON_H_
  42. #include <stdint.h>
  43. /**
  44. * \defgroup DEVICE_HAL_COMMON_DEVSTATE Common Device State
  45. * \ingroup DEVICE_HAL_COMMON
  46. * \brief definitions for device state
  47. * \details here defines macros for device open/close,
  48. * device working good/error, used in
  49. * \ref DEVICE_HAL_UART, \ref DEVICE_HAL_SPI,
  50. * \ref DEVICE_HAL_IIC, \ref DEVICE_HAL_GPIO
  51. * @{
  52. */
  53. /*
  54. * macros for device open and close state
  55. */
  56. #define DEV_CLOSED (0) /*!< Indicate that device was closed */
  57. #define DEV_OPENED (1) /*!< Indicate that the device was opened */
  58. /*
  59. * macros for device good and error state
  60. */
  61. #define DEV_GOOD (0) /*!< Indicate device is good */
  62. #define DEV_ERROR (1) /*!< Indicate device error */
  63. /** @} */
  64. /**
  65. * \defgroup DEVICE_HAL_COMMON_DEVMTHD Common Device Working Method
  66. * \ingroup DEVICE_HAL_COMMON
  67. * \brief definitions for device working method(interrupt or poll)
  68. * \details here defines macros for working method,
  69. * interrupt or poll method,used in
  70. * \ref DEVICE_HAL_UART, \ref DEVICE_HAL_SPI,
  71. * \ref DEVICE_HAL_IIC, \ref DEVICE_HAL_GPIO
  72. * @{
  73. */
  74. /*
  75. * macros for device working method
  76. */
  77. #define DEV_POLL_METHOD (0) /*!< Indicate that the device running in poll method */
  78. #define DEV_INTERRUPT_METHOD (1) /*!< Indicate that the device running in interrupt method */
  79. /** @} */
  80. /**
  81. * \defgroup DEVICE_HAL_COMMON_DEVMODE Common Device Working Mode
  82. * \ingroup DEVICE_HAL_COMMON
  83. * \brief definitions for device working mode(master or slave)
  84. * \details here defines macros for working mode,
  85. * Master or Slave mode,used in
  86. * \ref DEV_HAL_IIC, \ref DEV_HAL_SPI.
  87. * @{
  88. */
  89. /*
  90. * macros for device working mode
  91. */
  92. #define DEV_MASTER_MODE (0) /*!< Indicate that the device working as master */
  93. #define DEV_SLAVE_MODE (1) /*!< Indicate that the device working as slave */
  94. /** @} */
  95. /**
  96. * \defgroup DEVICE_HAL_COMMON_DEVSTATUS Common Device Status
  97. * \ingroup DEVICE_HAL_COMMON
  98. * \brief definitions for device status, 1 bit for 1 function
  99. * @{
  100. */
  101. #define DEV_DISABLED (0) /*!< Bit 0 for device enabled state, disabled */
  102. #define DEV_ENABLED (1<<0) /*!< Bit 0 for device enabled state, enabled */
  103. #define DEV_IN_TX (1<<1) /*!< Bit 1 for device in transmit state */
  104. #define DEV_IN_RX (1<<2) /*!< Bit 2 for device in receive state */
  105. #define DEV_IN_XFER (1<<3) /*!< Bit 3 for device in transfer state */
  106. #define DEV_IN_TX_ABRT (1<<4) /*!< Bit 4 for device in transmit abort state */
  107. #define DEV_IN_RX_ABRT (1<<5) /*!< Bit 5 for device in receive abort state */
  108. #define DEV_IN_XFER_ABRT (1<<6) /*!< Bit 6 for device in transfer abort state */
  109. /** @} */
  110. /**
  111. * \defgroup DEVICE_HAL_COMMON_DEFCMD Common Device Defining Command
  112. * \ingroup DEVICE_HAL_COMMON
  113. * \brief definitions for defining command code
  114. * \details here defines macros to define command code,
  115. * in system code, use \ref DEV_SET_SYSCMD to define command code.
  116. * in user code, use \ref DEV_SET_USRCMD to define command code.
  117. * So that there will be no conflicts in system and user defined command code.
  118. * this used used in
  119. * \ref DEVICE_HAL_UART, \ref DEVICE_HAL_SPI,
  120. * \ref DEVICE_HAL_IIC, \ref DEVICE_HAL_GPIO,
  121. * and in user code
  122. * @{
  123. */
  124. /*
  125. * macros for control command base
  126. */
  127. #define DEV_SYS_CMDBSE (0x00000000) /*!< default system device control command base(defined by embARC) */
  128. #define DEV_USR_CMDBSE (0x80000000) /*!< default user device control command base(defined by user) in user implementing */
  129. #define DEV_SET_SYSCMD(cmd) (DEV_SYS_CMDBSE|(cmd)) /*!< set device system control command */
  130. #define DEV_SET_USRCMD(cmd) (DEV_USR_CMDBSE|(cmd)) /*!< set device user control command */
  131. #define CONV2VOID(param) ((void *)(param)) /*!< convert param into void * type */
  132. /** @} */
  133. /**
  134. * Common Device Buffer Structure
  135. */
  136. typedef struct dev_buffer {
  137. void *buf; /*!< buffer pointer */
  138. uint32_t len; /*!< buffer length in bytes */
  139. uint32_t ofs; /*!< current offset in buffer */
  140. } DEV_BUFFER;
  141. /** Init device buffer */
  142. #define DEV_BUFFER_INIT(devbuf, buffer, size) { \
  143. (devbuf)->buf = (void *)(buffer); \
  144. (devbuf)->len = (uint32_t)(size); \
  145. (devbuf)->ofs = (uint32_t)(0); \
  146. }
  147. /**
  148. * Device callback function typedef.
  149. * This is usually used in device callback settings,
  150. * and \ptr should be the device object pointer,
  151. * such as DEV_IIC * */
  152. typedef void (*DEV_CALLBACK) (void *ptr);
  153. /** @} */
  154. #endif /* _DEVICE_HAL_COMMON_H_ */