Document fait avec Nvu Document made with Nvu




Emulator CAN buses driver

Instructions
Use
Example

Principle

If the CAN buses A and B of the emulator are transmission/reception interfaces addressables in the extension registers area of the FORTH core described in the corresponding page, the driver will allow to facilitate the use of these interfaces while making use of the real-time kernel.

Instructions

- CW_NUMERO 129

Numero of the extension register giving the board identification nupero.

- CW_CAN_A_CTRL 448
- CW_CAN_A_BRPR 449
- CW_CAN_A_BTR 450
- CW_CAN_A_TEC 451
- CW_CAN_A_REC 452
- CW_CAN_A_AFMR1_H 456
- CW_CAN_A_AFMR1_L 457
- CW_CAN_A_AFIR1_H 458
- CW_CAN_A_AFIR1_L 459
- CW_CAN_A_AFMR2_H 460
- CW_CAN_A_AFMR2_L 461
- CW_CAN_A_AFIR2_H 462
- CW_CAN_A_AFIR2_L 463
- CW_CAN_A_AFMR3_H 464
- CW_CAN_A_AFMR3_L 465
- CW_CAN_A_AFIR3_H 466
- CW_CAN_A_AFIR3_L 467
- CW_CAN_A_AFMR4_H 468
- CW_CAN_A_AFMR4_L 469
- CW_CAN_A_AFIR4_H 470
- CW_CAN_A_AFIR4_L 471
- CW_CAN_A_ID_H 472
- CW_CAN_A_ID_L 473
- CW_CAN_A_RF 474
- CW_CAN_A_DLC 475
- CW_CAN_A_DATA_01 476
- CW_CAN_A_DATA_23 477
- CW_CAN_A_DATA_45 478
- CW_CAN_A_DATA_67 479

Numeros of the CAN A bus extension registers.

- CW_CAN_B_CTRL 480
- CW_CAN_B_BRPR 481
- CW_CAN_B_BTR 482
- CW_CAN_B_TEC 483
- CW_CAN_B_REC 484
- CW_CAN_B_AFMR1_H 488
- CW_CAN_B_AFMR1_L 489
- CW_CAN_B_AFIR1_H 490
- CW_CAN_B_AFIR1_L 491
- CW_CAN_B_AFMR2_H 492
- CW_CAN_B_AFMR2_L 493
- CW_CAN_B_AFIR2_H 494
- CW_CAN_B_AFIR2_L 495
- CW_CAN_B_AFMR3_H 496
- CW_CAN_B_AFMR3_L 497
- CW_CAN_B_AFIR3_H 498
- CW_CAN_B_AFIR3_L 499
- CW_CAN_B_AFMR4_H 500
- CW_CAN_B_AFMR4_L 501
- CW_CAN_B_AFIR4_H 502
- CW_CAN_B_AFIR4_L 503
- CW_CAN_B_ID_H 504
- CW_CAN_B_ID_L 505
- CW_CAN_B_RF 506
- CW_CAN_B_DLC 507
- CW_CAN_B_DATA_01 508
- CW_CAN_B_DATA_23 509
- CW_CAN_B_DATA_45 510
- CW_CAN_B_DATA_67 511

Numeros of the CAN B bus extension registers.

id,msq,type,no CAN_A_FILTRE err

Configuration CAN A bus reception filters.
id is the identifier or address of the filtered frames.
msq is the identifier mask.
type: - 1 for a standard address frame,
- 2 for an aknowledgement with a standard address,
- 3 for an extended address frame,
- 4
for an aknowledgement with an extended address.
no is the filter number (1 to 4).
err: - 0 if the configuration is OK,
- -1 if the filter numero is bad,
- -2 if the type is bad.

id,msq,type,no CAN_B_FILTRE err


