home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / lxapi32.zip / Dev32 / lxdispatch.c < prev    next >
C/C++ Source or Header  |  2002-04-26  |  3KB  |  137 lines

  1. /* $Id: lxdispatch.c,v 1.2 2002/04/26 23:08:55 smilcke Exp $ */
  2.  
  3. /*
  4.  * dispatch.c
  5.  * Autor:               Stefan Milcke
  6.  * Erstellt am:         12.11.2001
  7.  * Letzte Aenderung am: 27.04.2002
  8.  *
  9. */
  10. extern "C" {               // 16-bit header files are not C++ aware
  11. #define INCL_NOPMAPI
  12. #define INCL_DOSMISC
  13. #include <os2.h>
  14. }
  15.  
  16. #include <devhelp.h>
  17. #include <devtype.h>
  18. #include <devrp.h>
  19. #include <ldefos2.h>
  20. #include "lxdevown.h"
  21. #include <linux/types.h>
  22.  
  23. extern "C" void OS2_V4lx_close_all_opened_devices(void);
  24.  
  25. //--------------------------------- StratClose ---------------------------------
  26. ULONG StratClose(RP __far* _rp)
  27. {
  28.  RPOpenClose __far* rp = (RPOpenClose __far*)_rp;
  29.  // only called if device successfully opened
  30.  numOS2Opens--;
  31.  if (numOS2Opens == 0)
  32.  {
  33.   OS2_V4lx_close_all_opened_devices();
  34.   deviceOwner = DEV_NO_OWNER;
  35.  }
  36.  return(RPDONE);
  37. }
  38.  
  39.  
  40. #define MAX_SCHEDULES   16
  41.  
  42. extern "C" int volatile timervecs_initialized;
  43. extern "C" unsigned long volatile jiffies=0;
  44. extern "C" unsigned long schedules[MAX_SCHEDULES]={0};
  45. extern "C" void run_timer_list(void);
  46. extern "C" void run_thread_list(void);
  47.  
  48. int volatile timer_mode=0;
  49.  
  50. //--------------------------------- TimerEntry ---------------------------------
  51. VOID __far TimerEntry(VOID);
  52. #pragma aux TimerEntry "TIMER_ENTRY"
  53. VOID __far TimerEntry(VOID)
  54. {
  55.  // increment jiffies
  56.  jiffies++;
  57.  timer_mode=1;
  58.  // run timer list if initialized
  59.  if(timervecs_initialized)
  60.   run_timer_list();
  61.  run_thread_list();
  62.  timer_mode=0;
  63. }
  64.  
  65. //------------------------------ schedule_timeout ------------------------------
  66. extern "C" signed long schedule_timeout(signed long timeout)
  67. {
  68.  int i;
  69.  signed long rc=0;
  70.  DWORD cpuflags;
  71.  DevPushfCli(&cpuflags);
  72.  if(!timer_mode)
  73.  {
  74.   for(i=0;i<MAX_SCHEDULES;i++)
  75.   {
  76.    if(!schedules[i])
  77.    {
  78.     schedules[i]=(unsigned long)&schedules[i];
  79.     rc=DevBlock(schedules[i],timeout==-1 ? 1 : timeout,0);
  80.     DevCli();
  81. //    DevPopf(cpuflags);
  82.     schedules[i]=0;
  83.     break;
  84.    }
  85.   }
  86.  }
  87.  DevPopf(cpuflags);
  88.  return rc;
  89. }
  90.  
  91. //---------------------------------- schedule ----------------------------------
  92. extern "C" void schedule(void)
  93. {
  94.  schedule_timeout(-1);
  95. }
  96.  
  97. //----------------------------------- EoiIrq -----------------------------------
  98. extern "C" void EoiIrq(int irq)
  99. {
  100.  DevEOI(irq);
  101. }
  102.  
  103. extern "C" FUNCTION IRQ_HDLRPTR;
  104. static int irq_use_count[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  105.  
  106. //--------------------------------- RequestIrq ---------------------------------
  107. extern "C" int RequestIrq(int irq,int flags)
  108. {
  109.  int rc=0;
  110.  if(irq>=0 && irq<=15)
  111.  {
  112.   if(0==irq_use_count[irq])
  113.   {
  114.    rc=DevIRQSet(irq,IRQ_HDLRPTR,flags);
  115.    if(0==rc)
  116.     irq_use_count[irq]++;
  117.   }
  118.   return rc;
  119.  }
  120.  else
  121.   return -1;
  122. }
  123.  
  124. //---------------------------------- FreeIrq -----------------------------------
  125. extern "C" void FreeIrq(int irq)
  126. {
  127.  if(irq>=0 && irq<=15)
  128.  {
  129.   if(irq_use_count[irq])
  130.   {
  131.    irq_use_count[irq]--;
  132.    if(0==irq_use_count[irq])
  133.     DevIRQClear(irq);
  134.   }
  135.  }
  136. }
  137.