/*!*************************************************************************** *! *! 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. The command consists *! of 3 to 6 bytes. Byte 0 is the command *! code, and the following two to five bytes *! contain the train command data. The train *! command is sent msb first and byte 1 *! first. The preamble, start bits, error *! detection byte and packet end bits are *! added by the driver and should not be *! included in the command. *! *! The DCC packet is transmitted repeatedly *! until a new command is given. *! *! train_cmd_mfx Märklin/ESU mfx train command. The command *! consists of 4 to 10 bytes, and sends one *! mfx packet. Byte 0 is the command code. *! Byte 1 contains the length of the packet *! (in number of bits, excluding flags, CRC *! and bit stuffing). The following two to *! eight bytes contain the train command *! data. The data is sent msb first within *! bytes. Any remaining bits in the last byte *! of the command are ignored. The start and *! end flags as well as the CRC and bit *! stuffing are added by the driver and *! should not be included in the command. *! *! The mfx packet is transmitted repeatedly *! until a new command is given. *! *! train_cmd_mfx_once Similar to 'train_cmd_mfx' but the *! command is not repeated. Instead, a *! Märklin/Motorola idle packet is sent *! repeatedly after the command is completed *! until a new command is given. *! *! This command also allows several *! concatenated mfx packets, up to a maximum *! total command size of 32 bytes. Each mfx *! packet starts with one byte containing *! the packet length, and the following bytes *! in each packet contain the packet data. *! *! 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 *! data. 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. *! *! The Märklin/Motorola packet is transmitted *! repeatedly until a new command is given. *! *! 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.alice-dsl.net/mue473/mfxmenue.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. *! *! Version: 0.2, 2007-02-12: - Added TRAIN_DCC_PACKET_GAP . *! *! Version: 0.3, 2007-09-08: - Updated the link to the mfx protocol *! description. No functional change. *! *! Version: 0.4, 2008-09-24 - Added 'train_cmd_mfx_once' command. *! Added description of mfx commands. *! --------------------------------------------------------------------------- *! *! (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 // DCC packet pause, in units of 17.36 us. The required pause is 5 ms. #define TRAIN_DCC_PACKET_GAP 288 //------------------------------------------------------------------ // 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_mfx_once = 'F', // Märklin/ESU mfx train command, not repeated. 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. };