// @(#) $Header: /usr/local/scalawags_cvs/Scalawags/Frc2006/sim/simfuncs.c,v 1.45 2006/03/07 02:31:50 abrown Exp $
/***********************************************************************
  * Copyright (C) 2003,2004,2005  Allen Brown
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
  * published by the Free Software Foundation.
  *
  * 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.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the
  *   Free Software Foundation, Inc.
  *   59 Temple Place, Suite 330
  *   Boston, MA  02111-1307  USA
  *
  * To contact the author of this software:
  *   Allen Brown
  *   PO Box J
  *   Corvallis, OR
  *
  *   http://brown.armoredpenguin.com/~abrown/contact.html
  ***********************************************************************/

#define MAXSTRING 255
#if defined(ABSIMULATION_NOCOPROCESSOR) || defined(ABSIMULATION_COPROCESSOR) \
  || defined(ABSIMULATION_COPRSIM) \
  || defined(COPROCESSOR_STANDALONE) || defined(COPROCESSOR_SIMULATION)
#  include <stdlib.h>
#  include <stdio.h>
#  include <string.h>
#  include <ctype.h>
#  include "../p18f8722.h"
#  include "../ifi_aliases.h"
#  include "../ifi_default.h"
#  include "../ifi_utilities.h"
#  include "../user_routines.h"
#  include "../user_SerialDrv.h"
#  include "simfuncs.h"
#  include "../supportfuncs.h"
#  include "../includes/usart.h"
#  define NEAR
#  define ROM
#  define SHORTLONG short
#  define imax(a,b) ((a)>(b)? (a): (b))
  typedef unsigned char byte;
#endif
#if defined(FRC_NOCOPROCESSOR) || defined(FRC_COPROCESSOR)
#  define NEAR near
#  define ROM rom
#  define SHORTLONG short long
#endif

extern char Revision[];

byte dummy;
byte *savearrayslow[] =
  {
    &rxdata.oi_swA_byte.allbits, &rxdata.oi_swB_byte.allbits,
    &rxdata.rc_mode_byte.allbits, &rxdata.packet_num,

    &rxdata.oi_analog01, &rxdata.oi_analog02,
    &rxdata.oi_analog03, &rxdata.oi_analog04,

    &rxdata.oi_analog05, &rxdata.oi_analog06,
    &rxdata.oi_analog07, &rxdata.oi_analog08
  };
byte *savearrayfast[] =
  {
    &PORTBbits.full8bits, &PORTCbits.full8bits, &PORTHbits.full8bits, &PORTJbits.full8bits,
    &rxdata.rc_mode_byte.allbits, &rxdata.packet_num,
    &actual_rc_ana[0], &actual_rc_ana[1], &actual_rc_ana[2], &actual_rc_ana[3],
    &actual_rc_ana[4], &actual_rc_ana[5], &actual_rc_ana[6], &actual_rc_ana[7]
  };
short getarray[imax(sizeof(savearrayfast)/sizeof(savearrayfast[0]),
		    sizeof(savearrayslow)/sizeof(savearrayslow[0]))];
int indx;

/* frc2tcl and frcfromtcl are named pipes and are experimental.
 * By not defining NAMEDPIPE2TCL and NAMEDPIPEFROMTCL we use the
 * old way: stdout and stdin.
 */
// #define NAMEDPIPE2TCL "./frc2tcl"
#if defined(NAMEDPIPE2TCL)
  FILE *pipe2tcl;
#else
  #define pipe2tcl stdout
#endif

// #define NAMEDPIPEFROMTCL "./frcfromtcl"
#if defined(NAMEDPIPEFROMTCL)
  FILE *pipefromtcl;
#else
  #define pipefromtcl stdin
#endif

