Skip to content

Commit 2e76a7f

Browse files
jh6186Kimmo Vaisanen
authored andcommitted
US Timer patch ARMmbed#1
Signed-off-by: PARKJIHOON <[email protected]>
1 parent 59c9d77 commit 2e76a7f

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

targets/TARGET_Samsung/TARGET_SIDK_S5JS100/us_ticker.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,13 @@
2626
#include "PeripheralNames.h"
2727

2828
#define TIMER_TARGET_COUNT_DEFAULT 0xFFFFFFFF
29+
#define TIMER0_UNIT (26*1000*1000) //1s
2930

3031
volatile uint32_t us_ticker_initialized = 0;
3132
volatile uint32_t us_user_intset;
3233
volatile uint32_t g_us_last_return = 0;
34+
uint64_t g_tick_sec = 0;
35+
uint32_t g_timer0_pre_cnt;
3336

3437
void us_ticker_enable_interrupt(void);
3538
void us_ticker_disable_interrupt(void);
@@ -46,9 +49,9 @@ const ticker_info_t *us_ticker_get_info()
4649
static void enable_timer0(void)
4750
{
4851
putreg32(1, S5JS100_TIMER0_BASE + S5JS100_TIMER_UP_DOWN_SEL); // Set Up count
49-
putreg32(0x0, S5JS100_TIMER0_BASE + S5JS100_TIMER_LOAD_VALUE);
52+
putreg32(g_timer0_pre_cnt, S5JS100_TIMER0_BASE + S5JS100_TIMER_LOAD_VALUE);
5053
putreg32(0x1, S5JS100_TIMER0_BASE + S5JS100_TIMER_CDC_ENABLE);
51-
putreg32(0, S5JS100_TIMER0_BASE + S5JS100_TIMER_CDC_COUNT_VALUE);
54+
putreg32(g_timer0_pre_cnt, S5JS100_TIMER0_BASE + S5JS100_TIMER_CDC_COUNT_VALUE);
5255
putreg32(TIMER_TARGET_COUNT_DEFAULT, S5JS100_TIMER0_BASE + S5JS100_TIMER_INT_SEL);
5356
putreg32(0, S5JS100_TIMER0_BASE + S5JS100_TIMER_INT_ENABLE);
5457
putreg32(3, S5JS100_TIMER0_BASE + S5JS100_TIMER_CONTROL);
@@ -98,6 +101,7 @@ void us_ticker_init(void)
98101

99102
if (!us_ticker_initialized) {
100103
us_ticker_initialized = 1;
104+
g_timer0_pre_cnt = 0;
101105
/* Enable timer0 to timer */
102106
enable_timer0();
103107
/* Enable timer1 to compare and Disable timer1 interrupt */
@@ -114,11 +118,21 @@ void us_ticker_init(void)
114118

115119
uint32_t us_ticker_read()
116120
{
121+
uint32_t cnt;
117122
/* from timer0 read count value */
118123
if (!us_ticker_initialized) {
119124
us_ticker_init();
120125
}
121-
volatile uint32_t current_count = getreg32(S5JS100_TIMER0_BASE + S5JS100_TIMER_CDC_COUNT_VALUE) / 26;
126+
volatile uint32_t current_count = getreg32(S5JS100_TIMER0_BASE + S5JS100_TIMER_CDC_COUNT_VALUE);
127+
cnt = current_count/TIMER0_UNIT;
128+
if (cnt) {
129+
g_tick_sec = g_tick_sec +cnt;
130+
g_timer0_pre_cnt = current_count%TIMER0_UNIT;
131+
current_count = current_count-(cnt*TIMER0_UNIT);
132+
disable_timer0();
133+
enable_timer0();
134+
}
135+
current_count = (current_count/26)+ (g_tick_sec*1000*1000);
122136
g_us_last_return = current_count;
123137
return current_count;
124138
}
@@ -128,11 +142,10 @@ void us_ticker_set_interrupt(timestamp_t timestamp)
128142
if (timestamp < 0x70000000 && timestamp != 0) {
129143
uint32_t temp = g_us_last_return;
130144
us_user_intset = timestamp - g_us_last_return;
131-
/* keep to check
132145
if (us_user_intset < 0) {
133146
us_ticker_irq_handler();
134147
return;
135-
}*/
148+
}
136149
us_user_intset = us_user_intset * 26;
137150
uint32_t past_tick = us_ticker_read() - temp;
138151
putreg32(0, S5JS100_TIMER1_BASE + S5JS100_TIMER_LOAD_CON_VALUE);

0 commit comments

Comments
 (0)