Skip to content

Commit 02c6659

Browse files
committed
💚 fix c28x initial state issues according to TI docs
1 parent cb2fae3 commit 02c6659

7 files changed

Lines changed: 18 additions & 4 deletions

File tree

Include/Platform/C28X/Chip/TMS320F2812/rmp_platform_tms320f2812.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ do \
5454
InitSysCtrl(); \
5555
/* Initialize vector table and sources but not global interrupt yet */ \
5656
InitPieVectTable(); \
57+
IFR=0x0000U; \
5758
IER=0xFFFFU; \
5859
/* Initialize RAMFUNC */ \
5960
MemCopy(&RamfuncsLoadStart,&RamfuncsLoadEnd,&RamfuncsRunStart); \

Include/Platform/C28X/Chip/TMS320F28335/rmp_platform_tms320f28335.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ do \
5454
InitSysCtrl(); \
5555
/* Initialize vector table and sources but not global interrupt yet */ \
5656
InitPieVectTable(); \
57+
IFR=0x0000U; \
5758
IER=0xFFFFU; \
5859
/* Initialize RAMFUNC */ \
5960
MemCopy(&RamfuncsLoadStart,&RamfuncsLoadEnd,&RamfuncsRunStart); \

Include/Platform/C28X/rmp_platform_c28x_ticc.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ RMP_C28X_SWITCH_PRE .macro
5151
MOV DP,#__RMP_C28X_SP_Kern
5252
MOV AL,@__RMP_C28X_SP_Kern
5353
MOV SP,AL
54+
SPM 0
55+
CLRC OVM
5456
.endm
5557

5658
;/* Finish up the context switch **********************************************/

Include/Test/Chip/rmp_test_tms320f2812.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,13 @@ Return : None.
6262
******************************************************************************/
6363
void Timer_Init(void)
6464
{
65+
CpuTimer1Regs.TCR.bit.TIE=0U;
6566
CpuTimer1Regs.TCR.bit.TSS=1U;
67+
CpuTimer1Regs.TCR.bit.TIF=0U;
6668
CpuTimer1Regs.PRD.all=0xFFFFU;
6769
CpuTimer1Regs.TPR.all=0U;
6870
CpuTimer1Regs.TPRH.all=0U;
6971
CpuTimer1Regs.TCR.bit.TRB=1U;
70-
CpuTimer1Regs.TCR.bit.TIE=0U;
7172
CpuTimer1Regs.TCR.bit.TSS=0U;
7273
}
7374
/* End Function:Timer_Init ***************************************************/

Include/Test/Chip/rmp_test_tms320f28335.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,13 @@ Return : None.
117117
******************************************************************************/
118118
void Timer_Init(void)
119119
{
120+
CpuTimer1Regs.TCR.bit.TIE=0U;
120121
CpuTimer1Regs.TCR.bit.TSS=1U;
122+
CpuTimer1Regs.TCR.bit.TIF=0U;
121123
CpuTimer1Regs.PRD.all=0xFFFFU;
122124
CpuTimer1Regs.TPR.all=0U;
123125
CpuTimer1Regs.TPRH.all=0U;
124126
CpuTimer1Regs.TCR.bit.TRB=1U;
125-
CpuTimer1Regs.TCR.bit.TIE=0U;
126127
CpuTimer1Regs.TCR.bit.TSS=0U;
127128
}
128129
/* End Function:Timer_Init ***************************************************/

Source/Platform/C28X/rmp_platform_c28x.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ rmp_ptr_t _RMP_Stack_Init(rmp_ptr_t Stack,
5151
Ctx->PC=Entry;
5252
Ctx->ACC=Param;
5353

54-
/* No product shift, sign extend, aux ptr 0, interrupt enabled upon entry */
54+
/* No product shift (SPM 0/PM=3'b001), sign extend enabled (SXM=1), no
55+
* saturation (OVM=0), aux ptr 0 (ARP=0), interrupt enabled (INTM=0),
56+
* no C27x compatibility mode (PAGE0=0) upon thread entry */
5557
Ctx->T_ST0=0x00000081U;
5658
Ctx->DP_ST1=0x00000A08U;
5759

Source/Platform/C28X/rmp_platform_c28x_ticc.s

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ RMP_C28X_SAVE .macro LABEL
138138
POP ACC
139139
AND AL,#0xFFFEU
140140
PUSH ACC
141-
;Push 0 for DBGSTAT; clear emulation context
141+
;Push 0 for DBGSTAT, may mess debugging up but we have no choice
142142
XOR AH,AH
143143
MOV AL,IER
144144
PUSH ACC
@@ -169,6 +169,12 @@ RMP_C28X_SWITCH .macro
169169
MOV DP,#__RMP_C28X_SP_Kern
170170
MOV AH,@__RMP_C28X_SP_Kern
171171
MOV SP,AH
172+
;C runtime assumes SPM 0 (PM=3'b001), OVM=0 and PAGE0=0, but PAGE0 is always
173+
;0 for C28x, and this yield stub is masqueraded as a C function. As a result,
174+
;we don't need to set anything here, because the compiler must have done that
175+
;for us. However, we have to SPM 0 and CLRC OVM at the interrupt because we
176+
;have no clue when an interrupt will kick in. We don't need to ASP/NASP
177+
;there because we're using a separate kernel stack to run the kernel code.
172178
LCR __RMP_Run_High
173179
MOV DP,#_RMP_SP_Cur
174180
MOV AH,@_RMP_SP_Cur

0 commit comments

Comments
 (0)