Skip to content

Commit 17dfd0f

Browse files
authored
Update XMOS xcore.ai port to be compatible with v11.x (#1096)
* Fix kexcept function * Create dummy pxCurrentTCBs for xcore.ai port * Additional commentary * Add a layer of indirection to cope with singlecore * Clarify use of _DoException
1 parent 9e83829 commit 17dfd0f

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

portable/ThirdParty/xClang/XCOREAI/port.c

+33-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ static hwtimer_t xKernelTimer;
1212

1313
uint32_t ulPortYieldRequired[ portMAX_CORE_COUNT ] = { pdFALSE };
1414

15+
/* When this port was designed, it was assumed that pxCurrentTCBs would always
16+
exist and that it would always be an array containing pointers to the current
17+
TCBs for each core. In v11, this is not the case; if we are only running one
18+
core, the symbol is pxCurrentTCB instead. Therefore, this port adds a layer
19+
of indirection - we populate this pointer-to-pointer in the RTOS kernel entry
20+
function below. This makes this port agnostic to whether it is running on SMP
21+
or singlecore RTOS. */
22+
void ** xcorePvtTCBContainer;
23+
1524
/*-----------------------------------------------------------*/
1625

1726
void vIntercoreInterruptISR( void )
@@ -140,15 +149,37 @@ DEFINE_RTOS_KERNEL_ENTRY( void, vPortStartSchedulerOnCore, void )
140149
}
141150
#endif
142151

152+
/* Populate the TCBContainer depending on whether we're singlecore or SMP */
153+
#if ( configNUMBER_OF_CORES == 1 )
154+
{
155+
asm volatile (
156+
"ldaw %0, dp[pxCurrentTCB]\n\t"
157+
: "=r"(xcorePvtTCBContainer)
158+
: /* no inputs */
159+
: /* no clobbers */
160+
);
161+
}
162+
#else
163+
{
164+
asm volatile (
165+
"ldaw %0, dp[pxCurrentTCBs]\n\t"
166+
: "=r"(xcorePvtTCBContainer)
167+
: /* no inputs */
168+
: /* no clobbers */
169+
);
170+
}
171+
172+
#endif
173+
143174
debug_printf( "FreeRTOS Core %d initialized\n", xCoreID );
144175

145176
/*
146177
* Restore the context of the first thread
147178
* to run and jump into it.
148179
*/
149180
asm volatile (
150-
"mov r6, %0\n\t" /* R6 must be the FreeRTOS core ID*/
151-
"ldaw r5, dp[pxCurrentTCBs]\n\t" /* R5 must be the TCB list which is indexed by R6 */
181+
"mov r6, %0\n\t" /* R6 must be the FreeRTOS core ID. In singlecore this is always 0. */
182+
"ldw r5, dp[xcorePvtTCBContainer]\n\t" /* R5 must be the TCB list which is indexed by R6 */
152183
"bu _freertos_restore_ctx\n\t"
153184
: /* no outputs */
154185
: "r" ( xCoreID )

portable/ThirdParty/xClang/XCOREAI/portasm.S

+3-6
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,8 @@ rest of the ISR callback functions. */
1414
.issue_mode dual
1515
.cc_top kexcept.function, kexcept
1616
kexcept:
17-
ldc r11, 0x0008
18-
shl r11, r11, 16
19-
ldc r9, 0x0080
20-
or r11, r11, r9
21-
bau r11 //_TrapHandler is at 0x00080080. TODO: Is it always? Why can't I access the symbol _TrapHandler?
17+
bu _DoException /* This symbol is generated by the toolchain and */
18+
/* provides graceful exception handling */
2219

2320
_yield:
2421
{set sp, r4 /* Restore the task's SP to save the rest of its context. */
@@ -123,7 +120,7 @@ _yield_continue:
123120
ldaw r11, sp[37]}
124121
vstc r11[0]
125122
#endif
126-
ldaw r5, dp[pxCurrentTCBs] /* Get the current TCB array into r5. */
123+
ldw r5, dp[xcorePvtTCBContainer]
127124
ldw r1, r5[r0] /* Get this core's current TCB pointer into r1. */
128125
stw r4, r1[0x0] /* Save the current task's SP to the first */
129126
/* word (top of stack) in the current TCB. */

0 commit comments

Comments
 (0)