/** ###################################################################
**     THIS COMPONENT MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
**     Filename  : EI2C2.C
**     Project   : Generator
**     Processor : MC9S08GT16ACFB
**     Component : SW_I2C
**     Version   : Component 01.121, Driver 03.27, CPU db: 2.87.091
**     Compiler  : CodeWarrior HCS08 C Compiler
**     Date/Time : 20.5.2010, 21:50
**     Abstract  :
**         This device "SW_I2C" implements an external I2C
**         communication interface. It uses two general-purpose
**         I/O pins.
**     Settings  :
**         Serial Clock (SCL) pin      :
**             ----------------------------------------------------
**                Number (on package)  |    Name
**             ----------------------------------------------------
**                       5             |  PTC3_SCL
**             ----------------------------------------------------
**
**         Serial Data (SDA) pin       :
**             ----------------------------------------------------
**                Number (on package)  |    Name
**             ----------------------------------------------------
**                       4             |  PTC2_SDA
**             ----------------------------------------------------
**
**
**         Mode                        : MASTER
**         Communication Speed         : FAST MODE
**         Output Buffer Size          : 0
**         Auto Stop Condition         : no
**         Acknowledge Polling Trials  : 2000
**
**         Speed modes
**
**             High Speed Mode         : Enabled
**             Low Speed Mode          : Disabled
**             Slow Speed Mode         : Disabled
**
**         Initialization
**
**             Slave address           : 121
**             Bean function           : Enabled
**             Events                  : Enabled
**     Contents  :
**         Enable       - byte EI2C2_Enable(void);
**         Disable      - byte EI2C2_Disable(void);
**         EnableEvent  - byte EI2C2_EnableEvent(void);
**         DisableEvent - byte EI2C2_DisableEvent(void);
**         SendChar     - byte EI2C2_SendChar(byte Chr);
**         RecvChar     - byte EI2C2_RecvChar(byte *Chr);
**         SendBlock    - byte EI2C2_SendBlock(void* Ptr, word Siz, word *Snt);
**         RecvBlock    - byte EI2C2_RecvBlock(void* Ptr, word Siz, word *Rcv);
**         SendStop     - byte EI2C2_SendStop(void);
**         SelectSlave  - byte EI2C2_SelectSlave(byte Slv);
**         GetSelected  - byte EI2C2_GetSelected(byte *Slv);
**
**     Copyright : 1997 - 2009 Freescale Semiconductor, Inc. All Rights Reserved.
**     
**     http      : www.freescale.com
**     mail      : support@freescale.com
** ###################################################################*/


/* MODULE EI2C2. */

#include "Events.h"
#include "PE_Error.h"
#include "EI2C2.h"
#include "Inhr4.h"
#include "Inhr3.h"


#define ACK         0
#define NOACK       1
#define OUTPUT      1
#define INPUT       0
#define WRITE       0
#define READ        1
#define TRIALS      0x07D0

static bool EnUser;                /* enabled/disabled by user       */
static bool EnEvent;               /* enabled/disabled event(s)      */
static byte SlaveAddr;             /* destination slave address      */

/* Internal method prototypes */
static void Delay(void);
static void Write(byte Data);
static byte Read(void);
static bool GetAck(void);
static void SetAck(bool Ack);
static void InternalStop(void);

/*
** ===================================================================
**     Method      :  EI2C2_Delay (component SW_I2C)
**
**     Description :
**         The method waits in delay loop.
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
/* Disable MISRA rule 19 checking - Octal constant used */
/*lint -esym( 960, 19)   */
/* Disable MISRA rule 55 checking - Non-case label used */
/*lint -esym( 961, 55)   */
static void Delay(void)
{
  asm {
    /* jsr/bsr                            (5 c) jump/branch to subroutine */
    /*
     * Delay
     *   - requested                  : 1250 ns @ 10MHz,
     *   - possible                   : 13 c, 1300 ns, delta 50 ns
     *   - without removable overhead : 2 c, 200 ns
     */
    nop                                /* (1 c: 100 ns) wait for 1 c */
    nop                                /* (1 c: 100 ns) wait for 1 c */
    /* rts                                (6 c) return from subroutine */
  }
}
/* Restore MISRA rule 19 checking - Octal constant used */
/*lint +esym( 960, 19)   */
/* Restore MISRA rule 55 checking - Non-case label used */
/*lint +esym( 961, 55)   */

