#include "platform.h"
#define __ADSPLPBLACKFIN__ // This define gets rid of warnings
#include "defBF532.h"
#include "bfemu.h"
#include "timing.h"
#include <stdio.h>
static char g_line[] =
"------------------------------------------------------------------------\n";
void memory_dump(unsigned char *buf, unsigned long n)
{
int i = 0;
int c = 0;
while (i < n) {
printf("%02x ", buf[i]);
c++;
if (c == 16) { c = 0; printf("\n"); }
i++;
}
if (c)
printf("\n");
}
int mem_cmp(unsigned char *in, unsigned char *out, unsigned long size)
{
int i;
for (i = 0; i < size; i++) {
if (in[i] != out[i]) {
printf("Mismatch at %d\n", i);
printf("In:\n");
memory_dump(&in[i], 16);
printf("Out:\n");
memory_dump(&out[i], 16);
return 1;
}
}
return 0;
}
int init_EBIU(CPU cpu)
{
set_memory_word(cpu, EBIU_SDGCTL, 0x0091998d, LDST_32);
set_memory_word(cpu, EBIU_SDBCTL, 0x0025, LDST_16);
set_memory_word(cpu, EBIU_SDRRC, 0x0817, LDST_16);
return 0;
}
#define LEN 0x1000
static unsigned char in[LEN];
static unsigned char out[LEN];
int test_memory(CPU cpu)
{
TIMEVAL t0, t1;
float t;
int i;
int n = LEN;
ADDR addr = 0x00000000;
for (i = 0; i < n; i++) {
in[i] = rand();
}
printf("Writing to memory @ %08lx...\n", addr);
gettime(&t0);
set_memory(cpu, addr, n, in);
gettime(&t1);
t = took_time(&t0, &t1);
printf("rate: %f kB/s\n", n / 1000.0 / t);
printf("Reading from memory...\n");
gettime(&t0);
get_memory(cpu, addr, n, out);
gettime(&t1);
t = took_time(&t0, &t1);
printf("rate: %f kB/s\n", n / 1000.0 / t);
if (mem_cmp(in, out, n)) {
printf("Buffer mismatch in block %08lx\n", addr);
return -1;
} else {
printf("Memory good.\n");
}
return 0;
}
int main(int argc, char **argv)
{
CPU cpu;
int error;
unsigned int revision;
int i;
if (jtag_init(0, &cpu) < 0) {
printf("Could not open jtag controller\n");
return -1;
}
printf("Initializing emulation\n");
error = emulation_init(cpu);
if (error < 0) return -1;
emulation_config(cpu, JTAG_CLKSPEED, 1);
char *s;
printf("Detecting device...\n");
s = detect_device(cpu, &revision);
if (s) {
printf("Detected Device: %s rev:%d\n", s, revision);
} else {
printf("Could not detect device, JTAG failure ?\n");
return -1;
}
error = emulation_enter(cpu);
if (error < 0) {
printf("Emulator not ready!\n");
return -1;
}
cpu_reset(cpu, 3);
init_EBIU(cpu);
printf(g_line);
for (i = 0; i < 100; i++) {
printf("Go #%d...\n", i);
if (test_memory(cpu) < 0) break;
}
printf(g_line);
emulation_leave(cpu);
emulation_exit(cpu);
jtag_exit(cpu);
return 0;
}