isreserv.doc

来自「TC 下的菜单、鼠标开发辅助工具」· DOC 代码 · 共 67 行

DOC
67
字号


                                                                     ISRESERV


 ISRESERV    Reserve dynamic memory for use in ISR 
 
 #include <bintrupt.h>
 
 int isreserv(size_t reserve,
              size_t blksize,
              char **ppblock);
 
 reserv      Size of space (in bytes) to reserve for use in an ISR.  
 blksize     Size of block to allocate via malloc().  
 ppblock     Address of pointer to fill with address of block allocated via 
             malloc(), or to fill with NULL if failure.  
 (Returns)   Success code.  Possible values include:  
             IS_OK (0) -- Success.  
             IS_NO_MEMORY (1) -- Insufficient memory.  
             IS_RANGE (2) -- reserve or blksize is out of range.  

 ISRESERV allocates a block of space via malloc() in  such  a  way  that  the
 amount  of space specified by reserve is available for later allocation from
 an ISR or intervention function.  

 In the T, S, and M memory models of Turbo C you  should  use  the  resulting
 allocated  block  as  the  stack(s) for the stack of the ISR or intervention
 function in question.  In the C, L, and H memory models of Turbo C, you  can
 place  the  ISR  stack  or  intervention  function  stack wherever you wish;
 blksize can be as small as 1.  

 size_t is defined in the standard header file stdlib.h.  

 Example:  
 
           /* Prepare an ISR stack for an ISR that will need to        */
           /* allocate dynamic memory via malloc().                    */
       
       #include <bintrupt.h>
       
       #define MY_INTYPE       0x60
       #define MY_STK_SIZE     2048      /* A conservative stack size. */
       #define MY_NUM_STKS        5      /* Maximum nesting depth.     */
       #define MY_RESERVE     20000      /* Needed for malloc() inside */
                                         /* ISR.                       */
       
       void cdecl     my_isr(ALLREG *,ISRCTRL *,ISRMSG *);
       static ISRCTRL isrblk;
       char          *pstacks;
       
       if (IS_OK != isreserv(MY_RESERVE,MY_STK_SIZE*MY_NUM_STKS,&pstacks))
           exit(3);                      /* Quit:  not enough memory   */
       
       isinstal(MY_INTYPE,my_isr,"THIS IS MY ISR.",
                &isrblk,pstacks,MY_STK_SIZE,MY_NUM_STKS);







 BLAISE COMPUTING                                                    Page   1


⌨️ 快捷键说明

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