/*
** ===================================================================
**     Method      :  EI2C2_Init (component SW_I2C)
**
**     Description :
**         Initializes the associated peripheral(s) and the beans 
**         internal variables. The method is called automatically as a 
**         part of the application initialization code.
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
void EI2C2_Init(void)
{
  SlaveAddr = 0xF2;
  EnUser = TRUE;
  EnEvent = TRUE;
}

/*
** ===================================================================
**     Method      :  EI2C2_Write (component SW_I2C)
**
**     Description :
**         The method sends one byte of data to the bus.
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
static void Write(byte Data)
{
  byte Shift;
  byte I;
  word timeout;

  Shift = 0x80;
  for (I = 0x08; I != 0; I--) {
    if (Data & Shift) {
      Inhr3_SetDir((bool)INPUT);   /* SDA HIGH */
    }
    else {
      Inhr3_SetDir((bool)OUTPUT);
      Inhr3_ClrVal();              /* SDA LOW */
    }
    Shift >>= 1;
    Inhr4_SetDir((bool)INPUT);     /* CLOCK HIGH PULSE */
    Delay();
    timeout = 65535;
    while((Inhr4_GetVal()==0)&&(timeout!=0)) { /* WAIT FOR CLOCK HIGH PULSE */
      timeout--;
    }
    Inhr4_SetDir((bool)OUTPUT);
    Inhr4_ClrVal();                /* CLOCK LOW PULSE */
    Delay();
  }
}

/*
** ===================================================================
**     Method      :  EI2C2_Read (component SW_I2C)
**
**     Description :
**         The method reads one byte of data from the bus.
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
static byte Read(void)
{
  byte Shift;
  byte I;
  word timeout;

  Shift = 0;
  Inhr3_SetDir((bool)INPUT);       /* SDA INPUT MODE */
  for (I = 0x08; I != 0; I--) {
    Inhr4_SetDir((bool)INPUT);     /* CLOCK HIGH PULSE */
    Delay();
    timeout = 65535;
    while((Inhr4_GetVal()==0)&&(timeout!=0)) { /* WAIT FOR CLOCK HIGH PULSE */
      timeout--;
    }
    Shift <<= 1;
    if (Inhr3_GetVal()) {
      Shift++;
    }
    Inhr4_SetDir((bool)OUTPUT);
    Inhr4_ClrVal();                /* CLOCK LOW PULSE */
    Delay();
  }
  return Shift;
}

/*
** ===================================================================
**     Method      :  EI2C2_GetAck (component SW_I2C)
**
**     Description :
**         The method reads ACK from the bus.
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
static bool GetAck(void)
{
  word timeout;

  Inhr3_SetDir((bool)INPUT);       /* SDA HIGH */
  Inhr4_SetDir((bool)INPUT);       /* CLOCK HIGH PULSE */
  Delay();
  timeout = 65535;
  while((Inhr4_GetVal()==0)&&(timeout!=0)) { /* WAIT FOR CLOCK HIGH PULSE */
    timeout--;
  }
  return((bool)Inhr3_GetVal());    /* ACKNOWLEDGE VALUE */
}

