forked from mrehkopf/sd2snes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfpga_spi.c
99 lines (82 loc) · 2.51 KB
/
fpga_spi.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* sd2snes - SD card based universal cartridge for the SNES
Copyright (C) 2009-2010 Maximilian Rehkopf <[email protected]>
AVR firmware portion
Inspired by and based on code from sd2iec, written by Ingo Korb et al.
See sdcard.c|h, config.h.
FAT file system access based on code by ChaN, Jim Brain, Ingo Korb,
see ff.c|h.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License only.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
fpga_spi.h: functions for SPI ctrl, SRAM interfacing and feature configuration
*/
/*
SPI commands
cmd param function
=============================================
00 bb[hh[ll]] set address to 0xbb0000, 0xbbhh00, or 0xbbhhll
10 bbhhll set SNES input address mask to 0xbbhhll
20 bbhhll set SRAM address mask to 0xbbhhll
3m - set mapper to m
0=HiROM, 1=LoROM, 2=ExHiROM, 7=Menu
80 - read with increment
81 - read w/o increment
90 {xx}* write xx with increment
91 {xx}* write xx w/o increment
F0 - receive test token (to see if FPGA is alive)
*/
#include <avr/pgmspace.h>
#include <util/delay.h>
#include "avrcompat.h"
#include "fpga.h"
#include "config.h"
#include "uart.h"
#include "spi.h"
#include "fpga_spi.h"
void spi_fpga(void) {
SPI_SS_HIGH();
FPGA_SS_LOW();
}
void spi_sd(void) {
FPGA_SS_HIGH();
SPI_SS_LOW();
}
void spi_none(void) {
FPGA_SS_HIGH();
SPI_SS_HIGH();
}
void fpga_spi_init(void) {
DDRC = _BV(PC7);
FPGA_SS_HIGH();
}
void set_avr_addr(uint32_t address) {
spi_fpga();
spiTransferByte(0x00);
spiTransferByte((address>>16)&0xff);
spiTransferByte((address>>8)&0xff);
spiTransferByte((address)&0xff);
spi_none();
}
void set_saveram_mask(uint32_t mask) {
spi_fpga();
spiTransferByte(0x20);
spiTransferByte((mask>>16)&0xff);
spiTransferByte((mask>>8)&0xff);
spiTransferByte((mask)&0xff);
spi_none();
}
void set_rom_mask(uint32_t mask) {
spi_fpga();
spiTransferByte(0x10);
spiTransferByte((mask>>16)&0xff);
spiTransferByte((mask>>8)&0xff);
spiTransferByte((mask)&0xff);
spi_none();
}