1
0
mirror of https://github.com/raphnet/gc_n64_usb-v3 synced 2024-12-22 07:18:52 -05:00

Add a delay API (for cross-platform sleeps)

This commit is contained in:
Raphael Assenat 2015-10-05 21:12:52 -04:00
parent 04f3bd8d08
commit 01c4c23125
4 changed files with 34 additions and 5 deletions

View File

@ -8,7 +8,7 @@ PREFIX=/usr/local
PROG=gcn64ctl PROG=gcn64ctl
OBJS=main.o gcn64.o mempak.o gcn64lib.o hexdump.o gc2n64_adapter.o ihex.o OBJS=main.o gcn64.o mempak.o gcn64lib.o hexdump.o gc2n64_adapter.o ihex.o delay.o
.PHONY : clean install .PHONY : clean install

27
tool/delay.c Normal file
View File

@ -0,0 +1,27 @@
#ifdef LIBDRAGON
#include <libdragon.h>
void _delay_us(unsigned long us)
{
wait_ms(us/1000);
}
void _delay_s(unsigned long s)
{
wait_ms(s*1000);
}
#else
#include <unistd.h>
void _delay_us(unsigned long us)
{
usleep(us);
}
void _delay_s(unsigned long s)
{
sleep(s);
}
#endif

2
tool/delay.h Normal file
View File

@ -0,0 +1,2 @@
void _delay_us(unsigned long us);
void _delay_s(unsigned long s);

View File

@ -1,11 +1,11 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#include "gcn64lib.h" #include "gcn64lib.h"
#include "gc2n64_adapter.h" #include "gc2n64_adapter.h"
#include "hexdump.h" #include "hexdump.h"
#include "ihex.h" #include "ihex.h"
#include "delay.h"
int gc2n64_adapter_echotest(gcn64_hdl_t hdl, int verbose) int gc2n64_adapter_echotest(gcn64_hdl_t hdl, int verbose)
{ {
@ -184,7 +184,7 @@ int gc2n64_adapter_boot_waitNotBusy(gcn64_hdl_t hdl, int verbose)
} }
printf("%c\b", spinner[c%4]); fflush(stdout); printf("%c\b", spinner[c%4]); fflush(stdout);
c++; c++;
usleep(50000); _delay_us(50000);
} }
return 0; return 0;
@ -267,7 +267,7 @@ int gc2n64_adapter_enterBootloader(gcn64_hdl_t hdl)
return n; return n;
// No answer since the effect is immediate. // No answer since the effect is immediate.
usleep(100000); _delay_us(100000);
return 0; return 0;
} }
@ -390,7 +390,7 @@ int gc2n64_adapter_waitForBootloader(gcn64_hdl_t hdl, int timeout_s)
return 0; return 0;
} }
sleep(1); _delay_s(1);
} }
return -1; return -1;