// -------------------------------------------------------------------
// Parse the parameter list.
static int parseParams(char* line, char* command, int radix, short* paramArray, int len)
{
  int cnt;
  char* pLinePtr  = line;

  while (isspace(*pLinePtr))
    ++pLinePtr;  /* Skip leading spaces */

  while (*pLinePtr != '\0'
	 && !isspace(*pLinePtr)
	 && *pLinePtr != '#')
    *command++ = *pLinePtr++;

  *command = '\0';
 
  for (cnt = 0; cnt < len; ++cnt)
  {
    while (isspace(*pLinePtr))
      ++pLinePtr;

    if (*pLinePtr != '\0')
    {
      paramArray[cnt] = (short) strtol(pLinePtr, &pLinePtr, radix);  
    }
    else
    {
      len = cnt;  /* We're done */
    }
  }

  return cnt;
}

// -------------------------------------------------------------------
void Set_Number_of_Analog_Channels (unsigned char number_of_channels)
{
} // Set_Number_of_Analog_Channels()

// -------------------------------------------------------------------
void Setup_PWM_Output_Type(int pwmSpec1,int pwmSpec2,int pwmSpec3,int pwmSpec4)
{
}

// -------------------------------------------------------------------
#ifdef _FRC_BOARD
  void Generate_Pwms(unsigned char pwm_13,unsigned char pwm_14,
                   unsigned char pwm_15,unsigned char pwm_16)
  {
  }
#else
  void Generate_Pwms(unsigned char pwm_1,unsigned char pwm_2,
                   unsigned char pwm_3,unsigned char pwm_4,
                   unsigned char pwm_5,unsigned char pwm_6,
                   unsigned char pwm_7,unsigned char pwm_8)
  {
  }
#endif

// -------------------------------------------------------------------
void Initialize_Serial_Comms (void)
{
} // Initialize_Serial_Comms()

// -------------------------------------------------------------------
void User_Proc_Is_Ready (void)
{
} // User_Proc_Is_Ready()

