hal_icu.dox 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 ICU ICU Driver
  15. * @brief Generic ICU Driver.
  16. * @details This module implements a generic ICU (Input Capture Unit) driver.
  17. * The purpose of the driver is to measure period and duty cycle of
  18. * an input digital signal (PWM input).
  19. * @pre In order to use the ICU driver the @p HAL_USE_ICU option
  20. * must be enabled in @p halconf.h.
  21. *
  22. * @section icu_1 Driver State Machine
  23. * The driver implements a state machine internally, not all the driver
  24. * functionalities can be used in any moment, any transition not explicitly
  25. * shown in the following diagram has to be considered an error and shall
  26. * be captured by an assertion (if enabled).
  27. * @if LATEX_PDF
  28. * @dot
  29. digraph example {
  30. size="5, 7";
  31. rankdir="LR";
  32. node [shape=circle, fontname=Sans, fontsize=8, fixedsize="true", width="0.9", height="0.9"];
  33. edge [fontname=Sans, fontsize=8];
  34. stop [label="ICU_STOP\nLow Power"];
  35. uninit [label="ICU_UNINIT", style="bold"];
  36. ready [label="ICU_READY\nClock Enabled"];
  37. waiting [label="ICU_WAITING"];
  38. active [label="ICU_ACTIVE"];
  39. uninit -> stop [label=" icuInit()", constraint=false];
  40. stop -> stop [label="\nicuStop()"];
  41. stop -> ready [label="\nicuStart()"];
  42. ready -> stop [label="\nicuStop()"];
  43. ready -> ready [label="\nicuStart()\nicuStopCapture()"];
  44. ready -> waiting [label="\nicuStartCapture()"];
  45. waiting -> active [label="\nFirst Activation Edge\nicuWaitCapture()"];
  46. waiting -> ready [label="\nicuStopCapture()"];
  47. active -> ready [label="\nicuStopCapture()"];
  48. active -> active [label="\nActivation Edge\n>period_cb<"];
  49. active -> active [label="\nDe-activation Edge\n>width_cb<"];
  50. }
  51. * @enddot
  52. * @else
  53. * @dot
  54. digraph example {
  55. rankdir="LR";
  56. node [shape=circle, fontname=Sans, fontsize=8, fixedsize="true", width="0.9", height="0.9"];
  57. edge [fontname=Sans, fontsize=8];
  58. stop [label="ICU_STOP\nLow Power"];
  59. uninit [label="ICU_UNINIT", style="bold"];
  60. ready [label="ICU_READY\nClock Enabled"];
  61. waiting [label="ICU_WAITING"];
  62. active [label="ICU_ACTIVE"];
  63. uninit -> stop [label=" icuInit()", constraint=false];
  64. stop -> stop [label="\nicuStop()"];
  65. stop -> ready [label="\nicuStart()"];
  66. ready -> stop [label="\nicuStop()"];
  67. ready -> ready [label="\nicuStart()\nicuStopCapture()"];
  68. ready -> waiting [label="\nicuStartCapture()"];
  69. waiting -> active [label="\nFirst Activation Edge\nicuWaitCapture()"];
  70. waiting -> ready [label="\nicuStopCapture()"];
  71. active -> ready [label="\nicuStopCapture()"];
  72. active -> active [label="\nActivation Edge\n>period_cb<"];
  73. active -> active [label="\nDe-activation Edge\n>width_cb<"];
  74. }
  75. * @enddot
  76. * @endif
  77. *
  78. * @section icu_2 ICU Operations.
  79. * This driver abstracts a generic Input Capture Unit composed of:
  80. * - A clock prescaler.
  81. * - A main up counter.
  82. * - Two capture registers triggered by the rising and falling edges on
  83. * the sampled input.
  84. * .
  85. * The ICU unit can be programmed to synchronize on the rising or falling
  86. * edge of the sample input:
  87. * - <b>ICU_INPUT_ACTIVE_HIGH</b>, a rising edge is the start signal.
  88. * - <b>ICU_INPUT_ACTIVE_LOW</b>, a falling edge is the start signal.
  89. * .
  90. * Callbacks are optionally invoked when:
  91. * - On the PWM de-activation edge.
  92. * - On the PWM activation edge, measurements for the previous cycle are
  93. * available from this callback and can be retrieved using
  94. * @p icuGetPeriodX() and @p icuGetWidthX().
  95. * .
  96. * @ingroup HAL_NORMAL_DRIVERS
  97. */