Skip to content

Commit

Permalink
💚 fix c28x initial state issues according to TI docs
Browse files Browse the repository at this point in the history
  • Loading branch information
EDI-Systems committed Jun 27, 2024
1 parent cb2fae3 commit 02c6659
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ do \
InitSysCtrl(); \
/* Initialize vector table and sources but not global interrupt yet */ \
InitPieVectTable(); \
IFR=0x0000U; \
IER=0xFFFFU; \
/* Initialize RAMFUNC */ \
MemCopy(&RamfuncsLoadStart,&RamfuncsLoadEnd,&RamfuncsRunStart); \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ do \
InitSysCtrl(); \
/* Initialize vector table and sources but not global interrupt yet */ \
InitPieVectTable(); \
IFR=0x0000U; \
IER=0xFFFFU; \
/* Initialize RAMFUNC */ \
MemCopy(&RamfuncsLoadStart,&RamfuncsLoadEnd,&RamfuncsRunStart); \
Expand Down
2 changes: 2 additions & 0 deletions Include/Platform/C28X/rmp_platform_c28x_ticc.inc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ RMP_C28X_SWITCH_PRE .macro
MOV DP,#__RMP_C28X_SP_Kern
MOV AL,@__RMP_C28X_SP_Kern
MOV SP,AL
SPM 0
CLRC OVM
.endm

;/* Finish up the context switch **********************************************/
Expand Down
3 changes: 2 additions & 1 deletion Include/Test/Chip/rmp_test_tms320f2812.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,13 @@ Return : None.
******************************************************************************/
void Timer_Init(void)
{
CpuTimer1Regs.TCR.bit.TIE=0U;
CpuTimer1Regs.TCR.bit.TSS=1U;
CpuTimer1Regs.TCR.bit.TIF=0U;
CpuTimer1Regs.PRD.all=0xFFFFU;
CpuTimer1Regs.TPR.all=0U;
CpuTimer1Regs.TPRH.all=0U;
CpuTimer1Regs.TCR.bit.TRB=1U;
CpuTimer1Regs.TCR.bit.TIE=0U;
CpuTimer1Regs.TCR.bit.TSS=0U;
}
/* End Function:Timer_Init ***************************************************/
Expand Down
3 changes: 2 additions & 1 deletion Include/Test/Chip/rmp_test_tms320f28335.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,13 @@ Return : None.
******************************************************************************/
void Timer_Init(void)
{
CpuTimer1Regs.TCR.bit.TIE=0U;
CpuTimer1Regs.TCR.bit.TSS=1U;
CpuTimer1Regs.TCR.bit.TIF=0U;
CpuTimer1Regs.PRD.all=0xFFFFU;
CpuTimer1Regs.TPR.all=0U;
CpuTimer1Regs.TPRH.all=0U;
CpuTimer1Regs.TCR.bit.TRB=1U;
CpuTimer1Regs.TCR.bit.TIE=0U;
CpuTimer1Regs.TCR.bit.TSS=0U;
}
/* End Function:Timer_Init ***************************************************/
Expand Down
4 changes: 3 additions & 1 deletion Source/Platform/C28X/rmp_platform_c28x.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ rmp_ptr_t _RMP_Stack_Init(rmp_ptr_t Stack,
Ctx->PC=Entry;
Ctx->ACC=Param;

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

Expand Down
8 changes: 7 additions & 1 deletion Source/Platform/C28X/rmp_platform_c28x_ticc.s
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ RMP_C28X_SAVE .macro LABEL
POP ACC
AND AL,#0xFFFEU
PUSH ACC
;Push 0 for DBGSTAT; clear emulation context
;Push 0 for DBGSTAT, may mess debugging up but we have no choice
XOR AH,AH
MOV AL,IER
PUSH ACC
Expand Down Expand Up @@ -169,6 +169,12 @@ RMP_C28X_SWITCH .macro
MOV DP,#__RMP_C28X_SP_Kern
MOV AH,@__RMP_C28X_SP_Kern
MOV SP,AH
;C runtime assumes SPM 0 (PM=3'b001), OVM=0 and PAGE0=0, but PAGE0 is always
;0 for C28x, and this yield stub is masqueraded as a C function. As a result,
;we don't need to set anything here, because the compiler must have done that
;for us. However, we have to SPM 0 and CLRC OVM at the interrupt because we
;have no clue when an interrupt will kick in. We don't need to ASP/NASP
;there because we're using a separate kernel stack to run the kernel code.
LCR __RMP_Run_High
MOV DP,#_RMP_SP_Cur
MOV AH,@_RMP_SP_Cur
Expand Down

0 comments on commit 02c6659

Please sign in to comment.