sja1000_get_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_get_message(can_t *msg)
37 {
38  uint8_t frame_info;
39  uint8_t address;
40 
41  // check if there is actually a message in the buffers
42  if (!sja1000_check_message())
43  return FALSE;
44 
45  frame_info = sja1000_read(16);
46  msg->length = frame_info & 0x0f;
47 
48  if (frame_info & (1<<FF))
49  {
50  // read extended identifier
51  msg->flags.extended = 1;
52 
53  uint32_t tmp;
54  uint8_t *ptr = (uint8_t *) &tmp;
55 
56  *ptr = sja1000_read(20);
57  *(ptr + 1) = sja1000_read(19);
58  *(ptr + 2) = sja1000_read(18);
59  *(ptr + 3) = sja1000_read(17);
60 
61  msg->id = tmp >> 3;
62 
63  /* equivalent to:
64  msg->id = sja1000_read(20) >> 3;
65  msg->id |= (uint16_t) sja1000_read(19) << 5;
66  msg->id |= (uint32_t) sja1000_read(18) << 13;
67  msg->id |= (uint32_t) sja1000_read(17) << 21;*/
68 
69  address = 21;
70  }
71  else
72  {
73  // read standard identifier
74  msg->flags.extended = 0;
75 
76  uint32_t *ptr32 = &msg->id; // used to supress a compiler warning
77  uint16_t *ptr = (uint16_t *) ptr32;
78 
79  *(ptr + 1) = 0;
80 
81  *ptr = sja1000_read(18) >> 5;
82  *ptr |= sja1000_read(17) << 3;
83 
84  address = 19;
85  }
86 
87 
88  if (frame_info & (1<<RTR)) {
89  msg->flags.rtr = 1;
90  }
91  else {
92  msg->flags.rtr = 0;
93 
94  // read data
95  for (uint8_t i = 0; i < msg->length; i++) {
96  msg->data[i] = sja1000_read(address + i);
97  }
98  }
99 
100  // release buffer
101  sja1000_write(CMR, (1<<RRB));
102 
104 
105  return TRUE;
106 }
107 
108 #endif // SUPPORT_FOR_SJA1000__
TRUE
@ TRUE
Definition: lpc_types.h:50
can_t::length
uint8_t length
Anzahl der Datenbytes.
Definition: can.h:192
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
FF
#define FF
Bitdefinition von RX_INFO und TX_INFO.
Definition: sja1000_defs.h:241
can_t::flags
struct can_t::@136 flags
RRB
#define RRB
Definition: sja1000_defs.h:118
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
CAN_INDICATE_RX_TRAFFIC_FUNCTION
#define CAN_INDICATE_RX_TRAFFIC_FUNCTION
Definition: can_private.h:137
sja1000_private.h
SJA1000 Interface.


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