diff --git a/board/mx1ads/syncflash.c b/board/mx1ads/syncflash.c index eb7fde5..1a38449 100644 --- a/board/mx1ads/syncflash.c +++ b/board/mx1ads/syncflash.c @@ -276,8 +276,6 @@ /* arm simple, non interrupt dependent timer */ - reset_timer_masked(); - SF_NvmodeErase(); SF_NvmodeWrite(); diff --git a/common/clock.c b/common/clock.c index 2e4e9d7..d500e5c 100644 --- a/common/clock.c +++ b/common/clock.c @@ -57,17 +57,23 @@ int is_timeout(uint64_t start_ns, uint64_t time_offset_ns) { + if (ctrlc ()) + return -1; + if (start_ns + time_offset_ns < get_time_ns()) return 1; else return 0; } -void udelay(unsigned long usecs) +int udelay(unsigned long usecs) { uint64_t start = get_time_ns(); - while(!is_timeout(start, usecs * 1000)); + while(!is_timeout(start, usecs * 1000)) + if (ctrlc ()) + return -1; + return 0; } void mdelay(unsigned long msecs) diff --git a/common/cmd_misc.c b/common/cmd_misc.c index 67ee9e8..968291a 100644 --- a/common/cmd_misc.c +++ b/common/cmd_misc.c @@ -26,12 +26,13 @@ */ #include #include +#include #if (CONFIG_COMMANDS & CFG_CMD_MISC) int do_sleep (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { - ulong start = get_timer(0); + uint64_t start; ulong delay; if (argc != 2) { @@ -41,12 +42,8 @@ delay = simple_strtoul(argv[1], NULL, 10) * CFG_HZ; - while (get_timer(start) < delay) { - if (ctrlc ()) { - return (-1); - } - udelay (100); - } + start = get_time_ns(); + while (!is_timeout(start, delay * 1000000)); return 0; } diff --git a/common/exports.c b/common/exports.c index 0cb4396..70b9c7f 100644 --- a/common/exports.c +++ b/common/exports.c @@ -25,7 +25,7 @@ gd->jt[XF_free] = (void *) free; gd->jt[XF_getenv] = (void *) getenv; gd->jt[XF_setenv] = (void *) setenv; - gd->jt[XF_get_timer] = (void *) get_timer; +// gd->jt[XF_get_timer] = (void *) get_timer; gd->jt[XF_simple_strtoul] = (void *) simple_strtoul; gd->jt[XF_udelay] = (void *) udelay; #if defined(CONFIG_I386) || defined(CONFIG_PPC) diff --git a/drivers/cfi_flash.c b/drivers/cfi_flash.c index 2699cce..d8e6223 100644 --- a/drivers/cfi_flash.c +++ b/drivers/cfi_flash.c @@ -788,18 +788,18 @@ * This routine does not set the flash to read-array mode. */ static int flash_status_check (flash_info_t * info, flash_sect_t sector, - ulong tout, char *prompt) + uint64_t tout, char *prompt) { - ulong start; + uint64_t start; #if CFG_HZ != 1000 tout *= CFG_HZ/1000; #endif /* Wait for command completion */ - start = get_timer (0); + start = get_time_ns(); while (flash_is_busy (info, sector)) { - if (get_timer (start) > tout) { + if (is_timeout(start, tout)) { printf ("Flash %s timeout at address %lx data %lx\n", prompt, info->start[sector], flash_read_long (info, sector, 0)); @@ -816,7 +816,7 @@ * This routine sets the flash to read-array mode. */ static int flash_full_status_check (flash_info_t * info, flash_sect_t sector, - ulong tout, char *prompt) + uint64_t tout, char *prompt) { int retcode; @@ -1318,10 +1318,10 @@ info->erase_blk_tout = (tmp * (1 << flash_read_uchar (info, FLASH_OFFSET_EMAX_TOUT))); tmp = (1 << flash_read_uchar (info, FLASH_OFFSET_WBTOUT)) * (1 << flash_read_uchar (info, FLASH_OFFSET_WBMAX_TOUT)); - info->buffer_write_tout = tmp / 1000 + (tmp % 1000 ? 1 : 0); /* round up when converting to ms */ + info->buffer_write_tout = tmp * 1000; tmp = (1 << flash_read_uchar (info, FLASH_OFFSET_WTOUT)) * (1 << flash_read_uchar (info, FLASH_OFFSET_WMAX_TOUT)); - info->write_tout = tmp / 1000 + (tmp % 1000 ? 1 : 0); /* round up when converting to ms */ + info->write_tout = tmp * 1000; info->flash_id = FLASH_MAN_CFI; if ((info->interface == FLASH_CFI_X8X16) && (info->chipwidth == FLASH_CFI_BY8)) { info->portwidth >>= 1; /* XXX - Need to test on x8/x16 in parallel. */ diff --git a/drivers/cs8900.c b/drivers/cs8900.c index 082434c..78d0149 100644 --- a/drivers/cs8900.c +++ b/drivers/cs8900.c @@ -40,6 +40,7 @@ #include #include "cs8900.h" #include +#include #ifdef CONFIG_DRIVER_CS8900 @@ -84,7 +85,7 @@ static void eth_reset (void) { - int tmo; + uint64_t start; unsigned short us; /* reset NIC */ @@ -94,9 +95,9 @@ udelay (200000); /* Wait until the chip is reset */ - tmo = get_timer (0) + 1 * CFG_HZ; + start = get_time_ns(); while ((((us = get_reg_init_bus (PP_SelfSTAT)) & PP_SelfSTAT_InitD) == 0) - && tmo < get_timer (0)) + && !is_timeout(start, SECOND)) /*NOP*/; } @@ -236,7 +237,7 @@ extern int eth_send (volatile void *packet, int length) { volatile unsigned short *addr; - int tmo; + uint64_t start; unsigned short s; retry: @@ -250,8 +251,9 @@ #ifdef DEBUG printf ("cs: unable to send packet; retrying...\n"); #endif - for (tmo = get_timer (0) + 5 * CFG_HZ; get_timer (0) < tmo;) - /*NOP*/; + /* FIXME */ + udelay(5000); + eth_reset (); eth_reginit (); goto retry; @@ -263,9 +265,9 @@ CS8900_RTDATA = *addr++; /* wait for transfer to succeed */ - tmo = get_timer (0) + 5 * CFG_HZ; + start = get_time_ns(); while ((s = get_reg (PP_TER) & ~0x1F) == 0) { - if (get_timer (0) >= tmo) + if (is_timeout(start, SECOND)) break; } diff --git a/include/asm-arm/u-boot-arm.h b/include/asm-arm/u-boot-arm.h index f4b9807..efff5e9 100644 --- a/include/asm-arm/u-boot-arm.h +++ b/include/asm-arm/u-boot-arm.h @@ -54,8 +54,4 @@ /* common/cmd_nvedit.c */ void setenv (char *, char *); -/* cpu/.../interrupt.c */ -void reset_timer_masked (void); -ulong get_timer_masked (void); - #endif /* _U_BOOT_ARM_H_ */ diff --git a/include/clock.h b/include/clock.h index a8920f1..85ce401 100644 --- a/include/clock.h +++ b/include/clock.h @@ -1,3 +1,5 @@ +#ifndef CLOCK_H +#define CLOCK_H struct clocksource { uint32_t shift; @@ -8,7 +10,7 @@ }; -inline uint32_t cyc2ns(struct clocksource *cs, uint64_t cycles) +static inline uint32_t cyc2ns(struct clocksource *cs, uint64_t cycles) { uint64_t ret = cycles; ret = (ret * cs->mult) >> cs->shift; @@ -27,3 +29,8 @@ void mdelay(unsigned long msecs); +#define SECOND ((uint64_t)(1000 * 1000 * 1000)) +#define MSECOND ((uint64_t)(1000 * 1000)) +#define USECOND ((uint64_t)(1000)) + +#endif /* CLOCK_H */ diff --git a/include/common.h b/include/common.h index 982d6a8..c955738 100644 --- a/include/common.h +++ b/include/common.h @@ -517,7 +517,6 @@ void irq_install_handler(int, interrupt_handler_t *, void *); void irq_free_handler (int); void reset_timer (void); -ulong get_timer (ulong base); void set_timer (ulong t); void enable_interrupts (void); int disable_interrupts (void); @@ -555,7 +554,7 @@ void wait_ticks (unsigned long); /* lib_$(ARCH)/time.c */ -void udelay (unsigned long); +int udelay (unsigned long); ulong usec2ticks (unsigned long usec); ulong ticks2usec (unsigned long ticks); int init_timebase (void); diff --git a/include/exports.h b/include/exports.h index 8f7f617..d40b050 100644 --- a/include/exports.h +++ b/include/exports.h @@ -16,8 +16,7 @@ void free_hdlr(int); void *malloc(size_t); void free(void*); -void udelay(unsigned long); -unsigned long get_timer(unsigned long); +int udelay(unsigned long); void vprintf(const char *, va_list); void do_reset (void); unsigned long simple_strtoul(const char *cp,char **endp,unsigned int base); diff --git a/include/net.h b/include/net.h index 46feb86..b6f0153 100644 --- a/include/net.h +++ b/include/net.h @@ -374,7 +374,7 @@ /* Set callbacks */ extern void NetSetHandler(rxhand_f *); /* Set RX packet handler */ -extern void NetSetTimeout(ulong, thand_f *);/* Set timeout handler */ +extern void NetSetTimeout(uint64_t, thand_f *);/* Set timeout handler */ /* Transmit "NetTxPacket" */ extern void NetSendPacket(volatile uchar *, int); diff --git a/net/bootp.c b/net/bootp.c index 6aef0d4..cded61c 100644 --- a/net/bootp.c +++ b/net/bootp.c @@ -17,6 +17,7 @@ #include #include +#include #include #include "bootp.h" #include "tftp.h" @@ -650,7 +651,8 @@ bp->bp_htype = HWT_ETHER; bp->bp_hlen = HWL_ETHER; bp->bp_hops = 0; - bp->bp_secs = htons(get_timer(0) / CFG_HZ); + /* FIXME what is this? */ +// bp->bp_secs = htons(get_timer(0) / CFG_HZ); NetWriteIP(&bp->bp_ciaddr, 0); NetWriteIP(&bp->bp_yiaddr, 0); NetWriteIP(&bp->bp_siaddr, 0); @@ -673,7 +675,7 @@ | ((ulong)NetOurEther[3] << 16) | ((ulong)NetOurEther[4] << 8) | (ulong)NetOurEther[5]; - BootpID += get_timer(0); + BootpID += (uint32_t)get_time_ns(); BootpID = htonl(BootpID); NetCopyLong(&bp->bp_id, &BootpID); @@ -828,7 +830,8 @@ bp->bp_htype = HWT_ETHER; bp->bp_hlen = HWL_ETHER; bp->bp_hops = 0; - bp->bp_secs = htons(get_timer(0) / CFG_HZ); + /* FIXME what is this? */ +// bp->bp_secs = htons(get_timer(0) / CFG_HZ); NetCopyIP(&bp->bp_ciaddr, &bp_offer->bp_ciaddr); /* both in network byte order */ NetCopyIP(&bp->bp_yiaddr, &bp_offer->bp_yiaddr); NetCopyIP(&bp->bp_siaddr, &bp_offer->bp_siaddr); diff --git a/net/net.c b/net/net.c index 7c4e755..aa67964 100644 --- a/net/net.c +++ b/net/net.c @@ -75,6 +75,7 @@ #include +#include #include #include #include @@ -94,7 +95,7 @@ DECLARE_GLOBAL_DATA_PTR; -#define ARP_TIMEOUT 5 /* Seconds before trying ARP again */ +#define ARP_TIMEOUT (5 * SECOND) /* Seconds before trying ARP again */ #ifndef CONFIG_NET_RETRY_COUNT # define ARP_TIMEOUT_COUNT 5 /* # of timeouts before giving up */ #else @@ -235,15 +236,11 @@ void ArpTimeoutCheck(void) { - ulong t; - if (!NetArpWaitPacketIP) return; - t = get_timer(0); - /* check for arp timeout */ - if ((t - NetArpWaitTimerStart) > ARP_TIMEOUT * CFG_HZ) { + if (is_timeout(NetArpWaitTimerStart, ARP_TIMEOUT)) { NetArpWaitTry++; if (NetArpWaitTry >= ARP_TIMEOUT_COUNT) { @@ -251,7 +248,7 @@ NetArpWaitTry = 0; NetStartAgain(); } else { - NetArpWaitTimerStart = t; + NetArpWaitTimerStart = get_time_ns(); ArpRequest(); } } @@ -501,7 +498,7 @@ * Check for a timeout, and run the timeout handler * if we have one. */ - if (timeHandler && ((get_timer(0) - timeStart) > timeDelta)) { + if (timeHandler && ((get_time_ns() - timeStart) > timeDelta)) { thand_f *x; #if defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII) @@ -615,13 +612,13 @@ void -NetSetTimeout(ulong iv, thand_f * f) +NetSetTimeout(uint64_t iv, thand_f * f) { if (iv == 0) { timeHandler = (thand_f *)0; } else { timeHandler = f; - timeStart = get_timer(0); + timeStart = get_time_ns(); timeDelta = iv; } } @@ -666,7 +663,7 @@ /* and do the ARP request */ NetArpWaitTry = 1; - NetArpWaitTimerStart = get_timer(0); + NetArpWaitTimerStart = get_time_ns(); ArpRequest(); return 1; /* waiting */ } @@ -737,7 +734,7 @@ /* and do the ARP request */ NetArpWaitTry = 1; - NetArpWaitTimerStart = get_timer(0); + NetArpWaitTimerStart = get_time_ns(); ArpRequest(); return 1; /* waiting */ } diff --git a/net/tftp.c b/net/tftp.c index f3a5471..055fc49 100644 --- a/net/tftp.c +++ b/net/tftp.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "tftp.h" #include "bootp.h" @@ -369,7 +370,7 @@ TftpTimeoutCount = 0; TftpState = STATE_RRQ; /* Use a pseudo-random port unless a specific port is set */ - TftpOurPort = 1024 + (get_timer(0) % 3072); + TftpOurPort = 1024 + (get_time_ns() % 3072); #ifdef CONFIG_TFTP_PORT if ((ep = getenv("tftpdstp")) != NULL) { TftpServerPort = simple_strtol(ep, NULL, 10);