mcp2515_private.h
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_private.h 6910 2008-11-30 21:13:14Z fabian $
28  */
29 // ----------------------------------------------------------------------------
30 
31 #ifndef MCP2515_PRIVATE_H
32 #define MCP2515_PRIVATE_H
33 
34 // ----------------------------------------------------------------------------
43 // ----------------------------------------------------------------------------
44 
45 #include <avr/io.h>
46 #include <avr/pgmspace.h>
47 #include <inttypes.h>
48 #include <stdbool.h>
49 
50 #include "can.h"
51 #include "utils.h"
52 
53 #include "can_private.h"
54 #include "spi.h"
55 
56 // ----------------------------------------------------------------------------
57 
58 #if (BUILD_FOR_MCP2515 == 1)
59  #if defined(__AVR_ATmega16__) || defined(__AVR_ATmega32__) || defined(__AVR_ATmega644__)
60  #define P_MOSI B,5
61  #define P_MISO B,6
62  #define P_SCK B,7
63  #define SUPPORT_FOR_MCP2515__
64  #elif defined(__AVR_AT90USB82__) || defined(__AVR_AT90USB162__)
65  #define P_MOSI B,2
66  #define P_MISO B,3
67  #define P_SCK B,1
68  #define SUPPORT_FOR_MCP2515__
69  #elif defined(__AVR_ATmega8__) || defined(__AVR_ATmega48__) || \
70  defined(__AVR_ATmega88__) || defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
71  #define P_MOSI B,3
72  #define P_MISO B,4
73  #define P_SCK B,5
74  #define SUPPORT_FOR_MCP2515__
75  #elif defined(__AVR_ATmega128__)
76  #define P_MOSI B,2
77  #define P_MISO B,3
78  #define P_SCK B,1
79  #define SUPPORT_FOR_MCP2515__
80  #elif defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
81  #define P_MOSI B,0
82  #define P_MISO B,1
83  #define P_SCK B,2
84 
85  #define USE_SOFTWARE_SPI 1
86  #define SUPPORT_FOR_MCP2515__
87  #else
88  #error choosen AVR-type is not supported yet!
89  #endif
90 #endif
91 
92 
93 #ifdef SUPPORT_FOR_MCP2515__
94 
95 // ----------------------------------------------------------------------------
96 // load some default values
97 
98 #ifndef MCP2515_CLKOUT_PRESCALER
99  #define MCP2515_CLKOUT_PRESCALER 0
100 #endif
101 #ifndef MCP2515_INTERRUPTS
102  #define MCP2515_INTERRUPTS (1<<RX1IE)|(1<<RX0IE)
103 #endif
104 
105 // ----------------------------------------------------------------------------
106 // TODO: this file is imcompatible with the at90can
107 #include "mcp2515_defs.h"
108 
109 #ifndef MCP2515_CS
110  #error MCP2515_CS ist nicht definiert!
111 #endif
112 
113 #if defined(MCP2515_RX0BF) && !defined(MCP2515_RX1BF)
114  #warning only MCP2515_RX0BF but not MCP2515_RX1BF defined!
115 #elif !defined(MCP2515_RX0BF) && defined(MCP2515_RX1BF)
116  #warning only MCP2515_RX1BF but not MCP2515_RX0BF defined!
117 #elif defined(MCP2515_RX0BF) && defined(MCP2515_RX1BF)
118  #define RXnBF_FUNKTION
119 #endif
120 
121 // -------------------------------------------------------------------------
125 extern void mcp2515_write_register( uint8_t adress, uint8_t data );
126 
127 // -------------------------------------------------------------------------
131 extern uint8_t mcp2515_read_register(uint8_t adress);
132 
133 extern uint8_t mcp2515_read_status(uint8_t type);
134 
135 // -------------------------------------------------------------------------
145 extern void mcp2515_bit_modify(uint8_t adress, uint8_t mask, uint8_t data);
146 
147 // -------------------------------------------------------------------------
148 extern __attribute__ ((gnu_inline)) inline void mcp2515_change_operation_mode(uint8_t mode)
149 {
150  mcp2515_bit_modify(CANCTRL, 0xe0, mode);
151  while ((mcp2515_read_register(CANSTAT) & 0xe0) != (mode & 0xe0))
152  ;
153 }
154 
155 // -------------------------------------------------------------------------
159 #if SUPPORT_EXTENDED_CANID
160 
161 extern void mcp2515_write_id( const uint32_t *id, uint8_t extended );
162 
163 extern uint8_t mcp2515_read_id( uint32_t *id );
164 
165 #else
166 
167 extern void mcp2515_write_id( const uint16_t *id );
168 
169 extern uint8_t mcp2515_read_id( uint16_t *id );
170 
171 #endif // USE_EXTENDED_CANID
172 
173 #endif // SUPPORT_FOR_MCP2515__
174 
175 #endif // MCP2515_PRIVATE_H
uavcan::uint32_t
std::uint32_t uint32_t
Definition: std.hpp:26
spi.h
uavcan::uint16_t
std::uint16_t uint16_t
Definition: std.hpp:25
utils.h
uavcan::uint8_t
std::uint8_t uint8_t
Definition: std.hpp:24
can_private.h
CANSTAT
#define CANSTAT
Definition: mcp2515_defs.h:67
CANCTRL
#define CANCTRL
Definition: mcp2515_defs.h:68
mcp2515_defs.h
__attribute__
__attribute__((gnu_inline)) inline void spi_start(uint8_t data)
Definition: spi.h:74


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