Skip to content

Commit 4a779f5

Browse files
committed
修改使用C语言构建任务栈帧,清除fls和ffs对<c6x.h>文件的依赖
1 parent c69cdad commit 4a779f5

File tree

9 files changed

+228
-133
lines changed

9 files changed

+228
-133
lines changed

libcpu/ti-dsp/c6x/c66xx.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@
1111
#ifndef __C66XX_H__
1212
#define __C66XX_H__
1313

14-
#include <c6x.h>
14+
extern cregister volatile unsigned int IERR; /* Internal Exception Report Register */
15+
extern cregister volatile unsigned int ECR; /* Exception Clear Register */
16+
extern cregister volatile unsigned int EFR; /* Exception Flag Register */
17+
extern cregister volatile unsigned int TSR; /* Task State Register */
18+
extern cregister volatile unsigned int ITSR; /* Interrupt Task State Register */
19+
extern cregister volatile unsigned int NTSR; /* NMI/exception Task State Register */
20+
extern cregister volatile unsigned int TSCL; /* Time Stamp Counter Register - Low Half */
21+
extern cregister volatile unsigned int TSCH; /* Time Stamp Counter Register - High Half */
22+
extern cregister volatile unsigned int DNUM; /* Core number */
1523

1624
#ifdef _BIG_ENDIAN
1725
#define RT_REG_PAIR(odd, even) unsigned long odd; unsigned long even
@@ -37,7 +45,7 @@ struct rt_hw_register
3745
RT_REG_PAIR(b9, b8);
3846
RT_REG_PAIR(b11, b10);
3947
RT_REG_PAIR(b13, b12);
40-
48+
4149
RT_REG_PAIR(a17, a16);
4250
RT_REG_PAIR(a19, a18);
4351
RT_REG_PAIR(a21, a20);
@@ -58,14 +66,14 @@ struct rt_hw_register
5866
RT_REG_PAIR(a15, a14);
5967
RT_REG_PAIR(sp, dp);
6068
};
61-
62-
struct rt_hw_exp_stack_register
69+
70+
typedef struct rt_hw_exp_stack_register
6371
{
6472
RT_REG_PAIR(tsr, orig_a4);
6573
RT_REG_PAIR(rilc, ilc);
6674
RT_REG_PAIR(pc, csr);
6775
struct rt_hw_register hw_register;
68-
};
76+
} rt_hw_thread_stack_register;
6977

7078
#define __dint() asm(" DINT")
7179
#define __rint() asm(" RINT")

libcpu/ti-dsp/c6x/context.asm

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,40 @@ rt_hw_interrupt_enable:
7979
NOP 5
8080
;}
8181

82+
;-----------------------------------------------------------
83+
; rt_uint32_t rt_hw_get_current_dp(void)
84+
;-----------------------------------------------------------
85+
.global rt_hw_get_current_dp
86+
rt_hw_get_current_dp:
87+
;{
88+
B B3
89+
MV B14, A4
90+
NOP 4
91+
;}
92+
93+
;-----------------------------------------------------------
94+
; rt_int32_t __fls(rt_int32_t val)
95+
;-----------------------------------------------------------
96+
.global __fls
97+
__fls:
98+
;{
99+
B B3
100+
LMBD .L1 1,A4,A4
101+
NOP 4
102+
;}
103+
104+
;-----------------------------------------------------------
105+
; rt_int32_t __ffs(rt_int32_t val)
106+
;-----------------------------------------------------------
107+
.global __ffs
108+
__ffs:
109+
;{
110+
BITR .M1 A4,A4
111+
B B3
112+
LMBD .L1 1,A4,A4
113+
NOP 4
114+
;}
115+
82116
;
83117
;-----------------------------------------------------------
84118
;

libcpu/ti-dsp/c6x/cpuport.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ void hw_int11_handler(void)
158158
-----------------------------------------------------------------------------*/
159159
void hw_int12_handler(void)
160160
{
161-
161+
162162
}
163163

