libs
platform_specific_components
avr
libcanard
avr-can-lib
src
mcp2515_read_id.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: mcp2515_read_id.c 7224 2009-01-25 20:19:32Z fabian $
28
*/
29
// ----------------------------------------------------------------------------
30
31
#include "
mcp2515_private.h
"
32
#ifdef SUPPORT_FOR_MCP2515__
33
34
// ----------------------------------------------------------------------------
35
// Liest eine ID aus dem Registern des MCP2515 (siehe auch mcp2515_write_id())
36
37
#if SUPPORT_EXTENDED_CANID
38
39
uint8_t
mcp2515_read_id(
uint32_t
*
id
)
40
{
41
uint8_t
first;
42
uint8_t
tmp;
43
44
first =
spi_putc
(0xff);
45
tmp =
spi_putc
(0xff);
46
47
if
(tmp & (1 <<
IDE
)) {
48
spi_start(0xff);
49
50
*((
uint16_t
*)
id
+ 1) = (
uint16_t
) first << 5;
51
*((
uint8_t
*)
id
+ 1) = spi_wait();
52
spi_start(0xff);
53
54
*((
uint8_t
*)
id
+ 2) |= (tmp >> 3) & 0x1C;
55
*((
uint8_t
*)
id
+ 2) |= tmp & 0x03;
56
57
*((
uint8_t
*)
id
) = spi_wait();
58
59
return
TRUE
;
60
}
61
else
{
62
spi_start(0xff);
63
64
*((
uint8_t
*)
id
+ 3) = 0;
65
*((
uint8_t
*)
id
+ 2) = 0;
66
67
*((
uint16_t
*)
id
) = (
uint16_t
) first << 3;
68
69
spi_wait();
70
spi_start(0xff);
71
72
*((
uint8_t
*)
id
) |= tmp >> 5;
73
74
spi_wait();
75
76
return
FALSE
;
77
}
78
}
79
80
#else
81
82
uint8_t
mcp2515_read_id(
uint16_t
*
id
)
83
{
84
uint8_t
first;
85
uint8_t
tmp;
86
87
first =
spi_putc
(0xff);
88
tmp =
spi_putc
(0xff);
89
90
if
(tmp & (1 <<
IDE
)) {
91
spi_putc
(0xff);
92
spi_putc
(0xff);
93
94
return
1;
// extended-frame
95
}
96
else
{
97
spi_start(0xff);
98
99
*
id
= (
uint16_t
) first << 3;
100
101
spi_wait();
102
spi_start(0xff);
103
104
*((
uint8_t
*)
id
) |= tmp >> 5;
105
106
spi_wait();
107
108
if
(tmp & (1 <<
SRR
))
109
return
2;
// RTR-frame
110
else
111
return
0;
// normal-frame
112
}
113
}
114
115
#endif // SUPPORT_EXTENDED_CANID
116
117
#endif // SUPPORT_FOR_MCP2515__
TRUE
@ TRUE
Definition:
lpc_types.h:50
uavcan::uint32_t
std::uint32_t uint32_t
Definition:
std.hpp:26
uavcan::uint16_t
std::uint16_t uint16_t
Definition:
std.hpp:25
IDE
#define IDE
Definition:
mcp2515_defs.h:296
uavcan::uint8_t
std::uint8_t uint8_t
Definition:
std.hpp:24
FALSE
@ FALSE
Definition:
lpc_types.h:50
mcp2515_private.h
spi_putc
uint8_t spi_putc(uint8_t data)
Write/read one byte of the SPI interface.
SRR
#define SRR
Bitdefinition von RXBnSIDL (n = 0, 1)
Definition:
mcp2515_defs.h:295
uavcan_communicator
Author(s):
autogenerated on Fri Dec 13 2024 03:10:02