LinCP.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. #ifndef __LINCP_H
  2. #define __LINCP_H
  3. #include "main.h"
  4. #define LINCPID_SE_VERSION_LIST (0x00)
  5. #define LINCPID_EV_VERSION_LIST (0x01)
  6. #define LINCPID_SE_STATUS (0x02)
  7. #define LINCPID_EV_STATUS (0x03)
  8. #define LINCPID_EV_PRESENT_CURRENTS (0x04)
  9. #define LINCPID_SE_NOM_VOLTAGES (0x05)
  10. #define LINCPID_SE_MAX_CURRENTS (0x06)
  11. #define LINCPID_EV_MAX_VOLTAGES (0x07)
  12. #define LINCPID_EV_MIN_VOLTAGES (0x08)
  13. #define LINCPID_EV_MAX_MIN_CURRENTS (0x09)
  14. //#define LINCPID_CA_PROPERTIES (0x0A)
  15. #define LINCPID_SE_INFO_LIST (0x0B)
  16. #define LINCPID_EV_INFO_LIST (0x0C)
  17. //#define LINCPID_ST_ERROR_LIST (0x0D)
  18. //#define LINCPID_EV_ERROR_LIST (0x0E)
  19. //#define LINCPID_SE_ID (0x0F)
  20. //#define LINCPID_EV_ID (0x10)
  21. //Frame: 0
  22. typedef struct
  23. {
  24. u8 SeSelectedVersion; //0
  25. union
  26. {
  27. u8 B1;
  28. struct
  29. {
  30. u8 _Reserved_B1_b7: 1; //1.7 0x01
  31. u8 SeStatusOp: 2; //1.5-6
  32. u8 SeStatusInit: 2; //1.3-4
  33. u8 SeStatusVer: 2; //1.1-2
  34. u8 _Reserved_B1_b0: 1; //1.0 0x01
  35. };
  36. };
  37. u8 SeVersionPageNumber; //2 0x00 (typically)
  38. u8 SeSupportedVersion1; //3 0x02 (typically)
  39. u8 SeSupportedVersion2; //4 0xFF (typically)
  40. u8 SeSupportedVersion3; //5 0xFF (typically)
  41. u8 SeSupportedVersion4; //6 0xFF (typically)
  42. u8 SeSupportedVersion5; //7 0xFF (typically)
  43. } __attribute__((__packed__)) SeVersionList;
  44. //Frame: 1
  45. typedef struct
  46. {
  47. u8 EvSelectedVersion; //0 0x02 (typically)
  48. u8 EvAwake: 1; //1.7
  49. u8 EvStatusOp: 2; //1.5-6
  50. u8 EvStatusInit: 2; //1.3-4
  51. u8 EvStatusVer: 2; //1.1-2
  52. u8 EvResponseError: 1; //1.0
  53. u8 EvVersionPageNumber; //2 0x00 (typically)
  54. u8 EvSupportedVersion1; //3 0x02 (typically)
  55. u8 EvSupportedVersion2; //4 0xFF (typically)
  56. u8 EvSupportedVersion3; //5 0xFF (typically)
  57. u8 EvSupportedVersion4; //6 0xFF (typically)
  58. u8 EvSupportedVersion5; //7 0xFF (typically)
  59. } __attribute__((__packed__)) EvVersionList;
  60. //Frame: 2
  61. typedef struct
  62. {
  63. u8 SeSelectedVersion; //0 0x02 (typically)
  64. u8 _Reserved_B1_b7: 1; //1.7 0x01
  65. u8 SeStatusOp: 2; //1.5-6
  66. u8 SeStatusInit: 2; //1.3-4
  67. u8 SeStatusVer: 2; //1.1-2
  68. u8 _Reserved_B1_b0: 1; //1.0 0x01
  69. u8 SeAvailableCurrentL1; //2
  70. u8 SeAvailableCurrentL2; //3
  71. u8 SeAvailableCurrentL3; //4
  72. u8 SeAvailableCurrentN; //5
  73. u8 _Reserved_B6; //6 0xFF
  74. u8 _Reserved_B7; //7 0xFF
  75. } __attribute__((__packed__)) SeStatus;
  76. //Frame: 3
  77. typedef struct
  78. {
  79. u8 EvSelectedVersion; //0 0x02 (typically)
  80. u8 EvAwake: 1; //1.7
  81. u8 EvStatusOp: 2; //1.5-6
  82. u8 EvStatusInit: 2; //1.3-4
  83. u8 EvStatusVer: 2; //1.1-2
  84. u8 EvResponseError: 1; //1.0
  85. u8 EvRequestedCurrentL1; //2
  86. u8 EvRequestedCurrentL2; //3
  87. u8 EvRequestedCurrentL3; //4
  88. u8 EvRequestedCurrentN; //5
  89. u8 _Reserved_B6; //6 0xFF
  90. u8 _Reserved_B7; //7 0xFF
  91. } __attribute__((__packed__)) EvStatus;
  92. //Frame: 4
  93. typedef struct
  94. {
  95. u8 EvSelectedVersion; //0 0x02 (typically)
  96. u8 EvPresentCurrentL1; //1
  97. u8 EvPresentCurrentL2; //2
  98. u8 EvPresentCurrentL3; //3
  99. u8 EvPresentCurrentN; //4
  100. u8 _Reserved_B5; //5 0xFF
  101. u8 _Reserved_B6; //6 0xFF
  102. u8 _Reserved_B7; //7 0xFF
  103. } __attribute__((__packed__)) EvPresentCurrents;
  104. //Frame: 5
  105. typedef struct
  106. {
  107. u8 SeSelectedVersion; //0 0x02 (typically)
  108. uint16_t SeNomVoltageL1N; //1-2
  109. uint16_t SeNomVoltageLL; //3-4
  110. u8 SeFrequency; //5
  111. u8 _Reserved_B6; //6 0xFF
  112. u8 _Reserved_B7; //7 0xFF
  113. } __attribute__((__packed__)) SeNomVoltages;
  114. //Frame: 6
  115. typedef struct
  116. {
  117. u8 SeSelectedVersion; //0 0x02 (typically)
  118. u8 SeMaxCurrentL1; //1
  119. u8 SeMaxCurrentL2; //2
  120. u8 SeMaxCurrentL3; //3
  121. u8 SeMaxCurrentN; //4
  122. u8 _Reserved_B5; //5 0xFF
  123. u8 _Reserved_B6; //6 0xFF
  124. u8 _Reserved_B7; //7 0xFF
  125. } __attribute__((__packed__)) SeMaxCurrents;
  126. //Frame: 7
  127. typedef struct
  128. {
  129. u8 EvSelectedVersion; //0 0x02 (typically)
  130. uint16_t EvMaxVoltageL1N; //1-2
  131. uint16_t EvMaxVoltageLL; //3-4
  132. u8 EvFrequencies; //5
  133. u8 _Reserved_B6; //6 0xFF
  134. u8 _Reserved_B7; //7 0xFF
  135. } __attribute__((__packed__)) EvMaxVoltages;
  136. //Frame: 8
  137. typedef struct
  138. {
  139. u8 EvSelectedVersion; //0 0x02 (typically)
  140. uint16_t EvMinVoltageL1N; //1-2
  141. uint16_t EvMinVoltageLL; //3-4
  142. u8 _Reserved_B5; //5 0xFF
  143. u8 _Reserved_B6; //6 0xFF
  144. u8 _Reserved_B7; //7 0xFF
  145. } __attribute__((__packed__)) EvMinVoltages;
  146. //Frame: 9
  147. typedef struct
  148. {
  149. u8 EvSelectedVersion; //0 0x02 (typically)
  150. u8 EvMaxCurrentL1; //1
  151. u8 EvMaxCurrentL2; //2
  152. u8 EvMaxCurrentL3; //3
  153. u8 EvMaxCurrentN; //4
  154. u8 EvMinCurrentL1; //5
  155. u8 EvMinCurrentL2; //6
  156. u8 EvMinCurrentL3; //7
  157. } __attribute__((__packed__)) EvMaxMinCurrents;
  158. //Frame: 10
  159. //Not used in this edition of SAE J3068.
  160. //Reserved for future implementation of cordset nodes
  161. //typedef struct
  162. //{
  163. // u8 CaVersion; //0 0x01 (typically)
  164. // u8 _Reserved_B1_b1_7: 7; //1.1-7 (all: ones)
  165. // u8 CaResponseError: 1; //1.0
  166. // uint16_t CaMaxVoltage; //2-3
  167. // u8 CaMaxCurrentL1; //4
  168. // u8 CaMaxCurrentL2; //5
  169. // u8 CaMaxCurrentL3; //6
  170. // u8 CaMaxCurrentN; //7
  171. //} __attribute__((__packed__)) CaProperties;
  172. //Frame: 11
  173. typedef struct
  174. {
  175. u8 SeSelectedVersion; //0
  176. u8 SeInfoPageNumber; //1
  177. u8 SeInfoEntry1; //2
  178. u8 SeInfoEntry2; //3
  179. u8 SeInfoEntry3; //4
  180. u8 SeInfoEntry4; //5
  181. u8 SeInfoEntry5; //6
  182. u8 SeInfoEntry6; //7
  183. } __attribute__((__packed__)) SeInfoList;
  184. //Frame: 12
  185. typedef struct
  186. {
  187. u8 EvSelectedVersion; //0
  188. u8 EvInfoPageNumber; //1
  189. u8 EvInfoEntry1; //2
  190. u8 EvInfoEntry2; //3
  191. u8 EvInfoEntry3; //4
  192. u8 EvInfoEntry4; //5
  193. u8 EvInfoEntry5; //6
  194. u8 EvInfoEntry6; //7
  195. } __attribute__((__packed__)) EvInfoList;
  196. //Frame: 13
  197. //Reserved; used in Protocol Version 1
  198. //typedef struct
  199. //{
  200. // u8 SeSelectedVersion;
  201. // u8 SeErrorPageNumber;
  202. // u8 SeErrorEntry1;
  203. // u8 SeErrorEntry2;
  204. // u8 SeErrorEntry3;
  205. // u8 SeErrorEntry4;
  206. // u8 SeErrorEntry5;
  207. // u8 SeErrorEntry6;
  208. //} __attribute__((__packed__)) StErrorList;
  209. //Frame: 14
  210. //Reserved; used in Protocol Version 1
  211. //typedef struct
  212. //{
  213. // u8 EvSelectedVersion;
  214. // u8 EvErrorPageNumber;
  215. // u8 EvErrorEntry1;
  216. // u8 EvErrorEntry2;
  217. // u8 EvErrorEntry3;
  218. // u8 EvErrorEntry4;
  219. // u8 EvErrorEntry5;
  220. // u8 EvErrorEntry6;
  221. //} __attribute__((__packed__)) EvErrorList;
  222. //--------------------------------------------------------------
  223. //15 to 49 Reserved
  224. //50 to 59 Available for application specific frames
  225. //60 Refer to ISO 17987, used in SAE J3068 for the LIN go-to-sleep command. See 10.1.
  226. //61 to 63 Refer to ISO 17987, not used in SAE J3068
  227. ////Frame: 15
  228. //typedef struct
  229. //{
  230. // u8 SeIDPageNumber;
  231. // u8 SeIDByteA;
  232. // u8 SeIDByteB;
  233. // u8 SeIDByteC;
  234. // u8 SeIDByteD;
  235. // u8 SeIDByteE;
  236. // u8 SeIDByteF;
  237. // u8 SeIDByteG;
  238. //} __attribute__((__packed__)) SeID;
  239. //
  240. ////Frame: 16
  241. //typedef struct
  242. //{
  243. // u8 EvIDPageNumber;
  244. // u8 EvIDByteA;
  245. // u8 EvIDByteB;
  246. // u8 EvIDByteC;
  247. // u8 EvIDByteD;
  248. // u8 EvIDByteE;
  249. // u8 EvIDByteF;
  250. // u8 EvIDByteG;
  251. //} __attribute__((__packed__)) EvID;
  252. //#define LIN_VER_2X
  253. #define LIN_BUF_MAX (11) //SYNC(1) + ID(1) + DATA(8) + CHECKSUM(1)
  254. struct _LinCP
  255. {
  256. USART_TypeDef* m_USART;
  257. u8 m_TxBuf[LIN_BUF_MAX];
  258. int m_TxLen;
  259. int m_TxIdx;
  260. u8 m_RxBuf[LIN_BUF_MAX];
  261. int m_RxLen;
  262. HTK_BOOL m_bTx;
  263. HTK_BOOL m_bRx;
  264. HTK_BOOL m_bTxTimeout;
  265. HTK_BOOL m_bRxTimeout;
  266. u32 m_nTxOK;
  267. u32 m_nRxOK;
  268. u32 m_nTxNG;
  269. u32 m_nRxNG;
  270. };
  271. void LIN_Init(PLinCP p, USART_TypeDef* usart);
  272. HTK_BOOL LIN_TxHeader(PLinCP p, u8 id);
  273. HTK_BOOL LIN_TxHeaderData(PLinCP p, u8 id, void* Data, u8 DataLen);
  274. void LIN_Display(PLinCP p);
  275. void LIN_IRQ_Proc(PLinCP p);
  276. #ifdef FUNC_LIN_MASTER
  277. void LIN_IRQ_Master_ProcTx(PLinCP p);
  278. void LIN_IRQ_Master_ProcRx(PLinCP p);
  279. #else
  280. //void LIN_IRQ_Slave_ProcTx(PLinCP p);
  281. //void LIN_IRQ_Slave_ProcRx(PLinCP p);
  282. #endif
  283. #endif //__LINCP_H