2016-05-19 21:43:10 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) by BlackMark 2015-2016
|
|
|
|
* Date 05/01/2016
|
|
|
|
* Version 1.4
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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"
|
2016-05-21 19:11:04 +02:00
|
|
|
#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();
|
2016-05-19 22:59:22 +02:00
|
|
|
cUSART.init();
|
|
|
|
|
2016-05-19 21:43:10 +02:00
|
|
|
uint32_t ui32Counter = 0;
|
|
|
|
|
2016-05-21 19:11:04 +02:00
|
|
|
array<char, 64> arrBuffer;
|
2016-05-20 15:51:01 +02:00
|
|
|
|
2016-05-20 17:02:23 +02:00
|
|
|
cUSART.transmitString( "\r\nSizes: \r\n" );
|
|
|
|
|
2016-05-21 19:11:04 +02:00
|
|
|
sprintf( arrBuffer.data(), "%d\r\n", sizeof( char ) );
|
2016-05-20 17:02:23 +02:00
|
|
|
cUSART.transmitString( "sizeof( char ) = " );
|
2016-05-21 19:11:04 +02:00
|
|
|
cUSART.transmitString( arrBuffer.data() );
|
2016-05-20 17:02:23 +02:00
|
|
|
|
2016-05-21 19:11:04 +02:00
|
|
|
sprintf( arrBuffer.data(), "%d\r\n", sizeof( unsigned char ) );
|
2016-05-20 17:02:23 +02:00
|
|
|
cUSART.transmitString( "sizeof( unsigned char ) = " );
|
2016-05-21 19:11:04 +02:00
|
|
|
cUSART.transmitString( arrBuffer.data() );
|
2016-05-20 17:02:23 +02:00
|
|
|
|
2016-05-21 19:11:04 +02:00
|
|
|
sprintf( arrBuffer.data(), "%d\r\n", sizeof( short int ) );
|
2016-05-20 17:02:23 +02:00
|
|
|
cUSART.transmitString( "sizeof( short int ) = " );
|
2016-05-21 19:11:04 +02:00
|
|
|
cUSART.transmitString( arrBuffer.data() );
|
2016-05-20 17:02:23 +02:00
|
|
|
|
2016-05-21 19:11:04 +02:00
|
|
|
sprintf( arrBuffer.data(), "%d\r\n", sizeof( unsigned short int ) );
|
2016-05-20 17:02:23 +02:00
|
|
|
cUSART.transmitString( "sizeof( unsigned short int ) = " );
|
2016-05-21 19:11:04 +02:00
|
|
|
cUSART.transmitString( arrBuffer.data() );
|
2016-05-20 17:02:23 +02:00
|
|
|
|
2016-05-21 19:11:04 +02:00
|
|
|
sprintf( arrBuffer.data(), "%d\r\n", sizeof( int ) );
|
2016-05-20 17:02:23 +02:00
|
|
|
cUSART.transmitString( "sizeof( int ) = " );
|
2016-05-21 19:11:04 +02:00
|
|
|
cUSART.transmitString( arrBuffer.data() );
|
2016-05-19 21:43:10 +02:00
|
|
|
|
2016-05-21 19:11:04 +02:00
|
|
|
sprintf( arrBuffer.data(), "%d\r\n", sizeof( unsigned int ) );
|
2016-05-20 17:02:23 +02:00
|
|
|
cUSART.transmitString( "sizeof( unsigned int ) = " );
|
2016-05-21 19:11:04 +02:00
|
|
|
cUSART.transmitString( arrBuffer.data() );
|
2016-05-19 21:43:10 +02:00
|
|
|
|
2016-05-21 19:11:04 +02:00
|
|
|
sprintf( arrBuffer.data(), "%d\r\n", sizeof( long int ) );
|
2016-05-20 17:02:23 +02:00
|
|
|
cUSART.transmitString( "sizeof( long int ) = " );
|
2016-05-21 19:11:04 +02:00
|
|
|
cUSART.transmitString( arrBuffer.data() );
|
2016-05-20 15:51:01 +02:00
|
|
|
|
2016-05-21 19:11:04 +02:00
|
|
|
sprintf( arrBuffer.data(), "%d\r\n", sizeof( unsigned long int ) );
|
2016-05-20 17:02:23 +02:00
|
|
|
cUSART.transmitString( "sizeof( unsigned long int ) = " );
|
2016-05-21 19:11:04 +02:00
|
|
|
cUSART.transmitString( arrBuffer.data() );
|
2016-05-19 21:43:10 +02:00
|
|
|
|
2016-05-21 19:11:04 +02:00
|
|
|
sprintf( arrBuffer.data(), "%d\r\n", sizeof( long long int ) );
|
2016-05-20 17:02:23 +02:00
|
|
|
cUSART.transmitString( "sizeof( long long int ) = " );
|
2016-05-21 19:11:04 +02:00
|
|
|
cUSART.transmitString( arrBuffer.data() );
|
2016-05-19 21:43:10 +02:00
|
|
|
|
2016-05-21 19:11:04 +02:00
|
|
|
sprintf( arrBuffer.data(), "%d\r\n", sizeof( unsigned long long int ) );
|
2016-05-20 17:02:23 +02:00
|
|
|
cUSART.transmitString( "sizeof( unsigned long long int ) = " );
|
2016-05-21 19:11:04 +02:00
|
|
|
cUSART.transmitString( arrBuffer.data() );
|
2016-05-19 21:43:10 +02:00
|
|
|
|
2016-05-21 19:11:04 +02:00
|
|
|
sprintf( arrBuffer.data(), "%d\r\n", sizeof( float ) );
|
2016-05-20 17:02:23 +02:00
|
|
|
cUSART.transmitString( "sizeof( float ) = " );
|
2016-05-21 19:11:04 +02:00
|
|
|
cUSART.transmitString( arrBuffer.data() );
|
2016-05-20 17:02:23 +02:00
|
|
|
|
2016-05-21 19:11:04 +02:00
|
|
|
sprintf( arrBuffer.data(), "%d\r\n", sizeof( double ) );
|
2016-05-20 17:02:23 +02:00
|
|
|
cUSART.transmitString( "sizeof( double ) = " );
|
2016-05-21 19:11:04 +02:00
|
|
|
cUSART.transmitString( arrBuffer.data() );
|
2016-05-20 17:02:23 +02:00
|
|
|
|
2016-05-21 19:11:04 +02:00
|
|
|
sprintf( arrBuffer.data(), "%d\r\n", sizeof( long double ) );
|
2016-05-20 17:02:23 +02:00
|
|
|
cUSART.transmitString( "sizeof( long double ) = " );
|
2016-05-21 19:11:04 +02:00
|
|
|
cUSART.transmitString( arrBuffer.data() );
|
2016-05-20 17:02:23 +02:00
|
|
|
|
2016-05-21 19:11:04 +02:00
|
|
|
sprintf( arrBuffer.data(), "%d\r\n\r\n", sizeof( void* ) );
|
2016-05-20 17:02:23 +02:00
|
|
|
cUSART.transmitString( "sizeof( void* ) = " );
|
2016-05-21 19:11:04 +02:00
|
|
|
cUSART.transmitString( arrBuffer.data() );
|
2016-05-20 17:02:23 +02:00
|
|
|
|
|
|
|
while( true )
|
|
|
|
{
|
2016-05-21 19:11:04 +02:00
|
|
|
sprintf( arrBuffer.data(), "%lu", ui32Counter++ );
|
2016-05-20 17:02:23 +02:00
|
|
|
cUSART.transmitString( "This has been running for \"" );
|
2016-05-21 19:11:04 +02:00
|
|
|
cUSART.transmitString( arrBuffer.data() );
|
2016-05-20 17:02:23 +02:00
|
|
|
cUSART.transmitString( "\" seconds!\r\n" );
|
2016-05-19 22:59:22 +02:00
|
|
|
|
2016-05-21 19:11:04 +02:00
|
|
|
if( !cUSART.receiveLine( arrBuffer.data(), arrBuffer.size(), "\r" ) )
|
2016-05-20 17:02:23 +02:00
|
|
|
{
|
|
|
|
cUSART.transmitString( "Receive error: " );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cUSART.transmitString( "Echo: " );
|
|
|
|
}
|
|
|
|
|
2016-05-21 19:11:04 +02:00
|
|
|
cUSART.transmitString( arrBuffer.data() );
|
2016-05-20 17:02:23 +02:00
|
|
|
cUSART.transmitString( "\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.transmitString( "\r\n" );
|
|
|
|
}
|
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;
|
2016-05-20 15:55:19 +02:00
|
|
|
}
|