sja1000_send_message.c
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 /*
3  * Copyright (c) 2007 Fabian Greif, Roboterclub Aachen e.V.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  * $Id$
28  */
29 // ----------------------------------------------------------------------------
30 
31 #include "sja1000_private.h"
32 #ifdef SUPPORT_FOR_SJA1000__
33 
34 // ----------------------------------------------------------------------------
35 
36 uint8_t sja1000_send_message(const can_t *msg)
37 {
38  uint8_t frame_info;
39  uint8_t address;
40 
41  if (!sja1000_check_free_buffer() || (msg->length > 8))
42  return FALSE;
43 
44  frame_info = msg->length | ((msg->flags.rtr) ? (1<<RTR) : 0);
45 
46  if (msg->flags.extended)
47  {
48  // write frame info
49  sja1000_write(TX_INFO, frame_info | (1<<FF));
50 
51  // write extended identifier
52  sja1000_write(20, msg->id << 3);
53  sja1000_write(19, msg->id >> 5);
54  sja1000_write(18, msg->id >> 13);
55  sja1000_write(17, msg->id >> 21);
56 
57  address = 21;
58  }
59  else
60  {
61  // write frame info
62  sja1000_write(TX_INFO, frame_info);
63 
64  const uint32_t *ptr32 = &msg->id; // used to supress a compiler warning
65  uint16_t *ptr = (uint16_t *) ptr32;
66 
67  // write standard identifier
68  sja1000_write(18, *ptr << 5);
69  sja1000_write(17, *ptr >> 3);
70 
71  address = 19;
72  }
73 
74  if (!msg->flags.rtr)
75  {
76  for (uint8_t i = 0;i < msg->length; i++) {
77  sja1000_write(address + i, msg->data[i]);
78  }
79  }
80 
81  // send buffer
82  sja1000_write(CMR, (1<<TR));
83 
85 
86  return TRUE;
87 }
88 
89 #endif // SUPPORT_FOR_SJA1000__
TRUE
@ TRUE
Definition: lpc_types.h:50
CAN_INDICATE_TX_TRAFFIC_FUNCTION
#define CAN_INDICATE_TX_TRAFFIC_FUNCTION
Definition: can_private.h:133
can_t::length
uint8_t length
Anzahl der Datenbytes.
Definition: can.h:192
TX_INFO
#define TX_INFO
Definition: sja1000_defs.h:85
uavcan::uint32_t
std::uint32_t uint32_t
Definition: std.hpp:26
can_t::rtr
int rtr
Remote-Transmit-Request-Frame?
Definition: can.h:182
can_t
Datenstruktur zum Aufnehmen von CAN Nachrichten.
Definition: can.h:177
RTR
#define RTR
Bitdefinition von RXBnDLC (n = 0, 1)
Definition: mcp2515_defs.h:302
can_t::data
uint8_t data[8]
Die Daten der CAN Nachricht.
Definition: can.h:193
uavcan::uint16_t
std::uint16_t uint16_t
Definition: std.hpp:25
uavcan::uint8_t
std::uint8_t uint8_t
Definition: std.hpp:24
FALSE
@ FALSE
Definition: lpc_types.h:50
can_t::extended
int extended
extended ID?
Definition: can.h:183
TR
#define TR
Definition: sja1000_defs.h:120
FF
#define FF
Bitdefinition von RX_INFO und TX_INFO.
Definition: sja1000_defs.h:241
can_t::flags
struct can_t::@136 flags
can_t::id
uint32_t id
ID der Nachricht (11 oder 29 Bit)
Definition: can.h:180
CMR
#define CMR
Definition: sja1000_defs.h:44
sja1000_private.h
SJA1000 Interface.


uavcan_communicator
Author(s):
autogenerated on Fri Dec 13 2024 03:10:03