CO_GFC.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /**
  2. * CANopen Global fail-safe command protocol.
  3. *
  4. * @file CO_GFC.h
  5. * @ingroup CO_GFC
  6. * @author Robert Grüning
  7. * @copyright 2020 - 2020 Robert Grüning
  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_GFC_H
  26. #define CO_GFC_H
  27. #include "301/CO_driver.h"
  28. /* default configuration, see CO_config.h */
  29. #ifndef CO_CONFIG_GFC
  30. #define CO_CONFIG_GFC (0)
  31. #endif
  32. #if ((CO_CONFIG_GFC) & CO_CONFIG_GFC_ENABLE) || defined CO_DOXYGEN
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /**
  37. * @defgroup CO_GFC GFC
  38. * @ingroup CO_CANopen_304
  39. * @{
  40. *
  41. * Global fail-safe command protocol.
  42. *
  43. * Very simple consumer/producer protocol.
  44. * A net can have multiple GFC producer and multiple GFC consumer.
  45. * On a safety-relevant the producer can send a GFC message (ID 0, DLC 0).
  46. * The consumer can use this message to start the transition to a safe state.
  47. * The GFC is optional for the security protocol and is not monitored (timed).
  48. */
  49. /**
  50. * GFC object.
  51. */
  52. typedef struct {
  53. uint8_t *valid; /**< From CO_GFC_init() */
  54. #if ((CO_CONFIG_GFC)&CO_CONFIG_GFC_PRODUCER) || defined CO_DOXYGEN
  55. CO_CANmodule_t *CANdevTx; /**< From CO_GFC_init() */
  56. CO_CANtx_t *CANtxBuff; /**< CAN transmit buffer inside CANdevTx */
  57. #endif
  58. #if ((CO_CONFIG_GFC)&CO_CONFIG_GFC_CONSUMER) || defined CO_DOXYGEN
  59. /** From CO_GFC_initCallbackEnterSafeState() or NULL */
  60. void (*pFunctSignalSafe)(void *object);
  61. /** From CO_GFC_initCallbackEnterSafeState() or NULL */
  62. void *functSignalObjectSafe;
  63. #endif
  64. } CO_GFC_t;
  65. /**
  66. * Initialize GFC object.
  67. *
  68. * Function must be called in the communication reset section.
  69. *
  70. * @param GFC This object will be initialized.
  71. * @param valid pointer to the valid flag in OD (0x1300)
  72. * @param GFC_CANdevRx CAN device used for SRDO reception.
  73. * @param GFC_rxIdx Index of receive buffer in the above CAN device.
  74. * @param CANidRxGFC GFC CAN ID for reception
  75. * @param GFC_CANdevTx AN device used for SRDO transmission.
  76. * @param GFC_txIdx Index of transmit buffer in the above CAN device.
  77. * @param CANidTxGFC GFC CAN ID for transmission
  78. *
  79. * @return #CO_ReturnError_t: CO_ERROR_NO or CO_ERROR_ILLEGAL_ARGUMENT.
  80. */
  81. CO_ReturnError_t CO_GFC_init(CO_GFC_t *GFC,
  82. uint8_t *valid,
  83. CO_CANmodule_t *GFC_CANdevRx,
  84. uint16_t GFC_rxIdx,
  85. uint16_t CANidRxGFC,
  86. CO_CANmodule_t *GFC_CANdevTx,
  87. uint16_t GFC_txIdx,
  88. uint16_t CANidTxGFC);
  89. #if ((CO_CONFIG_GFC)&CO_CONFIG_GFC_CONSUMER) || defined CO_DOXYGEN
  90. /**
  91. * Initialize GFC callback function.
  92. *
  93. * Function initializes optional callback function, that is called when GFC is
  94. * received. Callback is called from receive function (interrupt).
  95. *
  96. * @param GFC This object.
  97. * @param object Pointer to object, which will be passed to pFunctSignalSafe().
  98. * Can be NULL
  99. * @param pFunctSignalSafe Pointer to the callback function. Not called if NULL.
  100. */
  101. void CO_GFC_initCallbackEnterSafeState(CO_GFC_t *GFC,
  102. void *object,
  103. void (*pFunctSignalSafe)(void *object));
  104. #endif
  105. #if ((CO_CONFIG_GFC)&CO_CONFIG_GFC_PRODUCER) || defined CO_DOXYGEN
  106. /**
  107. * Send GFC message.
  108. *
  109. * It should be called by application, for example after a safety-relevant
  110. * change.
  111. *
  112. * @param GFC GFC object.
  113. *
  114. * @return Same as CO_CANsend().
  115. */
  116. CO_ReturnError_t CO_GFCsend(CO_GFC_t *GFC);
  117. #endif
  118. /** @} */ /* CO_GFC */
  119. #ifdef __cplusplus
  120. }
  121. #endif /*__cplusplus*/
  122. #endif /* (CO_CONFIG_GFC) & CO_CONFIG_GFC_ENABLE */
  123. #endif /* CO_GFC_H */