www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/08/22/03:11:33

Date: Mon, 22 Aug 1994 07:55:40 +0100 (CET)
From: "Roland Exler" <R DOT Exler AT jk DOT uni-linz DOT ac DOT at>
Sender: k3a0270 AT pop DOT uni-linz DOT ac DOT at
Reply-To: R DOT Exler AT jk DOT uni-linz DOT ac DOT at
To: <djgpp AT sun DOT soe DOT clarkson DOT edu>
Subject: RE: IRQs with djgpp

I saw a lot of messages about using int's, so I'll post a short example just
doing some io to a adc/dac-board using the system-timer.

Hope it helps,

  Roland

**** start of example (use -lpc to link the used functions of djgpp) ****


#define ADC 0x300
#define DAC 0x302

#define SAMPLES 100

short int *out_buffer;
short int *in_buffer;
volatile unsigned short int io_index;



_go32_dpmi_seginfo old_timer;

void timer_handler(void)
{
  if (io_index<SAMPLES)
  {
    outportw(DAC,out_buffer[io_index]);    // output to dac
    in_buffer[io_index]= inportw(ADC);     // input from adc
    io_index ++;
  }
}

void start_io(void)
{
  _go32_dpmi_seginfo new_timer;
  printf("starting interrupt-driven IO\n");
  _go32_dpmi_get_protected_mode_interrupt_vector(8, &old_timer);

  new_timer.pm_offset = (int)timer_handler;
  new_timer.pm_selector = _go32_my_cs();
  _go32_dpmi_chain_protected_mode_interrupt_vector(8, &new_timer);
}

void stop_io(void)
{
  printf("stopping IO\n");
  _go32_dpmi_set_protected_mode_interrupt_vector(8, &old_timer);
}


// calculation of values for output
void init_out(void)
{
  out_buffer =new short int[SAMPLES];
  in_buffer =new short int[SAMPLES];
  io_index=0;
  for (short int i=0; i<SAMPLES; i++)
  {
    out_buffer[i]=(int)(0x7FFF*sin(0.1*i));
    in_buffer[i]=0;
  }
}

void main(void)
{
  init_out();
  start_io();
  while (!kbhit() && (io_index<SAMPLES))
    printf("%i samples processed\n",io_index);
  stop_io();
}
+---------------------------------------+---------------------------+
I Roland Exler                          I EMAIL:                    I
I Universitaet Linz                     I R DOT Exler AT jk DOT uni-linz DOT ac DOT at I
I Institut fuer Elektrische Messtechnik I                           I
I Altenbergerstr. 69                    I Phone:                    I
I A-4040 Linz, AUSTRIA                  I + 43 732 2468 9205        I
+---------------------------------------+---------------------------+

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019