⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vx6208.c

📁 vxWorks下Pci设备驱动程序,简单的IO操作。
💻 C
字号:
/*
********************************************************************************
* Hwacreate, Inc.
* Xinshidai Building, 5th Floor NO.7 Hua Yuan Road,
* Haidian District Beijing, 100088 P.R.China
*
* (c) Copyright 2003, Hwa Create(China) Co.,Ltd.
*
* All rights reserved. Hwacreate’s source code is an unpublished work and the
* use of a copyright notice does not imply otherwise. This source code contains
* confidential, trade secret material of Hwacreate, Inc. Any attempt or participation
* in deciphering, decoding, reverse engineering or in any way altering the source
* code is strictly prohibited, unless the prior written consent of Hwacreate, Inc.
* is obtained.
*
* Filename : Vx6208_DA.c
* Version:   1.0
* Programmer(s):  li jian 
* Created : 2004.2.24
* Description : s function file for 6208v' s da 
* Modification History:
 
********************************************************************************
*/
#include "c:\Tornado2.2\target\h\vxworks.h"
#include "stdio.h"
#include "stdLib.h"
#include "sysLib.h"
#include "ioLib.h"
#include "taskLib.h"
#include "math.h"
#include "string.h"
#include "logLib.h"
#include "copyright_wrs.h"
#include "intlib.h"
#include "iv.h"
#include "drv/pci/pciConfigLib.h"
#include "drv/pci/pciIntlib.h"
#include "math.h"

#include "HwaTypes.h"
#include "vx6208.h"
#include "pci.h"

/*also use it to determine whether we get base address*/
UINT32 V6208_IOBase[MAX_6208_BOARD] = {0,0,0,0,0,0};
/*
get 6208's address from pci address
if success return true, else return false
*/
int V6208HwaInit(int BoardNO)
{
    int pciBus;
    int pciDevice;
    int pciFunc;
    int unit;

    if (BoardNO > MAX_6208_BOARD) 
    {
	printf("Board Number error, BoardNO = %d ,MAX_6208_BOARD = %d\n",BoardNO,MAX_6208_BOARD);
	return(FALSE);
    }
    if (V6208_IOBase[BoardNO] != 0) return (TRUE);
    if (pciFindDevice(PCI_6208_VENDERID, PCI_6208_DEVID ,BoardNO,
     				 &pciBus, &pciDevice, &pciFunc) != OK) 
     {
       printf("The %d board's V6208Init pciFindDevice error\n",BoardNO);
       return(FALSE);
     }     

     pciConfigInLong (pciBus, pciDevice, pciFunc, PCI_CFG_BASE_ADDRESS_2, &(V6208_IOBase[BoardNO]));

     sysBusToLocalAdrs(PCI_SPACE_IO_SEC, V6208_IOBase[BoardNO],&(V6208_IOBase[BoardNO]));

     V6208_IOBase[BoardNO] &= PCI_IOBASE_MASK;
#ifdef DEBUG
     printf("%d board 's V6208_IOBase = 0x%x\n",BoardNO,V6208_IOBase[BoardNO]);
#endif
	


     return (TRUE);
}

/*
send DA out at Value at v6208's port
6208's port number is 0-7, Value is from -10.0 - +10.0
if success return true, else return false
*/
int V6208HwaDAOutput(int BoardNO,int Port,double DAValue)
{
	int WriteFinish=0;
	uint16_T OutDate;
/*	printf("Port = %d,DAValue = %f\n",Port,DAValue);*/
    	if (BoardNO > MAX_6208_BOARD) 
    	{
		printf("Board Number error, BoardNO = %d ,MAX_6208_BOARD = %d\n",BoardNO,MAX_6208_BOARD);
		return(FALSE);
    	}
    	
	if (V6208_IOBase[BoardNO] == 0) 
	{
		printf("The %d board's V6208HwaDAOut :: V6208_IOBase error\n",BoardNO);
		return (FALSE);
	}
	if (Port >= MAX_6208_DAPORT  )
	{
		printf("The %d board: v6208's port NO should be 0-7, now is %d\n",BoardNO,Port);
		return (FALSE);
	}
	if (DAValue>DAC_MAX_OUTPUT)
	{
		printf("The %d board : v6208's da out value should  NOT larger than +10.0, now is %f\n",BoardNO,DAValue);
		DAValue = DAC_MAX_OUTPUT;
	}else
	if (DAValue<DAC_MIN_OUTPUT)
	{
		printf("The %d board : v6208's da out value should  NOT smaller than -10.0, now is %f\n",BoardNO,DAValue);
		DAValue = -DAC_MIN_OUTPUT;
	}
	/*out value*/	
	if (DAValue < 0.0) 
	{
		WriteFinish = sysInByte(V6208_IOBase[BoardNO]);
		while ((WriteFinish & 1) == 1)
			WriteFinish = sysInByte(V6208_IOBase[BoardNO]);
		OutDate = (DAValue-10.0)/PCI_6208_AD_REVOLUTOIN + 0x8000;
		sysOutWord(V6208_IOBase[BoardNO]+Port*2,OutDate);	
#ifdef DEBUG		
		printf("0x%x\n",OutDate);	
#endif		
	}else 
	{
		WriteFinish = sysInByte(V6208_IOBase[BoardNO]);
		while ((WriteFinish & 1) == 1)
			WriteFinish = sysInByte(V6208_IOBase[BoardNO]);
		OutDate = DAValue/PCI_6208_AD_REVOLUTOIN;
		sysOutWord(V6208_IOBase[BoardNO] + Port*2,OutDate);
#ifdef DEBUG		
		printf("0x%x\n",OutDate);
#endif
	}
	return TRUE;	
}

