------------------------------------------------------------------------------
--                                                                          --
--                             GNAT EXAMPLE                                 --
--                                                                          --
--             Copyright (C) 2014, Free Software Foundation, Inc.           --
--                                                                          --
-- GNAT is free software;  you can  redistribute it  and/or modify it under --
-- terms of the  GNU General Public License as published  by the Free Soft- --
-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE.                                     --
--                                                                          --
--                                                                          --
--                                                                          --
--                                                                          --
--                                                                          --
-- You should have received a copy of the GNU General Public License and    --
-- a copy of the GCC Runtime Library Exception along with this program;     --
-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
-- <http://www.gnu.org/licenses/>.                                          --
--                                                                          --
-- GNAT was originally developed  by the GNAT team at  New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc.      --
--                                                                          --
------------------------------------------------------------------------------

--  This file provides declarations for the user LEDs on the TMS570LS31
--  board from Texas Instruments.

with TMS570.GPIO;   use TMS570.GPIO;
with System;

package TMS570.LEDs is
   pragma Elaborate_Body;

   type User_LED is (Right, Left);

   for User_LED use
     (
      Right        => GPIO_Pin_6,
      Left         => GPIO_Pin_7);

   --  As a result of the representation clause, avoid iterating directly over
   --  the type since that will require an implicit lookup in the generated
   --  code of the loop.  Such usage seems unlikely so this direct
   --  representation is reasonable, and efficient.

   for User_LED'Size use Word'Size;
   --  we convert the LED values to Word values in order to write them to
   --  the registers, so the size must be the same

   procedure On  (This : User_LED) with Inline;
   procedure Off (This : User_LED) with Inline;

   -----------------------------------------------------------------------------
   --
   -----------------------------------------------------------------------------
private
   GPIO_Base : GPIO_Base_Register with
     Volatile,
     Address => System'To_Address (16#FFF7_BC00#);  -- GPIO BASE
   pragma Import (Ada, GPIO_Base);

   GPIOB_Port : GPIO_Register with
     Volatile,
     Address => System'To_Address (16#FFF7_BC54#);  -- GPIOB Port
   pragma Import (Ada, GPIOB_Port);

end TMS570.LEDs;
