📄 z85230drv.c
字号:
#else chanA->hw.dr = (char *)0; chanA->hw.cr = (char *)FPGA_SCC_PORT_A; chanA->hw.txfpga = (char *)FPGA_SCC_TXA_DESC; chanA->hw.rxfpga = (char *)FPGA_SCC_RXA_DESC; chanB->hw.dr = (char *)0; chanB->hw.cr = (char *)FPGA_SCC_PORT_B; chanB->hw.txfpga = (char *)FPGA_SCC_TXB_DESC; chanB->hw.rxfpga = (char *)FPGA_SCC_RXB_DESC;#endif /* P/T 669--move the for loop from after the intEnable to before */ /* to ensure the interrupt callbacks are configured prior to */ /* enabling interrupts */ /* TODO: set channel mode to Z85230_MODE_DMA and Z85230_MODE_INT, * respectively. */ for ( i = 0; i < Z85230_NUM_CHANNELS; i++ ) { gZ85230Channels[ i ]->blocking = FALSE; gZ85230Channels[ i ]->isOpen = FALSE; z85230DrvProtocolSet( gZ85230Channels[ i ], Z85230_PROTOCOL_ASYNC ); } intConnect( INUM_TO_IVEC( (int)(chanA->hw.intVec) ), z85230DrvInt, (int)NULL ); intEnable( INT_SRC_SCC ); /* Enable the interrupt handlers for the DMA engines gtDmaIntEnable( SCC_RXA_DMA_INT); gtDmaIntEnable( SCC_TXA_DMA_INT); gtDmaIntEnable( SCC_RXB_DMA_INT); gtDmaIntEnable( SCC_TXB_DMA_INT); */ }/*************************************************************************** * z85230DrvShutdown - shutdown the driver * * RETURNS * N/A */void z85230DrvShutdown() { int i; /* Close all channels */ for ( i = 0; i < Z85230_NUM_CHANNELS; i++ ) { z85230DrvClose( &(gZ85230Devices[ i ]) ); }#ifdef VME_181 /* Disable the interrupt handlers for the DMA engines */ gtDmaIntDisable( SCC_RXA_DMA_INT); gtDmaIntDisable( SCC_TXA_DMA_INT); gtDmaIntDisable( SCC_RXB_DMA_INT); gtDmaIntDisable( SCC_TXB_DMA_INT);#endif }/*************************************************************************** * z85230DrvOpen - open a channel * * RETURNS * OK: success * ERROR: failure */int z85230DrvOpen( DEV_HDR * pDevHdr, char * pName, int mode ) { int result; Z85230_CHAN * channel = gZ85230Channels[ ((Z85230_DEV *)pDevHdr)->channel.channel ]; Z85230_ASSERT( channel->isOpen >= 0 ); /* fail if channel is already open */ if ( channel->isOpen > 0 ) { gZ85230Errno = Z85230_ERR_CHAN_OPEN; errno = Z85230_ERR_CHAN_OPEN ; return ERROR; } /* set protocol */ result = z85230DrvProtocolSet( channel, mode ); if ( result != Z85230_OK ) { return ERROR; } /* clear all errors */ channel->error = Z85230_OK; channel->openError = Z85230_OK; channel->closeError = Z85230_OK; channel->readError = Z85230_OK; channel->writeError = Z85230_OK; channel->blocking = 1; channel->writeTimeout = WAIT_FOREVER; /* don't timeout on write by default */ channel->readTimeout = 300; /* 10 tick timeout by default */ /* open channel */ result = channel->protocol.open( channel ); if ( result != Z85230_OK ) { return result; } Z85230_CHECK( channel, channel->openError ); /* remember that channel is open */ channel->isOpen++; return (int)pDevHdr; }/*************************************************************************** * z85230DrvClose - close an open channel * * RETURNS * OK: success * ERROR: failure */STATUS z85230DrvClose( Z85230_DEV * pDev ) { int result; Z85230_CHAN * channel = gZ85230Channels[ ((Z85230_DEV *)pDev)->channel.channel ]; Z85230_ASSERT( channel->isOpen >= 0 ); /* fail if channel is already closed */ if ( channel->isOpen == 0 ) { errno = Z85230_ERR_CHAN_CLOSED ; return ERROR; } /* close channel */ result = channel->protocol.close( channel ); if ( result != Z85230_OK ) { return result; } /* remember that channel is closed */ channel->isOpen--; Z85230_CHECK( channel, channel->closeError ); return Z85230_OK; }/*************************************************************************** * z85230DrvIoctl - run an ioctl on the specified channel * * RETURNS * OK: success * ERROR: failure */int z85230DrvIoctl( Z85230_DEV * pDev, int command, int arg ) { int result = Z85230_OK; Z85230_CHAN * channel = gZ85230Channels[ pDev->channel.channel ]; /* Z8530_CHAN * hw = &(channel->hw); */ if ( !(channel->isOpen) ) { channel->error = Z85230_ERR_CHAN_CLOSED; } Z85230_CHECK_ERR( channel ); /* allow protocol to handle command */ result = channel->protocol.ioctl( channel, command, arg ); if ( result != Z85230_ERR_NOT_IMPLEMENTED ) { /* protocol handled command */ return result; } else { result = OK; } /* protocol didn't implement command - try to handle it ourselves */ switch ( command ) { case Z85230_SET_BLOCKING: if ( arg == FALSE ) { channel->blocking = FALSE; } else { channel->blocking = TRUE; } break; case Z85230_GET_BLOCKING: *(int *)arg = channel->blocking; break; case Z85230_SET_WRITE_TO: channel->writeTimeout = arg; break; case Z85230_GET_WRITE_TO: *(int *)arg = channel->writeTimeout; break; case Z85230_SET_READ_TO: channel->readTimeout = arg; break; case Z85230_GET_READ_TO: *(int *)arg = channel->readTimeout; break; default: result = Z85230_ERR_INVALID_COMMAND; break; } return result; }/*************************************************************************** * z85230DrvRead - read contents of pBuf to channel * * RETURNS * >= 0: the number of bytes read * <0: an error occured */int z85230DrvRead( Z85230_DEV * pDev, unsigned char * pBuf, int nBytes ) { int ret_val = 0 ; Z85230_CHAN * channel = gZ85230Channels[ ((Z85230_DEV *)pDev)->channel.channel ]; ret_val = channel->protocol.read( channel, pBuf, nBytes ); Z85230_CHECK( channel, channel->readError ); return ret_val ; }/*************************************************************************** * z85230DrvWrite - write contents of pBuf to channel * * RETURNS * >= 0: the number of bytes written * <0: an error occured */int z85230DrvWrite( Z85230_DEV * pDev, unsigned char * pBuf, int nBytes ) { Z85230_CHAN * channel = gZ85230Channels[ ((Z85230_DEV *)pDev)->channel.channel ]; Z85230_CHECK( channel, channel->writeError ); return channel->protocol.write( channel, pBuf, nBytes ); }/*************************************************************************** * z85230Drv - initialize driver * * RETURNS * OK: initialization successful * ERROR: initialization failed */STATUS z85230Drv( int reserved ) { /* default value for the uninitialized driver is ERROR * therefore , if the drive number is not equal error, the * driver must already be installed, so return OK */ if( gZ85230DrvNum != ERROR ) return (OK); gZ85230DrvNum = iosDrvInstall( z85230DrvOpen, NULL, z85230DrvOpen, z85230DrvClose, z85230DrvRead, z85230DrvWrite, z85230DrvIoctl ); if ( gZ85230DrvNum != ERROR ) { /* initialize driver */ memset( gZ85230Channels[ Z85230_CHANNEL_A ], 0, sizeof( Z85230_CHAN ) ); memset( gZ85230Channels[ Z85230_CHANNEL_B ], 0, sizeof( Z85230_CHAN ) ); gZ85230Channels[ Z85230_CHANNEL_A ] = &(gZ85230Devices[ Z85230_CHANNEL_A ].channel); gZ85230Channels[ Z85230_CHANNEL_B ] = &(gZ85230Devices[ Z85230_CHANNEL_B ].channel);#ifdef VME_181 z85230DrvInitialize( (void *)Z8530_BASE_ADRS, (void *)GT64260_BASE_ADRS, gZ85230Channels[ Z85230_CHANNEL_A ], gZ85230Channels[ Z85230_CHANNEL_B ] );#else z85230DrvInitialize( (void *)Z85230_BASE_ADRS, (void *)0, gZ85230Channels[ Z85230_CHANNEL_A ], gZ85230Channels[ Z85230_CHANNEL_B ] );#endif /* No matter how many times the driver is installed or uninstalled * this reboot hook only needs to be added once. */ if( gRebootHookAdded == FALSE ) { rebootHookAdd((FUNCPTR)z85230RebootHook); gRebootHookAdded = TRUE ; } /* success */ return OK; } /* failure */ return ERROR; }/*************************************************************************** * z85230DrvRemove - initialize driver * PARAMS * int force_close - force the closure of any open file descriptors * * RETURNS * OK: drive was removed successfully * ERROR: drive remove failed * - iosDrvRemove fails if there is an open file descriptor */STATUS z85230DrvRemove(int force_close) { STATUS ret_val = (OK) ; int i; /* if the driver has already been removed, then return success */ if( gZ85230DrvNum == ERROR ) { return OK; } if ( (force_close == 0) && (gZ85230Channels[0]->isOpen || gZ85230Channels[1]->isOpen) ) { errno = Z85230_ERR_CHAN_OPEN ; return ERROR; } for ( i = 0; i < Z85230_NUM_CHANNELS; i++ ) { Z85230_CHAN * channel = gZ85230Channels[ i ]; /* close file descriptors */ if ( channel->isOpen ) { channel->protocol.close( channel ); channel->isOpen = 0; } /* remove file descriptors from the driver table */ z85230DevRemove( channel->name ); } /* Remove the driver from the VxWorks Drive Table */ ret_val = iosDrvRemove(gZ85230DrvNum, force_close); if( ret_val != OK ) { gZ85230Errno = errno; } else { /* rest the driver number to its uninitialized value */ gZ85230DrvNum = ERROR ; } return ret_val ; }/*************************************************************************** * z85230DevCreat - "connect" a channel to a location in the file system * * RETURNS * OK: success * ERROR: failure */STATUS z85230DevCreat( char * devName, int channel )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -