void mcp23s17::writeWord(byte addr, uint16_t data){ startSend(0); SPI.transfer(addr); SPI.transfer(word2lowByte(data)); SPI.transfer(word2highByte(data)); endSend(); }
uint8_t mcp23s08::gpioRegisterReadByte(byte reg){ uint8_t data = 0; startSend(1); SPI.transfer(reg); data = SPI.transfer(0); endSend(); return data; }
uint8_t mcp23s08::readAddress(byte addr){ byte low_byte = 0x00; startSend(1); SPI.transfer(addr); low_byte = SPI.transfer(0x0); endSend(); return low_byte; }
uint16_t mcp23s17::readAddress(byte addr){ startSend(1); SPI.transfer(addr); byte low_byte = SPI.transfer(0x0); byte high_byte = SPI.transfer(0x0); endSend(); return byte2word(high_byte,low_byte); }
uint16_t mcp23s17::gpioRegisterReadWord(byte reg){ uint16_t data = 0; startSend(1); SPI.transfer(reg); data = SPI.transfer(0); data = SPI.transfer(0) << 8; endSend(); return data; }
void max7301::writeWord(byte addr, uint16_t data){ startSend(0); SPI.transfer(addr); #if !defined(__SAM3X8E__) && ((ARDUINO >= 160) || (TEENSYDUINO > 121)) SPI.transfer16(data); #else SPI.transfer(word2lowByte(data)); SPI.transfer(word2highByte(data)); #endif endSend(); }
uint16_t max7301::gpioRegisterReadWord(byte reg){ uint16_t data = 0; startSend(1); SPI.transfer(reg); #if !defined(__SAM3X8E__) && ((ARDUINO >= 160) || (TEENSYDUINO > 121)) data = SPI.transfer16(0); #else data = SPI.transfer(0); data = SPI.transfer(0) << 8; #endif endSend(); return data; }
uint16_t max7301::readAddress(byte addr){ startSend(1); SPI.transfer(addr); #if !defined(__SAM3X8E__) && ((ARDUINO >= 160) || (TEENSYDUINO > 121)) uint16_t temp = SPI.transfer16(0x0); endSend(); return temp; #else byte low_byte = SPI.transfer(0x0); byte high_byte = SPI.transfer(0x0); endSend(); uint16_t temp = low_byte | (high_byte << 8); return temp; #endif }
void mcp23s08::writeByte(byte addr, byte data){ startSend(0); SPI.transfer(addr); SPI.transfer(data); endSend(); }
/*! Starts sending the data to all the ranks */ void DataCommunicator::startAllSends() { for (int rank : m_sendRanks) { startSend(rank); } }
void MainWindow::updateImage() { //cap>>frame; //time1.stop(); if (receiveFlag == 0) { tempImg = cvQueryFrame(capture);//c++接口无法打开视频,利用c接口中转一下,所以需要将iplimage转换为Mat if (tempImg) rawFrame = Mat(tempImg); else { time1.stop(); return; } } if (!rawFrame.empty()) cv::resize(rawFrame,frame,Size(320,240)); else qDebug()<<"no images!"; // equalizeHist(frame,frame2); if(!frame.empty()) { //emit startSend(frame); double t=(double)cvGetTickCount(); switch (algorithmFlag) { case 0: divog.trackObject(frame,sailencyMap,motionMap); findFlag = divog.getFindAns(); break; case 1: sr.getSRsailencyMap(frame,sailencyMap,motionMap); findFlag = sr.getFindAns(); break; case 2: myft.getFTmap(frame,sailencyMap,motionMap,learnRate); findFlag = myft.getFindAns(); break; case 3: itti.getSailencyMapItti(frame,sailencyMap,motionMap); findFlag = itti.getFindAns(); break; case 4: lc.getLCsailencyMap(frame,sailencyMap,motionMap); findFlag = lc.getFindAns(); break; case 5: gmm.getGMMMap(frame,motionMap); findFlag = gmm.getFindAns(); //break; case 6: gmm.getGrayGMMMap(frame,motionMap); findFlag = gmm.getFindAns(); } if (sendFlag == 1) emit startSend(frame); if (findFlag == 1) emit detectSuccess(); else emit detectFailed(); t=((double)cvGetTickCount() - t)/(cvGetTickFrequency()*1000); fpsNum = 1000/t; //qDebug()<<fpsNum; cvtColor(frame, frame, CV_BGR2RGB); //getSailencyMap(frame,sailencyMap); //qDebug()<<sailencyMap.elemSize(); //qDebug()<<frame.elemSize(); //floatMap.convertTo(sailencyMap,CV_8U); //cvtColor(sailencyMap, sailencyMap, CV_BGR2RGB); this->update(); } //time1.start(); }
int main(int argc, char **argv) { unsigned int *data_samples; int i; int size; pd_device_t dev; void *memr, *mems; float throughput; struct timeval tv1,tv2; int mintime, curtime; printf("====================================\n"); printf("= DMA Throughput Test =\n"); printf("====================================\n\n"); if(argc != 2){ printf("Usage: %s [buffer size]\n",argv[0]); return -1; } size = atoi(argv[1]); if(size > 524288){ printf("Wohaa, easy there. Maximum buffer size is 262144\n"); return -1; } if(size % 4 != 0){ printf("Buffer size must be divisible by 4 bytes\n"); return -1; } printf("Buffer size: %d\n\n",size); if(pd_open(0,&dev) != 0){ printf("Failed to open file \n"); return -1; } printf("Device file opened successfuly\n"); // Allocate send and receive buffers posix_memalign( (void**)&memr, 16, size); posix_memalign( (void**)&mems, 16, size); //for(i=0;i<size/4;i++) // ((unsigned int*)mems)[i] = i; //for(i=0;i<size/4;i++) // ((unsigned int*)memr)[i] = 9; //-------------------------- if(initDMA(&dev) < 0) printf("Init DMA failed\n"); /* gettimeofday(&tv1,NULL); if(setupSend(&dev, (void*)mems, size) < 0) printf("Setup Send failed\n"); gettimeofday(&tv2,NULL); printf(">> Time taken to setup send transfer:%d\n", tv2.tv_usec - tv1.tv_usec); //-------------------------- gettimeofday(&tv1,NULL); if(setupRecv(&dev, memr, size) < 0) printf("Setup Recv failed\n"); gettimeofday(&tv2,NULL); printf(">> Time taken to setup receive transfer:%d\n", tv2.tv_usec - tv1.tv_usec); //-------------------------- gettimeofday(&tv1,NULL); if(startSend(&dev, 0) < 0) printf("DMA Send failed\n"); if(checkSend() < 0) printf("Check DMA send failed\n"); gettimeofday(&tv2,NULL); printf(">> Time taken to complete and check send transfer:%d\n", tv2.tv_usec - tv1.tv_usec); printf(">> Throughput: %f MB/s\n",(float)size/((float)(tv2.tv_usec - tv1.tv_usec))); //-------------------------- gettimeofday(&tv1,NULL); if(startRecv() < 0) printf("DMA Recv failed\n"); if(checkRecv() < 0) printf("Check DMA recv failed\n"); gettimeofday(&tv2,NULL); printf(">> Time taken to complete and check recv transfer:%d\n", tv2.tv_usec - tv1.tv_usec); printf(">> Throughput: %f MB/s\n",(float)size/((float)(tv2.tv_usec - tv1.tv_usec))); */ //-------------------------- // Send and receive in simultaneous mintime = 9999; for(i=0;i<NRUNS;i++){ gettimeofday(&tv1,NULL); if(setupSend(&dev, (void*)mems, size,1) < 0) printf("Setup Send failed\n"); if(setupRecv(&dev, (void*)memr, size) < 0) printf("Setup Recv failed\n"); gettimeofday(&tv2,NULL); printf("Time taken to setup receive AND send transfer:%d\n", tv2.tv_usec - tv1.tv_usec); //-------------------------- gettimeofday(&tv1,NULL); if(startRecv(&dev, 0) < 0) printf("DMA Recv failed\n"); if(startSend(&dev, 0) < 0) printf("DMA Send failed\n"); if(checkRecv() < 0) printf("Check DMA recv failed\n"); if(checkSend() < 0) printf("Check DMA send failed\n"); gettimeofday(&tv2,NULL); curtime = tv2.tv_usec - tv1.tv_usec; printf("Time taken to complete and check send AND receive transfer:%d\n", curtime); printf("Throughput: %f MB/s\n",(float)2*size/((float)(curtime))); freeSend(&dev); freeRecv(&dev); if(curtime < mintime) mintime = curtime; } stopDMA(&dev); //for(i=0;i<size/4;i++) // printf("%d ",((unsigned int*)memr)[i]); free(memr); free(mems); printf("Maximum throughput for %d points: %f MB/s\n",size,(float)2*size/((float)(mintime))); return 0; }
FileUI::FileUI(QWidget *parent) : QWidget(parent) { mData = new PrivData(); // 开始创建界面UI // 先创建接收界面 QFrame *frame1 = new QFrame(this); frame1->setWindowIconText(cns("接收")); QVBoxLayout *v1 = new QVBoxLayout(); QLabel *l1 = new QLabel(cns("接收总进度"), frame1); QLabel *l2 = new QLabel(cns("当前文件进度"), frame1); QProgressBar *bar1 = new QProgressBar(frame1); bar1->setMaximum(100); bar1->setMinimum(0); bar1->setValue(0); connect(this, SIGNAL(signalRecvTotalProgress(int)), bar1, SLOT(setValue(int))); QProgressBar *bar2 = new QProgressBar(frame1); bar2->setMaximum(100); bar2->setMinimum(0); bar2->setValue(0); connect(this, SIGNAL(signalRecvCurrentProgress(int)), bar2, SLOT(setValue(int))); mRecvMsg = new QLabel(cns("接收消息..."), frame1); QFont f; f.setPixelSize(10); mRecvMsg->setFont(f); QPushButton *pb1 = new QPushButton(cns("停止接收"), frame1); connect(pb1, SIGNAL(clicked()), this, SLOT(stopRecv())); QPushButton *pb4 = new QPushButton(cns("打开文件夹"), frame1); connect(pb4, SIGNAL(clicked()), this, SLOT(openPath())); mRecvList = new QListWidget(frame1); QHBoxLayout *rhb1 = new QHBoxLayout(); QHBoxLayout *rhb2 = new QHBoxLayout(); rhb1->addWidget(l1, 0, Qt::AlignCenter); rhb1->addWidget(bar1, 0, Qt::AlignCenter); rhb2->addWidget(l2, 0, Qt::AlignCenter); rhb2->addWidget(bar2, 0, Qt::AlignCenter); v1->addLayout(rhb1); v1->addLayout(rhb2); v1->addWidget(mRecvMsg, 0, Qt::AlignLeft | Qt::AlignTop); v1->addWidget(mRecvList); QHBoxLayout *h2 = new QHBoxLayout(); h2->addWidget(pb1); h2->addWidget(pb4); v1->addLayout(h2); frame1->setLayout(v1); QStatusBar *status1 = new QStatusBar(frame1); mRecvLabel = new QLabel(cns("接收速度:0MB/s"), frame1); status1->addPermanentWidget(mRecvLabel); frame1->layout()->addWidget(status1); // 再创建发送界面 QFrame *frame2 = new QFrame(this); frame2->setWindowIconText(cns("发送")); QLabel *l4 = new QLabel(cns("发送总进度"), frame2); QLabel *l5 = new QLabel(cns("当前文件进度"), frame2); QProgressBar *bar3 = new QProgressBar(frame2); bar3->setMaximum(100); bar3->setMinimum(0); bar3->setValue(0); connect(this, SIGNAL(signalSendTotalProgress(int)), bar3, SLOT(setValue(int))); QProgressBar *bar4 = new QProgressBar(frame2); bar4->setMaximum(100); bar4->setMinimum(0); bar4->setValue(0); connect(this, SIGNAL(signalSendCurrentProgress(int)), bar4, SLOT(setValue(int))); mSendMsg = new QLabel(cns("发送消息..."), frame2); mSendMsg->setFont(f); QPushButton *pb2 = new QPushButton(cns("开始发送"), frame2); connect(pb2, SIGNAL(clicked()), this, SLOT(askSend())); QPushButton *pb3 = new QPushButton(cns("停止发送"), frame2); connect(pb3, SIGNAL(clicked()), this, SLOT(stopSend())); mClear = new QPushButton(cns("清空列表"), frame2); connect(mClear, SIGNAL(clicked()), this, SLOT(clearList())); mList = new QListWidget(frame2); connect(mList, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(itemDoubleClicked(QListWidgetItem*))); QVBoxLayout *v2 = new QVBoxLayout(); QHBoxLayout *shb1 = new QHBoxLayout(); QHBoxLayout *shb2 = new QHBoxLayout(); shb1->addWidget(l4, 0, Qt::AlignCenter); shb1->addWidget(bar3, 0, Qt::AlignCenter); shb2->addWidget(l5, 0, Qt::AlignCenter); shb2->addWidget(bar4, 0, Qt::AlignCenter); v2->addLayout(shb1); v2->addLayout(shb2); v2->addWidget(mSendMsg, 0, Qt::AlignLeft | Qt::AlignTop); QHBoxLayout *h1 = new QHBoxLayout(); h1->addWidget(pb2); h1->addWidget(pb3); h1->addWidget(mClear); v2->addWidget(mList); v2->addLayout(h1); frame2->setLayout(v2); QStatusBar *status2 = new QStatusBar(frame2); mSendLabel = new QLabel(cns("发送速度:0MB/s"), frame2); status2->addPermanentWidget(mSendLabel); frame2->layout()->addWidget(status2); QVBoxLayout *v3 = new QVBoxLayout(); v3->addWidget(frame1); QSpacerItem *item = new QSpacerItem(192, 10); v3->addSpacerItem(item); v3->addWidget(frame2); setLayout(v3); // resize(192, 372); // 连接信息 connect(mData->opt, SIGNAL(recvInformation(QString,QString)), this, SLOT(recvInfo(QString,QString))); connect(mData->opt, SIGNAL(sendInformation(QString,QString)), this, SLOT(sendInfo(QString,QString))); connect(mData->opt, SIGNAL(recvFilesProgress(int)), this, SIGNAL(signalRecvTotalProgress(int))); connect(mData->opt, SIGNAL(recvCurrentFileProgress(int)), this, SIGNAL(signalRecvCurrentProgress(int))); connect(mData->opt, SIGNAL(sendFilesProgress(int)), this, SIGNAL(signalSendTotalProgress(int))); connect(mData->opt, SIGNAL(sendCurrentFileProgress(int)), this, SIGNAL(signalSendCurrentProgress(int))); connect(this, SIGNAL(signalStartSend()), this, SLOT(startSend())); connect(mData->opt, SIGNAL(signalRecvPreInfo(QStringList)), this, SLOT(insertRecvFile(QStringList))); connect(mData->opt, SIGNAL(signalRecvStart()), this, SLOT(recvstart())); connect(mData->opt, SIGNAL(signalRecvSuccess()), this, SLOT(recvsuccess())); connect(mData->opt, SIGNAL(signalSendStart()), this, SLOT(sendstart())); connect(mData->opt, SIGNAL(signalSendSuccess()), this, SLOT(sendsuccess())); connect(mData->opt, SIGNAL(sendFileSpeed(float)), this, SLOT(sendSpeed(float))); connect(mData->opt, SIGNAL(recvFileSpeed(float)), this, SLOT(recvSpeed(float))); }
int main(int argc, char **argv) { unsigned int *data_samples; int i,val,j; int size, new_size; pd_device_t dev; void *memr, *mems, *mem_new; float throughput; struct timeval tv1,tv2; int mintime, curtime, vsize; printf("====================================\n"); printf("= Pattern Tests =\n"); printf("====================================\n\n"); if(pd_open(0,&dev) != 0){ printf("Failed to open file \n"); return -1; } printf("Device file opened successfuly\n"); // Allocate send and receive buffers size = 4*1024*1024; // 32x32 matrix with 4 byte entries posix_memalign( (void**)&memr, 16, size); posix_memalign( (void**)&mems, 16, size); //for(i=0;i < size/4; i++){ // ((int*)mems)[i] = i; // printf("%d ",((int*)mems)[i]); //} /* vsize = 1; for(i=1; i < 16; i++) { mintime = 99999; for(j=0; j < 500; j++) { gettimeofday(&tv1,NULL); compressData(mems, &mem_new, &new_size, 0, 4, 120, vsize); gettimeofday(&tv2,NULL); curtime = tv2.tv_usec - tv1.tv_usec; if (curtime < mintime) mintime = curtime; free(mem_new); } printf("Total Size: %d, Time elapsed: %d\n", new_size, mintime); vsize *= 2; } return; */ // Each 5x5 subblock will hold the same value val = 0; for(i=0; i < size/4; i++){ if (i % 16 == 0 && i!=0) val ++; val = val % 2; ((int *)mems)[i] = val; } // Test matrix for(i=0; i < size/4; i++){ if (i%32 == 0 && i!=0) printf("\n"); printf("%d ", ((int*)mems)[i]); } //-------------------------- if(initDMA(&dev) < 0) printf("Init DMA failed\n"); // Send and receive in simultaneous gettimeofday(&tv1,NULL); #ifdef SEND if(setupSend(&dev, (void*)mems, size,1) < 0) printf("Setup Send failed\n"); if(applyBlocking_send(16, 32, 4) < 0) printf("Apply Blocking send failed\n"); #endif if(setupRecv(&dev, (void*)memr, size) < 0) printf("Setup Recv failed\n"); //int applyLinear_recv(int offset, int hsize, int stride, int total_size); // if(applyBlocking_recv(16, 32, 4) < 0) if(applyLinear_recv(0,128,128,4096) < 0) printf("Apply Blocking recv failed\n"); gettimeofday(&tv2,NULL); printf("Time taken to setup receive AND send transfer:%d\n", tv2.tv_usec - tv1.tv_usec); //-------------------------- gettimeofday(&tv1,NULL); #ifdef SEND //if(startSend(&dev, 0) < 0) // printf("DMA Send failed\n"); #endif // printf("Press any key to continue ;)\n"); // getchar(); if(startRecv(&dev, 0) < 0) printf("DMA Recv failed\n"); if(startSend(&dev, 0) < 0) printf("DMA Send failed\n"); if(checkRecv() < 0) printf("Check DMA recv failed\n"); #ifdef SEND if(checkSend() < 0) printf("Check DMA send failed\n"); #endif gettimeofday(&tv2,NULL); curtime = tv2.tv_usec - tv1.tv_usec; printf("Time taken to complete and check send AND receive transfer:%d\n", curtime); printf("Throughput: %f MB/s\n",(float)2*size/((float)(curtime))); // Test matrix for(i=0; i < size/4; i++){ if (i%32 == 0 && i!=0) printf("\n"); printf("%d ", ((int*)memr)[i]); } freeSend(&dev); freeRecv(&dev); stopDMA(&dev); //for(i=0;i<size/4;i++) // printf("%d ",((unsigned int*)memr)[i]); free(memr); free(mems); return 0; }