whitecatboard / Lua-RTOS-ESP32

Lua RTOS for ESP32
Other
1.18k stars 221 forks source link

Task exception #295

Closed Mynogs closed 2 years ago

Mynogs commented 4 years ago

Hello!

On your advice, I have rebuilt my system on tasks. Now the simulation main loop runs in its own task. In the block (module) 'ShowSubSystem' there is only a print(sim.timeS) in the block.step () function. block.start() is empty. Below is the source code. Interestingly, the simlation does two steps bevor the error appears (Start, Step 0, Step 0.1). What am I doing wrong?

sim = {
  assert = function(block, ok, message)
    assert(ok, message)
  end,
  stepRateS = 0.1,
  timeS = 0,
  step = 0,
  stepT0 = 0,
}

block = {
  ellapsedS = 0.1
}

block.ShowSubSystem = require 'ShowSubSystem' -- 0
block.ShowSubSystem.parent = block
block.start = block.ShowSubSystem.start
block.step = block.ShowSubSystem.step

block.start()
-- Main simulation loop
do
  if nvs.exists('p+', 'crash') then
    print('[p+] Crash detected:', nvs.read('p+', 'crash'))
    nvs.rm('p+', 'crash')
    os.rename('./startup.lua', './startup.old')
    while true do tmr.sleep(1) end
  else
    print('[p+] Start  simulation ' .. (sim.stepRateS * 1000) .. 'ms cycle time')
    nvs.write('p+', 'crash', true)
    block.start()
    local t = tmr.attach(
      math.floor(sim.stepRateS * 1000),
      function()
        block.step()
        collectgarbage()
        sim.step = sim.step + 1
        sim.stepT0 = sim.stepT0 + 1
        sim.timeS = sim.timeS + sim.stepRateS
        if nvs.exists('p+', 'crash') then
          nvs.rm('p+', 'crash')
        end
      end
    )
    t:start()
    while true do tmr.sleep(1) end
  end
end

Error message:

  /\       /\
 /  \_____/  \
/_____________\
W H I T E C A T

Lua RTOS beta 0.1. Copyright (C) 2015 - 2018 whitecatboard.org

build 1562924841
commit 7a38faedd7dc6df9ccf0517c2870a2de33757f9d
Running from factory partition
board type GENERIC

Lua RTOS beta 0.1 powered by Lua 5.3.4

Executing /system.lua ...
Executing /autorun.lua ...

/ > ShowSubSystem
Start
[p+] Start  simulation 100.0ms cycle time
ShowSubSystem
Start
Step    0
Step    0.1
assertion "res == coreID || res == portMUX_FREE_VAL" failed: file "/Users/jaumeolive/esp-idf/components/freertos/portmux_impl.inc.h", line 105, function: vPortCPUAcquireMutexIntsDisabledInternal
abort() was called at PC 0x4010ec93 on core 0

ELF file SHA256: 08e87e6104179fb0944400256cdd5d907b45ced194abcedba572e473466e06f6

Backtrace: 0x40090f3f:0x3ffbc8a0 0x40091281:0x3ffbc8c0 0x4010ec93:0x3ffbc8e0 0x40098471:0x3ffbc910 0x40097c2b:0x3ffbc930 0x40099e75:0x3ffbc970

Rebooting...
the0ne commented 2 years ago

@Mynogs did you solve this? If not, feel free to re-open the ticket.