Skip to content

Commit 8f5f428

Browse files
committedApr 24, 2015
runtime/main: fix sys_now
1 parent 934a6b0 commit 8f5f428

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed
 

Diff for: ‎soc/runtime/main.c

+7-9
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,19 @@
2727
#ifdef CSR_ETHMAC_BASE
2828
unsigned char macadr[6] = {0x10, 0xe2, 0xd5, 0x00, 0x00, 0x00};
2929

30-
u32_t clock_ms;
30+
static int clkdiv;
3131

3232
u32_t sys_now(void)
3333
{
34-
unsigned int freq;
35-
unsigned int prescaler;
34+
static unsigned long long int clock_sys;
35+
u32_t clock_ms;
3636

37-
freq = identifier_frequency_read();
38-
prescaler = freq/1000; /* sys_now expects time in ms */
3937
timer0_update_value_write(1);
40-
clock_ms += (0xffffffff - timer0_value_read())/prescaler;
41-
/* Reset timer to avoid rollover, this will increase clock_ms
42-
drift but we don't need precision */
38+
clock_sys += 0xffffffff - timer0_value_read();
4339
timer0_en_write(0);
4440
timer0_en_write(1);
41+
42+
clock_ms = clock_sys/clkdiv;
4543
return clock_ms;
4644
}
4745

@@ -66,7 +64,7 @@ static void network_init(void)
6664
timer0_load_write(0xffffffff);
6765
timer0_reload_write(0xffffffff);
6866
timer0_en_write(1);
69-
clock_ms = 0;
67+
clkdiv = identifier_frequency_read()/1000;
7068

7169
IP4_ADDR(&local_ip, 192, 168, 0, 42);
7270
IP4_ADDR(&netmask, 255, 255, 255, 0);

0 commit comments

Comments
 (0)
Please sign in to comment.