コード例 #1
0
ファイル: debug.c プロジェクト: 32bitmicro/newlib-nano-1.0
/*
 * Scan for the sequence $<data>#<checksum>
 */
void
getpacket(unsigned char *buffer)
{
  unsigned char checksum;
  unsigned char xmitcsum;
  int i;
  int count;
  unsigned char ch;

  do {
    /* wait around for the start character, ignore all other characters */
    while ((ch = (inbyte() & 0x7f)) != '$') ;
    
    checksum = 0;
    xmitcsum = -1;
    
    count = 0;
    
    /* now, read until a # or end of buffer is found */
    while (count < BUFMAX) {
      ch = inbyte() & 0x7f;
      if (ch == '#')
	break;
      checksum = checksum + ch;
      buffer[count] = ch;
      count = count + 1;
    }
    
    if (count >= BUFMAX)
      continue;
    
    buffer[count] = 0;
    
    if (ch == '#') {
      xmitcsum = hex2digit(inbyte() & 0x7f) << 4;
      xmitcsum |= hex2digit(inbyte() & 0x7f);
#if 1
      /* Humans shouldn't have to figure out checksums to type to it. */
      outbyte ('+');
      return;
#endif
      if (checksum != xmitcsum)
	outbyte('-');	/* failed checksum */
      else {
	outbyte('+'); /* successful transfer */
	/* if a sequence char is present, reply the sequence ID */
	if (buffer[2] == ':') {
	  outbyte(buffer[0]);
	  outbyte(buffer[1]);
	  /* remove sequence chars from buffer */
	  count = strlen(buffer);
	  for (i=3; i <= count; i++)
	    buffer[i-3] = buffer[i];
	}
      }
    }
  }
  while (checksum != xmitcsum);
}
コード例 #2
0
rtems_device_driver console_read(
  rtems_device_major_number major,
  rtems_device_minor_number minor,
  void                    * arg
)
{
  rtems_libio_rw_args_t *rw_args;
  char *buffer;
  int maximum;
  int count = 0;

  rw_args = (rtems_libio_rw_args_t *) arg;

  buffer = rw_args->buffer;
  maximum = rw_args->count;

  for (count = 0; count < maximum; count++) {
    buffer[ count ] = inbyte();
    if (buffer[ count ] == '\n' || buffer[ count ] == '\r') {
      buffer[ count++ ]  = '\n';
      break;
    }
  }

  rw_args->bytes_moved = count;
  return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED;
}
コード例 #3
0
ファイル: projector_app.c プロジェクト: joshalbrecht/ember
/*******************************************
 * Main Menu 
 * *****************************************/
void projector_app_run_loop()
{
   
   char choice;

   while (1)
   {
       xil_printf("Codexica Projector Test Menu\n\r");
       xil_printf("1: Laser Driver Menu\n\r"        );
       xil_printf("2: Fraunhofer MEMS Menu\n\r"     );


     choice = inbyte();

     switch (choice)
     {
         case '1':
                  break;
         case '2':
                  break;
         default:
                  break;

     }
   }
}
コード例 #4
0
ファイル: read.c プロジェクト: a-padole/embeddedsw
__attribute__((weak)) s32
_read (s32 fd, char8* buf, s32 nbytes)
{
#ifdef STDIN_BASEADDRESS
  s32 i;
  s32 numbytes = 0;
  char8* LocalBuf = buf;

  (void)fd;
  if(LocalBuf != NULL) {
	for (i = 0; i < nbytes; i++) {
		numbytes++;
		*(LocalBuf + i) = inbyte();
		if ((*(LocalBuf + i) == '\n' )|| (*(LocalBuf + i) == '\r')) {
			break;
		}
	}
  }

  return numbytes;
#else
  (void)fd;
  (void)buf;
  (void)nbytes;
  return 0;
#endif
}
コード例 #5
0
ファイル: debug.c プロジェクト: 32bitmicro/newlib-nano-1.0
/*
 * Send the packet in buffer.
 */