// -------------------------------------------------------------------
int GetInput (void)
{
  char lineoftext[MAXSTRING+1];
  char command[MAXSTRING+1];
  int getcount;
  int message;

  // *** Prompt ***
  fprintf(pipe2tcl,"-----------------------------------------------------\n");
  fprintf(pipe2tcl,"GetInput: \n"); fflush(pipe2tcl);

  // *** Read One Line **
  if( fgets( lineoftext, MAXSTRING, pipefromtcl) == NULL )
  {
    message = MSG_TEXIT;
  }
  else
  {
    /*
     * Parse the line of text, returning the command name verb and
     * a list of parameter values into "getarray".  The number of
     * parameter values is returned placed into "getcount".
     */
    getcount = parseParams( lineoftext, command, BASEFORMATIN, getarray, sizeof(getarray) / sizeof(getarray[0]) );

    if ( strcasecmp(command, "tslow") == 0 )
    {
      message = MSG_TSLOW;
    }
    else if ( strcasecmp(command, "tfast") == 0 )
    {
      message = MSG_TFAST;
    }
    else if ( strcasecmp(command, "tinterrupt") == 0 )
    {
      message = MSG_TINTERRUPT;
      fprintf(pipe2tcl,"got interrupt\n");
    }
    else if( strcasecmp( command, "treport" ) == 0 )
    {
      message = MSG_TREPORT;
      fprintf(pipe2tcl,"got report\n");
    }
    else if( strcasecmp( command, "tcopdat" ) == 0 )
    {
      message = MSG_TCOPDAT;
    }
    else if( strcasecmp( command, "tcoprmsg" ) == 0 )
    {
      message = MSG_TCOPRMSG;
    }
    else if( strcasecmp( command, "help" ) == 0 )
    {
      fprintf(pipe2tcl,"Commands:\n");
      fprintf(pipe2tcl,"  tslow <oi_analog01> <oi_analog02> <oi_analog03> <oi_analog04> <oi_analog05> <oi_analog06> <oi_analog07> <oi_analog08> <oi_swA> <oi_swB>\n");
      fprintf(pipe2tcl,"  tfast <portb> <portc> <porth> <portj> <rc_mode_byte> <packet_num>\n");
      fprintf(pipe2tcl,"  tinterrupt\n");
      fprintf(pipe2tcl,"  treport\n");
      fprintf(pipe2tcl,"  tcopdat\n");
      if( BASEFORMATOUT == 16 )
	{
	  fprintf(pipe2tcl,"All numbers are in hex.\n");
	} else {
	  fprintf(pipe2tcl,"All numbers are in decimal.\n");
	}
      fprintf(pipe2tcl,"\n");
      fflush(pipe2tcl);
      message = 0;
    }
    else if( command[0] == 0 )
    {
      message = 0;
    }
    else
    {
      message = 0;
      // -----------------------------------------------------
      // fprintf(pipe2tcl,"Huh? '%s'\n", command);
      reportstart(__FILE__,__LINE__,ERROR,"Unrecognized message. '");
      reporttext(command);
      reportend("'.");
    }

    fflush(pipe2tcl);
    switch(message)
    {
      int size;

      // ------------------------------------------------------------
      case MSG_TSLOW:
        size=sizeof(savearrayslow)/sizeof(savearrayslow[0]);
        if( size < getcount )
        {
          getcount = size;
	}
	// fprintf(pipe2tcl,"gc=%d, sz=%d.\n", getcount, size);
        for( indx=0; indx<getcount; indx++ )
        {
          *savearrayslow[indx] = (byte)getarray[indx];
        }
        fprintf(pipe2tcl,"# EchoGetInput(tslow): oi_swA=%hx(%hd), oi_swB=%hx(%hd)"
               ", rc_mode=%hx(%hd), pk_num=%hx(%hd), oi_analog01=%hx(%hd)"
               ", oi_analog02=%hx(%hd), oi_analog03=%hx(%hd), oi_analog04=%hx(%hd)"
               ", oi_analog05=%hx(%hd), oi_analog06=%hx(%hd), oi_analog07=%hx(%hd)"
               ", oi_analog08=%hx(%hd), oi_analog09=%hx(%hd), oi_analog10=%hx(%hd)"
               ", oi_analog11=%hx(%hd), oi_analog12=%hx(%hd), oi_analog13=%hx(%hd)"
               ", oi_analog14=%hx(%hd), oi_analog15=%hx(%hd), oi_analog16=%hx(%hd)"
	       "\n",
 	       rxdata.oi_swA_byte.allbits, rxdata.oi_swA_byte.allbits,
	       rxdata.oi_swB_byte.allbits, rxdata.oi_swB_byte.allbits,
	       rxdata.rc_mode_byte.allbits, rxdata.rc_mode_byte.allbits,
	       rxdata.packet_num, rxdata.packet_num,

	       rxdata.oi_analog01, rxdata.oi_analog01,
	       rxdata.oi_analog02, rxdata.oi_analog02,
	       rxdata.oi_analog03, rxdata.oi_analog03,
	       rxdata.oi_analog04, rxdata.oi_analog04,

	       rxdata.oi_analog05, rxdata.oi_analog05,
	       rxdata.oi_analog06, rxdata.oi_analog06,
	       rxdata.oi_analog07, rxdata.oi_analog07,
	       rxdata.oi_analog08, rxdata.oi_analog08,

	       rxdata.oi_analog09, rxdata.oi_analog09,
	       rxdata.oi_analog10, rxdata.oi_analog10,
	       rxdata.oi_analog11, rxdata.oi_analog11,
	       rxdata.oi_analog12, rxdata.oi_analog12,

	       rxdata.oi_analog13, rxdata.oi_analog13,
	       rxdata.oi_analog14, rxdata.oi_analog14,
	       rxdata.oi_analog15, rxdata.oi_analog15,
	       rxdata.oi_analog16, rxdata.oi_analog16
	       );
	break;
      // ------------------------------------------------------------
      case MSG_TFAST:
      {
        size=sizeof(savearrayfast)/sizeof(savearrayfast[0]);
        if( size < getcount )
        {
          getcount = size;
	}
	actual_rc_ana[0] /=4;
	actual_rc_ana[1] /=4;
	actual_rc_ana[2] /=4;
	actual_rc_ana[3] /=4;
	actual_rc_ana[4] /=4;
	actual_rc_ana[5] /=4;
	actual_rc_ana[6] /=4;
	actual_rc_ana[7] /=4;
	// fprintf(pipe2tcl,"gc=%d, sz=%d.\n", getcount, size);
	for( indx=0; indx<getcount; indx++ )
	{
	  *savearrayfast[indx] = (byte)getarray[indx];
        }
	actual_rc_ana[0] *=4;
	actual_rc_ana[1] *=4;
	actual_rc_ana[2] *=4;
	actual_rc_ana[3] *=4;
	actual_rc_ana[4] *=4;
	actual_rc_ana[5] *=4;
	actual_rc_ana[6] *=4;
	actual_rc_ana[7] *=4;
	fprintf(pipe2tcl,"# EchoGetInput(tfast): portbb=%hx(%hd)"
	       ", portcb=%hx(%hd), porthb=%hx(%hd), portjb=%hx(%hd)"
	       ", rc_mode=%hx(%hd), pk_num=%hx(%hd)"
	       ", rc_ana_in01=%hx(%hd), rc_ana_in02=%hx(%hd)"
	       ", rc_ana_in03=%hx(%hd), rc_ana_in04=%hx(%hd)"
	       ", rc_ana_in05=%hx(%hd), rc_ana_in06=%hx(%hd)"
	       ", rc_ana_in07=%hx(%hd), rc_ana_in08=%hx(%hd)"
	       // ", res01=%hx(%hd), res02=%hx(%hd)"
	       ".\n",
	       PORTBbits.full8bits, PORTBbits.full8bits,
	       PORTCbits.full8bits, PORTCbits.full8bits,
	       PORTHbits.full8bits, PORTHbits.full8bits,
	       PORTJbits.full8bits, PORTJbits.full8bits,
	       rxdata.rc_mode_byte.allbits, rxdata.rc_mode_byte.allbits,
	       rxdata.packet_num, rxdata.packet_num,
	       actual_rc_ana[0], actual_rc_ana[0],
	       actual_rc_ana[1], actual_rc_ana[1],
	       actual_rc_ana[2], actual_rc_ana[2],
	       actual_rc_ana[3], actual_rc_ana[3],
	       actual_rc_ana[4], actual_rc_ana[4],
	       actual_rc_ana[5], actual_rc_ana[5],
	       actual_rc_ana[6], actual_rc_ana[6],
	       actual_rc_ana[7], actual_rc_ana[7]
	       );
	break;
      }
      // ------------------------------------------------------------
      case MSG_TINTERRUPT:
	break;
      // ------------------------------------------------------------
      case MSG_TREPORT:
        break;
      // ------------------------------------------------------------
      case MSG_TCOPDAT:
        fprintf(pipe2tcl,"# EchoGetInput(tcopdat): oi_swA=%hx(%hd), oi_swB=%hx(%hd)"
               ", oi_analog01=%hx(%hd)"
               ", oi_analog02=%hx(%hd), oi_analog03=%hx(%hd), oi_analog04=%hx(%hd)"
               ", oi_analog05=%hx(%hd), oi_analog06=%hx(%hd), oi_analog07=%hx(%hd)"
               ", oi_analog08=%hx(%hd), oi_analog09=%hx(%hd), oi_analog10=%hx(%hd)"
               ", oi_analog11=%hx(%hd), oi_analog12=%hx(%hd), oi_analog13=%hx(%hd)"
               ", oi_analog14=%hx(%hd), oi_analog15=%hx(%hd), oi_analog16=%hx(%hd)"
	       ".\n",
 	       rxdata.oi_swA_byte.allbits, rxdata.oi_swA_byte.allbits,
	       rxdata.oi_swB_byte.allbits, rxdata.oi_swB_byte.allbits,

	       rxdata.oi_analog01, rxdata.oi_analog01,
	       rxdata.oi_analog02, rxdata.oi_analog02,
	       rxdata.oi_analog03, rxdata.oi_analog03,
	       rxdata.oi_analog04, rxdata.oi_analog04,

	       rxdata.oi_analog05, rxdata.oi_analog05,
	       rxdata.oi_analog06, rxdata.oi_analog06,
	       rxdata.oi_analog07, rxdata.oi_analog07,
	       rxdata.oi_analog08, rxdata.oi_analog08,

	       rxdata.oi_analog09, rxdata.oi_analog09,
	       rxdata.oi_analog10, rxdata.oi_analog10,
	       rxdata.oi_analog11, rxdata.oi_analog11,
	       rxdata.oi_analog12, rxdata.oi_analog12,

	       rxdata.oi_analog13, rxdata.oi_analog13,
	       rxdata.oi_analog14, rxdata.oi_analog14,
	       rxdata.oi_analog15, rxdata.oi_analog15,
	       rxdata.oi_analog16, rxdata.oi_analog16
	       );
        break;
      // ------------------------------------------------------------
#if defined(ABSIMULATION_COPROCESSOR)
      case MSG_TCOPRMSG:
	for (int i = 0; i<getcount; i++)
	{
	  //Serial_Char_Callback(getarray[i]);
	}
	break;
#endif
      // ------------------------------------------------------------
      default:
        break;
    } // switch(message)
    fflush(pipe2tcl);
    return(message);
  } // else(fgets() == NULL)
  return(message);
} // GetInput()