/*
** ===================================================================
**     Method      :  EI2C2_SetAck (component SW_I2C)
**
**     Description :
**         The method sends ACK to the bus.
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
static void SetAck(bool Ack)
{
  word timeout;

  if (Ack) {
    Inhr3_SetDir((bool)INPUT);     /* MASTER NOACKNOWLEDGE - SDA HIGH */
  }
  else {
    Inhr3_SetDir((bool)OUTPUT);
    Inhr3_ClrVal();                /* MASTER ACKNOWLEDGE - SDA LOW */
  }
  Inhr4_SetDir((bool)INPUT);       /* HIGH CLOCK PULSE */
  Delay();
  timeout = 65535;
  while((Inhr4_GetVal()==0)&&(timeout!=0)) { /* WAIT FOR CLOCK HIGH PULSE */
    timeout--;
  }
  Inhr4_SetDir((bool)OUTPUT);
  Inhr4_ClrVal();                  /* LOW CLOCK PULSE */
  Delay();
  Inhr3_SetDir((bool)INPUT);       /* ACKNOWLEDGE END - SDA HIGH  */
}

/*
** ===================================================================
**     Method      :  EI2C2_InternalStop (component SW_I2C)
**
**     Description :
**         The method generates the Stop condition on the bus.
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
static void InternalStop(void)
{
  Inhr3_SetDir((bool)OUTPUT);
  Inhr3_ClrVal();                  /* STOP SETUP */
  Inhr4_SetDir((bool)INPUT);       /* CLOCK HIGH PULSE + STOP SETUP TIME */
  Delay();
  Inhr3_SetDir((bool)INPUT);       /* STOP CONDITION */
}

/*
** ===================================================================
**     Method      :  EI2C2_Enable (component SW_I2C)
**
**     Description :
**         This method enables the I2C interface for send and receive
**         operations. This method cannot be disabled if the <Enabled
**         in init. code> property value is "no".
**     Parameters  : None
**     Returns     :
**         ---             - Error code, possible codes:
**                           ERR_OK - OK
**                           ERR_SPEED - This device does not work in
**                           the active speed mode
** ===================================================================
*/
byte EI2C2_Enable(void)
{
  if (!EnUser) {
    EnUser = TRUE;
  }
  return ERR_OK;
}

/*
** ===================================================================
**     Method      :  EI2C2_Disable (component SW_I2C)
**
**     Description :
**         This method disables the I2C interface for send and receive
**         operations.
**     Parameters  : None
**     Returns     :
**         ---             - Error code, possible codes:
**                           ERR_OK - OK
**                           ERR_SPEED - This device does not work in
**                           the active speed mode
** ===================================================================
*/
byte EI2C2_Disable(void)
{
  if (EnUser) {
    EnUser = FALSE;
  }
  return ERR_OK;
}

/*
** ===================================================================
**     Method      :  EI2C2_EnableEvent (component SW_I2C)
**
**     Description :
**         This method enables the events. This method is available
**         only if at least one event is enabled.
**     Parameters  : None
**     Returns     :
**         ---             - Error code, possible codes:
**                           ERR_OK - OK
**                           ERR_SPEED - This device does not work in
**                           the active speed mode
** ===================================================================
*/
byte EI2C2_EnableEvent(void)
{
  EnEvent = TRUE;
  return ERR_OK;
}

/*
** ===================================================================
**     Method      :  EI2C2_DisableEvent (component SW_I2C)
**
**     Description :
**         This method disables the events. This method is available
**         only if at least one event is enabled.
**     Parameters  : None
**     Returns     :
**         ---             - Error code, possible codes:
**                           ERR_OK - OK
**                           ERR_SPEED - This device does not work in
**                           the active speed mode
** ===================================================================
*/
byte EI2C2_DisableEvent(void)
{
  EnEvent = FALSE;
  return ERR_OK;
}

