giant_can.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /**
  2. * @file giant_can.h
  3. * @author Ye Jin
  4. * @brief giant can protocol
  5. * @version 0.1
  6. * @date 2025-01-09
  7. *
  8. * @copyright Copyright (c) 2025
  9. *
  10. */
  11. /************************************************************************
  12. Beginning of File, do not put anything above here except notes
  13. Compiler Directives:
  14. *************************************************************************/
  15. #ifndef GIANT_CAN_H
  16. #define GIANT_CAN_H
  17. #include "typedefine.h"
  18. /****************************************
  19. *
  20. * Definitions & Macros
  21. *
  22. ****************************************/
  23. #define MAXFRAME_SIZE 16
  24. //Data Frame- Function group
  25. #define FG_NETWORKMANAGER 0x0
  26. #define FG_EVENT 0x1
  27. #define FG_RESPONSEDATA 0x2
  28. #define FG_NORMALDATA 0x3
  29. //Node group
  30. #define NODE_ALL 0x0
  31. #define NODE_SERVICETOOL 0x1
  32. #define NODE_USERINTERFACE 0x2
  33. #define NODE_DRIVECHAIN 0x6
  34. #define NODE_MOTINOVA 0x7
  35. #define NODE_ENERGYPACK 0xC
  36. #define NODE_GIANTAPP 0xF
  37. //Data Frame-Data behavior
  38. #define DB_ACTIVEDATA 0x0
  39. #define DB_PASSIVEDATA 0x1
  40. //Remote Frame- motion group
  41. #define MG_HEARTBEAT 0x0
  42. #define MG_CONFIRMATION 0x1
  43. #define MG_ACTIVEDATA1 0x2
  44. #define MG_ACTIVEDATA2 0x3
  45. #define MG_PASSIVEDATA1 0x4
  46. #define MG_PASSIVEDATA2 0x5
  47. #define MG_PASSIVEDATA3 0x6
  48. #define MG_PASSIVEDATA4 0x7
  49. //mode
  50. #define AD_SERVICEMODE_S 0x6
  51. #define AD_SERVICEMODE_E 0xA
  52. #define AD_CHECKMODE 0xB
  53. #define AD_OFFMODE 0xC
  54. #define AD_ERRORMODE 0xD
  55. /***************************************
  56. *
  57. * Type Definations
  58. *
  59. ***************************************/
  60. /**
  61. * @brief Rx Standard Data ID
  62. *
  63. */
  64. typedef struct
  65. {
  66. UBYTE ucFrameSize; //缓冲区数组:缓冲区大小
  67. UBYTE ucFrameWrInde; //缓冲区数组:写索引
  68. UBYTE ucFrameRdInde; //缓冲区数组:读索引
  69. UBYTE ucFrameCnt; //缓冲区数组:数据计数
  70. } CANFrame_Info_Struct_t;
  71. typedef struct
  72. {
  73. ULONG id; /*!< standard format frame identifier */
  74. UBYTE rx_ft; /*!< type of frame, data or remote */
  75. UBYTE rx_dlen; /*!< data length */
  76. UBYTE rx_data[8]; /*!< receive data */
  77. } CAN_ReceiveFrame_Struct_t;
  78. typedef struct
  79. {
  80. UBYTE FunctionGroup;//2 bits
  81. UBYTE NodeGroup;//4 bits
  82. UBYTE DataBehaviors;//1 bit
  83. UBYTE DataAddress;//4 bits
  84. } GiantStandardDataFrameID_Struct_t;
  85. typedef struct
  86. {
  87. UBYTE MotionGroup;//3 bits
  88. UBYTE RequireNodeGroup;//4 bits
  89. UBYTE ResponseNodeGroup;//4 bits
  90. } GiantStandardRemoteFrameID_Struct_t;
  91. typedef struct
  92. {
  93. UWORD RefreshFlag;
  94. UBYTE Error;
  95. UBYTE ManualSleepEn;
  96. UBYTE AutomaticSleepEn;//1-ignore,0-keep
  97. UBYTE InactivateErrorDetection;
  98. UBYTE ThrottleEn;
  99. UBYTE BrakeleEn;
  100. UBYTE WalkEn;
  101. UBYTE ThrottlePowerPercentage;
  102. UBYTE RidingModeEn;
  103. UBYTE AdjustingMode;
  104. UBYTE StartMode;
  105. UWORD WheelCircumference;
  106. UBYTE MaximumTorque;
  107. UBYTE Acceleration;
  108. UBYTE AssistRatio;
  109. UBYTE MaximumPower;
  110. UWORD SpeedLimitation;
  111. UBYTE CommSleep;
  112. } GiantControlParams_Struct_t;
  113. /*****************************************
  114. *
  115. * Exported variable
  116. *
  117. ****************************************/
  118. //extern GiantStandardDataFrameID_Struct_t stGiantStandardDataFrameID_rx;
  119. //extern GiantStandardRemoteFrameID_Struct_t stGiantStandardRemoteFrameID_rx;
  120. extern GiantControlParams_Struct_t stGiantControlParams;
  121. //extern CANFrame_Info_Struct_t stCANFrame_InfoRx;
  122. //extern CAN_ReceiveFrame_Struct_t stCAN_ReceiveFrame_Buf_Rx[MAXFRAME_SIZE];
  123. /***************************************
  124. *
  125. * Function Definations
  126. *
  127. ***************************************/
  128. void giant_Init(void);
  129. void giant_10msTask(void);
  130. void CANFrame_Rx_ISR(void);
  131. void giant_CANRxData_Process(void);
  132. void giant_SendDriveChainPassiveData(UBYTE remoteMG, UBYTE DataAddr);
  133. void giant_SendDriveChainActiveData(UBYTE functiongroup, UBYTE dataaddr);
  134. void giant_SendRemote(UBYTE motiongroup);
  135. void giant_DataProcess(void);
  136. SLONG giant_slPolynomial(const SWORD *value);
  137. /************************************************************************/
  138. #endif
  139. /************************************************************************
  140. End of this File (EOF):
  141. Do not put anything after this part!
  142. *************************************************************************/