spi.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* sd2iec - SD/MMC to Commodore serial bus interface/controller
  2. Copyright (C) 2007-2010 Ingo Korb <ingo@akana.de>
  3. Inspiration and low-level SD/MMC access based on code from MMC2IEC
  4. by Lars Pontoppidan et al., see sdcard.c|h and config.h.
  5. FAT filesystem access based on code from ChaN and Jim Brain, see ff.c|h.
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; version 2 of the License only.
  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.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. spi.h: Definitions for the low-level SPI routines
  17. Based on original code by Lars Pontoppidan et al., see spi.c
  18. for full copyright details.
  19. */
  20. #ifndef SPI_H
  21. #define SPI_H
  22. #define SSP_TFE 0 // Transmit FIFO empty
  23. #define SSP_TNF 1 // Transmit FIFO not full
  24. #define SSP_RNE 2 // Receive FIFO not empty
  25. #define SSP_RFF 3 // Receive FIFO full
  26. #define SSP_BSY 4 // Busy
  27. /* Low speed 400kHz for init, fast speed <=20MHz (MMC limit) */
  28. typedef enum { SPI_SPEED_FAST, SPI_SPEED_SLOW, SPI_SPEED_FPGA_FAST, SPI_SPEED_FPGA_SLOW } spi_speed_t;
  29. /* Pre-Initialize SPI interface (PCLK divider before PLL setup) */
  30. void spi_preinit( void );
  31. /* Initialize SPI interface */
  32. void spi_init( void );
  33. /* Transmit a single byte */
  34. void spi_tx_byte( uint8_t data );
  35. /* Transmit a single byte and return received data */
  36. uint8_t spi_txrx_byte( uint8_t data );
  37. /* Transmit a data block */
  38. void spi_tx_block( const void *data, unsigned int length );
  39. /* Receive a single byte */
  40. uint8_t spi_rx_byte( void );
  41. /* Receive a data block */
  42. void spi_rx_block( void *data, unsigned int length );
  43. /* wait for SPI TX FIFO to become empty */
  44. void spi_tx_sync( void );
  45. #endif