uart/usart/main.cpp

108 lines
2.6 KiB
C++
Raw Normal View History

2016-05-19 21:43:10 +02:00
/*
* Copyright (c) by BlackMark 2015-2016
* Date 21/05/2016
* Version 1.5
2016-05-19 21:43:10 +02:00
*/
#include <stdio.h>
2016-05-20 15:51:01 +02:00
#include "clock.h"
2016-05-20 15:32:42 +02:00
#include "usart.h"
#include "array/array.h"
2016-05-19 21:43:10 +02:00
int main()
{
2016-05-20 22:27:57 +02:00
USART0 &cUSART = USART0::inst();
cUSART.init();
2016-05-19 21:43:10 +02:00
uint32_t ui32Counter = 0;
array<char, 64> arrBuffer;
2016-05-20 15:51:01 +02:00
cUSART << "\r\nSizes: \r\n";
sprintf( arrBuffer.data(), "%d\r\n", sizeof( char ) );
cUSART << "sizeof( char ) = ";
cUSART << arrBuffer.data();
sprintf( arrBuffer.data(), "%d\r\n", sizeof( unsigned char ) );
cUSART << "sizeof( unsigned char ) = ";
cUSART << arrBuffer.data();
sprintf( arrBuffer.data(), "%d\r\n", sizeof( short int ) );
cUSART << "sizeof( short int ) = ";
cUSART << arrBuffer.data();
sprintf( arrBuffer.data(), "%d\r\n", sizeof( unsigned short int ) );
cUSART << "sizeof( unsigned short int ) = ";
cUSART << arrBuffer.data();
sprintf( arrBuffer.data(), "%d\r\n", sizeof( int ) );
cUSART << "sizeof( int ) = ";
cUSART << arrBuffer.data();
2016-05-19 21:43:10 +02:00
sprintf( arrBuffer.data(), "%d\r\n", sizeof( unsigned int ) );
cUSART << "sizeof( unsigned int ) = ";
cUSART << arrBuffer.data();
2016-05-19 21:43:10 +02:00
sprintf( arrBuffer.data(), "%d\r\n", sizeof( long int ) );
cUSART << "sizeof( long int ) = ";
cUSART << arrBuffer.data();
2016-05-20 15:51:01 +02:00
sprintf( arrBuffer.data(), "%d\r\n", sizeof( unsigned long int ) );
cUSART << "sizeof( unsigned long int ) = ";
cUSART << arrBuffer.data();
2016-05-19 21:43:10 +02:00
sprintf( arrBuffer.data(), "%d\r\n", sizeof( long long int ) );
cUSART << "sizeof( long long int ) = ";
cUSART << arrBuffer.data();
2016-05-19 21:43:10 +02:00
sprintf( arrBuffer.data(), "%d\r\n", sizeof( unsigned long long int ) );
cUSART << "sizeof( unsigned long long int ) = ";
cUSART << arrBuffer.data();
2016-05-19 21:43:10 +02:00
sprintf( arrBuffer.data(), "%d\r\n", sizeof( float ) );
cUSART << "sizeof( float ) = ";
cUSART << arrBuffer.data();
sprintf( arrBuffer.data(), "%d\r\n", sizeof( double ) );
cUSART << "sizeof( double ) = ";
cUSART << arrBuffer.data();
sprintf( arrBuffer.data(), "%d\r\n", sizeof( long double ) );
cUSART << "sizeof( long double ) = ";
cUSART << arrBuffer.data();
sprintf( arrBuffer.data(), "%d\r\n\r\n", sizeof( void* ) );
cUSART << "sizeof( void* ) = ";
cUSART << arrBuffer.data();
while( true )
{
sprintf( arrBuffer.data(), "%lu", ui32Counter++ );
cUSART << "This has been running for \"";
cUSART << arrBuffer.data();
cUSART << "\" seconds!\r\n";
if( !cUSART.receiveLine( arrBuffer.data(), arrBuffer.size(), "\r" ) )
{
cUSART << "Receive error: ";
}
else
{
cUSART << "Echo: ";
}
cUSART << arrBuffer.data();
cUSART << "\r\n";
2016-05-20 15:51:01 +02:00
2016-05-20 22:27:57 +02:00
uint8_t ui8Byte;
if( cUSART.receiveByte( ui8Byte, 1000 ) )
{
cUSART.transmitByte( ui8Byte );
cUSART << "\r\n";
2016-05-20 22:27:57 +02:00
}
2016-05-19 21:43:10 +02:00
}
2016-05-20 15:51:01 +02:00
2016-05-19 21:43:10 +02:00
return 0;
}