mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-08 12:10:59 +00:00
Add checks for tasks woken up on other CPUs where needed, make xYieldPending and xPendingReadyList per-processor, add configurable ISR stack size to Kconfig, in general fix the entire wake-up-task-on-other-cpu-by-interrupt implementation
This commit is contained in:
@@ -44,64 +44,60 @@ ToDo: There is a small chance the CPU already has yielded when this ISR is servi
|
||||
the ISR will cause it to switch _away_ from it. portYIELD_FROM_ISR will probably just schedule the task again, but have to check that.
|
||||
*/
|
||||
static void esp_crosscore_isr(void *arg) {
|
||||
volatile uint32_t myReasonVal;
|
||||
volatile uint32_t myReasonVal;
|
||||
#if 0
|
||||
//A pointer to the correct reason array item is passed to this ISR.
|
||||
volatile uint32_t *myReason=arg;
|
||||
//A pointer to the correct reason array item is passed to this ISR.
|
||||
volatile uint32_t *myReason=arg;
|
||||
#else
|
||||
//Does not work yet, the interrupt code needs work to understand two separate interrupt and argument
|
||||
//tables...
|
||||
volatile uint32_t *myReason=&reason[xPortGetCoreID()];
|
||||
//Does not work yet, the interrupt code needs work to understand two separate interrupt and argument
|
||||
//tables...
|
||||
volatile uint32_t *myReason=&reason[xPortGetCoreID()];
|
||||
#endif
|
||||
//Clear the interrupt first.
|
||||
if (xPortGetCoreID()==0) {
|
||||
WRITE_PERI_REG(DPORT_CPU_INTR_FROM_CPU_0_REG, 0);
|
||||
} else {
|
||||
WRITE_PERI_REG(DPORT_CPU_INTR_FROM_CPU_1_REG, 0);
|
||||
}
|
||||
//Grab the reason and clear it.
|
||||
portENTER_CRITICAL(&reasonSpinlock);
|
||||
myReasonVal=*myReason;
|
||||
*myReason=0;
|
||||
portEXIT_CRITICAL(&reasonSpinlock);
|
||||
//Clear the interrupt first.
|
||||
if (xPortGetCoreID()==0) {
|
||||
WRITE_PERI_REG(DPORT_CPU_INTR_FROM_CPU_0_REG, 0);
|
||||
} else {
|
||||
WRITE_PERI_REG(DPORT_CPU_INTR_FROM_CPU_1_REG, 0);
|
||||
}
|
||||
//Grab the reason and clear it.
|
||||
portENTER_CRITICAL(&reasonSpinlock);
|
||||
myReasonVal=*myReason;
|
||||
*myReason=0;
|
||||
portEXIT_CRITICAL(&reasonSpinlock);
|
||||
|
||||
//Check what we need to do.
|
||||
if (myReasonVal&REASON_YIELD) {
|
||||
portYIELD_FROM_ISR();
|
||||
}
|
||||
|
||||
ets_printf("recv yield\n");
|
||||
//Check what we need to do.
|
||||
if (myReasonVal&REASON_YIELD) {
|
||||
portYIELD_FROM_ISR();
|
||||
}
|
||||
}
|
||||
|
||||
//Initialize the crosscore interrupt on this core. Call this once
|
||||
//on each active core.
|
||||
void esp_crosscore_int_init() {
|
||||
portENTER_CRITICAL(&reasonSpinlock);
|
||||
ets_printf("init cpu %d\n", xPortGetCoreID());
|
||||
reason[xPortGetCoreID()]=0;
|
||||
portEXIT_CRITICAL(&reasonSpinlock);
|
||||
ESP_INTR_DISABLE(ETS_FROM_CPU_INUM);
|
||||
if (xPortGetCoreID()==0) {
|
||||
intr_matrix_set(xPortGetCoreID(), ETS_FROM_CPU_INTR0_SOURCE, ETS_FROM_CPU_INUM);
|
||||
} else {
|
||||
intr_matrix_set(xPortGetCoreID(), ETS_FROM_CPU_INTR1_SOURCE, ETS_FROM_CPU_INUM);
|
||||
}
|
||||
xt_set_interrupt_handler(ETS_FROM_CPU_INUM, esp_crosscore_isr, (void*)&reason[xPortGetCoreID()]);
|
||||
ESP_INTR_ENABLE(ETS_FROM_CPU_INUM);
|
||||
portENTER_CRITICAL(&reasonSpinlock);
|
||||
reason[xPortGetCoreID()]=0;
|
||||
portEXIT_CRITICAL(&reasonSpinlock);
|
||||
ESP_INTR_DISABLE(ETS_FROM_CPU_INUM);
|
||||
if (xPortGetCoreID()==0) {
|
||||
intr_matrix_set(xPortGetCoreID(), ETS_FROM_CPU_INTR0_SOURCE, ETS_FROM_CPU_INUM);
|
||||
} else {
|
||||
intr_matrix_set(xPortGetCoreID(), ETS_FROM_CPU_INTR1_SOURCE, ETS_FROM_CPU_INUM);
|
||||
}
|
||||
xt_set_interrupt_handler(ETS_FROM_CPU_INUM, esp_crosscore_isr, (void*)&reason[xPortGetCoreID()]);
|
||||
ESP_INTR_ENABLE(ETS_FROM_CPU_INUM);
|
||||
}
|
||||
|
||||
void esp_crosscore_int_send_yield(int coreId) {
|
||||
ets_printf("send yield\n");
|
||||
assert(coreId<portNUM_PROCESSORS);
|
||||
//Mark the reason we interrupt the other CPU
|
||||
portENTER_CRITICAL(&reasonSpinlock);
|
||||
reason[coreId]|=REASON_YIELD;
|
||||
portEXIT_CRITICAL(&reasonSpinlock);
|
||||
//Poke the other CPU.
|
||||
if (coreId==0) {
|
||||
WRITE_PERI_REG(DPORT_CPU_INTR_FROM_CPU_0_REG, DPORT_CPU_INTR_FROM_CPU_0);
|
||||
} else {
|
||||
WRITE_PERI_REG(DPORT_CPU_INTR_FROM_CPU_1_REG, DPORT_CPU_INTR_FROM_CPU_1);
|
||||
}
|
||||
assert(coreId<portNUM_PROCESSORS);
|
||||
//Mark the reason we interrupt the other CPU
|
||||
portENTER_CRITICAL(&reasonSpinlock);
|
||||
reason[coreId]|=REASON_YIELD;
|
||||
portEXIT_CRITICAL(&reasonSpinlock);
|
||||
//Poke the other CPU.
|
||||
if (coreId==0) {
|
||||
WRITE_PERI_REG(DPORT_CPU_INTR_FROM_CPU_0_REG, DPORT_CPU_INTR_FROM_CPU_0);
|
||||
} else {
|
||||
WRITE_PERI_REG(DPORT_CPU_INTR_FROM_CPU_1_REG, DPORT_CPU_INTR_FROM_CPU_1);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user