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:
parent
d1c87ee29d
commit
d902a1c044
|
@ -252,10 +252,12 @@ timer0_init(uint8_t timeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
timer0_start(void)
|
timer0_start(uint32_t period)
|
||||||
{
|
{
|
||||||
AINTC->IRQ1 |= 0x00000001; /* Clear interrupt */
|
|
||||||
TIMER0->TGCR = 0x00000000; /* Reset timer */
|
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->TIM12 = 0x00000000; /* Reset timer count to zero */
|
||||||
TIMER0->TCR = 0x00000040; /* Setup for one-shot mode */
|
TIMER0->TCR = 0x00000040; /* Setup for one-shot mode */
|
||||||
TIMER0->TGCR = 0x00000005; /* Start TIMER12 in 32-bits mode. */
|
TIMER0->TGCR = 0x00000005; /* Start TIMER12 in 32-bits mode. */
|
||||||
|
|
|
@ -457,7 +457,7 @@ struct gpio_controller {
|
||||||
int davinci_platform_init(char *version);
|
int davinci_platform_init(char *version);
|
||||||
void ddr_vtp_calibration(void);
|
void ddr_vtp_calibration(void);
|
||||||
|
|
||||||
void timer0_start(void);
|
void timer0_start(uint32_t period);
|
||||||
uint32_t timer0_status(void);
|
uint32_t timer0_status(void);
|
||||||
void timer0_settimeout(uint8_t timeout);
|
void timer0_settimeout(uint8_t timeout);
|
||||||
int timer0_setdefault_timeout(void);
|
int timer0_setdefault_timeout(void);
|
||||||
|
|
1
dm644x.h
1
dm644x.h
|
@ -27,6 +27,7 @@
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
#define SYSTEM_CLK_HZ 27000000
|
#define SYSTEM_CLK_HZ 27000000
|
||||||
|
#define SYSTEM_CLK_MHZ 27
|
||||||
|
|
||||||
struct pll_settings_t {
|
struct pll_settings_t {
|
||||||
uint8_t mult;
|
uint8_t mult;
|
||||||
|
|
14
nand.c
14
nand.c
|
@ -37,7 +37,7 @@
|
||||||
#define NAND_ALE_OFFSET 0x08
|
#define NAND_ALE_OFFSET 0x08
|
||||||
#define NAND_CLE_OFFSET 0x10
|
#define NAND_CLE_OFFSET 0x10
|
||||||
|
|
||||||
#define NAND_TIMEOUT 20480
|
#define NAND_TIMEOUT 5000 /*us*/
|
||||||
|
|
||||||
/* NAND flash commands */
|
/* NAND flash commands */
|
||||||
#define NAND_LO_PAGE 0x00
|
#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 */
|
/* Poll bit of NANDFSR to indicate ready */
|
||||||
static int
|
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 ready;
|
||||||
|
uint32_t timerStatus;
|
||||||
|
|
||||||
waitloop(200);
|
waitloop(200);
|
||||||
|
timer0_start(SYSTEM_CLK_MHZ * timeout_us);
|
||||||
do {
|
do {
|
||||||
ready = AEMIF->NANDFSR & NAND_NANDFSR_READY;
|
ready = AEMIF->NANDFSR & NAND_NANDFSR_READY;
|
||||||
cnt--;
|
timerStatus = timer0_status();
|
||||||
} while ((cnt > 0) && !ready);
|
} while (!ready && timerStatus);
|
||||||
|
|
||||||
if (cnt == 0) {
|
if (timerStatus == 0) {
|
||||||
log_info("NAND busy timeout");
|
log_info("NAND busy timeout");
|
||||||
return E_FAIL;
|
return E_FAIL;
|
||||||
}
|
}
|
||||||
|
|
4
uart.c
4
uart.c
|
@ -39,7 +39,7 @@ uart_recv_bytes(size_t count, uint8_t *dest)
|
||||||
|
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
/* Enable timer one time */
|
/* Enable timer one time */
|
||||||
timer0_start();
|
timer0_start(SYSTEM_CLK_HZ * 5);
|
||||||
do {
|
do {
|
||||||
status = (UART0->LSR)&(0x01);
|
status = (UART0->LSR)&(0x01);
|
||||||
timerStatus = timer0_status();
|
timerStatus = timer0_status();
|
||||||
|
@ -74,7 +74,7 @@ uart_send_bytes(char *string)
|
||||||
|
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
/* Enable Timer one time */
|
/* Enable Timer one time */
|
||||||
timer0_start();
|
timer0_start(SYSTEM_CLK_HZ * 5);
|
||||||
do {
|
do {
|
||||||
status = (UART0->LSR)&(0x20);
|
status = (UART0->LSR)&(0x20);
|
||||||
timerStatus = timer0_status();
|
timerStatus = timer0_status();
|
||||||
|
|
Loading…
Reference in New Issue