static int tegra_fiqdb_getc(void)
{
	unsigned long lsr = uart_read(UART_LSR);
	if (lsr & UART_LSR_DR)
		return uart_read(UART_RX);
	return FIQDB_NO_CHAR;
}
Exemple #2
0
void
uart_init_siopinib(const SIOPINIB *siopinib)
{

	/*
	 *  Blackfin ADSP-BF531/2/3, BF534/6/7, BF561の内蔵UARTに固有の作業。
	 *  Power Downモードの解除。
	 */
	if ( siopinib->set_ucen )
		uart_write(siopinib->reg_base, UART_GCTL, 
			   (uart_read(siopinib->reg_base, UART_GCTL) | GCTL_UCEN ));
    /*
     *  分周比の設定
     */
    /* Divisor Enable */
    uart_write(siopinib->reg_base, UART_LCR,
                (uart_read(siopinib->reg_base, UART_LCR) | LCR_DL_MODE));
    uart_write(siopinib->reg_base, UART_DLL, siopinib->dll_val);
    uart_write(siopinib->reg_base, UART_DLM, siopinib->dlm_val);
    /* Divisor Disable */
    uart_write(siopinib->reg_base, UART_LCR,
                (uart_read(siopinib->reg_base, UART_LCR) & ~LCR_DL_MODE));

    /* モード設定, パリティ無し 8bit data, 1 stop bit */
    uart_write(siopinib->reg_base, UART_LCR, LCR_NP_8_1);

    /* 割込み禁止 */
    uart_write(siopinib->reg_base, UART_IER, 0x00);
}
Exemple #3
0
/**
 * \brief Get numeric value from console.
 *
 * \return Integer value from the console.
 */
static uint8_t get_num_value(void)
{
	uint32_t ul_numkey;
	uint8_t uc_key1, uc_key2;

	puts("New value : ");
#if defined (  __GNUC__  )
	fflush(stdout);
#endif
	while (uart_read(CONSOLE_UART, &uc_key1));
	printf("%c", uc_key1);
	while (uart_read(CONSOLE_UART, &uc_key2));
	printf("%c", uc_key2);
	puts("\r\n");

	if ('0' <= uc_key1 && '9' >= uc_key1) {
		ul_numkey = (uc_key1 - '0');
	}
	if ('0' <= uc_key2 && '9' >= uc_key2) {
		ul_numkey *= 10;
		ul_numkey += (uc_key2 - '0');
	}

	return (uint8_t) ul_numkey;
}
Exemple #4
0
static int
lpc_uart_io_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes,
		    uint32_t *eax, void *arg)
{
	int offset;
	struct lpc_uart_softc *sc = arg;

	offset = port - sc->iobase;

	switch (bytes) {
	case 1:
		if (in)
			*eax = uart_read(sc->uart_softc, offset);
		else
			uart_write(sc->uart_softc, offset, *eax);
		break;
	case 2:
		if (in) {
			*eax = uart_read(sc->uart_softc, offset);
			*eax |= uart_read(sc->uart_softc, offset + 1) << 8;
		} else {
			uart_write(sc->uart_softc, offset, *eax);
			uart_write(sc->uart_softc, offset + 1, *eax >> 8);
		}
		break;
	default:
		return (-1);
	}

	return (0);
}
/* Get the number of cmd available and version num */
char cmdGet(void){
    if(cmdGeneric(0x00)){
        unsigned char len = uart_read();
        unsigned char ver = uart_read();
        unsigned char * buff = (unsigned char *) malloc(sizeof(unsigned char) * (len+1));
        uart_reads(buff, len);
        buff[len] = '\0';
        
        
        for(int i=0; i<len; i++){
            if(0x44 == buff[i]){
                extendedErase = 1;
            }
        }
        time_sleep(0.1);
        int ok = wait_for_ask();
        /*
        if(ok){mdebug(0, "cmd get ok\n");}
        else {mdebug(0, "cmd get failed\n");}
        */
        
        return ver;
    }
    else{
        /* TODO: what to do if receive nack? */
        handle_error(NACK_ERROR);
        return 0;
    }
}
Exemple #6
0
/* This fuction returns the hex value of the  2 consequence received ascii characters (HEX) */
uint8_t get_hex_value()
{
     uint8_t data;
	 uint8_t temp_byte;
    while (!(data = uart_read()));
// Put here to save calling subroutine overhead	
	 if( data < 'A' )
    {
	   data  -= '0';
    }
    else
    {
	
   data -=  55 ;
    }
	temp_byte = data << 4;
	 while (!(data = uart_read()));
// Put here to save calling subroutine overhead	
	 if( data < 'A' )
    {
	   data  -= '0';
    }
    else
    {
	   data -=  55 ;
    }
	
	temp_byte |= data;
    return temp_byte;
    
}
Exemple #7
0
static int
ralink_cngetc(dev_t dv)
{
        if ((uart_read(RA_UART_LSR) & LSR_RXRDY) == 0)
		return -1;

	return uart_read(RA_UART_RBR) & 0xff;
}
Exemple #8
0
int uart_getc(void)
{
	unsigned long status;

	do {
		status = uart_read(UART_STATUS_OFFS);
	} while (!(status & UART_STATUS_RX_READY));

	return uart_read(UART_DATA_OFFS);
}
int __init tegra_fiqdb_register(void)
{
	while (uart_read(UART_LSR) & UART_LSR_DR)
		uart_read(UART_RX);

	/* enable rx and lsr interrupt */
	uart_write(UART_IER_RLSI | UART_IER_RDI, UART_IER);

	/* interrupt on every character */
	uart_write(0, UART_IIR);
	fiqdb_register(&tegra_fiqdb);
}
Exemple #10
0
/**
 * \ingroup SIOAPI
 * \brief 割込みサービスルーチン
 * \param exinf 拡張
 * \details
 * porting.txtの8.3節で養成されている割り込みサービスルーチン。
 * このルーチンはextinfの情報を元にどの割り込みが発生したか自動判別
 * している。
 *
 * extinfにどのような情報を与えるかは、明言されていないように思える。
 * CORTEX-M3版ではポート番号(1から始まってTNUM_PORTまでの識別
 * 番号)がtarget_erial.cfgの中でATTISRのextinf引数として与えられている。
 */
