home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c070 / 1.ddi / TOOLS.1 / ISRESERV.DOC next >
Encoding:
Text File  |  1989-03-31  |  2.4 KB  |  67 lines

  1.  
  2.  
  3.                                                                      ISRESERV
  4.  
  5.  
  6.  ISRESERV    Reserve dynamic memory for use in ISR 
  7.  
  8.  #include <bintrupt.h>
  9.  
  10.  int isreserv(size_t reserve,
  11.               size_t blksize,
  12.               char **ppblock);
  13.  
  14.  reserv      Size of space (in bytes) to reserve for use in an ISR.  
  15.  blksize     Size of block to allocate via malloc().  
  16.  ppblock     Address of pointer to fill with address of block allocated via 
  17.              malloc(), or to fill with NULL if failure.  
  18.  (Returns)   Success code.  Possible values include:  
  19.              IS_OK (0) -- Success.  
  20.              IS_NO_MEMORY (1) -- Insufficient memory.  
  21.              IS_RANGE (2) -- reserve or blksize is out of range.  
  22.  
  23.  ISRESERV allocates a block of space via malloc() in  such  a  way  that  the
  24.  amount  of space specified by reserve is available for later allocation from
  25.  an ISR or intervention function.  
  26.  
  27.  In the T, S, and M memory models of Turbo C you  should  use  the  resulting
  28.  allocated  block  as  the  stack(s) for the stack of the ISR or intervention
  29.  function in question.  In the C, L, and H memory models of Turbo C, you  can
  30.  place  the  ISR  stack  or  intervention  function  stack wherever you wish;
  31.  blksize can be as small as 1.  
  32.  
  33.  size_t is defined in the standard header file stdlib.h.  
  34.  
  35.  Example:  
  36.  
  37.            /* Prepare an ISR stack for an ISR that will need to        */
  38.            /* allocate dynamic memory via malloc().                    */
  39.        
  40.        #include <bintrupt.h>
  41.        
  42.        #define MY_INTYPE       0x60
  43.        #define MY_STK_SIZE     2048      /* A conservative stack size. */
  44.        #define MY_NUM_STKS        5      /* Maximum nesting depth.     */
  45.        #define MY_RESERVE     20000      /* Needed for malloc() inside */
  46.                                          /* ISR.                       */
  47.        
  48.        void cdecl     my_isr(ALLREG *,ISRCTRL *,ISRMSG *);
  49.        static ISRCTRL isrblk;
  50.        char          *pstacks;
  51.        
  52.        if (IS_OK != isreserv(MY_RESERVE,MY_STK_SIZE*MY_NUM_STKS,&pstacks))
  53.            exit(3);                      /* Quit:  not enough memory   */
  54.        
  55.        isinstal(MY_INTYPE,my_isr,"THIS IS MY ISR.",
  56.                 &isrblk,pstacks,MY_STK_SIZE,MY_NUM_STKS);
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  BLAISE COMPUTING                                                    Page   1
  65.  
  66.  
  67.