Rev 693 | Rev 698 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 693 | Rev 696 | ||
---|---|---|---|
Line -... | Line 1... | ||
- | 1 | #include <string.h> |
|
1 | #include "91x_lib.h" |
2 | #include "91x_lib.h" |
2 | #include "91x_can.h" |
3 | #include "91x_can.h" |
3 | #include "timer1.h" |
4 | #include "timer1.h" |
4 | #include "led.h" |
5 | #include "led.h" |
5 | #include "canbus.h" |
6 | #include "canbus.h" |
6 | #include "main.h" |
7 | #include "main.h" |
7 | #include "uart1.h" |
8 | #include "uart1.h" |
- | 9 | #include "GPS.h" |
|
Line 8... | Line 10... | ||
8 | 10 | ||
9 | canmsg CanMsg; |
11 | canmsg CanMsg; |
10 | canmsg RxCanMsg; |
12 | canmsg RxCanMsg; |
Line 11... | Line 13... | ||
11 | volatile u32 frame_received_flag; |
13 | volatile u32 AllMsgsReceived; |
12 | 14 | ||
Line 20... | Line 22... | ||
20 | Priority_2, |
22 | Priority_2, |
21 | Priority_3 |
23 | Priority_3 |
22 | }VIC_Priority; |
24 | }VIC_Priority; |
Line 23... | Line 25... | ||
23 | 25 | ||
24 | /* buffer for receive messages */ |
26 | /* buffer for receive messages */ |
Line 25... | Line 27... | ||
25 | canmsg RxCanMsg; |
27 | canmsg RxCanTxMsg; |
26 | 28 | ||
27 | /* used message object numbers */ |
29 | /* used message object numbers */ |
28 | enum { |
30 | enum { |
29 | CAN_TX_MSGOBJ = 0, |
31 | CAN_TX_MSGOBJ = 0, |
Line -... | Line 32... | ||
- | 32 | CAN_RX_MSGOBJ = 1 |
|
- | 33 | }; |
|
30 | CAN_RX_MSGOBJ = 1 |
34 | |
31 | }; |
35 | #define CAN_MSG_ADR 0x100 |
32 | 36 | ||
33 | /* array of pre-defined transmit messages */ |
37 | #define CAN_ID_VERSION 0 |
34 | canmsg TxCanMsg[3] = { |
38 | #define CAN_ID_STATUS 1 |
- | 39 | #define CAN_ID_FS_LON 2 |
|
- | 40 | #define CAN_ID_FS_LAT 3 |
|
35 | { CAN_STD_ID, 0x123, 4, { 0x01, 0x02, 0x04, 0x08 } }, |
41 | #define CAN_ID_FS_ALT 4 |
- | 42 | ||
- | 43 | #define MAX_CAN_MSG 10 |
|
Line 36... | Line 44... | ||
36 | { CAN_STD_ID, 0x321, 2, { 0xAA, 0x55, 0xAA, 0x55 } }, |
44 | |
37 | { CAN_EXT_ID, 0x12345678, 8, { 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 } } |
45 | CanMessage_t CanTxMessage[MAX_CAN_MSG]; |
38 | }; |
46 | CanMessage_t CanRxMessage[MAX_CAN_MSG]; |
39 | 47 | ||
Line 77... | Line 85... | ||
77 | CAN_ReleaseTxMessage(msgobj); |
85 | CAN_ReleaseTxMessage(msgobj); |
78 | break; |
86 | break; |
Line 79... | Line 87... | ||
79 | 87 | ||
80 | case 1 /* CAN_RX_MSGOBJ */: |
88 | case 1 /* CAN_RX_MSGOBJ */: |
81 | CAN_ReceiveMessage(msgobj, FALSE, &RxCanMsg); |
89 | CAN_ReceiveMessage(msgobj, FALSE, &RxCanMsg); |
- | 90 | CAN_ReleaseRxMessage(msgobj); |
|
- | 91 | ||
- | 92 | if(RxCanMsg.Id >= CAN_MSG_ADR && RxCanMsg.Id < CAN_MSG_ADR + MAX_CAN_MSG) |
|
- | 93 | { |
|
- | 94 | memcpy(&CanRxMessage[RxCanMsg.Id - CAN_MSG_ADR], &RxCanMsg,sizeof(RxCanMsg)); |
|
- | 95 | } |
|
- | 96 | if(RxCanMsg.Id == CAN_MSG_ADR + MAX_CAN_MSG - 1) |
|
82 | CAN_ReleaseRxMessage(msgobj); |
97 | { |
- | 98 | AllMsgsReceived = 1; |
|
83 | frame_received_flag = 1; |
99 | } |
84 | DebugOut.Analog[19]++; |
100 | DebugOut.Analog[16] = RxCanMsg.Id; |
Line 85... | Line 101... | ||
85 | break; |
101 | break; |
86 | 102 | ||
87 | default: |
103 | default: |
Line 95... | Line 111... | ||
95 | 111 | ||
Line 96... | Line 112... | ||
96 | } |
112 | } |
97 | 113 | ||
98 | void CanSend(void) |
114 | void CanSend(void) |
99 | { |
115 | { |
100 | // CAN_SetUnusedAllMsgObj(); |
116 | static u32 index = 1; |
101 | // CAN_SetTxMsgObj(CAN_TX_MSGOBJ, CAN_STD_ID, DISABLE); |
117 | CanTxMessage[4].D.sLong = DebugOut.Analog[24]; |
- | 118 | // CAN_SendMessage(CAN_TX_MSGOBJ, &TxCanMsg[1]); |
|
102 | // CAN_SetRxMsgObj(CAN_RX_MSGOBJ, CAN_STD_ID, 0, CAN_LAST_STD_ID, TRUE); |
119 | if(CAN_SendMessage(CAN_TX_MSGOBJ, &CanTxMessage[index]) == SUCCESS) |
- | 120 | { |
|
- | 121 | if(++index >= MAX_CAN_MSG) |
|
103 | //CAN_UpdateMsgObj(CAN_TX_MSGOBJ, &TxCanMsg[1]); |
122 | { |
104 | TxCanMsg[1].Data[0] = DebugOut.Analog[24] / 256; |
123 | index = 0; |
- | 124 | CanTxMessage[CAN_ID_FS_LON].D.sLong = GPS_FailsafePosition.Longitude; |
|
- | 125 | CanTxMessage[CAN_ID_FS_LAT].D.sLong = GPS_FailsafePosition.Latitude; |
|
105 | TxCanMsg[1].Data[1] = DebugOut.Analog[24] % 256; |
126 | } |
Line 106... | Line 127... | ||
106 | CAN_SendMessage(CAN_TX_MSGOBJ, &TxCanMsg[1]); |
127 | } |
107 | } |
128 | } |
Line 127... | Line 148... | ||
127 | 148 | ||
128 | CAN_SetUnusedAllMsgObj(); |
149 | CAN_SetUnusedAllMsgObj(); |
129 | CAN_SetTxMsgObj(CAN_TX_MSGOBJ, CAN_STD_ID, DISABLE); |
150 | CAN_SetTxMsgObj(CAN_TX_MSGOBJ, CAN_STD_ID, DISABLE); |
Line -... | Line 151... | ||
- | 151 | CAN_SetRxMsgObj(CAN_RX_MSGOBJ, CAN_STD_ID, 0, CAN_LAST_STD_ID, TRUE); |
|
- | 152 | ||
- | 153 | u32 i; |
|
- | 154 | for(i=0; i< MAX_CAN_MSG;i++) |
|
- | 155 | { |
|
- | 156 | CanTxMessage[i].IdType = CAN_STD_ID; |
|
- | 157 | CanTxMessage[i].Id = i + CAN_MSG_ADR; |
|
- | 158 | CanTxMessage[i].Length = 8; |
|
- | 159 | CanTxMessage[i].D.Long = i; |
|
- | 160 | } |
|
- | 161 | ||
- | 162 | CanTxMessage[CAN_ID_VERSION].D.Byte[0] = CAN_SLAVE_COMPATIBLE; |
|
- | 163 | CanTxMessage[CAN_ID_VERSION].D.Byte[1] = VERSION_PATCH; |
|
- | 164 | CanTxMessage[CAN_ID_VERSION].D.Byte[2] = VERSION_MINOR; |
|
130 | CAN_SetRxMsgObj(CAN_RX_MSGOBJ, CAN_STD_ID, 0, CAN_LAST_STD_ID, TRUE); |
165 | CanTxMessage[CAN_ID_VERSION].D.Byte[3] = VERSION_MAJOR; |
131 | 166 | ||
Line 132... | Line 167... | ||
132 | UART1_PutString("ok"); |
167 | UART1_PutString("ok"); |
133 | } |
168 | } |
Line 139... | Line 174... | ||
139 | CanReceive(); |
174 | CanReceive(); |
140 | if(CAN_GetTransmitErrorCounter() > 200) CanbusInit(); |
175 | if(CAN_GetTransmitErrorCounter() > 200) CanbusInit(); |
Line 141... | Line 176... | ||
141 | 176 | ||
Line 142... | Line 177... | ||
142 | //DebugOut.Analog[16] = CAN->SR ; |
177 | //DebugOut.Analog[16] = CAN->SR ; |
143 | 178 | ||
144 | if(frame_received_flag) |
179 | if(AllMsgsReceived) |
145 | { |
180 | { |
- | 181 | AllMsgsReceived = 0; |
|
146 | frame_received_flag = 0; |
182 | DebugOut.Analog[17] = CanRxMessage[4].D.sLong; |
- | 183 | DebugOut.Analog[19]++; |
|
- | 184 | ||
Line -... | Line 185... | ||
- | 185 | DebugOut.Analog[17] = CanRxMessage[CAN_ID_FS_LON].D.sLong / 100000; |
|
- | 186 | DebugOut.Analog[18] = CanRxMessage[CAN_ID_FS_LAT].D.sLong / 100000; |
|
- | 187 | ||
- | 188 | if(DebugOut.Analog[31] == 0) |
|
- | 189 | { |
|
- | 190 | GPS_FailsafePosition.Longitude = CanRxMessage[CAN_ID_FS_LON].D.sLong; |
|
147 | DebugOut.Analog[16] = RxCanMsg.Data[0] * 256 + RxCanMsg.Data[1]; |
191 | GPS_FailsafePosition.Latitude = CanRxMessage[CAN_ID_FS_LAT].D.sLong; |