Chapter 4: Software
CAN-Engine
_____________________________________________________________________________________
4-16
outputBuf, oSize –
similar to above; these variables represent the ring-buffer allocated for buffering
messages to be transmitted.
address, mask
– these two byte values are used to determining which messages transmitted on the
CAN network should be “received”. For all messages, the mask value and the first 8-bits of the message
address are AND’ed together, and then compared to the address value.
void can_transceiver_enable
Arguments: unsigned char enable
Return values: none
After software drivers have been enabled, the CAN transceiver must still be enabled using a digital output
pin. Once the transceiver is enabled, the port will be connected to the CAN bus, and able to
transmit/receive messages.
On the CAN-Engine, the transceiver is controlled using SER1 RTS pin:.
s1_rts(0); // RTS1 low - enable
.
void can_hit
Arguments:
none
Return value:
non-zero if packet received, 0 if receive buffer is empty.
Use this function to determine whether a packet has been received and buffered. Call this function before
calling can_get() to retrieve actual message.
void can_get
Arguments:
CanMsg*
message
Return value:
none
This function is used to retrieve a CAN message, after can_hit() has already been called. The argument
should be a pointer to a separately allocated CanMsg variable. The next message in the receive buffer will
be copied into this variable. Note: Make sure’message’ points to an allocated area of memory!
void can_put
Arguments: CanMsg* message
Return values: none.
This function adds
message
to the transmit buffer. Messages in the transmit buffer are sent on a FIFO
basis.
void can_flush
Arguments: none
Return values: none.
This function can be used to make sure the transmit buffer does not over-flow. It will not return until all
currently buffered messages are fully transmitted, and the transmit buffer is completely empty.