#include <ccommunicationuart.h>


Public Member Functions | |
| CCommunicationUART (CMachine::InterruptVector vector, UART_TypeDef *UARTx, CMachine::ubit32 baud=9600) | |
| void | disableTxInterrupts () |
| enables or disables transmitter interrutpts. | |
| void | enableTxInterrupts () |
| enables or disables transmitter interrutpts. | |
| virtual void | irq (CMachine::InterruptVector v) |
| receive a hardware interrupt. | |
| void | setBaud (CMachine::ubit32 baud) |
| set the baud rate. | |
| void | setLoopBack (bool enabled=true) |
| enables or disables loopback test mode. | |
| virtual CMachine::ubit8 | tx (CMachine::ubit8 ch) |
| transmit a single byte - may yield CPU time if transmitter ring buffer is full. | |
| virtual | ~CCommunicationUART () |
Private Attributes | |
| UART_TypeDef * | mUART |
Definition at line 32 of file ccommunicationuart.h.
| PikeAero::CCommunicationUART::CCommunicationUART | ( | CMachine::InterruptVector | vector, | |
| UART_TypeDef * | UARTx, | |||
| CMachine::ubit32 | baud = 9600 | |||
| ) |
Install self into interupt vector
Stop and Initialize the UART
Choose 8N1, enable rx, enable FIFOs, enable uart
Reset the FIFOs
Configure BaudRate
Set the timeout register
Set interrupt enable mask
Disable transmitter interrupts until we have some data to transmit...
Definition at line 27 of file ccommunicationuart.cpp.
References PikeAero::UART_TypeDef::CR, disableTxInterrupts(), PikeAero::UART_TypeDef::IER, PikeAero::CMachine::installVectorIRQ(), mUART, PikeAero::UART_TypeDef::RxRSTR, setBaud(), PikeAero::UART_TypeDef::TOR, PikeAero::UART_TypeDef::TxRSTR, UART_FIFO, UART_IT_FrameError, UART_IT_OverrunError, UART_IT_ParityError, UART_IT_RxBufNotEmpty, UART_IT_RxHalfFull, UART_IT_TimeOutNotEmpty, UART_Mode_8D, UART_RUN, UART_Rx_EN, UART_RxFIFO, UART_StopBits_1, and UART_TxFIFO.
00028 : inherited() 00029 , mUART(UARTx) 00030 { 00031 /** Install self into interupt vector */ 00032 CMachine::installVectorIRQ(vector,this); 00033 00034 /** Stop and Initialize the UART */ 00035 mUART->IER = 0; 00036 mUART->CR = 0; 00037 /** Choose 8N1, enable rx, enable FIFOs, enable uart */ 00038 mUART->CR = ( UART_Mode_8D | UART_StopBits_1 | UART_Rx_EN | UART_FIFO | UART_RUN ); 00039 /** Reset the FIFOs */ 00040 mUART->TxRSTR = UART_TxFIFO; 00041 mUART->RxRSTR = UART_RxFIFO; 00042 /** Configure BaudRate */ 00043 setBaud( baud ); 00044 /** Set the timeout register */ 00045 mUART->TOR = 0x00FF; 00046 /** Set interrupt enable mask */ 00047 mUART->IER = ( UART_IT_RxHalfFull | UART_IT_OverrunError | UART_IT_FrameError | UART_IT_ParityError | UART_IT_RxBufNotEmpty | UART_IT_TimeOutNotEmpty ); 00048 /** Disable transmitter interrupts until we have some data to transmit... */ 00049 disableTxInterrupts(); 00050 00051 }

| PikeAero::CCommunicationUART::~CCommunicationUART | ( | ) | [virtual] |
Reset the FIFOs
Stop and Initialize the UART
Remove self from interrupt vector
Definition at line 53 of file ccommunicationuart.cpp.
References PikeAero::UART_TypeDef::CR, PikeAero::UART_TypeDef::IER, mUART, PikeAero::CMachine::removeVectorIRQ(), PikeAero::UART_TypeDef::RxRSTR, PikeAero::UART_TypeDef::TxRSTR, UART_RxFIFO, and UART_TxFIFO.
00054 { 00055 /** Reset the FIFOs */ 00056 mUART->TxRSTR = UART_TxFIFO; 00057 mUART->RxRSTR = UART_RxFIFO; 00058 /** Stop and Initialize the UART */ 00059 mUART->IER = 0; 00060 mUART->CR = 0; 00061 00062 /** Remove self from interrupt vector */ 00063 CMachine::removeVectorIRQ(this); 00064 }

