diff --git a/davinci.c b/davinci.c index cc06a7b..c5e737f 100644 --- a/davinci.c +++ b/davinci.c @@ -238,41 +238,16 @@ 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) { TIMER0->TGCR = 0x00000000; /* Reset timer */ TIMER0->TCR = 0x00000000; /* Disable timer */ TIMER0->PRD12 = period; - AINTC->IRQ1 |= 0x00000001; /* Clear interrupt */ - TIMER0->TIM12 = 0x00000000; /* Reset timer count to zero */ - TIMER0->TCR = 0x00000040; /* Setup for one-shot mode */ - 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); + AINTC->IRQ1 |= 0x00000001; /* Clear interrupt */ + TIMER0->TIM12 = 0x00000000; /* Reset timer count to zero */ + TIMER0->TCR = 0x00000040; /* Setup for one-shot mode */ + TIMER0->TGCR = 0x00000005; /* Start TIMER12 in 32-bits mode. */ } uint32_t @@ -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); diff --git a/davinci.h b/davinci.h index 0e01dbc..07908a3 100644 --- a/davinci.h +++ b/davinci.h @@ -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_ */ diff --git a/uart.c b/uart.c index 0253f2d..7dcb91e 100644 --- a/uart.c +++ b/uart.c @@ -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; } diff --git a/uart.h b/uart.h index b9f0316..2085af1 100644 --- a/uart.h +++ b/uart.h @@ -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); diff --git a/ubl.c b/ubl.c index 08e0510..3cdf4da 100644 --- a/ubl.c +++ b/ubl.c @@ -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);