boot_fdl_channel.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /* Copyright (C) 2017 RDA Technologies Limited and/or its affiliates("RDA").
  2. * All rights reserved.
  3. *
  4. * This software is supplied "AS IS" without any warranties.
  5. * RDA assumes no responsibility or liability for the use of the software,
  6. * conveys no license or title under any patent, copyright, or mask work
  7. * right to the product. RDA reserves the right to make changes in the
  8. * software without notification. RDA also make no representation or
  9. * warranty that such application will be suitable for the specified use
  10. * without further testing or modification.
  11. */
  12. #ifndef _BOOT_FDL_CHANNEL_H_
  13. #define _BOOT_FDL_CHANNEL_H_
  14. #include <stdint.h>
  15. #include <stdbool.h>
  16. #include <stddef.h>
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. /**
  21. * Abstract FDL channel
  22. *
  23. * For concrete FDL channel, it must be put at the beginning for data
  24. * type casting.
  25. */
  26. typedef struct fdlChannel
  27. {
  28. /**
  29. * whether baud rate is supported
  30. *
  31. * @param ch the FDL channel
  32. * @param baud baud rate to be checked
  33. * @return
  34. * - true on supported
  35. * - false on unsupported
  36. */
  37. bool (*baud_supported)(struct fdlChannel *ch, uint32_t baud);
  38. /**
  39. * Set baud rate
  40. *
  41. * If the channel doesn't have baud rate, just return \a true.
  42. *
  43. * @param ch the FDL channel
  44. * @param baud baud rate
  45. * @return
  46. * - true if the baud rate is changed
  47. * - false if failed
  48. */
  49. bool (*set_baud)(struct fdlChannel *ch, uint32_t baud);
  50. /**
  51. * Read from the channel
  52. *
  53. * @param ch the FDL channel
  54. * @param data memory for read data
  55. * @param size maximum read size
  56. * @return actual read size
  57. */
  58. int (*read)(struct fdlChannel *ch, void *data, size_t size);
  59. /**
  60. * Write to the channel
  61. *
  62. * @param ch the FDL channel
  63. * @param data pointer of data to be written
  64. * @param size maximum write size
  65. * @return actual written size
  66. */
  67. int (*write)(struct fdlChannel *ch, const void *data, size_t size);
  68. /**
  69. * Flush and drop input
  70. *
  71. * @param ch the FDL channel
  72. */
  73. void (*flush_input)(struct fdlChannel *ch);
  74. /**
  75. * Flush output
  76. *
  77. * When there are cache in serial, flush the cache.
  78. *
  79. * @param ch the FDL channel
  80. */
  81. void (*flush)(struct fdlChannel *ch);
  82. /**
  83. * Destroy fdl channel
  84. *
  85. * @param ch the FDL channel
  86. */
  87. void (*destroy)(struct fdlChannel *ch);
  88. /**
  89. * Check fdl channel connected or not
  90. *
  91. * @param ch the FDL channel
  92. * @return ture on connected else false
  93. */
  94. bool (*connected)(struct fdlChannel *ch);
  95. } fdlChannel_t;
  96. /**
  97. * @brief open UART FDL channel
  98. *
  99. * @param input UART baudrate
  100. * The UART used, and UART baud can be config.
  101. *
  102. * @return UART FDL channel.
  103. */
  104. fdlChannel_t *fdlOpenUart(uint32_t name, uint32_t baud, bool reconfig);
  105. /**
  106. * @breif open USB Serial FDL channel
  107. * @return USB Serial FDL channel
  108. */
  109. fdlChannel_t *fdlOpenUsbSerial(void);
  110. #ifdef __cplusplus
  111. }
  112. #endif
  113. #endif