// -------------------------------------------------------------------

void PutFast(void)
{
  fprintf(pipe2tcl,"rfast:");
  if (disabled_mode)
  {
    DisableBot();
  }
  if( BASEFORMATOUT == 16 )
  {
    fprintf(pipe2tcl," pwm01=%x pwm02=%x pwm03=%x pwm04=%x",
	   txdata.rc_pwm01, txdata.rc_pwm02,
	   txdata.rc_pwm03, txdata.rc_pwm04
	   );
    fprintf(pipe2tcl," pwm05=%x pwm06=%x pwm07=%x pwm08=%x",
	   txdata.rc_pwm05, txdata.rc_pwm06,
	   txdata.rc_pwm07, txdata.rc_pwm08
	   );
    fprintf(pipe2tcl," pwm09=%x pwm10=%x pwm11=%x pwm12=%x",
	   txdata.rc_pwm09, txdata.rc_pwm10,
	   txdata.rc_pwm11, txdata.rc_pwm12
	   );
    fprintf(pipe2tcl," pwm13=%x pwm14=%x pwm15=%x pwm16=%x",
	   txdata.rc_pwm13, txdata.rc_pwm14,
	   txdata.rc_pwm15, txdata.rc_pwm16
	   );
    fprintf(pipe2tcl," pwm_mask=%x", txdata.pwm_mask );
    fprintf(pipe2tcl," latb=%x",
	   (LATBbits.LATB7 << 7) | (LATBbits.LATB6 << 6) |
	   (LATBbits.LATB5 << 5) | (LATBbits.LATB4 << 4) |
	   (LATBbits.LATB3 << 3) | (LATBbits.LATB2 << 2) |
	   (LATBbits.LATB1 << 1) | (LATBbits.LATB0)
	  );
    fprintf(pipe2tcl," latc=%x",
	   (LATCbits.LATC7 << 7) | (LATCbits.LATC6 << 6) |
	   (LATCbits.LATC5 << 5) | (LATCbits.LATC4 << 4) |
	   (LATCbits.LATC3 << 3) | (LATCbits.LATC2 << 2) |
	   (LATCbits.LATC1 << 1) | (LATCbits.LATC0)
	  );
    fprintf(pipe2tcl," lath=%x",
	   (LATHbits.LATH7 << 7) | (LATHbits.LATH6 << 6) |
	   (LATHbits.LATH5 << 5) | (LATHbits.LATH4 << 4) |
	   (LATHbits.LATH3 << 3) | (LATHbits.LATH2 << 2) |
	   (LATHbits.LATH1 << 1) | (LATHbits.LATH0)
	  );
    fprintf(pipe2tcl," latj=%x",
	   (LATJbits.LATJ7 << 7) | (LATJbits.LATJ6 << 6) |
	   (LATJbits.LATJ5 << 5) | (LATJbits.LATJ4 << 4) |
	   (LATJbits.LATJ3 << 3) | (LATJbits.LATJ2 << 2) |
	   (LATJbits.LATJ1 << 1) | (LATJbits.LATJ0)
	  );
  } else {
    fprintf(pipe2tcl," pwm01=%d pwm02=%d pwm03=%d pwm04=%d",
	   txdata.rc_pwm01, txdata.rc_pwm02,
	   txdata.rc_pwm03, txdata.rc_pwm04
	   );
    fprintf(pipe2tcl," pwm05=%d pwm06=%d pwm07=%d pwm08=%d",
	   txdata.rc_pwm05, txdata.rc_pwm06,
	   txdata.rc_pwm07, txdata.rc_pwm08
	   );
    fprintf(pipe2tcl," pwm09=%d pwm10=%d pwm11=%d pwm12=%d",
	   txdata.rc_pwm09, txdata.rc_pwm10,
	   txdata.rc_pwm11, txdata.rc_pwm12
	   );
    fprintf(pipe2tcl," pwm13=%d pwm14=%d pwm15=%d pwm16=%d",
	   txdata.rc_pwm13, txdata.rc_pwm14,
	   txdata.rc_pwm15, txdata.rc_pwm16
	   );
    fprintf(pipe2tcl," pwm_mask=%d", txdata.pwm_mask );
    fprintf(pipe2tcl," latb=%d",
	   (LATBbits.LATB7 << 7) | (LATBbits.LATB6 << 6) |
	   (LATBbits.LATB5 << 5) | (LATBbits.LATB4 << 4) |
	   (LATBbits.LATB3 << 3) | (LATBbits.LATB2 << 2) |
	   (LATBbits.LATB1 << 1) | (LATBbits.LATB0)
	  );
    fprintf(pipe2tcl," latc=%d",
	   (LATCbits.LATC7 << 7) | (LATCbits.LATC6 << 6) |
	   (LATCbits.LATC5 << 5) | (LATCbits.LATC4 << 4) |
	   (LATCbits.LATC3 << 3) | (LATCbits.LATC2 << 2) |
	   (LATCbits.LATC1 << 1) | (LATCbits.LATC0)
	  );
    fprintf(pipe2tcl," lath=%d",
	   (LATHbits.LATH7 << 7) | (LATHbits.LATH6 << 6) |
	   (LATHbits.LATH5 << 5) | (LATHbits.LATH4 << 4) |
	   (LATHbits.LATH3 << 3) | (LATHbits.LATH2 << 2) |
	   (LATHbits.LATH1 << 1) | (LATHbits.LATH0)
	  );
    fprintf(pipe2tcl," latj=%d",
	   (LATJbits.LATJ7 << 7) | (LATJbits.LATJ6 << 6) |
	   (LATJbits.LATJ5 << 5) | (LATJbits.LATJ4 << 4) |
	   (LATJbits.LATJ3 << 3) | (LATJbits.LATJ2 << 2) |
	   (LATJbits.LATJ1 << 1) | (LATJbits.LATJ0)
	  );
  }
  fprintf(pipe2tcl,"\n");
  fflush(pipe2tcl);
} // PutFast()

