(***************************************************************************

     $RCSfile: BattMem.mod $
  Description: Interface to battmem.resource

   Created by: fjc (Frank Copeland)
    $Revision: 3.2 $
      $Author: fjc $
        $Date: 1994/08/08 00:51:03 $

  Includes Release 40.15

  (C) Copyright 1985-1993 Commodore-Amiga, Inc.
      All Rights Reserved

  Oberon-A interface Copyright © 1994, Frank Copeland.
  This file is part of the Oberon-A Interface.
  See Oberon-A.doc for conditions of use and distribution.

***************************************************************************)

MODULE BattMem;

(*
** $C- CaseChk       $I- IndexChk  $L+ LongAdr   $N- NilChk
** $P- PortableCode  $R- RangeChk  $S- StackChk  $T- TypeChk
** $V- OvflChk       $Z- ZeroVars
*)

IMPORT E := Exec, SYS := SYSTEM;


(*
**      $VER: battmem.h 36.4 (1.5.90)
**
**      BattMem resource name strings.
*)

CONST

  name        * = "battmem.resource";


(*
**      $VER: battmembitsamiga.h 39.3 (14.9.92)
**
**      BattMem Amiga specific bit definitions.
*)


(*
 * Amiga specific bits in the battery-backedup ram.
 *
 *      Bits 0 to 31, inclusive
 *)

(*
 * AmigaAmnesia
 *
 *              The battery-backedup memory has had a memory loss.
 *              This bit is used as a flag that the user should be
 *              notified that all battery-backed bit have been
 *              reset and that some attention is required. Zero
 *              indicates that a memory loss has occured.
 *)

  amigaAmnesiaAddr      * = 0;
  amigaAmnesiaLen       * = 1;


(*
 * scsiTimeout
 *
 *              adjusts the timeout value for SCSI device selection.  A
 *              value of 0 will produce short timeouts (128 ms) while a
 *              value of 1 produces long timeouts (2 sec).  This is used
 *              for SeaCrate drives (and some Maxtors apparently) that
 *              don`t respond to selection until they are fully spun up
 *              and intialised.
 *)

  scsiTimeoutAddr       * = 1;
  scsiTimeoutLen        * = 1;


(*
 * scsiLuns
 *
 *              Determines if the controller attempts to access logical
 *              units above 0 at any given SCSI address.  This prevents
 *              problems with drives that respond to ALL LUN addresses
 *              (instead of only 0 like they should).  Default value is
 *              0 meaning don't support LUNs.
 *)

  scsiLunsAddr          * = 2;
  scsiLunsLen           * = 1;


(*
**      $VER: battmembitsamix.h 1.1 (25.5.90)
**
**      BattMem Amix specific bit definitions.
*)


(*
 *      See Amix documentation for these bit definitions
 *
 *      Bits 32 to 63, inclusive
 *)

(*
**      $VER: battmembitsshared.h 39.2 (4.6.93)
**
**      BattMem shared specific bit definitions.
*)


(*
 * Shared bits in the battery-backedup ram.
 *
 *      Bits 64 and above
 *)

(*
 * sharedAmnesia
 *
 *              The battery-backedup memory has had a memory loss.
 *              This bit is used as a flag that the user should be
 *              notified that all battery-backed bit have been
 *              reset and that some attention is required. Zero
 *              indicates that a memory loss has occured.
 *)

  sharedAmnesiaAddr     * = 64;
  sharedAmnesiaLen      * = 1;


(*
 * scsiHostID
 *
 *              a 3 bit field (0-7) that is stored in complemented form
 *              (this is so that default value of 0 really means 7)
 *              It's used to set the A3000 controllers SCSI ID (on reset)
 *)

  scsiHostIdAddr       * = 65;
  scsiHostIdLen        * = 3;


(*
 * scsiSyncXfer
 *
 *              determines if the driver should initiate synchronous
 *              transfer requests or leave it to the drive to send the
 *              first request.  This supports drives that crash or
 *              otherwise get confused when presented with a sync xfer
 *              message.  Default=0=sync xfer not initiated.
 *)

  scsiSyncXferAddr     * = 68;
  scsiSyncXferLen      * = 1;

(*
 * scsiFastSync
 *
 *              determines if the driver should initiate fast synchronous
 *              transfer requests (>5MB/s) instead of older <=5MB/s requests.
 *              Note that this has no effect if synchronous transfers are not
 *              negotiated by either side.
 *              Default=0=fast sync xfer used.
 *)

  scsiFastSyncAddr * = 69;
  scsiFastSyncLen * = 1;

(*
 * scsiTagQueues
 *
 *              determines if the driver should use SCSI-2 tagged queuing
 *              which allows the drive to accept and reorder multiple read
 *              and write requests.
 *              Default=0=tagged queuing NOT enabled
 *)

  scsiTagQueuesAddr * = 70;
  scsiTagQueuesLen * = 1;


(**-- Resource Base variable --------------------------------------------*)

TYPE

  BattMemBasePtr * = CPOINTER TO BattMemBase;
  BattMemBase * = RECORD (E.Node) END;

VAR

  base * : BattMemBasePtr;


(**-- Resource Functions ------------------------------------------------*)

(*
**      $VER: battmem_protos.h 1.5 (4.3.91)
*)

LIBCALL (base : BattMemBasePtr) ObtainBattSemaphore* ();
  -6;
LIBCALL (base : BattMemBasePtr) ReleaseBattSemaphore* ();
  -12;
LIBCALL (base : BattMemBasePtr) ReadBattMem*
  ( VAR buffer [8] : ARRAY OF SYS.BYTE;
    offset     [0] : E.ULONG;
    length     [1] : E.ULONG )
  : E.ULONG;
  -18;
LIBCALL (base : BattMemBasePtr) WriteBattMem*
  ( buffer [8] : ARRAY OF SYS.BYTE;
    offset [0] : E.ULONG;
    length [1] : E.ULONG )
  : E.ULONG;
  -24;


(**-- Resource Base variable --------------------------------------------*)
(** $L- Address globals through A4 *)


(**-----------------------------------*)
PROCEDURE OpenResource * (mustOpen : BOOLEAN);

BEGIN (* OpenResource *)
  IF base = NIL THEN
    base := E.base.OpenResource (name);
    IF mustOpen & (base = NIL) THEN HALT (100) END;
  END;
END OpenResource;


END BattMem.