void sio_isr(intptr_t exinf)
{
	SIOPCB* siopcb = GET_SIOPCB(exinf);
	int32_t reg = siopcb->reg_base;
		/* 送信コールバック可能でかつ送信可能なら、送信コールバックを呼ぶ  */
	if (sio_putready(siopcb) && ( uart_read(reg, UART_IER) &  IER_TX)) {
		sio_irdy_snd(siopcb->exinf);
	}
		/* 受信コールバック可能でかつ受信可能なら、受信コールバックを呼ぶ  */
	if (sio_getready(siopcb) && ( uart_read(reg, UART_IER) &  IER_RX)) {
		sio_irdy_rcv(siopcb->exinf);
	}
}
Exemple #11
0
int _read(int file, char *ptr, int len) {
  int todo,ch;
  if(len == 0)
    return 0;
 // uart_wait_rcv();
  *ptr++ = uart_read();
  for(todo = 1; todo < len; todo++) {
  	ch=uart_read();
    if(ch==-1) { break; }
    *ptr++ = ch;
  }
  return todo;
}
Exemple #12
0
/* This is called with the console lock held */
static int64_t uart_opal_read(int64_t term_number, int64_t *length,
			      uint8_t *buffer)
{
	size_t req_count = *length, read_cnt = 0;
	uint8_t lsr = 0;

	if (term_number != 0)
		return OPAL_PARAMETER;
	if (!in_buf)
		return OPAL_INTERNAL_ERROR;

	lock(&uart_lock);

	/* Read from buffer first */
	if (in_count) {
		read_cnt = in_count;
		if (req_count < read_cnt)
			read_cnt = req_count;
		memcpy(buffer, in_buf, read_cnt);
		req_count -= read_cnt;
		if (in_count != read_cnt)
			memmove(in_buf, in_buf + read_cnt, in_count - read_cnt);
		in_count -= read_cnt;
	}

	/*
	 * If there's still room in the user buffer, read from the UART
	 * directly
	 */
	while(req_count) {
		lsr = uart_read(REG_LSR);
		if ((lsr & LSR_DR) == 0)
			break;
		buffer[read_cnt++] = uart_read(REG_RBR);
		req_count--;
	}

	/* Finally, flush whatever's left in the UART into our buffer */
	uart_read_to_buffer();

	uart_trace(TRACE_UART_CTX_READ, read_cnt, tx_full, in_count);

	unlock(&uart_lock);
	
	/* Adjust the OPAL event */
	uart_adjust_opal_event();

	*length = read_cnt;
	return OPAL_SUCCESS;
}
Exemple #13
0
static void
ralink_cnputc(dev_t dv, int c)
{
	int timo = 150000;

        while ((uart_read(RA_UART_LSR) & LSR_TXRDY) == 0 && --timo > 0)
		;

	uart_write(RA_UART_TBR, c);
	__asm __volatile("sync");

	timo = 150000;
        while ((uart_read(RA_UART_LSR) & LSR_TSRE) == 0 && --timo > 0)
		;
}
Exemple #14
0
/**
 *  \ingroup SIOAPI
 *  \brief コールバックの禁止
 *  \param siopcb コールバックを禁止するSIOポート
 *  \param cbrtn SIO_RDY_SND あるいは SIO_RDY_RCV
 *  \details
 *  シリアル制御タスクのコールバック関数の呼び出しを禁止する関数。 cbrtn 引数を使って送信と受信のいずれの側で禁止するかを
 *  指定する。
 *
 *  この関数はTOPPERS/ASPのシリアル制御タスクの中から呼び出される。コールバックの禁止にはペリフェラルの割り込み禁止機能を使う。
 */
