# 1 "pixymove.c"
# 1 "C:\\ftMscCComp_V4.4.1\\Demo_C\\Demo\\pixymove//"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "pixymove.c"
//=============================================================================
// Demo program PIXY.c
//
// Can be run under control of the ROBO TX Controller
// firmware in download (local) mode.
// This example shows how to sense the picture with the I2C Pixy - CMUcam5
// sensor. The port-address is 0x14. After writing some initialisation bytes the program enters
// a loop updating the measured values for the detected objects each 20ms.
// The Roboter trys to follow objekt number 1.
//
// The procedures i2cread, txsinglelamp and txmotor of ROBO_TX_PRG are used.
//
// Disclaimer - Exclusion of Liability
//
// This software 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. It can be used and modified by anyone
// free of any license obligations or authoring rights.
//=============================================================================

# 1 "../../Common/ROBO_TX_PRG.h" 1
//=============================================================================
// Header file with definition of the software interface to the
// ROBO TX Controller program.
// Can be used for building C-programs which can run under control
// of the ROBO TX Controller firmware in download (local) mode.
//
// Erweiterte Version vom 20.10.2016:
// Um die Programmierung in C zu erleichtern, wurden die folgenden Prozeduren ergänzt:
//      i2cread, i2cwrite, txlamp, txmotor, txstartmotorsync, txaremotorsready,
//      txstartmotor, txmotorready,
//      txclearcounter, txgetcounter,
//      txtrack, txinput, txanalog, txvoltage, txdistance 
// Der Pointer zum Transfer Area p_ta ist global deklariert und daher in diesen 
// Prozeduren zugänglich.
//
// Disclaimer - Exclusion of Liability
//
// This software 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. It can be used and modified by anyone
// free of any license obligations or authoring rights.
//=============================================================================




# 1 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/math.h" 1 3




# 1 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/sys/reent.h" 1 3
/* This header file provides the reentrancy.  */

/* WARNING: All identifiers here must begin with an underscore.  This file is
   included by stdio.h and others and we therefore must only use identifiers
   in the namespace allotted to us.  */







# 1 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/_ansi.h" 1 3
/* Provide support for both ANSI and non-ANSI environments.  */

/* Some ANSI environments are "broken" in the sense that __STDC__ cannot be
   relied upon to have it's intended meaning.  Therefore we must use our own
   concoction: _HAVE_STDC.  Always use _HAVE_STDC instead of __STDC__ in newlib
   sources!

   To get a strict ANSI C environment, define macro __STRICT_ANSI__.  This will
   "comment out" the non-ANSI parts of the ANSI header files (non-ANSI header
   files aren't affected).  */




# 1 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/newlib.h" 1 3
/* newlib.h.  Generated by configure.  */
/* newlib.hin.  Generated from configure.in by autoheader.  */




/* EL/IX level */
/* #undef _ELIX_LEVEL */

/* Newlib version */


/* C99 formats support (such as %a, %zu, ...) in IO functions like
 * printf/scanf enabled */
/* #undef _WANT_IO_C99_FORMATS */

/* long long type support in IO functions like printf/scanf enabled */
/* #undef _WANT_IO_LONG_LONG */

/* long double type support in IO functions like printf/scanf enabled */
/* #undef _WANT_IO_LONG_DOUBLE */

/* Positional argument support in printf functions enabled.  */
/* #undef _WANT_IO_POS_ARGS */

/* Optional reentrant struct support.  Used mostly on platforms with
   very restricted storage.  */
/* #undef _WANT_REENT_SMALL */

/* Multibyte supported */
/* #undef _MB_CAPABLE */

/* MB_LEN_MAX */


/* ICONV enabled */
/* #undef _ICONV_ENABLED */

/* Enable ICONV external CCS files loading capabilities */
/* #undef _ICONV_ENABLE_EXTERNAL_CCS */

/* Define if the linker supports .preinit_array/.init_array/.fini_array
 * sections.  */


/* True if atexit() may dynamically allocate space for cleanup
   functions.  */


/* Define if the compiler supports aliasing an array to an address.  */
/* #undef  _HAVE_ARRAY_ALIASING */

/*
 * Iconv encodings enabled ("to" direction)
 */
/* #undef _ICONV_TO_ENCODING_BIG5 */
/* #undef _ICONV_TO_ENCODING_CP775 */
/* #undef _ICONV_TO_ENCODING_CP850 */
/* #undef _ICONV_TO_ENCODING_CP852 */
/* #undef _ICONV_TO_ENCODING_CP855 */
/* #undef _ICONV_TO_ENCODING_CP866 */
/* #undef _ICONV_TO_ENCODING_EUC_JP */
/* #undef _ICONV_TO_ENCODING_EUC_TW */
/* #undef _ICONV_TO_ENCODING_EUC_KR */
/* #undef _ICONV_TO_ENCODING_ISO_8859_1 */
/* #undef _ICONV_TO_ENCODING_ISO_8859_10 */
/* #undef _ICONV_TO_ENCODING_ISO_8859_11 */
/* #undef _ICONV_TO_ENCODING_ISO_8859_13 */
/* #undef _ICONV_TO_ENCODING_ISO_8859_14 */
/* #undef _ICONV_TO_ENCODING_ISO_8859_15 */
/* #undef _ICONV_TO_ENCODING_ISO_8859_2 */
/* #undef _ICONV_TO_ENCODING_ISO_8859_3 */
/* #undef _ICONV_TO_ENCODING_ISO_8859_4 */
/* #undef _ICONV_TO_ENCODING_ISO_8859_5 */
/* #undef _ICONV_TO_ENCODING_ISO_8859_6 */
/* #undef _ICONV_TO_ENCODING_ISO_8859_7 */
/* #undef _ICONV_TO_ENCODING_ISO_8859_8 */
/* #undef _ICONV_TO_ENCODING_ISO_8859_9 */
/* #undef _ICONV_TO_ENCODING_ISO_IR_111 */
/* #undef _ICONV_TO_ENCODING_KOI8_R */
/* #undef _ICONV_TO_ENCODING_KOI8_RU */
/* #undef _ICONV_TO_ENCODING_KOI8_U */
/* #undef _ICONV_TO_ENCODING_KOI8_UNI */
/* #undef _ICONV_TO_ENCODING_UCS_2 */
/* #undef _ICONV_TO_ENCODING_UCS_2_INTERNAL */
/* #undef _ICONV_TO_ENCODING_UCS_2BE */
/* #undef _ICONV_TO_ENCODING_UCS_2LE */
/* #undef _ICONV_TO_ENCODING_UCS_4 */
/* #undef _ICONV_TO_ENCODING_UCS_4_INTERNAL */
/* #undef _ICONV_TO_ENCODING_UCS_4BE */
/* #undef _ICONV_TO_ENCODING_UCS_4LE */
/* #undef _ICONV_TO_ENCODING_US_ASCII */
/* #undef _ICONV_TO_ENCODING_UTF_16 */
/* #undef _ICONV_TO_ENCODING_UTF_16BE */
/* #undef _ICONV_TO_ENCODING_UTF_16LE */
/* #undef _ICONV_TO_ENCODING_UTF_8 */
/* #undef _ICONV_TO_ENCODING_WIN_1250 */
/* #undef _ICONV_TO_ENCODING_WIN_1251 */
/* #undef _ICONV_TO_ENCODING_WIN_1252 */
/* #undef _ICONV_TO_ENCODING_WIN_1253 */
/* #undef _ICONV_TO_ENCODING_WIN_1254 */
/* #undef _ICONV_TO_ENCODING_WIN_1255 */
/* #undef _ICONV_TO_ENCODING_WIN_1256 */
/* #undef _ICONV_TO_ENCODING_WIN_1257 */
/* #undef _ICONV_TO_ENCODING_WIN_1258 */

/*
 * Iconv encodings enabled ("from" direction)
 */
