DSi_NWifi.h 3.26 KB
Newer Older
Arisotura's avatar
Arisotura committed
1
/*
2
    Copyright 2016-2020 Arisotura
Arisotura's avatar
Arisotura committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

    This file is part of melonDS.

    melonDS 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, either version 3 of the License, or (at your option)
    any later version.

    melonDS 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 melonDS. If not, see http://www.gnu.org/licenses/.
*/

#ifndef DSI_NWIFI_H
#define DSI_NWIFI_H

#include "DSi_SD.h"
23
#include "FIFO.h"
Arisotura's avatar
Arisotura committed
24
25
26
27
28
29
30

class DSi_NWifi : public DSi_SDDevice
{
public:
    DSi_NWifi(DSi_SDHost* host);
    ~DSi_NWifi();

Arisotura's avatar
Arisotura committed
31
32
    void Reset();

Arisotura's avatar
Arisotura committed
33
34
35
36
37
    void SendCMD(u8 cmd, u32 param);
    void SendACMD(u8 cmd, u32 param);

    void ContinueTransfer();

38
39
    void SetIRQ_F1_Counter(u32 n);

40
    void _MSTimer();
Arisotura's avatar
Arisotura committed
41
42
43

    static void MSTimer(u32 param);

Arisotura's avatar
Arisotura committed
44
private:
Arisotura's avatar
Arisotura committed
45
46
47
48
    u32 TransferCmd;
    u32 TransferAddr;
    u32 RemSize;

49
50
51
52
53
54
    void UpdateIRQ();
    void UpdateIRQ_F1();
    //void SetIRQ_F1_Counter(u32 n);
    void ClearIRQ_F1_Counter(u32 n);
    void SetIRQ_F1_CPU(u32 n);

Arisotura's avatar
Arisotura committed
55
56
57
58
59
60
61
62
63
64
65
    u8 F0_Read(u32 addr);
    void F0_Write(u32 addr, u8 val);

    u8 F1_Read(u32 addr);
    void F1_Write(u32 addr, u8 val);

    u8 SDIO_Read(u32 func, u32 addr);
    void SDIO_Write(u32 func, u32 addr, u8 val);

    void ReadBlock();
    void WriteBlock();
66

67
    void HandleCommand();
68
    void BMI_Command();
69
    void HTC_Command();
70
71
    void WMI_Command();

72
    void WMI_ConnectToNetwork();
Arisotura's avatar
Arisotura committed
73
    void WMI_SendPacket(u16 len);
74

Arisotura's avatar
Arisotura committed
75
    void SendWMIEvent(u8 ep, u16 id, u8* data, u32 len);
76
    void SendWMIAck(u8 ep);
77
    void SendWMIBSSInfo(u8 type, u8* data, u32 len);
78

Arisotura's avatar
Arisotura committed
79
    void CheckRX();
80
    void DrainRXBuffer();
Arisotura's avatar
Arisotura committed
81

Arisotura's avatar
Arisotura committed
82
83
    u32 WindowRead(u32 addr);
    void WindowWrite(u32 addr, u32 val);
84

85
86
87
88
89
90
91
92
93
94
95
96
97
    u16 MB_Read16(int n)
    {
        u16 ret = Mailbox[n]->Read();
        ret |= (Mailbox[n]->Read() << 8);
        return ret;
    }

    void MB_Write16(int n, u16 val)
    {
        Mailbox[n]->Write(val & 0xFF); val >>= 8;
        Mailbox[n]->Write(val & 0xFF);
    }

98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
    u32 MB_Read32(int n)
    {
        u32 ret = Mailbox[n]->Read();
        ret |= (Mailbox[n]->Read() << 8);
        ret |= (Mailbox[n]->Read() << 16);
        ret |= (Mailbox[n]->Read() << 24);
        return ret;
    }

    void MB_Write32(int n, u32 val)
    {
        Mailbox[n]->Write(val & 0xFF); val >>= 8;
        Mailbox[n]->Write(val & 0xFF); val >>= 8;
        Mailbox[n]->Write(val & 0xFF); val >>= 8;
        Mailbox[n]->Write(val & 0xFF);
    }

115
116
117
118
119
    void MB_Drain(int n)
    {
        while (!Mailbox[n]->IsEmpty()) Mailbox[n]->Read();
    }

120
    FIFO<u8>* Mailbox[9];
121

122
123
124
125
126
127
    u8 F0_IRQEnable;
    u8 F0_IRQStatus;

    u8 F1_IRQEnable, F1_IRQEnable_CPU, F1_IRQEnable_Error, F1_IRQEnable_Counter;
    u8 F1_IRQStatus, F1_IRQStatus_CPU, F1_IRQStatus_Error, F1_IRQStatus_Counter;

128
    u32 WindowData, WindowReadAddr, WindowWriteAddr;
129
130
131
132
133

    u8 EEPROM[0x400];
    u32 EEPROMReady;

    u32 BootPhase;
Arisotura's avatar
Arisotura committed
134
135

    u32 ErrorMask;
136
    u32 ScanTimer;
Arisotura's avatar
Arisotura committed
137

138
139
140
    u64 BeaconTimer;
    u32 ConnectionStatus;

Arisotura's avatar
Arisotura committed
141
    u8 LANBuffer[2048];
Arisotura's avatar
Arisotura committed
142
143
144
};

#endif // DSI_NWIFI_H