/*!***************************************************************************
*!
*! FILE NAME  : train_mod.h
*!
*! DESCRIPTION: Command definitions and other definitions for the train_mod
*!              module (synchronous serial driver module for model railway
*!              train control, for the ETRAX 100LX chip from Axis
*!              Communications AB).
*!
*!              The following commands are defined for the moment:
*!
*!              train_cmd_nop        No operation.
*!
*!              train_cmd_dcc        DCC train command, defined but not
*!                                   implemented.
*!
*!              train_cmd_mfx        Märklin/ESU mfx train command, defined
*!                                   but not implemented.
*!
*!              train_cmd_mm         Märklin/Motorola train command.
*!                                   The command consists of 4 bytes. Byte 0
*!                                   is the command code, and the following
*!                                   three bytes contain the train command.
*!                                   The train command is sent lsb first and
*!                                   byte 1 first. A Märklin/Motorola packet
*!                                   is 18 bits, so the 6 upper bits of byte 3
*!                                   are ignored.
*!
*!              train_cmd_mmd        Märklin/Motorola accessory command.
*!                                   Similar to train_cmd_mm but data is
*!                                   sent at double speed.
*!
*!              train_cmd_mm_pause   Märklin/Motorola pause configuration.
*!                                   The command consists of 3 bytes. Byte 0
*!                                   is the commmand code and the two following
*!                                   bytes form a 16-bit pause value, with
*!                                   byte 1 as the LSB and byte 2 as the MSB.
*!                                   The value should be given in units of
*!                                   17.36 us. Standard pause values for the
*!                                   Märklin/Motorola protocol are defined in
*!                                   train_mod.h .
*!
*!              For information about the Märklin/Motorola format, see
*!              http://spazioinwind.libero.it/scorzoni/motorola.htm
*!
*!              For information about the Märklin/ESU mfx format, see
*!              http://www.mue473.de/mfxrahmen.htm
*!
*!              For information about the DCC format, see
*!              http://www.nmra.org/standards/DCC/standards_rps/DCCStds.html
*!
*! Version: 0.0, 2007-01-14:   - Initial version.
*!
*! Version: 0.1, 2007-01-29:   - Added the train_cmd_mmd command.
*!
*! ---------------------------------------------------------------------------
*!
*! (C) Copyright 2007 Per Zander, SWEDEN http://home.swipnet.se/perz/
*!
*! ---------------------------------------------------------------------------
*!
*!    This program is free software; you can redistribute it and/or modify
*!    it under the terms of the GNU General Public License as published by
*!    the Free Software Foundation; either version 2 of the License, or
*!    (at your option) any later version.
*!
*!    This program is distributed in the hope that it will be useful,
*!    but WITHOUT ANY WARRANTY; without even the implied warranty of
*!    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*!    GNU General Public License for more details.
*!
*!		To have a copy of the GNU General Public License write to the Free
*!    Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
*!    02110-1301  USA.
*!
*!***************************************************************************/

//------------------------------------------------------------------
// Defines.
//------------------------------------------------------------------

//----- Märklin/Motorola format. -----*

// Idle packet. Note that data is transmitted lsb first.

#define TRAIN_MM_IDLE_PACKET 0x55

// Gap between the two halves of the packet. Should be 1.525 ms.
// Number of bytes = gap time * baud rate / 8 = 1.525 * 460.8 / 8 = 88.

#define TRAIN_MM_INTRA_PACKET_GAP 88

// Pause time between packets. There are three "standard" alternatives,
// 1.025 ms, 4.025 ms and 6.025 ms.
// For 1.025 ms pause: 1.025 * 460.8 / 8 = 59.

#define TRAIN_MM_SMALL_PACKET_GAP 59

// For 4.025 ms pause: 4.025 * 460.8 / 8 = 232.

#define TRAIN_MM_INTER_PACKET_GAP 232

// For 6.025 ms pause: 6.025 * 460.8 / 8 = 347.

#define TRAIN_MM_MAX_PACKET_GAP 347

// Also define this constant for the train_cmd_mm_pause command.

#define TRAIN_MM_UNIVERSAL_PACKET_GAP 0

//------------------------------------------------------------------
// Command definitions.
//------------------------------------------------------------------

enum train_cmd_t {
  train_cmd_nop = 0,              // No operation.
  train_cmd_dcc = 'd',            // DCC train command.
  train_cmd_mfx = 'f',            // Märklin/ESU mfx train command.
  train_cmd_mm = 'm',             // Märklin/Motorola train command.
  train_cmd_mmd = 'a',            // Märklin/Motorola accessory command.
  train_cmd_mm_pause ='p'         // Märklin/Motorola pause config.
};