/* #undef _ICONV_FROM_ENCODING_BIG5 */
/* #undef _ICONV_FROM_ENCODING_CP775 */
/* #undef _ICONV_FROM_ENCODING_CP850 */
/* #undef _ICONV_FROM_ENCODING_CP852 */
/* #undef _ICONV_FROM_ENCODING_CP855 */
/* #undef _ICONV_FROM_ENCODING_CP866 */
/* #undef _ICONV_FROM_ENCODING_EUC_JP */
/* #undef _ICONV_FROM_ENCODING_EUC_TW */
/* #undef _ICONV_FROM_ENCODING_EUC_KR */
/* #undef _ICONV_FROM_ENCODING_ISO_8859_1 */
/* #undef _ICONV_FROM_ENCODING_ISO_8859_10 */
/* #undef _ICONV_FROM_ENCODING_ISO_8859_11 */
/* #undef _ICONV_FROM_ENCODING_ISO_8859_13 */
/* #undef _ICONV_FROM_ENCODING_ISO_8859_14 */
/* #undef _ICONV_FROM_ENCODING_ISO_8859_15 */
/* #undef _ICONV_FROM_ENCODING_ISO_8859_2 */
/* #undef _ICONV_FROM_ENCODING_ISO_8859_3 */
/* #undef _ICONV_FROM_ENCODING_ISO_8859_4 */
/* #undef _ICONV_FROM_ENCODING_ISO_8859_5 */
/* #undef _ICONV_FROM_ENCODING_ISO_8859_6 */
/* #undef _ICONV_FROM_ENCODING_ISO_8859_7 */
/* #undef _ICONV_FROM_ENCODING_ISO_8859_8 */
/* #undef _ICONV_FROM_ENCODING_ISO_8859_9 */
/* #undef _ICONV_FROM_ENCODING_ISO_IR_111 */
/* #undef _ICONV_FROM_ENCODING_KOI8_R */
/* #undef _ICONV_FROM_ENCODING_KOI8_RU */
/* #undef _ICONV_FROM_ENCODING_KOI8_U */
/* #undef _ICONV_FROM_ENCODING_KOI8_UNI */
/* #undef _ICONV_FROM_ENCODING_UCS_2 */
/* #undef _ICONV_FROM_ENCODING_UCS_2_INTERNAL */
/* #undef _ICONV_FROM_ENCODING_UCS_2BE */
/* #undef _ICONV_FROM_ENCODING_UCS_2LE */
/* #undef _ICONV_FROM_ENCODING_UCS_4 */
/* #undef _ICONV_FROM_ENCODING_UCS_4_INTERNAL */
/* #undef _ICONV_FROM_ENCODING_UCS_4BE */
/* #undef _ICONV_FROM_ENCODING_UCS_4LE */
/* #undef _ICONV_FROM_ENCODING_US_ASCII */
/* #undef _ICONV_FROM_ENCODING_UTF_16 */
/* #undef _ICONV_FROM_ENCODING_UTF_16BE */
/* #undef _ICONV_FROM_ENCODING_UTF_16LE */
/* #undef _ICONV_FROM_ENCODING_UTF_8 */
/* #undef _ICONV_FROM_ENCODING_WIN_1250 */
/* #undef _ICONV_FROM_ENCODING_WIN_1251 */
/* #undef _ICONV_FROM_ENCODING_WIN_1252 */
/* #undef _ICONV_FROM_ENCODING_WIN_1253 */
/* #undef _ICONV_FROM_ENCODING_WIN_1254 */
/* #undef _ICONV_FROM_ENCODING_WIN_1255 */
/* #undef _ICONV_FROM_ENCODING_WIN_1256 */
/* #undef _ICONV_FROM_ENCODING_WIN_1257 */
/* #undef _ICONV_FROM_ENCODING_WIN_1258 */
# 16 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/_ansi.h" 2 3
# 1 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/sys/config.h" 1 3



# 1 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/machine/ieeefp.h" 1 3



/* This file can define macros to choose variations of the IEEE float
   format:

   _FLT_LARGEST_EXPONENT_IS_NORMAL

	Defined if the float format uses the largest exponent for finite
	numbers rather than NaN and infinity representations.  Such a
	format cannot represent NaNs or infinities at all, but it's FLT_MAX
	is twice the IEEE value.

   _FLT_NO_DENORMALS

	Defined if the float format does not support IEEE denormals.  Every
	float with a zero exponent is taken to be a zero representation.
 
   ??? At the moment, there are no equivalent macros above for doubles and
   the macros are not fully supported by --enable-newlib-hw-fp.

   __IEEE_BIG_ENDIAN

        Defined if the float format is big endian.  This is mutually exclusive
        with __IEEE_LITTLE_ENDIAN.

   __IEEE_LITTLE_ENDIAN
 
        Defined if the float format is little endian.  This is mutually exclusive
        with __IEEE_BIG_ENDIAN.

   Note that one of __IEEE_BIG_ENDIAN or __IEEE_LITTLE_ENDIAN must be specified for a
   platform or error will occur.

   __IEEE_BYTES_LITTLE_ENDIAN

        This flag is used in conjunction with __IEEE_BIG_ENDIAN to describe a situation 
	whereby multiple words of an IEEE floating point are in big endian order, but the
	words themselves are little endian with respect to the bytes.

   _DOUBLE_IS_32BITS 

        This is used on platforms that support double by using the 32-bit IEEE
        float type.

   _FLOAT_ARG

        This represents what type a float arg is passed as.  It is used when the type is
        not promoted to double.
	
*/


/* ARM traditionally used big-endian words; and within those words the
   byte ordering was big or little endian depending upon the target.
   Modern floating-point formats are naturally ordered; in this case
   __VFP_FP__ will be defined, even if soft-float.  */
# 184 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/machine/ieeefp.h" 3
/* necv70 was __IEEE_LITTLE_ENDIAN. */
# 5 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/sys/config.h" 2 3

/* exceptions first */







/* 16 bit integer machines */
# 87 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/sys/config.h" 3
/* For the PowerPC eabi, force the _impure_ptr to be in .sdata */
# 138 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/sys/config.h" 3
/* This block should be kept in sync with GCC's limits.h.  The point
   of having these definitions here is to not include limits.h, which
   would pollute the user namespace, while still using types of the
   the correct widths when deciding how to define __int32_t and
   __int64_t.  */
# 163 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/sys/config.h" 3
/* End of block that should be kept in sync with GCC's limits.h.  */
# 192 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/sys/config.h" 3
/* Define return type of read/write routines.  In POSIX, the return type
   for read()/write() is "ssize_t" but legacy newlib code has been using
   "int" for some time.  If not specified, "int" is defaulted.  */
# 205 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/sys/config.h" 3
/* See if small reent asked for at configuration time and
   is not chosen by the platform by default.  */
# 17 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/_ansi.h" 2 3

/* First try to figure out whether we really are in an ANSI C environment.  */
/* FIXME: This probably needs some work.  Perhaps sys/config.h can be
   prevailed upon to give us a clue.  */
# 74 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/_ansi.h" 3
/* Support gcc's __attribute__ facility.  */







/*  ISO C++.  */
# 14 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/sys/reent.h" 2 3
# 1 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/sys/_types.h" 1 3
/* ANSI C namespace clean utility typedefs */

/* This file defines various typedefs needed by the system calls that support
   the C library.  Basically, they're just the POSIX versions with an '_'
   prepended.  This file lives in the `sys' directory so targets can provide
   their own if desired (or they can put target dependant conditionals here).
*/




# 1 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/machine/_types.h" 1 3
/*
 *  $Id: _types.h,v 1.3 2007/09/07 21:16:25 jjohnstn Exp $
 */



# 1 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/machine/_default_types.h" 1 3
/*
 *  $Id: _default_types.h,v 1.2 2008/06/11 22:14:54 jjohnstn Exp $
 */
# 12 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/machine/_default_types.h" 3
/*
 * Guess on types by examining *_MIN / *_MAX defines.
 */


/* GCC >= 3.3.0 has __<val>__ implicitly defined. */
# 26 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/machine/_default_types.h" 3
typedef signed char __int8_t ;
typedef unsigned char __uint8_t ;
# 36 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/machine/_default_types.h" 3
typedef signed short __int16_t;
typedef unsigned short __uint16_t;
# 46 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/machine/_default_types.h" 3
typedef __int16_t __int_least16_t;
typedef __uint16_t __uint_least16_t;
# 58 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/machine/_default_types.h" 3
typedef signed int __int32_t;
typedef unsigned int __uint32_t;
# 76 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/machine/_default_types.h" 3
typedef __int32_t __int_least32_t;
typedef __uint32_t __uint_least32_t;
# 99 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/machine/_default_types.h" 3
typedef signed long long __int64_t;
typedef unsigned long long __uint64_t;


/* POSIX mandates LLONG_MAX in <limits.h> */
# 8 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/machine/_types.h" 2 3
# 13 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/sys/_types.h" 2 3
# 1 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/sys/lock.h" 1 3



/* dummy lock routines for single-threaded aps */

typedef int _LOCK_T;
typedef int _LOCK_RECURSIVE_T;

# 1 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/_ansi.h" 1 3
/* Provide support for both ANSI and non-ANSI environments.  */

/* Some ANSI environments are "broken" in the sense that __STDC__ cannot be
   relied upon to have it's intended meaning.  Therefore we must use our own
   concoction: _HAVE_STDC.  Always use _HAVE_STDC instead of __STDC__ in newlib
   sources!

   To get a strict ANSI C environment, define macro __STRICT_ANSI__.  This will
   "comment out" the non-ANSI parts of the ANSI header files (non-ANSI header
   files aren't affected).  */
# 10 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/sys/lock.h" 2 3
# 14 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/sys/_types.h" 2 3


typedef long _off_t;







typedef short __dev_t;




typedef unsigned short __uid_t;


typedef unsigned short __gid_t;



__extension__ typedef long long _off64_t;


/*
 * We need fpos_t for the following, but it doesn't have a leading "_",
 * so we use _fpos_t instead.
 */

typedef long _fpos_t; /* XXX must match off_t in <sys/types.h> */
    /* (and must be `long' for now) */
# 56 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/sys/_types.h" 3
typedef int _ssize_t;






# 1 "c:\\ftmscccomp_v4.4.1\\demo_c\\bin\\gnu\\gnu_arm\\bin\\../lib/gcc/arm-elf/4.4.1/include/stddef.h" 1 3 4
/* Copyright (C) 1989, 1997, 1998, 1999, 2000, 2002, 2004, 2009
   Free Software Foundation, Inc.

This file is part of GCC.

GCC 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 3, or (at your option)
any later version.

GCC 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.

Under Section 7 of GPL version 3, you are granted additional
permissions described in the GCC Runtime Library Exception, version
3.1, as published by the Free Software Foundation.

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/>.  */

/*
 * ISO C Standard:  7.17  Common definitions  <stddef.h>
 */






/* Any one of these symbols __need_* means that GNU libc
   wants us just to define one data type.  So don't define
   the symbols that indicate this file's entire job has been done.  */
# 49 "c:\\ftmscccomp_v4.4.1\\demo_c\\bin\\gnu\\gnu_arm\\bin\\../lib/gcc/arm-elf/4.4.1/include/stddef.h" 3 4
/* This avoids lossage on SunOS but only if stdtypes.h comes first.
   There's no way to win with the other order!  Sun lossage.  */

/* On 4.3bsd-net2, make sure ansi.h is included, so we have
   one less case to deal with in the following.  */



/* On FreeBSD 5, machine/ansi.h does not exist anymore... */




