Documentation

Softing CAN-AC2-PCI with Philips SJA1000 FIFO Write

Softing CAN-AC2-PCI with Philips SJA1000 FIFO Write Driver block

Library

Simulink® Real-Time™ Library for CAN

Description

The FIFO Write driver block writes CAN messages into the transmit FIFO. The firmware running in FIFO mode processes the information in the transmit FIFO and finally puts the constructed CAN messages onto the bus. This block dynamically detects the data type and signal size of the signal you connect to the input port. If you use this block inside an enabled subsystem, the block sends the message only when you enable the subsystem.

If you use the CAN_MESSAGE data type:

If the block input is a CAN_MESSAGE data type, use CAN Pack blocks to pack individual signals into a CAN message. If you use CAN Pack blocks to prepare each message, the FIFO Write block reads the CAN_MESSAGE data. To combine several messages into a vector of CAN_MESSAGE data that the FIFO Write block sends, use a Mux block. Use the Port (if input is CAN_MESSAGE) parameter to select the port to which to send the CAN_MESSAGE data.

    Tip   To prepare a remote frame, use the CAN Pack block with the Remote frame check box selected. To request the current value, send the remote frame to the responding subsystem.

If you use the double data type (legacy):

If the block input consists of double values in a matrix, the block has one input port of type double. At this port, the required information must be provided to construct valid CAN messages to be written into the transmit FIFO. For each CAN message, five elements are passed:

Port

The value can be either 1 (port 1) or 2 (port 2) and defines the port the CAN message is sent from.

Identifier

Identifier of the CAN message to be sent. If it is a standard CAN message the valid range is 0 to 2047. If the CAN message is extended, the range is 0 to 229-1.

Identifier type

The value can be either 0 (standard identifier range) or 1 (extended identifier range) and defines the identifier type of the outgoing CAN message.

Data frame size

The value can be in the range of 0 to 8 and defines the data frame size in bytes of the outgoing CAN message.

Data

Data for the data frame itself. Use the CAN Bit-Packing block to construct the data as double values in a matrix.

Because this information can be dynamically changed in FIFO mode during real-time application execution, the information is provided at the block input instead of you setting them through block parameters. To be able to transmit more than one CAN message per block instance, a matrix signal is used as a container.

The dimension of the matrix signal entering the block has to be n*5, where n is the number of CAN messages to be sent by this block instance. Therefore each row of the matrix signal defines one CAN message and each row combines the five elements of information defined above (in this order).

For examples of constructing the matrix signal for the FIFO Write block, see CAN FIFO Loopback Tests.

For certain models, you might make the writing of a CAN message into the transmit FIFO dependent on the model dynamics. For this case, the matrix signal can also be of dimension n*6 instead of n*5. In this case, the sixth column defines whether the corresponding CAN message is written into the transmit FIFO (1) or not (0).

Block Parameters

Board

Define the board used to send the CAN messages defined by this block instance. For more information about the meaning of the board number, see the Setup driver block. If just one board is present in the target system, you should select 1.

Show input count port

Select this check box to track the number of inputs to the block and add a second input port, N, to the block. If this port value exceeds the size of the input vector of CAN_MESSAGE messages, the block limits the transfer to the size of the input vector. If this port value is smaller than the CAN_MESSAGE input vector size, the block transfers data up to the size of this port value. For example, assume an input of 10*5 matrix. If you then input a 5 to input port N, the block sends only the first five messages. In an n*6 matrix, the last entry in the row is still the individual message enabled, but the block checks only messages up to n. If the input is a matrix of doubles, the block ignores the value of the Port parameter. The block considers the port as part of the data.

If this check box is cleared, the block sends all elements of the input vector.

Port (if input is CAN_MESSAGE)

If the message is a CAN_MESSAGE data type, from the list, select 1 or 2 for the port to send the message through. The block sends a message to a single CAN port. If you want to send messages to different ports in a model, use multiple FIFO Write blocks. This input port is the first one on the block. Its input is a vector or single CAN_MESSAGE message.

If the message consists of double values in a matrix, changing this parameter does not change the block behavior. You specify the port number in the CAN message. A single FIFO Write block can send messages through both ports.

Show status output port

Select this to enable the status output port. If the box is cleared, the block does not have an output port. If enabled, a port is shown. The signal leaving the block is a vector of type CAN_MESSAGE or double depending on which data type you are using for your messages, in which the number of elements depends on the signal dimension of the block input port. There is one element for each CAN message written into the transmit FIFO and the value is identical to the return argument of function CANPC_send_data, described in the Softing® user manual. Refer to that manual for more information. The function return codes are:

CodeDescription

0

Function executed without detecting an error.

-1

Function encountered an error.

-4

Timeout firmware communication.

-99

Board not initialized.

Sample time

Defines the sample time at which the FIFO Write block is executed during a real-time application run.

You can use as many instances of the FIFO Write block in the model as required. For example, by using two instances of the block, you can send CAN messages at different sample times. Or you can use multiple instances to structure your model more efficiently.

Was this topic helpful?