With these modifications I can correct ulisp as a freertos task.
As an example, we run the task Taskmain(),“arduino loop()” and a second task TaskBlink(), which blinks led 2, (LED_BUILTIN did not work for me)
This works fine, the led blinks and through the serial port I have the ulisp repl.
If in the repl I execute for example (+ 2 2 2 2) many times and in less than a second it gives me this error
"touchreadGuru Meditation Error: Core 1 panic’ed (Unhandled debug exception). 14:29:05.013 -> Debug exception reason: Stack canary watchpoint triggered (Main) "
Could it be due to the execution time of the task?
Thanks
#if CONFIG_FREERTOS_UNICORE
#define ARDUINO_RUNNING_CORE 0
#else
#define ARDUINO_RUNNING_CORE 1
#endif
#define LED_BUILTIN 2
// Setup
void TaskBlink( void *pvParameters );
void TaskMain( void *pvParameters );
void setup () {
Serial.begin(9600);
int start = millis();
while ((millis() - start) < 5000) { if (Serial) break; }
initworkspace();
initenv();
initsleep();
initgfx();
pfstring(PSTR("uLisp 4.3a "), pserial); pln(pserial);
// Now set up two tasks to run independently.
xTaskCreatePinnedToCore(
TaskBlink
, "TaskBlink" // A name just for humans
, 1024 // This stack size can be checked & adjusted by reading the Stack Highwater
, NULL
, 2 // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest.
, NULL
, ARDUINO_RUNNING_CORE);
xTaskCreatePinnedToCore(
TaskMain
, "Main"
, 1024 // Stack size
, NULL
, 1 // Priority
, NULL
, ARDUINO_RUNNING_CORE);
}
void loop ()
{
}
void TaskMain(void *pvParameters) // This is a task.
{
(void) pvParameters;
if (!setjmp(exception)) {
#if defined(resetautorun)
volatile int autorun = 12; // Fudge to keep code size the same
#else
volatile int autorun = 13;
#endif
if (autorun == 12) autorunimage();
}
// Come here after error
vTaskDelay(100 / portTICK_PERIOD_MS);while (Serial.available()) Serial.read();
clrflag(NOESC); BreakLevel = 0;
for (int i=0; i<TRACEMAX; i++) TraceDepth[i] = 0;
#if defined(sdcardsupport)
SDpfile.close(); SDgfile.close();
#endif
#if defined(lisplibrary)
if (!tstflag(LIBRARYLOADED)) { setflag(LIBRARYLOADED); loadfromlibrary(NULL); }
#endif
client.stop();
repl(NULL);
}
void TaskBlink(void *pvParameters) // This is a task.
{
(void) pvParameters;
// initialize digital LED_BUILTIN on pin 13 as an output.
pinMode(2, OUTPUT);
for (;;) // A Task shall never return or exit.
{
digitalWrite(2, HIGH); // turn the LED on (HIGH is the voltage level)
vTaskDelay(1000 / portTICK_PERIOD_MS ); // vTaskDelay wants ticks, not milliseconds
digitalWrite(2, LOW); // turn the LED off by making the voltage LOW
vTaskDelay(1000 / portTICK_PERIOD_MS); // 1 second delay
}
}