@ -32,14 +32,14 @@ extern uint32_t __DDR_FREE; /* Start of free DDR memory region. */
/* Receive data from UART */
static int
uart_recv_bytes ( size_t count , uint8_t * dest )
uart_recv_bytes ( size_t count , uint8_t * dest , const uint8_t timeout )
{
uint32_t i , status = 0 ;
uint32_t timerStatus = 1 ;
for ( i = 0 ; i < count ; i + + ) {
/* Enable timer one time */
timer0_start ( SYSTEM_CLK_HZ * 5 ) ;
timer0_start ( SYSTEM_CLK_HZ * timeout ) ;
do {
status = ( UART0 - > LSR ) & ( 0x01 ) ;
timerStatus = timer0_status ( ) ;
@ -90,7 +90,7 @@ uart_send_bytes(char *string)
/* Check if the given string is received via UART */
static int
uart_check_string ( char * string , int include_null )
uart_check_string ( char * string , int include_null , const uint8_t timeout )
{
int i , count ;
@ -102,7 +102,7 @@ uart_check_string(char *string, int include_null)
uint8_t recv ;
/* Get one byte */
if ( uart_recv_bytes ( 1 , & recv ) ! = E_PASS )
if ( uart_recv_bytes ( 1 , & recv , timeout ) ! = E_PASS )
return E_FAIL ;
if ( recv ! = string [ i ] )
@ -113,7 +113,7 @@ uart_check_string(char *string, int include_null)
/* Receive a uint32 value in HEX form (8 bytes) */
static int
uart_recv_hex_uint32 ( uint32_t * data )
uart_recv_hex_uint32 ( uint32_t * data , const uint8_t timeout )
{
int k ;
uint8_t recv [ 8 ] ;
@ -122,7 +122,7 @@ uart_recv_hex_uint32(uint32_t *data)
const int num_ascii_char = 8 ;
/* Get 8 bytes from UART */
if ( uart_recv_bytes ( num_ascii_char , recv ) ! = E_PASS )
if ( uart_recv_bytes ( num_ascii_char , recv , timeout ) ! = E_PASS )
return E_FAIL ;
* data = 0 ;
@ -186,10 +186,16 @@ uart_send_hexnum(uint32_t value, int digits)
int
uart_get_cmd ( uint32_t * boot_cmd )
{
if ( uart_check_string ( " CMD " , true ) ! = E_PASS )
return uart_get_cmd_timeout ( boot_cmd , 5 ) ;
}
int
uart_get_cmd_timeout ( uint32_t * boot_cmd , uint8_t timeout )
{
if ( uart_check_string ( " CMD " , true , timeout ) ! = E_PASS )
return E_FAIL ;
if ( uart_recv_hex_uint32 ( boot_cmd ) ! = E_PASS )
if ( uart_recv_hex_uint32 ( boot_cmd , timeout ) ! = E_PASS )
return E_FAIL ;
return E_PASS ;
@ -205,16 +211,16 @@ uart_get_prog(struct uart_ack_header_t *uart_ack_header)
uart_ack_header - > recv_buffer = ddr_free ;
/* Send ACK command */
error = uart_check_string ( " ACK " , true ) ;
error = uart_check_string ( " ACK " , true , 5 ) ;
if ( error ! = E_PASS )
return E_FAIL ;
/* Get the ACK header elements */
error = uart_recv_hex_uint32 ( & uart_ack_header - > magic ) ;
error | = uart_recv_hex_uint32 ( & recv_crc ) ;
error | = uart_recv_hex_uint32 ( & uart_ack_header - > size ) ;
error | = uart_recv_hex_uint32 ( & uart_ack_header - > entry_point ) ;
error | = uart_check_string ( " 0000 " , false ) ;
error = uart_recv_hex_uint32 ( & uart_ack_header - > magic , 5 ) ;
error | = uart_recv_hex_uint32 ( & recv_crc , 5 ) ;
error | = uart_recv_hex_uint32 ( & uart_ack_header - > size , 5 ) ;
error | = uart_recv_hex_uint32 ( & uart_ack_header - > entry_point , 5 ) ;
error | = uart_check_string ( " 0000 " , false , 5 ) ;
if ( error ! = E_PASS )
return E_FAIL ;
@ -240,7 +246,7 @@ uart_get_prog(struct uart_ack_header_t *uart_ack_header)
/* Receive the data over UART */
if ( uart_recv_bytes ( uart_ack_header - > size ,
uart_ack_header - > recv_buffer )
uart_ack_header - > recv_buffer , 5 )
! = E_PASS ) {
return E_FAIL ;
}