void sio_dis_cbr(SIOPCB *siopcb, uint_t cbrtn)
{
	uint32_t reg = siopcb->reg_base;	/* UARTのベースアドレスを取得 */

	switch (cbrtn) {
	case SIO_RDY_SND:
		uart_write( reg, UART_IER, uart_read(reg, UART_IER) & ~IER_TX );	/* 送信割り込みを禁止 */
		break;
	case SIO_RDY_RCV:
		uart_write( reg, UART_IER, uart_read(reg, UART_IER) & ~IER_RX );	/* 受信割り込みを禁止 */
		break;
	default:
		break;
	}
}
Exemple #15
0
void console_size(int *rows, int *cols) {
    char buf[6];
    char *cbuf;
    char c;
    
    // Save cursor position
    console_put("\033[s");

    // Set cursor out of the screen
    console_put("\033[999;999H");

    // Get cursor position
    console_put("\033[6n");

    // Return to saved cursor position
    console_put("\033[u"); 

    // Skip scape sequence
    while (uart_read(CONSOLE_UART, &c, 100) && (c != '\033')) {
	}

    while (uart_read(CONSOLE_UART, &c, 100) && (c != '[')) {
	}
    
    // Read rows
    c = '\0';
    cbuf = buf;
    while (uart_read(CONSOLE_UART, &c, 100) && (c != ';')) {
	    *cbuf++ = c;
	}
    *cbuf = '\0';
    
    if (*buf != '\0') {
        *rows = atoi(buf);
    }

    // Read cols
    c = '\0';
    cbuf = buf;
    while (uart_read(CONSOLE_UART, &c, 100) && (c != 'R')) {
		*cbuf++ = c;
	}
    *cbuf = '\0';

    if (*buf != '\0') {
        *cols = atoi(buf);
    }
}
Exemple #16
0
void main()
{
	uart_init();		
    lcd_init();
    int x;
	DDRD=0xF0;
	while(1)
	{

         x=uart_read();
		 _delay_ms(10);
		 PORTD =0X00;
		lcd_gotoxy(1,0);
		lcd_showvalue(x);
		
		if(x==102)		//forward
			PORTD=0xa0;			
		else if(x==108)		//left
			PORTD=0x60;
		else if(x==114)		//right
			PORTD=0x90;
		else PORTD=0x00;		//stop		
		
	}
   		
   
}
Exemple #17
0
char gps_get_data() {
    float lat, lon = 0.0;
    unsigned long fixAge = 0;
    char uart_buffer[512] = {};
    int ctr = 0;

    uart_init(9600);// The default baud rate for this GPS device is 9600

    uart_read(uart_buffer, sizeof(uart_buffer));
    while (uart_buffer[ctr] != NULL){
        char charRead = uart_buffer[ctr];
        GPSDevice.encode(charRead);
        if ((charRead == ',') && (GPSDevice._term_number == 1)) {
            itsAGPRMCMessage = !GPSDevice.gpsstrcmp(GPSDevice._term, _GPRMC_TERM);
        }

        if ((charRead == 'A' || charRead == 'V') && itsAGPRMCMessage) {
            dataStatus = charRead;
            itsAGPRMCMessage = 0;
        }
        ctr++;
    }
    GPSDevice.f_get_position(&lat, &lon, &fixAge);
    printf("lat: %.4f\t", lat);
    printf("lon: %.4f\t", lon);
    printf("alt: %.1f\t", GPSDevice.f_altitude());
    printf("sta: %c\n", dataStatus);

    return dataStatus;
}
Exemple #18
0
/* Note that we do not use the hw timer so that this function works
 * even if the system controller does not.
 */
