123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
-
-
- #include "MODSERIAL.h"
- #include "MACROS.h"
-
- namespace AjK {
-
- MODSERIAL::MODSERIAL( PinName tx, PinName rx, const char* name ) : Serial( tx, rx, name )
- {
- 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 )
- {
- init( bufferSize, bufferSize );
- }
-
- MODSERIAL::MODSERIAL( PinName tx, PinName rx, int txSize, int rxSize, const char* name ) : Serial( tx, rx, name )
- {
- init( txSize, rxSize );
- }
-
- MODSERIAL::~MODSERIAL()
- {
- disableIrq();
- if ( buffer[0] != NULL) free((char *)buffer[0] );
- if ( buffer[1] != NULL) free((char *)buffer[1] );
- }
-
- bool
- MODSERIAL::txBufferFull( void )
- {
- return MODSERIAL_TX_BUFFER_FULL;
- }
-
- bool
- MODSERIAL::rxBufferFull( void )
- {
- return MODSERIAL_RX_BUFFER_FULL;
- }
-
- bool
- MODSERIAL::txBufferEmpty( void )
- {
- return MODSERIAL_TX_BUFFER_EMPTY;
- }
-
- bool
- MODSERIAL::rxBufferEmpty( void )
- {
- return MODSERIAL_RX_BUFFER_EMPTY;
- }
-
- bool
- MODSERIAL::txIsBusy( void )
- {
- return ( ( _LSR & ( 3UL << 5 ) ) == 0 ) ? true : false;
- }
-
- void
- MODSERIAL::disableIrq( void )
- {
-
- #ifdef __LPC11UXX_H__
- NVIC_DisableIRQ( UART_IRQn );
- #else
- switch( _serial.index ) {
- 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)
- {
- #ifdef __LPC11UXX_H__
- NVIC_EnableIRQ( UART_IRQn );
- #else
- switch( _serial.index ) {
- 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 )
- {
-
-
-
- char c = buffer[RxIrq][buffer_in[RxIrq]];
-
- if (buffer_count[RxIrq]) {
- buffer_count[RxIrq]--;
- buffer_in[RxIrq]--;
- if (buffer_in[RxIrq] < 0) {
- buffer_in[RxIrq] = buffer_size[RxIrq] - 1;
- }
- }
-
- return (int)c;
- }
-
-
- }
|