CO_LEDs.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /**
  2. * CANopen Indicator specification (CiA 303-3 v1.4.0)
  3. *
  4. * @file CO_LEDs.h
  5. * @ingroup CO_LEDs
  6. * @author Janez Paternoster
  7. * @copyright 2020 Janez Paternoster
  8. *
  9. * This file is part of CANopenNode, an opensource CANopen Stack.
  10. * Project home page is <https://github.com/CANopenNode/CANopenNode>.
  11. * For more information on CANopen see <http://www.can-cia.org/>.
  12. *
  13. * Licensed under the Apache License, Version 2.0 (the "License");
  14. * you may not use this file except in compliance with the License.
  15. * You may obtain a copy of the License at
  16. *
  17. * http://www.apache.org/licenses/LICENSE-2.0
  18. *
  19. * Unless required by applicable law or agreed to in writing, software
  20. * distributed under the License is distributed on an "AS IS" BASIS,
  21. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22. * See the License for the specific language governing permissions and
  23. * limitations under the License.
  24. */
  25. #ifndef CO_LEDS_H
  26. #define CO_LEDS_H
  27. #include "301/CO_driver.h"
  28. #include "301/CO_NMT_Heartbeat.h"
  29. /* default configuration, see CO_config.h */
  30. #ifndef CO_CONFIG_LEDS
  31. #define CO_CONFIG_LEDS (CO_CONFIG_LEDS_ENABLE)
  32. #endif
  33. #if ((CO_CONFIG_LEDS) & CO_CONFIG_LEDS_ENABLE) || defined CO_DOXYGEN
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37. /**
  38. * @defgroup CO_LEDs LED indicators
  39. * @ingroup CO_CANopen_303
  40. * @{
  41. *
  42. * CIA 303-3 standard specifies indicator LED diodes, which reflects state of
  43. * the CANopen device. Green and red leds or bi-color led can be used.
  44. *
  45. * CANopen green led - run led:
  46. * - flickering: LSS configuration state is active
  47. * - blinking: device is in NMT pre-operational state
  48. * - single flash: device is in NMT stopped state
  49. * - triple flash: a software download is running in the device
  50. * - on: device is in NMT operational state
  51. *
  52. * CANopen red led - error led:
  53. * - off: no error
  54. * - flickering: LSS node id is not configured, CANopen is not initialized
  55. * - blinking: invalid configuration, general error
  56. * - single flash: CAN warning limit reached
  57. * - double flash: heartbeat consumer - error in remote monitored node
  58. * - triple flash: sync message reception timeout
  59. * - quadruple flash: PDO has not been received before the event timer elapsed
  60. * - on: CAN bus off
  61. *
  62. * To apply on/off state to led diode, use #CO_LED_RED and #CO_LED_GREEN macros.
  63. * For CANopen leds use CO_LED_BITFIELD_t CO_LED_CANopen. Other bitfields are
  64. * available for implementing custom leds.
  65. */
  66. /** Bitfield for combining with red or green led */
  67. typedef enum {
  68. CO_LED_flicker = 0x01, /**< LED flickering 10Hz */
  69. CO_LED_blink = 0x02, /**< LED blinking 2,5Hz */
  70. CO_LED_flash_1 = 0x04, /**< LED single flash */
  71. CO_LED_flash_2 = 0x08, /**< LED double flash */
  72. CO_LED_flash_3 = 0x10, /**< LED triple flash */
  73. CO_LED_flash_4 = 0x20, /**< LED quadruple flash */
  74. CO_LED_CANopen = 0x80 /**< LED CANopen according to CiA 303-3 */
  75. } CO_LED_BITFIELD_t;
  76. /** Get on/off state for green led for specified bitfield */
  77. #define CO_LED_RED(LEDs, BITFIELD) (((LEDs)->LEDred & BITFIELD) ? 1 : 0)
  78. /** Get on/off state for green led for specified bitfield */
  79. #define CO_LED_GREEN(LEDs, BITFIELD) (((LEDs)->LEDgreen & BITFIELD) ? 1 : 0)
  80. /**
  81. * LEDs object, initialized by CO_LEDs_init()
  82. */
  83. typedef struct{
  84. uint32_t LEDtmr50ms; /**< 50ms led timer */
  85. uint8_t LEDtmr200ms; /**< 200ms led timer */
  86. uint8_t LEDtmrflash_1; /**< single flash led timer */
  87. uint8_t LEDtmrflash_2; /**< double flash led timer */
  88. uint8_t LEDtmrflash_3; /**< triple flash led timer */
  89. uint8_t LEDtmrflash_4; /**< quadruple flash led timer */
  90. uint8_t LEDred; /**< red led #CO_LED_BITFIELD_t */
  91. uint8_t LEDgreen; /**< green led #CO_LED_BITFIELD_t */
  92. } CO_LEDs_t;
  93. /**
  94. * Initialize LEDs object.
  95. *
  96. * Function must be called in the communication reset section.
  97. *
  98. * @param LEDs This object will be initialized.
  99. *
  100. * @return #CO_ReturnError_t CO_ERROR_NO or CO_ERROR_ILLEGAL_ARGUMENT.
  101. */
  102. CO_ReturnError_t CO_LEDs_init(CO_LEDs_t *LEDs);
  103. /**
  104. * Process indicator states
  105. *
  106. * Function must be called cyclically.
  107. *
  108. * @param LEDs This object.
  109. * @param timeDifference_us Time difference from previous function call in
  110. * [microseconds].
  111. * @param NMTstate NMT operating state.
  112. * @param LSSconfig Node is in LSS configuration state indication.
  113. * @param ErrCANbusOff CAN bus off indication (highest priority).
  114. * @param ErrCANbusWarn CAN error warning limit reached indication.
  115. * @param ErrRpdo RPDO event timer timeout indication.
  116. * @param ErrSync Sync receive timeout indication.
  117. * @param ErrHbCons Heartbeat consumer error (remote node) indication.
  118. * @param ErrOther Other error indication (lowest priority).
  119. * @param firmwareDownload Firmware download is in progress indication.
  120. * @param [out] timerNext_us info to OS - see CO_process().
  121. */
  122. void CO_LEDs_process(CO_LEDs_t *LEDs,
  123. uint32_t timeDifference_us,
  124. CO_NMT_internalState_t NMTstate,
  125. bool_t LSSconfig,
  126. bool_t ErrCANbusOff,
  127. bool_t ErrCANbusWarn,
  128. bool_t ErrRpdo,
  129. bool_t ErrSync,
  130. bool_t ErrHbCons,
  131. bool_t ErrOther,
  132. bool_t firmwareDownload,
  133. uint32_t *timerNext_us);
  134. /** @} */ /* CO_LEDs */
  135. #ifdef __cplusplus
  136. }
  137. #endif /*__cplusplus*/
  138. #endif /* (CO_CONFIG_LEDS) & CO_CONFIG_LEDS_ENABLE */
  139. #endif /* CO_LEDS_H */