From 11ba283d0e135e1240be4d02a5f1e3b0c0a9e456 Mon Sep 17 00:00:00 2001 From: BlackMark Date: Thu, 19 May 2016 22:13:06 +0200 Subject: [PATCH] Replaced class variables with defines --- USART/Clock.h | 2 +- USART/USART.cpp | 96 +++++++---------------- USART/USART.cppproj | 182 ++++++++++++++++++++++++++++---------------- USART/USART.h | 49 +++++++----- USART/main.cpp | 3 + 5 files changed, 178 insertions(+), 154 deletions(-) diff --git a/USART/Clock.h b/USART/Clock.h index cbdc6c5..a04b5ea 100644 --- a/USART/Clock.h +++ b/USART/Clock.h @@ -7,7 +7,7 @@ #ifndef CLOCK_H #define CLOCK_H -#define F_CPU 16000000 +#define F_CPU 8000000 #include diff --git a/USART/USART.cpp b/USART/USART.cpp index 4cbb40c..b5cf3e8 100644 --- a/USART/USART.cpp +++ b/USART/USART.cpp @@ -30,11 +30,11 @@ void USART0::setRXState( bool bEnable ) { if( bEnable ) { - *m_vui8pUCSRB |= ( 1 << m_ui8RXEN ); + *m_vui8pUCSRB |= ( 1 << RXEN_D ); } else { - *m_vui8pUCSRB &= ~( 1 << m_ui8RXEN ); + *m_vui8pUCSRB &= ~( 1 << RXEN_D ); } } @@ -43,11 +43,11 @@ void USART0::setTXState( bool bEnable ) { if( bEnable ) { - *m_vui8pUCSRB |= ( 1 << m_ui8TXEN ); + *m_vui8pUCSRB |= ( 1 << TXEN_D ); } else { - *m_vui8pUCSRB &= ~( 1 << m_ui8TXEN ); + *m_vui8pUCSRB &= ~( 1 << TXEN_D ); } } @@ -80,28 +80,28 @@ void USART0::setDataBits( uint8_t ui8DataBits ) if( bZeroBit ) { - ui8UCSRC |= ( 1 << m_ui8UCSZ0 ); + ui8UCSRC |= ( 1 << UCSZ0_D ); } else { - ui8UCSRC &= ~( 1 << m_ui8UCSZ0 ); + ui8UCSRC &= ~( 1 << UCSZ0_D ); } if( bOneBit ) { - ui8UCSRC |= ( 1 << m_ui8UCSZ1 ); + ui8UCSRC |= ( 1 << UCSZ1_D ); } else { - ui8UCSRC &= ~( 1 << m_ui8UCSZ1 ); + ui8UCSRC &= ~( 1 << UCSZ1_D ); } - *m_vui8pUCSRB &= ~( 1 << m_ui8UCSZ2 ); + *m_vui8pUCSRB &= ~( 1 << UCSZ2_D ); } else { - ui8UCSRC |= ( 1 << m_ui8UCSZ1 ) | ( 1 << m_ui8UCSZ0 ); - *m_vui8pUCSRB |= ( 1 << m_ui8UCSZ2 ); + ui8UCSRC |= ( 1 << UCSZ1_D ) | ( 1 << UCSZ0_D ); + *m_vui8pUCSRB |= ( 1 << UCSZ2_D ); } setUCSRC( ui8UCSRC ); @@ -114,16 +114,16 @@ void USART0::setParity( Parity enmParity ) if( enmParity == Parity::DISABLED ) { - ui8UCSRC &= ~( ( 1 << m_ui8UPM1 ) | ( 1 << m_ui8UPM0 ) ); + ui8UCSRC &= ~( ( 1 << UPM1_D ) | ( 1 << UPM0_D ) ); } else if( enmParity == Parity::ODD ) { - ui8UCSRC |= ( ( 1 << m_ui8UPM1 ) | ( 1 << m_ui8UPM0 ) ); + ui8UCSRC |= ( ( 1 << UPM1_D ) | ( 1 << UPM0_D ) ); } else if( enmParity == Parity::EVEN ) { - ui8UCSRC &= ~( ( 1 << m_ui8UPM0 ) ); - ui8UCSRC |= ( ( 1 << m_ui8UPM1 ) ); + ui8UCSRC &= ~( ( 1 << UPM0_D ) ); + ui8UCSRC |= ( ( 1 << UPM1_D ) ); } setUCSRC( ui8UCSRC ); @@ -136,11 +136,11 @@ void USART0::setStopBits( StopBit enmStopBits ) if( enmStopBits == StopBit::ONE ) { - ui8UCSRC &= ~( 1 << m_ui8USBS ); + ui8UCSRC &= ~( 1 << USBS_D ); } else if( enmStopBits == StopBit::TWO ) { - ui8UCSRC |= ( 1 << m_ui8USBS ); + ui8UCSRC |= ( 1 << USBS_D ); } setUCSRC( ui8UCSRC ); @@ -154,25 +154,25 @@ void USART0::setMode( Mode enmMode ) #ifdef USART_SPI if( enmMode == Mode::ASYNCHRONOUS ) { - ui8UCSRC &= ~( ( 1 << m_ui8UMSEL1 ) | ( 1 << m_ui8UMSEL0 ) ); + ui8UCSRC &= ~( ( 1 << UMSEL1_D ) | ( 1 << UMSEL0_D ) ); } else if( enmMode == Mode::SYNCHRONOUS ) { - ui8UCSRC &= ~( 1 << m_ui8UMSEL1 ); - ui8UCSRC |= ( 1 << m_ui8UMSEL0 ); + ui8UCSRC &= ~( 1 << UMSEL1_D ); + ui8UCSRC |= ( 1 << UMSEL0_D ); } else if( enmMode == Mode::MASTERSPI ) { - ui8UCSRC |= ( ( 1 << m_ui8UMSEL1 ) | ( 1 << m_ui8UMSEL0 ) ); + ui8UCSRC |= ( ( 1 << UMSEL1_D ) | ( 1 << UMSEL0_D ) ); } #else if( enmMode == Mode::ASYNCHRONOUS ) { - ui8UCSRC &= ~( 1 << m_ui8UMSEL ); + ui8UCSRC &= ~( 1 << UMSEL_D ); } else if( enmMode == Mode::SYNCHRONOUS ) { - ui8UCSRC |= ( 1 << m_ui8UMSEL ); + ui8UCSRC |= ( 1 << UMSEL_D ); } #endif @@ -193,17 +193,6 @@ USART0::USART0( uint32_t ui32BaudRate, uint8_t ui8DataBits, Parity enmParity, St m_vui8pUBRRH = &UBRRH; m_vui8pUBRRL = &UBRRL; m_vui8pUDR = &UDR; - - m_ui8RXEN = RXEN; - m_ui8TXEN = TXEN; - m_ui8UCSZ0 = UCSZ0; - m_ui8UCSZ1 = UCSZ1; - m_ui8UCSZ2 = UCSZ2; - m_ui8UPM0 = UPM0; - m_ui8UPM1 = UPM1; - m_ui8USBS = USBS; - m_ui8RXC = RXC; - m_ui8UDRE = UDRE; #endif #ifndef USART_SHAREDIO @@ -213,26 +202,8 @@ USART0::USART0( uint32_t ui32BaudRate, uint8_t ui8DataBits, Parity enmParity, St m_vui8pUBRRH = &UBRR0H; m_vui8pUBRRL = &UBRR0L; m_vui8pUDR = &UDR0; - - m_ui8RXEN = RXEN0; - m_ui8TXEN = TXEN0; - m_ui8UCSZ0 = UCSZ00; - m_ui8UCSZ1 = UCSZ01; - m_ui8UCSZ2 = UCSZ02; - m_ui8UPM0 = UPM00; - m_ui8UPM1 = UPM01; - m_ui8USBS = USBS0; - m_ui8RXC = RXC0; - m_ui8UDRE = UDRE0; #endif - -#ifdef USART_SPI - m_ui8UMSEL0 = UMSEL00; - m_ui8UMSEL1 = UMSEL01; -#else - m_ui8UMSEL = UMSEL; -#endif - + init( ui32BaudRate, ui8DataBits, enmParity, enmStopBits, enmMode ); } @@ -263,7 +234,7 @@ bool USART0::receiveByte( unsigned char &chData, uint32_t ui32DelayMS ) do { - if( ( *m_vui8pUCSRA & ( 1 << m_ui8RXC ) ) ) + if( ( *m_vui8pUCSRA & ( 1 << RXC_D ) ) ) { chData = *m_vui8pUDR; return true; @@ -276,7 +247,7 @@ bool USART0::receiveByte( unsigned char &chData, uint32_t ui32DelayMS ) ////////////////////////////////////////////////////////////////////////// unsigned char USART0::receiveByte() { - while( !( *m_vui8pUCSRA & ( 1 << m_ui8RXC ) ) ); + while( !( *m_vui8pUCSRA & ( 1 << RXC_D ) ) ); return *m_vui8pUDR; } @@ -431,7 +402,7 @@ void USART0::receive( long double &ldReceived ) ////////////////////////////////////////////////////////////////////////// void USART0::transmitByte( unsigned char byteData ) { - while( !( *m_vui8pUCSRA & ( 1 << m_ui8UDRE ) ) ); + while( !( *m_vui8pUCSRA & ( 1 << UDRE_D ) ) ); *m_vui8pUDR = byteData; } @@ -563,19 +534,6 @@ USART1::USART1( uint32_t ui32BaudRate, uint8_t ui8DataBits, Parity enmParity, St m_vui8pUBRRL = &UBRR1L; m_vui8pUDR = &UDR1; - m_ui8RXEN = RXEN1; - m_ui8TXEN = TXEN1; - m_ui8UCSZ0 = UCSZ10; - m_ui8UCSZ1 = UCSZ11; - m_ui8UCSZ2 = UCSZ12; - m_ui8UPM0 = UPM10; - m_ui8UPM1 = UPM11; - m_ui8USBS = USBS1; - m_ui8RXC = RXC1; - m_ui8UDRE = UDRE1; - m_ui8UMSEL0 = UMSEL10; - m_ui8UMSEL1 = UMSEL11; - init( ui32BaudRate, ui8DataBits, enmParity, enmStopBits, enmMode ); } diff --git a/USART/USART.cppproj b/USART/USART.cppproj index 2f997d1..d882896 100644 --- a/USART/USART.cppproj +++ b/USART/USART.cppproj @@ -28,15 +28,15 @@ 0 - - - - - - - - - + + + + + + + + + com.atmel.avrdbg.tool.stk500 @@ -59,69 +59,119 @@ - -mmcu=atmega328p -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\gcc\dev\atmega328p" - True - True - True - True - False - True - True - %24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\include - True - True - True - True - True - %24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\include - True - True - True - True - -Wextra -std=c++11 - libm - %24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\include - NDEBUG - Optimize for size (-Os) - NDEBUG - Optimize for size (-Os) - + -mmcu=atmega328p -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\gcc\dev\atmega328p" + True + True + True + True + True + False + True + True + + + NDEBUG + + + + + %24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\include + + + Optimize for size (-Os) + True + True + True + True + True + + + NDEBUG + + + + + %24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\include + + + Optimize for size (-Os) + True + True + True + True + -Wextra -std=c++11 + + + libm + + + + + %24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\include + + + echo "C:\avrdude-6.2\avrdude.exe" -v -p$(avrdevice) %%* -Uflash:w:"$(OutputDirectory)\$(Name).hex":i > "$(MSBuildProjectDirectory)\avrdude.bat" - -mmcu=atmega328p -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\gcc\dev\atmega328p" - True - True - True - True - False - True - True - %24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\include - True - True - True - True - True - %24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\include - True - True - True - True - -Wextra -std=c++11 - libm - %24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\include - DEBUG - Optimize (-O1) - Default (-g2) - DEBUG - Optimize (-O1) - Default (-g2) - Default (-Wa,-g) - + -mmcu=atmega328p -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\gcc\dev\atmega328p" + True + True + True + True + True + False + True + True + + + DEBUG + + + + + %24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\include + + + Optimize (-O1) + True + True + Default (-g2) + True + True + True + + + DEBUG + + + + + %24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\include + + + Optimize (-O1) + True + True + Default (-g2) + True + True + -Wextra -std=c++11 + + + libm + + + + + %24(PackRepoDir)\atmel\ATmega_DFP\1.0.106\include + + + Default (-Wa,-g) + echo "C:\avrdude-6.2\avrdude.exe" -v -p$(avrdevice) %%* -Uflash:w:"$(OutputDirectory)\$(Name).hex":i > "$(MSBuildProjectDirectory)\avrdude.bat" diff --git a/USART/USART.h b/USART/USART.h index 29ed50a..e0ba439 100644 --- a/USART/USART.h +++ b/USART/USART.h @@ -26,6 +26,37 @@ #define SECOND_USART #endif +#ifdef USART_SHAREDIO +#define RXEN_D RXEN +#define TXEN_D TXEN +#define UCSZ0_D UCSZ0 +#define UCSZ1_D UCSZ1 +#define UCSZ2_D UCSZ2 +#define UPM0_D UPM0 +#define UPM1_D UPM1 +#define USBS_D USBS +#define RXC_D RXC +#define UDRE_D UDRE +#else +#define RXEN_D RXEN0 +#define TXEN_D TXEN0 +#define UCSZ0_D UCSZ00 +#define UCSZ1_D UCSZ01 +#define UCSZ2_D UCSZ02 +#define UPM0_D UPM00 +#define UPM1_D UPM01 +#define USBS_D USBS0 +#define RXC_D RXC0 +#define UDRE_D UDRE0 +#endif + +#ifdef USART_SPI +#define UMSEL0_D UMSEL00 +#define UMSEL1_D UMSEL01 +#else +#define UMSEL_D UMSEL +#endif + class USART0 { public: @@ -58,24 +89,6 @@ protected: volatile uint8_t *m_vui8pUBRRH; volatile uint8_t *m_vui8pUBRRL; volatile uint8_t *m_vui8pUDR; - - uint8_t m_ui8RXEN; - uint8_t m_ui8TXEN; - uint8_t m_ui8UCSZ0; - uint8_t m_ui8UCSZ1; - uint8_t m_ui8UCSZ2; - uint8_t m_ui8UPM0; - uint8_t m_ui8UPM1; - uint8_t m_ui8USBS; - uint8_t m_ui8RXC; - uint8_t m_ui8UDRE; - -#ifdef USART_SPI - uint8_t m_ui8UMSEL0; - uint8_t m_ui8UMSEL1; -#else - uint8_t m_ui8UMSEL; -#endif private: uint8_t readUCSRC(); diff --git a/USART/main.cpp b/USART/main.cpp index 0c6b7ae..fd1c533 100644 --- a/USART/main.cpp +++ b/USART/main.cpp @@ -28,6 +28,9 @@ int main() cUSART << "sizeof( float ) = " << sizeof( float ) << "\r\n"; cUSART << "sizeof( double ) = " << sizeof( double ) << "\r\n"; cUSART << "sizeof( long double ) = " << sizeof( long double ) << "\r\n\r\n"; + cUSART << "sizeof( void* ) = " << sizeof( void* ) << "\r\n"; + cUSART << "sizeof( unsigned char* ) = " << sizeof( unsigned char* ) << "\r\n"; + cUSART << "sizeof( unsigned int* ) = " << sizeof( unsigned int* ) << "\r\n\r\n"; while( true ) {