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

📄 drvr6430.c

📁 rt采集卡dos下dm6430驱动源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/***************************************************************************

	FILE NAME: DRVR6430.C

	FILE DESCRIPTION: 

	This file is a main part of DM6430 driver. It contains functions that
	implement many features (A/D, D/A etc.) of the DM6430 board.

	PROJECT NAME: Part of DM6430 DOS Driver

	DRIVER VERSION: 1.1

	COMPILER: Borland C++ 3.1

	TARGET: Real-Mode DOS

	Copyright 2003 RTD Embedded Technologies

***************************************************************************/

#include <conio.h>
#include <dos.h>
#include <stdio.h>
#include <string.h>

#include "DRVR6430.h"

// Board Registers
#define r_CLEAR_6430							0		// Clear Register (Read/Write)
#define r_STATUS_6430						2		// Status Register (Read)
#define r_CONTROL_6430						2		// Control Register (Write)
#define r_AD_6430								4		// AD Data (Read)
#define r_CHANNEL_GAIN_6430				4		// Channel/Gain Register (Write)
#define r_AD_TABLE_6430						4		// AD Table (Write)
#define r_DIGITAL_TABLE_6430				4		// Digital Table (Write)
#define r_START_CONVERSION_6430			6		// Start Conversion (Read)
#define r_TRIGGER_6430						6		// Trigger Register (Write)
#define r_IRQ_6430							8		// IRQ Register (Write)
#define r_DIN_FIFO_6430						10		// Digital Input FIFO Data (Read)
#define r_DIN_CONFIG_6430					10		// Config Digital Input FIFO (Write)
#define r_DAC1_6430							12		// DAC 1 Data (Write)
#define r_LOAD_AD_SAMPLE_COUNT_6430		14		// Load A/D Sample Counter (Read)
#define r_TIMER_CLCK0_6430					16		// Timer/Counter 0 (Read/Write)
#define r_TIMER_CLCK1_6430					18		// Timer/Counter 1 (Read/Write)
#define r_TIMER_CLCK2_6430					20		// Timer/Counter 2 (Read/Write)
#define r_TIMER_CTRL_6430					22		// Timer/Counter Control Word (Write)


// Defaults for the global variable.
//--------------------------------------------------

uint16  BaseAddress;

// Varibles to save board settings
static uint16 Control_Register_6430			= 0;      // Save Control Register
static uint16 Trigger_Register_6430			= 0;      // Save Trigger Register
static uint16	IRQ_Register_6430				= 0;      // Save IRQ Register
static uint16	DIN_Register_6430				= 0;      // Save Digital Input FIFO configuration Register





char* TitleString6430(void)
{
	return "DM6430 sample program.";
} //TitleString6430




//*************************************************************************
//	SetBaseAddress
//
//	This routine is used to set the variable BaseAddress.
//
//	Parameters:
//		Address:
//*************************************************************************
void SetBaseAddress(uint16 Address)
{
	BaseAddress = Address;
} // SetBaseAddress




//*************************************************************************
//	InitBoard6430
//
//	This Routine Should allways be called first.
//	This clears the board and varibles the driver uses.
//
//	Parameters:
//		None
//*************************************************************************
void InitBoard6430(void)
{
	ClearBoard6430();
	ClearADDMADone6430();
	ClearChannelGainTable6430();
	ClearADFIFO6430();
	// Clear Driver varibles.
	Control_Register_6430		= 0;      // Save Control Register
	Trigger_Register_6430  		= 0;      // Save Trigger Register
	IRQ_Register_6430          = 0;      // Save IRQ Register
	DIN_Register_6430          = 0;      // Save Digital Input Configuration Register
} // InitBoard6430




//************************ CLEAR ROUTINES *********************************
//	Read & Write at BA + 0

//*************************************************************************
//	ClearRegister6430
//
//	This routine is used to write the clear register with one command
// and issue a clear to the board.
//
//	Parameters:
//		ClearValue:		1 - 65535
//*************************************************************************
void ClearRegister6430(uint16 ClearValue)
{
	outpw(BaseAddress + r_CLEAR_6430, ClearValue);
	inpw(BaseAddress + r_CLEAR_6430);
} // ClearRegister6430




//*************************************************************************
//	ClearBoard6430
//
//	This routine is used to clear board.
//
//	Parameters:
//		None
//*************************************************************************
void ClearBoard6430(void)
{
	outpw(BaseAddress + r_CLEAR_6430, 0x0001);
	inpw(BaseAddress + r_CLEAR_6430);
} // ClearBoard6430




