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

Subversion Repositories plasma

[/] [plasma/] [trunk/] [tools/] [etermip.c] - Diff between revs 352 and 386

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 352 Rev 386
Line 14... Line 14...
#include <windows.h>
#include <windows.h>
#include <stdio.h>
#include <stdio.h>
#include <conio.h>
#include <conio.h>
 
 
//#define SIMULATE_PLASMA
//#define SIMULATE_PLASMA
 
//#define USE_WPCAP
 
#ifdef SIMULATE_PLASMA
 
#define USE_WPCAP
 
#endif
 
 
 
#ifdef USE_WPCAP
#if 0
#if 0
   #include "pcap.h"
   #include "pcap.h"
#else
#else
   //From "pcap.h"
   //From "pcap.h"
   #define PCAP_ERRBUF_SIZE 256
   #define PCAP_ERRBUF_SIZE 256
Line 54... Line 59...
static const unsigned char ethernetAddressNull[] =    {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
static const unsigned char ethernetAddressNull[] =    {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
static const unsigned char ethernetAddressPhantom[] = {0x00, 0x10, 0xdd, 0xce, 0x15, 0xd4};
static const unsigned char ethernetAddressPhantom[] = {0x00, 0x10, 0xdd, 0xce, 0x15, 0xd4};
static const unsigned char ethernetAddressPhantom2[] = {0x00, 0x10, 0xdd, 0xce, 0x15, 0xd5};
static const unsigned char ethernetAddressPhantom2[] = {0x00, 0x10, 0xdd, 0xce, 0x15, 0xd5};
 
 
static pcap_t *adhandle;
static pcap_t *adhandle;
 
#endif //USE_WPCAP
 
 
static HANDLE serial_handle;
static HANDLE serial_handle;
static int PacketBytes, PacketLength, PacketChecksum, Checksum;
static int PacketBytes, PacketLength, PacketChecksum, Checksum;
static int ChecksumOk, ChecksumError;
static int ChecksumOk, ChecksumError;
static unsigned char PacketData[2000];
static unsigned char PacketData[2000];
static int EthernetActive;
static int EthernetActive;
Line 71... Line 78...
   extern void ConsoleInit(void);
   extern void ConsoleInit(void);
   static void *ethFrame;
   static void *ethFrame;
#endif
#endif
 
 
 
 
 
#ifdef USE_WPCAP
int WinPcapInit(void)
int WinPcapInit(void)
{
{
        pcap_if_t *alldevs;
        pcap_if_t *alldevs;
        pcap_if_t *d;
        pcap_if_t *d;
        int inum;
        int inum;
Line 163... Line 171...
void EthernetSendPacket(const unsigned char *packet, int length)
void EthernetSendPacket(const unsigned char *packet, int length)
{
{
   if(EthernetActive == 0)
   if(EthernetActive == 0)
      WinPcapInit();
      WinPcapInit();
   EthernetActive = 1;
   EthernetActive = 1;
 
   //if((rand() % 8) == 0) return;
   pcap_sendpacket(adhandle, packet, length);
   pcap_sendpacket(adhandle, packet, length);
}
}
 
 
 
 
/* Callback function invoked by libpcap for every incoming packet */
/* Callback function invoked by libpcap for every incoming packet */
Line 214... Line 223...
   if(rc)
   if(rc)
      ethFrame = NULL;
      ethFrame = NULL;
#endif
#endif
}
}
 
 
/**************************************************************/
 
 
 
long SerialOpen(char *name, long baud)
 
{
 
   DCB dcb;
 
   COMMTIMEOUTS comm_timeouts;
 
   BOOL rc;
 
   serial_handle = CreateFile(name, GENERIC_READ|GENERIC_WRITE,
 
      0, NULL, OPEN_EXISTING, 0, NULL);
 
   if(serial_handle == INVALID_HANDLE_VALUE)
 
      printf("Serial Port In Use!\n");
 
   rc = SetupComm(serial_handle, 16000, 16000);
 
   if(rc == FALSE)
 
      printf("Serial port already in use!!!\n");
 
   rc = GetCommState(serial_handle, &dcb);
 
   if(rc == FALSE)
 
      printf("ERROR2\n");
 
   dcb.BaudRate = baud;
 
   dcb.fBinary = 1;
 
   dcb.ByteSize = 8;
 
   dcb.fAbortOnError = 0;
 
   dcb.StopBits = 0; //ONESTOPBIT;
 
   dcb.fOutX = 0;
 
   dcb.fInX = 0;
 
   dcb.fNull = 0;
 
   dcb.Parity = 0;
 
   dcb.fOutxCtsFlow = 0;
 
   dcb.fOutxDsrFlow = 0;
 
   dcb.fOutX = 0;
 
   dcb.fInX = 0;
 
   dcb.fRtsControl = 0;
 
   rc = SetCommState(serial_handle, &dcb);
 
   if(rc == FALSE)
 
      printf("ERROR3\n");
 
   rc = GetCommTimeouts(serial_handle, &comm_timeouts);
 
   if(rc == FALSE)
 
      printf("ERROR4\n");
 
   comm_timeouts.ReadIntervalTimeout = MAXDWORD;  //non-blocking read
 
   comm_timeouts.ReadTotalTimeoutMultiplier = 0;
 
   comm_timeouts.ReadTotalTimeoutConstant = 0;
 
   comm_timeouts.WriteTotalTimeoutMultiplier = 0;  //blocking write
 
   comm_timeouts.WriteTotalTimeoutConstant = 0;
 
   rc = SetCommTimeouts(serial_handle, &comm_timeouts);
 
   if(rc == FALSE)
 
      printf("ERROR5\n");
 
   return(0);
 
}
 
 
 
 
 
static void UartPacketRead(int value)
static void UartPacketRead(int value)
{
{
   if(PacketBytes == 0 && value == 0xff)
   if(PacketBytes == 0 && value == 0xff)
   {
   {
Line 312... Line 273...
         }
         }
         PacketBytes = 0;
         PacketBytes = 0;
      }
      }
   }
   }
}
}
 
