Skip to content

Commit

Permalink
US Timer patch ARMmbed#1
Browse files Browse the repository at this point in the history
Signed-off-by: PARKJIHOON <jh6186.park@samsung.com>
  • Loading branch information
jh6186 authored and Kimmo Vaisanen committed Jan 2, 2020
1 parent 59c9d77 commit 2e76a7f
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions targets/TARGET_Samsung/TARGET_SIDK_S5JS100/us_ticker.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@
#include "PeripheralNames.h"

#define TIMER_TARGET_COUNT_DEFAULT 0xFFFFFFFF
#define TIMER0_UNIT (26*1000*1000) //1s

volatile uint32_t us_ticker_initialized = 0;
volatile uint32_t us_user_intset;
volatile uint32_t g_us_last_return = 0;
uint64_t g_tick_sec = 0;
uint32_t g_timer0_pre_cnt;

void us_ticker_enable_interrupt(void);
void us_ticker_disable_interrupt(void);
Expand All @@ -46,9 +49,9 @@ const ticker_info_t *us_ticker_get_info()
static void enable_timer0(void)
{
putreg32(1, S5JS100_TIMER0_BASE + S5JS100_TIMER_UP_DOWN_SEL); // Set Up count
putreg32(0x0, S5JS100_TIMER0_BASE + S5JS100_TIMER_LOAD_VALUE);
putreg32(g_timer0_pre_cnt, S5JS100_TIMER0_BASE + S5JS100_TIMER_LOAD_VALUE);
putreg32(0x1, S5JS100_TIMER0_BASE + S5JS100_TIMER_CDC_ENABLE);
putreg32(0, S5JS100_TIMER0_BASE + S5JS100_TIMER_CDC_COUNT_VALUE);
putreg32(g_timer0_pre_cnt, S5JS100_TIMER0_BASE + S5JS100_TIMER_CDC_COUNT_VALUE);
putreg32(TIMER_TARGET_COUNT_DEFAULT, S5JS100_TIMER0_BASE + S5JS100_TIMER_INT_SEL);
putreg32(0, S5JS100_TIMER0_BASE + S5JS100_TIMER_INT_ENABLE);
putreg32(3, S5JS100_TIMER0_BASE + S5JS100_TIMER_CONTROL);
Expand Down Expand Up @@ -98,6 +101,7 @@ void us_ticker_init(void)

if (!us_ticker_initialized) {
us_ticker_initialized = 1;
g_timer0_pre_cnt = 0;
/* Enable timer0 to timer */
enable_timer0();
/* Enable timer1 to compare and Disable timer1 interrupt */
Expand All @@ -114,11 +118,21 @@ void us_ticker_init(void)

uint32_t us_ticker_read()
{
uint32_t cnt;
/* from timer0 read count value */
if (!us_ticker_initialized) {
us_ticker_init();
}
volatile uint32_t current_count = getreg32(S5JS100_TIMER0_BASE + S5JS100_TIMER_CDC_COUNT_VALUE) / 26;
volatile uint32_t current_count = getreg32(S5JS100_TIMER0_BASE + S5JS100_TIMER_CDC_COUNT_VALUE);
cnt = current_count/TIMER0_UNIT;
if (cnt) {
g_tick_sec = g_tick_sec +cnt;
g_timer0_pre_cnt = current_count%TIMER0_UNIT;
current_count = current_count-(cnt*TIMER0_UNIT);
disable_timer0();
enable_timer0();
}
current_count = (current_count/26)+ (g_tick_sec*1000*1000);
g_us_last_return = current_count;
return current_count;
}
Expand All @@ -128,11 +142,10 @@ void us_ticker_set_interrupt(timestamp_t timestamp)
if (timestamp < 0x70000000 && timestamp != 0) {
uint32_t temp = g_us_last_return;
us_user_intset = timestamp - g_us_last_return;
/* keep to check
if (us_user_intset < 0) {
us_ticker_irq_handler();
return;
}*/
}
us_user_intset = us_user_intset * 26;
uint32_t past_tick = us_ticker_read() - temp;
putreg32(0, S5JS100_TIMER1_BASE + S5JS100_TIMER_LOAD_CON_VALUE);
Expand Down

0 comments on commit 2e76a7f

Please sign in to comment.