mirror of
https://github.com/yellows8/dsi.git
synced 2025-06-18 11:15:34 -04:00
Added libtwlwifi. This was for attempting to use the TWL wifi SDIO hw but it never really worked properly.
This commit is contained in:
parent
59f250f05a
commit
1ed37d11bc
52
libraries/libtwlwifi/Makefile
Normal file
52
libraries/libtwlwifi/Makefile
Normal file
@ -0,0 +1,52 @@
|
||||
#---------------------------------------------------------------------------------
|
||||
.SUFFIXES:
|
||||
#---------------------------------------------------------------------------------
|
||||
ifeq ($(strip $(DEVKITARM)),)
|
||||
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
|
||||
endif
|
||||
|
||||
include $(DEVKITARM)/ds_rules
|
||||
|
||||
export TARGET := $(shell basename $(CURDIR))
|
||||
export TOPDIR := $(CURDIR)
|
||||
|
||||
PARAMS :=
|
||||
ifeq ($(USELIBNDS),1)
|
||||
PARAMS += USELIBNDS=1
|
||||
endif
|
||||
ifeq ($(strip $(USELIBNDS)),)
|
||||
PARAMS += USELIBMININDS=1
|
||||
endif
|
||||
ifeq ($(NOIPC),1)
|
||||
PARAMS += NOIPC=1
|
||||
endif
|
||||
ifeq ($(ARM7DISK),1)
|
||||
PARAMS += ARM7DISK=1
|
||||
endif
|
||||
ifeq ($(DEBUG),1)
|
||||
PARAMS += DEBUG=1
|
||||
endif
|
||||
|
||||
.PHONY: arm7/$(TARGET).elf arm9/$(TARGET).elf
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# main targets
|
||||
#---------------------------------------------------------------------------------
|
||||
all: release
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
release :
|
||||
$(MAKE) -C arm7 $(PARAMS)
|
||||
$(MAKE) -C arm9 $(PARAMS)
|
||||
@cp arm7/lib/$(TARGET)7.a $(LIBNDS)/lib
|
||||
@cp arm9/lib/$(TARGET)9.a $(LIBNDS)/lib
|
||||
@mkdir -p $(LIBNDS)/include/twlwifi
|
||||
@cp include/twlwifi.h $(LIBNDS)/include/twlwifi
|
||||
@cp arm7/include/twlwifi7.h $(LIBNDS)/include/twlwifi
|
||||
@cp arm9/include/twlwifi9.h $(LIBNDS)/include/twlwifi
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
clean:
|
||||
$(MAKE) -C arm9 clean
|
||||
$(MAKE) -C arm7 clean
|
||||
rm -f $(TARGET).nds $(TARGET).arm7 $(TARGET).arm9
|
138
libraries/libtwlwifi/arm7/Makefile
Normal file
138
libraries/libtwlwifi/arm7/Makefile
Normal file
@ -0,0 +1,138 @@
|
||||
#---------------------------------------------------------------------------------
|
||||
.SUFFIXES:
|
||||
#---------------------------------------------------------------------------------
|
||||
ifeq ($(strip $(DEVKITARM)),)
|
||||
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
|
||||
endif
|
||||
|
||||
include $(DEVKITARM)/ds_rules
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# TARGET is the name of the output
|
||||
# BUILD is the directory where object files & intermediate files will be placed
|
||||
# SOURCES is a list of directories containing source code
|
||||
# DATA is a list of directories containing data files
|
||||
# INCLUDES is a list of directories containing header files
|
||||
#---------------------------------------------------------------------------------
|
||||
TARGET := twlwifi7
|
||||
BUILD := build
|
||||
SOURCES := source ../source
|
||||
INCLUDES := include build ../include
|
||||
DATA := data
|
||||
|
||||
DEFINES :=
|
||||
ifeq ($(USELIBNDS),1)
|
||||
DEFINES += -DUSELIBNDS
|
||||
endif
|
||||
ifeq ($(USELIBMININDS),1)
|
||||
DEFINES += -DUSELIBMININDS
|
||||
endif
|
||||
ifeq ($(NOIPC),1)
|
||||
DEFINES += -DNOIPC
|
||||
endif
|
||||
ifeq ($(DEBUG),1)
|
||||
DEFINES += -DTWLDEBUG
|
||||
endif
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# options for code generation
|
||||
#---------------------------------------------------------------------------------
|
||||
ARCH := -mthumb -mthumb-interwork
|
||||
|
||||
CFLAGS := -g -Wall -O2\
|
||||
-mcpu=arm7tdmi -mtune=arm7tdmi -fomit-frame-pointer\
|
||||
-ffast-math \
|
||||
$(ARCH)
|
||||
|
||||
CFLAGS += $(INCLUDE) -DARM7 $(DEFINES)
|
||||
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -fno-rtti
|
||||
|
||||
|
||||
ASFLAGS := -g $(ARCH)
|
||||
LDFLAGS = -T dsi_arm7.ld -g $(ARCH) -Wl,-Map,$(notdir $*).map
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
# include and lib
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBDIRS := $(LIBNDS)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# no real need to edit anything past this point unless you need to add additional
|
||||
# rules for different file extensions
|
||||
#---------------------------------------------------------------------------------
|
||||
ifneq ($(BUILD),$(notdir $(CURDIR)))
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
export OUTPUT := $(CURDIR)/lib/lib$(TARGET).a
|
||||
|
||||
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
|
||||
|
||||
export DEPSDIR := $(CURDIR)/$(BUILD)
|
||||
|
||||
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
|
||||
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
|
||||
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
|
||||
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# use CXX for linking C++ projects, CC for standard C
|
||||
#---------------------------------------------------------------------------------
|
||||
ifeq ($(strip $(CPPFILES)),)
|
||||
#---------------------------------------------------------------------------------
|
||||
export LD := $(CC)
|
||||
#---------------------------------------------------------------------------------
|
||||
else
|
||||
#---------------------------------------------------------------------------------
|
||||
export LD := $(CXX)
|
||||
#---------------------------------------------------------------------------------
|
||||
endif
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
export OFILES := $(addsuffix .o,$(BINFILES)) \
|
||||
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
|
||||
|
||||
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
|
||||
-I$(CURDIR)/$(BUILD)
|
||||
|
||||
.PHONY: $(BUILD) clean all
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
all: $(BUILD)
|
||||
|
||||
lib:
|
||||
@[ -d $@ ] || mkdir -p $@
|
||||
|
||||
$(BUILD): lib
|
||||
@[ -d $@ ] || mkdir -p $@
|
||||
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
clean:
|
||||
@echo clean ...
|
||||
@rm -fr $(BUILD) lib lib$(TARGET).a startup/mininds_dsi_arm9_crt0.o
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
else
|
||||
|
||||
DEPENDS := $(OFILES:.o=.d)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# main targets
|
||||
#---------------------------------------------------------------------------------
|
||||
$(OUTPUT) : $(OFILES)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
%.bin.o : %.bin
|
||||
#---------------------------------------------------------------------------------
|
||||
@echo $(notdir $<)
|
||||
@$(bin2o)
|
||||
|
||||
|
||||
-include $(DEPENDS)
|
||||
|
||||
#---------------------------------------------------------------------------------------
|
||||
endif
|
||||
#---------------------------------------------------------------------------------------
|
7
libraries/libtwlwifi/arm7/include/twlwifi7.h
Normal file
7
libraries/libtwlwifi/arm7/include/twlwifi7.h
Normal file
@ -0,0 +1,7 @@
|
||||
#ifndef _H_TWLWIFI7
|
||||
#define _H_TWLWIFI7
|
||||
|
||||
int twlwifi_init();
|
||||
|
||||
#endif
|
||||
|
70
libraries/libtwlwifi/arm7/include/wifisdio.h
Normal file
70
libraries/libtwlwifi/arm7/include/wifisdio.h
Normal file
@ -0,0 +1,70 @@
|
||||
#ifndef __WIFISDIO_H__
|
||||
#define __WIFISDIO_H__
|
||||
|
||||
#include <nds.h>
|
||||
|
||||
#define WIFISDIO_BASE 0x04004a00
|
||||
|
||||
#define REG_SDDEVICE 0x02
|
||||
#define REG_SDSTATUS0 0x1c
|
||||
#define REG_SDSTATUS1 0x1e
|
||||
#define REG_SDRESET 0xe0
|
||||
#define REG_SDCLKCTL 0x24
|
||||
#define REG_SDOPT 0x28
|
||||
#define REG_SDCMD 0x00
|
||||
#define REG_SDCMDARG 0x04
|
||||
#define REG_SDCMDARG0 0x04
|
||||
#define REG_SDCMDARG1 0x06
|
||||
#define REG_SDSTOP 0x08
|
||||
#define REG_SDRESP 0x0c
|
||||
|
||||
#define REG_SDRESP0 0x0c
|
||||
#define REG_SDRESP1 0x0e
|
||||
#define REG_SDRESP2 0x10
|
||||
#define REG_SDRESP3 0x12
|
||||
#define REG_SDRESP4 0x14
|
||||
#define REG_SDRESP5 0x16
|
||||
#define REG_SDRESP6 0x18
|
||||
#define REG_SDRESP7 0x1a
|
||||
|
||||
#define REG_SDBLKLEN 0x26
|
||||
#define REG_SDBLKCOUNT 0x0a
|
||||
#define REG_SDFIFO 0x30
|
||||
|
||||
//The below defines are from tmio_mmc.h.
|
||||
/* Definitions for values the CTRL_STATUS register can take. */
|
||||
#define TMIO_STAT_CMDRESPEND 0x00000001
|
||||
#define TMIO_STAT_DATAEND 0x00000004
|
||||
#define TMIO_STAT_CARD_REMOVE 0x00000008
|
||||
#define TMIO_STAT_CARD_INSERT 0x00000010
|
||||
#define TMIO_STAT_SIGSTATE 0x00000020
|
||||
#define TMIO_STAT_WRPROTECT 0x00000080
|
||||
#define TMIO_STAT_CARD_REMOVE_A 0x00000100
|
||||
#define TMIO_STAT_CARD_INSERT_A 0x00000200
|
||||
#define TMIO_STAT_SIGSTATE_A 0x00000400
|
||||
#define TMIO_STAT_CMD_IDX_ERR 0x00010000
|
||||
#define TMIO_STAT_CRCFAIL 0x00020000
|
||||
#define TMIO_STAT_STOPBIT_ERR 0x00040000
|
||||
#define TMIO_STAT_DATATIMEOUT 0x00080000
|
||||
#define TMIO_STAT_RXOVERFLOW 0x00100000
|
||||
#define TMIO_STAT_TXUNDERRUN 0x00200000
|
||||
#define TMIO_STAT_CMDTIMEOUT 0x00400000
|
||||
#define TMIO_STAT_RXRDY 0x01000000
|
||||
#define TMIO_STAT_TXRQ 0x02000000
|
||||
#define TMIO_STAT_ILL_FUNC 0x20000000
|
||||
#define TMIO_STAT_CMD_BUSY 0x40000000
|
||||
#define TMIO_STAT_ILL_ACCESS 0x80000000
|
||||
|
||||
#ifndef USELIBMININDS
|
||||
#define wifisdio_controller_init twlwifisdio_wifisdio_controller_init
|
||||
#define wifisdio_initirq twlwifisdio_wifisdio_initirq
|
||||
|
||||
#define wifisdio_ath_init twlwifisdio_wifisdio_sdcard_init
|
||||
#endif
|
||||
|
||||
void wifisdio_controller_init();
|
||||
void wifisdio_initirq();
|
||||
|
||||
int wifisdio_ath_init();
|
||||
|
||||
#endif
|
71
libraries/libtwlwifi/arm7/source/twlwifi7.c
Normal file
71
libraries/libtwlwifi/arm7/source/twlwifi7.c
Normal file
@ -0,0 +1,71 @@
|
||||
#ifdef USELIBNDS
|
||||
#include <nds.h>
|
||||
#else
|
||||
#include <mininds/mininds.h>
|
||||
#endif
|
||||
#include "twlwifi.h"
|
||||
#include "wifisdioipc.h"
|
||||
#include "wifisdio.h"
|
||||
|
||||
static u32 twlwifi_arm9ready = 0;
|
||||
|
||||
#ifndef NOIPC
|
||||
void wifisdiohandler(void * address, void * userdata)
|
||||
{
|
||||
wifisdioipc_cmd *cmd = (wifisdioipc_cmd*)address;
|
||||
switch(cmd->cmdtype)
|
||||
{
|
||||
case 0:
|
||||
/*if(!cmd->rw)twlsdmmc_readsector(cmd->buffer, cmd->sector, cmd->total_sectors, cmd->raw);
|
||||
#ifdef ENABLEWR
|
||||
if(cmd->rw)twlsdmmc_writesector(cmd->buffer, cmd->sector, cmd->total_sectors, cmd->raw);
|
||||
#endif*/
|
||||
break;
|
||||
|
||||
case 2:
|
||||
twlwifi_arm9ready = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
cmd->busy = 0;
|
||||
}
|
||||
|
||||
void mini_wifisdiohandler(u32 data)
|
||||
{
|
||||
wifisdiohandler((void*)data, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
int twlwifi_init()
|
||||
{
|
||||
int retval = 0;
|
||||
|
||||
SendFIFOString("work. now.");
|
||||
//wifisdio_initirq();
|
||||
//wifisdio_controller_init();
|
||||
SendFIFOString("cmds init.....");
|
||||
retval = wifisdio_ath_init();
|
||||
SendFIFOString("alive");
|
||||
#ifndef NOIPC
|
||||
twlwifi_arm9ready = 0;
|
||||
#ifdef USELIBNDS
|
||||
fifoSetAddressHandler(TWLWIFI_FIFOCHAN, wifisdiohandler, 0);
|
||||
#else
|
||||
mininds_setfifochanhandler(TWLWIFI_FIFOCHAN, mini_wifisdiohandler);
|
||||
#endif
|
||||
|
||||
if(retval)return retval;
|
||||
while(!twlwifi_arm9ready)
|
||||
{
|
||||
#ifdef USELIBNDS
|
||||
fifoSendValue32(TWLWIFI_FIFOCHAN,0x594452);
|
||||
#else
|
||||
mininds_sendfifodata(TWLWIFI_FIFOCHAN,0x594452);//"RDY"
|
||||
#endif
|
||||
swiWaitForVBlank();
|
||||
}
|
||||
|
||||
#endif
|
||||
return retval;
|
||||
}
|
||||
|
205
libraries/libtwlwifi/arm7/source/wifisdio.c
Normal file
205
libraries/libtwlwifi/arm7/source/wifisdio.c
Normal file
@ -0,0 +1,205 @@
|
||||
#ifdef USELIBNDS
|
||||
#include <nds.h>
|
||||
#else
|
||||
#include <mininds/mininds.h>
|
||||
#define NULL 0
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include "wifisdio.h"
|
||||
|
||||
#define WIFMMC_BASE 0x04004a00
|
||||
#define DISPSTAT_CHK_VBLANK (1<<0)
|
||||
//#define REG_DISPSTAT *(vu16*)0x04000004
|
||||
|
||||
#define wifisdio_send_command twlwifi_wifisdio_send_command
|
||||
#define wifisdio_send_acmd41 twlwifi_wifisdio_send_acmd41
|
||||
#define wifisdio_clkdelay0 twlwifi_wifisdio_clkdelay0
|
||||
#define wifisdio_clkdelay1 twlwifi_wifisdio_clkdelay1
|
||||
#define wifisdio_clkdelay twlwifi_wifisdio_clkdelay
|
||||
|
||||
|
||||
void SendFIFOString(char *str);
|
||||
|
||||
#define IOHook_LogStr SendFIFOString
|
||||
//#define TWLDEBUG
|
||||
|
||||
//char logstr[256];
|
||||
void IOHook_LogHex(void* buf, int sz);
|
||||
|
||||
u32 twlwifi_cid[4];
|
||||
extern char *fifo_string;
|
||||
|
||||
static int wifisdio_timeout = 0;
|
||||
static int wifisdio_gotcmd8reply = 0;
|
||||
static int wifisdio_sdhc = 0;
|
||||
static int wifisdio_ismem = 0, wifisdio_isio = 0, wifisdio_numiofuncs = 0;
|
||||
|
||||
void wifisdio_initdelaytimers();
|
||||
|
||||
inline u16 wifisdio_read16(u16 reg) {
|
||||
return *(vu16*)(WIFISDIO_BASE + reg);
|
||||
}
|
||||
|
||||
inline void wifisdio_write16(u16 reg, u16 val) {
|
||||
*(vu16*)(WIFISDIO_BASE + reg) = val;
|
||||
}
|
||||
|
||||
inline void wifisdio_mask16(u16 reg, u16 clear, u16 set) {
|
||||
u16 val = wifisdio_read16(reg);
|
||||
val &= ~clear;
|
||||
val |= set;
|
||||
wifisdio_write16(reg, val);
|
||||
}
|
||||
|
||||
int wifisdio_send_command(u16 cmd, u16 arg0, u16 arg1) {
|
||||
u16 is_stat0, was_stat0;
|
||||
u16 is_stat1, was_stat1;
|
||||
|
||||
wifisdio_mask16(REG_SDCLKCTL, 0x100, 0x0);
|
||||
|
||||
wifisdio_write16(REG_SDCMDARG0, arg0);
|
||||
wifisdio_write16(REG_SDCMDARG1, arg1);
|
||||
|
||||
was_stat1 = wifisdio_read16(REG_SDSTATUS1);
|
||||
|
||||
while(wifisdio_read16(REG_SDSTATUS1) & 0x4000);
|
||||
|
||||
is_stat1 = wifisdio_read16(REG_SDSTATUS1);
|
||||
|
||||
wifisdio_mask16(REG_SDSTATUS1, 0x807F, 0);
|
||||
wifisdio_mask16(REG_SDSTATUS0, 0x0001, 0);
|
||||
wifisdio_mask16(REG_SDSTATUS0, 0x0004, 0);
|
||||
wifisdio_mask16(REG_SDSTATUS1, 0x100, 0);
|
||||
wifisdio_mask16(REG_SDSTATUS1, 0x200, 0);
|
||||
wifisdio_mask16(REG_SDSTOP, 1, 0);
|
||||
wifisdio_mask16(0x22, 0x807F, 0);
|
||||
wifisdio_mask16(0x20, 0x4, 0);
|
||||
wifisdio_timeout = 0;
|
||||
|
||||
if(cmd==17 || cmd==18) {
|
||||
if((wifisdio_read16(0x100) & 2)==0)wifisdio_mask16(0x22, 0x100, 0);
|
||||
}
|
||||
if(cmd==24 || cmd==25) {
|
||||
if((wifisdio_read16(0x100) & 2)==0)wifisdio_mask16(0x22, 0x200, 0);
|
||||
}
|
||||
|
||||
wifisdio_mask16(REG_SDSTOP, 1, 0);
|
||||
wifisdio_write16(REG_SDCMD, cmd);
|
||||
|
||||
if (cmd != 0) {
|
||||
was_stat0 = wifisdio_read16(REG_SDSTATUS0);
|
||||
|
||||
if (cmd != 0x5016) {
|
||||
while((wifisdio_read16(REG_SDSTATUS0) & 5) == 0) {
|
||||
if(wifisdio_read16(REG_SDSTATUS1) & 0x40) {
|
||||
wifisdio_mask16(REG_SDSTATUS1, 0x40, 0);
|
||||
wifisdio_timeout = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
is_stat0 = wifisdio_read16(REG_SDSTATUS0);
|
||||
wifisdio_mask16(REG_SDSTATUS0, 5, 0);
|
||||
}
|
||||
|
||||
if(wifisdio_timeout)SendFIFOString("TIMEOUT!");
|
||||
sprintf(fifo_string, "CMD STATUS: %04x%04x", wifisdio_read16(REG_SDSTATUS1), wifisdio_read16(REG_SDSTATUS0));
|
||||
SendFIFOString(NULL);
|
||||
|
||||
// irq mask?
|
||||
/*if(cmd!=17 && cmd!=18 && cmd!=24 && cmd!=25)*/wifisdio_mask16(0x22, 0, 0x807F);
|
||||
wifisdio_mask16(REG_SDCLKCTL, 0, 0x100);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void wifisdio_controller_init() {
|
||||
// Reset
|
||||
wifisdio_write16(0x100, 0x0402);
|
||||
wifisdio_write16(0x100, 0x0000);
|
||||
wifisdio_write16(0x104, 0x0000);
|
||||
wifisdio_write16(0x108, 0x0001);
|
||||
|
||||
// InitIP
|
||||
wifisdio_mask16(REG_SDRESET, 0x0003, 0x0000);
|
||||
wifisdio_mask16(REG_SDRESET, 0x0000, 0x0003);
|
||||
wifisdio_mask16(REG_SDSTOP, 0x0001, 0x0000);
|
||||
|
||||
// Reset
|
||||
wifisdio_mask16(REG_SDOPT, 0x0005, 0x0000);
|
||||
|
||||
// EnableInfo
|
||||
wifisdio_mask16(REG_SDSTATUS0, 0x0018, 0x0000);
|
||||
wifisdio_mask16(0x20, 0x0018, 0x0000); // ??
|
||||
wifisdio_mask16(0x20, 0x0000, 0x0018);
|
||||
}
|
||||
|
||||
u8 wifisdio_send_cmdrd_iodirect(u32 func, u32 regadr)
|
||||
{
|
||||
u32 resp = 0;
|
||||
u32 arg = ((func & 7)<<27) | ((regadr&0x1ffff)<<9);
|
||||
wifisdio_send_command(0x434, (u16)arg, (arg>>16));
|
||||
|
||||
resp = wifisdio_read16(REG_SDRESP0) | (wifisdio_read16(REG_SDRESP1)<<16);
|
||||
sprintf(fifo_string, "CMD52RD RESP: %x", resp);
|
||||
SendFIFOString(NULL);
|
||||
return (u8)resp;
|
||||
}
|
||||
|
||||
void wifisdio_send_cmdwr_iodirect(u32 func, u32 regadr, u8 value)
|
||||
{
|
||||
u32 resp = 0;
|
||||
u32 arg = (1<<31) | ((func & 7)<<27) | ((regadr&0x1ffff)<<9) | (value);
|
||||
wifisdio_send_command(0x434, (u16)arg, (arg>>16));
|
||||
|
||||
while( (REG_DISPSTAT & DISPSTAT_CHK_VBLANK) == 0 );
|
||||
while( (REG_DISPSTAT & DISPSTAT_CHK_VBLANK) != 0 );
|
||||
|
||||
resp = wifisdio_read16(REG_SDRESP0) | (wifisdio_read16(REG_SDRESP1)<<16);
|
||||
sprintf(fifo_string, "CMD52WR RESP: %x", resp);
|
||||
SendFIFOString(NULL);
|
||||
}
|
||||
|
||||
void wifisdio_send_cmd_iodirect_set32(u32 func, u32 regadr, u8 val)
|
||||
{
|
||||
u32 tmp = wifisdio_send_cmdrd_iodirect(func, regadr);
|
||||
wifisdio_send_cmdwr_iodirect(func, regadr, val | tmp);
|
||||
}
|
||||
|
||||
void wifisdio_send_cmd_iodirect_clear32(u32 func, u32 regadr, u8 val)
|
||||
{
|
||||
u32 tmp = wifisdio_send_cmdrd_iodirect(func, regadr);
|
||||
wifisdio_send_cmdwr_iodirect(func, regadr, ~val & tmp);
|
||||
}
|
||||
|
||||
int wifisdio_ath_init() {
|
||||
u16 sdaddr;
|
||||
u32 resp0;
|
||||
u32 resp1;
|
||||
u32 resp2;
|
||||
u32 resp3;
|
||||
u32 resp4;
|
||||
u32 resp5;
|
||||
u32 resp6;
|
||||
u32 resp7;
|
||||
u32 ocr, ccs, hcs, response, io_ocr;
|
||||
int vblank_counter = 0;
|
||||
|
||||
/*wifisdio_write16(REG_SDCLKCTL, 0x20);
|
||||
wifisdio_write16(REG_SDOPT, 0x40D0); // XXX: document me!
|
||||
wifisdio_write16(REG_SDDEVICE, 0x401);
|
||||
|
||||
wifisdio_mask16(REG_SDCLKCTL, 0, 0x100);
|
||||
wifisdio_write16(REG_SDCLKCTL, wifisdio_read16(REG_SDCLKCTL));
|
||||
wifisdio_mask16(REG_SDCLKCTL, 0x100, 0);
|
||||
wifisdio_mask16(REG_SDCLKCTL, 0, 0x200);
|
||||
wifisdio_mask16(REG_SDCLKCTL, 0, 0x100);*/
|
||||
|
||||
SendFIFOString("Sending reset cmds...");
|
||||
|
||||
wifisdio_send_cmdrd_iodirect(0, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
144
libraries/libtwlwifi/arm9/Makefile
Normal file
144
libraries/libtwlwifi/arm9/Makefile
Normal file
@ -0,0 +1,144 @@
|
||||
#---------------------------------------------------------------------------------
|
||||
.SUFFIXES:
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
ifeq ($(strip $(DEVKITARM)),)
|
||||
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
|
||||
endif
|
||||
|
||||
include $(DEVKITARM)/ds_rules
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# TARGET is the name of the output
|
||||
# BUILD is the directory where object files & intermediate files will be placed
|
||||
# SOURCES is a list of directories containing source code
|
||||
# DATA is a list of directories containing data files
|
||||
# INCLUDES is a list of directories containing header files
|
||||
#---------------------------------------------------------------------------------
|
||||
TARGET := twlwifi9
|
||||
BUILD := build
|
||||
SOURCES := source ../source
|
||||
DATA := data
|
||||
INCLUDES := include ../include ../source
|
||||
|
||||
ifeq ($(strip $(NOIPC)),)
|
||||
SOURCES += ../source/disk
|
||||
INCLUDES += ../source/disk
|
||||
endif
|
||||
|
||||
DEFINES :=
|
||||
ifeq ($(USELIBNDS),1)
|
||||
DEFINES += -DUSELIBNDS
|
||||
endif
|
||||
ifeq ($(USELIBMININDS),1)
|
||||
DEFINES += -DUSELIBMININDS
|
||||
endif
|
||||
ifeq ($(NOIPC),1)
|
||||
DEFINES += -DNOIPC
|
||||
endif
|
||||
ifeq ($(DEBUG),1)
|
||||
DEFINES += -DTWLDEBUG
|
||||
endif
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# options for code generation
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
ARCH := -mthumb -mthumb-interwork
|
||||
|
||||
CFLAGS := -g -Wall -O2\
|
||||
-march=armv5te -mtune=arm946e-s \
|
||||
-fomit-frame-pointer -ffast-math \
|
||||
$(ARCH)
|
||||
|
||||
CFLAGS += $(INCLUDE) -DARM9 $(DEFINES)
|
||||
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
|
||||
|
||||
ASFLAGS := -g $(ARCH) -march=armv5te -mtune=arm946e-s
|
||||
LDFLAGS = -T dsi_arm9.ld -g $(ARCH) -Wl,-Map,$(notdir $*.map)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
# include and lib
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBDIRS := $(LIBNDS)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# no real need to edit anything past this point unless you need to add additional
|
||||
# rules for different file extensions
|
||||
#---------------------------------------------------------------------------------
|
||||
ifneq ($(BUILD),$(notdir $(CURDIR)))
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
export OUTPUT := $(CURDIR)/lib/lib$(TARGET).a
|
||||
|
||||
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
|
||||
|
||||
export DEPSDIR := $(CURDIR)/$(BUILD)
|
||||
|
||||
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
|
||||
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
|
||||
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
|
||||
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# use CXX for linking C++ projects, CC for standard C
|
||||
#---------------------------------------------------------------------------------
|
||||
ifeq ($(strip $(CPPFILES)),)
|
||||
#---------------------------------------------------------------------------------
|
||||
export LD := $(CC)
|
||||
#---------------------------------------------------------------------------------
|
||||
else
|
||||
#---------------------------------------------------------------------------------
|
||||
export LD := $(CXX)
|
||||
#---------------------------------------------------------------------------------
|
||||
endif
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
export OFILES := $(addsuffix .o,$(BINFILES)) \
|
||||
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
|
||||
|
||||
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
|
||||
-I$(CURDIR)/$(BUILD)
|
||||
|
||||
.PHONY: $(BUILD) clean all
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
all: $(BUILD)
|
||||
|
||||
lib:
|
||||
@[ -d $@ ] || mkdir -p $@
|
||||
|
||||
$(BUILD): lib
|
||||
@[ -d $@ ] || mkdir -p $@
|
||||
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
clean:
|
||||
@echo clean ...
|
||||
@rm -fr $(BUILD) lib lib$(TARGET).a startup/mininds_dsi_arm9_crt0.o
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
else
|
||||
|
||||
DEPENDS := $(OFILES:.o=.d)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# main targets
|
||||
#---------------------------------------------------------------------------------
|
||||
$(OUTPUT) : $(OFILES)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
%.bin.o : %.bin
|
||||
#---------------------------------------------------------------------------------
|
||||
@echo $(notdir $<)
|
||||
@$(bin2o)
|
||||
|
||||
|
||||
-include $(DEPENDS)
|
||||
|
||||
#---------------------------------------------------------------------------------------
|
||||
endif
|
||||
#---------------------------------------------------------------------------------------
|
7
libraries/libtwlwifi/arm9/include/twlwifi9.h
Normal file
7
libraries/libtwlwifi/arm9/include/twlwifi9.h
Normal file
@ -0,0 +1,7 @@
|
||||
#ifndef _H_TWLWIFI9
|
||||
#define _H_TWLWIFI9
|
||||
|
||||
void twlwifi_init();
|
||||
|
||||
#endif
|
||||
|
71
libraries/libtwlwifi/arm9/source/twlwifi9.c
Normal file
71
libraries/libtwlwifi/arm9/source/twlwifi9.c
Normal file
@ -0,0 +1,71 @@
|
||||
#ifdef USELIBNDS
|
||||
#include <nds.h>
|
||||
#else
|
||||
#include <mininds/mininds.h>
|
||||
#endif
|
||||
#include "twlwifi.h"
|
||||
|
||||
#ifdef ARM9
|
||||
#include "wifisdioipc.h"
|
||||
|
||||
static wifisdioipc_cmd wifisdio_cmd;
|
||||
extern char strbuf[];
|
||||
#endif
|
||||
|
||||
vu32 twlwifi_arm7ready_flg = 0;
|
||||
|
||||
void twlwifi_sendmsg(wifisdioipc_cmd *cmd);
|
||||
|
||||
#ifndef NOIPC
|
||||
void twlwifi_arm7readyhandler(u32 data, void* userdata)
|
||||
{
|
||||
//printf("got mmc chan data %x\n", data);
|
||||
if(data==0x594452)
|
||||
{
|
||||
twlwifi_arm7ready_flg = 1;//"RDY"
|
||||
}
|
||||
}
|
||||
|
||||
void twlwifi_miniarm7readyhandler(u32 data)
|
||||
{
|
||||
twlwifi_arm7readyhandler(data, 0);
|
||||
}
|
||||
|
||||
u32 twlwifi_arm7ready()
|
||||
{
|
||||
return twlwifi_arm7ready_flg;
|
||||
}
|
||||
#endif
|
||||
|
||||
void twlwifi_init()
|
||||
{
|
||||
#ifndef NOIPC
|
||||
#ifdef USELIBNDS
|
||||
fifoSetValue32Handler(TWLWIFI_FIFOCHAN, twlwifi_arm7readyhandler, 0);
|
||||
#else
|
||||
mininds_setfifochanhandler(TWLWIFI_FIFOCHAN, twlwifi_miniarm7readyhandler);
|
||||
#endif
|
||||
while(!twlwifi_arm7ready_flg);
|
||||
wifisdio_cmd.cmdtype = 2;
|
||||
twlwifi_sendmsg(&wifisdio_cmd);
|
||||
#endif
|
||||
}
|
||||
|
||||
void twlwifi_sendmsg(wifisdioipc_cmd *cmd)
|
||||
{
|
||||
#ifndef NOIPC
|
||||
wifisdio_cmd.busy = 1;
|
||||
DC_FlushRange(cmd, sizeof(wifisdioipc_cmd));
|
||||
#ifdef USELIBNDS
|
||||
fifoSendAddress(TWLWIFI_FIFOCHAN, cmd);
|
||||
#else
|
||||
mininds_sendfifodata(TWLWIFI_FIFOCHAN, (u32)cmd);
|
||||
#endif
|
||||
while(1)
|
||||
{
|
||||
DC_InvalidateRange(cmd, sizeof(wifisdioipc_cmd));
|
||||
if(cmd->busy==0)break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
18
libraries/libtwlwifi/include/twlwifi.h
Normal file
18
libraries/libtwlwifi/include/twlwifi.h
Normal file
@ -0,0 +1,18 @@
|
||||
#ifndef _H_TWLSDMMC_
|
||||
#define _H_TWLSDMMC_
|
||||
|
||||
#ifndef ARM7
|
||||
#ifndef ARM9
|
||||
#error "Define either ARM7 or ARM9."
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef ARM7
|
||||
#include "twlwifi7.h"
|
||||
#endif
|
||||
#ifdef ARM9
|
||||
#include "twlwifi9.h"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
18
libraries/libtwlwifi/include/wifisdioipc.h
Normal file
18
libraries/libtwlwifi/include/wifisdioipc.h
Normal file
@ -0,0 +1,18 @@
|
||||
#ifndef _H_WIFISDIOIPC
|
||||
#define _H_WIFISDIOIPC
|
||||
|
||||
#define TWLWIFI_FIFOCHAN FIFO_USER_08
|
||||
|
||||
typedef struct _wifisdioipc_cmd
|
||||
{
|
||||
u32 busy;
|
||||
u32 cmdtype;
|
||||
u32 sector;
|
||||
u32 total_sectors;
|
||||
u32 *cryptbuf;
|
||||
u32 *buffer;
|
||||
int raw;
|
||||
int rw;
|
||||
} wifisdioipc_cmd;
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user