//*************************************************************************
//	ClearADFIFO6430
//
//	This routine is used to clear all the data from the A/D FIFO.
//
//	Parameters:
//		None
//*************************************************************************
void ClearADFIFO6430(void)
{
	outpw(BaseAddress + r_CLEAR_6430, 0x0002);
	inpw(BaseAddress + r_CLEAR_6430);
} // ClearADFIFO6430




//*************************************************************************
//	ClearADDMADone6430
//
//	This routine is used to clear the A/D DMA done status bit.
//
//	Parameters:
//		None
//*************************************************************************
void ClearADDMADone6430(void)
{
	outpw(BaseAddress + r_CLEAR_6430, 0x0004);
	inpw(BaseAddress + r_CLEAR_6430);
} // ClearADDMADone6430




//*************************************************************************
//	ClearChannelGainTable6430
//
//	This routine is used to clear both the AD Table and the Digital Table.
//
//	Parameters:
//		None
//*************************************************************************
void ClearChannelGainTable6430(void)
{
	outpw(BaseAddress + r_CLEAR_6430, 0x0008);
	inpw(BaseAddress + r_CLEAR_6430);
} // ClearChannelGainTable6430




//*************************************************************************
//	ResetChannelGainTable6430
//
//	This routine is used to reset both the AD Table and the Digital Table
//	pointers to the first location in the table.
//
//	Parameters:
//		None
//*************************************************************************
void ResetChannelGainTable6430(void)
{
	outpw(BaseAddress + r_CLEAR_6430, 0x0010);
	inpw(BaseAddress + r_CLEAR_6430);
} // ResetChannelGainTable6430




//*************************************************************************
//	ClearDINFIFO6430
//
//	This routine is used to clear the Digital Input FIFO.
//
//	Parameters:
//		None
//*************************************************************************
void ClearDINFIFO6430(void)
{
	outpw(BaseAddress + r_CLEAR_6430, 0x0020);
	inpw(BaseAddress + r_CLEAR_6430);
} // ClearDIN1FIFO6430




//*************************************************************************
//	ClearIRQ16430
//
//	This routine is used to clear the IRQ 1 circuitry and status bit.
//
//	Parameters:
//		None
//*************************************************************************
void ClearIRQ16430(void)
{
	outpw(BaseAddress + r_CLEAR_6430, 0x0040);
	inpw(BaseAddress + r_CLEAR_6430);
} // ClearIRQ16430




//*************************************************************************
//	ClearIRQ26430
//
//	This routine is used to clear the IRQ 2 status bit.
//
//	Parameters:
//		None
//*************************************************************************
void ClearIRQ26430(void)
{
	outpw(BaseAddress + r_CLEAR_6430, 0x0080);
	inpw(BaseAddress + r_CLEAR_6430);
} // ClearIRQ26430




//************************ QUERY ROUTINES *********************************
//	Read at BA + 2

//*************************************************************************
//	ReadStatus6430
//
//	This routine returns the status from the board.
//
//	Returns:		16 bit unsigned integer
//*************************************************************************
uint16 ReadStatus6430(void)
{
 return(inpw(BaseAddress + r_STATUS_6430));
} // ReadStatus6430




//*************************************************************************
//	IsADFIFOEmpty6430
//
//	This routine checks to see if the A/D FIFO is empty.
//
//	Returns:				1 if FIFO is empty
//							0 if FIFO is not empty
//*************************************************************************
uint16 IsADFIFOEmpty6430(void)
{
	uint16 Status;

	Status = inpw(BaseAddress + r_STATUS_6430);
	Status &= 1;
	return(!Status);
} // IsADFIFOEmpty6430




//*************************************************************************
//	IsADFIFOFull6430
//
//	This routine checks to see if the A/D FIFO is full.
//
//	Returns:				1 if FIFO is full
//							0 if FIFO is not full
//*************************************************************************
uint16 IsADFIFOFull6430(void)
{
	uint16 Status;

	Status = inpw(BaseAddress + r_STATUS_6430);
	Status = (Status >> 1) & 1;
	return(!Status);
} // IsADFIFOFull6430




//*************************************************************************
//	IsADHalted6430
//
//	This routine checks to see if the AD is halted.
//
//	Returns:				1 if AD is halted
//							0 if AD is not halted
//*************************************************************************
uint16 IsADHalted6430(void)
{
	uint16 Status;

	Status = inpw(BaseAddress + r_STATUS_6430);
	Status = (Status >> 2) & 1;
	return(Status);
} // IsADHalted6430




