OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.0/] [gdb/] [rdi-share/] [tx.c] - Diff between revs 106 and 107

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 106 Rev 107
/*
/*
 * Copyright (C) 1995 Advanced RISC Machines Limited. All rights reserved.
 * Copyright (C) 1995 Advanced RISC Machines Limited. All rights reserved.
 *
 *
 * This software may be freely used, copied, modified, and distributed
 * This software may be freely used, copied, modified, and distributed
 * provided that the above copyright notice is preserved in all copies of the
 * provided that the above copyright notice is preserved in all copies of the
 * software.
 * software.
 */
 */
 
 
/*-*-C-*-
/*-*-C-*-
 *
 *
 * $Revision: 1.1.1.1 $
 * $Revision: 1.1.1.1 $
 *     $Date: 2001-05-18 11:16:46 $
 *     $Date: 2001-05-18 11:16:46 $
 *
 *
 *   Project: ANGEL
 *   Project: ANGEL
 *
 *
 *     Title: Character based packet transmission engine
 *     Title: Character based packet transmission engine
 */
 */
 
 
#include <stdarg.h>    /* ANSI varargs support */
#include <stdarg.h>    /* ANSI varargs support */
#include "angel.h"     /* Angel system definitions */
#include "angel.h"     /* Angel system definitions */
#include "angel_endian.h"    /* Endian independant memory access macros */
#include "angel_endian.h"    /* Endian independant memory access macros */
#include "crc.h"       /* crc generation definitions and headers */
#include "crc.h"       /* crc generation definitions and headers */
#include "rxtx.h"
#include "rxtx.h"
#include "channels.h"
#include "channels.h"
#include "buffers.h"
#include "buffers.h"
#include "logging.h"
#include "logging.h"
 
 
/* definitions to describe the engines state */
/* definitions to describe the engines state */
#define N_STX           0x0  /* first 2 bits for N_ */
#define N_STX           0x0  /* first 2 bits for N_ */
#define N_BODY          0x1
#define N_BODY          0x1
#define N_ETX           0x2
#define N_ETX           0x2
#define N_IDLE          0x3
#define N_IDLE          0x3
#define N_MASK          0x3 /* mask for the Encapsulator state */
#define N_MASK          0x3 /* mask for the Encapsulator state */
 
 
#define E_PLAIN         (0x0 << 2) /* 3rd bit for E_ */
#define E_PLAIN         (0x0 << 2) /* 3rd bit for E_ */
#define E_ESC           (0x1 << 2) /* 3rd bit for E_ */
#define E_ESC           (0x1 << 2) /* 3rd bit for E_ */
#define E_MASK          (0x1 << 2) /* mask for the Escaper state */
#define E_MASK          (0x1 << 2) /* mask for the Escaper state */
 
 
#define F_HEAD          (0x0 << 3) /* 4th and 5th bits for F_ */
#define F_HEAD          (0x0 << 3) /* 4th and 5th bits for F_ */
#define F_DATA          (0x1 << 3) 
#define F_DATA          (0x1 << 3) 
#define F_CRC           (0x1 << 4)
#define F_CRC           (0x1 << 4)
#define F_MASK          (0x3 << 3) /* mask for the Escaper state */
#define F_MASK          (0x3 << 3) /* mask for the Escaper state */
 
 
static unsigned char escape(unsigned char ch_in, struct te_state *txstate);
static unsigned char escape(unsigned char ch_in, struct te_state *txstate);
 
 
void Angel_TxEngineInit(const struct re_config *txconfig,
void Angel_TxEngineInit(const struct re_config *txconfig,
                        const struct data_packet *packet,
                        const struct data_packet *packet,
                        struct te_state *txstate){
                        struct te_state *txstate){
  IGNORE(packet);
  IGNORE(packet);
  txstate->tx_state = N_STX | E_PLAIN | F_HEAD;
  txstate->tx_state = N_STX | E_PLAIN | F_HEAD;
  txstate->field_c = 0;
  txstate->field_c = 0;
  txstate->encoded = 0;
  txstate->encoded = 0;
  txstate->config = txconfig;
  txstate->config = txconfig;
  txstate->crc = 0;
  txstate->crc = 0;
}
}
 
 
te_status Angel_TxEngine(const struct data_packet *packet,
te_status Angel_TxEngine(const struct data_packet *packet,
                         struct te_state *txstate,
                         struct te_state *txstate,
                         unsigned char *tx_ch){
                         unsigned char *tx_ch){
  /* TODO: gaurd on long/bad packets */
  /* TODO: gaurd on long/bad packets */
  /*
  /*
   * encapsulate the packet, framing has been moved from a seperate
   * encapsulate the packet, framing has been moved from a seperate
   * function into the encapsulation routine as it needed too much
   * function into the encapsulation routine as it needed too much
   * inherited state for it to be sensibly located elsewhere
   * inherited state for it to be sensibly located elsewhere
   */
   */
  switch ((txstate->tx_state) & N_MASK){
  switch ((txstate->tx_state) & N_MASK){
  case N_STX:
  case N_STX:
#ifdef DO_TRACE
#ifdef DO_TRACE
    __rt_trace("txe-stx ");
    __rt_trace("txe-stx ");
#endif
#endif
    txstate->tx_state = (txstate->tx_state & ~N_MASK) | N_BODY;
    txstate->tx_state = (txstate->tx_state & ~N_MASK) | N_BODY;
    *tx_ch = txstate->config->stx;
    *tx_ch = txstate->config->stx;
    txstate->field_c = 3; /* set up for the header */
    txstate->field_c = 3; /* set up for the header */
    txstate->crc = startCRC32; /* set up basic crc */
    txstate->crc = startCRC32; /* set up basic crc */
    return TS_IN_PKT;
    return TS_IN_PKT;
  case N_BODY:{
  case N_BODY:{
    switch (txstate->tx_state & F_MASK) {
    switch (txstate->tx_state & F_MASK) {
    case F_HEAD:
    case F_HEAD:
#ifdef DO_TRACE
#ifdef DO_TRACE
    __rt_trace("txe-head ");
    __rt_trace("txe-head ");
#endif
#endif
      if (txstate->field_c == 3) {
      if (txstate->field_c == 3) {
        /* send type */
        /* send type */
        *tx_ch = escape(packet->type, txstate);
        *tx_ch = escape(packet->type, txstate);
        return TS_IN_PKT;
        return TS_IN_PKT;
      }
      }
      else {
      else {
        *tx_ch = escape((packet->len >> (txstate->field_c - 1) * 8) & 0xff,
        *tx_ch = escape((packet->len >> (txstate->field_c - 1) * 8) & 0xff,
                      txstate);
                      txstate);
          if (txstate->field_c == 0) {
          if (txstate->field_c == 0) {
            /* move on to the next state */
            /* move on to the next state */
            txstate->tx_state = (txstate->tx_state & ~F_MASK) | F_DATA;
            txstate->tx_state = (txstate->tx_state & ~F_MASK) | F_DATA;
            txstate->field_c = packet->len;
            txstate->field_c = packet->len;
          }
          }
        return TS_IN_PKT;
        return TS_IN_PKT;
      }
      }
    case F_DATA:
    case F_DATA:
#ifdef DO_TRACE
#ifdef DO_TRACE
    __rt_trace("txe-data ");
    __rt_trace("txe-data ");
#endif
#endif
      *tx_ch = escape(packet->data[packet->len - txstate->field_c], txstate);
      *tx_ch = escape(packet->data[packet->len - txstate->field_c], txstate);
      if (txstate->field_c == 0) {
      if (txstate->field_c == 0) {
        /* move on to the next state */
        /* move on to the next state */
        txstate->tx_state = (txstate->tx_state & ~F_MASK) | F_CRC;
        txstate->tx_state = (txstate->tx_state & ~F_MASK) | F_CRC;
        txstate->field_c = 4;
        txstate->field_c = 4;
      }
      }
      return TS_IN_PKT;
      return TS_IN_PKT;
    case F_CRC:
    case F_CRC:
#ifdef DO_TRACE
#ifdef DO_TRACE
    __rt_trace("txe-crc ");
    __rt_trace("txe-crc ");
#endif
#endif
     *tx_ch = escape((txstate->crc >> ((txstate->field_c - 1) * 8)) & 0xff,
     *tx_ch = escape((txstate->crc >> ((txstate->field_c - 1) * 8)) & 0xff,
                      txstate);
                      txstate);
 
 
      if (txstate->field_c == 0) {
      if (txstate->field_c == 0) {
#ifdef DO_TRACE
#ifdef DO_TRACE
        __rt_trace("txe crc = 0x%x\n", txstate->crc);
        __rt_trace("txe crc = 0x%x\n", txstate->crc);
#endif
#endif
        /* move on to the next state */
        /* move on to the next state */
        txstate->tx_state = (txstate->tx_state & ~N_MASK) | N_ETX;
        txstate->tx_state = (txstate->tx_state & ~N_MASK) | N_ETX;
      }
      }
      return TS_IN_PKT;
      return TS_IN_PKT;
    }
    }
  }
  }
  case N_ETX:
  case N_ETX:
#ifdef DO_TRACE
#ifdef DO_TRACE
    __rt_trace("txe-etx\n");
    __rt_trace("txe-etx\n");
#endif
#endif
    txstate->tx_state = (txstate->tx_state & ~N_MASK) | N_IDLE;
    txstate->tx_state = (txstate->tx_state & ~N_MASK) | N_IDLE;
    *tx_ch = txstate->config->etx;
    *tx_ch = txstate->config->etx;
    return TS_DONE_PKT;
    return TS_DONE_PKT;
  default:
  default:
#ifdef DEBUG
#ifdef DEBUG
    __rt_info("tx default\n");
    __rt_info("tx default\n");
#endif
#endif
    txstate->tx_state = (txstate->tx_state & ~N_MASK) | N_IDLE;
    txstate->tx_state = (txstate->tx_state & ~N_MASK) | N_IDLE;
    return TS_IDLE;
    return TS_IDLE;
  }
  }
  /* stop a silly -Wall warning */
  /* stop a silly -Wall warning */
  return (te_status)-1;
  return (te_status)-1;
}
}
 
 
/*
/*
 * crc generation occurs in the escape function because it is the only
 * crc generation occurs in the escape function because it is the only
 * place where we know that we're putting a real char into the buffer
 * place where we know that we're putting a real char into the buffer
 * rather than an escaped one.
 * rather than an escaped one.
 * We must be careful here not to update the crc when we're sending it
 * We must be careful here not to update the crc when we're sending it
 */
 */
