#ifdef WIN32 #include #else #define HANDLE int #endif #include #include "os_arb_interface.h" #include #include #include void print_binary(int num, int length){ int A; for(A=length-1;A >=0;A--){ if(A%8 == 7) printf(" "); if(num >> A & 1) printf("1"); else printf("0"); } } #define blocksize 0x3ff void block_load(HANDLE hCom, int* buffer, int length, int start){ int mini_length; int buffer_index = 0; int mini_index; int result; while(length > 0){ if(length > blocksize) mini_length = blocksize; else mini_length = length; for(mini_index=0;mini_index < mini_length;mini_index++){ Write_ARB_USB(hCom, mini_index+0x400, buffer[buffer_index++]); } Write_ARB_USB(hCom,0x7,0xffff & start); Write_ARB_USB(hCom,0x8,0xffff & (start >> 16)); Write_ARB_USB(hCom,0x9,mini_length-1); Write_ARB_USB(hCom,0xa,0x6); start += mini_length; length -= mini_length; do { Read_ARB_USB(hCom,0xa,&result); } while(result & 0x1); } } void test_comm_link(HANDLE hCom){ int A,B,C; int TX_error = 0; int RX_error = 0; int NO_error = 0; int total = 0; Write_ARB_USB(hCom,0x1,0x0000);//Disable DAC for(A=0x0000;A<0xfff;A+=0x1){ Write_ARB_USB(hCom,0x2,A); if(1){ total++; B=0; C=0; if(!Read_ARB_USB(hCom,0x2,&B)) Write_ARB_USB(hCom,0xb,0); if(A != B){ Read_ARB_USB(hCom,0x2,&C); printf("\n\nTX "); print_binary(A,16); printf("\nRX "); print_binary(B,16); printf("\nRX "); print_binary(C,16); if(B==C) ++TX_error; else ++RX_error; printf("\nTX %d RX %d Good %d\n", TX_error,RX_error,NO_error); } else { //printf("."); NO_error++; if(total%100 == 0) printf("\nTX %d RX %d Good %d Total %d\n", TX_error,RX_error,NO_error,total); } } //if(A >= 0xffff) A = 0; Write_ARB_USB(hCom,0x1,0x0001);//enable DAC } } void enable_arb_output(HANDLE hCom){ Write_ARB_USB(hCom,0x1,0x0001);//enable } void disable_arb_output(HANDLE hCom){ Write_ARB_USB(hCom,0x1,0x0000); //disable } void set_prescaler_value(HANDLE hCom){ int prescaler; printf("\nenter new prescaler value: "); scanf("%d",&prescaler); Write_ARB_USB(hCom,0x3,prescaler & 0xffff); //clock prescaler Write_ARB_USB(hCom,0x4,(prescaler >> 16) & 0xffff); } void set_end_address_value(HANDLE hCom){ int value; printf("\nenter new end address value: "); scanf("%d",&value); Write_ARB_USB(hCom,0x5,value & 0xffff); //end address Write_ARB_USB(hCom,0x6,(value >> 16) & 0xffff); } void load_square(HANDLE hCom){ Write_ARB_USB(hCom,0x1,0x0000); //disable //Write_ARB_USB(hCom,0x2,0x2); //enable direct SRAM accesses Write_ARB_USB(hCom,0x400,0x7000); Write_ARB_USB(hCom,0x401,0x9000); //Write_ARB_USB(hCom,0x2,0x0); //disable direct SRAM accesses Write_ARB_USB(hCom,0x7,0x0); Write_ARB_USB(hCom,0x8,0x0); Write_ARB_USB(hCom,0x9,1); Write_ARB_USB(hCom,0xa,0x6); Write_ARB_USB(hCom,0x5,0x0001); //end address Write_ARB_USB(hCom,0x6,0x0000); Write_ARB_USB(hCom,0x3,0x0007); //clock prescaler Write_ARB_USB(hCom,0x4,0x0000); Write_ARB_USB(hCom,0x1,0x0001);//enable } void load_triangle(HANDLE hCom){ int value; int A; int step; printf("\nenter length of triangle wave: "); scanf("%d",&value); int result; Write_ARB_USB(hCom,0x1,0x0000); //disable DAC //Write_ARB_USB(hCom,0x2,0x2); //enable direct SRAM accesses for(A=0;A> 16); Write_ARB_USB(hCom,0x3,0x0003); //clock prescaler Write_ARB_USB(hCom,0x4,0x0000); do { Read_ARB_USB(hCom,0xa,&result); } while(result & 0x1); Write_ARB_USB(hCom,0x1,0x0001);//enable } void load_sine(HANDLE hCom){ int length,result; int A; int* buffer; printf("\nenter length of sine wave: "); scanf("%d",&length); if(length > 0 && length <= 1<<19){ buffer = (int*)malloc(length * sizeof(int)); if(buffer == NULL) { printf("no memory available\n"); return; } } else { printf("bad size\n"); return; } for(A=0;A> 16)); Write_ARB_USB(hCom,0x3,0x0003); //clock prescaler Write_ARB_USB(hCom,0x4,0x0000); //do { Read_ARB_USB(hCom,0xa,&result); } while(result & 0x1); Write_ARB_USB(hCom,0x1,0x0001);//enable DAC } void read_register(HANDLE hCom){ int result; int prescale,endaddr,ima_base; Read_ARB_USB(hCom,0x0,&result); printf("Interface Control Register is %x\n",result); Read_ARB_USB(hCom,0x1,&result); printf("DAC enable Register is %x\n",result); Read_ARB_USB(hCom,0x2,&result); printf("Dummy test Register is %x\n",result); Read_ARB_USB(hCom,0x3,&result); printf("Prescaler LSW Register is %x\n",result); prescale = result; Read_ARB_USB(hCom,0x4,&result); printf("Prescaler MSW Register is %x\n",result); prescale |= (result<<16); Read_ARB_USB(hCom,0x5,&result); printf("End Address LSW Register is %x\n",result); endaddr = result; Read_ARB_USB(hCom,0x6,&result); printf("End Address MSW Register is %x\n",result); endaddr |= (result << 16)&0x70000; Read_ARB_USB(hCom,0x7,&result); printf("ima base LSW Register is %x\n",result); ima_base = result; Read_ARB_USB(hCom,0x8,&result); printf("ima base MSW Register is %x\n",result); ima_base |= (result << 16) & 0x70000; Read_ARB_USB(hCom,0x9,&result); printf("ima length Register is %x\n",result); Read_ARB_USB(hCom,0xa,&result); printf("ima status Register is %x\n",result); Read_ARB_USB(hCom,0xb,&result); printf("PCI status Register is %x\n",result); Read_ARB_USB(hCom,0xc,&result); printf("PCI base address Register is %x\n",result); printf("Prescaler: %dd %xh\n",prescale,prescale); printf("End Addr: %dd %xh\n",endaddr,endaddr); printf("IMA Base address: %dd %xh\n",ima_base,ima_base); } void read_ram(HANDLE hCom){ int result,address; Write_ARB_USB(hCom,0x1,0x0000); //disable DAC Write_ARB_USB(hCom,0x7,0x0); Write_ARB_USB(hCom,0x8,0x0); Write_ARB_USB(hCom,0x9,0x39); Write_ARB_USB(hCom,0xa,0x4); printf("\nRAM dump:"); do { Read_ARB_USB(hCom,0xa,&result); } while(result & 0x1); for(address = 0x00; address < 0x40; address++){ Read_ARB_USB(hCom,0x400+address,&result); if(address % 8 == 0) printf("\n0x%02x: ",address); printf("%x ",result); } Write_ARB_USB(hCom,0x1,0x0001); //enable DAC printf("\n\n"); } void read_ram_many(HANDLE hCom){ int result,address; int start; int size; printf("Enter address to start at (hex):"); scanf("%x",&start); printf("Enter length to view (hex):"); scanf("%x",&size); Write_ARB_USB(hCom,0x1,0x0000); //disable dac Write_ARB_USB(hCom,0x7,start & 0xffff); Write_ARB_USB(hCom,0x8,(start & 0x70000) >> 16 ); Write_ARB_USB(hCom,0x9,size); Write_ARB_USB(hCom,0xa,0x4); printf("\nRAM dump:"); for(address = 0; address < size; address++){ Read_ARB_USB(hCom,address+0x400,&result); if(address % 8 == 0) printf("\n0x%02x: ",address + start); printf("%x ",result); } Write_ARB_USB(hCom,0x1,0x0001); //enable dac printf("\n\n"); } void ram_test(HANDLE hCom){ int address; int size = 0x40; int result; int start = 0; for(address = 0; address < size; address++){ Read_ARB_USB(hCom,address+0x400,&result); if(address % 8 == 0) printf("\n0x%02x: ",address + start); printf("%x ",result); } printf("\n\n"); } void clear_ram(HANDLE hCom){ /*int address; int start; int size; printf("Enter address to start at (hex):"); scanf("%x",&start); printf("Enter length to clear (hex):"); scanf("%x",&size); Write_ARB_USB(hCom,0x1,0x0000); //disable dac Write_ARB_USB(hCom,0x2,0x2); //enable direct SRAM accesses for(address = start; address < start+size; address++){ Write_ARB_USB(hCom,address,0); } Write_ARB_USB(hCom,0x2,0x0); //disable direct SRAM accesses Write_ARB_USB(hCom,0x1,0x0001); //enable dac printf("done\n");*/ printf("Null\n"); } void set_ram(HANDLE hCom){ int address; int data; printf("Enter address (hex):"); scanf("%x",&address); printf("Enter value (hex):"); scanf("%x",&data); //Write_ARB_USB(hCom,0x1,0x0000); //disable dac Write_ARB_USB(hCom,address,data); //Write_ARB_USB(hCom,0x1,0x0001); //enable dac } int main(int numargs, char**args){ HANDLE hCom; char menu_item; char mennnuuuu[10]; char devicename[20]; if(!strncmp(args[0]+2,"sap",3)) strcpy(devicename,"/dev/ARB_DEV0"); else strcpy(devicename,"/dev/ttyUSB0"); hCom = open_usb_port(devicename); if(hCom == -1) { printf("failed to open port %s\n",devicename); return -1; } do{ printf("\nControl: 1: test comm link\n"); printf(" 2: enable ARB output "); printf(" 3: disable ARB output\n"); printf(" 4: set prescaler value "); printf(" 5: set end address value\n"); printf(" 6: load f/2 square wave "); printf(" 7: load triangle wave\n"); printf(" 8: load sine wave "); printf(" 9: read dac controls\n"); printf(" 0: read dac ram "); printf(" a: read dac ram buffer\n"); printf(" b: read dac ram (many) "); printf(" c: clear dac ram\n"); printf(" d: set dac ram\n"); printf(" q: quit\n"); //while(!_kbhit()); //menu_item = getch();//scanf("%c",&menu_item); scanf("%s",mennnuuuu); menu_item = mennnuuuu[0]; switch(menu_item){ case '1': test_comm_link(hCom); break; case '2': enable_arb_output(hCom); break; case '3': disable_arb_output(hCom); break; case '4': set_prescaler_value(hCom); break; case '5': set_end_address_value(hCom); break; case '6': load_square(hCom); break; case '7': load_triangle(hCom); break; case '8': load_sine(hCom); break; case '9': read_register(hCom); break; case '0': read_ram(hCom); break; case 'a': ram_test(hCom); break; case 'b': read_ram_many(hCom); break; case 'c': clear_ram(hCom);break; case 'd': set_ram(hCom);break; } } while (menu_item != 'q'); close_usb_port(hCom); return 0; }