- I have researched this and am suprised to have not found anything.
- I've been putting off for around a month asking this as it seemed that there would be answers on the internet
MY ENVIRONMENT :
Operating System and Software
- Windows 7 Professional
- Arduino IDE Version 2.1.1
HARDWARE
- ESP32 Wroom
(Driver - CH340)
Although the board that i'm using is irrelevant to the question.
I have CP2102 and CH340 Dev boards , all the drivers are installed and working without issue
Also i won't mention libraries as they are also not relevant to my question
TO THE QUESTION...
Re ESP32 Dual core structure
I already know all this and the internet keeps just repeating it,
// My understanding of the Base skeleton Dual Core Structure is...
// Libraries would go here
// Initiate the TaskCodes
void Task1code( void * pvParameters ); //Initiates Task1code
void Task2code( void * pvParameters ); //Initiates Task2code
// Define the TaskHandlers
TaskHandle_t Task1; //Assigned to Core 0
TaskHandle_t Task2; //Assigned to Core 1
void setup()
{ // OPENS the void setup
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// TASK DEFINITIONS
*///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*/////////////////////////////////////////////////////////////////////////////////////////
------------------------------------------ TASK 1 -----------------------------------------
///////////////////////////////////////////////////////////////////////////////////////////
-------------------------------------------------------------------------------------------
Create Task1 , Executed in Task1code() function , On Core 0 , Priority 1
-------------------------------------------------------------------------------------------
*///
xTaskCreatePinnedToCore(
Task1code, /* Task function. */
"Task1",/* name of task. */
10000, /* Stack size of task */
NULL, /* parameter of the task */
0, /* priority of the task */
&Task1, /* Task handle to keep track of created task */
0); /* pin task to core 0 */
delay(5);
/*/////////////////////////////////////////////////////////////////////////////////////////
------------------------------------------ TASK 2 -----------------------------------------
///////////////////////////////////////////////////////////////////////////////////////////
Create Task2 , Executed in Task2code() function , On Core 1 , Priority 1
-------------------------------------------------------------------------------------------
*///
xTaskCreatePinnedToCore(
Task2code, /* Task function. */
"Task2", /* name of task. */
10000, /* Stack size of task */
NULL, /* parameter of the task */
0, /* priority of the task */
&Task2, /* Task handle to keep track of created task */
1); /* pin task to core 1 */
delay(5);
///////////////////////////////////////////////////////////////////////////////////////////
} // CLOSES the void setup
// Then we execute the Functions
//-----------------------------------------------------------------------------------------
//Task1code:
//-----------------------------------------------------------------------------------------
void Task1code( void * pvParameters )
{
//Serial.println("STARTING CORE 0 ");
Serial.print("Task1 running on core ");
Serial.println(xPortGetCoreID());
for(;;)
{
// A HUGE CHUNK OF CODE IS INSERTED HERE
}
}
//-----------------------------------------------------------------------------------------
//Task2code:
//-----------------------------------------------------------------------------------------
void Task2code( void * pvParameters )
{
//Serial.println("STARTING CORE 1 ");
Serial.print("Task2 running on core ");
Serial.println(xPortGetCoreID());
for(;;)
{
}
}
void loop()
{ // OPENS the void loop
} // CLOSES the void loop
This is all Text book 101 Stuff and i understand it perfectly and this is the extent
that the internet will tell you
NOW HERE IS WHAT I WANT TO KNOW
Question 1 -
Re this
xTaskCreatePinnedToCore(
Task1code, /* Task function. */
"Task1",/* name of task. */
10000, /* Stack size of task */
NULL, /* parameter of the task */
0, /* priority of the task */
&Task1, /* Task handle to keep track of created task */
0); /* pin task to core 0 */
delay(5);
Am i correct in understanding that Stack "Size" is measured in "WORDS" and 1 Word = 2 Bytes.
so what then does "10000" Mean ? I mean i'm guessing and i shouldn't have to but...
10kB ?? so 5 Kilo Words ?
What do we do with "NULL Parameter of the task" what does this even mean
As for priority, 0 = the lowest, but then no other values are explained
is this 0 -1 or 0 - 100 ??
as for Task handle to keep track of tasks, i have seen this as &Task1 and NULL, I assume
i can change this to whatever i want right ?
QUESTION 2 -
Now RE Defining the Task Handlers
Usually you get told
TaskHandle_t Task1; //Assigned to Core 0
TaskHandle_t Task2; //Assigned to Core 1
Task 1 is for Core 0 and Task 2 for Core 1
But that can't be right because you can assign a task to a core
so i guess what i'm asking here is this...
Instead of just having 2 Tasks
TaskHandle_t Task1; //Assigned to Core 0
TaskHandle_t Task2; //Assigned to Core 1
Can i have , Say 20 ?
TaskHandle_t Task1; //Assigned to Core 0
TaskHandle_t Task2; //Assigned to Core 1
// All the way to 20
TaskHandle_t Task19; //Assigned to Core 1
TaskHandle_t Task20; //Assigned to Core 1
and then if i understand this correctly
My code would then look like this (as a Skeleton Structure)
// Libraries would go here
// Initiates the 20 TaskCodes
void Task1code( void * pvParameters ); //Initiates Task1code
void Task2code( void * pvParameters ); //Initiates Task2code
// All the way to 20
void Task19code( void * pvParameters ); //Initiates Task19code
void Task20code( void * pvParameters ); //Initiates Task20code
// Initiates the 20 TaskHandlers
TaskHandle_t Task1; //Assigned to Core 0
TaskHandle_t Task2; //Assigned to Core 1
// All the way to 20
TaskHandle_t Task19; //Assigned to Core 1
TaskHandle_t Task20; //Assigned to Core 1
void setup()
{ // OPENS the void setup
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// TASK DEFINITIONS
*///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*/////////////////////////////////////////////////////////////////////////////////////////
------------------------------------------ TASK 1 -----------------------------------------
///////////////////////////////////////////////////////////////////////////////////////////
-------------------------------------------------------------------------------------------
Create Task1 , Executed in Task1code() function , On Core 0 , Priority 1
-------------------------------------------------------------------------------------------
*///
xTaskCreatePinnedToCore(
Task1code, /* Task function. */
"Task1",/* name of task. */
10000, /* Stack size of task */
NULL, /* parameter of the task */
0, /* priority of the task */
&Task1, /* Task handle to keep track of created task */
0); /* pin task to core 0 */
delay(5);
/*/////////////////////////////////////////////////////////////////////////////////////////
------------------------------------------ TASK 2 -----------------------------------------
///////////////////////////////////////////////////////////////////////////////////////////
Create Task2 , Executed in Task2code() function , On Core 1 , Priority 1
-------------------------------------------------------------------------------------------
*///
xTaskCreatePinnedToCore(
Task2code, /* Task function. */
"Task2", /* name of task. */
10000, /* Stack size of task */
NULL, /* parameter of the task */
0, /* priority of the task */
&Task2, /* Task handle to keep track of created task */
1); /* pin task to core 1 */
delay(5);
///////////////////////////////////////////////////////////////////////////////////////////
// All the way to 20
/*/////////////////////////////////////////////////////////////////////////////////////////
------------------------------------------ TASK 19 -----------------------------------------
///////////////////////////////////////////////////////////////////////////////////////////
-------------------------------------------------------------------------------------------
Create Task19 , Executed in Task19code() function , On Core 1 , Priority 1
-------------------------------------------------------------------------------------------
*///
xTaskCreatePinnedToCore(
Task19code, /* Task function. */
"Task19", /* name of task. */
10000, /* Stack size of task */
NULL, /* parameter of the task */
0, /* priority of the task */
&Task19, /* Task handle to keep track of created task */
0); /* pin task to core 0 */
delay(5);
/*/////////////////////////////////////////////////////////////////////////////////////////
------------------------------------------ TASK 20 -----------------------------------------
///////////////////////////////////////////////////////////////////////////////////////////
-------------------------------------------------------------------------------------------
Create Task20 , Executed in Task20code() function , On Core 1 , Priority 1
-------------------------------------------------------------------------------------------
create a task that will be executed in the Task1code() function,
with priority 1 and executed on core 0
*///
xTaskCreatePinnedToCore(
Task20code, /* Task function. */
"Task20", /* name of task. */
10000, /* Stack size of task */
NULL, /* parameter of the task */
0, /* priority of the task */
&Task20, /* Task handle to keep track of created task */
0); /* pin task to core 0 */
delay(5);
/*/////////////////////////////////////////////////////////////////////////////////////////
} // CLOSES the void setup
// Then we execute the Functions
//-----------------------------------------------------------------------------------------
//Task1code:
//-----------------------------------------------------------------------------------------
void Task1code( void * pvParameters )
{
//Serial.println("STARTING CORE 0 ");
Serial.print("Task1 running on core ");
Serial.println(xPortGetCoreID());
for(;;)
{
// A HUGE CHUNK OF CODE IS INSERTED HERE
}
}
//-----------------------------------------------------------------------------------------
//Task2code:
//-----------------------------------------------------------------------------------------
void Task2code( void * pvParameters )
{
//Serial.println("STARTING CORE 1 ");
Serial.print("Task2 running on core ");
Serial.println(xPortGetCoreID());
for(;;)
{
// A HUGE CHUNK OF CODE IS INSERTED HERE
}
}
// All the way to 20
//-----------------------------------------------------------------------------------------
//Task19code:
//-----------------------------------------------------------------------------------------
void Task19code( void * pvParameters )
{
//Serial.println("STARTING CORE 1 ");
Serial.print("Task19 running on core ");
Serial.println(xPortGetCoreID());
for(;;)
{
// A HUGE CHUNK OF CODE IS INSERTED HERE
}
}
//-----------------------------------------------------------------------------------------
//Task20code:
//-----------------------------------------------------------------------------------------
void Task20code( void * pvParameters )
{
//Serial.println("STARTING CORE 1 ");
Serial.print("Task2 running on core ");
Serial.println(xPortGetCoreID());
for(;;)
{
// A HUGE CHUNK OF CODE IS INSERTED HERE
}
}
void loop()
{ // OPENS the void loop
} // CLOSES the void loop
Have i understood that correctly ?
QUESTION 3 - Can i then somewhat eliminate , Switch / Case / Break ?
so if i have a remote control and i want to create LED Strip Sequences for example
I was thinking i could assign 1 Task for the I.R. Receiver to listen for the I.R. Signal
and then the remote will have 10 Buttons and each one control a light sequence
Could i then Instead of creating a CASE for each button
Could i just create a Task for each button ?
These are the things that i'm unclear on because there is nothing on the internet that explains anything beyond Task1 and Task 2
and Lastly, is there any reason why this
xTaskCreatePinnedToCore(
Task1code, /* Task function. */
"Task1",/* name of task. */
10000, /* Stack size of task */
NULL, /* parameter of the task */
0, /* priority of the task */
&Task1, /* Task handle to keep track of created task */
0); /* pin task to core 0 */
delay(5);
Can't look like this
xTaskCreatePinnedToCore(
Task1code, /* Task function. */
"Task1",/* name of task. */
10000, /* Stack size of task */
NULL, /* parameter of the task */
0, /* priority of the task */
&Task1, /* Task handle to keep track of created task */
0); /* pin task to core 0 */
delay(5);
and i am aware that i can do this as well if i want
xTaskCreatePinnedToCore(Task1code, "Task1", 10000, NULL, 1, NULL, 0);
Thanks ahead of time