void
putpacket(unsigned char *buffer)
{
  unsigned char checksum;
  int count;
  unsigned char ch;

  /*  $<packet info>#<checksum>. */
  do {
    outbyte('$');
    checksum = 0;
    count = 0;
    
    while (ch = buffer[count]) {
      if (! outbyte(ch))
	return;
      checksum += ch;
      count += 1;
    }
    
    outbyte('#');
    outbyte(digit2hex(checksum >> 4));
    outbyte(digit2hex(checksum & 0xf));
    
  }
  while ((inbyte() & 0x7f) != '+');
}
コード例 #6
0
ファイル: csys68k.c プロジェクト: kyos1704/reports
int read(int fd, char *buf, int nbytes)
{
  char c;
  int  i;

  for (i = 0; i < nbytes; i++) {
    c = inbyte();

    if (c == '\r' || c == '\n'){ /* CR -> CRLF */
      outbyte('\r');
      outbyte('\n');
      *(buf + i) = '\n';

    } else if (c == '\x8'){      /* backspace */
      if (i > 0){
	outbyte('\x8'); /* bs  */
	outbyte(' ');   /* spc */
	outbyte('\x8'); /* bs  */
	i--;
      }
      i--;
      continue;

    } else {
      outbyte(c);
      *(buf + i) = c;
    }

    if (*(buf + i) == '\n'){
      return (i + 1);
    }
  }
  return (i);
}
コード例 #7
0
ファイル: helloworld_io.c プロジェクト: JoeyBytes/PPM
void rx_interrupt(void* hi){
	u8 data = inbyte();

	if( ((~MP_DATA) & 0x40000000) && ((~IO_DATA) & 0x80000000) ) { //Send only when both MP_ACK and IO_VALID are low
		send_to_mp(0,data);
	}
}
コード例 #8
0
ファイル: read.c プロジェクト: curtisembedded/embeddedsw
__attribute__((weak)) s32
_read (s32 fd, char8* buf, s32 nbytes)
{
#ifdef STDIN_BASEADDRESS
  s32 i;
  char8* LocalBuf = buf;

  (void)fd;
  for (i = 0; i < nbytes; i++) {
	if(LocalBuf != NULL) {
		LocalBuf += i;
	}
	if(LocalBuf != NULL) {
	    *LocalBuf = inbyte();
	    if ((*LocalBuf == '\n' )|| (*LocalBuf == '\r')) {
	        break;
		}
	}
	if(LocalBuf != NULL) {
	LocalBuf -= i;
	}
  }

  return (i + 1);
#else
  (void)fd;
  (void)buf;
  (void)nbytes;
  return 0;
#endif
}
コード例 #9
0
ファイル: x86machine.cpp プロジェクト: Logout22/Escape
void x86Machine::rebootPulseResetLine() {
	if(reqport(PORT_KB_DATA) < 0)
		throw init_error("Unable to request keyboard data-port");
	if(reqport(PORT_KB_CTRL) < 0)
		throw init_error("Unable to request keyboard-control-port");

	// wait until in-buffer empty
	while((inbyte(PORT_KB_CTRL) & 0x2) != 0)
		;
	// command 0xD1 to write the outputport
	outbyte(PORT_KB_CTRL,0xD1);
	// wait again until in-buffer empty
	while((inbyte(PORT_KB_CTRL) & 0x2) != 0)
		;
	// now set the new output-port for reset
	outbyte(PORT_KB_DATA,0xFE);
}
コード例 #10
0
ファイル: x86machine.cpp プロジェクト: Logout22/Escape
// source: NUL/NRE
void x86Machine::rebootPCI() {
	if(reqport(0xcf9) < 0) {
		printe("Unable to request port 0xcf9");
		return;
	}
	outbyte(0xcf9,(inbyte(0xcf9) & ~4) | 0x02);
    outbyte(0xcf9,0x06);
    outbyte(0xcf9,0x01);
}
コード例 #11
0
ファイル: tinysh.c プロジェクト: arcc/Pest_Control_mlib_devel
void binary_transaction()
{
	Xuint32 address = 0;
	Xuint8 access_type;
	Xuint32 data = 0;
	int write;
	int size;
	int i;

	/* access type and size */
	access_type = inbyte();
	write = access_type >> 7;
	size = access_type & 0x7F;

	/* the address */
	address |= inbyte();
	address <<= 8;
	address |= inbyte();
	address <<= 8;
	address |= inbyte();
	address <<= 8;
	address |= inbyte();

	/* if it's a write, we read the data to write */
	if(write == 1)
		for(i=0;i<size;i++)
		{
			data |= inbyte();
			data <<= 8;
			data |= inbyte();
			data <<= 8;
			data |= inbyte();
			data <<= 8;
			data |= inbyte();
			XIo_Out32(address + 4*i,data);
		}

	/* if it's a read, we send the data */
	if(write == 0)
		for(i=0;i<size;i++)
		{
			data = XIo_In32(address + 4*i);
			outbyte(data >> 24);
			outbyte(data >> 16);
			outbyte(data >>  8);
			outbyte(data >>  0);
		}
}
コード例 #12
0
ファイル: console-io.c プロジェクト: kptran/rtems
int console_inbyte_nonblocking(
    int port
)
{
    char c;

    c = inbyte();
    if (!c)
        return -1;
    return c;
}
コード例 #13
0
ファイル: lex.c プロジェクト: EtchedPixels/FUZIX
void junk(void) {
    if (alphanumeric (inbyte ()))
        while (alphanumeric (ch ()))
            gch ();
    else
        while (alphanumeric (ch ())) {
            if (ch () == 0)
                break;
            gch ();
        }
    blanks ();
}
コード例 #14
0
ファイル: log.c プロジェクト: Nils-TUD/Escape
void logc(char c) {
	if(!reqPorts) {
		/* request io-ports for qemu and bochs */
		sassert(reqport(0xe9) >= 0);
		sassert(reqport(0x3f8) >= 0);
		sassert(reqport(0x3fd) >= 0);
		reqPorts = true;
	}
	while((inbyte(0x3f8 + 5) & 0x20) == 0)
		;
	outbyte(0x3f8,c);
}
コード例 #15
0
ファイル: lex.c プロジェクト: EtchedPixels/FUZIX
/**
 * compares two string both must be zero ended, otherwise no match found
 * advances line pointer only if match found
 * it assumes that an alphanumeric (including underscore) comparison
 * is being made and guarantees that all of the token in the source line is
 * scanned in the process
 * @param lit
 * @param len
 * @return 
 */
int amatch(char *lit, int len) {
    int k;

    blanks();
    if ((k = astreq (line + lptr, lit, len)) != 0) {
        lptr = lptr + k;
        while (alphanumeric (ch ()))
            inbyte ();
        return (1);
    }
    return (0);
}
コード例 #16
0
ファイル: primary.c プロジェクト: beretta42/FUZIX
int number(int val[]) {
    int     k, minus, base;
    char    c;

    k = minus = 1;
    while (k) {
        k = 0;
        if (match("+"))
            k = 1;
        if (match("-")) {
            minus = (-minus);
            k = 1;
        }
    }
    if (!numeric(c = ch ()))
        return (0);
    if (match("0x") || match ("0X"))
        while (numeric(c = ch ()) ||
               (c >= 'a' && c <= 'f') ||
               (c >= 'A' && c <= 'F')) {
            inbyte ();
            k = k * 16 + (numeric (c) ? (c - '0') : ((c & 07) + 9));
        }
    else {
        base = (c == '0') ? 8 : 10;
        while (numeric(ch())) {
            c = inbyte ();
            k = k * base + (c - '0');
        }
    }
    if (minus < 0)
            k = (-k);
    val[0] = k;
    if(k < 0) {
        return (UINT);
    } else {
        return (CINT);
    }
}
コード例 #17
0
/*
 * read  -- read bytes from the serial port. Ignore fd, since
 *          we only have stdin.
 */
int
read (int fd, char* buf, int nbytes)
{
  int i = 0;

  for (i = 0; i < nbytes; i++) {
    *(buf + i) = inbyte();
    if ((*(buf + i) == '\n' || *(buf + i) == '\r')) 
        break;
  }
  
  return (i + 1);
}
コード例 #18
0
ファイル: lex.c プロジェクト: blakewford/BPM
junk ()
{
        if (an (inbyte ()))
                while (an (ch ()))
                        gch ();
        else
                while (an (ch ())) {
                        if (ch () == 0)
                                break;
                        gch ();
                }
        blanks ();

}
コード例 #19
0
ファイル: main.c プロジェクト: B-C/Coprocesseur-Flottant
// reads hex from uart and convert it to
// int. nibbles is the number of char to 
// read.
uint32_t readint(uint8_t nibbles)
{
    uint32_t val = 0, i;
    uint8_t c;
    for (i = 0; i < nibbles; i++) {
        val <<= 4;
        c = inbyte();
        // outbyte(c);
        if (c <= '9')
            val |= (c - '0') & 0xf;
        else
            val |= (c - 'A' + 0xa) & 0xf; 
    }

    return val;
}
コード例 #20
0
int main (void) {

	init_platform();
   
	unsigned int *reset = RESET_REG;
   
	*reset = 1;
	*reset = 0;
   
	unsigned int i  = 0;	

	unsigned int *timer_0 = TIMER_REG_0;	
	unsigned int *timer_1 = TIMER_REG_1;
	unsigned int *count_0 = COUNTER_REG_0;	
	unsigned int *count_1 = COUNTER_REG_1;
	unsigned int *packet_0 = PACKET_REG_0;	
	unsigned int *packet_1 = PACKET_REG_1;
	
	unsigned int *hash_0 = HASH_REG_0;
	unsigned int *hash_1 = HASH_REG_1;
	unsigned int *hash_2 = HASH_REG_2;
	unsigned int *hash_3 = HASH_REG_3;
	
	while(1){
		xil_printf("Press 'g' to read registers, 'r' to reset registers' value");
		char t = inbyte();
		if (t == 'g') {
			xil_printf("\nTimer 0:    %d\n", *timer_0);
			xil_printf("Timer 1:    %d\n", *timer_1);
			xil_printf("Counter 0:  %d\n", *count_0);
			xil_printf("Counter 1:  %d\n", *count_1);
			xil_printf("Packet 0:   %d\n", *packet_0);
			xil_printf("Packet 1:   %d\n", *packet_1);
			xil_printf("Hash: %x %x %x %x\n", *hash_0, *hash_1, *hash_2, *hash_3);
			xil_printf("\n\n");
		}else if (t == 'r') {
			*reset = 1;
			*reset = 0;
		}		
	}

	cleanup_platform();
	return 0;

}
コード例 #21
0
ファイル: function.c プロジェクト: EtchedPixels/FUZIX
void doLocalAnsiArgument(int type) {
    char symbol_name[NAMESIZE];
    int identity, address, argptr, ptr;

    if (match("*")) {
        identity = POINTER;
    } else {
        if (type == STRUCT) {
            error("cannot pass struct");
            return;
        }
        identity = VARIABLE;
        if (type == VOID)
            return;
    }
    if (symname(symbol_name)) {
        if (find_locale(symbol_name) > -1) {
            multidef(symbol_name);
        } else {
            argptr = add_local (symbol_name, identity, type, 0, AUTO);
            argstk = argstk + INTSIZE;
            ptr = local_table_index;
            while (ptr != NUMBER_OF_GLOBALS) { // modify stack offset as we push more params
                ptr = ptr - 1;
                address = symbol_table[ptr].offset;
                symbol_table[ptr].offset = address + INTSIZE;
                /* Struct etc FIXME */
            }
        }
    } else {
        error("illegal argument name");
        junk();
    }
    if (match("[")) {
        while (inbyte() != ']') {
            if (endst()) {
                break;
            }
        }
        identity = POINTER;
        symbol_table[argptr].identity = identity;
    }
}
コード例 #22
0
/**
 * copy from stdin to named file
 * @param filename - file to print
 * @return 1 on success, 0 on failure
 */
