canopennode.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * Copyright (c) 2019 Vestas Wind Systems A/S
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @defgroup CAN CAN BUS
  8. * @{
  9. * @}
  10. */
  11. /**
  12. * @brief CANopen Network Stack
  13. * @defgroup canopen CANopen Network Stack
  14. * @ingroup CAN
  15. * @{
  16. */
  17. #ifndef CANOPENNODE_CANOPENNODE_H_
  18. #define CANOPENNODE_CANOPENNODE_H_
  19. #include <CANopen.h>
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. /**
  24. * @brief CANopen object dictionary storage types.
  25. */
  26. enum canopen_storage {
  27. CANOPEN_STORAGE_RAM,
  28. CANOPEN_STORAGE_ROM,
  29. CANOPEN_STORAGE_EEPROM,
  30. };
  31. struct canopen_context {
  32. struct device *dev;
  33. };
  34. /**
  35. * @brief Attach CANopen object dictionary storage handlers.
  36. *
  37. * Attach CANopen storage handler functions to object dictionary
  38. * indexes 0x1010 (Store parameters) and 0x1011 (Restore default
  39. * parameters). This function must be called after calling CANopenNode
  40. * `CO_init()`.
  41. *
  42. * The handlers will save object dictionary entries of type @ref
  43. * CANOPEN_STORAGE_ROM to non-volatile storage when a CANopen SDO
  44. * client writes 0x65766173 ('s', 'a', 'v', 'e' from LSB to MSB) to
  45. * object dictionary index 0x1010 sub-index 1.
  46. *
  47. * Object dictionary entries of types @ref CANOPEN_STORAGE_ROM (and
  48. * optionally @ref CANOPEN_STORAGE_EEPROM) will be deleted from
  49. * non-volatile storage when a CANopen SDO client writes 0x64616F6C
  50. * ('l', 'o', 'a', 'd' from LSB to MSB) to object dictionary index
  51. * 0x1011 sub-index 1.
  52. *
  53. * Object dictionary entries of type @ref CANOPEN_STORAGE_EEPROM may be
  54. * saved by the application by periodically calling @ref
  55. * canopen_storage_save().
  56. *
  57. * Object dictionary entries of type @ref CANOPEN_STORAGE_RAM are
  58. * never saved to non-volatile storage.
  59. *
  60. * @param sdo CANopenNode SDO server object
  61. * @param em CANopenNode Emergency object
  62. */
  63. void canopen_storage_attach(CO_SDO_t *sdo, CO_EM_t *em);
  64. /**
  65. * @brief Save CANopen object dictionary entries to non-volatile storage.
  66. *
  67. * Save object dictionary entries of a given type to non-volatile
  68. * storage.
  69. *
  70. * @param storage CANopen object dictionary entry type
  71. *
  72. * @return 0 if successful, negative errno code if failure
  73. */
  74. int canopen_storage_save(enum canopen_storage storage);
  75. /**
  76. * @brief Erase CANopen object dictionary entries from non-volatile storage.
  77. *
  78. * Erase object dictionary entries of a given type from non-volatile
  79. * storage.
  80. *
  81. * @param storage CANopen object dictionary entry type
  82. *
  83. * @return 0 if successful, negative errno code if failure
  84. */
  85. int canopen_storage_erase(enum canopen_storage storage);
  86. /**
  87. * @brief Attach CANopen object dictionary program download handlers.
  88. *
  89. * Attach CANopen program download functions to object dictionary
  90. * indexes 0x1F50, 0x1F51, 0x1F56, and 0x1F57. This function must be
  91. * called after calling CANopenNode `CO_init()`.
  92. *
  93. * @param nmt CANopenNode NMT object
  94. * @param sdo CANopenNode SDO server object
  95. * @param em CANopenNode Emergency object
  96. */
  97. void canopen_program_download_attach(CO_NMT_t *nmt, CO_SDO_t *sdo, CO_EM_t *em);
  98. /**
  99. * @typedef canopen_led_callback_t
  100. * @brief CANopen LED indicator callback function signature.
  101. *
  102. * @param value true if the LED indicator shall be turned on, false otherwise.
  103. * @param arg argument that was passed when LEDs were initialized.
  104. */
  105. typedef void (*canopen_led_callback_t)(bool value, void *arg);
  106. /**
  107. * @brief Initialize CANopen LED indicators.
  108. *
  109. * Initialize CANopen LED indicators and attach callbacks for setting
  110. * their state. Two LED indicators, a red and a green, are supported
  111. * according to CiA 303-3.
  112. *
  113. * @param nmt CANopenNode NMT object.
  114. * @param green_cb callback for changing state on the green LED indicator.
  115. * @param green_arg argument to pass to the green LED indicator callback.
  116. * @param red_cb callback for changing state on the red LED indicator.
  117. * @param red_arg argument to pass to the red LED indicator callback.
  118. */
  119. void canopen_leds_init(CO_NMT_t *nmt,
  120. canopen_led_callback_t green_cb, void *green_arg,
  121. canopen_led_callback_t red_cb, void *red_arg);
  122. /**
  123. * @brief Indicate CANopen program download in progress
  124. *
  125. * Indicate that a CANopen program download is in progress.
  126. *
  127. * @param in_progress true if program download is in progress, false otherwise
  128. */
  129. void canopen_leds_program_download(bool in_progress);
  130. #ifdef __cplusplus
  131. }
  132. #endif
  133. /**
  134. * @}
  135. */
  136. #endif /* CANOPENNODE_CANOPENNODE_H_ */