Где-то скопипастил, но ключевые моменты понять можно, правда код для АВРок, но не думаю что для АРМ он будет сильно отличаться.
Это заголовочный файл, тела методов описаны в соответствующем .cpp файле.
CODE
/// pp.debski@gmail.com
/// Debug with uart c++ example for ATmega88.
/// It's always possible to buy me a beer or two :-).
#ifndef _C_UART_H_
#define _C_UART_H_
#include <avr/interrupt.h>
extern "C" void USART2_TX_vect(void) __attribute__ ((signal));
extern "C" void USART2_RX_vect(void) __attribute__ ((signal));
/// You should definitely change this values.
/// They're correct only for ~8.8MHz and 9600 b/s baud rate.
//#define UBRR0H_9600 0
//#define UBRR0L_9600 47
/// UART class.
class C_UART
{
private:
/// Data to send.
char* pTxBuffer;
/// Buffer for received data.
char* pRxBuffer;
/// Transmitter data counter and data size. When equals - transmiter is ready to send new data.
volatile unsigned int uiTxCounter;
volatile unsigned int uiTxSize;
/// Receiver data counter and data size. When equals - transmiter is ready to send new data.
volatile unsigned int uiRxCounter;
volatile unsigned int uiRxSize;
/// Static pointer used in interrupts routines.
static C_UART* pUart;
public:
/// Setting up UART registers.
void Init(void);
/// Sending data.
bool Send(char* pBuffer, unsigned int uiSize);
/// Receiving data.
bool Receive(char* pBuffer, unsigned int uiSize);
/// Checks if transmitter is ready to send new data.
bool IsTxReady(void)
{
return !uiTxSize;
}
/// Checks if receiver is ready to send new data.
bool IsRxReady(void)
{
return !uiRxSize;
}
/// Setting static pUart pointer.
C_UART()
{
pUart = this;
}
/// Interrupt routines.
friend void USART2_TX_vect(void);
friend void USART2_RX_vect(void);
};
#endif