Пример #1
0
size_t printf(const char *format, ...) {
    va_list ap;
    size_t count = 0;

    va_start(ap, format);
    for (count = 0; *format != '\0'; ++format) {
        if (*format == '%') {
            switch (*++format) {
                case 'c':
                    count += transmit_char(va_arg(ap, int));
                    break;

                case 's':
                    count += transmit_string(va_arg(ap, char *));
                    break;

                case 'u':
                    count += transmit_unsigned(va_arg(ap, unsigned));
                    break;

                default:
                    count += transmit_char(*format);
                    break;
            }
        } else {
            count += transmit_char(*format);
        }
    }
Пример #2
0
static void transmit_chars(struct uart_port *up)
{
	struct circ_buf *xmit = &up->info->xmit;
	int count,written;
	unsigned short *txptr;
	unsigned short s;

	txptr=dpram_data.data_virt;

	if (up->x_char) {
		dprintk("x_char\n");
		*txptr=up->x_char;
		REG0=(REG0&0xfe00)|1;
		dpram_req1();
		up->icount.tx++;
		up->x_char = 0;
		return;
	}
	if (uart_circ_empty(xmit) || uart_tx_stopped(up)) {
		dpram_stop_tx(up);
		return;
	}

	dprintk("REG0=0x%x\n", REG0);
	count = 255;
	written=0;
	do {
		s=transmit_char(up, xmit);
		written++;
		if (! uart_circ_empty(xmit)) {
			s |= (transmit_char(up, xmit) << 8);
			written++;
		}
		dprintk("transmitting 0x%x\n", s);
		*txptr++=s;
		if (uart_circ_empty(xmit))
			break;
	} while (--count > 0);
	dprintk("written %d\n", written);
	REG0=(REG0&0xfe00)|(written & 0x1ff);
	dpram_req1();
	
	if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
		uart_write_wakeup(up);

	if (uart_circ_empty(xmit))
		dpram_stop_tx(up);
}
Пример #3
0
static int max3110_main_thread(void *_max)
{
	struct uart_max3110 *max = _max;
	wait_queue_head_t *wq = &max->wq;
	int ret = 0;
	struct circ_buf *xmit = &max->con_xmit;

	init_waitqueue_head(wq);
	pr_info(PR_FMT "start main thread\n");

	do {
		wait_event_interruptible(*wq, max->uart_flags || kthread_should_stop());

		mutex_lock(&max->thread_mutex);

		if (test_and_clear_bit(BIT_IRQ_PENDING, &max->uart_flags))
			max3110_console_receive(max);

		/* first handle console output */
		if (test_and_clear_bit(CON_TX_NEEDED, &max->uart_flags))
			send_circ_buf(max, xmit);

		/* handle uart output */
		if (test_and_clear_bit(UART_TX_NEEDED, &max->uart_flags))
			transmit_char(max);

		mutex_unlock(&max->thread_mutex);

	} while (!kthread_should_stop());

	return ret;
}
Пример #4
0
void transmit_str(unsigned char* str)
{
    int i=0;
    while(str[i] != '\0')
    {
       transmit_char(str[i]);
        
       i++;
    }
}
Пример #5
0
void transmit_decimal(s32 n)
{
	if(n == 0) {
		transmit_string("0\r\n");
	}
	else
	{
		char buffer[16];
		char *p = buffer;
		while(n > 0) {
			*p = '0' + (n%10);
			++p;
			n/=10;
		}
		while(p != buffer) {
			transmit_char(*--p);
		}
		transmit_string("\r\n");
	}

}
Пример #6
0
void transmit_hexadecimal(unsigned char n)
{
	if(n == 0) {
		transmit_string("0x00\r\n");
	}
	else
	{
		transmit_string("0x");
		char buffer[4];
		char *p = buffer;
		while(n > 0) {
			*p = '0' + (n%16);
			++p;
			n/=16;
		}
		while(p != buffer) {
			transmit_char(*--p);
		}
		transmit_string("\r\n");
	}

}
Пример #7
0
int main( void )
{
    
    system_init();
    lcd_init();
    uart_init();
    timer_init();
    
    DDRA_Bit3=1;
    PORTA_Bit3=0;
    
    __enable_interrupt(); 
    
	write_str("  Traffic counter                       Nagy Krisztina 2013");
    d_1s();
    d_1s();
    d_1s();   
    
    ptr_lcd=0;
	write_str("People IN:          ");
    write_str("                    ");
	write_str("Total traffic:      ");
    write_str("                    ");
    
    while(1)
    {
        if(flag1==1)
        {
            timer1=1000;
            flag1=0;
        }
        if(flag2==1)
        {
            timer2=1000;
            flag2=0;
        }
   
        if((timer1>0 && timer2>0) && (timer2 > timer1))
        {
            people_in++;
            people_all++;
            flag1=0;
            flag2=0;
            timer1=0;
            timer2=0;
            
            /*write to LCD*/
            write_num_on_lcd();
                
            
        }
        if((timer1>0 && timer2>0) && (timer1 > timer2))
        {
            if(people_in)
            {
                people_in--;
            }
            flag1=0;
            flag2=0;
            timer1=0;
            timer2=0;
            
            /*write to LCD*/
            write_num_on_lcd();
        }
        
        if(flag_button1==1)
        {
            people_in=0;
            write_num_on_lcd();
            flag_button1=0;
        }
        if(flag_button2==1)
        {
            transmit_str("Number of people in the room:");
            transmit_char(lcd[16]);
            transmit_char(lcd[17]);
            transmit_char(lcd[18]);
            transmit_char(lcd[19]);
            transmit_char((char)13);
            
            transmit_str("Total traffic:");
            transmit_char(lcd[36]);
            transmit_char(lcd[37]);
            transmit_char(lcd[38]);
            transmit_char(lcd[39]);
            transmit_char((char)13);
            
            flag_button2=0;
        } 
    }
    
}