예제 #1
0
static void rs232_recv(uint8_t byte)
{
  // just an echo back dummy.
  rs232_send('=');
  rs232_send(byte);
  cmd_seen = byte;
}
예제 #2
0
파일: raven-ipso.c 프로젝트: kincki/contiki
/* Send a serial command frame to the ATMega3290 Processor on Raven
   via serial port */
static void
send_frame(uint8_t cmd, uint8_t len, uint8_t *payload)
{
    uint8_t i;

    rs232_send(0, SOF_CHAR);    /* Start of Frame */
    rs232_send(0, len);
    rs232_send(0, cmd);
    for (i=0; i<len; i++)
        rs232_send(0,*payload++);
    rs232_send(0, EOF_CHAR);
}
예제 #3
0
int term_phoenix_send(uint8_t * buf, int len)
{
    uint8_t *echobuf = NULL;
    int res;

    assert((echobuf = alloca(len)));

    res = rs232_send(fd, buf, len);

    if (res < 0)
        return res;
    else if (res != len)
        return -EIO;

    // kill the echo!
    //printf("echo\n");
    res = rs232_read(fd, echobuf, len);
    //printf("echo done\n");

    if (res < 0)
        return res;
    else if (res != len)
        return -EIO;

    // paranoia mode!
    if (memcmp(buf, echobuf, len))
        return -EIO;

    return 0;
}
예제 #4
0
파일: main.c 프로젝트: DerGenaue/usbprog
void sendUSBString(char *s)
{
	TOGGLE_IO11();
	USBNWrite(TXC2,FLUSH);
	while(*s != '\0')
		USBNWrite(TXD2,*s++);
	rs232_send();
}
예제 #5
0
static int rs232_putchar(char ch, FILE *fp)
{
  if (!rs232_headroom)
    {
      while (!rs232_headroom)
        ;
    }
  return rs232_send((uint8_t)ch);
}
예제 #6
0
파일: main.c 프로젝트: DerGenaue/usbprog
//SIGNAL(SIG_UART_RECV)
void sendUSB(char c)
{
	TOGGLE_IO11();
	//UARTWrite("tipp");
	//fifo_put (toUSBFIFO,UARTGetChar());
	USBNWrite(TXC2,FLUSH);
	USBNWrite(TXD2,c);
	rs232_send();	
//		USBNWrite(TXC1,FLUSH);
//		USBNWrite(TXD1,0x44);
}
예제 #7
0
int _write(int file, char *ptr, int len) {
	int i;
	for (i = 0; i < len; i++) {
#if ADD_CARRAGE_RETURNS_TO_SERIAL_OUTPUT
		if(*ptr=='\n') {
			rs232_send(stdout_rs232_port, '\r');
		}
		if(*ptr=='\r') {
			ptr++;
		}
		else {
			rs232_send(stdout_rs232_port, *ptr++);
		}
#else
    rs232_send(stdout_rs232_port, *ptr++);
#endif
  }

  return len;
}
예제 #8
0
/*---------------------------------------------------------------------------*/
void
rs232_print(char *cptr)
{
  /* lock UART for the print operation */
  if(uart_lock(UART_MODE_RS232)) {
    while(*cptr != 0) {
      rs232_send(*cptr);
      ++cptr;
    }
    uart_unlock(UART_MODE_RS232);
  }
}
예제 #9
0
파일: main.c 프로젝트: DerGenaue/usbprog
int main(void)
{
    usbprog.datatogl = 0;   // 1MHz

	// init fifos
//	fifo_init (toRS232FIFO, toRS232Buf, 100);
//	fifo_init (toUSBFIFO, toUSBBuf, 100);
	
	USBNCallbackFIFORX1(&USBtoRS232);
	//USBNCallbackFIFOTX2Ready(&USBtoRS232);

	sei();			// activate global interrupts
//	UARTInit();		// only for debugging

	// setup usbstack with your descriptors
	USBNInit(usbrs232,usbrs232Conf);


	USBNInitMC();		// start usb controller
	USBNStart();		// start device stack


//	sendUSBString("Hello World!");

	while(1){
	  #if 0
		// wenn cpu zeit vorhanden fifos weiterverteilen
		// usb -> rs232
	
		// rs232 -> usb
		if( USBBuf_i>2){
		USBNWrite(TXC2,FLUSH);
		USBNWrite(TXD2,toUSBBuf[0]);
		USBNWrite(TXD2,toUSBBuf[1]);
		//USBNWrite(TXD2,0x46);
		//send_toggle();	
		rs232_send();
		USBBuf_i=0;
		}
		_delay_ms(1);
	  #endif

	}
}
예제 #10
0
int main()
{
  static uint16_t pulse_width;

  DDRB = 0;
  DDRD = 0;
  LED_DDR |= LED_BITS;			// LED pins out
  DDRB |= (1<<PB4);			// PWM out
  PORTD	= (1<<PD2)|(1<<PD3);		// pullups for sensors
  PORTB	= (1<<PB0)|(1<<PB1)|(1<<PB2);	// pullups for switches
  timer_init();
  hall_init();
  sei();			// enable interrupts.

  uint16_t pwm_stop_val = (PW_MIN+PW_MAX)/2+PW_TUNED_STOP;
  OCR1B	= pulse_width = pwm_stop_val;	// start stopped.

#define BAUD      19200
  rs232_init(UBRV(BAUD), &rs232_recv);

  uint16_t counter = 0;
  uint8_t paused = 0;
  uint8_t button_seen = 0;
  int16_t incr_counter = 0;

  for (;;)
    {
      if (!button_seen)
	{
	  if ((PINB & (1<<PB0)) || cmd_seen == '+' || cmd_seen == 'l')
	    {
	      if (!cmd_seen) button_seen = 1;
	      if (paused) 
	        {
		  pulse_width = pwm_stop_val;
		  incr_counter = 0;
		}
	      incr_counter++;
	      pulse_width = pwm_stop_val + speedup(incr_counter) * PW_BUT_INCR;
	      if (pulse_width > PW_MAX) pulse_width = PW_MAX;
	      paused = 0;
              rs232_send('l');
	    }
	  if ((PINB & (1<<PB2)) || cmd_seen == '-' || cmd_seen == 'r')
	    { 
	      if (!cmd_seen) button_seen = 1;
	      if (paused) 
	        {
		  pulse_width = pwm_stop_val;
		  incr_counter = 0;
		}
	      incr_counter--;
	      pulse_width = pwm_stop_val + speedup(incr_counter) * PW_BUT_INCR;
	      if (pulse_width < PW_MIN) pulse_width = PW_MIN;
	      paused = 0;
              rs232_send('r');
	    }
	  if ((PINB & (1<<PB1)) || cmd_seen == ' ')
	    {
	      if (!cmd_seen) button_seen = 1;
	      if (paused) 
	        {
		  paused = 0;
                  rs232_send('g');	  
		}
	      else 
	        {
		  paused = 1;
                  rs232_send('p');	  
		}
	    }
	}
      else
	{
	  // disable automatic key repeat
	  if (!(PINB & ((1<<PB0)|(1<<PB1)|(1<<PB2))))
	    button_seen = 0;	// need a release before press.
	  if (cmd_seen)
	    rs232_send('!');
	}

      if (paused)
        OCR1B = pwm_stop_val;
      else
        OCR1B = pulse_width;

      if (cmd_seen)
        {
	  cmd_seen = 0;	// very small race
          rs232_send_hex(pulse_width>>8);	  
          rs232_send_hex(pulse_width&0xff);	  
          rs232_send(' ');	  
          rs232_send_hex(hall_counter>>8);	  
          rs232_send_hex(hall_counter&0xff);	  
          rs232_send('\r');	  
          rs232_send('\n');	  
	}


      if (!(counter++ % 8))	// (1<<(led_what-1))))
        {
          _delay_ms(10.0); 
	  if (pulse_width > pwm_stop_val)
	    LED_PORT |=   GREEN_LED_BITS;         // pull high ...
	  if (pulse_width < pwm_stop_val)
	    LED_PORT |=   RED_LED_BITS;           // pull high ...
          _delay_ms(10.0);
	  if (paused) LED_PORT &= ~(LED_BITS);        // pull low ...
	  _delay_ms(80.0);
	  if (!paused) LED_PORT &= ~(LED_BITS);        // pull low ...
	}
      else
        {
	  _delay_ms(100.0);
	}
    }
}
예제 #11
0
파일: main.c 프로젝트: DerGenaue/usbprog
/* central command parser */
void Commands()
{
  char c = toRS232Buf[0];
  
  usbprog.datatogl = 0;

  int pin,value;

  int j;
  for(j=0;j<8;j++)
    toUSBBuf[j]=0;

  if((toRS232Buf[1]>=0x31) && (toRS232Buf[1]<=0x39))
    pin=(uint8_t)toRS232Buf[1]-0x30;

  if(toRS232Buf[1]=='A')pin=10;
  if(toRS232Buf[1]=='B')pin=11;

  if(toRS232Buf[2]==0x31)value=1;
  else value=0;

  toUSBBuf[0]=c;
  toUSBBuf[1]=toRS232Buf[2];
  USBBuf_i=2;
  
  switch(c) {
  /*
    case PORT_DIRECTION:  //WASTE!!!
      set_direction((uint8_t)toRS232Buf[1]);
    break;
    case PORT_SET:  // WASTE!!!
      set_port(pin, (uint8_t)toRS232Buf[2]);
    break;
  */
    
    case PORT_GET:
      USBBuf_i=8;
      uint8_t port = PINB;
      if((port & BIT(IO1))) toUSBBuf[0] = 0x31; else toUSBBuf[0] = 0x30;
      if((port & BIT(IO2))) toUSBBuf[1] = 0x31; else toUSBBuf[1] = 0x30;
      if((port & BIT(IO3))) toUSBBuf[2] = 0x31; else toUSBBuf[2] = 0x30;
      if((port & BIT(IO4))) toUSBBuf[3] = 0x31; else toUSBBuf[3] = 0x30;
      if((port & BIT(IO5))) toUSBBuf[4] = 0x31; else toUSBBuf[4] = 0x30;
      if((port & BIT(IO6))) toUSBBuf[5] = 0x31; else toUSBBuf[5] = 0x30;
      if((port & BIT(IO7))) toUSBBuf[6] = 0x31; else toUSBBuf[6] = 0x30;
      if((port & BIT(IO8))) toUSBBuf[7] = 0x31; else toUSBBuf[7] = 0x30;
    break;
    case PORT_SETPIN:
      set_pin(pin,value);
      USBBuf_i=0;
    break;
    case PORT_SETPINDIR:
      set_pin_dir(pin,value);
      USBBuf_i=0;
    break;

    case PORT_GETPIN:
      if(get_pin(pin)==1)
      toUSBBuf[1] = 0x31;
      else
      toUSBBuf[1] = 0x30;
    break;
    
    default:
      // unkown command
      toUSBBuf[0]='x';
      USBBuf_i=0;
  }
  
  //USBNWrite(TXC2,FLUSH);
  for(j=0;j<USBBuf_i;j++){
    USBNWrite(TXD2,toUSBBuf[j]);
  }
  rs232_send();
  USBBuf_i = 0;
}
예제 #12
0
void
slip_arch_writeb(unsigned char c)
{
  rs232_send(c);
}