diff options
author | Adam <you@example.com> | 2020-05-17 05:51:50 +0200 |
---|---|---|
committer | Adam <you@example.com> | 2020-05-17 05:51:50 +0200 |
commit | e611b132f9b8abe35b362e5870b74bce94a1e58e (patch) | |
tree | a5781d2ec0e085eeca33cf350cf878f2efea6fe5 /private/ntos/ndis/digi/pcimac/util.c | |
download | NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.gz NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.bz2 NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.lz NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.xz NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.zst NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.zip |
Diffstat (limited to 'private/ntos/ndis/digi/pcimac/util.c')
-rw-r--r-- | private/ntos/ndis/digi/pcimac/util.c | 146 |
1 files changed, 146 insertions, 0 deletions
diff --git a/private/ntos/ndis/digi/pcimac/util.c b/private/ntos/ndis/digi/pcimac/util.c new file mode 100644 index 000000000..448afe990 --- /dev/null +++ b/private/ntos/ndis/digi/pcimac/util.c @@ -0,0 +1,146 @@ +/* + * UTIL.C - some utility functions + */ + +#include <ndis.h> +#include <mydefs.h> +#include <mytypes.h> +#include <util.h> + +// Total Memory Allocated +ULONG TotalMemory = 0; + +/* constants */ +#define BUF_SIZE 512 + +#if !BINARY_COMPATIBLE +/* get current time, in seconds */ +ULONG +ut_time_now(VOID) +{ + LARGE_INTEGER curr_time; + LARGE_INTEGER sec; + static LARGE_INTEGER base = {0, 0}; + static BOOL first_call = TRUE; + + /* get current system time */ + KeQuerySystemTime(&curr_time); + + /* on first call, store base */ + if ( first_call ) + { + base = curr_time; + first_call = FALSE; + } + /* make relative to base */ + curr_time.QuadPart -= base.QuadPart; + + /* convert to seconds */ + sec.QuadPart = curr_time.QuadPart/10000000L; + + /* return as a ULONG */ + return((ULONG)sec.LowPart); +} +#else +/* get current time, in seconds */ +ULONG +ut_time_now(VOID) +{ + ULONG seconds; + static BOOL first_call = TRUE; + + static ULONG base = 0; + ULONG curr_time; + + + // BUGBUG - Have to get real time somehow + + curr_time = base + 1; + + /* on first call, store base */ + if ( first_call ) + { + base = curr_time; + first_call = FALSE; + } + + /* make relative to base */ + seconds = curr_time - base; + + /* return as a ULONG */ + return(seconds); +} +#endif + +/* allocate a buffer */ +CHAR* +ut_get_buf(VOID) +{ + CHAR *ret; + + NDIS_PHYSICAL_ADDRESS pa = NDIS_PHYSICAL_ADDRESS_CONST(-1, -1); + + NdisAllocateMemory((PVOID*)&ret, BUF_SIZE, 0, pa); + + return(ret); +} + +/* free buffer */ +VOID +ut_free_buf(CHAR *buf) +{ + if ( buf ) + NdisFreeMemory(buf, BUF_SIZE, 0); +} + +/* init */ +VOID +sema_init(SEMA *s) +{ + s->signalled = FALSE; + NdisAllocateSpinLock (&s->lock); +} + +VOID +sema_term(SEMA *s) +{ + s->signalled = FALSE; + NdisFreeSpinLock (&s->lock); +} + +/* try to get semaphore */ +BOOL +sema_get(SEMA *s) +{ + BOOL ret; +// KIRQL NewIrql, OldIrql; + +// NewIrql = HIGH_LEVEL; + +// KeRaiseIrql (NewIrql, &OldIrql); + + NdisAcquireSpinLock (&s->lock); + + if ( !s->signalled ) + ret = s->signalled = TRUE; + else + ret = FALSE; + + NdisReleaseSpinLock (&s->lock); + +// KeLowerIrql (OldIrql); + + return(ret); +} + +/* free semaphore */ +VOID +sema_free(SEMA *s) +{ + NdisAcquireSpinLock (&s->lock); + + s->signalled = FALSE; + + NdisReleaseSpinLock (&s->lock); +} + |