MODSERIAL with support for more devices
Fork of MODSERIAL by
Diff: MODSERIAL.cpp
- Revision:
- 23:5c45c21f36b7
- Parent:
- 18:21ef26402365
- Child:
- 24:9c456e647a8f
diff -r c11ea36f17f9 -r 5c45c21f36b7 MODSERIAL.cpp --- a/MODSERIAL.cpp Thu Apr 19 20:47:46 2012 +0000 +++ b/MODSERIAL.cpp Wed Jul 25 22:27:49 2012 +0000 @@ -31,82 +31,91 @@ namespace AjK { -MODSERIAL::MODSERIAL(PinName tx, PinName rx, const char *name) : Serial(tx, rx, name) +MODSERIAL::MODSERIAL( PinName tx, PinName rx, const char *name ) : Serial( tx, rx, name ) { - init(MODSERIAL_DEFAULT_TX_BUFFER_SIZE, MODSERIAL_DEFAULT_RX_BUFFER_SIZE); + init( MODSERIAL_DEFAULT_TX_BUFFER_SIZE, MODSERIAL_DEFAULT_RX_BUFFER_SIZE ); } -MODSERIAL::MODSERIAL(PinName tx, PinName rx, int bufferSize, const char *name) : Serial(tx, rx, name) +MODSERIAL::MODSERIAL( PinName tx, PinName rx, int bufferSize, const char *name ) : Serial( tx, rx, name ) { - init(bufferSize, bufferSize); + init( bufferSize, bufferSize ); } -MODSERIAL::MODSERIAL(PinName tx, PinName rx, int txSize, int rxSize, const char *name) : Serial(tx, rx, name) +MODSERIAL::MODSERIAL( PinName tx, PinName rx, int txSize, int rxSize, const char *name ) : Serial( tx, rx, name ) { - init(txSize, rxSize); + init( txSize, rxSize ); } MODSERIAL::~MODSERIAL() { disableIrq(); - if (buffer[0] != NULL) free((char *)buffer[0]); - if (buffer[1] != NULL) free((char *)buffer[1]); + if ( buffer[0] != NULL) free((char *)buffer[0] ); + if ( buffer[1] != NULL) free((char *)buffer[1] ); } bool -MODSERIAL::txBufferFull(void) +MODSERIAL::txBufferFull( void ) { return MODSERIAL_TX_BUFFER_FULL; } bool -MODSERIAL::rxBufferFull(void) +MODSERIAL::rxBufferFull( void ) { return MODSERIAL_RX_BUFFER_FULL; } bool -MODSERIAL::txBufferEmpty(void) +MODSERIAL::txBufferEmpty( void ) { return MODSERIAL_TX_BUFFER_EMPTY; } bool -MODSERIAL::rxBufferEmpty(void) +MODSERIAL::rxBufferEmpty( void ) { return MODSERIAL_RX_BUFFER_EMPTY; } bool -MODSERIAL::txIsBusy(void) +MODSERIAL::txIsBusy( void ) { - return (_LSR & (3UL << 5) == 0) ? true : false; + return ( _LSR & ( 3UL << 5 ) == 0 ) ? true : false; } void -MODSERIAL::disableIrq(void) +MODSERIAL::disableIrq( void ) { + +#ifdef __LPC11UXX_H__ + NVIC_DisableIRQ( UART_IRQn ); +#else switch(_uidx) { - case 0: NVIC_DisableIRQ(UART0_IRQn); break; - case 1: NVIC_DisableIRQ(UART1_IRQn); break; - case 2: NVIC_DisableIRQ(UART2_IRQn); break; - case 3: NVIC_DisableIRQ(UART3_IRQn); break; + case 0: NVIC_DisableIRQ( UART0_IRQn ); break; + case 1: NVIC_DisableIRQ( UART1_IRQn ); break; + case 2: NVIC_DisableIRQ( UART2_IRQn ); break; + case 3: NVIC_DisableIRQ( UART3_IRQn ); break; } +#endif } void MODSERIAL::enableIrq(void) { - switch(_uidx) { - case 0: NVIC_EnableIRQ(UART0_IRQn); break; - case 1: NVIC_EnableIRQ(UART1_IRQn); break; - case 2: NVIC_EnableIRQ(UART2_IRQn); break; - case 3: NVIC_EnableIRQ(UART3_IRQn); break; +#ifdef __LPC11UXX_H__ + NVIC_EnableIRQ( UART_IRQn ); +#else + switch( _uidx ) { + case 0: NVIC_EnableIRQ( UART0_IRQn ); break; + case 1: NVIC_EnableIRQ( UART1_IRQn ); break; + case 2: NVIC_EnableIRQ( UART2_IRQn ); break; + case 3: NVIC_EnableIRQ( UART3_IRQn ); break; } +#endif } int -MODSERIAL::rxDiscardLastChar(void) +MODSERIAL::rxDiscardLastChar( void ) { // This function can only be called indirectly from // an rxCallback function. Therefore, we know we