gtime.c
765 Bytes
#include "os.h"
#include "os_bb.h"
#include "bcp.h"
#include "gtime.h"
#define GTIME_PATCH_MAGIC 0xbabe0002
#define MAGIC_GTIME_ADDR ((void*)PHYS_TO_K1(USB1_BDT_SRAM+496))
#define GTIME_PATCH_ADDR ((void*)(MAGIC_GTIME_ADDR+4))
static void
_wcopy(u32 *src, u32 *dst, int bytes)
{
int i;
int num_words = (bytes+3)>>2;
for (i = 0; i < num_words; ++i) {
*dst++ = *src++;
}
}
void
vwGetGtime(int* gtime)
{
if (IO_READ(MAGIC_GTIME_ADDR) == GTIME_PATCH_MAGIC) {
_wcopy(GTIME_PATCH_ADDR, (u32*)gtime, sizeof(int));
} else {
bzero(gtime, sizeof(int));
}
}
void
vwStoreGtime(int gtime)
{
IO_WRITE(MAGIC_GTIME_ADDR, GTIME_PATCH_MAGIC);
_wcopy((u32*)>ime, GTIME_PATCH_ADDR, sizeof(int));
}