libs
platform_specific_components
avr
libcanard
avr-can-lib
src
sja1000_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$
28
*/
29
// ----------------------------------------------------------------------------
30
31
#ifndef SJA1000_PRIVATE_H
32
#define SJA1000_PRIVATE_H
33
34
// ----------------------------------------------------------------------------
44
// ----------------------------------------------------------------------------
45
46
#include <avr/io.h>
47
#include <avr/pgmspace.h>
48
49
#include "
can_private.h
"
50
51
#include "can.h"
52
#include "
utils.h
"
53
54
#if (BUILD_FOR_SJA1000 == 1)
55
// set some default-values
56
#ifndef SJA1000_MEMORY_MAPPED
57
#define SJA1000_MEMORY_MAPPED 0
58
#endif
59
60
// check if the settings are correct
61
#if SUPPORT_EXTENDED_CANID == 0
62
#error Extended CANIDs need to be supported!
63
#endif
64
65
#ifndef SJA1000_INT
66
#error SJA1000_INT is not defined!
67
#endif
68
69
#ifndef SJA1000_CLKOUT_PRESCALER
70
#define SJA1000_CLOCK_REGISTER (1<<CLKOFF)
71
#else
72
#if SJA1000_CLKOUT_PRESCALER == 1
73
#define SJA1000_CLOCK_REGISTER ((1<<CD2)|(1<<CD1)|(1<<CD0))
74
#elif SJA1000_CLKOUT_PRESCALER == 2
75
#define SJA1000_CLOCK_REGISTER 0
76
#elif SJA1000_CLKOUT_PRESCALER == 4
77
#define SJA1000_CLOCK_REGISTER (1<<CD0)
78
#elif SJA1000_CLKOUT_PRESCALER == 6
79
#define SJA1000_CLOCK_REGISTER (1<<CD1)
80
#elif SJA1000_CLKOUT_PRESCALER == 8
81
#define SJA1000_CLOCK_REGISTER ((1<<CD1)|(1<<CD0))
82
#elif SJA1000_CLKOUT_PRESCALER == 10
83
#define SJA1000_CLOCK_REGISTER (1<<CD2)
84
#elif SJA1000_CLKOUT_PRESCALER == 12
85
#define SJA1000_CLOCK_REGISTER ((1<<CD2)|(1<<CD0))
86
#elif SJA1000_CLKOUT_PRESCALER == 14
87
#define SJA1000_CLOCK_REGISTER ((1<<CD2)|(1<<CD1))
88
#endif
89
#endif
90
91
#if SJA1000_MEMORY_MAPPED
92
#ifndef SJA1000_BASE_ADDR
93
#error SJA1000_BASE_ADDR is not defined!
94
#endif
95
96
#define SUPPORT_FOR_SJA1000__ 1
97
98
// write to a register
99
static
inline
void
sja1000_write(
uint8_t
address,
uint8_t
data) {
100
(*((
uint8_t
*) (
SJA1000_BASE_ADDR
+ address))) = data;
101
}
102
103
// read a register
104
static
inline
uint8_t
sja1000_read(
uint8_t
address) {
105
return
(*((
uint8_t
*) (
SJA1000_BASE_ADDR
+ address)));
106
}
107
108
#else
109
#warning not tested yet!
110
111
#if !defined(SJA1000_WR) || !defined(SJA1000_RD) || \
112
!defined(SJA1000_CS) || !defined(SJA1000_DATA) || !defined(SJA1000_ALE)
113
#error in definition of SJA1000-pins (check SJA1000_WR, SJA1000_RD, SJA1000_CS, SJA1000_DATA and SJA1000_ALE)!
114
#endif
115
116
#define SUPPORT_FOR_SJA1000__ 1
117
extern
void
sja1000_write(
uint8_t
address,
uint8_t
data);
118
extern
uint8_t
sja1000_read(
uint8_t
address);
119
#endif // SJA1000_MEMORY_MAPPED
120
121
#ifdef SUPPORT_FOR_SJA1000__
122
#include "
sja1000_defs.h
"
123
#endif
124
#endif // SUPPORT_SJA1000
125
126
#endif // SJA1000_PRIVATE_H
sja1000_defs.h
utils.h
uavcan::uint8_t
std::uint8_t uint8_t
Definition:
std.hpp:24
can_private.h
SJA1000_BASE_ADDR
#define SJA1000_BASE_ADDR
Definition:
src/config.h:58
uavcan_communicator
Author(s):
autogenerated on Fri Dec 13 2024 03:10:03