giant_can.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 APPLICATIONSTATUS_ADDRESS (uint32_t)0x0803D000 /* Start user code status address: */
  24. #define MAXFRAME_SIZE 16
  25. //DriveChain Dir -for updata
  26. #define MC_FILEMAINDIR 0x0006
  27. #define MC_FILESUBDIR 0x0100
  28. //Data Frame- Function group
  29. #define FG_NETWORKMANAGER 0x0
  30. #define FG_EVENT 0x1
  31. #define FG_RESPONSEDATA 0x2
  32. #define FG_NORMALDATA 0x3
  33. //Node group
  34. #define NODE_ALL 0x0
  35. #define NODE_SERVICETOOL 0x1
  36. #define NODE_USERINTERFACE 0x2
  37. #define NODE_DRIVECHAIN 0x6
  38. #define NODE_MOTINOVA 0x7
  39. #define NODE_ENERGYPACK 0xC
  40. #define NODE_GIANTAPP 0xF
  41. //Data Frame-Data behavior
  42. #define DB_ACTIVEDATA 0x0
  43. #define DB_PASSIVEDATA 0x1
  44. //Remote Frame- motion group
  45. #define MG_HEARTBEAT 0x0
  46. #define MG_CONFIRMATION 0x1
  47. #define MG_ACTIVEDATA1 0x2
  48. #define MG_ACTIVEDATA2 0x3
  49. #define MG_PASSIVEDATA1 0x4
  50. #define MG_PASSIVEDATA2 0x5
  51. #define MG_PASSIVEDATA3 0x6
  52. #define MG_PASSIVEDATA4 0x7
  53. //mode
  54. #define AD_SERVICEMODE_S 0x6
  55. #define AD_SERVICEMODE_E 0xA
  56. #define AD_CHECKMODE 0xB
  57. #define AD_OFFMODE 0xC
  58. #define AD_ERRORMODE 0xD
  59. /***************************************
  60. *
  61. * Type Definations
  62. *
  63. ***************************************/
  64. /**
  65. * @brief Rx Standard Data ID
  66. *
  67. */
  68. typedef struct
  69. {
  70. UBYTE ucFrameSize; //缓冲区数组:缓冲区大小
  71. UBYTE ucFrameWrInde; //缓冲区数组:写索引
  72. UBYTE ucFrameRdInde; //缓冲区数组:读索引
  73. UBYTE ucFrameCnt; //缓冲区数组:数据计数
  74. } CANFrame_Info_Struct_t;
  75. typedef struct
  76. {
  77. ULONG id; /*!< standard format frame identifier */
  78. UBYTE rx_ff; /*!< format of frame, standard or extended format */
  79. UBYTE rx_ft; /*!< type of frame, data or remote */
  80. UBYTE rx_dlen; /*!< data length */
  81. UBYTE rx_data[8]; /*!< receive data */
  82. } CAN_ReceiveFrame_Struct_t;
  83. typedef struct
  84. {
  85. UBYTE FunctionGroup;//2 bits
  86. UBYTE NodeGroup;//4 bits
  87. UBYTE DataBehaviors;//1 bit
  88. UBYTE DataAddress;//4 bits
  89. } GiantStandardDataFrameID_Struct_t;
  90. typedef struct
  91. {
  92. UBYTE MotionGroup;//3 bits
  93. UBYTE RequireNodeGroup;//4 bits
  94. UBYTE ResponseNodeGroup;//4 bits
  95. } GiantStandardRemoteFrameID_Struct_t;
  96. typedef struct
  97. {
  98. UWORD RefreshFlag;
  99. UBYTE Error;
  100. UBYTE ManualSleepEn;
  101. UBYTE AutomaticSleepEn;//1-ignore,0-keep
  102. UBYTE InactivateErrorDetection;
  103. UBYTE ThrottleEn;
  104. UBYTE BrakeleEn;
  105. UBYTE WalkEn;
  106. UBYTE ThrottlePowerPercentage;
  107. UBYTE RidingModeEn;
  108. UBYTE AdjustingMode;
  109. UBYTE StartMode;
  110. UBYTE RearLight;//12V(2)
  111. UBYTE FrontLight;//12V(1)
  112. UWORD WheelCircumference;
  113. UBYTE MaximumTorque;
  114. UBYTE Acceleration;
  115. UBYTE AssistRatio;
  116. UBYTE MaximumPower;
  117. UWORD SpeedLimitation;
  118. UBYTE CommSleep;
  119. } GiantControlParams_Struct_t;
  120. /*****************************************
  121. *
  122. * Exported variable
  123. *
  124. ****************************************/
  125. //extern GiantStandardDataFrameID_Struct_t stGiantStandardDataFrameID_rx;
  126. //extern GiantStandardRemoteFrameID_Struct_t stGiantStandardRemoteFrameID_rx;
  127. extern GiantControlParams_Struct_t stGiantControlParams;
  128. //extern CANFrame_Info_Struct_t stCANFrame_InfoRx;
  129. //extern CAN_ReceiveFrame_Struct_t stCAN_ReceiveFrame_Buf_Rx[MAXFRAME_SIZE];
  130. /***************************************
  131. *
  132. * Function Definations
  133. *
  134. ***************************************/
  135. void giant_Init(void);
  136. void giant_10msTask(void);
  137. void CANFrame_Rx_ISR(void);
  138. void giant_CANRxData_Process(void);
  139. void giant_SendDriveChainPassiveData(UBYTE nodegroup, UBYTE dataaddr);
  140. void giant_SendDriveChainActiveData(UBYTE functiongroup, UBYTE dataaddr);
  141. void giant_SendRemote(UBYTE motiongroup);
  142. void giant_SendExtendData(UBYTE dataaddr, UBYTE datatype, UBYTE *data, UBYTE len);
  143. void giant_DataProcess(void);
  144. SLONG giant_slPolynomial(const SWORD *value);
  145. /************************************************************************/
  146. #endif
  147. /************************************************************************
  148. End of this File (EOF):
  149. Do not put anything after this part!
  150. *************************************************************************/