/*
read DI input from Port(0,1,2,3)
return the value readed
*/
int V6208HwaDIInput(int BoardNO,int Port,int *DIOut)
{
	char_T	DIValue = 0;
	
    	if (BoardNO > MAX_6208_BOARD) 
    	{
		printf("Board Number error, BoardNO = %d ,MAX_6208_BOARD = %d\n",BoardNO,MAX_6208_BOARD);
		return(FALSE);
    	}
    		
	if (V6208_IOBase[BoardNO] == 0) 
	{
		printf("The %d board : V6208HwaDAOut :: V6208_IOBase error\n",BoardNO);
		return (FALSE);
	}
	if ( Port >= MAX_6208_DIOPORT) 
	{
		printf("The %d board : v6208's DI port should be 0-3,now is %d\n",BoardNO,Port);
		return (FALSE);
	}	
	DIValue = sysInByte(V6208_IOBase[BoardNO]+PCI_6208_DIO_OFFSET);	
	DIValue = DIValue >> (Port+4);
	*DIOut =  DIValue & 1;
	return TRUE;
}

/*
output DO to Port(0,1,2,3)
*/
unsigned char Hwa6208LastOutput = 0;

int V6208HwaDOOutput(int BoardNO,int Port,double HiV,double LoV,double DOOut)
{
	char TempDOOut,OldOne;
	char isOutEqHi,isLastOutEqHi,LastOut;
	
    if (BoardNO > MAX_6208_BOARD) 
    {
		printf("Board Number error, BoardNO = %d ,MAX_6208_BOARD = %d\n",BoardNO,MAX_6208_BOARD);
		return(FALSE);
    }	
	if (V6208_IOBase[BoardNO] == 0) 
	{
		printf("The %d board : V6208HwaDAOut :: V6208_IOBase error\n",BoardNO);
		return (FALSE);
	}	
	if ( Port >= MAX_6208_DIOPORT) 
	{
		printf("The %d board : v6208's DO port should be 0-3,now is %d\n",BoardNO,Port);
		return (FALSE);
	}	
	
	LastOut = Hwa6208LastOutput;
        isLastOutEqHi = (LastOut >> Port) &  0x1;
        isOutEqHi = (DOOut >= HiV) || ((DOOut >= LoV) && isLastOutEqHi);
        isOutEqHi = isOutEqHi << Port;
	/*make the 'port' bit 0, others remain what they are*/
	OldOne = 1;
	OldOne = OldOne << Port;
	OldOne = ~OldOne;
	Hwa6208LastOutput = Hwa6208LastOutput & OldOne;

	Hwa6208LastOutput = Hwa6208LastOutput | isOutEqHi;
	sysOutByte(V6208_IOBase[BoardNO]+PCI_6208_DIO_OFFSET,Hwa6208LastOutput);	

	return TRUE;		
}

void v6208test(UINT BoardNO)
{
	double sinout;
	int i=0;
	int WriteFinish=0;
	int add = 0;
	int *p = &add;
	V6208HwaInit(BoardNO);
/*	V6208HwaDAOutput(0,0,-1.5);*/
	sysLocalToBusAdrs(PCI_SPACE_MEMIO_PRI,&(V6208_IOBase[0]),p);
	printf("0x%x\n",add);

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -