Esempio n. 1
0
int open_serial_port(const char *port_name)
{
	int r;

	if (port_fd >= 0) {
		close(port_fd);
	}
	port_fd = open(port_name, O_RDWR);
	if (port_fd < 0) {
		report_open_error(port_name, errno);
		return -1;
	}
	r = set_baud(baud_rate);
	if (r == 0) {
		printf("Port \"%s\" opened at %s baud\r\n",
			port_name, baud_rate);
	} else {
		printf("Port \"%s\" opened, unable to set baud to %s\r\n",
			port_name, baud_rate);
	}
	#ifdef LINUX
	{
		struct serial_struct kernel_serial_settings;
		/* attempt to set low latency mode, but don't worry if we can't */
		r = ioctl(port_fd, TIOCGSERIAL, &kernel_serial_settings);
		if (r < 0) return 0;
		kernel_serial_settings.flags |= ASYNC_LOW_LATENCY;
		ioctl(port_fd, TIOCSSERIAL, &kernel_serial_settings);
	}
	#endif
    return 0;
}
Esempio n. 2
0
void open_serial_port(const char *port_name)
{
	int r;
	struct serial_struct kernel_serial_settings;

	if (port_fd >= 0) {
		close(port_fd);
	}
	port_fd = open(port_name, O_RDWR | O_NDELAY | O_NOCTTY);
	if (port_fd < 0) {
		report_open_error(port_name, errno);
		return;
	}
	r = set_baud(baud_setting());
	if (r == 0) {
		printf("Port \"%s\" opened at %s baud\r\n",
			port_name, baud_setting());
		new_port_setting(port_name);
	} else {
		printf("Port \"%s\" opened, unable to set baud to %s\r\n",
			port_name, baud_setting());
	}
	/* attempt to set low latency mode, but don't worry if we can't */
	r = ioctl(port_fd, TIOCGSERIAL, &kernel_serial_settings);
	if (r < 0) return;
	kernel_serial_settings.flags |= ASYNC_LOW_LATENCY;
	ioctl(port_fd, TIOCSSERIAL, &kernel_serial_settings);
}
Esempio n. 3
0
static int
cyg_hal_plf_serial_control(void *__ch_data, __comm_control_cmd_t __func, ...)
{
    static int irq_state = 0;
    channel_data_t* chan = (channel_data_t*)__ch_data;
    int ret = 0;
    CYGARC_HAL_SAVE_GP();

    switch (__func) {
    case __COMMCTL_IRQ_ENABLE:
        irq_state = 1;

	HAL_WRITE_UINT8(chan->base+CYG_DEV_IER, SIO_IER_RCV);
        HAL_INTERRUPT_UNMASK(chan->isr_vector);
        break;
    case __COMMCTL_IRQ_DISABLE:
        ret = irq_state;
        irq_state = 0;

	HAL_WRITE_UINT8(chan->base+CYG_DEV_IER, 0);
        HAL_INTERRUPT_MASK(chan->isr_vector);
        break;
    case __COMMCTL_DBG_ISR_VECTOR:
        ret = chan->isr_vector;
        break;
    case __COMMCTL_SET_TIMEOUT:
    {
        va_list ap;

        va_start(ap, __func);

        ret = chan->msec_timeout;
        chan->msec_timeout = va_arg(ap, cyg_uint32);

        va_end(ap);
    }        
    case __COMMCTL_GETBAUD:
        ret = chan->baud_rate;
        break;
    case __COMMCTL_SETBAUD:
    {
        va_list ap;
        va_start(ap, __func);
        chan->baud_rate = va_arg(ap, cyg_int32);
        va_end(ap);
        ret = set_baud(chan);
        break;
    }
    default:
        break;
    }
    CYGARC_HAL_RESTORE_GP();
    return ret;
}
Esempio n. 4
0
void change_baud(const char *baud_name)
{
	int r;

	r = set_baud(baud_name);
	if (r == 0) {
		printf("Baud rate set to %s\r\n", baud_name);
		new_baud_setting(baud_name);
	} else {
		printf("Unable to set baud to %s\r\n", baud_name);
	}
}
Esempio n. 5
0
int open_serial_port(const char *port_name)
{
    int r;
    struct termios term_setting;

    if (port_fd >= 0) {
        close(port_fd);
    }

    port_fd = open(port_name, O_RDWR);

    if (port_fd < 0) {
        report_open_error(port_name, errno);
        return -1;
    }

    bzero(&term_setting, sizeof(term_setting));
    term_setting.c_cflag = (CS8 | CREAD);
    term_setting.c_cc[VMIN] = 1;
    term_setting.c_cc[VTIME] = 1;
    r = tcsetattr(port_fd, TCSANOW, &term_setting);

    if (r != 0) {
        return -1;
    }

    r = set_baud(baud_rate);

    if (r == 0) {
        printf("Port \"%s\" opened at %s baud\r\n",
               port_name, baud_rate);
    }
    else {
        printf("Port \"%s\" opened, unable to set baud to %s\r\n",
               port_name, baud_rate);
    }

#ifdef LINUX
    {
        struct serial_struct kernel_serial_settings;
        /* attempt to set low latency mode, but don't worry if we can't */
        r = ioctl(port_fd, TIOCGSERIAL, &kernel_serial_settings);

        if (r < 0) {
            return 0;
        }

        kernel_serial_settings.flags |= ASYNC_LOW_LATENCY;
        ioctl(port_fd, TIOCSSERIAL, &kernel_serial_settings);
    }
#endif
    return 0;
}
Esempio n. 6
0
static void
cyg_hal_plf_serial_init_channel(void* __ch_data)
{
    cyg_uint8* base = ((channel_data_t*)__ch_data)->base;
    channel_data_t* chan = (channel_data_t*)__ch_data;
    
    // 8-1-no parity.
    HAL_WRITE_UINT8(base+CYG_DEV_LCR, SIO_LCR_WLS0 | SIO_LCR_WLS1);
    chan->baud_rate = CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL_BAUD;
    set_baud( chan );
    HAL_WRITE_UINT8(base+CYG_DEV_FCR, 0x07);  // Enable & clear FIFO
}
Esempio n. 7
0
static int open_device(const char *tty, GHashTable *options)
{
	struct termios ti;
	int fd;

	/* Switch TTY to raw mode */
	memset(&ti, 0, sizeof(ti));
	cfmakeraw(&ti);

	if (options) {
		GHashTableIter iter;
		const char *key;
		const char *value;

		g_hash_table_iter_init (&iter, options);
		while (g_hash_table_iter_next(&iter, (void *) &key,
							(void *) &value)) {
			gboolean ok = FALSE;

			if (g_str_equal(key, "Baud"))
				ok = set_baud(value, &ti);
			else if (g_str_equal(key, "StopBits"))
				ok = set_stop_bits(value, &ti);
			else if (g_str_equal(key, "DataBits"))
				ok = set_data_bits(value, &ti);
			else if (g_str_equal(key, "Parity"))
				ok = set_parity(value, &ti);
			else if (g_str_equal(key, "XonXoff"))
				ok = set_xonxoff(value, &ti);
			else if (g_str_equal(key, "RtsCts"))
				ok = set_rtscts(value, &ti);
			else if (g_str_equal(key, "Local"))
				ok = set_local(value, &ti);
			else if (g_str_equal(key, "Read"))
				ok = set_read(value, &ti);

			if (ok == FALSE)
				return -1;
		}
	}

	fd = open(tty, O_RDWR | O_NOCTTY | O_NONBLOCK);
	if (fd < 0)
		return -1;

	tcflush(fd, TCIOFLUSH);
	tcsetattr(fd, TCSANOW, &ti);

	return fd;
}
Esempio n. 8
0
/*******************************************************************************
 * Init
 *
 * Description: Initializes the i2c identified by the ID (only 2 i2c
 *              periferals are supported)
 *
 * Inputs:      float buad - buad rate
 *
 *
 * Revision: Initial Creation 2/27/2014 - Mitchell S. Tilson
 *           Update to c++ 3/18/2014 - Mitchell S. Tilson
 *
 ******************************************************************************/
void I2C_Class::Init( I2C_ID id, float baud )
{
    // Intialize the register base for the I2C peripheral
    regs_ = I2C_REGISTERS[id];

    // set the initialized flag
    initialized_ = FALSE;

    // set the enabled flag
    enabled_ = FALSE;

    // Set up the buad rate
    baud_ = baud;

    // Disable the peripherial for now
    // disable();

    // set up the control register
    con_setup();

    // set up the status register
    stat_setup();

    // set up the address register
    addr_setup();

    // set up the address register
    addr_msk_setup();

    // set up the baud rate
    set_baud();

    // set the initialized flag
    initialized_ = TRUE;

    // Enable the I2C
    enable();
}
Esempio n. 9
0
main( )
{
  volatile UartRegs *uart0        = (UartRegs *) (UPG_BASE | 0x000b00); // 0xb00 == uart0 for 7401
  volatile UartRegs *uart1        = (UartRegs *) (UPG_BASE | 0x000b40); // 0xb40 == uart1 for 7401
  volatile uint32	*ebic         = (uint32 *) EBIC_BASE;
  //  volatile uint32    *mbox         = (uint32 *) (SDRAM_MEM_BASE|(GLOBAL_EBI_RBUS_START + 0*0x00800000));  // mbox address will be 0x1e000000

  volatile uint32   *uart0StatPtr = (volatile uint32 * ) (UPG_BASE | 0x000b00);
  volatile uint32   *uart1StatPtr = (volatile uint32 * ) (UPG_BASE | 0x000b40);

  volatile uint32   uart0Stat     = 0;
  volatile uint32   uart1Stat     = 0;
  int   i, j;
  byte  txd0, rxd0, txd1, rxd1;

  /*_go_cacheable( ); */

  /* 4K block */
  // program the ebi core such that addr mbox addr 0x1e000000 will map to ebi_cs1
  ebic[EBI_CS_BASE_1] = (LtoP(SDRAM_MEM_BASE) | (GLOBAL_EBI_RBUS_START + 0*0x00800000));          // write 0x1e000000 to addr: ebic+8 
  ebic[EBI_CS_CONFIG_1] = 0x01 | SETUP | HOLD;   // write 0x01 | SETUP | HOLD to addr: ebic+0xc

  mbox[0] = 'c';  /* Control Reg Programming */
  /*  ORIG programming
  *(uint32 *)&uart0->line_ctrl = UA_BAUD_LATCH;
  *(uint32 *)&uart0->dlh = 0x0;
  *(uint32 *)&uart0->data_dll = 0xe;
  *(uint32 *)&uart0->line_ctrl = UA_8BIT;  // 8 bit characters
  *(uint32 *)&uart0->fifo_ctrl = UA_TXFIFO_RESET | UA_RXFIFO_RESET | UA_FIFO_ENABLE;

  *(uint32 *)&uart1->line_ctrl = UA_BAUD_LATCH;
  *(uint32 *)&uart1->dlh = 0x0;
  *(uint32 *)&uart1->data_dll = 0xe;
  *(uint32 *)&uart1->line_ctrl = UA_8BIT;  // 8 bit characters
  *(uint32 *)&uart1->fifo_ctrl = UA_TXFIFO_RESET | UA_RXFIFO_RESET | UA_FIFO_ENABLE;
  */

  unsigned int PCLK = 100000000;

  set_baud( PCLK , PCLK/16 , 0 );
  RegWt( UARTA_LCR , UA_8BIT );
  RegWt( UARTA_FCR , UA_TXFIFO_RESET | UA_RXFIFO_RESET | UA_FIFO_ENABLE );

  set_baud( PCLK , PCLK/16 , 1 );
  RegWt( UARTB_LCR , UA_8BIT );
  RegWt( UARTB_FCR , UA_TXFIFO_RESET | UA_RXFIFO_RESET | UA_FIFO_ENABLE );


  mbox[0] = 't';  /* Transmit data */

  RegWt (UARTA_THR , 'y' );
  wait_for_uart(0) ;

  RegWt (UARTA_THR , 'o' );
  wait_for_uart(0) ;

  RegWt (UARTA_THR , ' ' );
  wait_for_uart(0) ;

  RegWt (UARTA_THR , 'm' );
  wait_for_uart(0) ;

  RegWt (UARTA_THR , 'a' );
  wait_for_uart(0) ;

  RegWt (UARTA_THR , 'n' );
  wait_for_uart(0) ;



  RegWt (UARTB_THR , 'h' );
  wait_for_uart(1) ;

  RegWt (UARTB_THR , 'i' );
  wait_for_uart(1) ;

  RegWt (UARTB_THR , ' ' );
  wait_for_uart(1) ;

  RegWt (UARTB_THR , 'b' );
  wait_for_uart(1) ;

  RegWt (UARTB_THR , 'r' );
  wait_for_uart(1) ;

  RegWt (UARTB_THR , 'o' );
  wait_for_uart(1) ;

  /* Terminate Sim - send 1 to mbox[0] */
  mbox[0] = 0x1;
  while( 1 ); // wait until all chars are transmitted out of fifo....
}
Esempio n. 10
0
int main (void) {
  io_init(); //Setup IO pins and defaults
  set_baud();

  char input;

  while (1) {

    input = getchar();

    //first stage will be a simple switch case`


    switch (input) {
      case '0':
        //shake sequence
        spk=0;
        play_ready_beep();

        putchar('0');
        break;
      case '1':
        //shake sequence
        PORTB |= _BV(ENA); // ON the enable bit
        shake_sequence(2); // TODO shake twice -- can mod this later for custom shakes
        PORTB &= ~_BV(ENA);// OFF the enable bit
        putchar('1');
        break;
      case '2':
        //ramp sequence
        PORTB |= _BV(ENA); // ON the enable bit
        demo_centrifuge_stage(); // TODO add control method for customization
        PORTB &= ~_BV(ENA);// OFF the enable bit
        putchar('2');
        break;
      case '3':
        //recording_sequence
        PORTB |= _BV(ENA); // ON the enable bit
        find_first_well(); // TODO find the pwm speed for Servo.h 
        //and emulate to avoid needing to perform trial and error
        PORTB &= ~_BV(ENA);// OFF the enable bit
        putchar('3');
        break;
      case '4':
        //full_sequence
        PORTB |= _BV(ENA); // ON the enable bit
        demo_full_sequence();// TODO create full sequence
        PORTB &= ~_BV(ENA);// OFF the enable bit
        putchar('4');
        break;
      case '5':
        //LED ON
        PORTB |= _BV(LED); // TODO Test LED ON
        putchar('5');
        break;
      case '6':
        //LED OFF
        PORTB &= ~_BV(LED); // TODO Test LED OFF
        putchar('6');
        break;
      default:
        putchar('a');
        break;
    }
  }

  /*
     if ( input == '1' ) {
     for (i = 255; i > 0 ; i--) {
     OCR1AL = i;
     printf("Hello world %u \r\n", i);
     _delay_ms(1000);
     }
     OCR1AL = 0;
     } else {

     printf("not the right answer");
     }
     */
  return 0;
}
int main (void)
{
	char x, y, temp, q;
    ioinit(); //Setup IO pins and defaults
	//USART_Init( MYUBRR);
	set_baud(6);//115200
	rprintf_devopen(put_char); /* init rrprintf */
	
	//check for existing preset values==============================================================
	temp = EEPROM_read((unsigned int)BPS);
	
	if ((temp < 1) | (temp > 6))//BPS will only be 1-6
	{
		cli();//Disable Interrupts
		
		EEPROM_write((unsigned int) BPS, 6);
		EEPROM_write((unsigned int) BACKLIGHT, 100);
		EEPROM_write((unsigned int) SPLASH, 1);
		EEPROM_write((unsigned int) REV, 0);
		
		sei();//Enable Interrupts
		
		BL_dutycycle = 100;
		baud_rate = 6;
		splash_screen = 1;
		reverse = 0;
	}
	
	else
	{
		baud_rate = temp;
		BL_dutycycle = EEPROM_read((unsigned int)BACKLIGHT);
		splash_screen = EEPROM_read((unsigned int)SPLASH);
		reverse = EEPROM_read((unsigned int)REV);
	}
	
	
	//Reset the display
	PORTC &= ~(1 << RESET);
	delay_ms(50);
	PORTC |= (1 << RESET);
	//delay_ms(500);

	
	clear_screen();

	set_page(0);
	
	set_x(0);
	
	display_on();
	
	//set display start line to 0
	//set control lines
	PORTC &= ~((1 << EN) | (1 << R_W) | (1 << RS));//down
	
	set_data(0xC0);
	//set_data(0xFF);
	delay();
	PORTC |= (1 << EN);//up
	delay();
	PORTC &= ~(1 << EN);//down
	delay();
	PORTC |= ((1 << EN) | (1 << R_W) | (1 << RS));//all high
	
	delay();
	
	x_offset = 0;

	set_page(0);
	
	DDRB |= (1<<BL_EN);//set PB2 as output
	
	set_backlight(BL_dutycycle);
	
	//Logo==========================================================
	if (splash_screen == 1)
	{
		y = 40;
		
		for (q = 0; q < 30; q++)
		{
			temp = logo[q];
			for (x = 56; x < 64; x++)
			{
				if (temp & 0x80) pixel(1,x,y);
				
				temp <<= 1;
			}
			
			q++;
			
			temp = logo[q];
			for (x = 64; x < 72; x++)
			{
				if (temp & 0x80) pixel(1,x,y);
				
				temp <<= 1;
			}
			y--;
	
		}	
	}
	
	pixel(0,0,0);//cheat
	
	RX_in = 0;
	
	delay_ms(1000);
	clear_screen();
	
	if (RX_in > 0)//revert to 115200
	{
		print_char(1,'1');
		print_char(1,'1');
		print_char(1,'5');
		print_char(1,'2');
		print_char(1,'0');
		print_char(1,'0');
		
		baud_rate = 6;
		set_baud(6);//115200
		
		cli();
		
		EEPROM_write((unsigned int) BPS, 6);
		
		sei();//Enable Interrupts
	}
	
	else (set_baud(baud_rate));
	
	delay_ms(1000);
	clear_screen();
	
	//main loop===================================================
	while(1)
	{
		if(RX_in != RX_read)
		{
			x = RX_array[RX_read];
			RX_read++;
			if(RX_read >= 416) RX_read = 0;
			
			//Backspace===================================================
			if(x == 8) del_char(0);
			
			//Special commands
			else if (x == 124)
			{	
				//make sure the next byte is there
				while(RX_in == RX_read);
				
				//0, clear screen======================================================
				if(RX_array[RX_read] == 0)//^@
				{
					clear_screen();
					RX_read++;
					if(RX_read >= 416) RX_read = 0;
				}
				
				//demo mode
				else if(RX_array[RX_read] == 4)//^d
				{
					RX_in = 0, RX_read = 0;
					demo();
					clear_screen();
					RX_in = 0;
				}
				
				
				//reverse mode
				else if(RX_array[RX_read] == 18)//^r
				{
					reverse ^= 1;
					clear_screen();
					RX_read++;
					if(RX_read >= 416) RX_read = 0;
					
					cli();
					EEPROM_write((unsigned int) REV, reverse);
					sei();
				}
				
				
				//toggle spasl screen
				else if(RX_array[RX_read] == 19)//^s
				{
					splash_screen ^= 1;
					//clear_screen();
					RX_read++;
					if(RX_read >= 416) RX_read = 0;
					
					cli();
					EEPROM_write((unsigned int) SPLASH, splash_screen);
					sei();
				}
				
				else
				{
					//set backlight (0 to 100)=========================================================
					if(RX_array[RX_read] == 2)//^b
					{
						RX_read++;
						if(RX_read >= 416) RX_read = 0;
						while(RX_in == RX_read);//wait for byte
						BL_dutycycle = RX_array[RX_read];
						
						RX_read++;
						if(RX_read >= 416) RX_read = 0;
						
						set_backlight(BL_dutycycle);
						
						cli();
						EEPROM_write((unsigned int) BACKLIGHT, BL_dutycycle);
						sei();
						
						

					}
					
					
					//change baud rate=========================================================
					if(RX_array[RX_read] == 7)//^g
					{
						RX_read++;
						if(RX_read >= 416) RX_read = 0;
						while(RX_in == RX_read);//wait for byte
						//if (RX_array[RX_read] == '1') USART_Init( 1000000/2400-1);//4800
						//else if (RX_array[RX_read] == '2') USART_Init( 1000000/4800-1);//9600
						//else if (RX_array[RX_read] == '3') USART_Init( 1000000/9600-1);//19200
						//else if (RX_array[RX_read] == '4') USART_Init( 1000000/19200-1);//38400
						//else if (RX_array[RX_read] == '5') USART_Init( 1000000/28800-1);//57600
						//else if (RX_array[RX_read] == '6') USART_Init( 1000000/57600-1);//115200
						
						if ((RX_array[RX_read] > '0') * (RX_array[RX_read] < '7')) baud_rate = (RX_array[RX_read]) - 48;
						
						set_baud(baud_rate);
						
						cli();
						EEPROM_write((unsigned int) BPS, baud_rate);
						sei();
						
						RX_read++;
						if(RX_read >= 416) RX_read = 0;
						
					}	
					
					
					//set x or y=========================================================
					if((RX_array[RX_read] == 24) | (RX_array[RX_read] == 25))//^x or ^y
					{
						RX_read++;
						if(RX_read >= 416) RX_read = 0;
						while(RX_in == RX_read);//wait for byte
						if (RX_array[RX_read-1] == 24) x_offset = RX_array[RX_read];
						else if (RX_array[RX_read-1] == 25) y_offset = RX_array[RX_read];
						
						RX_read++;
						if(RX_read >= 416) RX_read = 0;
						
						if (x_offset > 159) x_offset = 159;
						if (y_offset > 127) y_offset = 127;

					}

					//set pixel=========================================================
					if (RX_array[RX_read] == 16)//^p
					{
						//need 3 bytes
						for (y = 0; y < 3; y++)
						{
							RX_read++;
							if(RX_read >= 416) RX_read = 0;
							while(RX_in == RX_read);//wait for byte
						}
						
						pixel(RX_array[RX_read], RX_array[RX_read-2], RX_array[RX_read-1]);
						
						RX_read++;
						if(RX_read >= 416) RX_read = 0;

					}

					
					//<ctrl>c, circle======================================================
					if(RX_array[RX_read] == 3)//^c
					{
						//need 4 bytes
						for (y = 0; y < 4; y++)
						{
							RX_read++;
							if(RX_read >= 416) RX_read = 0;
							while(RX_in == RX_read);//wait for byte
						}
						
						circle(RX_array[RX_read], RX_array[RX_read-3], RX_array[RX_read-2], RX_array[RX_read-1]);
						
						RX_read++;
						if(RX_read >= 416) RX_read = 0;
					}
					
					
					//<ctrl>e, erase block======================================================
					if(RX_array[RX_read] == 5)//^e
					{
						//need 4 bytes
						for (y = 0; y < 4; y++)
						{
							RX_read++;
							if(RX_read >= 416) RX_read = 0;
							while(RX_in == RX_read);//wait for byte
						}
						
						erase_block(RX_array[RX_read-3], RX_array[RX_read-2], RX_array[RX_read-1], RX_array[RX_read]);
						
						RX_read++;
						if(RX_read >= 416) RX_read = 0;
					}
					
					
					//box======================================================
					if(RX_array[RX_read] == 15)//^o
					{
						//need 4 bytes
						for (y = 0; y < 4; y++)
						{
							RX_read++;
							if(RX_read >= 416) RX_read = 0;
							while(RX_in == RX_read);//wait for byte
						}
						
						box(RX_array[RX_read-3], RX_array[RX_read-2], RX_array[RX_read-1], RX_array[RX_read]);
						
						RX_read++;
						if(RX_read >= 416) RX_read = 0;
					}


					//line========================================================
					else if (RX_array[RX_read] == 12)//^l
					{
						//need 5 bytes
						for (y = 0; y < 5; y++)
						{
							RX_read++;
							if(RX_read >= 416) RX_read = 0;
							while(RX_in == RX_read);//wait for byte
						}
						
						line(RX_array[RX_read], RX_array[RX_read-4], RX_array[RX_read-3], RX_array[RX_read-2], RX_array[RX_read+-1]);
						RX_read++;
						if(RX_read >= 416) RX_read = 0;
					}
					
					
				}
	
			}
			
			//print character to the screen===============================================
			else
			{
				del_char(1);
				print_char(1, x);
			}
		}
		
	}
	
	//demo();
	


    
}