/* In 4.3bsd-net2, machine/ansi.h defines these symbols, which are
   defined if the corresponding type is *not* defined.
   FreeBSD-2.1 defines _MACHINE_ANSI_H_ instead of _ANSI_H_ */
# 94 "c:\\ftmscccomp_v4.4.1\\demo_c\\bin\\gnu\\gnu_arm\\bin\\../lib/gcc/arm-elf/4.4.1/include/stddef.h" 3 4
/* Sequent's header files use _PTRDIFF_T_ in some conflicting way.
   Just ignore it.  */




/* On VxWorks, <type/vxTypesBase.h> may have defined macros like
   _TYPE_size_t which will typedef size_t.  fixincludes patched the
   vxTypesBase.h so that this macro is only defined if _GCC_SIZE_T is
   not defined, and so that defining this macro defines _GCC_SIZE_T.
   If we find that the macros are still defined at this point, we must
   invoke them so that the type is defined as expected.  */
# 119 "c:\\ftmscccomp_v4.4.1\\demo_c\\bin\\gnu\\gnu_arm\\bin\\../lib/gcc/arm-elf/4.4.1/include/stddef.h" 3 4
/* In case nobody has defined these types, but we aren't running under
   GCC 2.00, make sure that __PTRDIFF_TYPE__, __SIZE_TYPE__, and
   __WCHAR_TYPE__ have reasonable values.  This can happen if the
   parts of GCC is compiled by an older compiler, that actually
   include gstddef.h, such as collect2.  */

/* Signed type of difference of two pointers.  */

/* Define this type if we are doing the whole job,
   or if we want this type in particular.  */
# 164 "c:\\ftmscccomp_v4.4.1\\demo_c\\bin\\gnu\\gnu_arm\\bin\\../lib/gcc/arm-elf/4.4.1/include/stddef.h" 3 4
/* Unsigned type of `sizeof' something.  */

/* Define this type if we are doing the whole job,
   or if we want this type in particular.  */
# 237 "c:\\ftmscccomp_v4.4.1\\demo_c\\bin\\gnu\\gnu_arm\\bin\\../lib/gcc/arm-elf/4.4.1/include/stddef.h" 3 4
/* Wide character type.
   Locale-writers should change this as necessary to
   be big enough to hold unique values not between 0 and 127,
   and not (wchar_t) -1, for each defined multibyte character.  */

/* Define this type if we are doing the whole job,
   or if we want this type in particular.  */
# 352 "c:\\ftmscccomp_v4.4.1\\demo_c\\bin\\gnu\\gnu_arm\\bin\\../lib/gcc/arm-elf/4.4.1/include/stddef.h" 3 4
typedef unsigned int wint_t;




/*  In 4.3bsd-net2, leave these undefined to indicate that size_t, etc.
    are already defined.  */
/*  BSD/OS 3.1 and FreeBSD [23].x require the MACHINE_ANSI_H check here.  */
# 392 "c:\\ftmscccomp_v4.4.1\\demo_c\\bin\\gnu\\gnu_arm\\bin\\../lib/gcc/arm-elf/4.4.1/include/stddef.h" 3 4
/* A null pointer constant.  */
# 64 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/sys/_types.h" 2 3


/* Conversion state information.  */
typedef struct
{
  int __count;
  union
  {
    wint_t __wch;
    unsigned char __wchb[4];
  } __value; /* Value so far.  */
} _mbstate_t;



typedef _LOCK_RECURSIVE_T _flock_t;



/* Iconv descriptor type */
typedef void *_iconv_t;
# 15 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/sys/reent.h" 2 3






typedef unsigned long __ULong;
# 37 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/sys/reent.h" 3
struct _reent;

/*
 * If _REENT_SMALL is defined, we make struct _reent as small as possible,
 * by having nearly everything possible allocated at first use.
 */

struct _Bigint
{
  struct _Bigint *_next;
  int _k, _maxwds, _sign, _wds;
  __ULong _x[1];
};

/* needed by reentrant structure */
struct __tm
{
  int __tm_sec;
  int __tm_min;
  int __tm_hour;
  int __tm_mday;
  int __tm_mon;
  int __tm_year;
  int __tm_wday;
  int __tm_yday;
  int __tm_isdst;
};

/*
 * atexit() support.
 */



struct _on_exit_args {
 void * _fnargs[32]; /* user fn args */
 void * _dso_handle[32];
 /* Bitmask is set if user function takes arguments.  */
 __ULong _fntypes; /* type of exit routine -
				   Must have at least _ATEXIT_SIZE bits */
 /* Bitmask is set if function was registered via __cxa_atexit.  */
 __ULong _is_cxa;
};
# 89 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/sys/reent.h" 3
struct _atexit {
 struct _atexit *_next; /* next in list */
 int _ind; /* next index in this table */
 /* Some entries may already have been called, and will be NULL.  */
 void (*_fns[32])(void); /* the table itself */
        struct _on_exit_args _on_exit_args;
};


/*
 * Stdio buffers.
 *
 * This and __FILE are defined here because we need them for struct _reent,
 * but we don't want stdio.h included when stdlib.h is.
 */

struct __sbuf {
 unsigned char *_base;
 int _size;
};

/*
 * Stdio state variables.
 *
 * The following always hold:
 *
 *	if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR),
 *		_lbfsize is -_bf._size, else _lbfsize is 0
 *	if _flags&__SRD, _w is 0
 *	if _flags&__SWR, _r is 0
 *
 * This ensures that the getc and putc macros (or inline functions) never
 * try to write or read from a file that is in `read' or `write' mode.
 * (Moreover, they can, and do, automatically switch from read mode to
 * write mode, and back, on "r+" and "w+" files.)
 *
 * _lbfsize is used only to make the inline line-buffered output stream
 * code as compact as possible.
 *
 * _ub, _up, and _ur are used when ungetc() pushes back more characters
 * than fit in the current _bf, or when ungetc() pushes back a character
 * that does not match the previous one in _bf.  When this happens,
 * _ub._base becomes non-nil (i.e., a stream has ungetc() data iff
 * _ub._base!=NULL) and _up and _ur save the current values of _p and _r.
 */
# 169 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/sys/reent.h" 3
struct __sFILE {
  unsigned char *_p; /* current position in (some) buffer */
  int _r; /* read space left for getc() */
  int _w; /* write space left for putc() */
  short _flags; /* flags, below; this FILE is free if 0 */
  short _file; /* fileno, if Unix descriptor, else -1 */
  struct __sbuf _bf; /* the buffer (at least 1 byte, if !NULL) */
  int _lbfsize; /* 0 or -_bf._size, for inline putc */





  /* operations */
  void * _cookie; /* cookie passed to io functions */

  int (*_read) (struct _reent *, void *, char *, int);

  int (*_write) (struct _reent *, void *, const char *, int);

  _fpos_t (*_seek) (struct _reent *, void *, _fpos_t, int);
  int (*_close) (struct _reent *, void *);

  /* separate buffer for long sequences of ungetc() */
  struct __sbuf _ub; /* ungetc buffer */
  unsigned char *_up; /* saved _p when _p is doing ungetc data */
  int _ur; /* saved _r when _r is counting ungetc data */

  /* tricks to meet minimum requirements even when malloc() fails */
  unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */
  unsigned char _nbuf[1]; /* guarantee a getc() buffer */

  /* separate buffer for fgetline() when line crosses buffer boundary */
  struct __sbuf _lb; /* buffer for fgetline() */

  /* Unix stdio files get aligned to block boundaries on fseek() */
  int _blksize; /* stat.st_blksize (may be != _bf._size) */
  int _offset; /* current lseek offset */


  struct _reent *_data; /* Here for binary compatibility? Remove? */



  _flock_t _lock; /* for thread-safety locking */

  _mbstate_t _mbstate; /* for wide char stdio functions. */
  int _flags2; /* for future use */
};
# 273 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/sys/reent.h" 3
typedef struct __sFILE __FILE;



struct _glue
{
  struct _glue *_next;
  int _niobs;
  __FILE *_iobs;
};

/*
 * rand48 family support
 *
 * Copyright (c) 1993 Martin Birgmeier
 * All rights reserved.
 *
 * You may redistribute unmodified or modified versions of this source
 * code provided that the above copyright notice and this and the
 * following conditions are retained.
 *
 * This software is provided ``as is'', and comes with no warranties
 * of any kind. I shall in no event be liable for anything that happens
 * to anyone/anything when using this software.
 */







struct _rand48 {
  unsigned short _seed[3];
  unsigned short _mult[3];
  unsigned short _add;




};

/* How big the some arrays are.  */




/*
 * struct _reent
 *
 * This structure contains *all* globals needed by the library.
 * It's raison d'etre is to facilitate threads by making all library routines
 * reentrant.  IE: All state information is contained here.
 */
# 579 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/sys/reent.h" 3
struct _reent
{
  int _errno; /* local copy of errno */

  /* FILE is a big struct and may change over time.  To try to achieve binary
     compatibility with future versions, put stdin,stdout,stderr here.
     These are pointers into member __sf defined below.  */
  __FILE *_stdin, *_stdout, *_stderr;

  int _inc; /* used by tmpnam */
  char _emergency[25];

  int _current_category; /* used by setlocale */
  const char *_current_locale;

  int __sdidinit; /* 1 means stdio has been init'd */

  void (*__cleanup) (struct _reent *);

  /* used by mprec routines */
  struct _Bigint *_result;
  int _result_k;
  struct _Bigint *_p5s;
  struct _Bigint **_freelist;

  /* used by some fp conversion routines */
  int _cvtlen; /* should be size_t */
  char *_cvtbuf;

