Skip to content

Commit 003dd7c

Browse files
authored
Merge pull request #5044 from Archcady/Profile_debug
Realtek_RTL8195AM fix for debug profile
2 parents 02a10e5 + f7bc126 commit 003dd7c

File tree

11 files changed

+137
-46
lines changed

11 files changed

+137
-46
lines changed

features/FEATURE_LWIP/lwip-interface/mbed_lib.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,10 @@
8484
"help": "Thread stack size for PPP",
8585
"value": 768
8686
}
87+
},
88+
"target_overrides": {
89+
"REALTEK_RTL8195AM": {
90+
"tcpip-thread-stacksize": 1600
91+
}
8792
}
8893
}

targets/TARGET_Realtek/TARGET_AMEBA/RTWInterface.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include "osdep_service.h"
2929

3030
typedef struct _wifi_scan_hdl {
31-
void *scan_sema;
31+
_sema scan_sema;
3232
nsapi_size_t ap_num;
3333
nsapi_size_t scan_num;
3434
WiFiAccessPoint *ap_details;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
;
2+
; Copyright (c) 2017 Realtek Semiconductor Corp.
3+
;
4+
; Licensed under the Apache License, Version 2.0 (the "License");
5+
; you may not use this file except in compliance with the License.
6+
; You may obtain a copy of the License at
7+
;
8+
; http://www.apache.org/licenses/LICENSE-2.0
9+
;
10+
; Unless required by applicable law or agreed to in writing, software
11+
; distributed under the License is distributed on an "AS IS" BASIS,
12+
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
; See the License for the specific language governing permissions and
14+
; limitations under the License.
15+
16+
PRESERVE8
17+
THUMB
18+
19+
AREA |i.PLAT_Start|, CODE, READONLY
20+
21+
PLAT_Start PROC
22+
23+
EXPORT PLAT_Start
24+
IMPORT |Image$$ARM_LIB_STACK$$ZI$$Limit|
25+
IMPORT PLAT_Init
26+
LDR SP, =|Image$$ARM_LIB_STACK$$ZI$$Limit|
27+
LDR R0, =PLAT_Init
28+
BX R0
29+
ENDP
30+
ALIGN
31+
END
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (c) 2017 Realtek Semiconductor Corp.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
.syntax unified
18+
.thumb
19+
20+
.global __StackTop
21+
.global PLAT_Init
22+
23+
/* entry point of application image */
24+
.section .text.PLAT_Start
25+
.weak PLAT_Start
26+
.type PLAT_Start, %function
27+
PLAT_Start:
28+
ldr sp, =__StackTop
29+
ldr r0, =PLAT_Init
30+
bx r0
31+
.size PLAT_Start, .-PLAT_Start
32+
.end
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
;
2+
; Copyright (c) 2017 Realtek Semiconductor Corp.
3+
;
4+
; Licensed under the Apache License, Version 2.0 (the "License");
5+
; you may not use this file except in compliance with the License.
6+
; You may obtain a copy of the License at
7+
;
8+
; http://www.apache.org/licenses/LICENSE-2.0
9+
;
10+
; Unless required by applicable law or agreed to in writing, software
11+
; distributed under the License is distributed on an "AS IS" BASIS,
12+
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
; See the License for the specific language governing permissions and
14+
; limitations under the License.
15+
16+
MODULE ?cstartup
17+
18+
SECTION .text:CODE:NOROOT:REORDER(2)
19+
EXTERN CSTACK$$Limit
20+
EXTERN PLAT_Init
21+
22+
; Default image 2 entry
23+
THUMB
24+
PUBWEAK PLAT_Start
25+
26+
PLAT_Start
27+
LDR SP, =CSTACK$$Limit
28+
LDR R0, =PLAT_Init
29+
BX R0
30+
31+
END

targets/TARGET_Realtek/TARGET_AMEBA/TARGET_RTL8195A/device/rtl8195a_init.c

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#if defined(__CC_ARM) || \
3030
(defined (__ARMCC_VERSION) && __ARMCC_VERSION >= 6010050)
3131

32-
extern uint32_t Image$$ARM_LIB_STACK$$ZI$$Limit;
3332
extern uint8_t Image$$RW_IRAM2$$ZI$$Base[];
3433
extern uint8_t Image$$RW_IRAM2$$ZI$$Limit[];
3534
extern uint8_t Image$$TCM_OVERLAY$$ZI$$Base[];
@@ -42,13 +41,11 @@ extern uint8_t Image$$RW_DRAM2$$ZI$$Limit[];
4241
#define __bss_dtcm_end__ Image$$TCM_OVERLAY$$ZI$$Limit
4342
#define __bss_dram_start__ Image$$RW_DRAM2$$ZI$$Base
4443
#define __bss_dram_end__ Image$$RW_DRAM2$$ZI$$Limit
45-
#define __stackp Image$$ARM_LIB_STACK$$ZI$$Limit
4644

4745
#elif defined (__ICCARM__)
4846

4947
#pragma section=".ram.bss"
5048

51-
extern uint32_t CSTACK$$Limit;
5249
uint8_t *__bss_start__;
5350
uint8_t *__bss_end__;
5451

@@ -57,20 +54,16 @@ void __iar_data_init_app(void)
5754
__bss_start__ = (uint8_t *)__section_begin(".ram.bss");
5855
__bss_end__ = (uint8_t *)__section_end(".ram.bss");
5956
}
60-
#define __stackp CSTACK$$Limit
6157

