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

📄 dma.c

📁 rt采集卡dos下dm6430驱动源代码
💻 C
字号:
/***************************************************************************

	FILE NAME: DMA.C

	FILE DESCRIPTION: DMA (Direct Memory Acces with the PC's DMA chip)

	 Sample program that demonstrates how to use DMA transfer.

	 This program stores acquired data into a buffer at a designated rate
	 using DMA transfers. When the requested number of samples have been
	 transferred to the buffer the data is graphed on the screen.

	PROJECT NAME: DMA (Part of DM6430 DOS Driver)

	DRIVER VERSION: 1.1

	COMPILER: Borland C++ 3.1
	 - ATTENTION !   You must compile this project in Large Model.

	TARGET: Real-Mode DOS

	Copyright 2003 RTD Embedded Technologies

***************************************************************************/
#include <alloc.h>
#include <conio.h>
#include <dos.h>
#include <mem.h>
#include <stdio.h>
#include "drvr6430.h"
#include "dio5812.h"
#include "dmautil.h"
#include "vgraph.h"
/***************************************************************************
	Defines

	Change these constants to alter the program parameters.
****************************************************************************/

#define DMA_BUF_SIZE   20000l				// The size of the DMA buffer
#define BASE_ADDRESS   768             // Number of samples


#define CHANNEL         0              // A/D channel
#define GAIN            0              // Gain
#define SE_DIFF         0              // Single ended
#define RATE        100000.0           // Sampling rate
#define ADDMAChannel  	7              // DMA Channel

// To set DMA Mode Register
#define MODE_REGISTER (DMA_DEMAND_TRANSFER | DMA_WRITE | DMA_INCREMENT_COUNTER)


	int far * DMAPtr;
	unsigned int DMAPage, DMAPageOffset;

/***************************************************************************
	SetProgramScreen()

	The SetProgramScreen() function initializes the screen.
****************************************************************************/

void SetProgramScreen(void)
{
	clrscr();

	// Print header and footer.
	gotoxy(1,1);   cprintf(TitleString6430());
	gotoxy(50, 1); cprintf("DMA Example");

	gotoxy(25, 8); cprintf("DMA is running. Please, wait.\r\n");
} //SetProgramScreen


int main(void)
{
	FILE* DataFile;
	unsigned long Rate;
	float Range;
	float Slope;
	unsigned NumberOfPoints;
	unsigned long NumberofBytes;
	double Actual_PACER_RATE;

	//  32768 is the largest bata buffer
	//  32768 samples 65535 bytes or 1 page

	NumberofBytes = (long)(DMA_BUF_SIZE) * 2L;
	DMAPtr = allocdmabuffer(NumberofBytes, ADDMAChannel, &DMAPage, &DMAPageOffset);	// Allocating memory buffer for DMA.
	if (DMAPtr == NULL)  {
	 cprintf("Buffer allocation has failed.");
	 getch();
	 return 1;
  } //if
	_fmemset(DMAPtr, 0, NumberofBytes -1);		// Write buffer to all "0".

  SetProgramScreen();

  SetBaseAddress(BASE_ADDRESS);        // Set BaseAddress

  InitBoard6430();                     // Board initializing
  Actual_PACER_RATE = SetPacerClock6430(RATE);	// Programing the timer.
  SetChannelGain6430(CHANNEL, GAIN, SE_DIFF); // Initilaizing Single A/D conversion.
  SetStartTrigger6430(0);              // Start Trigger = Software.
  SetStopTrigger6430(0);               // Stop Trigger = Software.
  SetConversionSelect6430(1);          // Conversion Select = Pacer Clock.

  DisableDMA(ADDMAChannel);            // Disable DMA in CPU.
  SetADDMA6430(ADDMAChannel,0);        // Program DMA 1 channel, DMA 2 disabled.
  SetDMAController(ADDMAChannel, MODE_REGISTER, DMAPage, DMAPageOffset, NumberofBytes);  // Set DMA Controller.
  EnableDMA(ADDMAChannel);             // Enable DMA.

  ClearADFIFO6430();                   // Clear FIFO.
  StartConversion6430();               // Start the measurement.

  while ( !IsADDMADone6430() && !kbhit() );   // Wait until measurement is running.
  DisableDMA(ADDMAChannel);            // Disable DMA.
  ClearADDMADone6430();                // Clear DMA done flag.
  if (kbhit()) getch();

  Rate = Actual_PACER_RATE;
  Range = 20;
  Slope = (20.0/65536.0);
  NumberOfPoints = DMA_BUF_SIZE;
  DataFile = fopen("DMA.DAT", "wb");

  fwrite(&Rate, sizeof(Rate), 1, DataFile);
  fwrite(&Range, sizeof(Range), 1, DataFile);
  fwrite(&Slope, sizeof(Slope), 1, DataFile);
  fwrite(&NumberOfPoints, sizeof(NumberOfPoints), 1, DataFile);
  fwrite(DMAPtr, sizeof(int), NumberOfPoints, DataFile);
  fclose(DataFile);

  freedmabuffer(DMAPtr);
  vgraph("DMA.DAT");
  clrscr();                            // Clear the screen.

  return 0;
} //main

⌨️ 快捷键说明

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