  union
    {
      struct
        {
          unsigned int _unused_rand;
          char * _strtok_last;
          char _asctime_buf[26];
          struct __tm _localtime_buf;
          int _gamma_signgam;
          __extension__ unsigned long long _rand_next;
          struct _rand48 _r48;
          _mbstate_t _mblen_state;
          _mbstate_t _mbtowc_state;
          _mbstate_t _wctomb_state;
          char _l64a_buf[8];
          char _signal_buf[24];
          int _getdate_err;
          _mbstate_t _mbrlen_state;
          _mbstate_t _mbrtowc_state;
          _mbstate_t _mbsrtowcs_state;
          _mbstate_t _wcrtomb_state;
          _mbstate_t _wcsrtombs_state;
   int _h_errno;
        } _reent;
  /* Two next two fields were once used by malloc.  They are no longer
     used. They are used to preserve the space used before so as to
     allow addition of new reent fields and keep binary compatibility.   */
      struct
        {

          unsigned char * _nextf[30];
          unsigned int _nmalloc[30];
        } _unused;
    } _new;

  /* atexit stuff */
  struct _atexit *_atexit; /* points to head of LIFO stack */
  struct _atexit _atexit0; /* one guaranteed table, required by ANSI */

  /* signal info */
  void (**(_sig_func))(int);

  /* These are here last so that __FILE can grow without changing the offsets
     of the above members (on the off chance that future binary compatibility
     would be broken otherwise).  */
  struct _glue __sglue; /* root of glue chain */
  __FILE __sf[3]; /* first three file descriptors */
};
# 803 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/sys/reent.h" 3
/*
 * All references to struct _reent are via this pointer.
 * Internally, newlib routines that need to reference it should use _REENT.
 */





extern struct _reent *_impure_ptr ;
extern struct _reent *const _global_impure_ptr ;

void _reclaim_reent (struct _reent *);

/* #define _REENT_ONLY define this to get only reentrant routines */
# 6 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/math.h" 2 3

# 1 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/_ansi.h" 1 3
/* Provide support for both ANSI and non-ANSI environments.  */

/* Some ANSI environments are "broken" in the sense that __STDC__ cannot be
   relied upon to have it's intended meaning.  Therefore we must use our own
   concoction: _HAVE_STDC.  Always use _HAVE_STDC instead of __STDC__ in newlib
   sources!

   To get a strict ANSI C environment, define macro __STRICT_ANSI__.  This will
   "comment out" the non-ANSI parts of the ANSI header files (non-ANSI header
   files aren't affected).  */
# 8 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/math.h" 2 3



union __dmath
{
  __ULong i[2];
  double d;
};

union __fmath
{
  __ULong i[1];
  float f;
};

union __ldmath
{
  __ULong i[4];
  long double ld;
};

/* Natural log of 2 */






 /* gcc >= 3.3 implicitly defines builtins for HUGE_VALx values.  */
# 82 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/math.h" 3
/* Reentrant ANSI C functions.  */


extern double atan (double);
extern double cos (double);
extern double sin (double);
extern double tan (double);
extern double tanh (double);
extern double frexp (double, int *);
extern double modf (double, double *);
extern double ceil (double);
extern double fabs (double);
extern double floor (double);


/* Non reentrant ANSI C functions.  */



extern double acos (double);
extern double asin (double);
extern double atan2 (double, double);
extern double cosh (double);
extern double sinh (double);
extern double exp (double);
extern double ldexp (double, int);
extern double log (double);
extern double log10 (double);
extern double pow (double, double);
extern double sqrt (double);
extern double fmod (double, double);





/* ISO C99 types and macros. */



typedef float float_t;
typedef double double_t;
# 149 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/math.h" 3
extern int __isinff (float x);
extern int __isinfd (double x);
extern int __isnanf (float x);
extern int __isnand (double x);
extern int __fpclassifyf (float x);
extern int __fpclassifyd (double x);
extern int __signbitf (float x);
extern int __signbitd (double x);
# 168 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/math.h" 3
/* Note: isinf and isnan were once functions in newlib that took double
 *       arguments.  C99 specifies that these names are reserved for macros
 *       supporting multiple floating point types.  Thus, they are
 *       now defined as macros.  Implementations of the old functions
 *       taking double arguments still exist for compatibility purposes.  */
# 210 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/math.h" 3
/* Non ANSI double precision functions.  */

extern double infinity (void);
extern double nan (const char *);
extern int finite (double);
extern double copysign (double, double);
extern int ilogb (double);

extern double asinh (double);
extern double cbrt (double);
extern double nextafter (double, double);
extern double rint (double);
extern double scalbn (double, int);

extern double exp2 (double);
extern double scalbln (double, long int);
extern double tgamma (double);
extern double nearbyint (double);
extern long int lrint (double);
extern long long int llrint (double);
extern double round (double);
extern long int lround (double);
extern double trunc (double);
extern double remquo (double, double, int *);
extern double copysign (double, double);
extern double fdim (double, double);
extern double fmax (double, double);
extern double fmin (double, double);
extern double fma (double, double, double);


extern double log1p (double);
extern double expm1 (double);



extern double acosh (double);
extern double atanh (double);
extern double remainder (double, double);
extern double gamma (double);
extern double lgamma (double);
extern double erf (double);
extern double erfc (double);



extern double hypot (double, double);




/* Single precision versions of ANSI functions.  */

extern float atanf (float);
extern float cosf (float);
extern float sinf (float);
extern float tanf (float);
extern float tanhf (float);
extern float frexpf (float, int *);
extern float modff (float, float *);
extern float ceilf (float);
extern float fabsf (float);
extern float floorf (float);


extern float acosf (float);
extern float asinf (float);
extern float atan2f (float, float);
extern float coshf (float);
extern float sinhf (float);
extern float expf (float);
extern float ldexpf (float, int);
extern float logf (float);
extern float log10f (float);
extern float powf (float, float);
extern float sqrtf (float);
extern float fmodf (float, float);


/* Other single precision functions.  */

extern float exp2f (float);
extern float scalblnf (float, long int);
extern float tgammaf (float);
extern float nearbyintf (float);
extern long int lrintf (float);
extern long long llrintf (float);
extern float roundf (float);
extern long int lroundf (float);
extern float truncf (float);
extern float remquof (float, float, int *);
extern float copysignf (float, float);
extern float fdimf (float, float);
extern float fmaxf (float, float);
extern float fminf (float, float);
extern float fmaf (float, float, float);

extern float infinityf (void);
extern float nanf (const char *);
extern int isnanf (float);
extern int isinff (float);
extern int finitef (float);
extern float copysignf (float, float);
extern int ilogbf (float);

extern float asinhf (float);
extern float cbrtf (float);
extern float nextafterf (float, float);
extern float rintf (float);
extern float scalbnf (float, int);
extern float log1pf (float);
extern float expm1f (float);


extern float acoshf (float);
extern float atanhf (float);
extern float remainderf (float, float);
extern float gammaf (float);
extern float lgammaf (float);
extern float erff (float);
extern float erfcf (float);

extern float hypotf (float, float);


/* Other long double precision functions.  */
extern long double rintl (long double);
extern long int lrintl (long double);
extern long long llrintl (long double);





extern double cabs();
extern double drem (double, double);
extern void sincos (double, double *, double *);
extern double gamma_r (double, int *);
extern double lgamma_r (double, int *);

extern double y0 (double);
extern double y1 (double);
extern double yn (int, double);
extern double j0 (double);
extern double j1 (double);
extern double jn (int, double);

extern float cabsf();
extern float dremf (float, float);
extern void sincosf (float, float *, float *);
extern float gammaf_r (float, int *);
extern float lgammaf_r (float, int *);

extern float y0f (float);
extern float y1f (float);
extern float ynf (int, float);
extern float j0f (float);
extern float j1f (float);
extern float jnf (int, float);

/* GNU extensions */

extern double exp10 (double);


extern double pow10 (double);


extern float exp10f (float);


extern float pow10f (float);






/* The gamma functions use a global variable, signgam.  */


extern int *__signgam (void);




/* The exception structure passed to the matherr routine.  */
/* We have a problem when using C++ since `exception' is a reserved
   name in C++.  */



struct exception

{
  int type;
  char *name;
  double arg1;
  double arg2;
  double retval;
  int err;
};




extern int matherr (struct exception *e);


/* Values for the type field of struct exception.  */
# 428 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/math.h" 3
/* Useful constants.  */
# 455 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/math.h" 3
/* Global control over fdlibm error handling.  */

enum __fdlibm_version
{
  __fdlibm_ieee = -1,
  __fdlibm_svid,
  __fdlibm_xopen,
  __fdlibm_posix
};




extern enum __fdlibm_version __fdlib_version;
# 477 "c:/ftmscccomp_v4.4.1/demo_c/bin/gnu/gnu_arm/lib/gcc/../../arm-elf/include/math.h" 3

# 28 "../../Common/ROBO_TX_PRG.h" 2







                                        // Transfer Area used in program is the same as the one used in firmware.
# 57 "../../Common/ROBO_TX_PRG.h"
typedef enum
{
    false = (!(1 == 1)),
    true = (1 == 1)
} bool;


typedef signed char CHAR8;
typedef unsigned char UCHAR8;

typedef unsigned char BOOL8; //  boolean variable (should be TRUE or FALSE)
typedef unsigned short BOOL16; //  boolean variable (should be TRUE or FALSE)
typedef unsigned long BOOL32; //  boolean variable (should be TRUE or FALSE)

typedef signed char INT8;
typedef signed short INT16;
typedef signed int INT32;

typedef unsigned char UINT8;
typedef unsigned short UINT16;
typedef unsigned long UINT32;


