fpga.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* sd2snes - SD card based universal cartridge for the SNES
  2. Copyright (C) 2009-2010 Maximilian Rehkopf <otakon@gmx.net>
  3. AVR firmware portion
  4. Inspired by and based on code from sd2iec, written by Ingo Korb et al.
  5. See sdcard.c|h, config.h.
  6. FAT file system access based on code by ChaN, Jim Brain, Ingo Korb,
  7. see ff.c|h.
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; version 2 of the License only.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. fpga.h: FPGA (re)configuration
  19. */
  20. #ifndef FPGA_H
  21. #define FPGA_H
  22. #include <arm/NXP/LPC17xx/LPC17xx.h>
  23. #include "bits.h"
  24. void fpga_set_prog_b(uint8_t val);
  25. void fpga_set_cclk(uint8_t val);
  26. int fpga_get_initb(void);
  27. void fpga_init(void);
  28. void fpga_postinit(void);
  29. void fpga_pgm(uint8_t* filename);
  30. void fpga_rompgm(void);
  31. void set_mcu_ovr(uint8_t val);
  32. uint8_t SPI_OFFLOAD;
  33. #define CCLKREG LPC_GPIO0
  34. #define PROGBREG LPC_GPIO1
  35. #define INITBREG LPC_GPIO2
  36. #define DINREG LPC_GPIO2
  37. #define DONEREG LPC_GPIO0
  38. #define CCLKBIT (11)
  39. #define PROGBBIT (10)
  40. #define INITBBIT (9)
  41. #define DINBIT (8)
  42. #define DONEBIT (22)
  43. #define FPGA_TEST_TOKEN (0xa5)
  44. // some macros for bulk transfers (faster)
  45. #define FPGA_SEND_BYTE_SERIAL(data) do {SET_FPGA_DIN(data>>7); CCLK();\
  46. SET_FPGA_DIN(data>>6); CCLK(); SET_FPGA_DIN(data>>5); CCLK();\
  47. SET_FPGA_DIN(data>>4); CCLK(); SET_FPGA_DIN(data>>3); CCLK();\
  48. SET_FPGA_DIN(data>>2); CCLK(); SET_FPGA_DIN(data>>1); CCLK();\
  49. SET_FPGA_DIN(data); CCLK();} while (0)
  50. #define SET_CCLK() do {BITBAND(LPC_GPIO0->FIOSET, 11) = 1;} while (0)
  51. #define CLR_CCLK() do {BITBAND(LPC_GPIO0->FIOCLR, 11) = 1;} while (0)
  52. #define CCLK() do {SET_CCLK(); CLR_CCLK();} while (0)
  53. #define SET_MCU_OVR() do {BITBAND(LPC_GPIO2->FIOSET, 8) = 1;} while (0)
  54. #define CLR_MCU_OVR() do {BITBAND(LPC_GPIO2->FIOCLR, 8) = 1;} while (0)
  55. #define SET_FPGA_DIN(data) do {LPC_GPIO2->FIOPIN1 = data;} while (0)
  56. #endif