示例#1
0
int main(void)
{
    uint8_t buf[256], byte;

    DDRB = _BV(DDB1) | _BV(DDB2);
        
    usart_init(STUART_UBRR);

    for(;;) {
        volatile int i, j;

        PORTB = _BV(PB1);
        
        for(i = 0; (byte = usart_recieve_byte()) != '\0'; i++) {            
            buf[i] = byte;
            PORTB = ~PORTB;
        }
        buf[i++] = '1';
        buf[i++] = '2';
        buf[i++] = '3';
        buf[i++] = '\0';

        for(j = 0; j < i; j++) {
            usart_send_byte(buf[j]);
            PORTB = ~PORTB;
        }

        PORTB = 0;
        _delay_ms(1000);
    }

    return 0;
}
示例#2
0
/**
 * @brief Shell loop.
 * Wait for commands in command_queue, run it, report command run status via usart tty.
 */
void shell_run()
{
	char local_command[CMD_SIZE];
	queue_init(&command_queue);

	usart_send_str("************************************\r\n");
	usart_send_str("Welcome to Neuraxis shell\r\n");
	usart_send_str("************************************\r\n>");

	while(1) {
		if( !queue_is_empty(&command_queue) ) {
			strcpy(local_command, queue_dequeue(&command_queue));
			cmd_status_t status = cmd_run(local_command);
			if(status == CMD_SUCCESSFUL ) {
				usart_send_str("Command '");
				usart_send_str(local_command);
				usart_send_str("' successfully executed\r\n");
			}
			else
			{
				usart_send_str("Command '");
				usart_send_str(local_command);
				usart_send_str("' can't be executed\r\n");
			}

			usart_send_byte((uint8_t) '>');
		}
		else {
			__WFI();
		}
	}

}
示例#3
0
void send_buf() 
{
    uint8_t i;

    for(i = 0; i < 16; ++i) {
        usart_send_byte(buf[i]);
    }
}
int main(void)
{
	//char *msg = " There be dragons ";
	char *msg = ".";
	
	struct usart_dev *ser0 = usart_init(USART_0,
					    9600, 
					    USART_BITS_8,
					    USART_STOPBITS_1,
					    USART_PARITY_NONE,
					    0);

	struct usart_dev *ser1 = usart_init(USART_1,
					    19200, 
					    USART_BITS_8,
					    USART_STOPBITS_1,
					    USART_PARITY_NONE,
					    0);
	for (;;) {
		char r[5];
		usart_send_byte(ser0, '0');
		usart_send_byte(ser1, '1');
/*
		r[0] = *ser0->ucsra;
		r[1] = *ser0->ucsrb;
		r[2] = *ser0->ucsrc;
		usart_send_bytes(ser0, r, 3);
		r[0] = *ser1->ubrrh;
		r[1] = *ser1->ubrrl;
		usart_send_bytes(ser1, r, 2);

*/

		if (usart_data_available(ser0)) {
			char b = usart_read(ser0);
			usart_send_byte(ser0, '+');
			usart_send_byte(ser0, b);
		}

		if (usart_data_available(ser1)) {
			char b = usart_read(ser1);
			usart_send_byte(ser1, '-');
			usart_send_byte(ser1, b);
		}

		_delay_ms(10);
	}
}
示例#5
0
/**
 * UART2 Receive hander.
 * Shell implementation. This function (handler) fill command queue by new valid command received
 * from UART2.
 */
void  USART2_IRQHandler()
{
	static char buffer[CMD_SIZE];
	static uint16_t char_number;
	static uint8_t received_byte;

	received_byte = USART2->DR;
	USART2->DR = USART2->DR;

	if(  ( char_number+1 )> ( CMD_SIZE-2 ) ) {
		char_number=0;
		usart_send_str("Exceed command line limit (63 chars)\r\n>");
		usart_send_str("\n\r>");
	} else {
		buffer[char_number] = received_byte;
		if( (char)received_byte == '\b') {
			if(char_number-1>-1)
				char_number--;
			else
				usart_send_byte((uint8_t)'>');

		} else if( (char) received_byte == '\n' ) {
			buffer[char_number]='\0'; //set end of null terminated string

			if (!cmd_check(buffer))
				usart_send_str("\n\rUndefined command\n\r");
			else {
				usart_send_str("\n\rCommand enqueued\n\r");
				queue_enqueue(&command_queue, buffer);
			}

			usart_send_str("\n\r>");
			char_number=0;
		} else {
			char_number++;
		}
	}
	USART_ClearITPendingBit(USART2, USART_IT_RXNE);
}
示例#6
0
void serial_send_char(char c) {
    usart_send_byte(c);
}
void usart_send_string(struct usart_dev *dev, const char *bytes)
{
	char c;
	while ((c = *bytes++))
		usart_send_byte(dev, c);
}
void usart_send_bytes(struct usart_dev *dev, const char *bytes, uint16_t len)
{
	uint16_t i;
	for (i=0; i<len; i++)
		usart_send_byte(dev, bytes[i]);
}