| [4] | 1 | /* -*- 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 | #ifndef INCLUDED_SPI_H
|
|---|
| 24 | #define INCLUDED_SPI_H
|
|---|
| 25 |
|
|---|
| 26 | // FX2 is SPI bus master going to fpga
|
|---|
| 27 | #define SPI IOA
|
|---|
| 28 | #define SPI_OE OEA
|
|---|
| 29 | #define bmSPI_OE 0x8B // bits on PA
|
|---|
| 30 | #define VEN_SPI_EN 0x96 // vendor commands
|
|---|
| 31 | #define VEN_SPI_DIS 0x97
|
|---|
| 32 | #define VEN_SPI_RD 0x98
|
|---|
| 33 | #define VEN_SPI_WR 0x99
|
|---|
| 34 |
|
|---|
| 35 | #define bmSCLK bmBIT0 // sclk on port A
|
|---|
| 36 | #define bmSDO bmBIT1 // SPI MOSI
|
|---|
| 37 | #define bmSDI bmBIT3 // SPI MISO
|
|---|
| 38 | #define bmSS bmBIT7 // Slave select
|
|---|
| 39 | #define SPI_FMT_HDR_MASK (3 << 5)
|
|---|
| 40 | #define SPI_FMT_HDR_0 (0 << 5) // 0 header bytes
|
|---|
| 41 | #define SPI_FMT_HDR_1 (1 << 5) // 1 header byte
|
|---|
| 42 | #define SPI_FMT_HDR_2 (2 << 5) // 2 header bytes
|
|---|
| 43 |
|
|---|
| 44 | sbit at 0x80+0 bitS_CLK; // 0x80 is the bit address of IOA
|
|---|
| 45 | sbit at 0x80+1 bitS_OUT; // out from FX2 point of view
|
|---|
| 46 | sbit at 0x80+3 bitS_IN; // in from FX2 point of view
|
|---|
| 47 |
|
|---|
| 48 | void init_spi (void); // one time call to init
|
|---|
| 49 |
|
|---|
| 50 | // returns non-zero if successful, else 0
|
|---|
| 51 | unsigned char
|
|---|
| 52 | spi_read (unsigned char header_hi, unsigned char header_lo,
|
|---|
| 53 | unsigned char enables, unsigned char format,
|
|---|
| 54 | xdata unsigned char *buf, unsigned char len);
|
|---|
| 55 |
|
|---|
| 56 | // returns non-zero if successful, else 0
|
|---|
| 57 | unsigned char
|
|---|
| 58 | spi_write (unsigned char header_hi, unsigned char header_lo,
|
|---|
| 59 | unsigned char enables, unsigned char format,
|
|---|
| 60 | const xdata unsigned char *buf, unsigned char len);
|
|---|
| 61 |
|
|---|
| 62 | void
|
|---|
| 63 | spi_write_byte_msb (unsigned char v);
|
|---|
| 64 |
|
|---|
| 65 | void
|
|---|
| 66 | spi_write_bytes_msb (const xdata unsigned char *buf, unsigned char len);
|
|---|
| 67 |
|
|---|
| 68 | unsigned char
|
|---|
| 69 | spi_read_byte_msb (void) _naked;
|
|---|
| 70 |
|
|---|
| 71 | void
|
|---|
| 72 | spi_read_bytes_msb (xdata unsigned char *buf, unsigned char len);
|
|---|
| 73 |
|
|---|
| 74 | #endif /* INCLUDED_SPI_H */
|
|---|