diff options
author | Thomas Tsou <ttsou@vt.edu> | 2010-08-12 16:22:04 -0700 |
---|---|---|
committer | Thomas Tsou <ttsou@vt.edu> | 2010-08-13 17:54:01 -0700 |
commit | b3a092055abacb99b3e9d71edd26c2dd2059dd7f (patch) | |
tree | 6c3466c342525e21de69008ebb6b2d9e2eb87ffd /firmware/fx2/src/usrp1/spi.c | |
parent | 70eae1d242a9530cab4efa927bd1331b099fdd00 (diff) | |
download | uhd-b3a092055abacb99b3e9d71edd26c2dd2059dd7f.tar.gz uhd-b3a092055abacb99b3e9d71edd26c2dd2059dd7f.tar.bz2 uhd-b3a092055abacb99b3e9d71edd26c2dd2059dd7f.zip |
usrp1: Add SPI transaction command to FX2 firmware
The existing SPI read command is set for half-duplex 8-bit
or 16-bit writes followed by an equivalent sized read.
This patch adds a new command, VRQ_SPI_TRANSACT, which
performs a full-duplex transaction up to 4-bytes. Since the
data buffer of the USB control transfer is not available
for outbound data on IN requests, the 4 bytes of write data
are sent through the request parameters. Enables are sent
in the previsouly unused high byte of the length parameter.
The USB field mappings are shown below. Only rising edge
and MSB operation is supported.
Field (8-bit) Description
===== =====
bmRequestType 0x80 (USB Device IN request)
bRequest 0x83 (VRQ_SPI_TRANSACT)
wValueH OUT data(0)
wValueL OUT data(1)
wIndexH OUT data(2)
wIndexL OUT data(3)
wLengthH SPI enables
wLengthL Number of bytes to transfer (1-4)
EP0BUF IN data
Diffstat (limited to 'firmware/fx2/src/usrp1/spi.c')
-rw-r--r-- | firmware/fx2/src/usrp1/spi.c | 95 |
1 files changed, 93 insertions, 2 deletions
diff --git a/firmware/fx2/src/usrp1/spi.c b/firmware/fx2/src/usrp1/spi.c index f5803c55b..0aaffea5d 100644 --- a/firmware/fx2/src/usrp1/spi.c +++ b/firmware/fx2/src/usrp1/spi.c @@ -97,13 +97,18 @@ count_bits8 (unsigned char v) static void write_byte_msb (unsigned char v); +unsigned char +transact_byte_msb (unsigned char v); + static void write_bytes_msb (const xdata unsigned char *buf, unsigned char len); static void read_bytes_msb (xdata unsigned char *buf, unsigned char len); - +static void +transact_bytes_msb (xdata unsigned char *buf, unsigned char len); + // returns non-zero if successful, else 0 unsigned char spi_read (unsigned char header_hi, unsigned char header_lo, @@ -214,7 +219,93 @@ spi_write (unsigned char header_hi, unsigned char header_lo, return 1; // success } -// ---------------------------------------------------------------- +unsigned char +spi_transact (unsigned char data0, unsigned char data1, + unsigned char data2, unsigned char data3, + unsigned char enables, xdata unsigned char *buf, + unsigned char len) +{ + if (count_bits8 (enables) > 1) + return 0; // error, too many enables set + + if (len > 4) + return 0; + + setup_enables (enables); + + buf[0] = data0; + buf[1] = data1; + buf[2] = data2; + buf[3] = data3; + + if (len != 0) + transact_bytes_msb(buf, len); + + disable_all (); + return 1; // success +} + +static unsigned char +transact_byte_msb (unsigned char v) +{ + v = (v << 1) | (v >> 7); // rotate left (MSB into bottom bit) + bitS_OUT = v & 0x1; + bitS_CLK = 1; + v |= bitS_IN; // read into bottom bit + bitS_CLK = 0; + + v = (v << 1) | (v >> 7); + bitS_OUT = v & 0x1; + bitS_CLK = 1; + v |= bitS_IN; + bitS_CLK = 0; + + v = (v << 1) | (v >> 7); + bitS_OUT = v & 0x1; + bitS_CLK = 1; + v |= bitS_IN; + bitS_CLK = 0; + + v = (v << 1) | (v >> 7); + bitS_OUT = v & 0x1; + bitS_CLK = 1; + v |= bitS_IN; + bitS_CLK = 0; + + v = (v << 1) | (v >> 7); + bitS_OUT = v & 0x1; + bitS_CLK = 1; + v |= bitS_IN; + bitS_CLK = 0; + + v = (v << 1) | (v >> 7); + bitS_OUT = v & 0x1; + bitS_CLK = 1; + v |= bitS_IN; + bitS_CLK = 0; + + v = (v << 1) | (v >> 7); + bitS_OUT = v & 0x1; + bitS_CLK = 1; + v |= bitS_IN; + bitS_CLK = 0; + + v = (v << 1) | (v >> 7); + bitS_OUT = v & 0x1; + bitS_CLK = 1; + v |= bitS_IN; + bitS_CLK = 0; + + return v; +} + +static void +transact_bytes_msb (xdata unsigned char *buf, unsigned char len) +{ + while (len-- != 0){ + *buf++ = transact_byte_msb (*buf); + } +} static void write_byte_msb (unsigned char v) |