/*
** ===================================================================
**     Method      :  EI2C2_SendChar (component SW_I2C)
**
**     Description :
**         When working as a MASTER, this method writes 7 bits of slave
**         address plus R/W bit = 0 to the I2C bus and then writes one
**         character (byte) to the bus. The slave address must be
**         specified before by the "SelectSlave" method or in the bean
**         initialization section of <Slave address init> property.
**         When working as the SLAVE, this method writes one character
**         (byte) to the bus. If the ERR_NOTAVAIL error code returned,
**         the char is successfully sent to master but the master
**         device responds by an acknowledgement instead of no
**         acknowledgement at the end of transfer. <OnError> event is
**         called in this case.
**     Parameters  :
**         NAME            - DESCRIPTION
**         Chr             - Character to send
**     Returns     :
**         ---             - Error code, possible codes:
**                           ERR_OK - OK
**                           ERR_SPEED - This device does not work in
**                           the active speed mode
**                           ERR_BUSY - The slave device is busy, it
**                           does not respond by the acknowledgement
**                           (MASTER mode only)
**                           ERR_NOTAVAIL - The master device sends
**                           acknowledgement instead of no
**                           acknowledgement after the last byte
**                           transfer (SLAVE mode only)
**                           ERR_DISABLED - Device is disabled
**                           ERR_BUSOFF - Clock timeout elapsed (SLAVE
**                           mode only)
** ===================================================================
*/
byte EI2C2_SendChar(byte Chr)
{
  word Trial;
  bool Acknowledge;

  if (!EnUser) {
    return ERR_DISABLED;
  }
  Trial = TRIALS;
  do {
    Inhr3_SetDir((bool)INPUT);     /* SDA HIGH - START SETUP*/
    Inhr4_SetDir((bool)INPUT);     /* CLOCK HIGH PULSE */
    Delay();                       /* CLOCK HIGH PULSE & BUS FREE TIME */
    Inhr3_SetDir((bool)OUTPUT);
    Inhr3_ClrVal();                /* START CONDITION */
    Delay();                       /* START HOLD TIME */
    Inhr4_SetDir((bool)OUTPUT);
    Inhr4_ClrVal();                /* CLOCK LOW PULSE */
    Delay();
    Write((byte)(SlaveAddr + WRITE));
    Acknowledge = GetAck();
    --Trial;
  } while (Trial && Acknowledge);
  if (Acknowledge) {               /* WRONG ACKNOWLEDGE */
    Inhr4_SetDir((bool)OUTPUT);
    Inhr4_ClrVal();                /* CLOCK LOW PULSE */
    InternalStop();
    return ERR_BUSY;
  }
  else {
    Inhr4_SetDir((bool)OUTPUT);
    Inhr4_ClrVal();                /* CLOCK LOW PULSE */
    Delay();
  }
  Write(Chr);
  if (GetAck()) {                  /* WRONG ACKNOWLEDGE */
    Inhr4_SetDir((bool)OUTPUT);
    Inhr4_ClrVal();                /* CLOCK LOW PULSE */
    InternalStop();
    return ERR_BUSY;
  }
  else {
    Inhr4_SetDir((bool)OUTPUT);
    Inhr4_ClrVal();                /* CLOCK LOW PULSE */
    Delay();
  }
  return ERR_OK;
}