// -------------------------------------------------------------------
void Getdata(rx_data_record * rxdataG)
{
} // Getdata()

// -------------------------------------------------------------------
void Putdata(tx_data_record * txdataP)
{
  fprintf(pipe2tcl,"rslow:");
  if (disabled_mode)
  {
    DisableBot();
  }
  if( BASEFORMATOUT == 16 )
    {
      fprintf(pipe2tcl," LED_byte1=%x LED_byte2=%x",
	     txdataP->LED_byte1.data, txdataP->LED_byte2.data
	     );
    } else {
      fprintf(pipe2tcl," LED_byte1=%d LED_byte2=%d",
	     txdataP->LED_byte1.data, txdataP->LED_byte2.data
	     );
    }
  fprintf(pipe2tcl,"\n");
  fflush(pipe2tcl);
} // Putdata()

// -------------------------------------------------------------------
void IFI_Initialization ()
{
  char *revpt;

#if defined(NAMEDPIPE2TCL)
  pipe2tcl = fopen(NAMEDPIPE2TCL,"w");
#endif
#if defined(NAMEDPIPEFROMTCL)
  pipefromtcl = fopen(NAMEDPIPEFROMTCL,"r");
#endif

  fputs("Rev=", pipe2tcl);
  for(revpt=Revision; *(++revpt); )
  {
    if(*revpt == ' ')
    {
      putc((int)'_', pipe2tcl);
    }
    else
    {
      putc((int)*revpt, pipe2tcl);
    }
  }
  fputs(";", pipe2tcl);
  //  fprintf(pipe2tcl,"Rev=%s;", Revision);
#if defined(FRC_COPROCESSOR) || defined(ABSIMULATION_COPROCESSOR)
  fprintf(pipe2tcl," Cop=2;"); 
#endif
#if defined(ABSIMULATION_COPRSIM)
  fprintf(pipe2tcl," Cop=1;"); 
#endif
#if defined(FRC_NOCOPROCESSOR) || defined(ABSIMULATION_NOCOPROCESSOR)
  fprintf(pipe2tcl," Cop=0;"); 
#endif
  fprintf(pipe2tcl,"\n");
} // IFI_Initialization()