//*************************************************************************
//	IsADConverting6430
//
//	This routine checks to see if the AD converting.
//
//	Returns:				1 if AD is converting
//							0 if AD is not converting
//*************************************************************************
uint16 IsADConverting6430(void)
{
	uint16 Status;

	Status = inpw(BaseAddress + r_STATUS_6430);
	Status = (Status >> 3) & 1;
	return(!Status);
} // IsADConverting6430




//*************************************************************************
//	IsADDMADone6430
//
//	This routine checks to see if the A/D DMA transfer is done.
//
//	Returns:				1 if DMA is done
//							0 if DMA is not done
//*************************************************************************
uint16 IsADDMADone6430(void)
{
	uint16 Status;

	Status = inpw(BaseAddress + r_STATUS_6430);
	Status = (Status >> 4) & 1;
	return(Status);
} // IsADDMADone6430




//*************************************************************************
//	IsFirstADDMADone6430
//
//	This routine checks to see if the A/D DMA transfer is done on the first
//	channel.
//
//	Returns:				1 if DMA is done
//							0 if DMA is not done
//*************************************************************************
uint16 IsFirstADDMADone6430(void)
{
	uint16 Status;

	Status = inpw(BaseAddress + r_STATUS_6430);
	Status = (Status >> 5) & 1;
	return(Status);
} // IsFirstADDMADone6430




//*************************************************************************
//	IsBurstClockOn6430
//
//	This routine checks to see if the burst clock is enabled.
//
//	Returns:				1 if Burst Clock is on
//							0 if Burst Clock is off
//*************************************************************************
uint16 IsBurstClockOn6430(void)
{
	uint16 Status;

	Status = inpw(BaseAddress + r_STATUS_6430);
	Status = (Status >> 6) & 1;
	return(Status);
} // IsBurstClockOn6430




//*************************************************************************
//	IsPacerClockOn6430
//
//	This routine checks to see if the pacer clock is running.
//
//	Returns:				1 if Pacer Clock is on
//							0 if Pacer Clock is off
//*************************************************************************
uint16 IsPacerClockOn6430(void)
{
	uint16 Status;

	Status = inpw(BaseAddress + r_STATUS_6430);
	Status = (Status >> 7) & 1;
	return(Status);
} // IsPacerClockOn6430




//*************************************************************************
//	IsAboutTrigger6430
//
//	This routine checks to see if the about trigger has occurred.
//
//	Returns:				1 if trigger has occurred
//							0 if trigger has not occurred
//*************************************************************************
uint16 IsAboutTrigger6430(void)
{
	uint16 Status;

	Status = inpw(BaseAddress + r_STATUS_6430);
	Status = (Status >> 8) & 1;
	return(Status);
} // IsboutTrigger6430




//*************************************************************************
//	IsDigitalIRQ6430
//
//	This routine checks to see if the digital I/O chip has generated
//	an interrupt.
//
//	Returns:				1 if IRQ has been generated
//							0 if no IRQ
//*************************************************************************
uint16 IsDigitalIRQ6430(void)
{
	uint16 Status;

	Status = inpw(BaseAddress + r_STATUS_6430);
	Status = (Status >> 9) & 1;
	return(Status);
} // IsDigitalIRQ6430




//*************************************************************************
//	IsDINFIFOEmpty6430
//
//	This routine checks to see if the Digital Input FIFO is empty.
//
//	Returns:				1 if FIFO is empty
//							0 if FIFO is not empty
//*************************************************************************
uint16 IsDINFIFOEmpty6430(void)
{
	uint16 Status;

	Status = inpw(BaseAddress + r_STATUS_6430);
	Status = (Status >> 10) & 1;
	return(!Status);
} // IsDINFIFOEmpty6430




//*************************************************************************
//	IsDINFIFOHalf6430
//
//	This routine checks to see if the Digital Input FIFO is half full.
//
//	Returns:				1 if FIFO is half full
//							0 if FIFO is not half full
//*************************************************************************
uint16 IsDINFIFOHalf6430(void)
{
	uint16 Status;

	Status = inpw(BaseAddress + r_STATUS_6430);
	Status = (Status >> 11) & 1;
	return(!Status);
} // IsDINFIFOHalf6430




//*************************************************************************

⌨️ 快捷键说明

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