# 1 "../../Common/ROBO_TX_FW.h" 1
//=============================================================================
// Header file with definition of the software interface to the
// ROBO TX Controller firmware.
// Can be used for building C-programs which can run under control
// of the ROBO TX Controller firmware in download (local) mode or
// for building PC-programs which can communicate with the
// ROBO TX Controller firmware in online mode.
//
// Disclaimer - Exclusion of Liability
//
// This software 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. It can be used and modified by anyone
// free of any license obligations or authoring rights.
//=============================================================================
# 26 "../../Common/ROBO_TX_FW.h"
// 5kOhm range




// 10V range




// Ultrasonic Sensor range





// Motor outputs PWM values range



// Length of strings




// Number of Bluetooth channels


// Allowed values for channel index are 1...8







// Bluetooth connection states
enum BtConnState
{
    BT_STATE_IDLE = 0, // BT channel is disconnected
    BT_STATE_CONN_ONGOING, // BT channel is being connected
    BT_STATE_CONNECTED, // BT channel is connected
    BT_STATE_DISC_ONGOING // BT channel is being disconnected
};


// Status of Bluetooth inquiry scan
enum BtInquiryScanStatus
{
    BT_INQUIRY_SCAN_NOT_POSSIBLE = 0,
    BT_INQUIRY_SCAN_START,
    BT_INQUIRY_SCAN_RESULT,
    BT_INQUIRY_SCAN_BUSY,
    BT_INQUIRY_SCAN_TIMEOUT,
    BT_INQUIRY_SCAN_END
};


// Status codes for status field in Bluetooth callback functions
enum CB_BtStatus
{
  /*  0 */ BT_SUCCESS = 0, // Successful end of command
  /*  1 */ BT_CON_EXIST, // Already connected
  /*  2 */ BT_CON_SETUP, // Establishing of connection is ongoing
  /*  3 */ BT_SWITCHED_OFF, // Cannot connect/listen, Bluetooth is set to off
  /*  4 */ BT_ALL_CHAN_BUSY, // Cannot connect, no more free Bluetooth channels
  /*  5 */ BT_NOT_ROBOTX, // Cannot connect/listen, device is not a ROBO TX Controller
  /*  6 */ BT_CON_TIMEOUT, // Cannot connect, timeout, no device with such a BT address
  /*  7 */ BT_CON_INVALID, // Connection does not exist
  /*  8 */ BT_CON_RELEASE, // Disconnecting is ongoing
  /*  9 */ BT_LISTEN_ACTIVE, // Listen is already active
  /* 10 */ BT_RECEIVE_ACTIVE, // Receive is already active
  /* 11 */ BT_CON_INDICATION, // Passive connection establishment (incoming connection)
  /* 12 */ BT_DISCON_INDICATION, // Passive disconnection (initiated by remote end)
  /* 13 */ BT_MSG_INDICATION, // Received data (incoming message)
  /* 14 */ BT_CHANNEL_BUSY, // No connect command is allowed when listen is active or
                                    // no listen command is allowed when connected
  /* 15 */ BT_BTADDR_BUSY, // BT address is already used by another channel
  /* 16 */ BT_NO_LISTEN_ACTIVE // Cannot connect, no active listen on remote end
};


// Identifiers of the Transfer Area
enum ta_id_e
{
    TA_LOCAL = 0, // Transfer Area for local Controller. Corresponds to the Controller
                            // on which program is currently running in download (local) mode or
                            // to the remotely controlled Controller (seen from controlled device,
                            // not from controlling device) in online mode.
    TA_EXT_1, // Transfer Area for Extension 1 Controller
    TA_EXT_2, // Transfer Area for Extension 2 Controller
    TA_EXT_3, // Transfer Area for Extension 3 Controller
    TA_EXT_4, // Transfer Area for Extension 4 Controller
    TA_EXT_5, // Transfer Area for Extension 5 Controller
    TA_EXT_6, // Transfer Area for Extension 6 Controller
    TA_EXT_7, // Transfer Area for Extension 7 Controller
    TA_EXT_8, // Transfer Area for Extension 8 Controller
    TA_COUNT // Number of Transfer Areas in array = 9
};




// Device (Controller) functioning modes
enum dev_mode_e
{
    DEV_MODE_LOCAL = 0,
    DEV_MODE_ONLINE,
    DEV_MODE_INVALID
};


// State of connection to an extension device (Controller)
enum ext_dev_connect_state_e
{
    EXT_DEV_OFFLINE = 0,
    EXT_DEV_ONLINE,
    EXT_DEV_INVALID
};


// Modes of universal inputs
enum input_mode_e
{
    MODE_U = 0,
    MODE_R = 1,
    MODE_ULTRASONIC = 3,
    MODE_INVALID
};


// Program states
enum pgm_state_e
{
    PGM_STATE_INVALID = 0,
    PGM_STATE_RUN,
    PGM_STATE_STOP
};


// Timer units for GetSystemTime hook function
enum TimerUnit
{
    TIMER_UNIT_INVALID = 0,
    TIMER_UNIT_SECONDS = 2,
    TIMER_UNIT_MILLISECONDS = 3,
    TIMER_UNIT_MICROSECONDS = 4
};


// Bluetooth inquiry scan status
typedef struct bt_scan_status_s
{
    UINT16 status; // Status code, see enum BtInquiryScanStatus

    // Bluetooth device info, valid only when status == BT_INQUIRY_SCAN_RESULT
    UCHAR8 bt_addr[6];
    char dummy_1[2];
    char bt_name[16 + 1];
    char dummy_2[3];
} BT_SCAN_STATUS;


// Structure for Bluetooth callback functions (other than receive)
typedef struct bt_cb_s
{
    UINT16 chan_idx; // Channel index
    UINT16 status; // Status code, see enum CB_BtStatus
} BT_CB;


// Structure for Bluetooth receive callback function
typedef struct bt_receive_cb_s
{
    UINT16 chan_idx; // Channel index
    UINT16 status; // Status code, see enum CB_BtStatus
    UINT16 msg_len; // Bluetooth message length
    UCHAR8 msg[16];// Bluetooth message
} BT_RECV_CB;


// Status codes for status field in I2C callback functions
enum CB_I2cStatus
{
  /*  0 */ I2C_SUCCESS = 0, // Successful end of command
  /*  1 */ I2C_READ_ERROR, // read error
  /*  2 */ I2C_WRITE_ERROR // write error
};

// Structure for I2C callback functions
typedef struct i2c_cb_s
{
    UINT16 value; // read/write value
    UINT16 status; // status code, see enum CB_I2Status
} I2C_CB;

struct ta_s;

// Pointer to the Bluetooth callback function (other than receive)
typedef void (*P_CB_FUNC)(struct ta_s *, BT_CB *);

// Pointer to the Bluetooth receive callback function
typedef void (*P_RECV_CB_FUNC)(struct ta_s *, BT_RECV_CB *);

// Pointer to the I2C callback function
typedef void (*P_I2C_CB_FUNC)(struct ta_s *, I2C_CB *);

//=============================================================================
//  Structures for Transfer Area (TA)
//=============================================================================


// Bluetooth connection status structure, 8 bytes
typedef struct btstatus_s
{
    UINT16 conn_state; // See enum BtConnState
    BOOL16 is_listen; // If TRUE - BT channel is waiting for incoming connection (listening)
    BOOL16 is_receive; // If TRUE - BT channel is ready to receive incoming messages
    UINT16 link_quality; // 0...31, 0 - the worst, 31 - the best signal quality
} BT_STATUS;


// Program information, 8 bytes
typedef struct
{
    char * name; // Name of a program with a full path, for example, "/ramdisk/Program_1"
    UINT8 state; // See enum pgm_state_e
    char reserved[3];
} PGM_INFO;


// Display message, 128 bytes. Used to show pop-up message box on the boards display
typedef struct
{
    UINT8 id; // Should be increased by 1 each time a new pop-up message is to be shown
    char text[98 + 1];
} DISPLAY_MSG;


// Display frame, 8 bytes. Used to refresh boards display with a bitmap image frame
typedef struct
{
    UCHAR8 * frame; // Contents of a frame as a 128x64 pixels bitmap
    UINT16 id; // Should be increased by 1 each time a new display frame is to be shown
    BOOL16 is_pgm_master_of_display; // ++ if program wants to have control over display,
                                                // i.e. image frame is displayed over firmware menus;
                                                // -- if program wants to return control over display
                                                // to the firmware menus
} DISPLAY_FRAME;


// Version structure definition, 4 bytes
typedef union
{
    UINT32 abcd;
    struct
    {
        UCHAR8 a;
        UCHAR8 b;
        UCHAR8 c;
        UCHAR8 d;
    } part;
} FT_VER;


// Versions of hardware and firmware components, 16 bytes
typedef struct
{
    FT_VER hardware; // Version of hardware (hardware.part.a = 'A' or 'B' or 'C')
    FT_VER firmware; // Version of firmware ("V %d.%02d, DLL %d", firmware.part.c,
                                // firmware.part.d, firmware.part.b)
    FT_VER ta; // Version of transfer area ("V %d.%02d", ta.part.c, ta.part.d)
    char reserved[4];
} FT_VERSION;


// Info structure, 64 bytes
typedef struct
{
    char device_name[16 + 1]; // Controller name
    char bt_addr[17 + 1]; // Bluetooth address as a string
    char reserved;
    UINT32 ta_array_start_addr;
    UINT32 pgm_area_start_addr;
    UINT32 pgm_area_size;
    FT_VERSION version;
} TA_INFO;


