2 * Copyright 2007,2008 Free Software Foundation, Inc.
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include "memory_map.h"
25 * f_sclk = f_wb / ((div + 1) * 2)
27 spi_regs->div = 1; // 0 = Div by 2 (25 MHz); 1 = Div-by-4 (12.5 MHz)
33 while (spi_regs->ctrl & SPI_CTRL_GO_BSY)
38 spi_transact(bool readback, int slave, uint32_t data, int length, uint32_t flags)
40 flags &= (SPI_CTRL_TXNEG | SPI_CTRL_RXNEG);
41 int ctrl = SPI_CTRL_ASS | (SPI_CTRL_CHAR_LEN_MASK & length) | flags;
45 // Tell it which SPI slave device to access
46 spi_regs->ss = slave & 0xff;
49 spi_regs->txrx0 = data;
51 // Run it -- write once and rewrite with GO set
52 spi_regs->ctrl = ctrl;
53 spi_regs->ctrl = ctrl | SPI_CTRL_GO_BSY;
57 return spi_regs->txrx0;