esp_modbus_slave_serial.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. #include "esp_err.h" // for esp_err_t
  16. #include "sdkconfig.h" // for KConfig defines
  17. #include "mbc_slave.h" // for slave interface define
  18. #include "esp_modbus_slave.h" // for public slave defines
  19. #include "mbc_serial_slave.h" // for public interface defines
  20. /**
  21. * Initialization of Modbus Serial slave controller
  22. */
  23. esp_err_t mbc_slave_init(mb_port_type_t port_type, void** handler)
  24. {
  25. void* port_handler = NULL;
  26. esp_err_t error = ESP_ERR_NOT_SUPPORTED;
  27. switch(port_type)
  28. {
  29. case MB_PORT_SERIAL_SLAVE:
  30. // Call constructor function of actual port implementation
  31. error = mbc_serial_slave_create(&port_handler);
  32. break;
  33. default:
  34. return ESP_ERR_NOT_SUPPORTED;
  35. }
  36. if ((port_handler != NULL) && (error == ESP_OK)) {
  37. mbc_slave_init_iface(port_handler);
  38. *handler = port_handler;
  39. }
  40. return error;
  41. }