// State structure, 100 bytes
typedef struct
{
    // Used by local program
    BOOL8 pgm_initialized;
    char reserved_1[7];

    // Public state info
    BOOL8 dev_mode; // See enum dev_mode_e
    UINT8 id; // Should be increased by 1 each time something (except id fields and btstatus)
                                // is changed in this state structure
    UINT8 info_id; // Should be increased by 1 each time something is changed in info structure
    UINT8 config_id; // Should be increased by 1 each time something is changed in config structure
    BOOL8 ext_dev_connect_state[(TA_COUNT - 1)]; // See enum ext_dev_connect_state_e
    BT_STATUS btstatus[8]; // Status of Bluetooth connections
    char reserved_2[8];
    PGM_INFO local_pgm; // Corresponds to the program currently being in the program memory
} TA_STATE;


// Universal inputs configuration, 4 bytes
typedef struct
{
    UINT8 mode; // See enum input_mode_e
    BOOL8 digital; // FALSE = analog input, TRUE = digital input
    char reserved[2];
} UNI_CONFIG;


// Counter inputs configuration, 4 bytes
typedef struct
{
    UINT8 mode; // 0 = normal counter mode (change 0 -> 1 is counted)
                                // 1 = inverse counter mode (change 1 -> 0 is counted)
    char reserved[3];
} CNT_CONFIG;


// Config structure, 88 bytes
typedef struct
{
    UINT8 pgm_state_req; // See enum pgm_state_e, program state change request
    char reserved_1[3];
    BOOL8 motor[4]; // TRUE = corresponding outputs are used as a pair of motor outputs M1...M4,
                                    // FALSE = corresponding outputs are used as a pair of separate digital
                                    // PWM outputs O1...O8
    UNI_CONFIG uni[8];
    CNT_CONFIG cnt[4];
    char reserved_2[32];
} TA_CONFIG;


// Input structure, 68 bytes
typedef struct
{
    INT16 uni[8]; // Current values of the universal inputs
    INT16 cnt_in[4]; // Current levels (0 or 1) on the counter inputs according
                                            // to their configuration (normal or inverse)
    INT16 counter[4]; // Current values of the counter inputs
    INT16 display_button_left; // Number of milliseconds during which the left display button
                                            // is being kept pressed
    INT16 display_button_right; // Number of milliseconds during which the right display button
                                            // is being kept pressed
    BOOL16 cnt_resetted[4]; // Set to 1 when last requested counter reset was fulfilled
    BOOL16 motor_pos_reached[4]; // Set to 1 by motor control if target position
                                                // (distance from output structure) is reached
    char reserved[16];
} TA_INPUT;


// Output structure, 44 bytes
typedef struct
{
    UINT16 cnt_reset_cmd_id[4]; // Counter reset requests (should be increased by 1 each time
                                              // counter reset is needed)
    UINT8 master[4]; // If not 0, synchronize this channel with the given channel
                                              // (1:channel 0, ...)
    INT16 duty[8]; // Selected motor outputs PWM values
    UINT16 distance[4]; // Selected distance (counter value) at which motor shall stop
    UINT16 motor_ex_cmd_id[4]; // Should be increased by 1 each time settings for extended
                                              // motor control mode (duty and/or distance) are changed
} TA_OUTPUT;


// Display structure, 108 bytes
typedef struct
{
    DISPLAY_MSG display_msg;
    DISPLAY_FRAME display_frame;
} TA_DISPLAY;


// Status of Transfer Area (valid only for ftMscLib), 4 bytes
typedef struct
{
    UINT8 status; // Status of transfer area
                                    //     TA_STATUS_STOP = 0 - Transfer Area is not running,
                                    //     TA_STATUS_RUN  = 1 - Transfer Area is running,
                                    //     TA_STATUS_SYNC = 2 - Transfer Area is being synchronized
    UINT8 iostatus; // Status of I/O communication
                                    //     SE_REMIO_REQ   = 0 - Remote I/O Request was sent,
                                    //     SE_CONFIG_REQ  = 1 - Set Configuration Request was sent
    UINT16 ComErr; // System error code by COM port connection error
} TA_STATUS;


// Change structure (valid only for ftMscLib), 8 bytes
typedef struct
{
    char reserved_1[2];
    UINT8 ChangeStatus; // TRUE = there was a change in any of the following fields
    UINT8 ChangeUni; // There was a change of the input value (bit 0 = I1, bit 1 = I2, ...)
    UINT8 ChangeCntIn; // There was a change of the counter level (bit 0 = C1, bit 1 = C2, ...)
    UINT8 ChangeCounter; // There was a change of the counter value (bit 0 = C1, bit 1 = C2, ...)
    char reserved_2[2];
} TA_CHANGE;


// 16-bit timers, 12 bytes
typedef struct
{
    UINT16 Timer1ms;
    UINT16 Timer10ms;
    UINT16 Timer100ms;
    UINT16 Timer1s;
    UINT16 Timer10s;
    UINT16 Timer1min;
} TA_TIMER;


// Hook table with pointers to the firmware functions,
// that can be called by local program, 132 bytes
typedef struct
{
    // Informs the calling program if it can still run (return TRUE) or should
    // immediately return to the firmware in order not to destroy the multitasking
    // mechanism of the firmware (return FALSE).
    BOOL32 (*IsRunAllowed) (void);

    // Returns system time in seconds, milliseconds or microseconds depending on the
    // parameter unit.
    UINT32 (*GetSystemTime) (enum TimerUnit unit);

    // Display pop-up message on the display of the ROBO TX Controller. If p_msg
    // is NULL, then all pop-up messages are removed from the display and its cache,
    // and the main frame is displayed.
    void (*DisplayMsg) (struct ta_s * p_ta, char * p_msg);

    // Returns TRUE if display is currently being refreshed. A program should in such a
    // case wait until the display finishes its refreshing before sending new output to it.
    BOOL32 (*IsDisplayBeingRefreshed) (struct ta_s * p_ta);

    // Connect to the Bluetooth device with the given Bluetooth address through the given
    // channel (1...8). If p_cb_func (pointer to the callback function) is not NULL, then the
    // callback function is called to inform about the result of this command.
    void (*BtConnect) (UINT32 channel, UCHAR8 * btaddr, P_CB_FUNC p_cb_func);

    // Disconnect from the Bluetooth device on the given channel (1...8). If p_cb_func
    // (pointer to the callback function) is not NULL, then the callback function is called
    // to inform about the result of this command.
    void (*BtDisconnect) (UINT32 channel, P_CB_FUNC p_cb_func);

    // Send a message (max 255 characters) through the given Bluetooth channel (1...8).
    // If p_cb_func (pointer to the callback function) is not NULL, then the callback function is called
    // to inform about the result of this command.
    void (*BtSend) (UINT32 channel, UINT32 len, UCHAR8 * p_msg, P_CB_FUNC p_cb_func);

    // Start wait for incoming messages on the given Bluetooth channel (1...8). If p_cb_func
    // (pointer to the callback function) is not NULL, then the callback function is called
    // to inform about the result of this command and about arrival of a Bluetooth message.
    void (*BtStartReceive) (UINT32 channel, P_RECV_CB_FUNC p_cb_func);

    // Stop wait for incoming messages on the given Bluetooth channel (1...8). If p_cb_func
    // (pointer to the callback function) is not NULL, then the callback function is called
    // to inform about the result of this command.
    void (*BtStopReceive) (UINT32 channel, P_RECV_CB_FUNC p_cb_func);

    // Start wait for incoming connection (i.e. listen) from the Bluetooth device with the given
    // Bluetooth address on the given channel (1...8). If p_cb_func (pointer to the callback function)
    // is not NULL, then the callback function is called to inform about the result of this command.
    void (*BtStartListen) (UINT32 channel, UCHAR8 * btaddr, P_CB_FUNC p_cb_func);

    // Stop wait for incoming connection (i.e. listen) on the given Bluetooth channel (1...8).
    // If p_cb_func (pointer to the callback function) is not NULL, then the callback function is called
    // to inform about the result of this command.
    void (*BtStopListen) (UINT32 channel, P_CB_FUNC p_cb_func);

    // Convert a Bluetooth address (6 bytes) to the string with the format "xx:xx:xx:xx:xx:xx".
    // Returns pointer to the string with converted btaddr (same pointer as str parameter).
    char *(*BtAddrToStr) (UCHAR8 * btaddr, char * str);

    // Interface to I2C API functions
    UINT32 (*I2cRead) (UCHAR8 devaddr, UINT32 offset, UCHAR8 protocol, P_I2C_CB_FUNC p_cb_func);
    UINT32 (*I2cWrite) (UCHAR8 devaddr, UINT32 offset, UINT16 data, UCHAR8 protocol, P_I2C_CB_FUNC p_cb_func);

    // Interface to some runtime library functions.
    INT32 (*sprintf) (char * s, const char * format, ...);
    INT32 (*memcmp) (const void * s1, const void * s2, UINT32 n);
    void *(*memcpy) (void * s1, const void * s2, UINT32 n);
    void *(*memmove) (void * s1, const void * s2, UINT32 n);
    void *(*memset) (void * s, INT32 c, UINT32 n);
    char *(*strcat) (char * s1, const char * s2);
    char *(*strncat) (char * s1, const char * s2, UINT32 n);
    char *(*strchr) (const char * s, INT32 c);
    char *(*strrchr) (const char * s, INT32 c);
    INT32 (*strcmp) (const char * s1, const char * s2);
    INT32 (*strncmp) (const char * s1, const char * s2, UINT32 n);
    INT32 (*stricmp) (const char * s1, const char * s2);
    INT32 (*strnicmp) (const char * s1, const char * s2, UINT32 n);
    char *(*strcpy) (char * s1, const char * s2);
    char *(*strncpy) (char * s1, const char * s2, UINT32 n);
    UINT32 (*strlen) (const char * s);
    char *(*strstr) (const char * s1, const char * s2);
    char *(*strtok) (char * s1, const char * s2);
    char *(*strupr) (char * s);
    char *(*strlwr) (char * s);
    INT32 (*atoi) (const char * nptr);
} TA_HOOK_TABLE;



