include/mgba/internal/ds/slot1.h (view raw)
1/* Copyright (c) 2013-2017 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#ifndef DS_SLOT1_H
7#define DS_SLOT1_H
8
9#include <mgba-util/common.h>
10
11CXX_GUARD_START
12
13#include <mgba/core/log.h>
14#include <mgba/core/timing.h>
15
16mLOG_DECLARE_CATEGORY(DS_SLOT1);
17
18DECL_BITFIELD(DSSlot1AUXSPICNT, uint16_t);
19DECL_BITS(DSSlot1AUXSPICNT, Baud, 0, 2);
20DECL_BIT(DSSlot1AUXSPICNT, CSHold, 6);
21DECL_BIT(DSSlot1AUXSPICNT, Busy, 7);
22DECL_BIT(DSSlot1AUXSPICNT, SPIMode, 13);
23DECL_BIT(DSSlot1AUXSPICNT, DoIRQ, 14);
24DECL_BIT(DSSlot1AUXSPICNT, Enable, 15);
25
26DECL_BITFIELD(DSSlot1ROMCNT, uint32_t);
27DECL_BITS(DSSlot1ROMCNT, Delay, 0, 12);
28DECL_BITS(DSSlot1ROMCNT, Gap, 16, 5);
29DECL_BIT(DSSlot1ROMCNT, WordReady, 23);
30DECL_BITS(DSSlot1ROMCNT, BlockSize, 24, 3);
31DECL_BIT(DSSlot1ROMCNT, TransferRate, 27);
32DECL_BIT(DSSlot1ROMCNT, BlockBusy, 31);
33
34enum DSSavedataType {
35 DS_SAVEDATA_AUTODETECT = -1,
36 DS_SAVEDATA_FORCE_NONE = 0,
37 DS_SAVEDATA_EEPROM512 = 1,
38 DS_SAVEDATA_EEPROM = 2,
39 DS_SAVEDATA_FLASH = 3
40};
41
42struct VFile;
43struct DSSlot1 {
44 uint8_t command[8];
45 uint32_t address;
46 uint32_t transferSize;
47 uint32_t transferRemaining;
48 struct mTimingEvent transferEvent;
49 uint8_t readBuffer[4];
50
51 int dmaSource;
52
53 enum DSSavedataType savedataType;
54 struct mTimingEvent spiEvent;
55 bool spiHoldEnabled;
56 uint8_t spiCommand;
57 uint8_t statusReg;
58 int spiAddressingRemaining;
59 uint32_t spiAddress;
60 int spiAddressingBits;
61 uint32_t spiSize;
62
63 uint8_t* spiData;
64 struct VFile* spiVf;
65 struct VFile* spiRealVf;
66};
67
68struct DS;
69struct DSCommon;
70void DSSlot1SPIInit(struct DS* ds, struct VFile* vf);
71void DSSlot1Reset(struct DS* ds);
72
73DSSlot1AUXSPICNT DSSlot1Configure(struct DS* ds, DSSlot1AUXSPICNT config);
74DSSlot1ROMCNT DSSlot1Control(struct DS* ds, DSSlot1ROMCNT control);
75void DSSlot1WriteSPI(struct DSCommon* dscore, uint8_t datum);
76void DSSlot1ConfigureSPI(struct DS* ds, uint32_t paramPtr);
77
78struct GBADMA;
79void DSSlot1ScheduleDMA(struct DSCommon* dscore, int number, struct GBADMA* info);
80
81uint32_t DSSlot1Read(struct DS* ds);
82
83CXX_GUARD_END
84
85#endif