Skip to content

Commit

Permalink
- Make use of EXILock callback for transmit.
Browse files Browse the repository at this point in the history
  • Loading branch information
Extrems committed Jan 11, 2020
1 parent 0446dbf commit d0f109b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
21 changes: 6 additions & 15 deletions cube/patches/bba/bba.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@
#define BBA_INIT_RWP BBA_INIT_BP
#define BBA_INIT_RRP BBA_INIT_BP

static bool exi_selected(void)
{
return !!(EXI[EXI_CHANNEL_0][0] & 0x380);
}

static void exi_clear_interrupts(int32_t chan, bool exi, bool tc, bool ext)
{
EXI[chan][0] = (EXI[chan][0] & ~0x80A) | (ext << 11) | (tc << 3) | (exi << 1);
Expand Down Expand Up @@ -167,15 +162,11 @@ static void bba_outs(uint16_t reg, const void *val, uint32_t len)
exi_deselect();
}

bool bba_transmit(const void *data, size_t size)
void bba_transmit(const void *data, size_t size)
{
if (exi_selected()) return false;

while (bba_in8(BBA_NCRA) & (BBA_NCRA_ST0 | BBA_NCRA_ST1));
bba_outs(BBA_WRTXFIFOD, data, size);
bba_out8(BBA_NCRA, (bba_in8(BBA_NCRA) & ~BBA_NCRA_ST0) | BBA_NCRA_ST1);

return true;
}

void bba_receive_end(bba_page_t page, void *data, size_t size)
Expand Down Expand Up @@ -280,14 +271,14 @@ bool exi_trylock(int32_t chan, uint32_t dev, EXIControl *exi)
void di_update_interrupts(void);
void di_complete_transfer(void);

void schedule_read(uint32_t offset, uint32_t length, OSTick ticks)
void schedule_read(uint32_t offset, uint32_t length, OSTick ticks, bool lock)
{
*_position = offset;
*_remainder = length;

if (length) {
if (!is_frag_read(offset, length))
fsp_get_file(offset, length);
fsp_get_file(offset, length, lock);
else
timer1_start(ticks);
return;
Expand All @@ -299,7 +290,7 @@ void schedule_read(uint32_t offset, uint32_t length, OSTick ticks)
void perform_read(uint32_t offset, uint32_t length, uint32_t address)
{
*_data = OSPhysicalToCached(address);
schedule_read(offset, length, 0);
schedule_read(offset, length, 0, true);
}

void trickle_read(void)
Expand All @@ -319,14 +310,14 @@ void trickle_read(void)
remainder -= data_size;

*_data = data + data_size;
schedule_read(position, remainder, OSDiffTick(end, start));
schedule_read(position, remainder, OSDiffTick(end, start), true);
dcache_store(data, data_size);
} else {
OSTime start = *_start;
OSTime end = OSGetTime();

if (OSSecondsToTicks(1) < end - start)
fsp_get_file(position, remainder);
fsp_get_file(position, remainder, true);
}
}

Expand Down
2 changes: 1 addition & 1 deletion cube/patches/bba/bba.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ typedef struct {

typedef uint8_t bba_page_t[256] __attribute((aligned(32)));

bool bba_transmit(const void *data, size_t size);
void bba_transmit(const void *data, size_t size);
void bba_receive_end(bba_page_t page, void *data, size_t size);

#endif /* BBA_H */
20 changes: 14 additions & 6 deletions cube/patches/bba/tcpip.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <string.h>
#include "../alt/timer.h"
#include "../base/common.h"
#include "../base/exi.h"
#include "../base/os.h"
#include "bba.h"
#include "globals.h"
Expand Down Expand Up @@ -137,7 +138,10 @@ static uint8_t fsp_checksum(fsp_header_t *header, size_t size)
return sum;
}

static void fsp_get_file(uint32_t offset, size_t size)
void schedule_read(uint32_t offset, uint32_t length, OSTick ticks, bool lock);
void trickle_read(void);

static void fsp_get_file(uint32_t offset, size_t size, bool lock)
{
const char *file = _file;
uint8_t filelen = *_filelen;
Expand All @@ -148,6 +152,10 @@ static void fsp_get_file(uint32_t offset, size_t size)
filelen = *_file2len;
}

*_start = 0;
if (lock && !EXILock(EXI_CHANNEL_0, EXI_DEVICE_2, trickle_read))
return;

uint8_t data[MIN_FRAME_SIZE + filelen];
eth_header_t *eth = (eth_header_t *)data;
ipv4_header_t *ipv4 = (ipv4_header_t *)eth->data;
Expand Down Expand Up @@ -187,13 +195,13 @@ static void fsp_get_file(uint32_t offset, size_t size)
eth->src_addr.addr = (*_client_mac).addr;
eth->type = ETH_TYPE_IPV4;

if (bba_transmit(eth, sizeof(*eth) + ipv4->length))
*_start = OSGetTime();
bba_transmit(eth, sizeof(*eth) + ipv4->length);

*_start = OSGetTime();
timer1_start(OSSecondsToTicks(1));
}

void schedule_read(uint32_t offset, uint32_t length, OSTick ticks);
if (lock) EXIUnlock(EXI_CHANNEL_0);
}

static void fsp_input(bba_page_t page, eth_header_t *eth, ipv4_header_t *ipv4, udp_header_t *udp, fsp_header_t *fsp, size_t size)
{
Expand Down Expand Up @@ -265,7 +273,7 @@ static void udp_input(bba_page_t page, eth_header_t *eth, ipv4_header_t *ipv4, u

*_data = data + data_size;
*_data_size = 0;
schedule_read(position, remainder, 0);
schedule_read(position, remainder, 0, false);
}

bba_receive_end(page, data + data_offset, size);
Expand Down

0 comments on commit d0f109b

Please sign in to comment.