// -------------------------------------------------------------------

void Serial_Driver_Initialize (void)
{
} // Serial_Driver_Initialize()

// -------------------------------------------------------------------
void Serial_Write_Char(int port,int ch_out)
{
}

// -------------------------------------------------------------------
char getc1USART(void)	// Read1USART
{
  return('U');
}

// -------------------------------------------------------------------
char getc2USART(void)	// Read2USART
{
  return('U');
}

// -------------------------------------------------------------------
int Busy1USART(void)
{
  return(!TXSTA1bits.TRMT);
}

// -------------------------------------------------------------------
int Busy2USART(void)
{
  return(!TXSTA2bits.TRMT);
}

// -------------------------------------------------------------------
char DataRdy1USART(void)
{
  return('b');
}

// -------------------------------------------------------------------
char DataRdy2USART(void)
{
  return('c');
}

// -------------------------------------------------------------------

unsigned char Breaker_Tripped(unsigned char id)
{
  return (unsigned char) 0;
} // Breaker_Tripped()

// -------------------------------------------------------------------
void CheckUartInts(void)
{
} // CheckUartInts()

// -------------------------------------------------------------------
unsigned int Get_Analog_Value(unsigned char channel)
{
  return(actual_rc_ana[channel]);
} // Get_Analog_Value()

