00001
00031 #include <iostream>
00032 #include <string>
00033 #include <time.h>
00034
00035 #include "usbp_pbrd_v01.h"
00036 #include "usbp.h"
00037 #include "usbp_cyusb.h"
00038 #include "upl_err.h"
00039 #include "config_files.h"
00040
00041
00042
00047
00048
00049
00058 int USBP_PBRD_V01::PyWriteData(BP::list& pyList)
00059 {
00060 byte wb[MAX_LEN];
00061 int err = UPL_OK;
00062
00063 int len = BP::extract<int>(pyList.attr("__len__")());
00064
00065 if(len > MAX_LEN){
00066 fprintf(stderr, "Error: Only Max 512 bytes supported\n");
00067 return UPL_ERR;
00068 }
00069 else if (len == 1){
00070 fprintf(stderr, "Error: Need more than 1 byte of data to send\n");
00071 fprintf(stderr, " Sending [0] more than once\n");
00072 }
00073
00074 for(int i=0; i<len; i++){
00075 wb[i] = BP::extract<unsigned char>(pyList[i]);
00076 printf("Extracted %d[%d]\n",wb[i], i);
00077 }
00084 if(len <= 1){
00085 fprintf(stderr, " -- Length Needs to be greater than one, appending\n");
00086 while(len <= 1){
00087 wb[len++] = BP::extract<unsigned char>(pyList[0]);;
00088 }
00089 len = 2;
00090 }
00091
00092 if(UsbD){
00093 err = UsbFpga->writeData(wb, len);
00094 if(err)
00095 fprintf(stderr, "-- WRITE of Bytes to FPGA (EP4) FAILED %d\n", err);
00096 }
00097
00098 return err;
00099 }
00100
00112 int USBP_PBRD_V01::PyReadData(BP::list& pyList)
00113 {
00114 byte rb[MAX_LEN];
00115 int err = UPL_OK;
00116
00117 int len = BP::extract<int>(pyList.attr("__len__")());
00118
00119 if(len > MAX_LEN){
00120 fprintf(stderr, "Only Max 512 bytes supported\n");
00121 return UPL_ERR;
00122 }
00123
00124 if(UsbD){
00125 err = UsbFpga->readData(rb, len);
00126 if(err)
00127 fprintf(stderr, "-- Read of Bytes to FPGA (EP8) FAILED %d\n", err);
00128 }
00129
00130 for(int i=0; i<len; i++){
00131 if(err)
00132 pyList.append(-1);
00133 else
00134 pyList.append(rb[i]);
00135 }
00136
00137 return err;
00138 }
00139
00144 int USBP_PBRD_V01::WriteReg(int addr, int data)
00145 {
00146 int err = UPL_OK;
00147
00148 return err;
00149 }
00150
00156 int USBP_PBRD_V01::ReadReg(int addr, int& data)
00157 {
00158 int err = UPL_OK;
00159
00160
00161
00162
00163
00164 return err;
00165 }
00172 int USBP_PBRD_V01::testFPGAXfer(int data)
00173 {
00174 int err = UPL_OK;
00175 byte wb[2];
00176
00177 wb[0] = (byte)data;
00178 wb[1] = (byte)data;
00179 if(UsbD){
00180 err = UsbFpga->writeData(wb, 2);
00181 if(err)
00182 fprintf(stderr, "-- WRITE of Bytes to FPGA (EP4) FAILED %d\n", err);
00183 }
00184
00185
00186 return err;
00187 }
00188
00196 int USBP_PBRD_V01::testFPGAXferSpeed()
00197 {
00198 int i;
00199 int err = UPL_OK;
00200 byte wb[512];
00201
00202
00203 for(i=0; i<512; i++){
00204 wb[i] = (i%2) ? 0x55 : 0xAA;
00205 }
00206
00207 for(i=0; i<5000; i++){
00208 if(UsbD){
00209 err = UsbFpga->writeData(wb, 512);
00210 if(err)
00211 fprintf(stderr, "-- WRITE of Bytes to FPGA (EP4) FAILED %d\n", err);
00212 }
00213 }
00214
00215
00216 return err;
00217 }
00218
00219
00227 int USBP_PBRD_V01::testXferLoopback(int x)
00228 {
00229 int i,j;
00230 int err = UPL_OK;
00231 byte wb[512], rb[512];
00232
00234
00235 wb[0] = 0; wb[1] = 1;
00236 for(i=2; i<512; i++){
00237 wb[i] = wb[i-2] + wb[i-1];
00238 }
00239
00240 if(UsbD){
00241 err = UsbFpga->writeData(wb, x);
00242 if(err)
00243 fprintf(stderr, "-- WRITE of Bytes to FPGA (EP4) FAILED %d\n", err);
00244
00245 err = UsbFpga->readData(rb, x);
00246 if(err)
00247 {
00248 fprintf(stderr, "-- READ of Bytes from FPGA (EP2) FAILED %d\n", err);
00249 }
00250 else{
00251 for(i=0; i<512; i=i+16){
00252 for(j=0; j<16; j++){
00253 printf("%02X[%02X] ",wb[i+j], rb[i+j]);
00254 }
00255 printf("\n");
00256 }
00257 }
00258 }
00259
00260 return err;
00261 }
00262
00263
00264 #if 0
00269 int USBP_PBRD_V01::xferTestStart()
00270 {
00271 int err = UPL_OK;
00272
00274
00275 return err;
00276 }
00277
00282 int USBP_PBRD_V01::xferTestStop()
00283 {
00284 int err = UPL_OK;
00285
00286
00287
00288 return err;
00289 }
00290
00295 int USBP_PBRD_V01::xferTestGet()
00296 {
00297 int err = UPL_OK;
00298
00299
00300
00301 return err;
00302 }
00303
00308 int USBP_PBRD_V01::xferTestThread()
00309 {
00310 int err = UPL_OK;
00311
00312
00313 byte wb[1], rb[1];
00314
00316 wb[0] = (byte)x;
00317
00318 if(UsbD){
00319 err = UsbFpga->writeData(wb, 1);
00320 if(err)
00321 fprintf(stderr, "-- WRITE of Bytes to FPGA (EP2) FAILED %d\n", err);
00322
00323
00324
00325
00326
00327
00328 }
00329
00330 return err;
00331 }
00332
00333
00334
00335 #endif