|  | Dual Active Bridge Development Board (Part-No. ) |
Content |  |  |  |  |  |

Loading...
Searching...
No Matches
PBV_CAN.c
1
2/*
3 * @file PBV_CAN.c
4 * @author M70027
5 * @ingroup PBV_CAN
6 * @brief Power Board Visualizer CAN interface
7 */
8
9// includes
10#include "PBV_CAN.h"
11// MCC header files
12#include "can/can1.h"
13
15typedef struct CAN_MSG_OBJ CAN_MSG_OBJ_t;
16
17
21 CAN_MSG_OBJ_t pbvCanObjectTx;
22
23
27 CAN_MSG_OBJ_t pbvCanObjectRx;
28
29
33 CAN_MSG_OBJ_t pbvCanObjectAscii;
34
35
44 void PBV_CAN_Init(PBV_Datatype_TX_t* boardToPBV, PBV_Datatype_TX_t* boardToPBVAscii, PBV_Datatype_RX_t *pbvToBoard)
45{
46 pbvCanObjectTx.msgId = boardToPBV->PBV_Protcol_ID;
47 pbvCanObjectTx.field.dlc = DLC_64;
48 pbvCanObjectTx.field.brs = CAN_BRS_MODE;
49 pbvCanObjectTx.field.formatType = CAN_FD_FORMAT;
50 pbvCanObjectTx.field.frameType = CAN_FRAME_DATA;
51 pbvCanObjectTx.field.idType = CAN_FRAME_STD;
52
53 pbvCanObjectAscii.msgId = boardToPBVAscii->PBV_Protcol_ID;
54 pbvCanObjectAscii.field.dlc = DLC_64;
55 pbvCanObjectAscii.field.brs = CAN_BRS_MODE;
56 pbvCanObjectAscii.field.formatType = CAN_FD_FORMAT;
57 pbvCanObjectAscii.field.frameType = CAN_FRAME_DATA;
58 pbvCanObjectAscii.field.idType = CAN_FRAME_EXT;
59}
60
61
67uint8_t PBV_CAN_Receive_from_GUI()
68{
69 if (CAN1_ReceivedMessageCountGet() > 0)
70 {
71 if (CAN1_Receive(&pbvCanObjectRx) == true)
72 return 0;
73 }
74 return 1;
75}
76
77
83uint8_t PBV_CAN_Transmit_Ascii_to_GUI()
84{
85 if( CAN1_Transmit(CAN1_TXQ, &pbvCanObjectAscii ) != CAN_TX_MSG_REQUEST_SUCCESS)
86 return PBV_MESSAGE_TX_ERROR;
87 else
88 return PBV_MESSAGE_TRANSMITTED;
89}
90
91
97uint8_t PBV_CAN_Transmit_to_GUI()
98{
99 if( CAN1_Transmit(CAN1_TXQ, &pbvCanObjectTx ) != CAN_TX_MSG_REQUEST_SUCCESS)
100 return PBV_MESSAGE_TX_ERROR;
101 else
102 return PBV_MESSAGE_TRANSMITTED;
103}
104
105
112 void PBV_CAN_Reinit(PBV_Datatype_TX_t * ptr){
113 if (ptr->PBV_Signal_Ascii == PBV_SIGNAL_MODE)
114 {
115 pbvCanObjectTx.msgId = ptr->PBV_Protcol_ID;
116 switch (ptr->Length)
117 {
118 case 0:
119 pbvCanObjectTx.field.dlc = DLC_0; /*< Data length count 0 */
120 break;
121 case 1:
122 pbvCanObjectTx.field.dlc = DLC_1; /*< Data length count 1 */
123 break;
124 case 2:
125 pbvCanObjectTx.field.dlc = DLC_2; /*< Data length count 2 */
126 break;
127 case 3:
128 pbvCanObjectTx.field.dlc = DLC_3; /*< Data length count 3 */
129 break;
130 case 4:
131 pbvCanObjectTx.field.dlc = DLC_4; /*< Data length count 4 */
132 break;
133 case 5:
134 pbvCanObjectTx.field.dlc = DLC_5; /*< Data length count 5 */
135 break;
136 case 6:
137 pbvCanObjectTx.field.dlc = DLC_6; /*< Data length count 6 */
138 break;
139 case 7:
140 pbvCanObjectTx.field.dlc = DLC_7; /*< Data length count 7 */
141 break;
142 case 8:
143 pbvCanObjectTx.field.dlc = DLC_8; /*< Data length count 8 */
144 break;
145 case 9 ... 12:
146 pbvCanObjectTx.field.dlc = DLC_12; /*< Data length count 12 */
147 break;
148 case 13 ... 16:
149 pbvCanObjectTx.field.dlc = DLC_16; /*< Data length count 16 */
150 break;
151 case 17 ... 20:
152 pbvCanObjectTx.field.dlc = DLC_20; /*< Data length count 20 */
153 break;
154 case 21 ... 24:
155 pbvCanObjectTx.field.dlc = DLC_24; /*< Data length count 24 */
156 break;
157 case 25 ... 32:
158 pbvCanObjectTx.field.dlc = DLC_32; /*< Data length count 32 */
159 break;
160 case 33 ... 48:
161 pbvCanObjectTx.field.dlc = DLC_48; /*< Data length count 48 */
162 break;
163 case 49 ... 64:
164 pbvCanObjectTx.field.dlc = DLC_64; /*< Data length count 64 */
165 break;
166 default:
167 pbvCanObjectTx.field.dlc = DLC_64; /*< Data length count 64 */
168 break;
169 }
170 }
171 else
172 {
173 pbvCanObjectAscii.msgId = ptr->PBV_Protcol_ID;
174 switch (ptr->Length)
175 {
176 case 0:
177 pbvCanObjectAscii.field.dlc = DLC_0; /*< Data length count 0 */
178 break;
179 case 1:
180 pbvCanObjectAscii.field.dlc = DLC_1; /*< Data length count 1 */
181 break;
182 case 2:
183 pbvCanObjectAscii.field.dlc = DLC_2; /*< Data length count 2 */
184 break;
185 case 3:
186 pbvCanObjectAscii.field.dlc = DLC_3; /*< Data length count 3 */
187 break;
188 case 4:
189 pbvCanObjectAscii.field.dlc = DLC_4; /*< Data length count 4 */
190 break;
191 case 5:
192 pbvCanObjectAscii.field.dlc = DLC_5; /*< Data length count 5 */
193 break;
194 case 6:
195 pbvCanObjectAscii.field.dlc = DLC_6; /*< Data length count 6 */
196 break;
197 case 7:
198 pbvCanObjectAscii.field.dlc = DLC_7; /*< Data length count 7 */
199 break;
200 case 8:
201 pbvCanObjectAscii.field.dlc = DLC_8; /*< Data length count 8 */
202 break;
203 case 9 ... 12:
204 pbvCanObjectAscii.field.dlc = DLC_12; /*< Data length count 12 */
205 break;
206 case 13 ... 16:
207 pbvCanObjectAscii.field.dlc = DLC_16; /*< Data length count 16 */
208 break;
209 case 17 ... 20:
210 pbvCanObjectAscii.field.dlc = DLC_20; /*< Data length count 20 */
211 break;
212 case 21 ... 24:
213 pbvCanObjectAscii.field.dlc = DLC_24; /*< Data length count 24 */
214 break;
215 case 25 ... 32:
216 pbvCanObjectAscii.field.dlc = DLC_32; /*< Data length count 32 */
217 break;
218 case 33 ... 48:
219 pbvCanObjectAscii.field.dlc = DLC_48; /*< Data length count 48 */
220 break;
221 case 49 ... 64:
222 pbvCanObjectAscii.field.dlc = DLC_64; /*< Data length count 64 */
223 break;
224 default:
225 pbvCanObjectAscii.field.dlc = DLC_64; /*< Data length count 64 */
226 break;
227 }
228 }
229}
230
231
238 void PBV_CAN_Link_Data_TX(PBV_Datatype_TX_t * ptr){
239 if (ptr->PBV_Signal_Ascii == PBV_SIGNAL_MODE)
240 pbvCanObjectTx.data = ptr->Data_Buffer;
241 else
242 pbvCanObjectAscii.data = ptr->Data_Buffer;
243}
244
245
252 void PBV_CAN_Link_Data_RX(PBV_Datatype_RX_t * ptr){
253 if (ptr->PBV_Message_State == 0){
254 ptr->Data_Buffer = pbvCanObjectRx.data;
255 ptr->PBV_Protcol_ID = pbvCanObjectRx.msgId;
256 switch (pbvCanObjectRx.field.dlc)
257 {
258 case DLC_0:
259 ptr->Length = 0; /*< Data length count 0 */
260 break;
261 case DLC_1:
262 ptr->Length = 1; /*< Data length count 1 */
263 break;
264 case DLC_2:
265 ptr->Length = 2; /*< Data length count 2 */
266 break;
267 case DLC_3:
268 ptr->Length = 3; /*< Data length count 3 */
269 break;
270 case DLC_4:
271 ptr->Length = 4; /*< Data length count 4 */
272 break;
273 case DLC_5:
274 ptr->Length = 5; /*< Data length count 5 */
275 break;
276 case DLC_6:
277 ptr->Length = 6; /*< Data length count 6 */
278 break;
279 case DLC_7:
280 ptr->Length = 7; /*< Data length count 7 */
281 break;
282 case DLC_8:
283 ptr->Length = 8; /*< Data length count 8 */
284 break;
285 case DLC_12:
286 ptr->Length = 12; /*< Data length count 12 */
287 break;
288 case DLC_16:
289 ptr->Length = 16; /*< Data length count 16 */
290 break;
291 case DLC_20:
292 ptr->Length = 20; /*< Data length count 20 */
293 break;
294 case DLC_24:
295 ptr->Length = 24; /*< Data length count 24 */
296 break;
297 case DLC_32:
298 ptr->Length = 32; /*< Data length count 32 */
299 break;
300 case DLC_48:
301 ptr->Length = 48; /*< Data length count 48 */
302 break;
303 case DLC_64:
304 ptr->Length = 64; /*< Data length count 64 */
305 break;
306 default:
307 ptr->Length = 64; /*< Data length count 64 */
308 break;
309 }
310 }
311}
can1.h
This is the generated driver header file for the CAN1 driver using CCL.
CAN1_TXQ
@ CAN1_TXQ
Definition can1.h:217
DLC_24
@ DLC_24
Definition can_types.h:194
DLC_0
@ DLC_0
Definition can_types.h:179
DLC_5
@ DLC_5
Definition can_types.h:184
DLC_20
@ DLC_20
Definition can_types.h:193
DLC_2
@ DLC_2
Definition can_types.h:181
DLC_12
@ DLC_12
Definition can_types.h:191
DLC_8
@ DLC_8
Definition can_types.h:187
DLC_16
@ DLC_16
Definition can_types.h:192
DLC_1
@ DLC_1
Definition can_types.h:180
DLC_48
@ DLC_48
Definition can_types.h:196
DLC_3
@ DLC_3
Definition can_types.h:182
DLC_4
@ DLC_4
Definition can_types.h:183
DLC_64
@ DLC_64
Definition can_types.h:197
DLC_6
@ DLC_6
Definition can_types.h:185
DLC_32
@ DLC_32
Definition can_types.h:195
DLC_7
@ DLC_7
Definition can_types.h:186
CAN_FRAME_STD
@ CAN_FRAME_STD
Definition can_types.h:92
CAN_FRAME_EXT
@ CAN_FRAME_EXT
Definition can_types.h:93
CAN_FRAME_DATA
@ CAN_FRAME_DATA
Definition can_types.h:103
CAN_FD_FORMAT
@ CAN_FD_FORMAT
Definition can_types.h:115
CAN_BRS_MODE
@ CAN_BRS_MODE
Definition can_types.h:82
CAN_TX_MSG_REQUEST_SUCCESS
@ CAN_TX_MSG_REQUEST_SUCCESS
Definition can_types.h:125
PBV_CAN_Link_Data_TX
void PBV_CAN_Link_Data_TX(PBV_Datatype_TX_t *ptr)
Links the data from TX PBV datatype to CAN TX object.
Definition PBV_CAN.c:238
PBV_CAN_Receive_from_GUI
uint8_t PBV_CAN_Receive_from_GUI()
Checks the queue and if a message is received then links the data pointer to can object.
Definition PBV_CAN.c:67
PBV_CAN_Link_Data_RX
void PBV_CAN_Link_Data_RX(PBV_Datatype_RX_t *ptr)
links the received data to the application data structure
Definition PBV_CAN.c:252
PBV_CAN_Init
void PBV_CAN_Init(PBV_Datatype_TX_t *boardToPBV, PBV_Datatype_TX_t *boardToPBVAscii, PBV_Datatype_RX_t *pbvToBoard)
Initializes CAN objects with PBV objects ( only CAN IDs for now)
Definition PBV_CAN.c:44
pbvCanObjectAscii
CAN_MSG_OBJ_t pbvCanObjectAscii
CAN object for ascii TX. Initialized by PBV_CAN_Init()
Definition PBV_CAN.c:33
PBV_CAN_Reinit
void PBV_CAN_Reinit(PBV_Datatype_TX_t *ptr)
Reinitializes the can object with new can id.
Definition PBV_CAN.c:112
PBV_CAN_Transmit_Ascii_to_GUI
uint8_t PBV_CAN_Transmit_Ascii_to_GUI()
transmits the Ascii msg to PBV
Definition PBV_CAN.c:83
pbvCanObjectRx
CAN_MSG_OBJ_t pbvCanObjectRx
CAN object for numeric RX. Does not have to be initialized.
Definition PBV_CAN.c:27
pbvCanObjectTx
CAN_MSG_OBJ_t pbvCanObjectTx
CAN object for Numeric TX. Initialized by PBV_CAN_Init()
Definition PBV_CAN.c:21
PBV_CAN_Transmit_to_GUI
uint8_t PBV_CAN_Transmit_to_GUI()
Transmits the numerical msg to PBV.
Definition PBV_CAN.c:97
PBV_SIGNAL_MODE
@ PBV_SIGNAL_MODE
Object will transmit/receive signals.
Definition PBV_interface.h:23
PBV_MESSAGE_TRANSMITTED
@ PBV_MESSAGE_TRANSMITTED
Message transmitted. successful transmit.
Definition PBV_interface.h:35
PBV_MESSAGE_TX_ERROR
@ PBV_MESSAGE_TX_ERROR
if some error happens. unsuccessful transmit
Definition PBV_interface.h:39
CAN1_Receive
bool CAN1_Receive(struct CAN_MSG_OBJ *rxCanMsg)
Reads the received single message object.
Definition can1.c:703
CAN1_ReceivedMessageCountGet
uint8_t CAN1_ReceivedMessageCountGet(void)
Returns the number of CAN messages received in all the FIFO.
Definition can1.c:854
CAN1_Transmit
enum CAN_TX_MSG_REQUEST_STATUS CAN1_Transmit(const enum CAN1_TX_FIFO_CHANNELS fifoChannel, struct CAN_MSG_OBJ *txCanMsg)
Writes the CAN message object to specified transmit FIFO channel.
Definition can1.c:788
CAN_MSG_FIELD::frameType
unsigned int frameType
Definition can_types.h:55
CAN_MSG_FIELD::formatType
unsigned int formatType
Definition can_types.h:57
CAN_MSG_FIELD::dlc
unsigned int dlc
Definition can_types.h:56
CAN_MSG_FIELD::idType
unsigned int idType
Definition can_types.h:54
CAN_MSG_FIELD::brs
unsigned int brs
Definition can_types.h:58
CAN_MSG_OBJ
This data structure used to configure the CAN FD message object.
Definition can_types.h:68
CAN_MSG_OBJ::field
struct CAN_MSG_FIELD field
Definition can_types.h:70
CAN_MSG_OBJ::msgId
uint32_t msgId
Definition can_types.h:69
CAN_MSG_OBJ::data
uint8_t * data
Definition can_types.h:71
PBV_Datatype_TX_t
Definition PBV_interface.h:75
PBV_Datatype_TX_t::PBV_Protcol_ID
uint32_t PBV_Protcol_ID
Protocol ID.
Definition PBV_interface.h:77
PBV_Datatype_TX_t::Data_Buffer
uint8_t * Data_Buffer
Pointer to the data to be transmitted.
Definition PBV_interface.h:80
PBV_Datatype_TX_t::PBV_Signal_Ascii
enum PBV_SIGNAL_ASCII_MODE PBV_Signal_Ascii
Object will transmit Signals or ASCII.
Definition PBV_interface.h:78
PBV_Datatype_TX_t::Length
uint16_t Length
Length of transmitted message in Bytes.
Definition PBV_interface.h:76
PBV_Datatype_RX_t
Definition PBV_interface.h:89
PBV_Datatype_RX_t::PBV_Protcol_ID
uint32_t PBV_Protcol_ID
Protocol ID of the received message.
Definition PBV_interface.h:91
PBV_Datatype_RX_t::PBV_Message_State
PBV_MESSAGE_RX_STATE_t PBV_Message_State
State of the received message.
Definition PBV_interface.h:93
PBV_Datatype_RX_t::Data_Buffer
uint8_t * Data_Buffer
Received Data pointer.
Definition PBV_interface.h:94
PBV_Datatype_RX_t::Length
uint16_t Length
Length of received message in Bytes.
Definition PBV_interface.h:90