serial_protocol.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright 2022 Stefan Kerkmann
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include <stddef.h>
  4. #include <stdint.h>
  5. #include <stdbool.h>
  6. #pragma once
  7. /**
  8. * @brief Clears any intermediate sending or receiving state of the driver to a known good
  9. * state. This happens after errors in the middle of transactions, to start with
  10. * a clean slate.
  11. */
  12. void serial_transport_driver_clear(void);
  13. /**
  14. * @brief Driver specific initialization on the slave half.
  15. */
  16. void serial_transport_driver_slave_init(void);
  17. /**
  18. * @brief Driver specific specific initialization on the master half.
  19. */
  20. void serial_transport_driver_master_init(void);
  21. /**
  22. * @brief Blocking receive of size * bytes.
  23. *
  24. * @return true Receive success.
  25. * @return false Receive failed, e.g. by bit errors.
  26. */
  27. bool __attribute__((nonnull, hot)) serial_transport_receive(uint8_t* destination, const size_t size);
  28. /**
  29. * @brief Blocking receive of size * bytes with an implicitly defined timeout.
  30. *
  31. * @return true Receive success.
  32. * @return false Receive failed, e.g. by timeout or bit errors.
  33. */
  34. bool __attribute__((nonnull, hot)) serial_transport_receive_blocking(uint8_t* destination, const size_t size);
  35. /**
  36. * @brief Blocking send of buffer with timeout.
  37. *
  38. * @return true Send success.
  39. * @return false Send failed, e.g. by timeout or bit errors.
  40. */
  41. bool __attribute__((nonnull, hot)) serial_transport_send(const uint8_t* source, const size_t size);