esp_modbus_slave.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* Copyright 2018 Espressif Systems (Shanghai) PTE LTD
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. #ifndef _ESP_MB_SLAVE_INTERFACE_H
  16. #define _ESP_MB_SLAVE_INTERFACE_H
  17. // Public interface header for slave
  18. #include <stdint.h> // for standard int types definition
  19. #include <stddef.h> // for NULL and std defines
  20. #include "soc/soc.h" // for BITN definitions
  21. #include "freertos/FreeRTOS.h" // for task creation and queues access
  22. #include "freertos/event_groups.h" // for event groups
  23. #include "esp_modbus_common.h" // for common types
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. /**
  28. * @brief Parameter access event information type
  29. */
  30. typedef struct {
  31. uint32_t time_stamp; /*!< Timestamp of Modbus Event (uS)*/
  32. uint16_t mb_offset; /*!< Modbus register offset */
  33. mb_event_group_t type; /*!< Modbus event type */
  34. uint8_t* address; /*!< Modbus data storage address */
  35. size_t size; /*!< Modbus event register size (number of registers)*/
  36. } mb_param_info_t;
  37. /**
  38. * @brief Parameter storage area descriptor
  39. */
  40. typedef struct {
  41. uint16_t start_offset; /*!< Modbus start address for area descriptor */
  42. mb_param_type_t type; /*!< Type of storage area descriptor */
  43. void* address; /*!< Instance address for storage area descriptor */
  44. size_t size; /*!< Instance size for area descriptor (bytes) */
  45. } mb_register_area_descriptor_t;
  46. /**
  47. * @brief Initialize Modbus controller and stack
  48. *
  49. * @param[out] handler handler(pointer) to master data structure
  50. * @param[in] port_type type of stack
  51. * @return
  52. * - ESP_OK Success
  53. * - ESP_ERR_NO_MEM Parameter error
  54. */
  55. //esp_err_t mbc_slave_init(mb_port_type_t port_type, void** handler);
  56. esp_err_t mbc_slave_init(mb_port_type_t port_type, void** handler);
  57. /**
  58. * @brief Destroy Modbus controller and stack
  59. *
  60. * @return
  61. * - ESP_OK Success
  62. * - ESP_ERR_INVALID_STATE Parameter error
  63. */
  64. esp_err_t mbc_slave_destroy(void);
  65. /**
  66. * @brief Start Modbus communication stack
  67. *
  68. * @return
  69. * - ESP_OK Success
  70. * - ESP_ERR_INVALID_ARG Modbus stack start error
  71. */
  72. esp_err_t mbc_slave_start(void);
  73. /**
  74. * @brief Set Modbus communication parameters for the controller
  75. *
  76. * @param comm_info Communication parameters structure.
  77. *
  78. * @return
  79. * - ESP_OK Success
  80. * - ESP_ERR_INVALID_ARG Incorrect parameter data
  81. */
  82. esp_err_t mbc_slave_setup(void* comm_info);
  83. /**
  84. * @brief Wait for specific event on parameter change.
  85. *
  86. * @param group Group event bit mask to wait for change
  87. *
  88. * @return
  89. * - mb_event_group_t event bits triggered
  90. */
  91. mb_event_group_t mbc_slave_check_event(mb_event_group_t group);
  92. /**
  93. * @brief Get parameter information
  94. *
  95. * @param[out] reg_info parameter info structure
  96. * @param timeout Timeout in milliseconds to read information from
  97. * parameter queue
  98. * @return
  99. * - ESP_OK Success
  100. * - ESP_ERR_TIMEOUT Can not get data from parameter queue
  101. * or queue overflow
  102. */
  103. esp_err_t mbc_slave_get_param_info(mb_param_info_t* reg_info, uint32_t timeout);
  104. /**
  105. * @brief Set Modbus area descriptor
  106. *
  107. * @param descr_data Modbus registers area descriptor structure
  108. *
  109. * @return
  110. * - ESP_OK: The appropriate descriptor is set
  111. * - ESP_ERR_INVALID_ARG: The argument is incorrect
  112. */
  113. esp_err_t mbc_slave_set_descriptor(mb_register_area_descriptor_t descr_data);
  114. #ifdef __cplusplus
  115. }
  116. #endif
  117. #endif