// ============================================================================
//  Transfer Area (TA) of ROBO TX Controller (one element of TA array)
// ============================================================================
# 556 "../../Common/ROBO_TX_FW.h"
typedef struct ta_s
{
    TA_INFO info; // info structure
    TA_STATE state; // state structure
    TA_CONFIG config; // config structure   
    TA_INPUT input; // input structure
    TA_OUTPUT output; // output structure
    TA_DISPLAY display; // display structure
    TA_STATUS status; // status structure
    TA_CHANGE change; // change structure
    TA_TIMER timer; // 16-bit timers

    char reserved_1[28];

    TA_HOOK_TABLE hook_table; // hook table with functions pointers

    char reserved_2[(1024 - ( sizeof(TA_INFO) + sizeof(TA_STATE) + sizeof(TA_CONFIG) + sizeof(TA_INPUT) + sizeof(TA_OUTPUT) + sizeof(TA_DISPLAY) + sizeof(TA_STATUS) + sizeof(TA_CHANGE) + sizeof(TA_TIMER) + 28 + sizeof(TA_HOOK_TABLE) ))];
} TA;
# 81 "../../Common/ROBO_TX_PRG.h" 2

TA * p_ta;

BOOL8 istate[8] = {(!(1 == 1)),(!(1 == 1)),(!(1 == 1)),(!(1 == 1)),(!(1 == 1)),(!(1 == 1)),(!(1 == 1)),(!(1 == 1))};
BOOL8 mstate[4] = {(!(1 == 1)),(!(1 == 1)),(!(1 == 1)),(!(1 == 1))};

enum bt_commands_e
{
    CMD_NO_CMD,
    CMD_CONNECT,
    CMD_DISCONNECT,
    CMD_START_LISTEN,
    CMD_STOP_LISTEN,
    CMD_START_RECEIVE,
    CMD_STOP_RECEIVE,
    CMD_SEND
};

extern UCHAR8 bt_address_table[8][6];

 // At the beginning of the program code should be this structure
struct prg_code_intro_s
{
    unsigned long magic; // PRG_MAGIC
    FT_VER ta_version; // TA_VERSION
    unsigned long entry; // entry point of the program, usually address of
                                        // the program dispatcher (PrgDisp) function
};

static void I2cCallback
(
    TA * p_ta_array,
    I2C_CB * p_data
);

static void i2cread(UCHAR8 devaddr, UINT32 offset, UCHAR8 flags)
{p_ta->hook_table.I2cRead (devaddr, offset, flags , I2cCallback);}


static void i2cwrite(UCHAR8 devaddr, UINT32 offset, UINT32 data, UCHAR8 flags)
{p_ta->hook_table.I2cWrite (devaddr, offset, data, flags , I2cCallback);}

static void txsinglelamp ( unsigned short n, UINT16 duty)
{ p_ta->output.duty[6] = 0; p_ta->output.duty[7] = 0; p_ta->output.duty[5] = 0;
   p_ta->output.duty[n] = duty ;
}
static void txlamp ( unsigned short n, UINT16 duty)
{ p_ta->output.duty[n] = duty ;
}

static void txclearcounter ( unsigned short MOTOR_IDX)
 { p_ta->input.cnt_resetted[MOTOR_IDX] = (!(1 == 1));
    p_ta->output.cnt_reset_cmd_id[MOTOR_IDX]++;
 }
static INT16 txgetcounter ( unsigned short MOTOR_IDX)
 { return p_ta->input.counter[MOTOR_IDX];
 }
static void txstartmotorsync ( unsigned short MASTER_MOTOR_IDX, unsigned short SLAVE_MOTOR_IDX,
unsigned short mdir, unsigned short sdir, UINT16 duty, UINT16 icount)
{
if (!mstate[MASTER_MOTOR_IDX]) {
   p_ta->config.motor[MASTER_MOTOR_IDX] = (1 == 1);
   mstate[MASTER_MOTOR_IDX] = (1 == 1);
   p_ta->state.config_id += 1;
}
if (!mstate[SLAVE_MOTOR_IDX]) {
   p_ta->config.motor[SLAVE_MOTOR_IDX] = (1 == 1);
   mstate[SLAVE_MOTOR_IDX] = (1 == 1);
   p_ta->state.config_id += 1;
}
if (mdir == 1) {
 p_ta->output.duty[2 * MASTER_MOTOR_IDX ] = duty;
                    p_ta->output.duty[2 * MASTER_MOTOR_IDX + 1] = 0; }
    else {if (mdir == 2) {
 p_ta->output.duty[2 * MASTER_MOTOR_IDX ] = 0;
                    p_ta->output.duty[2 * MASTER_MOTOR_IDX + 1] = duty; }
          else {p_ta->output.duty[2 * MASTER_MOTOR_IDX ] = 0;
                    p_ta->output.duty[2 * MASTER_MOTOR_IDX + 1] = 0;} } ;
 if (sdir == 1) {
 p_ta->output.duty[2 * SLAVE_MOTOR_IDX ] = duty;
                    p_ta->output.duty[2 * SLAVE_MOTOR_IDX + 1] = 0; }
    else {if (sdir == 2) {
 p_ta->output.duty[2 * SLAVE_MOTOR_IDX ] = 0;
                    p_ta->output.duty[2 * SLAVE_MOTOR_IDX + 1] = duty; }
          else {p_ta->output.duty[2 * SLAVE_MOTOR_IDX ] = 0;
                    p_ta->output.duty[2 * SLAVE_MOTOR_IDX + 1] = 0;} } ;
        // Master motor should run until counter reaches icount
        p_ta->output.distance[MASTER_MOTOR_IDX] = icount;

        // Slave motor should run until counter reaches icount
        p_ta->output.distance[SLAVE_MOTOR_IDX] = icount;

        // Link slave motor to master motor
        p_ta->output.master[SLAVE_MOTOR_IDX] = MASTER_MOTOR_IDX + 1;

        p_ta->input.motor_pos_reached[MASTER_MOTOR_IDX] = (!(1 == 1));
        p_ta->input.motor_pos_reached[SLAVE_MOTOR_IDX] = (!(1 == 1));

        // Start extended motor control command for master motor
        p_ta->output.motor_ex_cmd_id[MASTER_MOTOR_IDX]++;

        // Start extended motor control command for slave motor
        p_ta->output.motor_ex_cmd_id[SLAVE_MOTOR_IDX]++;
}
static void txstartmotor ( unsigned short MASTER_MOTOR_IDX,
unsigned short mdir, UINT16 duty, UINT16 icount)
{
if (!mstate[MASTER_MOTOR_IDX]) {
   p_ta->config.motor[MASTER_MOTOR_IDX] = (1 == 1);
   mstate[MASTER_MOTOR_IDX] = (1 == 1);
   p_ta->state.config_id += 1;
}
if (mdir == 1) {
 p_ta->output.duty[2 * MASTER_MOTOR_IDX ] = duty;
                    p_ta->output.duty[2 * MASTER_MOTOR_IDX + 1] = 0; }
    else {if (mdir == 2) {
 p_ta->output.duty[2 * MASTER_MOTOR_IDX ] = 0;
                    p_ta->output.duty[2 * MASTER_MOTOR_IDX + 1] = duty; }
          else {p_ta->output.duty[2 * MASTER_MOTOR_IDX ] = 0;
                    p_ta->output.duty[2 * MASTER_MOTOR_IDX + 1] = 0;} } ;
        // Master motor should run until counter reaches icount
        p_ta->output.distance[MASTER_MOTOR_IDX] = icount;

        p_ta->input.motor_pos_reached[MASTER_MOTOR_IDX] = (!(1 == 1));

        // Start extended motor control command for master motor
        p_ta->output.motor_ex_cmd_id[MASTER_MOTOR_IDX]++;
}

static void txmotor ( unsigned short MOTOR_IDX, unsigned short dir, UINT16 duty)
{if (!mstate[MOTOR_IDX]) {
   p_ta->config.motor[MOTOR_IDX] = (1 == 1);
   mstate[MOTOR_IDX] = (1 == 1);
   p_ta->state.config_id += 1;
}
if (dir == 1) {
 p_ta->output.duty[2 * MOTOR_IDX ] = duty;
                    p_ta->output.duty[2 * MOTOR_IDX + 1] = 0; }
    else {if (dir == 2) {
 p_ta->output.duty[2 * MOTOR_IDX ] = 0;
                    p_ta->output.duty[2 * MOTOR_IDX + 1] = duty; }
          else {p_ta->output.duty[2 * MOTOR_IDX ] = 0;
                    p_ta->output.duty[2 * MOTOR_IDX + 1] = 0;} } ;
 }
static INT16 txdistance ( unsigned short SENSOR_IDX)
{ if (!istate[SENSOR_IDX]) {
     // Configure input to "Distance" mode
    p_ta->config.uni[SENSOR_IDX].mode = MODE_ULTRASONIC;
    // Inform firmware that configuration was changed
    p_ta->state.config_id += 1;
    istate[SENSOR_IDX] = (1 == 1);
    }
    return p_ta->input.uni[SENSOR_IDX];
}

static INT16 txtrack ( unsigned short BUTTON_IDX)
{ if (!istate[BUTTON_IDX]) {
     // Configure input to "Digital Voltage" mode
    p_ta->config.uni[BUTTON_IDX].mode = MODE_U;
    p_ta->config.uni[BUTTON_IDX].digital = (1 == 1);
    // Inform firmware that configuration was changed
    p_ta->state.config_id += 1;
    istate[BUTTON_IDX] = (1 == 1);
    }
   return p_ta->input.uni[BUTTON_IDX];
}

