3      Copyright (C) Dean Camera, 2009. 
   5   dean [at] fourwalledcubicle [dot] com 
   6       www.fourwalledcubicle.com 
  10   Copyright 2009  Dean Camera (dean [at] fourwalledcubicle [dot] com) 
  12   Permission to use, copy, modify, and distribute this software 
  13   and its documentation for any purpose and without fee is hereby 
  14   granted, provided that the above copyright notice appear in all 
  15   copies and that both that the copyright notice and this 
  16   permission notice and warranty disclaimer appear in supporting 
  17   documentation, and that the name of the author not be used in 
  18   advertising or publicity pertaining to distribution of the 
  19   software without specific, written prior permission. 
  21   The author disclaim all warranties with regard to this 
  22   software, including all implied warranties of merchantability 
  23   and fitness.  In no event shall the author be liable for any 
  24   special, indirect or consequential damages or any damages 
  25   whatsoever resulting from loss of use, data or profits, whether 
  26   in an action of contract, negligence or other tortious action, 
  27   arising out of or in connection with the use or performance of 
  33  *  Driver for the USART subsystem on supported USB AVRs. 
  41                 #include <avr/pgmspace.h> 
  44                 #include "../../Common/Common.h" 
  45                 #include "../Misc/TerminalCodes.h" 
  47         /* Enable C linkage for C++ Compilers: */ 
  48                 #if defined(__cplusplus) 
  52         /* Public Interface - May be used in end-application: */ 
  54                         /** Indicates whether a character has been received through the USART - boolean false if no character 
  55                          *  has been received, or non-zero if a character is waiting to be read from the reception buffer. 
  57                         #define Serial_IsCharReceived() ((UCSR1A & (1 << RXC1)) ? true : false) 
  59                         /** Macro for calculating the baud value from a given baud rate when the U2X (double speed) bit is 
  62                         #define SERIAL_UBBRVAL(baud)    (((F_CPU / 16) / baud) - 1) 
  64                         /** Macro for calculating the baud value from a given baud rate when the U2X (double speed) bit is 
  67                         #define SERIAL_2X_UBBRVAL(baud) (((F_CPU / 8) / baud) - 1) 
  69                 /* Function Prototypes: */ 
  70                         /** Initializes the USART, ready for serial data transmission and reception. 
  72                          *  \param BaudRate     Baud rate to configure the USART to 
  73                          *  \param DoubleSpeed  Enables double speed mode when set, halving the sample time to double the baud rate 
  75                         void Serial_Init(const uint32_t BaudRate
, const bool DoubleSpeed
); 
  77                         /** Transmits a given string located in program space (FLASH) through the USART. 
  79                          *  \param FlashStringPtr  Pointer to a string located in program space 
  81                         void Serial_TxString_P(const char *FlashStringPtr
) ATTR_NON_NULL_PTR_ARG(1); 
  83                         /** Transmits a given string located in SRAM memory through the USART. 
  85                          *  \param StringPtr  Pointer to a string located in SRAM space 
  87                         void Serial_TxString(const char *StringPtr
) ATTR_NON_NULL_PTR_ARG(1); 
  89                 /* Inline Functions: */ 
  90                         /** Transmits a given byte through the USART. 
  92                          *  \param DataByte  Byte to transmit through the USART 
  94                         static inline void Serial_TxByte(const char DataByte
) 
  96                                 while (!(UCSR1A 
& (1 << UDRE1
))); 
 100                         /** Receives a byte from the USART. 
 102                          *  \return Byte received from the USART 
 104                         static inline char Serial_RxByte(void) 
 106                                 while (!(UCSR1A 
& (1 << RXC1
))); 
 110         /* Disable C linkage for C++ Compilers: */ 
 111                 #if defined(__cplusplus)