164164
/*------------ hw_int13_handler() function ------------------------------------

libcpu/ti-dsp/c6x/interrupt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,6 @@ void rt_hw_interrupt_clear(int vector)
9494
{
9595
if (vector < 0 || vector >= MAX_HANDLERS)
9696
{
97-
return;
97+
return;
9898
}
9999
}

libcpu/ti-dsp/c6x/intexc.asm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ RT_INTERRUPT_ENTRY .macro
8181
.endm
8282

8383
RT_CALL_INT .macro __isr
84-
CALLP __isr,B3
84+
B __isr
85+
ADDKPC $1 ,B3,4
86+
$1:
8587
B .S1 rt_interrupt_context_restore
8688
NOP 5
8789
.endm

libcpu/ti-dsp/c6x/stack.asm

Lines changed: 0 additions & 107 deletions
This file was deleted.

libcpu/ti-dsp/c6x/stack.c

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/*
2+
* Copyright (c) 2021, Shenzhen Academy of Aerospace Technology
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2021-11-16 Dystopia the first version
9+
*/
10+
11+
#include <rtthread.h>
12+
#include <c66xx.h>
13+
14+
extern rt_uint32_t rt_hw_get_current_dp(void);
15+
16+
/**
17+
* @addtogroup C66xx
18+
*/
19+
/*@{*/
20+
21+
/**
22+
* This function will initialize thread stack
23+
*
24+
* @param tentry the entry of thread
25+
* @param parameter the parameter of entry
26+
* @param stack_addr the beginning stack address
27+
* @param texit the function will be called when thread exit
28+
*
29+
* @return stack address
30+
*/
31+
rt_uint8_t *rt_hw_stack_init(void *tentry, void *parameter,
32+
rt_uint8_t *stack_addr, void *texit)
33+
{
34+
rt_hw_thread_stack_register *thread_context;
35+
rt_uint32_t stk;
36+
37+
stack_addr += sizeof(rt_uint32_t);
38+
stack_addr = (rt_uint8_t *)RT_ALIGN_DOWN((rt_uint32_t)stack_addr, 8);
39+
stk = (rt_uint32_t)stack_addr;
40+
thread_context = (rt_hw_thread_stack_register *)(stk - sizeof(rt_hw_thread_stack_register));
41+
42+
thread_context->pc = (rt_uint32_t)tentry;
43+
thread_context->csr = 0x0103;
44+
thread_context->tsr = 0x3;
45+
thread_context->orig_a4 = 1;
46+
thread_context->ilc = 0;
47+
thread_context->rilc = 0;
48+
49+
thread_context->hw_register.b17 = 0xB17;
50+
thread_context->hw_register.b16 = 0xB16;
51+
thread_context->hw_register.b19 = 0xB19;
52+
thread_context->hw_register.b18 = 0xB18;
53+
thread_context->hw_register.b21 = 0xB21;
54+
thread_context->hw_register.b20 = 0xB20;
55+
thread_context->hw_register.b23 = 0xB23;
56+
thread_context->hw_register.b22 = 0xB22;
57+
thread_context->hw_register.b25 = 0xB25;
58+
thread_context->hw_register.b24 = 0xB24;
59+
thread_context->hw_register.b27 = 0xB27;
60+
thread_context->hw_register.b26 = 0xB26;
61+
thread_context->hw_register.b29 = 0xB29;
62+
thread_context->hw_register.b28 = 0xB28;
63+
thread_context->hw_register.b31 = 0xB31;
64+
thread_context->hw_register.b30 = 0xB30;
65+
66+
thread_context->hw_register.b1 = 0xB01;
67+
thread_context->hw_register.b0 = 0xB00;
68+
thread_context->hw_register.b3 = (rt_uint32_t)texit;
69+
thread_context->hw_register.b2 = 0xB02;
70+
thread_context->hw_register.b5 = 0xB05;
71+
thread_context->hw_register.b4 = 0xB04;
72+
thread_context->hw_register.b7 = 0xB07;
73+
thread_context->hw_register.b6 = 0xB06;
74+
thread_context->hw_register.b9 = 0xB09;
75+
thread_context->hw_register.b8 = 0xB08;
76+
thread_context->hw_register.b11 = 0xB11;
77+
thread_context->hw_register.b10 = 0xB10;
78+
thread_context->hw_register.b13 = 0xB13;
79+
thread_context->hw_register.b12 = 0xB12;
80+
81+
thread_context->hw_register.a17 = 0xA17;
82+
thread_context->hw_register.a16 = 0xA16;
83+
thread_context->hw_register.a19 = 0xA19;
84+
thread_context->hw_register.a18 = 0xA18;
85+
thread_context->hw_register.a21 = 0xA21;
86+
thread_context->hw_register.a20 = 0xA20;
87+
thread_context->hw_register.a23 = 0xA23;
88+
thread_context->hw_register.a22 = 0xA22;
89+
thread_context->hw_register.a25 = 0xA25;
90+
thread_context->hw_register.a24 = 0xA24;
91+
thread_context->hw_register.a27 = 0xA27;
92+
thread_context->hw_register.a26 = 0xA26;
93+
thread_context->hw_register.a29 = 0xA29;
94+
thread_context->hw_register.a28 = 0xA28;
95+
thread_context->hw_register.a31 = 0xA31;
96+
thread_context->hw_register.a30 = 0xA30;
97+
98+
thread_context->hw_register.a1 = 0xA01;
99+
thread_context->hw_register.a0 = 0xA00;
100+
thread_context->hw_register.a3 = 0xA03;
101+
thread_context->hw_register.a2 = 0xA02;
102+
thread_context->hw_register.a5 = 0xA05;
103+
thread_context->hw_register.a4 = (rt_uint32_t)parameter;
104+
thread_context->hw_register.a7 = 0xA07;
105+
thread_context->hw_register.a6 = 0xA06;
106+
thread_context->hw_register.a9 = 0xA09;
107+
thread_context->hw_register.a8 = 0xA08;
108+
thread_context->hw_register.a11 = 0xA11;
109+
thread_context->hw_register.a10 = 0xA10;
110+
thread_context->hw_register.a13 = 0xA13;
111+
thread_context->hw_register.a12 = 0xA12;
112+
113+
thread_context->hw_register.a15 = 0xA15;
114+
thread_context->hw_register.a14 = 0xA14;
115+
thread_context->hw_register.dp = rt_hw_get_current_dp();
116+
thread_context->hw_register.sp = (rt_uint32_t)stk;
117+
118+
/* return task's current stack address */
119+
return (rt_uint8_t *)thread_context - 8;
120+
}

0 commit comments

Comments
 (0)