serial_io.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* Copyright 2020 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. #pragma once
  16. #include <stdint.h>
  17. #include "esp_loader.h"
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. /**
  22. * @brief Initializes serial interface.
  23. *
  24. * @param baud_rate[in] Communication speed.
  25. *
  26. * @return
  27. * - ESP_LOADER_SUCCESS Success
  28. * - ESP_LOADER_ERROR_FAIL Initialization failure
  29. */
  30. esp_loader_error_t loader_port_serial_init(uint32_t baud_rate);
  31. /**
  32. * @brief Deinitialize serial interface.
  33. */
  34. void loader_port_serial_deinit(void);
  35. /**
  36. * @brief Writes data to serial interface.
  37. *
  38. * @param data[in] Buffer with data to be written.
  39. * @param size[in] Size of data in bytes.
  40. * @param timeout[in] Timeout in milliseconds.
  41. *
  42. * @return
  43. * - ESP_LOADER_SUCCESS Success
  44. * - ESP_LOADER_ERROR_TIMEOUT Timeout elapsed
  45. */
  46. esp_loader_error_t loader_port_serial_write(const uint8_t *data, uint16_t size, uint32_t timeout);
  47. /**
  48. * @brief Reads data from serial interface.
  49. *
  50. * @param data[out] Buffer into which received data will be written.
  51. * @param size[in] Number of bytes to read.
  52. * @param timeout[in] Timeout in milliseconds.
  53. *
  54. * @return
  55. * - ESP_LOADER_SUCCESS Success
  56. * - ESP_LOADER_ERROR_TIMEOUT Timeout elapsed
  57. */
  58. esp_loader_error_t loader_port_serial_read(uint8_t *data, uint16_t size, uint32_t timeout);
  59. /**
  60. * @brief Delay in milliseconds.
  61. *
  62. * @param ms[in] Number of milliseconds.
  63. *
  64. */
  65. void loader_port_delay_ms(uint32_t ms);
  66. /**
  67. * @brief Starts timeout timer.
  68. *
  69. * @param ms[in] Number of milliseconds.
  70. *
  71. */
  72. void loader_port_start_timer(uint32_t ms);
  73. /**
  74. * @brief Returns remaining time since timer was started by calling esp_loader_start_timer.
  75. * 0 if timer has elapsed.
  76. *
  77. * @return Number of milliseconds.
  78. *
  79. */
  80. uint32_t loader_port_remaining_time(void);
  81. /**
  82. * @brief Asserts bootstrap pins to enter boot mode and toggles reset pin.
  83. *
  84. * @note Reset pin should stay asserted for at least 20 milliseconds.
  85. */
  86. void loader_port_enter_bootloader(void);
  87. /**
  88. * @brief Toggles reset pin.
  89. *
  90. * @note Reset pin should stay asserted for at least 20 milliseconds.
  91. */
  92. void loader_port_reset_target(void);
  93. /**
  94. * @brief Function can be defined by user to print debug message.
  95. *
  96. * @note Empty weak function is used, otherwise.
  97. *
  98. */
  99. void loader_port_debug_print(const char *str);
  100. #ifdef __cplusplus
  101. }
  102. #endif