drv_crc.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * Copyright (C) 2017 C-SKY Microsystems Co., Ltd. All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /******************************************************************************
  17. * @file drv_crc.h
  18. * @brief Header File for CRC Driver
  19. * @version V1.0
  20. * @date 02. June 2017
  21. ******************************************************************************/
  22. #ifndef _CSI_CRC_H_
  23. #define _CSI_CRC_H_
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. #include <stdint.h>
  28. #include <drv_errno.h>
  29. #include <drv_common.h>
  30. /****** CRC specific error codes *****/
  31. #define CRC_ERROR_MODE (EDRV_SPECIFIC + 1) ///< Specified Mode not supported
  32. /// definition for crc handle.
  33. typedef void *crc_handle_t;
  34. /*----- CRC Control Codes: Mode -----*/
  35. typedef enum {
  36. CRC_MODE_CRC8 = 0, ///< Mode CRC8
  37. CRC_MODE_CRC16 , ///< Mode CRC16
  38. CRC_MODE_CRC32 ///< Mode CRC32
  39. } crc_mode_e;
  40. /*----- CRC Control Codes: Mode Parameters: Key length -----*/
  41. typedef enum {
  42. CRC_STANDARD_CRC_ROHC = 0, ///< Standard CRC RHOC
  43. CRC_STANDARD_CRC_MAXIM , ///< Standard CRC MAXIAM
  44. CRC_STANDARD_CRC_X25 , ///< Standard CRC X25
  45. CRC_STANDARD_CRC_CCITT , ///< Standard CRC CCITT
  46. CRC_STANDARD_CRC_USB , ///< Standard CRC USB
  47. CRC_STANDARD_CRC_IBM , ///< Standard CRC IBM
  48. CRC_STANDARD_CRC_MODBUS ///< Standard CRC MODBUS
  49. } crc_standard_crc_e;
  50. /**
  51. \brief CRC Status
  52. */
  53. typedef struct {
  54. uint32_t busy : 1; ///< busy flag
  55. } crc_status_t;
  56. /****** CRC Event *****/
  57. typedef enum {
  58. CRC_EVENT_CALCULATE_COMPLETE = 0, ///< Calculate completed
  59. } crc_event_e;
  60. typedef void (*crc_event_cb_t)(crc_event_e event); ///< Pointer to \ref crc_event_cb_t : CRC Event call back.
  61. /**
  62. \brief CRC Device Driver Capabilities.
  63. */
  64. typedef struct {
  65. uint32_t ROHC : 1; ///< supports ROHC mode
  66. uint32_t MAXIM : 1; ///< supports MAXIM mode
  67. uint32_t X25 : 1; ///< supports X25 mode
  68. uint32_t CCITT : 1; ///< supports CCITT mode
  69. uint32_t USB : 1; ///< supports USB mode
  70. uint32_t IBM : 1; ///< supports IBM mode
  71. uint32_t MODBUS : 1; ///< supports MODBUS mode
  72. } crc_capabilities_t;
  73. // Function documentation
  74. /**
  75. \brief get crc handle count.
  76. \return crc handle count
  77. */
  78. int32_t csi_crc_get_instance_count(void);
  79. /**
  80. \brief Initialize CRC Interface. 1. Initializes the resources needed for the CRC interface 2.registers event callback function
  81. \param[in] idx must not exceed return value of csi_crc_get_handle_count()
  82. \param[in] cb_event Pointer to \ref crc_event_cb_t
  83. \return return crc handle if success
  84. */
  85. crc_handle_t csi_crc_initialize(int32_t idx, crc_event_cb_t cb_event);
  86. /**
  87. \brief De-initialize CRC Interface. stops operation and releases the software resources used by the interface
  88. \param[in] handle crc handle to operate.
  89. \return error code
  90. */
  91. int32_t csi_crc_uninitialize(crc_handle_t handle);
  92. /**
  93. \brief Get driver capabilities.
  94. \param[in] handle crc handle to operate.
  95. \return \ref crc_capabilities_t
  96. */
  97. crc_capabilities_t csi_crc_get_capabilities(crc_handle_t handle);
  98. /**
  99. \brief config crc mode.
  100. \param[in] handle crc handle to operate.
  101. \param[in] mode \ref crc_mode_e
  102. \param[in] standard \ref crc_standard_crc_e
  103. \return error code
  104. */
  105. int32_t csi_crc_config(crc_handle_t handle,
  106. crc_mode_e mode,
  107. crc_standard_crc_e standard
  108. );
  109. /**
  110. \brief calculate crc.
  111. \param[in] handle crc handle to operate.
  112. \param[in] in Pointer to the input data
  113. \param[out] out Pointer to the result.
  114. \param[in] len intpu data len.
  115. \return error code
  116. */
  117. int32_t csi_crc_calculate(crc_handle_t handle, const void *in, void *out, uint32_t len);
  118. /**
  119. \brief Get CRC status.
  120. \param[in] handle crc handle to operate.
  121. \return CRC status \ref crc_status_t
  122. */
  123. crc_status_t csi_crc_get_status(crc_handle_t handle);
  124. #ifdef __cplusplus
  125. }
  126. #endif
  127. #endif /* _CSI_CRC_H_ */