/*
 * $Log: simfuncs.c,v $
 * Revision 1.45  2006/03/07 02:31:50  abrown
 * Correctly ignore blank lines and comment lines.
 *
 * Revision 1.44  2006/02/05 01:49:52  abrown
 * Fix the order of variables input/output to TCL.  Improve help.
 *
 * Revision 1.43  2006/02/04 23:54:18  abrown
 * Remove some code that is no longer used.
 *
 * Revision 1.42  2006/02/04 23:47:19  abrown
 * Add portc to the list of ports we manage.
 *
 * Revision 1.41  2006/02/01 00:35:07  abrown
 * Only include MSG_TCOPRMSG case if we are targetting a coprocessor system.
 *
 * Revision 1.40  2005/12/24 02:02:32  abrown
 * Report in the status line if the coprocessor is physical or simulated.
 *
 * Revision 1.39  2005/12/24 01:36:50  abrown
 * Split the old target ABSIMULATION_COPROCESSOR into two.  Now
 * ABSIMULATION_COPROCESSOR includes a physical coprocessor.  The new
 * target, ABSIMULATION_COPRSIM, includes a simulated coprocessor.
 *
 * Revision 1.38  2005/12/23 22:16:18  abrown
 * Clean up hooks for replacing stdin and stdout for communicating with Tcl.
 *
 * Revision 1.37  2005/12/17 04:02:46  asumu
 * Added a command to the FRC simulation to simulate serial communications interrupt. Also allow sd_* declarations for ABSIMULATION_COPROCESSOR.
 *
 * Revision 1.36  2005/12/15 03:46:32  abrown
 * Put hooks in place to move simulator communication channel off
 * of stdout and onto its own pipe.
 *
 * Revision 1.35  2005/04/30 18:05:04  abrown
 * Convert from obsolete defines to the new ones.
 *
 * Revision 1.34  2005/03/13 20:33:44  abrown
 * In a fairly kludgy way, add in support for rc_ana_in*.  This really
 * should be cleaned up some day.  But it require dealing with 10 bit
 * words being sent between Tcl and C.
 *
 * Revision 1.33  2005/02/24 22:52:26  abrown
 * Add porth.
 *
 * Revision 1.32  2005/02/20 21:33:03  abrown
 * Remove an errant / from a printf.
 *
 * Revision 1.31  2005/02/19 06:54:15  abrown
 * Define Get_Analog_Value().
 *
 * Revision 1.30  2005/02/17 02:33:19  abrown
 * Move simfuncs into the sim directory.
 *
 * Revision 1.29  2005/02/13 19:24:47  abrown
 * Change revision printing code to remove blanks.
 *
 * Revision 1.28  2005/01/30 20:34:57  abrown
 * Make coprocessor activities visible to TCL.
 *
 * Revision 1.27  2005/01/28 02:50:00  abrown
 * Add some debug code.  Why isn't coprocessor binary doing anything?
 *
 * Revision 1.26  2005/01/26 05:53:00  abrown
 * Some of the coprocessor code.
 *
 * Revision 1.25  2005/01/25 03:52:57  abrown
 * Add DataRdy*USART() definitions.
 *
 * Revision 1.24  2005/01/25 03:35:17  abrown
 * Update to the default code from Innovation First.  This is rev 2.4
 * and includes ifdef'ed camera code.
 *
 * Revision 1.23  2005/01/22 21:28:18  abrown
 * Comment out some debug-only code.
 *
 * Revision 1.22  2005/01/22 03:23:20  go
 * Parser changes and some other formatting adjustments.
 *
 * Revision 1.21  2005/01/22 03:09:36  go
 * New parser
 *
 * Revision 1.20  2005/01/20 16:25:26  abrown
 * Prevent simfuncs from storing more data into savearry*() than the size
 * of those arrays.
 *
 * Revision 1.19  2005/01/16 21:01:19  abrown
 * Report works.  Don't need to say that we got the message.
 *
 * Revision 1.18  2005/01/14 03:35:27  abrown
 * Added rudimentary com link to a coprocessor.
 *
 * Revision 1.17  2005/01/09 05:14:59  abrown
 * Update to 2005 default code base. -- Allen Brown
 *
 * Revision 1.16  2004/12/29 18:34:35  abrown
 * Use full names (like the default code) for oi_analog and rc_ana_in.
 *
 * Revision 1.15  2004/12/29 05:31:12  abrown
 * Major changes.  Fixed problems with several declaration types.
 * Some functions had wrong number of parameters.  Added a new
 * message: MSG_TEXIT.  Cleaned up some warnings.
 */


syntax highlighted by Code2HTML, v. 0.9.1