int mfs_copy_stdin_to_file(char *filename) {
  char buf2[512];
  int offset = 0;
  int c;
  int fdw = mfs_file_open(filename, MFS_MODE_CREATE);
  if (fdw < 0) { /* cannot open file */
    print ("Cannot open file\n");
    return 0;
  }
  while ((c = inbyte()) != EOF) {
    buf2[offset++] = c;
    if (offset == 512) {
      mfs_file_write(fdw, buf2, 512);
      offset = 0;
    }
  }
  if (offset != 512) { /* write the last buffer */
    mfs_file_write(fdw, buf2, offset);
  }
  mfs_file_close(fdw);
  return 1;
}
コード例 #23
0
ファイル: main.c プロジェクト: gabi-l/inf3995_tp2
/***************************************************************************//**
 * @brief Changes the video resolution.
 *
 * @return None.
*******************************************************************************/
static void APP_ChangeResolution (void)
{
	char *resolutions[7] = {"640x480", "800x600", "1024x768", "1280x720", "1360x768", "1600x900", "1920x1080"};
	char receivedChar    = 0;

	if(XUartPs_IsReceiveData(UART_BASEADDR))
	{
		receivedChar = inbyte();
		if((receivedChar >= 0x30) && (receivedChar <= 0x36))
		{
			SetVideoResolution(receivedChar - 0x30);
			DBG_MSG("Resolution was changed to %s \r\n", resolutions[receivedChar - 0x30]);
		}
		else
		{
			if((receivedChar != 0x0A) && (receivedChar != 0x0D))
			{
				SetVideoResolution(RESOLUTION_640x480);
				DBG_MSG("Resolution was changed to %s \r\n", resolutions[0]);
			}
		}
	}
}
コード例 #24
0
ファイル: csys68k.c プロジェクト: kyos1704/reports
int read(int fd, char *buf, int nbytes)
{
  char c;
  int  i, ch;
  ch = ch_set(fd);
  if(ch == EBADF){
    return ch;
  }
  for (i = 0;i < nbytes; i++) {
    c= inbyte(ch);

    if (c == '\r' || c == '\n'){ /* CR -> CRLF */
      outbyte(ch,'\r');
      outbyte(ch,'\n');
      *(buf + i) = '\n';

    } else if (c == '\x8' || c==127 ){      /* backspace */
      if (i > 0){
        outbyte(ch,'\x8'); /* bs  */
        outbyte(ch,' ');   /* spc */
        outbyte(ch,'\x8'); /* bs  */
        i--;
      }
      i--;
      continue;

    } else {
      outbyte(ch,c);
      *(buf + i) = c;
    }

    if (*(buf + i) == '\n'){
      return (i + 1);
    }
  }
  return (i);
}
コード例 #25
0
ファイル: function.c プロジェクト: JamesLinus/FUZIX
/**
 * declare argument types
 * called from "newfunc", this routine adds an entry in the local
 * symbol table for each named argument
 * completely rewritten version.  p.l. woods
 * @param t argument type (char, int)
 * @return 
 */