#endif //USE_WPCAP
 
 
 
/**************************************************************/
 
 
 
long SerialOpen(char *name, long baud)
 
{
 
   DCB dcb;
 
   COMMTIMEOUTS comm_timeouts;
 
   BOOL rc;
 
   serial_handle = CreateFile(name, GENERIC_READ|GENERIC_WRITE,
 
      0, NULL, OPEN_EXISTING, 0, NULL);
 
   if(serial_handle == INVALID_HANDLE_VALUE)
 
      printf("Serial Port In Use!\n");
 
   rc = SetupComm(serial_handle, 16000, 16000);
 
   if(rc == FALSE)
 
      printf("Serial port already in use!!!\n");
 
   rc = GetCommState(serial_handle, &dcb);
 
   if(rc == FALSE)
 
      printf("ERROR2\n");
 
   dcb.BaudRate = baud;
 
   dcb.fBinary = 1;
 
   dcb.fParity = 0;
 
   dcb.ByteSize = 8;
 
   dcb.StopBits = 0; //ONESTOPBIT;
 
   dcb.fOutX = 0;
 
   dcb.fInX = 0;
 
   dcb.fNull = 0;
 
   dcb.Parity = 0;
 
   dcb.fOutxCtsFlow = 0;
 
   dcb.fOutxDsrFlow = 0;
 
   dcb.fOutX = 0;
 
   dcb.fInX = 0;
 
   dcb.fRtsControl = 0;
 
   dcb.fDsrSensitivity = 0;
 
   rc = SetCommState(serial_handle, &dcb);
 
   if(rc == FALSE)
 
      printf("ERROR3\n");
 
   rc = GetCommTimeouts(serial_handle, &comm_timeouts);
 
   if(rc == FALSE)
 
      printf("ERROR4\n");
 
   comm_timeouts.ReadIntervalTimeout = MAXDWORD;  //non-blocking read
 
   comm_timeouts.ReadTotalTimeoutMultiplier = 0;
 
   comm_timeouts.ReadTotalTimeoutConstant = 0;
 
   comm_timeouts.WriteTotalTimeoutMultiplier = 0;  //blocking write
 
   comm_timeouts.WriteTotalTimeoutConstant = 0;
 
   rc = SetCommTimeouts(serial_handle, &comm_timeouts);
 
   if(rc == FALSE)
 
      printf("ERROR5\n");
 
   return(0);
 
}
 
 
 
 
long SerialRead(unsigned char *data, unsigned long length)
long SerialRead(unsigned char *data, unsigned long length)
{
{
   DWORD count, bytes;
   DWORD count, bytes;
Line 325... Line 336...
   for(;;)
   for(;;)
   {
   {
      ReadFile(serial_handle, buf, 1, &bytes, NULL);
      ReadFile(serial_handle, buf, 1, &bytes, NULL);
      if(bytes == 0)
      if(bytes == 0)
         break;
         break;
 
#ifdef USE_WPCAP
      if(buf[0] == 0xff || PacketBytes)
      if(buf[0] == 0xff || PacketBytes)
         UartPacketRead(buf[0]);
         UartPacketRead(buf[0]);
      else
      else
 
#endif
         data[count++] = buf[0];
         data[count++] = buf[0];
      if(count >= length)
      if(count >= length)
         break;
         break;
   }
   }
   return count;
   return count;
}
}
 
 
 
 
//****************************************************
//****************************************************
 
 
#define BUF_SIZE 1024*1024
#define BUF_SIZE 1024*1024
void SendFile(void)
void SendFile(void)
{
{
Line 407... Line 419...
            break;
            break;
         buf[length] = 0;
         buf[length] = 0;
         printf("%s", buf);
         printf("%s", buf);
      }
      }
 
 
 
#ifdef USE_WPCAP
      // Read Ethernet
      // Read Ethernet
      while(EthernetActive)
      while(EthernetActive)
      {
      {
         struct pcap_pkthdr header;
         struct pcap_pkthdr header;
         const u_char *pkt_data;
         const u_char *pkt_data;
Line 418... Line 431...
         if(pkt_data == NULL)
         if(pkt_data == NULL)
            break;
            break;
         if(EthernetActive)
         if(EthernetActive)
            packet_handler(NULL, &header, pkt_data);
            packet_handler(NULL, &header, pkt_data);
      }
      }
 
#endif
      Sleep(10);
      Sleep(10);
      ticks = GetTickCount();
      ticks = GetTickCount();
      if(ticks - ticksLast > 1000)
      if(ticks - ticksLast > 1000)
      {
      {
#ifdef SIMULATE_PLASMA
#ifdef SIMULATE_PLASMA

powered by: WebSVN 2.1.0

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