static int check_ack()
{
	int timeout;
	int recognized;
	static const char str[SFL_MAGIC_LEN] = SFL_MAGIC_ACK;

	timeout = 2000000;
	recognized = 0;
	while(timeout > 0) {
		if(uart_read_nonblock()) {
			char c;
			c = uart_read();
			if(c == str[recognized]) {
				recognized++;
				if(recognized == SFL_MAGIC_LEN)
					return 1;
			} else {
				if(c == str[0])
					recognized = 1;
				else
					recognized = 0;
			}
		}
		timeout--;
	}
	return 0;
}
Exemple #19
0
/**
 * Get comparison mode.
 */
static uint8_t get_comparison_mode(void)
{
	uint8_t uc_mode = adc_get_comparison_mode(ADC);
	uint8_t uc_char;

	while (1) {
		while (uart_read(CONSOLE_UART, &uc_char));
		switch (uc_char) {
		case 'a':
		case 'A':
			uc_mode = 0x0;
			break;
		case 'b':
		case 'B':
			uc_mode = 0x1;
			break;
		case 'c':
		case 'C':
			uc_mode = 0x2;
			break;
		case 'd':
		case 'D':
			uc_mode = 0x3;
			break;
		case 'q':
		case 'Q':
			break;
		default:
			continue;
		}
		return uc_mode;
	}
}
Exemple #20
0
void printf_information()
{
    uint8_t a; 
    uint8_t na = 0;
    
    // Get num entries.
    uart_write("an",2); 
    
    uart_read((char *)&na, 1);   
 

    printf("== Alarms ==\n");
    for(a = 0; a < na; a++ ) {
        ssize_t t = 0;
        char buffer[32] = { 'a', 'r', '0'+a };
        while(t < 3) {
            t+=write(fd, &buffer[t], 3-t);
        }

        t = 0;
        while(t < 4) {
            t +=read(fd, &buffer[t], 4-t);
        }
        buffer[t] = '\0';
        printf("%d: %02d:%02d ( %7s ) (%3s)\n", a+1, buffer[0]%24, buffer[1],
            (buffer[2])?"Enable":"Disable",
            (buffer[3])?"Ack":"");
        
    }


}
Exemple #21
0
static void serial_service(void)
{
    char *txdata;
    int txlen;
    static char rxdata;
    static int rxpending;
    int r, i;

    if(!rxpending && uart_read_nonblock()) {
        rxdata = uart_read();
        rxpending = 1;
    }
    if(rxpending) {
        r = session_input(&rxdata, 1);
        if(r > 0)
            rxpending = 0;
        if(r < 0)
            /* do not signal if reset was requested by host */
            reset_serial_session(r != -2);
    }

    session_poll((void **)&txdata, &txlen);
    if(txlen > 0) {
        for(i = 0; i < txlen; i++)
            uart_write(txdata[i]);
        session_ack_consumed(txlen);
        session_ack_sent(txlen);
    } else if(txlen < 0) {
        reset_serial_session(1);
    }
}
Exemple #22
0
int platform_uart_recv( unsigned id, unsigned timer_id, int timeout )
{
  timer_data_type tmr_start, tmr_crt;
  int res;
    
  if( timeout == 0 )
  {
    // Return data only if already available
    return uart_read_nb();
  }
  else if( timeout == PLATFORM_UART_INFINITE_TIMEOUT )
  {
    // Wait for data
    return uart_read();
  }
  else
  {
    // Receive char with the specified timeout
    tmr_start = platform_timer_op( timer_id, PLATFORM_TIMER_OP_START,0 );
    while( 1 )
    {
      if( ( res = uart_read_nb() ) > 0 )
        break;
      tmr_crt = platform_timer_op( timer_id, PLATFORM_TIMER_OP_READ, 0 );
      if( platform_timer_get_diff_us( timer_id, tmr_crt, tmr_start ) >= timeout )
        break;
    }
    return res;    
  }  
}
Exemple #23
0
int main (void)
{
	sysclk_init();
	wdt_disable(WDT);
	initLeds();
//	rumblecationInit();
	uartInit();

	
	volatile int i;
	
	while(1) {
		//uart_write(UART0, 's');
		//i++;
		/*if(transmitBufRead != transmitBufWrite) {
			uart_write(UART0, transmitBuf[transmitBufRead]);
			transmitBufRead++;
		}*/
		if(uart_is_rx_ready(UART0)) {
			uint8_t in;
			uart_read(UART0, &in);
			uart_write(UART0, in);
		}
	}

}
Exemple #24
0
char
uart_getc(void)
{

	while (!uart_readable());
	return (uart_read());
}
Exemple #25
0
/*
Function that receives a complete ascii frame and stores address, function code and data.
*/
int modbusRS485_recv(u_char *address, u_char *function, u_char *data, uint8_t* nbytes)
{
	
	u_char asciiFrameBuffer[MAX_ASCIIFRAME_SIZE] , *ptr = NULL;
	u_char frameLRCByte = 0;

	int status = MODBUS_SUCCESS,num_bytes;
	u_char i,j;
	 ptz_write(RS485_DEVICE_READ_MODE);
	memset( asciiFrameBuffer,'\0', sizeof(asciiFrameBuffer));
	num_bytes = uart_read(rs485port,asciiFrameBuffer,MAX_ASCIIFRAME_SIZE );
	
	if(num_bytes < 0  )
	{	status = num_bytes;

	} 
	else if(num_bytes == 13)  {
		status = decode_recv_data(asciiFrameBuffer,address,function ,data,nbytes,num_bytes) ;
	}
	else 
	{		
		status = decode_recv_data(asciiFrameBuffer,address,function ,data,nbytes,num_bytes) ;
        }


    //  ptz_write(RS485_DEVICE_WRITE_MODE);
	#if MODBUS_DEBUG
	printf("Rx:\t");
	hex_dump(*address, *function, data, *nbytes);
	#endif
	return status;
}
Exemple #26
0
/**
 * \brief Set AFEC resolution mode.
 */
