#define I_AM_HOST #include "hostspec.h" #include "sys_pub.h" #include "sys_priv.h" #include "sys_gen.h" dpr *io_base[1]; extern int32 wordsMessageBase; extern int32 *message_base; int dsp_status[1]; /* dsp_status must be declared */ unsigned long next = 17; /* For pseudo-random number generator */ unsigned int rand ( void ); void srand ( unsigned int ); void exit (int); /* ================================================= */ /* do echo */ /* ================================================= */ void do_echo() { m_echo message; m_echo *mp = &message; m_echo *rm = (m_echo *) message_base; int i, length, t; int err, thiserr, cycle, itell; unsigned int rand1 = 0; unsigned int rand2 = 0; com_init() ; err = cycle = 0; itell = 1; t = 0; mp->ciw = ECHO; mp->dsp = 0; mp->channel = 0; while ( t < 100 ) { t++ ; cycle++; length = rand() & 2047; /* orig 4095 tim */ mp->len = length + sizeof(m_generic) / sizeof(int32); rand1 = rand(); rand2 = rand(); thiserr = 0; mp->data[0] = rand1; mp->data[1] = rand2; for(i = 2; i < length; i++) { mp->data[i] = mp->data[i-1] + mp->data[i-2]; #ifdef DEBUG if(i>240 && i<279) printf("i = %d, value = %x\n", i, mp->data[i]); #endif /* DEBUG */ } if ( send_mess ( (int32 *) mp) != SUCCESS ) printf("Error in send_mess, cycle = %d\n", cycle); m_wait(0); if ( get_mess (0) != SUCCESS ) printf ("Error in get_mess, cylcle = %d\n", cycle);; if ( rm->ciw != ECHO_REPLY ) { printf("Didn't get an echo reply!! ciw = %d\n", rm->ciw); continue; } for ( i = 0; i < length; i++ ) { #ifdef DEBUG if ( i > 240 && i < 279 ) printf("Rec' i = %d, value = %x\n", i, rm->data[i]); #endif /* DEBUG */ if ( mp->data[i] != rm->data[i] ) { printf("Bad echo data rec'd - message location %d\n", i); thiserr++; } } err += thiserr; if ( cycle % itell == 0 ) { printf("cycle %d complete. Message length = %d. Got %d errors. %d total error so far.\n", cycle, length, thiserr, err); if ( cycle / itell == 9 ) itell *= 10; } thiserr = 0; } } /* =================================================================== */ /* com_init sets up the pointers in the host's memory to the bases */ /* of the dual port rams. */ /* */ /* =================================================================== */ void set_ioBase (unsigned short *addr) { io_base[0] = (dpr *) addr; printf (" io base address: %lx\n", addr); } void com_init( void ) { int dipsw; printf ( "beginning initialization\n"); dipsw = 1; printf ("Using DIP switch = 1\n"); dipsw &= 0x1f; printf ( "About to clear signals\n"); io_base[0]->signals = 0; printf ("Initialization Complete \n"); } /* =================================================================== */ /* A sample host application. This just sends echo messages of */ /* random size and content to a dsp (currently only dsp 0) and */ /* checks the content of the echoed message for errors. */ /* =================================================================== */ /* For pseudo-random number generator */ /* unsigned long next = 17; /* unsigned int rand( void ); void srand( unsigned int ); /* ======================================================================= */ /* This is the main routine. All it does it call com_init, download */ /* the system to a range of dsps, then call do_echo, which loops forever */ /* sending and receiving echo messages. You may need to call this */ /* routine from a main() function, if your system requires such a thing. */ /* ======================================================================== */ void send_sys_ech (int dsp_min, int dsp_max, char *filnam) { int err; com_init(); if ( (err = init_dsps (dsp_min, dsp_max, filnam) ) != 0 ) { printf("error in send_sys_ech, err = %d", err); exit (-1); } printf (" \n System Download Complete \n"); } /* ============================================ */ /* */ /* ============================================ */ void srandom( unsigned int seed ) { extern unsigned long next; next = seed; } /* ============================================ */ /* */ /* ============================================ */ unsigned int random2( void ) { extern unsigned long next; next = next + 0x18e1a432; return (unsigned int ) next; }