From b7185b48b0807fb3ee36101a84f64bd73ac3a0f3 Mon Sep 17 00:00:00 2001 From: mightymax Date: Sat, 13 Jan 2007 19:09:57 +0000 Subject: [PATCH] added usec timer, wifi irq requests --- desmume/src/wifi.c | 25 ++++++++++++++++++++++++- desmume/src/wifi.h | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/desmume/src/wifi.c b/desmume/src/wifi.c index e79ed99ef..7698dd95a 100644 --- a/desmume/src/wifi.c +++ b/desmume/src/wifi.c @@ -19,6 +19,9 @@ */ #include "wifi.h" +#include "armcpu.h" + +wifimac_t wifiMac ; /******************************************************************************* @@ -325,4 +328,24 @@ u16 WIFI_read16(wifimac_t *wifi,u32 address) } } -wifimac_t wifiMac ; +void WIFI_triggerIRQ(wifimac_t *wifi, u8 irq) +{ + /* trigger an irq */ + u16 irqBit = 1 << irq ; + if (wifi->IE.val & irqBit) + { + wifi->IF.val |= irqBit ; + NDS_makeARM7Int(24) ; /* cascade it via arm7 wifi irq */ + } +} + +void WIFI_usTrigger(wifimac_t *wifi) +{ + /* a usec (=3F03 cycles) has passed */ + if (wifi->usecEnable) + wifi->usec++ ; + if ((wifi->ucmpEnable) && (wifi->ucmp == wifi->usec)) + { + WIFI_triggerIRQ(wifi,WIFI_IRQ_TIMEBEACON) ; + } +} diff --git a/desmume/src/wifi.h b/desmume/src/wifi.h index 1af14571e..0f150ef23 100644 --- a/desmume/src/wifi.h +++ b/desmume/src/wifi.h @@ -25,6 +25,15 @@ extern "C" { #endif +/* standardize socket interface for linux and windows */ +#ifdef WIN32 + #include + #define socket_t SOCKET +#else + #include + #define socket_t socket +#endif + #include "types.h" #define REG_WIFI_MODE 0x004 @@ -297,6 +306,18 @@ typedef union u16 val ; } bbIOCnt_t ; +#define WIFI_IRQ_RECVCOMPLETE 0x0001 +#define WIFI_IRQ_SENDCOMPLETE 0x0002 +#define WIFI_IRQ_COUNTUP 0x0004 +#define WIFI_IRQ_SENDERROR 0x0008 +#define WIFI_IRQ_STATCOUNTUP 0x0010 +#define WIFI_IRQ_STATACKUP 0x0020 +#define WIFI_IRQ_RECVSTART 0x0040 +#define WIFI_IRQ_SENDSTART 0x0080 +#define WIFI_IRQ_RFWAKEUP 0x0800 +#define WIFI_IRQ_TIMEBEACON 0x4000 +#define WIFI_IRQ_TIMEPREBEACON 0x8000 + /* definition of the irq bitfields for wifi irq's (cascaded at arm7 irq #24) */ typedef union { @@ -306,7 +327,7 @@ typedef union /* 1*/ unsigned send_complete:1; /* 2*/ unsigned recv_countup:1; /* 3*/ unsigned send_error:1; -/* 4*/ unsigned stat_coutup:1; +/* 4*/ unsigned stat_countup:1; /* 5*/ unsigned stat_ackup:1; /* 6*/ unsigned recv_start:1; /* 7*/ unsigned send_start:1; @@ -342,6 +363,12 @@ typedef struct u16 aid ; u16 retryLimit ; + /* timing */ + u64 usec ; + BOOL usecEnable ; + u64 ucmp ; + BOOL ucmpEnable ; + /* subchips */ rffilter_t RF ; bb_t BB ; @@ -364,6 +391,9 @@ typedef struct u16 CircBufEnd ; u16 CircBufSkip ; + /* desmume host communication */ + socket_t udpSocket ; + } wifimac_t ; extern wifimac_t wifiMac ; @@ -382,6 +412,9 @@ void WIFI_setBB_DATA(wifimac_t *wifi, u8 val) ; void WIFI_write16(wifimac_t *wifi,u32 address, u16 val) ; u16 WIFI_read16(wifimac_t *wifi,u32 address) ; +/* wifimac timing */ +void WIFI_usTrigger(wifimac_t *wifi) ; + #ifdef __cplusplus } #endif