Rev Author Line No. Line
615 kaklik 1 #ifndef __usart_h__
2 #define __usart_h__
3  
4 #include "common.h"
5  
6 namespace USART0 {
7 // setting = f_osc/16/BAUD - 1
8 const uint16_t baud9600_8MHz = 51;
9 const uint16_t baud19200_8MHz = 25;
10 const uint16_t baud57600_8MHz = 8;
11 const uint16_t baud19200_6_14MHz = 19;
12 const uint16_t baud38400_6_14MHz = 9;
13 const uint16_t baud19200_6_5MHz = 20;
14 const uint16_t baud38400_6_5MHz = 10;
15 const uint16_t baud57600_6_5MHz = 6;
16 inline uint8_t FastReceiveData();
17 inline void Init(uint16_t aBaudSetting) {
18 UBRR0 = aBaudSetting;
19 UCSR0A = 0;
20 FastReceiveData(); // Clear any possible pending input data (to avoid spurious IRQ
21 UCSR0B = (1 << RXCIE0) | (1 << RXEN0) | (1 << TXEN0);
22 UCSR0C = (1 << USBS0) | (3 << UCSZ00);
23 }
24 void SendData(uint8_t aData);
25 uint8_t ReceiveData();
26 inline void FastSendData(uint8_t aData) {
27 UDR0 = aData;
28 }
29 inline uint8_t FastReceiveData() {
30 return UDR0;
31 }
32 void SendHexData(uint8_t aData);
33 void SendHexData(uint16_t aData);
34 void SendHexData(uint32_t aData);
35 void SendHexData(int16_t aData);
36 void SendHexData(int32_t aData);
37 void SendString(const char *aString);
38 void SendPGString(const char *aString);
39 }
40  
41 #endif // __usart_h__