void byte_shift ( char direction , uint8_t locations , uint32_t * data )
{
if ( direction == 'r' )
{
* data = ( ( * data ) >> 8 * locations ) ;
}
else if ( direction == 'l' )
{
* data = ( ( * data ) << 8 * locations ) ;
}
}
uint8_t read_and_concatenate ( bool data_ready , uint8_t index , uint32_t * data )
{
uint32_t x = 0 ;
if ( UARTCharsAvail ( UART0_BASE ) )
{
x = ( uint32_t ) UARTCharGet ( UART0_BASE ) ;
* data = ( ( * data ) << 8 ) | x ;
if ( index == 3 )
{
index = 0 ;
}
else
{
index ++ ;
}
}
return index ;
}
int main(void)
{
uint8_t current_uart_byte = 0 ;
bool flag = 0 ;
uint8_t index = 0 ;
uint32_t full_word = 0 ;
while ( 1 )
{
//void byte_shift ( char direction , uint32_t * data )
byte_shift ( 'r' , 1 , & y ) ;
current_uart_byte = read_and_concatenate ( UARTCharsAvail ( UART0_BASE ) , current_uart_byte , & full_word ) ;
if ( full_word == 0x20202020 ) // Equivalent to pressing 4 times on the Space button of the keyboard
{
flag = 1 ;
}
}
}