/*
** ===================================================================
**     Method      :  EI2C2_RecvChar (component SW_I2C)
**
**     Description :
**         When working as a MASTER, this method writes 7 bits of slave
**         address plus R/W bit = 1 to the I2C bus and then reads one
**         character (byte) from the bus. The slave address must be
**         specified before by the "SelectSlave" method or in the bean
**         initialization section of <Slave address init> property.
**         When working as a SLAVE, this method reads one character
**         (byte) from the bus.
**     Parameters  :
**         NAME            - DESCRIPTION
**       * Chr             - Pointer to received character
**     Returns     :
**         ---             - Error code, possible codes:
**                           ERR_OK - OK
**                           ERR_SPEED - This device does not work in
**                           the active speed mode
**                           ERR_BUSY - The slave device is busy, it
**                           does not respond by the acknowledgement
**                           (MASTER mode only)
**                           ERR_DISABLED - Device is disabled
**                           ERR_BUSOFF - Clock timeout elapsed (SLAVE
**                           mode only)
** ===================================================================
*/
byte EI2C2_RecvChar(byte *Chr)
{
  word Trial;
  bool Acknowledge;

  if (!EnUser) {
    return ERR_DISABLED;
  }
  Trial = TRIALS;
  do {
    Inhr3_SetDir((bool)INPUT);     /* SDA HIGH - START SETUP */
    Inhr4_SetDir((bool)INPUT);     /* CLOCK HIGH PULSE */
    Delay();                       /* CLOCK HIGH PULSE & BUS FREE TIME */
    Inhr3_SetDir((bool)OUTPUT);
    Inhr3_ClrVal();                /* START CONDITION */
    Delay();                       /* START HOLD TIME */
    Inhr4_SetDir((bool)OUTPUT);
    Inhr4_ClrVal();                /* CLOCK LOW PULSE */
    Delay();
    Write((byte)(SlaveAddr + READ));
    Acknowledge = GetAck();
    --Trial;
  } while (Trial && Acknowledge);
  if (Acknowledge) {
    Inhr4_SetDir((bool)OUTPUT);
    Inhr4_ClrVal();                /* CLOCK LOW PULSE */
    InternalStop();
    return ERR_BUSY;
  }
  else {
    Inhr4_SetDir((bool)OUTPUT);
    Inhr4_ClrVal();                /* CLOCK LOW PULSE */
    Delay();
  }
  *Chr = Read();
  if (EnEvent) {
    EI2C2_OnRxChar();
  }
  SetAck((bool)NOACK);
  return ERR_OK;
}

/*
** ===================================================================
**     Method      :  EI2C2_SendBlock (component SW_I2C)
**
**     Description :
**         When working as a MASTER, this method writes 7 bits of slave
**         address plus R/W bit = 0 to the I2C bus and then writes the
**         block of characters to the bus. If the bean is disabled (by
**         the "Disable" method or initialization), the block is moved
**         to the output buffer if the <Output buffer size> property is
**         different from zero. The content of the output buffer is
**         sent immediately with the stop condition at the end when the
**         bean is enabled by the "Enable" method. After the output
**         buffer transmission, the whole output buffer is cleared. The
**         slave address must be specified before by the "SelectSlave"
**         method or in bean initialization section of <Slave address
**         init> property. When working as a SLAVE, this method writes
**         block of characters to the bus. If the ERR_NOTAVAIL error
**         code is returned, the whole block is successfully sent to a
**         master but the master device responds by an acknowledgement
**         instead of no acknowledgment sent at the end of the last
**         block byte transfer. <OnError> event is called in this case.
**     Parameters  :
**         NAME            - DESCRIPTION
**       * Ptr             - A pointer to the block of data to send
**         Siz             - The size of the block
**       * Snt             - A pointer to the number of data that are
**                           sent (copied to buffer)
**     Returns     :
**         ---             - Error code, possible codes:
**                           ERR_OK - OK
**                           ERR_SPEED - This device does not work in
**                           the active speed mode
**                           ERR_BUSY - The slave device is busy, it
**                           does not respond by the acknowledgement
**                           (MASTER mode only)
**                           ERR_TXFULL - Output buffer is full (MASTER
**                           mode only)
**                           ERR_NOTAVAIL - The master device sends
**                           acknowledgement instead of no
**                           acknowledgement after the last byte
**                           transfer (SLAVE mode only)
**                           ERR_DISABLED - Device is disabled
**                           ERR_BUSOFF - Clock timeout elapsed (SLAVE
**                           mode only)
** ===================================================================
*/
byte EI2C2_SendBlock(void * Ptr,word Siz,word *Snt)
{
  register word I;
  bool Acknowledge;
  word Trial;

  *Snt = 0;
  if (!EnUser) {
    return ERR_DISABLED;
  }
  Trial = TRIALS;
  do {
    Inhr3_SetDir((bool)INPUT);     /* SDA HIGH  - START SETUP */
    Inhr4_SetDir((bool)INPUT);     /* CLOCK HIGH PULSE */
    Delay();                       /* CLOCK HIGH PULSE + BUS FREE TIME */
    Inhr3_SetDir((bool)OUTPUT);
    Inhr3_ClrVal();                /* START CONDITION */
    Delay();                       /* START HOLD TIME */
    Inhr4_SetDir((bool)OUTPUT);
    Inhr4_ClrVal();                /* CLOCK LOW PULSE */
    Delay();
    Write((byte)(SlaveAddr + WRITE));
    Acknowledge = GetAck();
    --Trial;
  } while (Trial && Acknowledge);
  if (Acknowledge) {
    Inhr4_SetDir((bool)OUTPUT);
    Inhr4_ClrVal();                /* CLOCK LOW PULSE */
    InternalStop();
    return ERR_BUSY;
  }
  else {
    Inhr4_SetDir((bool)OUTPUT);
    Inhr4_ClrVal();                /* CLOCK LOW PULSE */
    Delay();
  }
  for (I = 0; I < Siz; I++) {
    Write ( *((byte *) Ptr + I) );
    if (GetAck()) {
      Inhr4_SetDir((bool)OUTPUT);
      Inhr4_ClrVal();              /* CLOCK LOW PULSE */
      InternalStop();
      return ERR_BUSY;
    }
    else {
      Inhr4_SetDir((bool)OUTPUT);
      Inhr4_ClrVal();              /* CLOCK LOW PULSE */
      Delay();
    }
    ++(*Snt);
  }
  return ERR_OK;
}

/*
** ===================================================================
**     Method      :  EI2C2_RecvBlock (component SW_I2C)
**
**     Description :
**         When working as a MASTER, this method writes 7 bits of slave
**         address plus R/W bit = 1 to the I2C bus and then reads the
**         block of characters from the bus. The slave address must be
**         specified before by the "SelectSlave" method or in bean
**         initialization section of <Slave address init> property.
**         When working as a SLAVE, this method reads the block of
**         characters from the bus.
**     Parameters  :
**         NAME            - DESCRIPTION
**       * Ptr             - A pointer to the block space for received
**                           data
**         Siz             - The size of the block
**       * Rcv             - A pointer to the number of actually
**                           received data
**     Returns     :
**         ---             - Error code, possible codes:
**                           ERR_OK - OK
**                           ERR_SPEED - This device does not work in
**                           the active speed mode
**                           ERR_BUSY - The slave device is busy, it
**                           does not respond by the acknowledgement
**                           (MASTER mode only)
**                           ERR_DISABLED - Device is disabled
**                           ERR_BUSOFF - Clock timeout elapsed (SLAVE
**                           mode only)
** ===================================================================
*/
byte EI2C2_RecvBlock(void* Ptr,word Siz,word *Rcv)
{
  register word I;
  bool Acknowledge;
  word Trial;

  *Rcv = 0;
  if (!EnUser) {
    return ERR_DISABLED;
  }
  Trial = TRIALS;
  do {
    Inhr3_SetDir((bool)INPUT);     /* SDA HIGH - START SETUP */
    Inhr4_SetDir((bool)INPUT);     /* CLOCK HIGH PULSE */
    Delay();                       /* CLOCK HIGH PULSE + BUS FREE TIME */
    Inhr3_SetDir((bool)OUTPUT);
    Inhr3_ClrVal();                /* START CONDITION */
    Delay();                       /* START HOLD TIME */
    Inhr4_SetDir((bool)OUTPUT);
    Inhr4_ClrVal();                /* CLOCK LOW PULSE */
    Delay();
    Write((byte)(SlaveAddr + READ));
    Acknowledge = GetAck();
    --Trial;
  } while (Trial && Acknowledge);
  if (Acknowledge) {
    Inhr4_SetDir((bool)OUTPUT);
    Inhr4_ClrVal();                /* CLOCK LOW PULSE */
    InternalStop();
    return ERR_BUSY;
  }
  else {
    Inhr4_SetDir((bool)OUTPUT);
    Inhr4_ClrVal();                /* CLOCK LOW PULSE */
    Delay();
  }
  for (I = 0; I < Siz; I++) {
    *((byte *) Ptr + I) = Read();
    if (EnEvent) {
      EI2C2_OnRxChar();
    }
    if (I == (Siz - 1)) {
      SetAck((bool)NOACK);
    }
    else {
      SetAck((bool)ACK);
    }
    ++(*Rcv);
  }
  return ERR_OK;
}