static INT16 txaremotorsready ( unsigned short MASTER_MOTOR_IDX, unsigned short SLAVE_MOTOR_IDX)
{
if (istate[MASTER_MOTOR_IDX] && istate[SLAVE_MOTOR_IDX] ) {
    return p_ta->input.motor_pos_reached[MASTER_MOTOR_IDX] && p_ta->input.motor_pos_reached[SLAVE_MOTOR_IDX] ;}
else { return -1 ;}
}
static INT16 txmotorready ( unsigned short MASTER_MOTOR_IDX)
{
if (istate[MASTER_MOTOR_IDX] ) {
    return p_ta->input.motor_pos_reached[MASTER_MOTOR_IDX] ;}
else { return -1 ;}
}
static INT16 txinput ( unsigned short BUTTON_IDX)
{ if (!istate[BUTTON_IDX]) {
     // Configure input to "Digital 5 kOhm" mode
    p_ta->config.uni[BUTTON_IDX].mode = MODE_R;
    p_ta->config.uni[BUTTON_IDX].digital = (1 == 1);
    // Inform firmware that configuration was changed
    p_ta->state.config_id += 1;
    istate[BUTTON_IDX] = (1 == 1);
    }
   return p_ta->input.uni[BUTTON_IDX];
}
static INT16 txanalog ( unsigned short BUTTON_IDX)
{ if (!istate[BUTTON_IDX]) {
     // Configure input to "Analog 5 kOhm" mode
    p_ta->config.uni[BUTTON_IDX].mode = MODE_R;
    p_ta->config.uni[BUTTON_IDX].digital = (!(1 == 1));
    // Inform firmware that configuration was changed
    p_ta->state.config_id += 1;
    istate[BUTTON_IDX] = (1 == 1);
    }
   return p_ta->input.uni[BUTTON_IDX];
}
static INT16 txvoltage ( unsigned short BUTTON_IDX)
{ if (!istate[BUTTON_IDX]) {
     // Configure input to "Analog voltage" mode
    p_ta->config.uni[BUTTON_IDX].mode = MODE_U;
    p_ta->config.uni[BUTTON_IDX].digital = (!(1 == 1));
    // Inform firmware that configuration was changed
    p_ta->state.config_id += 1;
    istate[BUTTON_IDX] = (1 == 1);
    }
   return p_ta->input.uni[BUTTON_IDX];
}


// This function is called only once by the program dispatcher (PrgDisp) at the very first call
// of the program dispatcher by the firmware
void PrgInit
(
    TA * p_ta, // pointer to the array of transfer area parts
    int n_ta // number of transfer area parts in array (equal to TA_COUNT)
);


// This function is called periodically by the program dispatcher (PrgDisp) with the period
// of CALL_CYCLE_MS

int PrgTic
(
    TA * p_ta, // pointer to the array of transfer area parts
    int n_ta // number of transfer area parts in array (equal to TA_COUNT)
);


// This function converts the status of the executed Bluetooth command to a string
// and displays this string on the display of a ROBO TX Controller
BOOL32 BtDisplayCommandStatus
(
    TA * p_ta,
    UCHAR8 * bt_address,
    UINT32 channel,
    enum bt_commands_e command,
    CHAR8 command_status
);
# 22 "pixymove.c" 2




static enum
{ BYTESYNC1,
    WAIT_BYTESYNC1,
    BYTESYNC2,
    WAIT_BYTESYNC2,
    BYTESYNC3,
    SYNC_1,
    WAIT_1,
    SYNC_2,
    LOOP_0,
    WAIT_LOOP_0,
    SEARCH,
    PO,
    WAIT_3,
    PX,
    WAIT_4,
    PY,
    WAIT_5,
    PB,
    WAIT_6,
    PH,
    WAIT_7,
    action,
    Objekt,
    li,
    re,
    vw,
    rw,
    aus,
    sonstige,
} stage;

unsigned int ticks;
unsigned int next_action = 0;
UINT16 sync = 0xaa55;
UINT16 chk, po, px, py, pb, ph;
UINT16 status, value, speed;


/*-----------------------------------------------------------------------------

 * Function Name       : I2cCallback

 *

 * This callback function is called to inform the program about result (status)

 * of execution of any I2c command.

 *-----------------------------------------------------------------------------*/
# 71 "pixymove.c"
static void I2cCallback
(
    TA * p_ta_array,
    I2C_CB * p_data
)
{
    status = p_data->status;
    value = p_data->value;

                   stage++;
}



/*-----------------------------------------------------------------------------

 * Function Name       : PrgInit

 *

 * This it the program initialization.

 * It is called once.

 *-----------------------------------------------------------------------------*/
# 91 "pixymove.c"
void PrgInit
(
    TA * p_ta_array, // pointer to the array of transfer areas
    int ta_count // number of transfer areas in array (equal to TA_COUNT)
)
{
   // TA * p_ta = &p_ta_array[TA_LOCAL];
    p_ta = &p_ta_array[TA_LOCAL];

    ticks = 0;
    stage = BYTESYNC1;
    speed = 480;
}

void links(speed)
{txmotor(0,1, speed / 4); txmotor(1,2,speed / 4);}

void rechts(speed)
{txmotor(0,2, speed / 4); txmotor(1,1,speed / 4);}

void vorwaerts(speed)
{txmotor(0,1, speed); txmotor(1,1,speed);}

void zurueck(speed)
{txmotor(0,2, speed); txmotor(1,2,speed);}

void stopp()
{txmotor(0,0, speed); txmotor(1,0,speed);}

/*-----------------------------------------------------------------------------

 * Function Name       : PrgTic

 *

 * This is the main function of this program.

 * It is called every tic (1 ms) realtime.

 *-----------------------------------------------------------------------------*/
# 126 "pixymove.c"
int PrgTic
(
    TA * p_ta_array, // pointer to the array of transfer areas
    int ta_count // number of transfer areas in array (equal to TA_COUNT)
)
{
    int rc = 0x7FFF; // return code: 0x7FFF - program should be further called by the firmware;
                     //              0      - program should be normally stopped by the firmware;
                     //              any other value is considered by the firmware as an error code
                     //              and the program is stopped.
   // TA * p_ta = &p_ta_array[TA_LOCAL];

    char str[64];

    ticks++;


    while(1)
    {
        switch(stage)
        { case BYTESYNC1:
                i2cread(0x14, 0x00, 0xc4);
                stage++;
                return rc;

            case WAIT_BYTESYNC1:
                // waiting for callback    
                return rc;

           case BYTESYNC2:
                if (value != 0x55) {stage = BYTESYNC1;}
                else {
                i2cread(0x14, 0x00, 0xc4);
                stage++;}
                return rc;

            case WAIT_BYTESYNC2:
                // waiting for callback    
                return rc;

            case BYTESYNC3:
                if (value != 0xaa) {stage = BYTESYNC1;}
                else {
                stage++;}
                return rc;

            case SYNC_1:
                i2cread(0x14, 0x00, 0xdc);
                stage++;
                return rc;

            case WAIT_1:
                // waiting for callback    
                return rc;

            case SYNC_2:
                if (value == 0xaa55) {stage = SYNC_1;}
                else {stage++;}
                return rc;

            case LOOP_0:
                 if (value == 0) {
                 po = 0; px = 0; py = 0; pb = 0; ph = 0;
                 i2cread(0x14, 0x00, 0xcc); //cc
                 stage++; }
                 else {stage = PO;}
                 return rc;

            case WAIT_LOOP_0:
                 // waiting for callback    
                return rc;

            case SEARCH:
            if (value == 0) { stage = LOOP_0; }
            else {stage = SYNC_1;}
            //     stage = SYNC_1;   
                 return rc;

            case PO:
                i2cread(0x14, 0x00, 0xdc);
                stage++;
                return rc;

            case WAIT_3:
                // waiting for callback    
                return rc;

            case PX:
                po = value;
                i2cread(0x14, 0x00, 0xdc);
                stage++;
                return rc;

            case WAIT_4:
                // waiting for callback    
                return rc;

            case PY:
                px = value;
                i2cread(0x14, 0x00, 0xdc);
                stage++;
                return rc;

            case WAIT_5:
                // waiting for callback    
                return rc;

            case PB:
                py = value;
                i2cread(0x14, 0x00, 0xdc);
                stage++;
                return rc;

            case WAIT_6:
                // waiting for callback    
                return rc;

            case PH:
                pb = value;
                i2cread(0x14, 0x00, 0xcc);
                stage++;
                return rc;

            case WAIT_7:
                // waiting for callback    
                return rc;

            case action:
                ph = value;
                if(ticks < next_action)
                { stage = SYNC_1;}
                else {stage++ ;}
                 return rc;
            case Objekt:
                 next_action = ticks + 20;
                 if (po == 1)
                 {txsinglelamp(6, 510);
                  stage++ ;}
                 else {stage = sonstige;}
                 return rc;
            case li:
                 if (px < 115) {links (speed * 3); stage = SYNC_1;}
                 else {stage++ ;}
                 return rc;
             case re:
                 if (px > 205) {rechts (speed * 3); stage = SYNC_1;}
                 else {stage++ ;}
                 return rc;
             case vw:
                 if (pb < 35) {vorwaerts(speed); stage = SYNC_1;}
                 else {stage++ ;}
                 return rc;
             case rw:
                 if (pb > 60) {zurueck(speed); stage = SYNC_1;}
                 else {stage++ ;}
                 return rc;
             case aus:
                 stopp();
                 stage = SYNC_1;
                 return rc;
             case sonstige:
                 if (po == 2) {txsinglelamp(7, 490); }
                 else {if (po == 3) {txsinglelamp(5, 400); }
                       else {txlamp(5,0); txlamp(6,0); txlamp(7,0); }
                      }
                 stopp();
                 stage = SYNC_1;
                 return rc;
        }
    }
    return rc;
}