Configuration CAN B bus reception filters.
id is the identifier or address of the filtered frames.
msq is the identifier mask.
type: - 1 for a standard address frame,
- 2 for an aknowledgement with a standard address,
- 3 for an extended address frame,
- 4
for an aknowledgement with an extended address.
no is the filter number (1 to 4).
err: - 0 if the configuration is OK,
- -1 if the filter numero is bad,
- -2 if the type is bad.

adr,dlc,id,type CAN_A_TX err

Transmission of a frame on the CAN A bus.
adr is the address of the first byte to be transmitted.
dlc is the byte number of the frame (0 to 8).
id is the identifier or address of the frame.
t type: - 1 for a standard address frame,
- 2 for an aknowledgement with a standard address,
- 3 for an extended address frame,
- 4
for an aknowledgement with an extended address.
err: - 0 if the transmission is OK,
- -1 if the transmission is not possible (saturated transmission file),
- -2 if the dlc is bad,
- -3 if the type is bad.

adr,dlc,id,type CAN_B_TX err

Transmission of a frame on the CAN B bus.
adr is the address of the first byte to be transmitted.
dlc is the byte number of the frame (0 to 8).
id is the identifier or address of the frame.
t type: - 1 for a standard address frame,
- 2 for an aknowledgement with a standard address,
- 3 for an extended address frame,
- 4
for an aknowledgement with an extended address.
err: - 0 if the transmission is OK,
- -1 if the transmission is not possible (saturated transmission file),
- -2 if the dlc is bad,
- -3 if the type is bad.

adr CAN_A_RX dlc,id,type

Reception of a frame on the CAN A bus.
adr is the address of the first byte to be transmitted.
dlc is the byte number of the frame (0 to 8).
id is the identifier or address of the frame.
t type: - 1 for a standard address frame,
- 2 for an aknowledgement with a standard address,
- 3 for an extended address frame,
- 4
for an aknowledgement with an extended address.
dlc, id et type are 0 if not any frame is available (empty reception file).

adr CAN_B_RX dlc,id,type

Reception of a frame on the CAN B bus.
adr is the address of the first byte to be transmitted.
dlc is the byte number of the frame (0 to 8).
id is the identifier or address of the frame.
t type: - 1 for a standard address frame,
- 2 for an aknowledgement with a standard address,
- 3 for an extended address frame,
- 4
for an aknowledgement with an extended address.
dlc, id et type are 0 if not any frame is available (empty reception file).

phseg2,phseg1,propseg,sjw,brtq CAN_A_INIT -

CAN A bus parameters initialization.
phseg2, phseg1, propseg and sjw configurate the timing of each bit following the CAN standard.
brtq is the frequency of the bit quantum.

phseg2,phseg1,propseg,sjw,brtq  CAN_B_INIT -

CAN B bus parameters initialization.
phseg2, phseg1, propseg and sjw configurate the timing of each bit following the CAN standard.
brtq is the frequency of the bit quantum.


Use

The driver not being integrated into the kernel, it is initially necessary to compile the source file can_A_B.txt before being able to use it.

The reception filters must be first programmed if necessary with the instructions CAN_A_FILTRE and CAN_B_FILTRE (up to 4 for each bus) then initialize the required buses with the instructions CAN_A_INIT and CAN_B_INIT.

A frame could be so transmitted with the instructions CAN_A_TX and CAN_B_TX or received with the instructions CAN_A_RX and CAN_B_RX.

Example

the script of the file test_can.txt  allows to check if the CAN A and B buses are linked or not. A counter is steping up if the link exists and steping down up to 0 otherwise:

CAN A and B buses initialization
compteur_emis = 0
compteur_recu = 0
while not any keyboard action, do
     transmission of compteur_emis on the CAN A bus
     waiting for 50ms
     if reception on CAN B bus
     then compteur_recu = received value and transmission of compteur_recu+2 on the CAN B bus
     end if
     waiting for 50ms
     if reception on the CAN A bus
     then compteur_emis = received value
     end if
     if compteur_emis>0
     then compteur_emis = compteur_emis-1
     end if
     displaying of compteur_emis value
end while

Here is a video: