I'm finding that the function "readFile" below takes about 240ms to retrieve a 12k file when it's called from code executing on core 0. When called from loop() (running on core 1), it takes about 1900ms to retrieve a 12k file, which is unacceptably slow.
Questions:
1. Does it make sense that the time to retrieve would differ depending on which core the function is called from? If so, could someone explain why that's the case?
2. If so....can someone help me set up the method to pin this function to core 0? I'm struggling with my attempts to do that, particularly in the 4th field of xTaskCreatePinnedToCore() where I need to pass the "parameter of the task". I've tried " (void*) (fs::FS &fs, const char * path, char* bufPtr)" but that isn't compiling for me. I'm mighty confused regarding what's supposed to be passed here, and would likely understand it better if I could see a working example.
Here's the function I'd like to pin to core 0. The main area of interest is really just the parameter list in the first line.
Code: Select all
void readFile(fs::FS &fs, const char * path, char* bufPtr) {
unsigned int i = 0;
File file = fs.open(path);
if (!file || file.isDirectory()) {
Serial.println("- failed to open file for reading");
bufPtr[0] = 0xFF;
}
while (file.available()) {
bufPtr[i++] = file.read();
}
file.close();
}
Code: Select all
xTaskCreatePinnedToCore(
readFile, /* Task function. */
"Task1", /* name of task. */
10000, /* Stack size of task */
(void*) (fs::FS &fs, const char * path, char* bufPtr), /* parameter of the task */
1, /* priority of the task */
&Task1, /* Task handle to keep track of created task */
0); /* pin task to core 0 */
Rick