3 Copyright (C) Dean Camera, 2012.
\r
5 dean [at] fourwalledcubicle [dot] com
\r
10 Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)
\r
12 Permission to use, copy, modify, distribute, and sell this
\r
13 software and its documentation for any purpose is hereby granted
\r
14 without fee, provided that the above copyright notice appear in
\r
15 all copies and that both that the copyright notice and this
\r
16 permission notice and warranty disclaimer appear in supporting
\r
17 documentation, and that the name of the author not be used in
\r
18 advertising or publicity pertaining to distribution of the
\r
19 software without specific, written prior permission.
\r
21 The author disclaim all warranties with regard to this
\r
22 software, including all implied warranties of merchantability
\r
23 and fitness. In no event shall the author be liable for any
\r
24 special, indirect or consequential damages or any damages
\r
25 whatsoever resulting from loss of use, data or profits, whether
\r
26 in an action of contract, negligence or other tortious action,
\r
27 arising out of or in connection with the use or performance of
\r
31 #include "../../../Common/Common.h"
\r
32 #if (ARCH == ARCH_XMEGA)
\r
34 #define __INCLUDE_FROM_SERIAL_C
\r
35 #include "../Serial.h"
\r
37 FILE USARTSerialStream;
\r
39 int Serial_putchar(char DataByte,
\r
42 USART_t* USART = fdev_get_udata(Stream);
\r
44 Serial_SendByte(USART, DataByte);
\r
48 int Serial_getchar(FILE *Stream)
\r
50 USART_t* USART = fdev_get_udata(Stream);
\r
52 if (!(Serial_IsCharReceived(USART)))
\r
55 return Serial_ReceiveByte(USART);
\r
58 int Serial_getchar_Blocking(FILE *Stream)
\r
60 USART_t* USART = fdev_get_udata(Stream);
\r
62 while (!(Serial_IsCharReceived(USART)));
\r
63 return Serial_ReceiveByte(USART);
\r
66 void Serial_SendString_P(USART_t* const USART,
\r
67 const char* FlashStringPtr)
\r
71 while ((CurrByte = pgm_read_byte(FlashStringPtr)) != 0x00)
\r
73 Serial_SendByte(USART, CurrByte);
\r
78 void Serial_SendString(USART_t* const USART,
\r
79 const char* StringPtr)
\r
83 while ((CurrByte = *StringPtr) != 0x00)
\r
85 Serial_SendByte(USART, CurrByte);
\r
90 void Serial_SendData(USART_t* const USART,
\r
91 const uint8_t* Buffer,
\r
95 Serial_SendByte(USART, *(Buffer++));
\r
98 void Serial_CreateStream(FILE* Stream)
\r
102 Stream = &USARTSerialStream;
\r
107 *Stream = (FILE)FDEV_SETUP_STREAM(Serial_putchar, Serial_getchar, _FDEV_SETUP_RW);
\r
110 void Serial_CreateBlockingStream(FILE* Stream)
\r
114 Stream = &USARTSerialStream;
\r
119 *Stream = (FILE)FDEV_SETUP_STREAM(Serial_putchar, Serial_getchar_Blocking, _FDEV_SETUP_RW);
\r