CO_driver_target.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * Copyright (c) 2019 Vestas Wind Systems A/S
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef CANOPENNODE_CO_DRIVER_H
  7. #define CANOPENNODE_CO_DRIVER_H
  8. /*
  9. * Zephyr RTOS CAN driver interface and configuration for CANopenNode
  10. * CANopen protocol stack.
  11. *
  12. * See CANopenNode/stack/drvTemplate/CO_driver.h for API description.
  13. */
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. #include "types.h" /* float32_t, float64_t */
  18. #include "stdbool.h"
  19. # ifndef __INT_MAX__
  20. # define __INT_MAX__ 2147483647
  21. # endif
  22. # undef INT_MIN
  23. # define INT_MIN (-INT_MAX-1)
  24. # undef INT_MAX
  25. # define INT_MAX __INT_MAX__
  26. #define INT_MAX __INT_MAX__
  27. /* Use static variables instead of calloc() */
  28. #define CO_USE_GLOBALS
  29. /* Use Zephyr provided crc16 implementation */
  30. #define CO_USE_OWN_CRC16
  31. /* Use SDO buffer size from Kconfig */
  32. #define CO_SDO_BUFFER_SIZE 32
  33. /* Use trace buffer size from Kconfig */
  34. #define CO_TRACE_BUFFER_SIZE_FIXED CONFIG_CANOPENNODE_TRACE_BUFFER_SIZE
  35. #define CO_CONFIG_SRDO 0x1
  36. #define CO_CONFIG_LEDS 0x1
  37. #define CO_CONFIG_LSS 0x0
  38. #define CO_CONFIG_GTW 0x0
  39. #define CO_CONFIG_TRACE 0x0
  40. #define CO_OD_STORAGE 0x0
  41. #define CO_CONFIG_SDO_CLI 0x0
  42. #define CO_CONFIG_TIME 0x0
  43. #define CO_CONFIG_CRC16 0x1
  44. #ifdef CONFIG_CANOPENNODE_LEDS
  45. #define CO_USE_LEDS 1
  46. #endif
  47. #define CONFIG_LITTLE_ENDIAN 0x1
  48. #define CO_SWAP_16(x) x
  49. #define CO_SWAP_32(x) x
  50. #define CO_SWAP_64(x) x
  51. #ifdef CONFIG_LITTLE_ENDIAN
  52. #define CO_LITTLE_ENDIAN
  53. #else
  54. #define CO_BIG_ENDIAN
  55. #endif
  56. typedef bool bool_t;
  57. typedef char char_t;
  58. typedef unsigned char oChar_t;
  59. typedef unsigned char domain_t;
  60. typedef struct canopen_rx_msg {
  61. uint8_t data[8];
  62. uint16_t ident;
  63. uint8_t DLC;
  64. } CO_CANrxMsg_t;
  65. typedef void (*CO_CANrxBufferCallback_t)(void *object,
  66. const CO_CANrxMsg_t *message);
  67. typedef struct {
  68. int filter_id;
  69. uint16_t ident;
  70. uint16_t mask;
  71. void *object;
  72. void (*CANrx_callback)(void *object, void *message);
  73. } CO_CANrx_t;
  74. typedef struct {
  75. uint32_t ident;
  76. uint8_t DLC;
  77. uint8_t data[8];
  78. volatile bool_t rtr;
  79. volatile bool_t bufferFull;
  80. volatile bool_t syncFlag;
  81. } CO_CANtx_t;
  82. typedef struct {
  83. void *CANptr;
  84. CO_CANrx_t *rxArray;
  85. uint16_t rxSize;
  86. CO_CANtx_t *txArray;
  87. uint16_t txSize;
  88. uint16_t CANerrorStatus;
  89. volatile bool_t configured;
  90. volatile bool_t CANnormal;
  91. volatile bool_t useCANrxFilters;
  92. volatile bool_t bufferInhibitFlag;
  93. volatile bool_t firstCANtxMessage;
  94. volatile uint16_t CANtxCount;
  95. uint32_t errOld;
  96. int32_t errinfo;
  97. } CO_CANmodule_t;
  98. void canopen_send_lock(void);
  99. void canopen_send_unlock(void);
  100. #define CO_LOCK_CAN_SEND() canopen_send_lock()
  101. #define CO_UNLOCK_CAN_SEND() canopen_send_unlock()
  102. void canopen_emcy_lock(void);
  103. void canopen_emcy_unlock(void);
  104. #define CO_LOCK_EMCY() canopen_emcy_lock()
  105. #define CO_UNLOCK_EMCY() canopen_emcy_unlock()
  106. void canopen_od_lock(void);
  107. void canopen_od_unlock(void);
  108. #define CO_LOCK_OD() canopen_od_lock()
  109. #define CO_UNLOCK_OD() canopen_od_unlock()
  110. /*
  111. * CANopenNode RX callbacks run in interrupt context, no memory
  112. * barrier needed.
  113. */
  114. #define CO_MemoryBarrier()
  115. #define CO_FLAG_READ(rxNew) ((rxNew) != NULL)
  116. #define CO_FLAG_SET(rxNew) {CO_MemoryBarrier(); rxNew = (void *)1L; }
  117. #define CO_FLAG_CLEAR(rxNew) {CO_MemoryBarrier(); rxNew = NULL; }
  118. #ifdef __cplusplus
  119. }
  120. #endif
  121. #endif /* CANOPENNODE_CO_DRIVER_H */