📄 ixm1200hpc.c
字号:
if (binfo->interface == HPC_NONE) { semGive(hpcGlobalState.commonSem); return HPC_NOT_OPENED; } *mode = binfo[0].ibMode; semGive(hpcGlobalState.commonSem); return HPC_OK;}HPC_ERROR_CODEhpcStartio(int channelNum){ /* we don't want to take the common semaphore here, in case we're called from ISR priority. */ int buffNum = channelNum * QUEUES_PER_CHANNEL + HPC_TX_OFFSET; HPC_BUFFER_INFO *binfo = &hpcGlobalState.bufferInfo[buffNum]; if ( binfo->interface != HPC_SIO ) { if ( binfo->interface == HPC_NONE ) return HPC_NOT_OPENED; else return HPC_WRONG_MODE; } binfo->txWaiting = TRUE; semGive(hpcGlobalState.DPCSem); return HPC_OK;}HPC_ERROR_CODEhpcReadwrite(int channelNum, HPC_OP op, unsigned char *buff, int buffsize, unsigned int *bytesUsed, HPC_IRP *userIrp){ int buffNum = channelNum * QUEUES_PER_CHANNEL; HPC_BUFFER_INFO *binfo; HPC_IRP *irp; HPC_ERROR_CODE result; if (buffsize < 1) return HPC_INVALID_SIZE; if (op == HPC_WRITE) buffNum += HPC_TX_OFFSET; else if (op == HPC_READ) buffNum += HPC_RX_OFFSET; else return HPC_INVALID_OP; binfo = &hpcGlobalState.bufferInfo[buffNum]; if (!userIrp) { semTake(binfo->irpSem, WAIT_FOREVER); } semTake(hpcGlobalState.commonSem, WAIT_FOREVER); if ( binfo->interface != HPC_W32 ) { semGive(hpcGlobalState.commonSem); if (!userIrp) semGive(binfo->irpSem); if ( binfo->interface == HPC_NONE ) { return HPC_NOT_OPENED; } else { return HPC_WRONG_MODE; } } if (userIrp) { irp = userIrp; } else { irp = &binfo->irp; } irp->buff = buff; irp->incomplete = 0; if (buffsize & HPC_IB_BIT) { irp->incomplete = 1; CLEAR(buffsize, HPC_IB_BIT); } irp->bSize = buffsize; irp->bUsed = 0; semTake(irp->done, NO_WAIT); /* make sure it is taken */ irp->returnStatus = HPC_PENDING; HPC_QUEUE_PUSH(&binfo->queue, irp); SET(configStatus->IXM1200IsWaitingMask, binfo->waitingMask); semGive(hpcGlobalState.DPCSem); semGive(hpcGlobalState.commonSem); if (!userIrp) { /* block on IRP */ semTake(irp->done, WAIT_FOREVER); *bytesUsed = irp->bUsed; result = irp->returnStatus; semGive(binfo->irpSem); return result; } return HPC_PENDING;}HPC_ERROR_CODEhpcGetIrpStatus( HPC_IRP *irp, unsigned int *bytesUsed, BOOL wait ){ HPC_ERROR_CODE returnStatus; if (wait) semTake(irp->done, WAIT_FOREVER); semTake(hpcGlobalState.commonSem, WAIT_FOREVER); *bytesUsed = irp->bUsed; returnStatus = irp->returnStatus; semGive(hpcGlobalState.commonSem); return returnStatus;}voidhpcInitIrp( HPC_IRP *irp){ irp->done = semBCreate(SEM_Q_FIFO, SEM_EMPTY); irp->returnStatus = HPC_OK; irp->bUsed = 0;}HPC_ERROR_CODEhpcDeleteIrp( HPC_IRP *irp){ if (irp->returnStatus == HPC_PENDING) return HPC_PENDING; semDelete(irp->done); return HPC_OK;}#ifdef TESTVOID pciInt(int irq);voidhpcStartup(){ /* To be done before PCI starts up */ hpcMemInit(); /* To be done after OS starts up */ IXM1200_PCI_REG_WRITE(IXM1200_DBELL_PCI_MASK, 0); IXM1200_PCI_REG_WRITE(IXM1200_DBELL_SA_MASK, 0); intConnect((void*)INT_VEC_DFH, pciInt, INT_VEC_DFH); intEnable(INT_VEC_DFH); hpcSysInit();}#define BSIZE 40#define BSIZE2 1024#define NBUFFS 3voidhpcRecPkts(int n){ HPC_ERROR_CODE rc; unsigned char buf[BSIZE]; int i; unsigned int j, bytesUsed; rc = hpcClose(1); if (rc != HPC_NOT_OPENED) { printf("Channel 1 was not properly closed earlier: %x\n",rc); } rc = hpcOpenW32(1); if (rc != HPC_OK) { printf("Error opening channel 1: %X\n",rc); return; } rc = hpcSetmode(1, HPC_IB_SIZE); if (rc != HPC_OK) { printf("Error setting mode: %X\n",rc); hpcClose(1); return; } for (i=0; i<n; i++) { rc = hpcReadwrite(1, HPC_READ, buf, BSIZE, &bytesUsed, NULL); if (rc != HPC_OK) { printf("Error in HPC_READWRITE: %X\n",rc); hpcClose(1); return; } printf("bytesUsed = %X\n",bytesUsed); bytesUsed &= ~HPC_IB_BIT; for (j=0; j < bytesUsed; j++) { printf(" %02X",buf[j]); } printf("\n"); } hpcClose(1);}typedef struct { unsigned char buf[BSIZE]; HPC_IRP irp;} IRPB;voidhpcRecPkts2(int n){ HPC_ERROR_CODE rc; IRPB irpb[NBUFFS]; int i,k; unsigned int j, bytesUsed; rc = hpcClose(1); if (rc != HPC_NOT_OPENED) { printf("Channel 1 was not properly closed earlier: %x\n",rc); } rc = hpcOpenW32(1); if (rc != HPC_OK) { printf("Error opening channel 1: %X\n",rc); return; } rc = hpcSetmode(1, HPC_IB_SIZE); if (rc != HPC_OK) { printf("Error setting mode: %X\n",rc); hpcClose(1); return; } for (i=0; i<NBUFFS; i++) { hpcInitIrp(&irpb[i].irp); rc = hpcReadwrite(1, HPC_READ, &irpb[i].buf[0], BSIZE, &bytesUsed, &irpb[i].irp); if (rc != HPC_PENDING) { printf("hpcReadwrite not pending\n"); goto myexit; } } k = 0; for (i=0; i<n; i++) { rc = hpcGetIrpStatus(&irpb[k].irp, &bytesUsed, TRUE); if (rc != HPC_OK) { printf("Error in HPCGetIrpStatus: %X\n",rc); goto myexit; } printf("bytesUsed = %X\n",bytesUsed); bytesUsed &= ~HPC_IB_BIT; for (j=0; j < bytesUsed; j++) { printf(" %02X",irpb[k].buf[j]); } printf("\n"); rc = hpcReadwrite(1, HPC_READ, &irpb[k].buf[0], BSIZE, &bytesUsed, &irpb[k].irp); if (rc != HPC_PENDING) { printf("hpcReadwrite not pending\n"); goto myexit; } k++; if (k >= NBUFFS) k = 0; } myexit: hpcClose(1); for (i=0; i<NBUFFS; i++) { hpcDeleteIrp(&irpb[i].irp); } }voidhpcSendPkts(int n, unsigned int size){ HPC_ERROR_CODE rc; unsigned char buf[BSIZE2]; int i; unsigned int j, k, bytesUsed; if (size > BSIZE2) { printf("size exceeds %d\n",BSIZE2); return; } rc = hpcClose(1); if (rc != HPC_NOT_OPENED) { printf("Channel 1 was not properly closed earlier: %x\n",rc); } rc = hpcOpenW32(1); if (rc != HPC_OK) { printf("Error opening channel 1: %X\n",rc); return; } rc = hpcSetmode(1, HPC_IB_SIZE); if (rc != HPC_OK) { printf("Error setting mode: %X\n",rc); hpcClose(1); return; } for (i=0; i<n; i++) { k = 0; for (j=0; j<size; j++) { k += i+1; buf[j] = 0x30 + (k & 0x3F); } rc = hpcReadwrite(1, HPC_WRITE, buf, size, &bytesUsed, NULL); if (rc != HPC_OK) { printf("Error in HPC_READWRITE: %X\n",rc); hpcClose(1); return; } printf("bytesUsed = %X\n",bytesUsed); } hpcClose(1);}voidhpcSendPkts2(int n, unsigned int size){ HPC_ERROR_CODE rc; IRPB irpb[NBUFFS]; int i,p; unsigned int j, k, bytesUsed; if (size > BSIZE2) { printf("size exceeds %d\n",BSIZE2); return; } if (n < NBUFFS) { printf("n must be at least %d\n",NBUFFS); return; } rc = hpcClose(1); if (rc != HPC_NOT_OPENED) { printf("Channel 1 was not properly closed earlier: %x\n",rc); } rc = hpcOpenW32(1); if (rc != HPC_OK) { printf("Error opening channel 1: %X\n",rc); return; } rc = hpcSetmode(1, HPC_IB_SIZE); if (rc != HPC_OK) { printf("Error setting mode: %X\n",rc); hpcClose(1); return; } for (i=0; i<NBUFFS; i++) { hpcInitIrp(&irpb[i].irp); } p = 0; for (i=0; i<n+NBUFFS; i++) { if (i >= NBUFFS) { rc = hpcGetIrpStatus(&irpb[p].irp, &bytesUsed, TRUE); if (rc != HPC_OK) { printf("Error in HPCGetIrpStatus: %X\n",rc); goto myexit; } printf("bytesUsed = %X\n",bytesUsed); } if (i < n) { k = 0; for (j=0; j<size; j++) { k += i+1; irpb[p].buf[j] = 0x30 + (k & 0x3F); } rc = hpcReadwrite(1, HPC_WRITE, &irpb[p].buf[0], size, &bytesUsed, &irpb[p].irp); if (rc != HPC_PENDING) { printf("Error in HPC_READWRITE: %X\n",rc); goto myexit; } } p++; if (p >= NBUFFS) p = 0; } myexit: hpcClose(1); for (i=0; i<NBUFFS; i++) { hpcDeleteIrp(&irpb[i].irp); }}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -