[Zrouter-src-freebsd] ZRouter.org: push to FreeBSD HEAD tree
zrouter-src-freebsd at zrouter.org
zrouter-src-freebsd at zrouter.org
Wed Feb 1 10:57:11 UTC 2012
details: http://zrouter.org/hg/FreeBSD/head//rev/b0ba90c55594
changeset: 331:b0ba90c55594
user: ray at terran.dlink.ua
date: Wed Feb 01 12:55:36 2012 +0200
description:
Update gpiospi to current SPI state (tx and rx sizes can be different)
diffstat:
head/sys/dev/gpio/gpiospi.c | 35 +++++++++++++++++++++++++----------
1 files changed, 25 insertions(+), 10 deletions(-)
diffs (63 lines):
diff -r 200490b02f30 -r b0ba90c55594 head/sys/dev/gpio/gpiospi.c
--- a/head/sys/dev/gpio/gpiospi.c Wed Feb 01 12:53:42 2012 +0200
+++ b/head/sys/dev/gpio/gpiospi.c Wed Feb 01 12:55:36 2012 +0200
@@ -307,17 +307,12 @@
gpio_spi_transfer(device_t dev, device_t child, struct spi_command *cmd)
{
struct gpio_spi_softc *sc;
- uint8_t *buf_in, *buf_out;
+ uint8_t *buf_in, *buf_out, byte;
struct spibus_ivar *devi = SPIBUS_IVAR(child);
int i;
sc = device_get_softc(dev);
- KASSERT(cmd->tx_cmd_sz == cmd->rx_cmd_sz,
- ("TX/RX command sizes should be equal"));
- KASSERT(cmd->tx_data_sz == cmd->rx_data_sz,
- ("TX/RX data sizes should be equal"));
-
GPIOBUS_LOCK_BUS(sc->sc_busdev);
GPIOBUS_ACQUIRE_BUS(sc->sc_busdev, sc->sc_dev);
@@ -338,16 +333,36 @@
buf_out = (uint8_t *)cmd->tx_cmd;
buf_in = (uint8_t *)cmd->rx_cmd;
- for (i = 0; i < cmd->tx_cmd_sz; i++)
- buf_in[i] = gpio_spi_txrx(sc, devi->cs, devi->mode, buf_out[i]);
+ for (i = 0; i < MAX(cmd->tx_cmd_sz, cmd->rx_cmd_sz); i++) {
+ if (cmd->tx_cmd_sz > i)
+ byte = buf_out[i];
+ else
+ byte = 0;
+
+ byte = gpio_spi_txrx(sc, devi->cs, devi->mode, byte);
+
+ if (cmd->rx_cmd_sz > i)
+ buf_in[i] = byte;
+ }
/*
* Receive/transmit data (depends on command)
*/
buf_out = (uint8_t *)cmd->tx_data;
buf_in = (uint8_t *)cmd->rx_data;
- for (i = 0; i < cmd->tx_data_sz; i++)
- buf_in[i] = gpio_spi_txrx(sc, devi->cs, devi->mode, buf_out[i]);
+
+ for (i = 0; i < MAX(cmd->tx_data_sz, cmd->rx_data_sz); i++) {
+ if (cmd->tx_data_sz > i)
+ byte = buf_out[i];
+ else
+ byte = 0;
+
+ byte = gpio_spi_txrx(sc, devi->cs, devi->mode, byte);
+
+ if (cmd->rx_data_sz > i)
+ buf_in[i] = byte;
+ }
+
/* Return pins to mode default */
if ((devi->mode == MODE_CPOL) || (devi->mode == MODE_CPHA)) {
More information about the Zrouter-src-freebsd
mailing list