void getarg(int t) {
    int j, legalname, address, argptr;
    char n[NAMESIZE];

    FOREVER
    {
        if (argstk == 0)
            return;
        if (match("*"))
            j = POINTER;
        else
            j = VARIABLE;
        if (!(legalname = symname(n)))
            illname();
        if (match("[")) {
            while (inbyte() != ']')
                if (endst())
                    break;
            j = POINTER;
        }
        if (legalname) {
            if ((argptr = find_locale(n)) > -1) {
                symbol_table[argptr].identity = j;
                symbol_table[argptr].type = t;
                address = argtop - symbol_table[argptr].offset;
                symbol_table[argptr].offset = address;
            } else
                error("expecting argument name");
        }
        argstk = argstk - INTSIZE;
        if (endst())
            return;
        if (!match(","))
            error("expected comma");
    }
}
コード例 #26
0
ファイル: read.c プロジェクト: AlexShiLucky/freertos
int
_read (int fd, char* buf, int nbytes)
{
#ifdef STDIN_BASEADDRESS
  int i = 0;

  (void)fd;
  for (i = 0; i < nbytes; i++) {
    *(buf + i) = inbyte();
    if ((*(buf + i) == '\n' || *(buf + i) == '\r'))
    {
        i++;
        break;
    }
  }

  return (i);
#else
  (void)fd;
  (void)buf;
  (void)nbytes;
  return 0;
#endif
}
コード例 #27
0
ファイル: rlserial.cpp プロジェクト: Oaks/sdbtest
int rlSerial::writeBlock(const unsigned char *buf, int len)
{
#ifdef RLUNIX
  int ret;

  if(fd == -1) return -1;
  if(trace == 1)
  {
    printf("writeBlock:");
    for(int i=0; i<len; i++) printf(" %d",(int) buf[i]);
    printf("\n");
  }
  ret = write(fd,buf,len);
  //tcflush(fd, TCIOFLUSH);
  return ret;
#endif

#ifdef __VMS
  int  status;
  IOSB iosb;


  status = SYS$QIOW(0,vms_channel,IO$_WRITEVBLK | IO$M_CANCTRLO | IO$M_NOFORMAT,
                    &iosb,0,0,buf,len,0,0,0,0);
  if(status != SS$_NORMAL) return -1;
  return len;
#endif

#ifdef RLWIN32
  BOOL ret;
  unsigned long retlen;

  if(trace == 1)
  {
    printf("writeBlock:");
    for(int i=0; i<len; i++) printf(" %d",(int) buf[i]);
    printf("\n");
  }
  retlen = len;
  ret = WriteFile(
                  hdl,     // handle to file to write to
                  buf,     // pointer to data to write to file
                  len,     // number of bytes to write
                  &retlen, // pointer to number of bytes written
                  NULL     // pointer to structure for overlapped I/O
                 );

  if(ret) return (int) retlen;
  return -1;
#endif

#ifdef RM3
  RmBytParmStruct  PBlock;    /* Parameterstruktur fr RmIO - Funktion          */
  RmIOStatusStruct DrvSts;    /* Struktur der Rckgabewerte fr RmIO - Funktion  */
  unsigned char    cByte;     /* Rckgabewert von ibyte - Funktion              */
  int              iStatus;   /* Rckgabewert                                   */
  int              i;         /* Schleifenz�ler                                */
                              /**************************************************/

  /*
   * Schreibparameter setzen
   */
  PBlock.string = (char*)buf;
  PBlock.strlen = len;
  PBlock.buffer = 0;
  PBlock.timlen = 0;
  PBlock.status = 0;

  /******************************************************
   *                                                    *
   * Toggle mode wird emuliert indem an dieser Stelle   *
   * RTS-Signal gesetzt und sp�er wieder gel�cht wird   *
   *                                                    *
   ******************************************************/

  cByte = inbyte( com + 0x04u );
  outbyte( com + 0x04, (unsigned char)(cByte | 0x02u) );

  /*
   * Schreibvorgang einleiten
   */
  iStatus = RmIO( BYT_WRITE_WAIT, (unsigned)device, (unsigned)unit, 0u, 0u, &DrvSts, &PBlock );

  /******************************************************************
   *                                                                *
   * 8ms warten.Bei der Aenderung der Uebertragungsgeschwindigkeit, *
   * sollte dieser Wert angepasst werden. Hier fuer 9600            *
   *                                                                *
   ******************************************************************/
  RmPauseTask((RTS_TIME_WAIT*9600)/baudrate);

  /*
   * RTS-Signal l�chen
   */
  outbyte( com + 0x04, (unsigned char)(cByte & 0xFDu) );

  if( iStatus ) printf( "BYT_WRITE_WAIT (write block): Error status = %X\n", iStatus );

  if( !iStatus ) return len;
  return -1;
#endif
}
コード例 #28
0
ファイル: ivk_iic_diag.c プロジェクト: tghaefli/ADD
/*****************************************************************************
* This function creates a menu structure that allows the user the ability to 
*  read and write the IIC registers of the chips in the VSK in real-time.
*
* @param    pContext contains a pointer to the FMC-IMAGEOV instance's context.
*
* @return   Returns '0' when it exits successfully.
*
* @note     None.
*
******************************************************************************/
Xint32 ivk_iic_diag_main ( fmc_imageov_t *pModule )
{ 
  Xint32 inchar;
  Xint32 i;
  static Xint32  data=0, addr=0, device=0;
  Xuint8 xdata[2];
  Xint8 mux_data;
  Xuint8  num_bytes;

  Xuint8 camera1_addr = 0xFF; // Not a valid address. 
  Xuint8 camera2_addr = 0xFF; // Means the camera has not been checked for.

  xdata[1] = 0; xdata[0] = 0;

  ivk_iic_diag_help();

  while (1)
  {
    print(">");

    inchar = inbyte();

    if(inchar != 0x1b) { xil_printf("%c\n\r",inchar); }
    else               { print("esc\n\r"); }

    switch (inchar)
    {
      case '?' : 
      {
        ivk_iic_diag_help(); 
        break;
      }          

      case 0x1b :
      {
        xil_printf("- exit menu -\n\n\r");
        return(0);
        break;
      }

	  // scan
	  case 's' :
      {
        Xuint8 iic_mux;
        Xuint8 iic_addr;
        Xuint8 iic_data;
        Xuint8 num_bytes;

        // Scan for devices
        xil_printf( "Scanning for I2C devices on FMC-IMAGEOV module ...\n\r" );
        for ( iic_mux = FMC_IMAGEOV_I2C_MIN; iic_mux <= FMC_IMAGEOV_I2C_MAX; iic_mux++ )
        {
          xil_printf( "\tMux Select = %d\n\r", iic_mux );
          fmc_imageov_iic_mux( pModule, iic_mux );
          for ( iic_addr = 0; iic_addr < 128; iic_addr++ )
          {
            num_bytes = pModule->pIIC->fpIicRead( pModule->pIIC, iic_addr, 0, &iic_data, 1); 
            if ( num_bytes > 0 )
            {
              xil_printf( "\t\tFound device at address 0x%02X\n\r", iic_addr );
            }
          }
        }
        break;
      }

      // device 
      case '=' :
      {
        device++; 
        if(device>MAX_IIC_DEV-1){ device=MAX_IIC_DEV-1; }
        xil_printf("device[%x]:IIC(0x%x):<%s> regs\n \r", device ,iic_addr[device],iic_device[device]);
        break;
      }
        
      case '-' :
      {
        device--; 
        if(device<0) { device=0; }
        xil_printf("device[%x]:IIC(0x%x):<%s> regs,  \n \r", device ,iic_addr[device],iic_device[device]);
        break;
      }

      // addr
      case ']' :
      {
        addr++; 
        if(addr>0xff){ addr=0xff; }
        xil_printf("IIC_reg[%x][%x] = <%s>\n\r",device, addr, iic_device[device]);
        break;
      }

      case '[' :
      {
        addr--; 
        if(addr<0){ addr=0; }
        xil_printf("IIC_reg[%x][%x] = <%s>\n\r",device, addr, iic_device[device]);      
        break;
      }
      
      case '}' :
      {
        addr+=0x10; 
        if(addr>0xff){ addr=0xff; }
        xil_printf("IIC_reg[%x][%x] = <%s>\n\r",device, addr, iic_device[device]);
        break;
      }

      case '{' :
      {
        addr-=0x10; 
        if(addr<0){ addr=0; }
        xil_printf("IIC_reg[%x][%x] = <%s>\n\r",device, addr, iic_device[device]);      
        break;
      }

      // data
      case '\'' :
      {
        data++;  
        xdata[1] = (Xint8)(data & 0xFF);
        xdata[0] = (Xint8)((data>>8) & 0xFF);        
        xil_printf("data=0x%x\n\r",data);
//        xil_printf("xdata=0x%x %x\n\r",xdata[0],xdata[1]);
        break;
      }
        
      case ';' :
      {
        data--;
        xdata[1] = (Xint8)(data & 0xFF);
        xdata[0] = (Xint8)((data>>8) & 0xFF);        
        xil_printf("data=0x%x\n\r",data);
//        xil_printf("xdata=0x%x %x\n\r",xdata[0],xdata[1]);
        break;
      }

      case '\"' :
      {
        data=data+0x100;  
        xdata[1] = (Xint8)(data & 0xFF);
        xdata[0] = (Xint8)((data>>8) & 0xFF);        
        xil_printf("data=0x%x\n\r",data);
//        xil_printf("xdata=0x%x %x\n\r",xdata[0],xdata[1]);
        break;
      }

      case ':' :
      {
        data=data-0x100;
        xdata[1] = (Xint8)(data & 0xFF);
        xdata[0] = (Xint8)((data>>8) & 0xFF);        
        xil_printf("data=0x%x\n\r",data);
//        xil_printf("xdata=0x%x %x\n\r",xdata[0],xdata[1]);
        break;
      }

      // write register
      case '.' : 
      {
        num_bytes = 1;
        if(device ==IIC_DVI_OUT)
        {
          fmc_imageov_iic_mux( pModule, FMC_IMAGEOV_I2C_SELECT_TFP410 );
          num_bytes = pModule->pIIC->fpIicWrite( pModule->pIIC, iic_addr[device], 
                                                 addr, &xdata[1], 1); 
        }
        else if(device ==IIC_CLK_GEN)
        {
          fmc_imageov_iic_mux( pModule, FMC_IMAGEOV_I2C_SELECT_CDCE925 );
          num_bytes = pModule->pIIC->fpIicWrite( pModule->pIIC, iic_addr[device], 
                                                 addr, &xdata[1], 1); 
        }
        else if(device ==IIC_CAMERA_1) 
        { 
          if (camera1_addr == 0xFF || camera1_addr == 0x00)
          {
            camera1_addr = get_camera_addr( pModule, 1 );
          }
          if (camera1_addr != 0)
          {
            fmc_imageov_iic_mux( pModule, FMC_IMAGEOV_I2C_SELECT_CAMERA1 );
            num_bytes = pModule->pIIC->fpIicWrite( pModule->pIIC, iic_addr[device], 
                                                   addr, &xdata[1], 1); 
          }
          else { print("Camera #1 is not present.\r\n"); break; }        
        }
        else if(device ==IIC_CAMERA_2) 
        { 
          if (camera2_addr == 0xFF || camera2_addr == 0x00)
          {
            camera2_addr = get_camera_addr( pModule, 2 );
          }
          if (camera2_addr != 0)
          {
            fmc_imageov_iic_mux( pModule, FMC_IMAGEOV_I2C_SELECT_CAMERA2 );
            num_bytes = pModule->pIIC->fpIicWrite( pModule->pIIC, iic_addr[device], 
                                                   addr, &xdata[1], 1); 
          }
          else  { print("Camera #2 is not present.\r\n"); break; }
        }
        else if(device ==IIC_EDID_DVI_OUT)
        {
          fmc_imageov_iic_mux( pModule, FMC_IMAGEOV_I2C_SELECT_EDID );
          num_bytes = pModule->pIIC->fpIicWrite( pModule->pIIC, iic_addr[device], 
                                                 addr, &xdata[1], 1); 
        }
        
        else 
        { 
          num_bytes = pModule->pIIC->fpIicWrite( pModule->pIIC, iic_addr[device], 
                                                 addr, &xdata[1], 1); 
        }

        if (num_bytes < 1) 
        {
          xil_printf("\r\nError writing to device<%s> = %d \r\n\r\n",iic_device[device],num_bytes);
        }
        else
        {
          if (device ==IIC_CAMERA_1 || device ==IIC_CAMERA_2)
          {
            xil_printf("write IIC_reg[0x%x][0x%x]=0x%x (%d) \n\r",iic_addr[device],addr,data,data);
          }
          else
          {
            xil_printf("write IIC_reg[0x%x][0x%x]=0x%x (%d) \n\r",iic_addr[device],addr,(data&0xFF),(data&0xFF));
          }                  
        }

        break;
      }
     
      // read register
      case ',' : 
      {
        num_bytes = 1;
        if(device ==IIC_DVI_OUT)
        {
          fmc_imageov_iic_mux( pModule, FMC_IMAGEOV_I2C_SELECT_TFP410 );
          num_bytes = pModule->pIIC->fpIicRead( pModule->pIIC, iic_addr[device], 
                                                addr, &xdata[1], 1);
          data = (int)xdata[1];                                                        
        }
        else if(device ==IIC_CLK_GEN)
        {
          fmc_imageov_iic_mux( pModule, FMC_IMAGEOV_I2C_SELECT_CDCE925 );
          num_bytes = pModule->pIIC->fpIicRead( pModule->pIIC, iic_addr[device], 
                                                addr, &xdata[1], 1);
          data = (int)xdata[1];                                                        
        }
        else if(device ==IIC_CAMERA_1) 
        { 
          if (camera1_addr == 0xFF || camera1_addr == 0x00)
          {
            camera1_addr = get_camera_addr( pModule, 1 );
          }
          if (camera1_addr != 0)
          {
            fmc_imageov_iic_mux( pModule, FMC_IMAGEOV_I2C_SELECT_CAMERA1 );
            num_bytes = pModule->pIIC->fpIicRead( pModule->pIIC, iic_addr[device], 
                                                  addr, &xdata[1], 1);
            data = (int)xdata[1];
          }            
          else  { print("Camera #1 is not present.\r\n"); break; }
        }
        else if(device ==IIC_CAMERA_2) 
        { 
          if (camera2_addr == 0xFF || camera2_addr == 0x00)
          {
            camera2_addr = get_camera_addr( pModule, 2 );
          }
          if (camera2_addr != 0)
          {
            fmc_imageov_iic_mux( pModule, FMC_IMAGEOV_I2C_SELECT_CAMERA2 );
            num_bytes = pModule->pIIC->fpIicRead( pModule->pIIC, iic_addr[device], 
                                                  addr, &xdata[1], 1);
            data = (int)xdata[1];
          }            
          else  { print("Camera #2 is not present.\r\n"); break; }
        }
        else if(device ==IIC_EDID_DVI_OUT)
        {
          fmc_imageov_iic_mux( pModule, FMC_IMAGEOV_I2C_SELECT_EDID );
          num_bytes = pModule->pIIC->fpIicRead( pModule->pIIC, iic_addr[device], 
                                                addr, &xdata[1], 1);
          data = (int)xdata[1];                                                        
        }
        else 
        { 
          num_bytes = pModule->pIIC->fpIicRead( pModule->pIIC, iic_addr[device], 
                                                addr, &xdata[1], 1);
          data = (int)xdata[1]; 
        }

        if (num_bytes < 1) 
        {
          xil_printf("\r\nError reading from device<%s> = %d \r\n\r\n",iic_device[device],num_bytes);
        }
        else
        {        
          if (device ==IIC_CAMERA_1 || device ==IIC_CAMERA_2)
          {
            xil_printf("read IIC_reg[0x%x][0x%x]=0x%x (%d) \n\r",iic_addr[device],addr,data,data);
          }
          else
          {
            xil_printf("read IIC_reg[0x%x][0x%x]=0x%x (%d) \n\r",iic_addr[device],addr,(data&0xFF),(data&0xFF));
          }                  
        }
        
        break;
      }
      
      // Dump All Device Registers
      case 'd' : 
      {
        num_bytes = 1;
        xil_printf("display device memory: device[%x]=<%s>\r\n\r\n",device, 
                    iic_device[device]); 

        // Setup the FMC IIC MUX if needed
        if(device ==IIC_DVI_OUT)
        {
          fmc_imageov_iic_mux( pModule, FMC_IMAGEOV_I2C_SELECT_TFP410 );
        }
        else if(device ==IIC_CLK_GEN)
        {
          fmc_imageov_iic_mux( pModule, FMC_IMAGEOV_I2C_SELECT_CDCE925 );
        }
        else if(device ==IIC_CAMERA_1) 
        {
          if (camera1_addr == 0xFF || camera1_addr == 0x00)
          {
            camera1_addr = get_camera_addr( pModule, 1 );
          }
          if (camera1_addr != 0)
          {
            fmc_imageov_iic_mux( pModule, FMC_IMAGEOV_I2C_SELECT_CAMERA1 );
          }
          else  { print("Camera #1 is not present.\r\n"); break; }          
        }
        else if(device ==IIC_CAMERA_2) 
        {
          if (camera2_addr == 0xFF || camera2_addr == 0x00)
          {
            camera2_addr = get_camera_addr( pModule, 2 );
          }
          if (camera2_addr != 0)
          {
            fmc_imageov_iic_mux( pModule, FMC_IMAGEOV_I2C_SELECT_CAMERA2 );
          }
          else  { print("Camera #2 is not present.\r\n"); break; }          
        }
        else if(device ==IIC_EDID_DVI_OUT)
        {
          fmc_imageov_iic_mux( pModule, FMC_IMAGEOV_I2C_SELECT_EDID );
        }
        

        // Read registers 0x00 - 0xFF
        for(i=0; i<=0xFF; i++) 
        {
          addr = (Xuint8)i;
          num_bytes = pModule->pIIC->fpIicRead( pModule->pIIC, iic_addr[device], 
                                                addr, &xdata[1], 1);
          data = (int)xdata[1];
          
          if (num_bytes < 1) 
          {
            xil_printf("\r\nError reading from device<%s> \r\n\r\n",iic_device[device]);
            break;
          }
          else
          {        
            xil_printf("read IIC_reg[%x][%x]=0x%x (%d) \n\r",device,i,data,data);  
          }          
        }

        break;
      }      
    }
  }
}
コード例 #29
0
ファイル: project_multiply.c プロジェクト: HrNilsson/Xilinx
int main(void) {

	XGpio dip, push;
	XScuTimer Timer;  /* Cortex A9 SCU Private Timer Instance */
	XScuTimer_Config *ConfigPtr;
	int value, skip, psb_check, dip_check, status, timerCounter, time1, time2;
	VectorArray AInst;
	VectorArray BTinst;
	VectorArray PInst;
	
	xil_printf("-- Start of the Program --\r\n");
	xil_printf("Enter choice: 1 (SW->Leds), 2 (Timer->Leds), 3 (Matrix), 4 (Exit) \r\n");

	XGpio_Initialize(&dip, XPAR_SW_8BIT_DEVICE_ID);
	XGpio_SetDataDirection(&dip, 1, 0xffffffff);

	XGpio_Initialize(&push, XPAR_BTNS_5BIT_DEVICE_ID);
	XGpio_SetDataDirection(&push, 1, 0xffffffff);

	ConfigPtr = XScuTimer_LookupConfig (XPAR_PS7_SCUTIMER_0_DEVICE_ID);
	status = XScuTimer_CfgInitialize (&Timer, ConfigPtr, ConfigPtr->BaseAddr);

	if(status != XST_SUCCESS){
		xil_printf("Timer init() failed\r\n");
		return XST_FAILURE;
	}

	// Load timer with delay
	XScuTimer_LoadTimer(&Timer, ONE_SECOND);
	// Set AutoLoad mode
	XScuTimer_EnableAutoReload(&Timer);

	while (1) {
		xil_printf("CMD:> ");
		// Read an input value from the console.
		value = inbyte();
		skip = inbyte(); //CR
		skip = inbyte(); //LF
		switch (value) {
			case '1':
				while(!XGpio_DiscreteRead(&push, 1))
				{
					dip_check = XGpio_DiscreteRead(&dip, 1);
					LED_IP_mWriteReg(XPAR_LED_IP_S_AXI_BASEADDR, 0, dip_check);
					for (skip = 0; skip < 9999999; skip++);
				}
				break;
			case '2':

				timerCounter = 0;
				XScuTimer_Start(&Timer);

				while(!XGpio_DiscreteRead(&push, 1))
				{
					if(XScuTimer_IsExpired(&Timer))
					{
						XScuTimer_ClearInterruptStatus(&Timer);
						timerCounter = (timerCounter + 1) % 256;
						LED_IP_mWriteReg(XPAR_LED_IP_S_AXI_BASEADDR, 0, timerCounter);
					}
				}
				break;
			case '3':
				setInputMatrices(AInst, BTinst);
				displayMatrix(AInst);
				displayMatrix(BTinst);

				XScuTimer_Start(&Timer);
				// Software matrix
				time1 = XScuTimer_GetCounterValue(&Timer);
				multiMatrixSoft(AInst, BTinst, PInst);
				time2 = XScuTimer_GetCounterValue(&Timer);

				xil_printf("SW time: %d\n\n", time1-time2);
				displayMatrix(PInst);

				// Hardware matrix
				time1 = XScuTimer_GetCounterValue(&Timer);
				multiMatrixHard(AInst, BTinst, PInst);
				time2 = XScuTimer_GetCounterValue(&Timer);

				XScuTimer_Stop(&Timer);

				xil_printf("HW time: %d\n\n", time1-time2);
				displayMatrix(PInst);
				break;
			case '4':
				// Exit
				return XST_SUCCESS;
				break;
			default :
				break;
		}
	}
}
コード例 #30
0
ファイル: rlserial.cpp プロジェクト: Oaks/sdbtest
int rlSerial::openDevice(const char *devicename, int speed, int block, int rtscts, int bits, int stopbits, int parity)
{
    int y;
#ifdef RLUNIX
  struct termios buf;

  if(fd != -1) return -1;
  fd = open(devicename, O_RDWR | O_NOCTTY | O_NDELAY);
  if(fd < 0) { return -1; }

  //signal(SIGINT, sighandler);

  if(tcgetattr(fd, &save_termios) < 0) { return -1; }
  buf = save_termios;
  buf.c_cflag = speed | CLOCAL | CREAD;
  if(rtscts   == 1)  buf.c_cflag |= CRTSCTS;
  if(bits     == 7)  buf.c_cflag |= CS7;
  else               buf.c_cflag |= CS8;
  if(stopbits == 2)  buf.c_cflag |= CSTOPB;
  if(parity == rlSerial::ODD)  buf.c_cflag |= (PARENB | PARODD);
  if(parity == rlSerial::EVEN) buf.c_cflag |= PARENB;
  buf.c_lflag = IEXTEN; //ICANON;
  buf.c_oflag     = OPOST;
  buf.c_cc[VMIN]  = 1;
  buf.c_cc[VTIME] = 0;
#ifndef PVMAC
  buf.c_line      = 0;
#endif
  buf.c_iflag     = IGNBRK | IGNPAR | IXANY;
  if(tcsetattr(fd, TCSAFLUSH, &buf) < 0) { return -1; }
  //if(tcsetattr(fd, TCSANOW, &buf) < 0) { return -1; }
  ttystate = RAW;
  ttysavefd = fd;
  if(block == 1) fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) & ~O_NONBLOCK);
  tcflush(fd,TCIOFLUSH);