static unsigned char escape(unsigned char ch_in, struct te_state *txstate) {
static unsigned char escape(unsigned char ch_in, struct te_state *txstate) {
   if (((txstate->tx_state) & E_MASK) == E_ESC) {
   if (((txstate->tx_state) & E_MASK) == E_ESC) {
      /* char has been escaped so send the real char */
      /* char has been escaped so send the real char */
#ifdef DO_TRACE
#ifdef DO_TRACE
     __rt_trace("txe-echar ");
     __rt_trace("txe-echar ");
#endif
#endif
      txstate->tx_state = (txstate->tx_state & ~E_MASK) | E_PLAIN;
      txstate->tx_state = (txstate->tx_state & ~E_MASK) | E_PLAIN;
      txstate->field_c--;
      txstate->field_c--;
      if ((txstate->tx_state & F_MASK) != F_CRC)
      if ((txstate->tx_state & F_MASK) != F_CRC)
        txstate->crc = crc32( &ch_in, 1, txstate->crc);
        txstate->crc = crc32( &ch_in, 1, txstate->crc);
      return ch_in | serial_ESCAPE;
      return ch_in | serial_ESCAPE;
   }
   }
   if ((ch_in < 32) && ((txstate->config->esc_set & (1 << ch_in)) != 0)) {
   if ((ch_in < 32) && ((txstate->config->esc_set & (1 << ch_in)) != 0)) {
     /* char needs escaping */
     /* char needs escaping */
#ifdef DO_TRACE
#ifdef DO_TRACE
     __rt_trace("txe-esc ");
     __rt_trace("txe-esc ");
#endif
#endif
     txstate->tx_state = (txstate->tx_state & ~E_MASK) | E_ESC;
     txstate->tx_state = (txstate->tx_state & ~E_MASK) | E_ESC;
     return txstate->config->esc;
     return txstate->config->esc;
   }
   }
   /* must be a char that can be sent plain */
   /* must be a char that can be sent plain */
   txstate->field_c--;
   txstate->field_c--;
   if ((txstate->tx_state & F_MASK) != F_CRC)
   if ((txstate->tx_state & F_MASK) != F_CRC)
     txstate->crc = crc32(&ch_in, 1, txstate->crc);
     txstate->crc = crc32(&ch_in, 1, txstate->crc);
   return ch_in;
   return ch_in;
}
}
 
 
/* EOF tx.c */
/* EOF tx.c */
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.