- Timestamp:
- May 30, 2013, 5:16:33 PM (12 years ago)
- Location:
- trunk/softs/tsar_boot
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/softs/tsar_boot/include/spi.h
r388 r398 60 60 */ 61 61 inline volatile unsigned char spi_get_rx(struct spi_dev * spi, int index); 62 63 /** 64 * \param spi : initialized pointer to a SPI controller. 65 * \param buf : buffer to store data read 66 * \param count : byte count to read 67 * 68 * \return void 69 * 70 * \brief get a data block from the SPI controller using 128bits 71 * reads if possible 72 */ 73 void spi_get_data(struct spi_dev * spi, void *buf, unsigned int count); 62 74 63 75 /** -
trunk/softs/tsar_boot/src/sdcard.c
r388 r398 228 228 _sdcard_wait_data_block(sdcard); 229 229 230 for ( i = 0; i < count; i++ ) 231 { 232 *((char *) buf + i) = _sdcard_receive_char(sdcard); 233 } 230 spi_get_data(sdcard->spi, buf, count); 234 231 235 232 /* … … 237 234 * at the end of the data block) 238 235 */ 236 i = count; 239 237 while( i++ < (sdcard->block_length + 2) ) _sdcard_receive_char(sdcard); 240 238 -
trunk/softs/tsar_boot/src/spi.c
r388 r398 5 5 */ 6 6 #include <spi.h> 7 8 /** 9 * \param x: input value 10 * 11 * \return byte-swapped value 12 * 13 * \brief byte-swap a 32bit word 14 */ 15 static unsigned int bswap32(unsigned int x) 16 { 17 unsigned int y; 18 y = (x & 0x000000ff) << 24; 19 y |= (x & 0x0000ff00) << 8; 20 y |= (x & 0x00ff0000) >> 8; 21 y |= (x & 0xff000000) >> 24; 22 return y; 23 } 7 24 8 25 /** … … 67 84 } 68 85 86 void spi_get_data(struct spi_dev * spi, void *buf, unsigned int count) 87 { 88 unsigned int *data = buf; 89 unsigned char *data8; 90 unsigned int spi_ctrl0, spi_ctrl; 91 int i; 92 93 _spi_wait_if_busy(spi); 94 /* switch to 128 bits words */ 95 spi_ctrl0 = ioread32(&spi->ctrl); 96 spi_ctrl = (spi_ctrl0 & ~SPI_CTRL_CHAR_LEN_MASK) | 128; 97 iowrite32(&spi->ctrl, spi_ctrl); 98 99 /* read data */ 100 for (i = 0; i + 3 < count / 4; i += 4) { 101 iowrite32(&spi->rx_tx[0], 0xffffffff); 102 iowrite32(&spi->rx_tx[1], 0xffffffff); 103 iowrite32(&spi->rx_tx[2], 0xffffffff); 104 iowrite32(&spi->rx_tx[3], 0xffffffff); 105 iowrite32(&spi->ctrl, spi_ctrl | SPI_CTRL_GO_BSY); 106 _spi_wait_if_busy(spi); 107 *data = bswap32(ioread32(&spi->rx_tx[3])); 108 data++; 109 *data = bswap32(ioread32(&spi->rx_tx[2])); 110 data++; 111 *data = bswap32(ioread32(&spi->rx_tx[1])); 112 data++; 113 *data = bswap32(ioread32(&spi->rx_tx[0])); 114 data++; 115 } 116 /* switch back to original word size */ 117 iowrite32(&spi->ctrl, spi_ctrl0); 118 /* read missing bits */ 119 data8 = (void *)data; 120 i = i * 4; 121 for (; i < count; i++) { 122 iowrite32(&spi->rx_tx[0], 0xffffffff); 123 iowrite32(&spi->ctrl, spi_ctrl0 | SPI_CTRL_GO_BSY); 124 _spi_wait_if_busy(spi); 125 *data8 = spi_get_rx(spi, 0); 126 data8++; 127 } 128 return; 129 } 130 69 131 void spi_ss_assert(struct spi_dev * spi, int index) 70 132 {
Note: See TracChangeset
for help on using the changeset viewer.