/*
** ===================================================================
**     Method      :  EI2C2_SendStop (component SW_I2C)
**
**     Description :
**         When working as a MASTER, if the <Automatic stop condition>
**         property value is 'no', this method sends a valid stop
**         condition to the serial data line of the I2C bus to
**         terminate the communication on the bus after using send
**         methods. This method is enabled only if the bean is in
**         MASTER mode and <Automatic stop condition> property value is
**         'no'
**     Parameters  : None
**     Returns     :
**         ---             - Error code, possible codes:
**                           ERR_OK - OK
**                           ERR_SPEED - This device does not work in
**                           the active speed mode
**                           ERR_DISABLED - Device is disabled
** ===================================================================
*/
byte EI2C2_SendStop(void)
{
  if (!EnUser) {
    return ERR_DISABLED;
  }
  Inhr3_SetDir((bool)OUTPUT);
  Inhr3_ClrVal();                  /* STOP SETUP */
  Inhr4_SetDir((bool)INPUT);       /* HIGH CLOCK PULSE + STOP SETUP TIME */
  Delay();
  Inhr3_SetDir((bool)INPUT);       /* STOP CONDITION */
  return ERR_OK;
}

/*
** ===================================================================
**     Method      :  EI2C2_SelectSlave (component SW_I2C)
**
**     Description :
**         When working as a MASTER, this method selects a new slave
**         for communication by its slave address value. Any send or
**         receive method are directed to or from the selected device,
**         until a new slave device is selected by this method. If the
**         selected slave uses 10-bit slave addressing, as the
**         parameter 7 bits must be passed, which involves 10-bit
**         addressing (11110XX), including two MSBs of slave address
**         (XX). The second byte of the 10-bit slave address must be
**         sent to the slave as a general character of send methods.
**         This method is available only if the bean is in MASTER mode.
**     Parameters  :
**         NAME            - DESCRIPTION
**         Slv             - Slave address value
**     Returns     :
**         ---             - Error code, possible codes:
**                           ERR_OK - OK
**                           ERR_SPEED - This device does not work in
**                           the active speed mode
**                           ERR_DISABLED -  Device is disabled
** ===================================================================
*/
byte EI2C2_SelectSlave(byte Slv)
{
  if (!EnUser) {
    return ERR_DISABLED;
  }
  SlaveAddr = (byte)(Slv << 1);
  return ERR_OK;
}

/*
** ===================================================================
**     Method      :  EI2C2_GetSelected (component SW_I2C)
**
**     Description :
**         When working as a MASTER, this method returns the
**         identification address value of the slave, which is
**         currently selected for communication with the master. If the
**         current slave uses 10-bit slave addressing, the method
**         returns the first 7 bits only, which involves 10-bit
**         addressing (11110XX), including two MSBs of the slave
**         address (XX). This method is not able to return the rest
**         value of 10-bit slave address. This method is available only
**         if the bean is in MASTER mode.
**     Parameters  :
**         NAME            - DESCRIPTION
**       * Slv             - A pointer to the current selected slave
**                           address value
**     Returns     :
**         ---             - Error code, possible codes:
**                           ERR_OK - OK
**                           ERR_SPEED - This device does not work in
**                           the active speed mode
** ===================================================================
*/
byte EI2C2_GetSelected(byte *Slv)
{
  *Slv = (byte)(SlaveAddr >> 1);
  return ERR_OK;
}


/* END EI2C2. */

/*
** ###################################################################
**
**     This file was created by Processor Expert 3.07 [04.34]
**     for the Freescale HCS08 series of microcontrollers.
**
** ###################################################################
*/
