uart/timeout: Reduce the I_ME timeout to a lower value again

Do not block the boot process for five seconds or longer. When
adding the configurable timeout the other timeout code got broken.
Remove it and instead supply uart_recv_bytes with the timeout per
charachter.
This commit is contained in:
Holger Hans Peter Freyther 2014-07-11 10:12:50 +02:00
parent e057397dad
commit 43383917fd
5 changed files with 27 additions and 52 deletions

View File

@ -238,19 +238,6 @@ ivt_init(void)
*ivect = 0xEAFFFFFE; /* FIQ @ 0x1C */
}
static int
timer0_init(uint8_t timeout)
{
TIMER0->TGCR = 0x00000000; /* Reset timer */
TIMER0->TCR = 0x00000000; /* Disable timer */
TIMER0->TIM12 = 0x00000000; /* Reset timer count to zero */
/* Set timer period (5 seconds timeout) */
TIMER0->PRD12 = SYSTEM_CLK_HZ * timeout;
return E_PASS;
}
void
timer0_start(uint32_t period)
{
@ -263,18 +250,6 @@ timer0_start(uint32_t period)
TIMER0->TGCR = 0x00000005; /* Start TIMER12 in 32-bits mode. */
}
void
timer0_settimeout(uint8_t timeout)
{
timer0_init(timeout);
}
int
timer0_setdefault_timeout()
{
return timer0_init(5);
}
uint32_t
timer0_status(void)
{
@ -693,9 +668,6 @@ davinci_platform_init(char *version)
if (status == E_PASS)
status |= uart0_init();
if (status == E_PASS)
status |= timer0_setdefault_timeout();
uart_send_lf();
log_info(version);

View File

@ -459,7 +459,5 @@ void ddr_vtp_calibration(void);
void timer0_start(uint32_t period);
uint32_t timer0_status(void);
void timer0_settimeout(uint8_t timeout);
int timer0_setdefault_timeout(void);
#endif /* _DAVINCI_H_ */

36
uart.c
View File

@ -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;
}

1
uart.h
View File

@ -42,6 +42,7 @@ void uart_send_str_lf(char *string);
void uart_send_hexnum(uint32_t value, int digits);
int uart_get_cmd(uint32_t *boot_cmd);
int uart_get_cmd_timeout(uint32_t *boot_cmd, uint8_t timeout);
uint32_t uart_get_prog(struct uart_ack_header_t *uart_ack_header);

4
ubl.c
View File

@ -95,12 +95,10 @@ interrupt_me(void)
/* short for interrupt me */
host_msg("I_ME");
timer0_settimeout(1);
if (uart_get_cmd(&boot_cmd) != E_PASS)
if (uart_get_cmd_timeout(&boot_cmd, 1) != E_PASS)
return;
if (boot_cmd != 0x23)
return;
timer0_setdefault_timeout();
log_info("Boot interrupted");
uart_boot(&jump_entry_point);