Skip to content

Commit 617f410

Browse files
Merge pull request #5143 from tung7970/fix-lockup
RTL8195AM - Fix us_ticker porting
2 parents b5c53f4 + 6c11678 commit 617f410

File tree

4 files changed

+32
-45
lines changed

4 files changed

+32
-45
lines changed

targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/TOOLCHAIN_ARM_STD/rtl8195a.sct

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,9 @@ LR_IRAM 0x10007000 (0x70000 - 0x7000) {
1919

2020
ER_IRAM +0 FIXED {
2121
*rtl8195a_crypto.o (+RO)
22-
* (i.mbedtls*)
22+
*(i.mbedtls*)
2323
*libc.a (+RO)
24-
25-
*rtx_*.o (+RO)
26-
*Ticker.o (+RO)
27-
*Timeout.o (+RO)
28-
*rtx_timer.o (+RO)
29-
*TimerEvent.o (+RO)
30-
*mbed_ticker_api.o (+RO)
31-
*mbed_critical.o (+RO)
32-
*us_ticker.o (+RO)
33-
24+
*rtx_*.o (+RO)
3425
*lib_peripheral_mbed_arm.ar (+RO)
3526
}
3627

targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/TOOLCHAIN_GCC_ARM/rtl8195a.ld

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,7 @@ SECTIONS
7070
*rtl8195a_crypto.o (.text* .rodata*)
7171
*mbedtls*.o (.text* .rodata*)
7272
*libc.a: (.text* .rodata*)
73-
*Ticker.o (.text*)
74-
*Timeout.o (.text*)
75-
*TimerEvent.o (.text*)
76-
*mbed_ticker_api.o (.text*)
77-
*mbed_critical.o (.text*)
78-
*us_ticker.o (.text*)
79-
8073
*lib_peripheral_mbed_gcc.a: (.text*)
81-
8274
} > SRAM1
8375

8476
.text.sram2 :

targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/TOOLCHAIN_IAR/rtl8195a.icf

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,6 @@ define block MBEDTLS_TEXT with alignment = 8, fixed order{
213213

214214
define block .sram1.text with fixed order {
215215
block MBEDTLS_TEXT,
216-
section .text* object Ticker.o,
217-
section .text* object Timeout.o,
218-
section .text* object TimerEvent.o,
219-
section .text* object mbed_ticker_api.o,
220-
section .text* object mbed_critical.o,
221-
section .text* object us_ticker.o,
222-
223216
section .text* object lib_peripheral_mbed_iar.a,
224217
};
225218

targets/TARGET_Realtek/TARGET_AMEBA/us_ticker.c

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,22 @@
2020
#include "PeripheralNames.h"
2121

2222
#define TICK_READ_FROM_CPU 0 // 1: read tick from CPU, 0: read tick from G-Timer
23-
#define SYS_TIM_ID 1 // the G-Timer ID for System
24-
#define APP_TIM_ID 6 // the G-Timer ID for Application
23+
#define SYS_TIM_ID 1 // the G-Timer ID for System
24+
#define APP_TIM_ID 6 // the G-Timer ID for Application
2525

26-
#define TICK_TO_US(x) (uint64_t)(((x)/2) * 61 + ((x)%2) * TIMER_TICK_US)
26+
/*
27+
* For RTL8195AM, clock source is 32k
28+
*
29+
* us per tick: 30.5
30+
* tick per ms: 32.7
31+
* tick per us: 0.032
32+
* tick per sec: 32768
33+
*
34+
* Define the following macros to convert between TICK and US.
35+
*/
36+
#define MS_TO_TICK(x) (uint64_t)(((x)*327) / 10)
37+
#define US_TO_TICK(x) (uint64_t)(((x)*32) / 1000)
38+
#define TICK_TO_US(x) (uint64_t)(((x)/2) * 61 + ((x)%2) * TIMER_TICK_US)
2739

2840
static int us_ticker_inited = 0;
2941
static TIMER_ADAPTER TimerAdapter;
@@ -34,23 +46,22 @@ extern HAL_TIMER_OP_EXT HalTimerOpExt;
3446
VOID _us_ticker_irq_handler(void *Data)
3547
{
3648
us_ticker_irq_handler();
37-
HalTimerOp.HalTimerDis((u32)TimerAdapter.TimerId);
3849
}
3950

40-
void us_ticker_init(void)
51+
void us_ticker_init(void)
4152
{
42-
43-
if (us_ticker_inited){
53+
if (us_ticker_inited) {
4454
return;
4555
}
46-
56+
4757
us_ticker_inited = 1;
48-
58+
59+
// Reload and restart sys-timer
4960
HalTimerOp.HalTimerDis(SYS_TIM_ID);
5061
HalTimerOpExt.HalTimerReLoad(SYS_TIM_ID, 0xFFFFFFFFUL);
5162
HalTimerOp.HalTimerEn(SYS_TIM_ID);
52-
53-
// Initial a G-Timer
63+
64+
// Initial a app-timer
5465
TimerAdapter.IrqDis = 0; // Enable Irq @ initial
5566
TimerAdapter.IrqHandle.IrqFun = (IRQ_FUN) _us_ticker_irq_handler;
5667
TimerAdapter.IrqHandle.IrqNum = TIMER2_7_IRQ;
@@ -66,22 +77,22 @@ void us_ticker_init(void)
6677
DBG_TIMER_INFO("%s: Timer_Id=%d\n", __FUNCTION__, APP_TIM_ID);
6778
}
6879

69-
uint32_t us_ticker_read(void)
80+
uint32_t us_ticker_read(void)
7081
{
7182
uint32_t tick_cnt;
7283
uint64_t tick_us;
73-
84+
7485
if (!us_ticker_inited) {
7586
us_ticker_init();
7687
}
77-
88+
7889
tick_cnt = HalTimerOp.HalTimerReadCount(SYS_TIM_ID);
7990
tick_us = TICK_TO_US(0xFFFFFFFFUL - tick_cnt);
8091

8192
return ((uint32_t)tick_us); //return ticker value in micro-seconds (us)
8293
}
8394

84-
void us_ticker_set_interrupt(timestamp_t timestamp)
95+
void us_ticker_set_interrupt(timestamp_t timestamp)
8596
{
8697
uint32_t time_cur;
8798
uint32_t time_cnt;
@@ -95,9 +106,9 @@ void us_ticker_set_interrupt(timestamp_t timestamp)
95106
HalTimerOp.HalTimerEn((u32)TimerAdapter.TimerId);
96107
us_ticker_fire_interrupt();
97108
return;
98-
}
109+
}
99110

100-
TimerAdapter.TimerLoadValueUs = time_cnt / TIMER_TICK_US;
111+
TimerAdapter.TimerLoadValueUs = MAX(MS_TO_TICK(time_cnt/1000) + US_TO_TICK(time_cnt%1000), 1);
101112
HalTimerOpExt.HalTimerReLoad((u32)TimerAdapter.TimerId, TimerAdapter.TimerLoadValueUs);
102113
HalTimerOp.HalTimerEn((u32)TimerAdapter.TimerId);
103114
}
@@ -107,12 +118,12 @@ void us_ticker_fire_interrupt(void)
107118
NVIC_SetPendingIRQ(TIMER2_7_IRQ);
108119
}
109120

110-
void us_ticker_disable_interrupt(void)
121+
void us_ticker_disable_interrupt(void)
111122
{
112123
HalTimerOp.HalTimerDis((u32)TimerAdapter.TimerId);
113124
}
114125

115-
void us_ticker_clear_interrupt(void)
126+
void us_ticker_clear_interrupt(void)
116127
{
117128
HalTimerOp.HalTimerIrqClear((u32)TimerAdapter.TimerId);
118129
}

0 commit comments

Comments
 (0)