delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/04/14/12:00:34

From: Matthew Kennedy <q957722 AT mail DOT connect DOT usq DOT edu DOT au>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Real mode ISR's
Date: Tue, 15 Apr 1997 00:27:47 +1000
Organization: University of Southern Queensland
Lines: 154
Message-ID: <33523EE3.6604@mail.connect.usq.edu.au>
References: <5iqtre$jt7 AT lion DOT cs DOT latrobe DOT edu DOT au>
Reply-To: q957722 AT mail DOT connect DOT usq DOT edu DOT au
NNTP-Posting-Host: 139.86.24.105
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

This is a multi-part message in MIME format.

--------------49D53C8F3FBE
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hello Aussie!

There are many FAQs and example files on the internet showing how you
can create ISRs. I recently created the following (rather simple) ISR to
execute a 'task' periodically. It is straight forward and serves as a
good intro. Note, it won't run by itself - its sort-of-a module, but the
use of it in a main program is obvious.

Gregary J Boyles wrote:
> 
> Which are the steps which need to be taken on entering and leaving an ISR?
> I can't find any info which will tell me and I am used to using the
> Borland key word 'interrupt'.
> 
> When using _go32_dpmi_allocate_dos_memory(...) I was going to enclose the
> ISR function and variables it uses inside two dummy functions and do
> pointer arithmetic to determine the size of the memory required. Is there
> any way of ensuring that gcc won't rearrange the variables or functions?

-- 
Matthew Kennedy
Student of Electronics Engineering, USQ Australia

--------------49D53C8F3FBE
Content-Type: text/plain; charset=us-ascii; name="clock.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="clock.c"

/*
 *  MODULE: clock.c
 *
 *    Implements a user timer interrupt function which executes 
 *    a specified user function every arbitary count of timer
 *    ticks (55ms).
 *
 *    NOTES: No functions are lock out of paging!  To ensure 
 *    safe operation, the startup flags should be set so that
 *    all virtual memory is disabled.
 *
 */

#include <sys/segments.h>
#include <go32.h>
#include <dpmi.h>
#include "clock.h"

/*
 *  Interrupt number of the internal PC timer.
 */
#define TIMER 0x1c

/*
 *  Copies of old interrupt timer and new timer ISR.
 */
static _go32_dpmi_seginfo old_timer, new_timer;

/*
 *  Global variables used by clock().
 */
static void (*process)(void);
static unsigned long interval;
volatile unsigned long clock_count;


/*
 *	FUNCTION: clock()
 *
 *    This function is hooked directly into the PC real-time clock.
 *    Every 'interval' ticks, the function variable process() is
 *    executed.
 *
 *    NOTES:  Must call 'init_clock()' for this function to work.
 */
void clock(void)
{
  if (clock_count % interval==0)
    process();
  clock_count++;
}


/*
 *  FUNCTION: init_clock()
 *
 *    Hook the PC real-time clock interrupt.  The hooked function,
 *    clock() is executed every 'time_interval' increments. 
 *    init_clock() allows the user to specify an auxilliary function 
 *    to call every time a clock interrupt occurs called 'x()'.
 *
 *    NOTES:  1 'time_interval' = 1/18.2 seconds (appx)
 */
void init_clock(void (*x)(void),unsigned long time_interval)
{
  process = x;
  interval = time_interval;
  /* save the old clock interrupt info */  
  _go32_dpmi_get_protected_mode_interrupt_vector(TIMER, &old_timer);
  /* create wrapper function to chain into old timer ISR */
  new_timer.pm_offset = (unsigned long)&clock;
  new_timer.pm_selector = _my_cs();
  _go32_dpmi_allocate_iret_wrapper(&new_timer);  
  _go32_dpmi_chain_protected_mode_interrupt_vector(TIMER, &new_timer);
  /* set interrupt vector to point to new handler */
  _go32_dpmi_set_protected_mode_interrupt_vector(TIMER, &new_timer);
}


/*
 *  FUNCTION: done_clock()
 *
 *    This function unhooks clock() from the timer interrupt.
 *    done_clock() must be called after init_clock() and before
 *    before main() finishes - else unpredictable behaviour!
 *
 *    NOTES:  init_clock() must be called before done_clock()
 */
void done_clock(void)
{
  /* free wrappers and restore old clock interrupt */
  _go32_dpmi_set_protected_mode_interrupt_vector(TIMER, &old_timer);
  _go32_dpmi_free_iret_wrapper(&new_timer);
}

--------------49D53C8F3FBE
Content-Type: text/plain; charset=us-ascii; name="clock.h"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="clock.h"

#ifndef _CLOCK_H_
#define _CLOCK_H_

#ifdef __cplusplus
extern "C" {
#endif

/* function prototypes */

void init_clock(void (*x)(void),unsigned long time_interval);
void done_clock(void);

#ifdef __cplusplus
}
#endif

#endif /* _CLOCK_H_ */

--------------49D53C8F3FBE--

- Raw text -


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