#endif

#ifdef __VMS
  // Please set com parameters at DCL level
  struct dsc$descriptor_s dsc;
  int status;

  dsc.dsc$w_length  = strlen(devicename);
  dsc.dsc$a_pointer = (char *) devicename;
  dsc.dsc$b_class   = DSC$K_CLASS_S;
  dsc.dsc$b_dtype   = DSC$K_DTYPE_T;
  status = SYS$ASSIGN(&dsc,&vms_channel,0,0);
  if(status != SS$_NORMAL) return -1;
#endif

#ifdef RLWIN32
  DWORD ccsize;
  COMMCONFIG cc;
  //int baudrate,ret;
  //char devname[100];

  int baudrate,ret;
  //WCHAR
  wchar_t devname[100]; //={'C','O','M','1',0};

    if(strlen(devicename) > 80) return -1;
    y=0;
    while(*(devicename+y)!=0){
        devname[y]=*(devicename+y);
        y++;
    }
    devname[y]=0;
    //printf("%s",devname);        // Aenderung: allow more than 4 COM ports


  //if(strlen(devicename) > 80) return -1;
  //sprintf(devname,"\\\\.\\%s",devicename);        // Aenderung: allow more than 4 COM ports
  hdl = CreateFile(
                   devname,                       // devicename, // pointer to name of the file
                   GENERIC_READ | GENERIC_WRITE,  // access (read-write) mode
                   0,                             // share mode
                   0,                             // pointer to security attributes
                   OPEN_EXISTING,                 // how to create
                   0,                             // not overlapped I/O
                   0                              // handle to file with attributes to copy
                  );
  if(hdl == INVALID_HANDLE_VALUE)
  {
    printf("CreateFile(%s) failed\n",devicename);
    return -1;
  }

  baudrate = CBR_9600;
  if(speed == B50     ) baudrate = 50;
  if(speed == B75     ) baudrate = 75;
  if(speed == B110    ) baudrate = CBR_110;
  if(speed == B134    ) baudrate = 134;
  if(speed == B150    ) baudrate = 150;
  if(speed == B200    ) baudrate = 200;
  if(speed == B300    ) baudrate = CBR_300;
  if(speed == B600    ) baudrate = CBR_600;
  if(speed == B1200   ) baudrate = CBR_1200;
  if(speed == B1800   ) baudrate = 1800;
  if(speed == B2400   ) baudrate = CBR_2400;
  if(speed == B4800   ) baudrate = CBR_4800;
  if(speed == B9600   ) baudrate = CBR_9600;
  if(speed == B19200  ) baudrate = CBR_19200;
  if(speed == B38400  ) baudrate = CBR_38400;
  if(speed == B57600  ) baudrate = CBR_57600;
  if(speed == B115200 ) baudrate = CBR_115200;
  if(speed == B230400 ) baudrate = 230400;
  if(speed == B460800 ) baudrate = 460800;
  if(speed == B500000 ) baudrate = 500000;
  if(speed == B576000 ) baudrate = 576000;
  if(speed == B921600 ) baudrate = 921600;
  if(speed == B1000000) baudrate = 1000000;
  if(speed == B1152000) baudrate = 1152000;
  if(speed == B1500000) baudrate = 1500000;
  if(speed == B2000000) baudrate = 2000000;
  if(speed == B2500000) baudrate = 2500000;
  if(speed == B3000000) baudrate = 3000000;
  if(speed == B3500000) baudrate = 3500000;
  if(speed == B4000000) baudrate = 4000000;

  GetCommConfig(hdl,&cc,&ccsize);
  //cc.dwSize            = sizeof(cc);  // size of structure
  //cc.wVersion          = 1;           // version of structure
  //cc.wReserved         = 0;           // reserved
  //  DCB   dcb;                      // device-control block
  cc.dcb.DCBlength     = sizeof(DCB); // sizeof(DCB)
  cc.dcb.BaudRate      = baudrate;    // current baud rate
  cc.dcb.fBinary       = 1;           // binary mode, no EOF check
  cc.dcb.fParity       = 1;           // enable parity checking
  cc.dcb.fOutxCtsFlow  = 0;           // CTS output flow control
  if(rtscts == 1) cc.dcb.fOutxCtsFlow = 1;
  cc.dcb.fOutxDsrFlow  = 0;           // DSR output flow control
  cc.dcb.fDtrControl   = DTR_CONTROL_DISABLE;  // DTR flow control type
  cc.dcb.fDsrSensitivity   = 0;       // DSR sensitivity
  cc.dcb.fTXContinueOnXoff = 1;       // XOFF continues Tx
  //cc.dcb.fOutX         = 0;           // XON/XOFF out flow control
  //cc.dcb.fInX          = 0;           // XON/XOFF in flow control
  //cc.dcb.fErrorChar    = 0;           // enable error replacement
  cc.dcb.fNull         = 0;           // enable null stripping
  cc.dcb.fRtsControl   = RTS_CONTROL_DISABLE;
  if(rtscts == 1)  cc.dcb.fRtsControl = RTS_CONTROL_HANDSHAKE;  // RTS flow control
  cc.dcb.fAbortOnError = 0;           // abort reads/writes on error
  //cc.dcb.fDummy2       = 0;           // reserved
  //cc.dcb.wReserved     = 0;           // not currently used
  //cc.dcb.XonLim        = 0;           // transmit XON threshold
  //cc.dcb.XoffLim       = 0;           // transmit XOFF threshold
  cc.dcb.ByteSize      = bits;        // number of bits/byte, 4-8
  cc.dcb.Parity        = 0;           // 0-4=no,odd,even,mark,space
  if(parity == rlSerial::ODD)    cc.dcb.Parity = 1;
  if(parity == rlSerial::EVEN)   cc.dcb.Parity = 2;
  cc.dcb.StopBits      = ONESTOPBIT;  // 0,1,2 = 1, 1.5, 2
  if(stopbits==2) cc.dcb.StopBits = TWOSTOPBITS;
  //cc.dcb.XonChar       = 0;           // Tx and Rx XON character
  //cc.dcb.XoffChar      = 0;           // Tx and Rx XOFF character
  //cc.dcb.ErrorChar     = 0;           // error replacement character
  //cc.dcb.EofChar       = 0;           // end of input character
  //cc.dcb.EvtChar       = 0;           // received event character
  //cc.dcb.wReserved1    = 0;           // reserved; do not use
  cc.dwProviderSubType = PST_RS232;   // type of provider-specific data
  //cc.dwProviderOffset  = 0;           // offset of provider-specific data
  //cc.dwProviderSize    = 0;           // size of provider-specific data
  //cc.wcProviderData[0] = 0;           // provider-specific data

  ret = SetCommConfig(hdl,&cc,sizeof(cc));
  if(ret == 0)
  {
    printf("SetCommConfig ret=%d devicename=%s LastError=%d\n",ret,devicename,(int)GetLastError());
    return -1;
  }
