Beispielquelltexte für USB-BITP-200
// ****************************************************************************
// ****************************************************************************
// ****************************************************************************
// ****************************************************************************
// ****************************************************************************
//
// (c) DEDITEC GmbH, 2009
//
// web: http://www.deditec.de
//
// mail: vertrieb@deditec.de
//
//
//
// bit-pattern-demo1.cpp
//
//
// ****************************************************************************
// ****************************************************************************
// ****************************************************************************
// ****************************************************************************
// ****************************************************************************
// Anweisung zum compilieren:
// ----------------------------------------
// Folgende DDL'S beim Linken mit einbinden
// DELIB.LIB (bindet dann DELIB.DLL mit ein)
//
//
#include "windows.h"
#include
#include "malloc.h"
#include "delib.h"
#include "bit-pattern_functions.h"
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
void main()
{
ULONG ret;
ULONG i;
ULONG anz=10;
ULONG device_nr=1;
ULONG err=0;
ULONG handle;
ULONG ok;
ULONG a;
ULONG d0;
unsigned char * buff;
// Configuration
BP_Configuration bp_conf;
// ----------------------------------------------------
// Open Bit Pattern Generator
handle = DapiOpenModule(USB_BITP_200,0);
if(handle==0)
{
printf("No Module found\n");
printf("press any key\n");
getch();
return;
}
// ----------------------------------------------------
// Send ping to test the connection to the USB-device
printf("PING\n");
anz=100;
for(i=0;i!=anz;++i)
{
ret=DapiPing(handle, i); // DapiPing should return the value i
if(i==ret)
{
printf(".");
}
else
{
printf("E");
}
}
printf("\n");
// ----------------------------------------------------
// Test Memory
printf("Memory Test\n");
bp_memory_test(handle, 8*1024); // Teste den Speicher für max 512*1024
// ----------------------------------------------------
// Memory alloc for Pattern
buff = (unsigned char *) malloc(512 * 1024*5); // Memory of Bit Pattern Generator
if(buff == 0)
{
printf("malloc buff Error\n");
getch();
return;
}
// ----------------------------------------------------
// Generate Test-Data
printf("Write Pattern Data to allocated-memory\n");
ULONG memory_lines = 100;
for(i=0;i!=memory_lines;++i)
{
// Test Data (counter-values)
d0 = i & 0xffff;
d0|= ((~i) & 0xffff)<<16; // Inverted Data
*(buff + i*5 + 0) = (unsigned char) (d0>>0) & 255;
*(buff + i*5 + 1) = (unsigned char) (d0>>8) & 255;
*(buff + i*5 + 2) = (unsigned char) (d0>>16) & 255;
*(buff + i*5 + 3) = (unsigned char) (d0>>24) & 255;
*(buff + i*5 + 4) = (unsigned char) (d0>>24) & 255;
}
// ----------------------------------------------------
// Transfere Memory to Hardware
ok=bp_write_ram(handle, buff, memory_lines*5); //buff= memory adress, memory_lines*5 (36 Bit need 5 Bytes) -> size in Bytes
printf("Memory Data written to Bit Pattern Generator\n");
// ----------------------------------------------------
// Reset Hardware
bp_api_stop(handle);
// ----------------------------------------------------
// Set configuration
bp_conf.ram_adress_start = 2; // Set start address (only even addresses are valid)
bp_conf.ram_adress_stop = 22; // Set stop address (only even addresses are valid)
bp_conf.repeat_nr = 1; // counter for repeats (if = 0 -> don't stop output)
//bp_conf.sample_clock_divider = 0; // Ausgangstakt - Teiler für max. speed
bp_conf.sample_clock_divider = 76; // Ausgangstakt - Teiler für 1 MHZ Takt
//bp_conf.sample_clock_divider = 75757572; // Ausgangstakt - Teiler für 1sec Takt
// clock_divider T [ns]
// ------------------------
// 0 6,6ns
// 1 53ns
// 2 66ns
// 3 80ns
// 5 105ns
// Formel:
// Ausgangstakt T[ns] = (3 + clock_divider) * 2 * 6,6 ns
bp_api_set_configuration(handle, bp_conf); // Configure Bit-Pattern Generator
// ----------------------------------------------------
// Start Bit Pattern generation
printf("Start Bit Pattern Generator now ...\n");
bp_api_start(handle);
// ----------------------------------------------------
// Check status
a=bp_api_get_status(handle);
printf("Sm=%x\n", a);
do
{
a=bp_get_adr_cnt(handle);
printf("RD Adress-Counter=%x bp_sm=%x ext_ram_sm=%x\n", bp_get_adr_cnt(handle), bp_get_bp_sm(handle), bp_get_ext_ram_sm(handle));
//getch();
} while((!kbhit()) && (bp_get_bp_sm(handle) != 2));
// ----------------------------------------------------
// Reset Hardware
bp_api_stop(handle);
printf("any key to leave demo\n");
getch();
// ----------------------------------------------------
// Close Hardware
DapiCloseModule(handle);
free(buff);
return ;
}