home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / adav313.zip / gnat-3_13p-os2-bin-20010916.zip / emx / gnatlib / i-vxwork.ads < prev    next >
Text File  |  2000-07-19  |  7KB  |  161 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                 GNU ADA RUN-TIME LIBRARY (GNARL) COMPONENTS              --
  4. --                                                                          --
  5. --                      I N T E R F A C E S . V X W O R K S                 --
  6. --                                                                          --
  7. --                                   S p e c                                --
  8. --                                                                          --
  9. --                               $Revision: 1.1 $
  10. --                                                                          --
  11. --               Copyright (C) 1999 Ada Core Technologies, Inc.             --
  12. --                                                                          --
  13. -- GNARL is free software; you can  redistribute it  and/or modify it under --
  14. -- terms of the  GNU General Public License as published  by the Free Soft- --
  15. -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
  16. -- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
  17. -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
  18. -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
  19. -- for  more details.  You should have  received  a copy of the GNU General --
  20. -- Public License  distributed with GNARL; see file COPYING.  If not, write --
  21. -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
  22. -- MA 02111-1307, USA.                                                      --
  23. --                                                                          --
  24. -- As a special exception,  if other files  instantiate  generics from this --
  25. -- unit, or you link  this unit with other files  to produce an executable, --
  26. -- this  unit  does not  by itself cause  the resulting  executable  to  be --
  27. -- covered  by the  GNU  General  Public  License.  This exception does not --
  28. -- however invalidate  any other reasons why  the executable file  might be --
  29. -- covered by the  GNU Public License.                                      --
  30. --                                                                          --
  31. -- GNARL was developed by the GNARL team at Florida State University. It is --
  32. -- now maintained by Ada Core Technologies Inc. in cooperation with Florida --
  33. -- State University (http://www.gnat.com).                                  --
  34. --                                                                          --
  35. ------------------------------------------------------------------------------
  36.  
  37. --  This package provides a limited binding to the VxWorks API
  38. --  In particular, it interfaces with the VxWorks hardware interrupt facilities
  39. --  For a complete documentation on these operations, please consult your
  40. --  VxWorks Reference Manual.
  41.  
  42. with Interfaces.C;
  43. with System;
  44.  
  45. package Interfaces.VxWorks is
  46.    pragma Preelaborate (VxWorks);
  47.  
  48.    ------------------------------------------------------------------------
  49.    --  Here is a complete example that shows how to handle the Interrupt 18
  50.    --  in Ada using this package:
  51.  
  52.    --  with Interfaces.VxWorks; use Interfaces.VxWorks;
  53.    --  with System;
  54.    --
  55.    --  package P is
  56.    --
  57.    --     Count : Integer;
  58.    --     pragma Atomic (Count);
  59.    --
  60.    --     Level : constant := 1;
  61.    --     --  Interrupt level used by this example
  62.    --
  63.    --     procedure Handler (parameter : System.Address);
  64.    --
  65.    --  end P;
  66.    --
  67.    --  package body P is
  68.    --
  69.    --     procedure Handler (parameter : System.Address) is
  70.    --        S : STATUS;
  71.    --     begin
  72.    --        Count := Count + 1;
  73.    --        logMsg ("received an interrupt" & ASCII.LF & ASCII.Nul);
  74.    --        S := sysBusIntAck (intLevel => Level);
  75.    --     end Handler;
  76.    --  end P;
  77.    --
  78.    --  with Interfaces.VxWorks; use Interfaces.VxWorks;
  79.    --  with Ada.Text_IO; use Ada.Text_IO;
  80.    --
  81.    --  with P; use P;
  82.    --  procedure Useint is
  83.    --     Interrupt : constant := 18;
  84.    --
  85.    --     task T;
  86.    --
  87.    --     S : STATUS;
  88.    --
  89.    --     task body T is
  90.    --     begin
  91.    --        loop
  92.    --           Put_Line ("Generating an interrupt...");
  93.    --           delay 1.0;
  94.    --           S := sysBusIntGen (1, INUM_TO_IVEC (Interrupt));
  95.    --        end loop;
  96.    --     end T;
  97.    --
  98.    --  begin
  99.    --     S := sysIntEnable (intLevel => Level);
  100.    --     S := intConnect (INUM_TO_IVEC (Interrupt), handler'Access);
  101.    --
  102.    --     loop
  103.    --        delay 2.0;
  104.    --        Put_Line ("value of count:" & P.Count'Img);
  105.    --     end loop;
  106.    --  end Useint;
  107.    -------------------------------------
  108.  
  109.    package IC renames Interfaces.C;
  110.  
  111.    subtype int is IC.int;
  112.  
  113.    type STATUS is new int;
  114.    --  Equivalent of the C type STATUS
  115.  
  116.    OK    : constant STATUS := 0;
  117.    ERROR : constant STATUS := -1;
  118.  
  119.    type VOIDFUNCPTR is access procedure (parameter : System.Address);
  120.    type Interrupt_Vector is new System.Address;
  121.    type Exception_Vector is new System.Address;
  122.  
  123.    function intConnect
  124.      (vector    : Interrupt_Vector;
  125.       handler   : VOIDFUNCPTR;
  126.       parameter : System.Address := System.Null_Address) return STATUS;
  127.    --  Binding to the C routine intConnect.
  128.  
  129.    function INUM_TO_IVEC (intNum : int) return Interrupt_Vector;
  130.    --  Equivalent to the C macro INUM_TO_IVEC used to convert an interrupt
  131.    --  number to an interrupt vector
  132.  
  133.    function sysIntEnable (intLevel : int) return STATUS;
  134.    --  Binding to the C routine sysIntEnable
  135.  
  136.    function sysIntDisable (intLevel : int) return STATUS;
  137.    --  Binding to the C routine sysIntDisable
  138.  
  139.    function sysBusIntAck (intLevel : int) return STATUS;
  140.    --  Binding to the C routine sysBusIntAck
  141.  
  142.    function sysBusIntGen (intLevel : int; vector : Interrupt_Vector)
  143.      return STATUS;
  144.    --  Binding to the C routine sysBusIntGen
  145.  
  146.    procedure logMsg
  147.      (fmt : String; arg1, arg2, arg3, arg4, arg5, arg6 : int := 0);
  148.    --  Binding to the C routine logMsg. Note that it is the caller
  149.    --  responsibility to ensure that fmt is a null terminated string
  150.    --  (e.g logMsg ("Interrupt" & ASCII.Nul))
  151.  
  152. private
  153.    pragma Import (C, intConnect, "intConnect");
  154.    pragma Import (C, INUM_TO_IVEC, "__gnat_inum_to_ivec");
  155.    pragma Import (C, sysIntEnable, "sysIntEnable");
  156.    pragma Import (C, sysIntDisable, "sysIntDisable");
  157.    pragma Import (C, sysBusIntAck, "sysBusIntAck");
  158.    pragma Import (C, sysBusIntGen, "sysBusIntGen");
  159.    pragma Import (C, logMsg, "logMsg");
  160. end Interfaces.VxWorks;
  161.