1 |
9 |
nussgipfel |
/* -*- c++ -*- */
|
2 |
|
|
/*
|
3 |
|
|
* Copyright 2004 Free Software Foundation, Inc.
|
4 |
|
|
*
|
5 |
|
|
* This file is part of GNU Radio
|
6 |
|
|
*
|
7 |
|
|
* GNU Radio is free software; you can redistribute it and/or modify
|
8 |
|
|
* it under the terms of the GNU General Public License as published by
|
9 |
|
|
* the Free Software Foundation; either version 3, or (at your option)
|
10 |
|
|
* any later version.
|
11 |
|
|
*
|
12 |
|
|
* GNU Radio is distributed in the hope that it will be useful,
|
13 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
|
|
* GNU General Public License for more details.
|
16 |
|
|
*
|
17 |
|
|
* You should have received a copy of the GNU General Public License
|
18 |
|
|
* along with GNU Radio; see the file COPYING. If not, write to
|
19 |
|
|
* the Free Software Foundation, Inc., 51 Franklin Street,
|
20 |
|
|
* Boston, MA 02110-1301, USA.
|
21 |
|
|
*/
|
22 |
|
|
|
23 |
|
|
/************************************************************/
|
24 |
|
|
/** \file spi.h
|
25 |
|
|
*************************************************************
|
26 |
|
|
* \brief SPI bus functions
|
27 |
|
|
*
|
28 |
|
|
* \details Library to communicate with SPI devices
|
29 |
|
|
*
|
30 |
32 |
nussgipfel |
* \author GNU Radio team
|
31 |
9 |
nussgipfel |
*
|
32 |
|
|
* \note to use this SPI library you have to define the following
|
33 |
|
|
* keywords in your pinmapping header file. For GECKO3COM
|
34 |
|
|
* this is the "gecko3com_regs.h" file. \n
|
35 |
|
|
* \li SPI_PORT, SPI signals are connected to this port
|
36 |
|
|
* \li SPI_OE, SPI port direction register
|
37 |
|
|
* \li bmSPI_CLK, bitmask for SPI serial clock pin
|
38 |
|
|
* \li bmSPI_MOSI, bitmask for SPI MOSI pin, Master Out, Slave In
|
39 |
|
|
* \li bmSPI_MISO, bitmask for SPI MISO pin, Master In, Slave Out
|
40 |
|
|
* \li bitSPI_CLK, bitadress of the SPI CLK pin
|
41 |
|
|
* \li bitSPI_MOSI, bitadress of the SPI MOSI pin
|
42 |
|
|
* \li bitSPI_MISO, bitadress of the SPI MISO pin
|
43 |
|
|
* \li SPI_CS_PORT, SPI chip select signals are connected to this port
|
44 |
|
|
* \li bmSPI_CS_FLASH, bitmask to enable the SPI Flash
|
45 |
|
|
* \li bmSPI_CS_MASK, bit mask to select the SPI chip select pins
|
46 |
|
|
*/
|
47 |
|
|
|
48 |
|
|
#ifndef INCLUDED_SPI_H
|
49 |
|
|
#define INCLUDED_SPI_H
|
50 |
|
|
|
51 |
|
|
#include "gecko3com_regs.h"
|
52 |
|
|
|
53 |
|
|
|
54 |
|
|
/*
|
55 |
|
|
* SPI_FMT_* goes in wIndexL
|
56 |
|
|
*/
|
57 |
32 |
nussgipfel |
#define bmSPI_FORMAT 0x80 /**< bitmask to work on the format */
|
58 |
9 |
nussgipfel |
# define bmSPI_FORMAT_LSB 0x80 /**< least signficant bit first */
|
59 |
|
|
# define bmSPI_FORMAT_MSB 0x00 /**< most significant bit first */
|
60 |
32 |
nussgipfel |
#define bmSPI_HEADER 0x60 /**< bits to select the header bytes */
|
61 |
9 |
nussgipfel |
# define bmSPI_HEADER_0 0x00 /**< 0 header bytes */
|
62 |
|
|
# define bmSPI_HEADER_1 0x20 /**< 1 header byte */
|
63 |
|
|
# define bmSPI_HEADER_2 0x40 /**< 2 header bytes */
|
64 |
|
|
|
65 |
|
|
|
66 |
|
|
/** one time call to init SPI subsystem */
|
67 |
|
|
void init_spi (void);
|
68 |
|
|
|
69 |
|
|
/** \brief basic function to read data from the SPI bus
|
70 |
32 |
nussgipfel |
* \param[in] header_hi high byte of the header to send
|
71 |
|
|
* \param[in] header_lo low byte of the header to send
|
72 |
|
|
* \param[in] enables bitmask with the correct device selected
|
73 |
|
|
* \param[in] format bitmask byte to select byte order
|
74 |
|
|
* and number of header bytes
|
75 |
|
|
* \param[out] *buf pointer to a buffer to write the received data in it
|
76 |
|
|
* \param[in] len number of bytes to be read from bus
|
77 |
9 |
nussgipfel |
*
|
78 |
|
|
* \return returns non-zero if successful, else 0 */
|
79 |
|
|
unsigned char
|
80 |
|
|
spi_read (unsigned char header_hi, unsigned char header_lo,
|
81 |
|
|
unsigned char enables, unsigned char format,
|
82 |
|
|
xdata unsigned char *buf, unsigned char len);
|
83 |
|
|
|
84 |
|
|
/** \brief basic function to write data to the SPI bus
|
85 |
32 |
nussgipfel |
* \param[in] header_hi high byte of the header to send
|
86 |
|
|
* \param[in] header_lo low byte of the header to send
|
87 |
|
|
* \param[in] enables bitmask with the correct device selected
|
88 |
|
|
* \param[in] format bitmask byte to select byte order
|
89 |
9 |
nussgipfel |
* and number of header bytes
|
90 |
32 |
nussgipfel |
* \param[in] *buf pointer to a buffer which holds the data to send
|
91 |
|
|
* \param[in] len number of bytes to be written to the bus
|
92 |
9 |
nussgipfel |
*
|
93 |
|
|
* \return returns non-zero if successful, else 0 */
|
94 |
|
|
unsigned char
|
95 |
|
|
spi_write (unsigned char header_hi, unsigned char header_lo,
|
96 |
|
|
unsigned char enables, unsigned char format,
|
97 |
|
|
const xdata unsigned char *buf, unsigned char len);
|
98 |
|
|
|
99 |
|
|
|
100 |
|
|
#endif /* INCLUDED_SPI_H */
|