6258
#else
6359

64-
extern uint32_t __StackTop;
65-
extern uint32_t __StackLimit;
6660
extern uint8_t __bss_sram_start__[];
6761
extern uint8_t __bss_sram_end__[];
6862
extern uint8_t __bss_dtcm_start__[];
6963
extern uint8_t __bss_dtcm_end__[];
7064
extern uint8_t __bss_dram_start__[];
7165
extern uint8_t __bss_dram_end__[];
7266

73-
#define __stackp __StackTop
7467
#endif
7568

7669
extern VECTOR_Func NewVectorTable[];
@@ -175,31 +168,26 @@ void TRAP_HardFaultHandler_Patch(void)
175168

176169
extern _LONG_CALL_ void * __rtl_memset_v1_00(void * m , int c , size_t n);
177170
// Image2 Entry Function
178-
void PLAT_Start(void)
171+
void PLAT_Init(void)
179172
{
180173
uint32_t val;
181174

182-
#if defined (__ICCARM__)
183-
__iar_data_init_app();
175+
// Overwrite vector table
176+
NewVectorTable[2] = (VECTOR_Func) TRAP_NMIHandler;
177+
#if defined ( __ICCARM__ )
178+
NewVectorTable[3] = (VECTOR_Func) TRAP_HardFaultHandler_Patch;
184179
#endif
185180

186181
// Clear RAM BSS
187182
#if defined (__ICCARM__)
183+
__iar_data_init_app();
188184
__rtl_memset_v1_00((void *)__bss_start__, 0, __bss_end__ - __bss_start__);
189185
#else
190186
__rtl_memset_v1_00((void *)__bss_sram_start__, 0, __bss_sram_end__ - __bss_sram_start__);
191187
__rtl_memset_v1_00((void *)__bss_dtcm_start__, 0, __bss_dtcm_end__ - __bss_dtcm_start__);
192188
__rtl_memset_v1_00((void *)__bss_dram_start__, 0, __bss_dram_end__ - __bss_dram_start__);
193189
#endif
194190

195-
// Set MSP
196-
__set_MSP((uint32_t)&__stackp - 0x100);
197-
// Overwrite vector table
198-
NewVectorTable[2] = (VECTOR_Func) TRAP_NMIHandler;
199-
#if defined ( __ICCARM__ )
200-
NewVectorTable[3] = (VECTOR_Func) TRAP_HardFaultHandler_Patch;
201-
#endif
202-
203191
extern HAL_TIMER_OP_EXT HalTimerOpExt;
204192
__rtl_memset_v1_00((void *)&HalTimerOpExt, 0, sizeof(HalTimerOpExt));
205193
__rtl_memset_v1_00((void *)&HalTimerOp, 0, sizeof(HalTimerOp));

targets/TARGET_Realtek/TARGET_AMEBA/sdk/os/rtx2/rtx2_service.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ _func_exit_;
548548

549549
static u32 _rtx2_get_current_time(void)
550550
{
551-
return osKernelGetTickCount();
551+
return osKernelGetSysTimerCount();
552552
}
553553

554554
static u32 _rtx2_systime_to_ms(u32 systime)

targets/TARGET_Realtek/TARGET_AMEBA/us_ticker.c

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,33 @@
2323
#define SYS_TIM_ID 1 // the G-Timer ID for System
2424
#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)
27+
2628
static int us_ticker_inited = 0;
2729
static TIMER_ADAPTER TimerAdapter;
2830

2931
extern HAL_TIMER_OP HalTimerOp;
3032
extern HAL_TIMER_OP_EXT HalTimerOpExt;
3133

32-
VOID _us_ticker_irq_handler(IN VOID *Data)
34+
VOID _us_ticker_irq_handler(void *Data)
3335
{
3436
us_ticker_irq_handler();
37+
HalTimerOp.HalTimerDis((u32)TimerAdapter.TimerId);
3538
}
3639

3740
void us_ticker_init(void)
3841
{
3942

40-
if (us_ticker_inited) return;
43+
if (us_ticker_inited){
44+
return;
45+
}
46+
4147
us_ticker_inited = 1;
4248

43-
49+
HalTimerOp.HalTimerDis(SYS_TIM_ID);
50+
HalTimerOpExt.HalTimerReLoad(SYS_TIM_ID, 0xFFFFFFFFUL);
51+
HalTimerOp.HalTimerEn(SYS_TIM_ID);
52+
4453
// Initial a G-Timer
4554
TimerAdapter.IrqDis = 0; // Enable Irq @ initial
4655
TimerAdapter.IrqHandle.IrqFun = (IRQ_FUN) _us_ticker_irq_handler;
@@ -52,50 +61,45 @@ void us_ticker_init(void)
5261
TimerAdapter.TimerLoadValueUs = 0xFFFFFFFF;
5362
TimerAdapter.TimerMode = USER_DEFINED;
5463

55-
HalTimerOp.HalTimerInit((VOID*) &TimerAdapter);
64+
HalTimerOp.HalTimerInit((void *) &TimerAdapter);
5665

5766
DBG_TIMER_INFO("%s: Timer_Id=%d\n", __FUNCTION__, APP_TIM_ID);
5867
}
5968

60-
uint32_t us_ticker_read()
69+
uint32_t us_ticker_read(void)
6170
{
6271
uint32_t tick_cnt;
63-
uint32_t ticks_125ms;
64-
uint32_t ticks_remain;
65-
uint64_t us_tick;
66-
72+
uint64_t tick_us;
73+
74+
if (!us_ticker_inited) {
75+
us_ticker_init();
76+
}
77+
6778
tick_cnt = HalTimerOp.HalTimerReadCount(SYS_TIM_ID);
68-
tick_cnt = 0xffffffff - tick_cnt; // it's a down counter
69-
ticks_125ms = tick_cnt/(GTIMER_CLK_HZ/8); //use 125ms as a intermediate unit;
70-
ticks_remain = tick_cnt - (ticks_125ms*(GTIMER_CLK_HZ/8)); //calculate the remainder
71-
us_tick = ticks_125ms * 125000; //change unit to us, 125ms is 125000 us
72-
us_tick += (ticks_remain * 1000000)/GTIMER_CLK_HZ; //also use us as unit
79+
tick_us = TICK_TO_US(0xFFFFFFFFUL - tick_cnt);
7380

74-
return ((uint32_t)us_tick); //return ticker value in micro-seconds (us)
81+
return ((uint32_t)tick_us); //return ticker value in micro-seconds (us)
7582
}
7683

7784
void us_ticker_set_interrupt(timestamp_t timestamp)
7885
{
79-
uint32_t cur_time_us;
80-
uint32_t time_dif;
86+
uint32_t time_cur;
87+
uint32_t time_cnt;
8188

8289
HalTimerOp.HalTimerDis((u32)TimerAdapter.TimerId);
83-
cur_time_us = us_ticker_read();
84-
if ((uint32_t)timestamp > cur_time_us) {
85-
time_dif = (uint32_t)timestamp - cur_time_us;
90+
time_cur = us_ticker_read();
91+
if (timestamp > time_cur + TIMER_TICK_US) {
92+
time_cnt = timestamp - time_cur;
8693
} else {
8794
HalTimerOpExt.HalTimerReLoad((u32)TimerAdapter.TimerId, 0xffffffff);
88-
HalTimerOpExt.HalTimerIrqEn((u32)TimerAdapter.TimerId);
8995
HalTimerOp.HalTimerEn((u32)TimerAdapter.TimerId);
90-
NVIC_SetPendingIRQ(TIMER2_7_IRQ);
96+
us_ticker_fire_interrupt();
9197
return;
9298
}
9399

94-
TimerAdapter.TimerLoadValueUs = time_dif;
95-
HalTimerOpExt.HalTimerReLoad((u32)TimerAdapter.TimerId, time_dif / TIMER_TICK_US);
96-
HalTimerOpExt.HalTimerIrqEn((u32)TimerAdapter.TimerId);
100+
TimerAdapter.TimerLoadValueUs = time_cnt / TIMER_TICK_US;
101+
HalTimerOpExt.HalTimerReLoad((u32)TimerAdapter.TimerId, TimerAdapter.TimerLoadValueUs);
97102
HalTimerOp.HalTimerEn((u32)TimerAdapter.TimerId);
98-
99103
}
100104

101105
void us_ticker_fire_interrupt(void)

0 commit comments

Comments
 (0)