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);
	}
}
int HardwareSerial::read(void) {
	if(usart_data_available(usart_device) > 0) {
		return usart_getc(usart_device);
	} else {
		return -1;
	}
}
Example #3
0
/**
 * @brief Nonblocking USART receive.
 * @param dev Serial port to receive bytes from
 * @param buf Buffer to store received bytes into
 * @param len Maximum number of bytes to store
 * @return Number of bytes received
 */
uint32 usart_rx(usart_dev *dev, uint8 *buf, uint32 len) {
    uint32 rxed = 0;

    while (usart_data_available(dev) && rxed < len) {
        *buf++ = usart_getc(dev);
        rxed++;
    }
    return rxed;
}
/*-----------------------------------------------------------------vSerialTask()
 *
 * Handle (usb/serial) from console and monitored device. 
 * The idea here is to handle the incoming characters as quickly as possible. 
 * All data coming from the console or the datalogger
 * is delimited by <CR><LF>. Finding an end of line "gives" a semaphore.
 * 
 * eventually this should be moved down to the 
 */
static void vSerialTask(void* pvParameters)
{
    portTickType xLastWakeTime = xTaskGetTickCount();
    const portTickType xWakePeriod = 50;
    
    usart_init(USART1);
    usart_set_baud_rate(USART1, USART_USE_PCLK, 9600);
    usart_enable(USART1);
    deviceComm.len=0;
    deviceComm.gotline=false;
    vSemaphoreCreateBinary( deviceComm.xGotLineSemaphore );
    //if( deviceComm.xGotLineSemaphore == NULL )
    //{ // FREAK OUT!!!
    //}
    consoleComm.len=0;
    consoleComm.gotline=false;
    vSemaphoreCreateBinary( consoleComm.xGotLineSemaphore );
    //if( consoleComm.xGotLineSemaphore == NULL )
    //{ // FREAK THE HELL OUT!!!
    //}
    
    
    //    usart_init(USART2);
    //    usart_set_baud_rate(USART2, USART_USE_PCLK, 9600);
    //    usart_enable(USART2);
    
    while (true)
    {   
        togglePin(YEL_LED);
        uint32_t rc=0;
        unsigned char ch;
#if 0        
        if (!deviceComm.gotline) {
            //rc=usart_data_available(USART1);
            while (usart_data_available(USART1) 
                   && deviceComm.len<(MAX_COMMAND_LINE_LENGTH-1)) {
                ch=usart_getc(USART1);
                
                if (ch=='\r') {  
                    deviceComm.gotline=true;
                    deviceComm.line[deviceComm.len]='\0';
                    //xSemaphoreGive(deviceComm.xGotLineSemaphore);
                    break;
                } else if (ch!='\n') {
                    deviceComm.line[deviceComm.len++]=ch;
                }
            }
        }
#endif       
        if (!consoleComm.gotline) {
            while(SerialUSB.isConnected() && SerialUSB.available()
                  && consoleComm.len<(MAX_COMMAND_LINE_LENGTH-1)) {
                ch=SerialUSB.read();
                SerialUSB.write(ch);
                if (ch=='\r') {  
                    consoleComm.gotline=true;
                    consoleComm.line[consoleComm.len]='\0';
                    //xSemaphoreGive(consoleComm.xGotLineSemaphore);
                    break;
                } else if ((ch==ASCII_DELETE) || (ch==ASCII_BACKSPACE)) {
                    if (consoleComm.len) consoleComm.len--;
                } else if (ch!='\n') {
                    consoleComm.line[consoleComm.len++]=ch;                    
                }
            }
        }

        vTaskDelayUntil(&xLastWakeTime, xWakePeriod);
        
    }
}
int HardwareSerial::available(void) {
    return usart_data_available(this->usart_device);
}
Example #6
0
int UARTClass::available( void )
{
    return usart_data_available(this->_dev);
}
char usart_read_wait(struct usart_dev *dev)
{
	while (!(usart_data_available(dev))) 
		;
	return *dev->udr;
}
Example #8
0
uint32 HardwareSerial::available(void) {
    return usart_data_available(usart_device);
}
uint32 HardwareSerialFlowControl::available(void) {
    return usart_data_available(this->usart_device);
}
Example #10
0
uint32 gps_available(void){
    return usart_data_available(GPS_USART);
}
Example #11
0
int FastSerial::available(void) {
    return usart_data_available(this->usart_device);
}