hal_uart.dox 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
  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. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. /**
  14. * @defgroup UART UART Driver
  15. * @brief Generic UART Driver.
  16. * @details This driver abstracts a generic UART (Universal Asynchronous
  17. * Receiver Transmitter) peripheral, the API is designed to be:
  18. * - Unbuffered and copy-less, transfers are always directly performed
  19. * from/to the application-level buffers without extra copy
  20. * operations.
  21. * - Asynchronous, the API is always non blocking.
  22. * - Callbacks capable, operations completion and other events are
  23. * notified using callbacks.
  24. * .
  25. * Special hardware features like deep hardware buffers, DMA transfers
  26. * are hidden to the user but fully supportable by the low level
  27. * implementations.<br>
  28. * This driver model is best used where communication events are
  29. * meant to drive an higher level state machine, as example:
  30. * - RS485 drivers.
  31. * - Multipoint network drivers.
  32. * - Serial protocol decoders.
  33. * .
  34. * If your application requires a synchronous buffered driver then
  35. * the @ref SERIAL should be used instead.
  36. * @pre In order to use the UART driver the @p HAL_USE_UART option
  37. * must be enabled in @p halconf.h.
  38. *
  39. * @section uart_1 Driver State Machine
  40. * The driver implements a state machine internally, not all the driver
  41. * functionalities can be used in any moment, any transition not explicitly
  42. * shown in the following diagram has to be considered an error and shall
  43. * be captured by an assertion (if enabled).
  44. * @dot
  45. digraph example {
  46. rankdir="LR";
  47. node [shape=circle, fontname=Helvetica, fontsize=8, fixedsize="true", width="0.9", height="0.9"];
  48. edge [fontname=Helvetica, fontsize=8];
  49. uninit [label="UART_UNINIT", style="bold"];
  50. stop [label="UART_STOP\nLow Power"];
  51. ready [label="UART_READY\nClock Enabled"];
  52. uninit -> stop [label="\nuartInit()"];
  53. stop -> ready [label="\nuartStart()"];
  54. ready -> ready [label="\nuartStart()"];
  55. ready -> stop [label="\nuartStop()"];
  56. stop -> stop [label="\nuartStop()"];
  57. }
  58. * @enddot
  59. *
  60. * @subsection uart_1_1 Transmitter sub State Machine
  61. * The follow diagram describes the transmitter state machine, this diagram
  62. * is valid while the driver is in the @p UART_READY state. This state
  63. * machine is automatically reset to the @p TX_IDLE state each time the
  64. * driver enters the @p UART_READY state.
  65. * @dot
  66. digraph example {
  67. rankdir="LR";
  68. node [shape=circle, fontname=Helvetica, fontsize=8, fixedsize="true", width="0.9", height="0.9"];
  69. edge [fontname=Helvetica, fontsize=8];
  70. tx_idle [label="TX_IDLE", style="bold"];
  71. tx_active [label="TX_ACTIVE"];
  72. tx_complete [label="TX_COMPLETE"];
  73. tx_idle -> tx_active [label="\nuartStartSend()"];
  74. tx_idle -> tx_idle [label="\nuartStopSend()\n>txend2_cb<"];
  75. tx_active -> tx_complete [label="\nbuffer transmitted\n>txend1_cb<"];
  76. tx_active -> tx_idle [label="\nuartStopSend()"];
  77. tx_complete -> tx_active [label="\nuartStartSendI()\nthen\ncallback return"];
  78. tx_complete -> tx_idle [label="\ncallback return"];
  79. }
  80. * @enddot
  81. *
  82. * @subsection uart_1_2 Receiver sub State Machine
  83. * The follow diagram describes the receiver state machine, this diagram
  84. * is valid while the driver is in the @p UART_READY state. This state
  85. * machine is automatically reset to the @p RX_IDLE state each time the
  86. * driver enters the @p UART_READY state.
  87. * @dot
  88. digraph example {
  89. rankdir="LR";
  90. node [shape=circle, fontname=Helvetica, fontsize=8, fixedsize="true", width="0.9", height="0.9"];
  91. edge [fontname=Helvetica, fontsize=8];
  92. rx_idle [label="RX_IDLE", style="bold"];
  93. rx_active [label="RX_ACTIVE"];
  94. rx_complete [label="RX_COMPLETE"];
  95. rx_idle -> rx_idle [label="\nuartStopReceive()\n>rxchar_cb<\n>rxerr_cb<"];
  96. rx_idle -> rx_active [label="\nuartStartReceive()"];
  97. rx_active -> rx_complete [label="\nbuffer filled\n>rxend_cb<"];
  98. rx_active -> rx_idle [label="\nuartStopReceive()"];
  99. rx_active -> rx_active [label="\nreceive error\n>rxerr_cb<"];
  100. rx_complete -> rx_active [label="\nuartStartReceiveI()"];
  101. rx_complete -> rx_idle [label="\ncallback return"];
  102. }
  103. * @enddot
  104. *
  105. * @ingroup HAL_NORMAL_DRIVERS
  106. */