static void set_afec_resolution(void)
{
	uint8_t uc_key;
	uint8_t uc_done = 0;

	display_menu();

	while (!uc_done) {
		while (uart_read(CONF_UART, &uc_key));

		switch (uc_key) {
		case 'n':
			g_max_digital = MAX_DIGITAL_12_BIT;
			afec_set_resolution(AFEC0, AFEC_12_BITS);
			puts(" Set Resolution to Normal \n\r");
			break;
		case 'e':
			g_max_digital = MAX_DIGITAL_12_BIT * 16;
			afec_set_resolution(AFEC0, AFEC_16_BITS);
			puts(" Set Resolution to Enhanced \n\r");
			break;
		case 'q':
			uc_done = 1;
			puts(" Quit Configuration \n\r");
			break;
		default:
			break;
		}
	}
}
/* Wait for nack or ack response */
int wait_for_ask(void){
    /* wait for ask */
    time_sleep(0.2); //need this in here :(
    unsigned char ask = uart_read();
    /* TODO: what to do if timeout? */
    if(uart_timeout()){
        /* Timeout handler here */
    handle_error(TIMEOUT_ERROR);
        return 0;
    }
    else{
        if(ask == 0x79){
            /* ACK */
            return 1;
        }
        else{
            if(ask == 0x1F){
                /* NACK */
                /* TODO: how are we going to handle nack? */
                handle_error(NACK_ERROR);
                return 0;
            }
            else{
                /* Unknown response */
                /* TODO: how are we going to handle unknown response */
        handle_error(UNKNOWN_ERROR);
                return 0;
            }
        }
    }
    return 0; /* should not get here */
}
Exemple #28
0
/*! Read from UART (using software buffer) */
static int uart_recv ( void *data, size_t size, uint flags, device_t *dev )
{
	arch_uart_t *up;
	uint8 *d;
	int i;

	ASSERT ( dev );

	up = dev->params;

	/* first, copy from uart to software buffer */
	uart_read ( up );

	/* second, copy from software buffer to data */
	d = data;
	i = 0;
	while ( i < size && up->insz > 0 )
	{
		d[i] = up->inbuff[up->inf];
		INC_MOD ( up->inf, up->inbufsz );
		up->insz--;
		i++;
	}

	return i; /* bytes read */
}
Exemple #29
0
int main(int argc, char *argv[])
{

	unsigned long count;
	count = 0;
	int temp = 0;
	int i =0 ;       
	int reset = 0;
	int bd = atoi(argv[1]);
        int dc1 = atoi(argv[2]);
        int dc2 = atoi(argv[3]);

	baud_rate = bd;
	printf("bd is set to %d\n",baud_rate);
	ptz_init();
	ptz_write(RS485_DEVICE_WRITE_MODE);
	status = uart_init(UART_PORT) ;
	printf("\n V.2.2: delay: %d \n",dc1);
	if(status <= 0 )
	{
                printf("\nmodbusRS485_init: uart_init failed:%d \n",status);
                return  FAILURE;
        }
		dc2 =dc2*1000;
		dc1 =dc1*1000;
	printf("Delay set is Before write %d \t after write %d \n",dc1,dc2);
	while(1)
	{
//	ptz_write(RS485_DEVICE_WRITE_MODE);
          //      usleep(dc);
#if 1
	status = uart_write(UART_PORT,r2,11);
	if(status < SUCCESS){
                printf("\nsensor write failed Error:%d \n ",status);
                status = FAILURE;
         }
	usleep(dc1);
#endif
	ptz_write(RS485_DEVICE_READ_MODE);
     // usleep(dc2);
#if 1 
	temp = uart_read(UART_PORT,buffer_t1, 1);
         if(temp > 0){
		printf("\nbuff contains : \n");
		  for(i = 0; i <= temp; i++)
			  printf("\t%c\t ",buffer_t1[i]);
	 }
	 else{
		printf("uart read : error %d \n",temp);
	}

     #endif 
//	usleep(500);
//	ptz_write(RS485_DEVICE_WRITE_MODE);
	sleep(1);
	printf("\n ++ %d \n",++tp);


	}
}
int main()
{
uart_init();
rf_init();
DDRD=0xF0;
while(1)
 {

	switch(uart_read())
	{
	case 'F':
	    rf_transmit_B(5,2,0x50);
	    break;
	case 'B':
	    rf_transmit_B(5,2,0xA0);
	    break;
	case 'R':
	    rf_transmit_B(5,2,0x40);
	    break;
	case 'L':
	    rf_transmit_B(5,2,0x10);
	    break;
	case 'S':
	    rf_transmit_B(5,2,0x00);
	    break;
	}
	 delayms(10);	
 }
}