spi.h
Go to the documentation of this file.
1 // coding: utf-8
2 // ----------------------------------------------------------------------------
3 /*
4  * Copyright (c) 2007 Fabian Greif, Roboterclub Aachen e.V.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  *
28  * $Id: spi.h 6910 2008-11-30 21:13:14Z fabian $
29  */
30 // ----------------------------------------------------------------------------
31 
32 #ifndef SPI_H
33 #define SPI_H
34 
35 #include "can_private.h"
36 
37 // ----------------------------------------------------------------------------
38 // load some default values
39 
40 #ifndef SPI_PRESCALER
41  #define SPI_PRESCALER 8
42 #endif
43 
44 // ----------------------------------------------------------------------------
48 extern void mcp2515_spi_init(void);
49 
50 // ----------------------------------------------------------------------------
57 extern uint8_t spi_putc(uint8_t data);
58 
59 // ----------------------------------------------------------------------------
60 #ifdef USE_SOFTWARE_SPI
61 
62 static uint8_t usi_interface_spi_temp;
63 
64 extern __attribute__ ((gnu_inline)) inline void spi_start(uint8_t data) {
65  usi_interface_spi_temp = spi_putc(data);
66 }
67 
68 extern __attribute__ ((gnu_inline)) inline uint8_t spi_wait(void) {
69  return usi_interface_spi_temp;
70 }
71 
72 #else
73 
74 extern __attribute__ ((gnu_inline)) inline void spi_start(uint8_t data) {
75  SPDR = data;
76 }
77 
78 extern __attribute__ ((gnu_inline)) inline uint8_t spi_wait(void) {
79  // warten bis der vorherige Werte geschrieben wurde
80  while(!(SPSR & (1<<SPIF)))
81  ;
82 
83  return SPDR;
84 }
85 
86 #endif
87 
88 #endif // SPI_H
mcp2515_spi_init
void mcp2515_spi_init(void)
Initialize SPI interface.
uavcan::uint8_t
std::uint8_t uint8_t
Definition: std.hpp:24
can_private.h
__attribute__
__attribute__((gnu_inline)) inline void spi_start(uint8_t data)
Definition: spi.h:74
spi_putc
uint8_t spi_putc(uint8_t data)
Write/read one byte of the SPI interface.


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