with Byte_Defs;
with Crc;

package Crc_Ccitt is

    Generator : constant Crc.Polynomial -- X**16 + X**12 + X**5 + 1
        := Crc.Polynomial'(12 => True, 5 => True, 0 => True, others => False);

    package Accumulator is new Crc.Accumulator (Generator);

    subtype Checksum is Crc.Checksum;

    Preset : constant Checksum := Crc.All_1;
    Remainder : constant Checksum := Crc.Convert (2#0001110100001111#);

    procedure Accumulate (R : in out Checksum; D : Byte_Defs.Byte)
        renames Accumulator.Accumulate;
    procedure Accumulate (R : in out Checksum; D : Byte_Defs.Byte_String)
        renames Accumulator.Accumulate;

    -- To calculate a checksum, declare a variable R of type
    -- Checksum, initialize it to Preset, and Accumulate
    -- over all the data bytes.  Transmit Crc."not" (R)
    -- in index order.

    -- To check a checksum, declare a variable R of type
    -- Checksum, initialize it to Preset, and Accumulate
    -- over all the data bytes AND the checksum bytes.
    -- At this point, R = Remainder if there are no errors.

end Crc_Ccitt;