| void PikeAero::CCommunicationUART::disableTxInterrupts | ( | ) | [inline] |
enables or disables transmitter interrutpts.
Definition at line 70 of file ccommunicationuart.h.
References PikeAero::UART_TypeDef::IER, mUART, UART_IT_TxEmpty, and UART_IT_TxHalfEmpty.
Referenced by CCommunicationUART(), and irq().
00071 { 00072 mUART->IER &= ~( UART_IT_TxEmpty | UART_IT_TxHalfEmpty ); 00073 }

| void PikeAero::CCommunicationUART::enableTxInterrupts | ( | ) | [inline] |
enables or disables transmitter interrutpts.
Definition at line 62 of file ccommunicationuart.h.
References PikeAero::UART_TypeDef::IER, mUART, UART_IT_TxEmpty, and UART_IT_TxHalfEmpty.
Referenced by tx().
00063 { 00064 mUART->IER |= ( UART_IT_TxEmpty | UART_IT_TxHalfEmpty ); 00065 }

| void PikeAero::CCommunicationUART::irq | ( | CMachine::InterruptVector | v | ) | [virtual] |
receive a hardware interrupt.
receive a hardware interrupt.g
RX data ...
TX data ...
Reimplemented from PikeAero::CObject.
Definition at line 92 of file ccommunicationuart.cpp.
References disableTxInterrupts(), PikeAero::CRingBuffer::insert(), mUART, PikeAero::CRingBuffer::remove(), PikeAero::UART_TypeDef::RxBUFR, PikeAero::CCommunication::rxRingBuffer(), PikeAero::UART_TypeDef::SR, PikeAero::UART_TypeDef::TxBUFR, PikeAero::CCommunication::txRingBuffer(), UART_SR_FrameError, UART_SR_ParityError, UART_SR_RxBufNotEmpty, UART_SR_TimeOutNotEmpty, and UART_SR_TxFull.
00093 { 00094 /** RX data ... */ 00095 while ( (mUART->SR & (UART_SR_RxBufNotEmpty | UART_SR_FrameError | UART_SR_ParityError | UART_SR_TimeOutNotEmpty)) != 0 && !rxRingBuffer()->full() ) 00096 { 00097 CMachine::ubit16 ch = mUART->RxBUFR; 00098 if ( (ch & 0x0200) == 0 ) /* if no framing error... */ 00099 { 00100 rxRingBuffer()->insert((CMachine::ubit8)(ch&0x00FF)); 00101 } 00102 } 00103 00104 /** TX data ... */ 00105 while ( ((mUART->SR & UART_SR_TxFull) == 0) && !txRingBuffer()->empty() ) 00106 { 00107 mUART->TxBUFR = txRingBuffer()->remove(); 00108 } 00109 if ( txRingBuffer()->empty() ) 00110 { 00111 disableTxInterrupts(); 00112 } 00113 }

| void PikeAero::CCommunicationUART::setBaud | ( | CMachine::ubit32 | baud | ) |
set the baud rate.
Definition at line 69 of file ccommunicationuart.cpp.
References PikeAero::UART_TypeDef::BR, PikeAero::CMachine::fMCLK(), and mUART.
Referenced by CCommunicationUART().
00070 { 00071 mUART->BR = static_cast<CMachine::ubit16>( ( CMachine::fMCLK() / (16 * baud) ) & 0x0000FFFF ); 00072 }


| void PikeAero::CCommunicationUART::setLoopBack | ( | bool | enabled = true |
) | [inline] |
enables or disables loopback test mode.
Definition at line 51 of file ccommunicationuart.h.
References PikeAero::UART_TypeDef::CR, mUART, and UART_LoopBack.
00052 { 00053 if ( enabled ) 00054 mUART->CR |= UART_LoopBack; 00055 else 00056 mUART->CR &= ~UART_LoopBack; 00057 }
| CMachine::ubit8 PikeAero::CCommunicationUART::tx | ( | CMachine::ubit8 | ch | ) | [virtual] |
transmit a single byte - may yield CPU time if transmitter ring buffer is full.
Reimplemented from PikeAero::CCommunication.
Reimplemented in PikeAero::CCommunicationPacket.
Definition at line 78 of file ccommunicationuart.cpp.
References enableTxInterrupts(), PikeAero::CCommunication::txRingBuffer(), and PikeAero::CTaskScheduler::yield().
00079 { 00080 while ( !txRingBuffer()->insert(ch) ) 00081 { 00082 CTaskScheduler::yield(); 00083 enableTxInterrupts(); 00084 } 00085 enableTxInterrupts(); 00086 return ch; 00087 }

UART_TypeDef* PikeAero::CCommunicationUART::mUART [private] |
Definition at line 82 of file ccommunicationuart.h.
Referenced by CCommunicationUART(), disableTxInterrupts(), enableTxInterrupts(), irq(), setBaud(), setLoopBack(), and ~CCommunicationUART().
1.5.8