timer: Make the timer configurable and use it

Instead of counting a variable sleep for a given/predictable time.
Update the uart code with this value.
This commit is contained in:
Holger Hans Peter Freyther 2014-07-09 19:38:07 +02:00
parent d1c87ee29d
commit d902a1c044
5 changed files with 18 additions and 15 deletions

View File

@ -252,10 +252,12 @@ timer0_init(uint8_t timeout)
}
void
timer0_start(void)
timer0_start(uint32_t period)
{
AINTC->IRQ1 |= 0x00000001; /* Clear interrupt */
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. */

View File

@ -457,7 +457,7 @@ struct gpio_controller {
int davinci_platform_init(char *version);
void ddr_vtp_calibration(void);
void timer0_start(void);
void timer0_start(uint32_t period);
uint32_t timer0_status(void);
void timer0_settimeout(uint8_t timeout);
int timer0_setdefault_timeout(void);

View File

@ -27,6 +27,7 @@
#include "common.h"
#define SYSTEM_CLK_HZ 27000000
#define SYSTEM_CLK_MHZ 27
struct pll_settings_t {
uint8_t mult;

14
nand.c
View File

@ -37,7 +37,7 @@
#define NAND_ALE_OFFSET 0x08
#define NAND_CLE_OFFSET 0x10
#define NAND_TIMEOUT 20480
#define NAND_TIMEOUT 5000 /*us*/
/* NAND flash commands */
#define NAND_LO_PAGE 0x00
@ -289,19 +289,19 @@ flash_read_bytes(uint8_t *dest, uint32_t numBytes)
/* Poll bit of NANDFSR to indicate ready */
static int
nand_wait_for_ready(uint32_t timeout)
nand_wait_for_ready(uint32_t timeout_us)
{
volatile uint32_t cnt = timeout;
uint32_t ready;
uint32_t timerStatus;
waitloop(200);
timer0_start(SYSTEM_CLK_MHZ * timeout_us);
do {
ready = AEMIF->NANDFSR & NAND_NANDFSR_READY;
cnt--;
} while ((cnt > 0) && !ready);
timerStatus = timer0_status();
} while (!ready && timerStatus);
if (cnt == 0) {
if (timerStatus == 0) {
log_info("NAND busy timeout");
return E_FAIL;
}

4
uart.c
View File

@ -39,7 +39,7 @@ uart_recv_bytes(size_t count, uint8_t *dest)
for (i = 0; i < count; i++) {
/* Enable timer one time */
timer0_start();
timer0_start(SYSTEM_CLK_HZ * 5);
do {
status = (UART0->LSR)&(0x01);
timerStatus = timer0_status();
@ -74,7 +74,7 @@ uart_send_bytes(char *string)
for (i = 0; i < count; i++) {
/* Enable Timer one time */
timer0_start();
timer0_start(SYSTEM_CLK_HZ * 5);
do {
status = (UART0->LSR)&(0x20);
timerStatus = timer0_status();