#endif

#ifdef RM3
  RmEntryStruct    CatEntry;        /* Struktur der Deiviceinformationen              */
  int              iStatus;         /* Rckgabewert                                    */
  RmIOStatusStruct DrvSts;          /* Struktur der Rckgabewerte fr RmIO - Funktion   */
  RmBytParmStruct  PBlock;          /* Parameterstruktur fr RmIO - Funktion           */
  static UCD_BYT_PORT Ucd_byt_drv;  /* Struktur zum Setzen der UCD - Werte            */
  ushort           uTimeBd;         /* Timing - Wert der �ertragungsgeschwindigkeit   */
  uint             uMode;           /* Portsteuerungsparameter                        */
  unsigned char    cByte;           /* Byte - Parameter                               */
                                    /* Timing = 748800 / Baudrate;                    */
                                    /**************************************************/
  char byt_com[32];
                                    
  /* COM1=0x3F8 COM2=0x2F8 - Port Adresse           */
  if     (strcmp(devicename,"COM1") == 0)
  {
    strcpy(byt_com,"BYT_COM1");
    com = 0x3f8;
  }
  else if(strcmp(devicename,"COM2") == 0)
  {
    strcpy(byt_com,"BYT_COM2");
    com = 0x2f8;
  }
  else 
  {
    printf("Error: devicename=%s unknown\n",devicename);
    return -1;
  }  
  //printf("Open COM port - inside\n");

  /*
  * Device und Unit - Id auslesen
  */
  if( RmGetEntry( RM_WAIT, byt_com, &CatEntry ) != RM_OK ) /* RM_CONTINUE */
  {
    printf( "Error: %s device not found\n", byt_com);
    return -1;
  }

  device = (int) ((ushort) CatEntry.ide);
  unit   = (int) CatEntry.id;

  /*
  * Ger� reservieren
  */
  if( RmIO( BYT_RESERVE, (unsigned)(device), (unsigned)(unit), 0u, 0u, &DrvSts, &PBlock ) < 0 )
  {
    printf( "Error: Unable to reserve %s device\n", byt_com);
    return -1;
  }

  /*
  * Baudrate ausrechnen
  */
  baudrate = 9600;
  if(speed == B50     ) baudrate = 50;
  if(speed == B75     ) baudrate = 75;
  if(speed == B110    ) baudrate = 110;
  if(speed == B134    ) baudrate = 134;
  if(speed == B150    ) baudrate = 150;
  if(speed == B200    ) baudrate = 200;
  if(speed == B300    ) baudrate = 300;
  if(speed == B600    ) baudrate = 600;
  if(speed == B1200   ) baudrate = 1200;
  if(speed == B1800   ) baudrate = 1800;
  if(speed == B2400   ) baudrate = 2400;
  if(speed == B4800   ) baudrate = 4800;
  if(speed == B9600   ) baudrate = 9600;
  if(speed == B19200  ) baudrate = 19200;
  if(speed == B38400  ) baudrate = 38400;
  if(speed == B57600  ) baudrate = 57600;
  if(speed == B115200 ) baudrate = 115200;
  if(speed == B230400 ) baudrate = 230400;
  if(speed == B460800 ) baudrate = 460800;
  if(speed == B500000 ) baudrate = 500000;
  if(speed == B576000 ) baudrate = 576000;
  if(speed == B921600 ) baudrate = 921600;
  if(speed == B1000000) baudrate = 1000000;
  if(speed == B1152000) baudrate = 1152000;
  if(speed == B1500000) baudrate = 1500000;
  if(speed == B2000000) baudrate = 2000000;
  if(speed == B2500000) baudrate = 2500000;
  if(speed == B3000000) baudrate = 3000000;
  if(speed == B3500000) baudrate = 3500000;
  if(speed == B4000000) baudrate = 4000000;
  uTimeBd = 748800 / baudrate;

  /*
  * Portsteuerungsparameter setzen
  */
  uMode = 0x1000 | DATA_8 | STOP_1 | NOPARITY;

  /*
  * UCD des seriellen Ports auslesen
  */
  PBlock.string = 0;
  PBlock.strlen = 0;
  PBlock.buffer = (char *)&Ucd_byt_drv;
  PBlock.timlen = sizeof(UCD_BYT_PORT);
  PBlock.status = 0;

  iStatus = RmIO( BYT_CREATE_NEW, (unsigned)(device), (unsigned)(unit), 0u, 0u, &DrvSts, &PBlock );

  /*
   * Modus �dern
   */
  Ucd_byt_drv.mobyte[5] |= (ushort) (uMode & 0xFFu);

  /*
   * Timeout setzen
   */
  Ucd_byt_drv.header.timout = timeout;

  /*
   * Werte zuweisen
   */
  PBlock.string = (char*) &Ucd_byt_drv;
  PBlock.strlen = sizeof(UCD_BYT_PORT);
  PBlock.buffer = 0;
  PBlock.timlen = 0;
  PBlock.status = 0;

  iStatus = RmIO( BYT_CREATE_NEW, (unsigned)(device), (unsigned)(unit), 0u, 0u, &DrvSts, &PBlock );

  /*
   * Register 0 und 1 zum Schreiben freigeben
   */
  cByte = inbyte( com + 0x03 );
  outbyte( com + 0x03, (unsigned char)(cByte | 0x80) );

  /*
   * Baudrate setzen
   */
  outbyte( com + 0x00, (ushort) LOW  (uTimeBd) );
  outbyte( com + 0x01, (ushort) HIGH (uTimeBd) );

  /*
   * Register 0 und 1 sperren
   */
  outbyte( com + 0x03, cByte );

  if( iStatus ) printf( "BYT_CREATE_NEW (set ucb): Error status = %X\n", iStatus );
#endif
  
  return 0;
}