📄 can.lst
字号:
242 1 /// Configuration of Message Object 1:
243 1 /// -----------------------------------------------------------------------
244 1 /// - message object 1 is valid
245 1 /// - enable transmit interrupt; bit INTPND is set after successfull
246 1 /// transmission of a frame
247 1
248 1 /// - message object is used as transmit object
249 1 /// - standard 11-bit identifier
250 1 /// - 8 valid data bytes
251 1 /// - this message object works with CAN node B
252 1 /// - remote monitoring is disabled
253 1 /// - transmit interrupt node pointer: TwinCAN SRN 1
254 1
255 1 CAN_MSGCFGL1 = 0x008A; // load message configuration register low
256 1 CAN_MSGCFGH1 = 0x0010; // load message configuration register high
257 1
258 1 /// - acceptance mask 11-bit: 0x7FF
259 1 /// - identifier 11-bit: 0x132
260 1
261 1 CAN_MSGAMRL1 = 0xFFFF; // load acceptance mask register low
262 1 CAN_MSGAMRH1 = 0xFFFF; // load acceptance mask register high
263 1 //28--18位为掩码位
264 1 CAN_MSGARL1 = 0x0000; // load arbitration register low
265 1 CAN_MSGARH1 = 0x04C8; // load arbitration register high
266 1 //28--18位为标志位
267 1 CAN_MSGDRL10 = 0x0000; // load data register 0 low
268 1 CAN_MSGDRH10 = 0x0000; // load data register 0 high
269 1 CAN_MSGDRL14 = 0x0000; // load data register 4 low
270 1 CAN_MSGDRH14 = 0x0000; // load data register 4 high
271 1
272 1 /// - functionality of standard message object
273 1
274 1 CAN_MSGFGCRL1 = 0x0000; // load FIFO/gateway control register low
275 1 CAN_MSGFGCRH1 = 0x0001; // load FIFO/gateway control register high
276 1
277 1 CAN_MSGCTRH1 = 0x0000; // load message control register high
278 1 CAN_MSGCTRL1 = 0x55A5; // load message control register low
279 1
280 1 /// -----------------------------------------------------------------------
281 1 /// Configuration of Message Object 2:
282 1 /// -----------------------------------------------------------------------
283 1 /// - message object 2 is valid
284 1 /// - enable receive interrupt; bit INTPND is set after successfull
285 1 /// reception of a frame
286 1
287 1 /// - message object is used as receive object
288 1 /// - standard 11-bit identifier
289 1 /// - 8 valid data bytes
290 1 /// - this message object works with CAN node B
291 1 /// - remote monitoring is disabled
292 1 /// - receive interrupt node pointer: TwinCAN SRN 2
293 1
294 1 CAN_MSGCFGL2 = 0x0082; // load message configuration register low
295 1 CAN_MSGCFGH2 = 0x0002; // load message configuration register high
296 1
297 1 /// - acceptance mask 11-bit: 0x7FF
298 1 /// - identifier 11-bit: 0x124
299 1
300 1 CAN_MSGAMRL2 = 0xFFFF; // load acceptance mask register low
301 1 CAN_MSGAMRH2 = 0xFFFF; // load acceptance mask register high
302 1 //28--18位为掩码位
303 1 CAN_MSGARL2 = 0x0000; // load arbitration register low
C166 COMPILER V6.04, CAN 12/10/2006 20:50:28 PAGE 6
304 1 CAN_MSGARH2 = 0x0490; // load arbitration register high
305 1 //28--18位为标志位
306 1 CAN_MSGDRL20 = 0x0000; // load data register 0 low
307 1 CAN_MSGDRH20 = 0x0000; // load data register 0 high
308 1 CAN_MSGDRL24 = 0x0000; // load data register 4 low
309 1 CAN_MSGDRH24 = 0x0000; // load data register 4 high
310 1
311 1 /// - functionality of standard message object
312 1
313 1 CAN_MSGFGCRL2 = 0x0000; // load FIFO/gateway control register low
314 1 CAN_MSGFGCRH2 = 0x0002; // load FIFO/gateway control register high
315 1
316 1 CAN_MSGCTRH2 = 0x0000; // load message control register high
317 1 CAN_MSGCTRL2 = 0x5599; // load message control register low
318 1
319 1
320 1 /// -----------------------------------------------------------------------
321 1 /// Configuration of Service Request Nodes 0 - 7:
322 1 /// -----------------------------------------------------------------------
323 1 /// SRN0 service request node configuration:
324 1 /// - SRN0 interrupt priority level (ILVL) = 14
325 1 /// - SRN0 interrupt group level (GLVL) = 1
326 1 /// - SRN0 group priority extension (GPX) = 0
327 1
328 1 CAN_0IC = 0x0079;
329 1
330 1 /// Use PEC channel 1 for CAN INT 0:
331 1 /// - normal interrupt
332 1 /// - pointers are not modified
333 1 /// - transfer a word
334 1 /// - service End of PEC interrrupt by a EOP interrupt node is disabled
335 1
336 1 PECC1 = 0x0000; // load PECC1 control register
337 1
338 1
339 1 /// SRN1 service request node configuration:
340 1 /// - SRN1 interrupt priority level (ILVL) = 12
341 1 /// - SRN1 interrupt group level (GLVL) = 2
342 1 /// - SRN1 group priority extension (GPX) = 0
343 1
344 1 CAN_1IC = 0x0072;
345 1
346 1 /// SRN2 service request node configuration:
347 1 /// - SRN2 interrupt priority level (ILVL) = 10
348 1 /// - SRN2 interrupt group level (GLVL) = 1
349 1 /// - SRN2 group priority extension (GPX) = 0
350 1
351 1 CAN_2IC = 0x0069;
352 1
353 1
354 1
355 1 // USER CODE BEGIN (Init,3)
356 1
357 1 // USER CODE END
358 1
359 1
360 1 CAN_PISEL = 0x0008; // load port input select register
361 1
362 1 // -----------------------------------------------------------------------
363 1 // Start the CAN Nodes:
364 1 // -----------------------------------------------------------------------
365 1
C166 COMPILER V6.04, CAN 12/10/2006 20:50:28 PAGE 7
366 1 CAN_BCR &= ~(uword)0x0041; // reset INIT and CCE
367 1
368 1
369 1 // USER CODE BEGIN (Init,4)
370 1
371 1 // USER CODE END
372 1
373 1 } // End of function CAN_vInit
374
375
376 //****************************************************************************
377 // @Function void CAN_vGetMsgObj(ubyte ubObjNr, TCAN_SWObj *pstObj)
378 //
379 //----------------------------------------------------------------------------
380 // @Description This function fills the forwarded SW message object with
381 // the content of the chosen HW message object.
382 //
383 // The structure of the SW message object is defined in the
384 // header file CAN.H (see TCAN_SWObj).
385 //
386 //----------------------------------------------------------------------------
387 // @Returnvalue None
388 //
389 //----------------------------------------------------------------------------
390 // @Parameters ubObjNr:
391 // Number of the message object to be read (0-31)
392 // @Parameters *pstObj:
393 // Pointer on a message object to be filled by this function
394 //
395 //----------------------------------------------------------------------------
396 // @Date 2006-12-10
397 //
398 //****************************************************************************
399
400 // USER CODE BEGIN (GetMsgObj,1)
401
402 // USER CODE END
403
404 void CAN_vGetMsgObj(ubyte ubObjNr, TCAN_SWObj *pstObj)
405 {
406 1 ubyte i;
407 1
408 1 for(i = 0; i < (CAN_HWOBJ[ubObjNr].uwMSGCFG & 0x00f0) >> 4; i++)
409 1 {
410 2 pstObj->ubData[i] = CAN_HWOBJ[ubObjNr].ubData[i];
411 2 }
412 1
413 1 if(CAN_HWOBJ[ubObjNr].uwMSGCFG & 0x04) // extended identifier
414 1 {
415 2 pstObj->ulID = CAN_HWOBJ[ubObjNr].ulCANAR;
416 2 pstObj->ulMask = CAN_HWOBJ[ubObjNr].ulCANAMR;
417 2 }
418 1 else // standard identifier
419 1 {
420 2 pstObj->ulID = CAN_HWOBJ[ubObjNr].ulCANAR >> 18;
421 2 pstObj->ulMask = CAN_HWOBJ[ubObjNr].ulCANAMR >> 18;
422 2 }
423 1
424 1 pstObj->uwCounter = CAN_HWOBJ[ubObjNr].uwCounter;
425 1 pstObj->uwMsgCfg = CAN_HWOBJ[ubObjNr].uwMSGCFG;
426 1
427 1 } // End of function CAN_vGetMsgObj
C166 COMPILER V6.04, CAN 12/10/2006 20:50:28 PAGE 8
428
429
430 //****************************************************************************
431 // @Function ubyte CAN_ubRequestMsgObj(ubyte ubObjNr)
432 //
433 //----------------------------------------------------------------------------
434 // @Description If a TRANSMIT OBJECT is to be reconfigured it must first be
435 // accessed. The access to the transmit object is exclusive.
436 // This function checks whether the choosen message object is
437 // still executing a transmit request, or if the object can be
438 // accessed exclusively.
439 // After the message object is reserved, it can be
440 // reconfigured by using the function CAN_vConfigMsgObj or
441 // CAN_vLoadData.
442 // Both functions enable access to the object for the CAN
443 // controller.
444 // By calling the function CAN_vTransmit transfering of data
445 // is started.
446 //
447 //----------------------------------------------------------------------------
448 // @Returnvalue 0 message object is busy (a transfer is active), else 1
449 //
450 //----------------------------------------------------------------------------
451 // @Parameters ubObjNr:
452 // Number of the message object (0-31)
453 //
454 //----------------------------------------------------------------------------
455 // @Date 2006-12-10
456 //
457 //****************************************************************************
458
459 // USER CODE BEGIN (RequestMsgObj,1)
460
461 // USER CODE END
462
463 ubyte CAN_ubRequestMsgObj(ubyte ubObjNr)
464 {
465 1 ubyte ubReturn;
466 1
467 1 ubReturn = 0;
468 1 if((CAN_HWOBJ[ubObjNr].uwMSGCTR & 0x3000) == 0x1000) // if reset TXRQ
469 1 {
470 2 CAN_HWOBJ[ubObjNr].uwMSGCTR = 0xfbff; // set CPUUPD
471 2 ubReturn = 1;
472 2 }
473 1 return(ubReturn);
474 1
475 1 } // End of function CAN_ubRequestMsgObj
476
477
478 //****************************************************************************
479 // @Function ubyte CAN_ubNewData(ubyte ubObjNr)
480 //
481 //----------------------------------------------------------------------------
482 // @Description This function checks whether the selected RECEIVE OBJECT
483 // has received a new message. If so the function returns the
484 // value '1'.
485 //
486 //----------------------------------------------------------------------------
487 // @Returnvalue 1 the message object has received a new message, else 0
488 //
489 //----------------------------------------------------------------------------
C166 COMPILER V6.04, CAN 12/10/2006 20:50:28 PAGE 9
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -