Can Lua run within the real-time kernel?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
18 messages Options
Reply | Threaded
Open this post in threaded view
|

Can Lua run within the real-time kernel?

孙世龙 sunshilong
Hi,

Can Lua run within the real-time kernel?
Does anybody do such a test?

Is it possible to run Lua scripts on the controller for real-time control?

Best regards
Sunshilong
Reply | Threaded
Open this post in threaded view
|

Re: Can Lua run within the real-time kernel?

Rob Kendrick-2
On Wed, Sep 16, 2020 at 09:39:34AM +0800, 孙世龙 sunshilong wrote:
> Hi,
>
> Can Lua run within the real-time kernel?
> Does anybody do such a test?

Which real time kernel?

> Is it possible to run Lua scripts on the controller for real-time control?

In general, it's best to avoid languages with garbage collection for
real time applications as they introduce far too much unpredictability,
but it depends on how hard real time you are.  Things to consider are:
will physical damage or monetary loss occur if you miss a deadline, are
your deadlines measured in microseconds?

If the answer is no to both you're probably fine!

B.
Reply | Threaded
Open this post in threaded view
|

Re: Can Lua run within the real-time kernel?

孙世龙 sunshilong
Hi,

>> Can Lua run within the real-time kernel?
>> Does anybody do such a test?
>Which real time kernel?
Xenomai. Did anybody run Lua within xenomai+linux kernel?

>> Is it possible to run Lua scripts on the controller for real-time control?

>In general, it's best to avoid languages with garbage collection for
>real time applications as they introduce far too much unpredictability,
>but it depends on how hard real time you are.  Things to consider are:
>will physical damage or monetary loss occur if you miss a deadline, are
>your deadlines measured in microseconds?
Basically, soft real-time is needed.






On Wed, Sep 16, 2020 at 3:04 PM Rob Kendrick <[hidden email]> wrote:

>
> On Wed, Sep 16, 2020 at 09:39:34AM +0800, 孙世龙 sunshilong wrote:
> > Hi,
> >
> > Can Lua run within the real-time kernel?
> > Does anybody do such a test?
>
> Which real time kernel?
>
> > Is it possible to run Lua scripts on the controller for real-time control?
>
> In general, it's best to avoid languages with garbage collection for
> real time applications as they introduce far too much unpredictability,
> but it depends on how hard real time you are.  Things to consider are:
> will physical damage or monetary loss occur if you miss a deadline, are
> your deadlines measured in microseconds?
>
> If the answer is no to both you're probably fine!
>
> B.
Reply | Threaded
Open this post in threaded view
|

Re: Can Lua run within the real-time kernel?

Francisco Olarte
On Wed, Sep 16, 2020 at 1:21 PM 孙世龙 sunshilong <[hidden email]> wrote:
> >will physical damage or monetary loss occur if you miss a deadline, are
> >your deadlines measured in microseconds?
> Basically, soft real-time is needed.

You can try to trade speed for jitter if code is fast enough. I mean,
I have a system which is somehow realtime, I process messages in lua
in response to VoIP call events. I can take a couple milliseconds, and
normally finish in a hundreds of microseconds. I experimented by
running a collection after each message, the mean handling time was
higher but deviation was lower  ( as I had a network of long lived
objects implementing the handlers and a bunch of data generated to
handle the message and expiring after handling ) ( I can try to dig
out the code, but I zapped it many lua versions ago  as collection
pauses where very small and I didn't want to maintain the extra code
).

Francisco Olarte.
Reply | Threaded
Open this post in threaded view
|

Re: Can Lua run within the real-time kernel?

Tim McCracken
In reply to this post by 孙世龙 sunshilong

Can Lua run within the real-time kernel?
Does anybody do such a test?

Is it possible to run Lua scripts on the controller for real-time control?
Do you truly want to run it "within" the kernel, or use it for a wrapper around the kernel?

The real time kernels I have worked with are pretty complete and rarely need anything added within the kernel for real time control itself. As someone else pointed out garbage collection will make the kernel non-deterministic. However, you can leave the "hard" real time tasks coded in 'C' while providing a Lua thin wrapper around the kernel API (and other APIs such as network) and thereby support "soft" real time tasks that are written in Lua. A pretty good hybrid solution that I experimented with sometime ago. There are a number of commercial products that use this solution to provide end user programmability on a closed source product.


From: 孙世龙 sunshilong <[hidden email]>
Sent: Tuesday, September 15, 2020 8:39 PM
To: Lua mailing list <[hidden email]>
Subject: Can Lua run within the real-time kernel?
 
Hi,

Can Lua run within the real-time kernel?
Does anybody do such a test?

Is it possible to run Lua scripts on the controller for real-time control?

Best regards
Sunshilong
Reply | Threaded
Open this post in threaded view
|

Re: Can Lua run within the real-time kernel?

孙世龙 sunshilong
In reply to this post by Francisco Olarte
Hi, Francisco Olarte

Thank you for your reply.

>>>will physical damage or monetary loss occur if you miss a deadline, are
>>>your deadlines measured in microseconds?
>> Basically, soft real-time is needed.
>I mean, I have a system which is somehow realtime, I process messages
>in lua in response to VoIP call events.
Does Lua run on a realtime OS to process VoIP call events?
What OS do you use?

Best regards
Sunshilong

On Wed, Sep 16, 2020 at 7:42 PM Francisco Olarte <[hidden email]> wrote:

>
> On Wed, Sep 16, 2020 at 1:21 PM 孙世龙 sunshilong <[hidden email]> wrote:
> > >will physical damage or monetary loss occur if you miss a deadline, are
> > >your deadlines measured in microseconds?
> > Basically, soft real-time is needed.
>
> You can try to trade speed for jitter if code is fast enough. I mean,
> I have a system which is somehow realtime, I process messages in lua
> in response to VoIP call events. I can take a couple milliseconds, and
> normally finish in a hundreds of microseconds. I experimented by
> running a collection after each message, the mean handling time was
> higher but deviation was lower  ( as I had a network of long lived
> objects implementing the handlers and a bunch of data generated to
> handle the message and expiring after handling ) ( I can try to dig
> out the code, but I zapped it many lua versions ago  as collection
> pauses where very small and I didn't want to maintain the extra code
> ).
>
> Francisco Olarte.
Reply | Threaded
Open this post in threaded view
|

Re: Can Lua run within the real-time kernel?

孙世龙 sunshilong
In reply to this post by Tim McCracken
Hi, Tim McCracken

>>Can Lua run within the real-time kernel?
>>Does anybody do such a test?
>>Is it possible to run Lua scripts on the controller for real-time control?
>Do you truly want to run it "within" the kernel, or use it for a wrapper around the kernel?
Sorry for misleading you.
I doubt whether Lua could run on the real-time kernel or not.  Did you
achieve it?
Should I run on a real-time OS if I intend to run Lua scripts on the
controller for real-time control?

Best regards
Sunshilong

On Wed, Sep 16, 2020 at 9:08 PM Tim McCracken <[hidden email]> wrote:

>
>
> Can Lua run within the real-time kernel?
> Does anybody do such a test?
>
> Is it possible to run Lua scripts on the controller for real-time control?
>
> Do you truly want to run it "within" the kernel, or use it for a wrapper around the kernel?
>
> The real time kernels I have worked with are pretty complete and rarely need anything added within the kernel for real time control itself. As someone else pointed out garbage collection will make the kernel non-deterministic. However, you can leave the "hard" real time tasks coded in 'C' while providing a Lua thin wrapper around the kernel API (and other APIs such as network) and thereby support "soft" real time tasks that are written in Lua. A pretty good hybrid solution that I experimented with sometime ago. There are a number of commercial products that use this solution to provide end user programmability on a closed source product.
>
> ________________________________
> From: 孙世龙 sunshilong <[hidden email]>
> Sent: Tuesday, September 15, 2020 8:39 PM
> To: Lua mailing list <[hidden email]>
> Subject: Can Lua run within the real-time kernel?
>
> Hi,
>
> Can Lua run within the real-time kernel?
> Does anybody do such a test?
>
> Is it possible to run Lua scripts on the controller for real-time control?
>
> Best regards
> Sunshilong
Reply | Threaded
Open this post in threaded view
|

Re: Can Lua run within the real-time kernel?

François Perrad
In reply to this post by 孙世龙 sunshilong


Le mer. 16 sept. 2020 à 14:53, 孙世龙 sunshilong <[hidden email]> a écrit :
Hi, Francisco Olarte

Thank you for your reply.

>>>will physical damage or monetary loss occur if you miss a deadline, are
>>>your deadlines measured in microseconds?
>> Basically, soft real-time is needed.
>I mean, I have a system which is somehow realtime, I process messages
>in lua in response to VoIP call events.
Does Lua run on a realtime OS to process VoIP call events?

RaptorJIT could be the Lua interpreter that you need.

https://prosody.im/ (a XMPP server) works with LuaJIT.

François

 
What OS do you use?

Best regards
Sunshilong

On Wed, Sep 16, 2020 at 7:42 PM Francisco Olarte <[hidden email]> wrote:
>
> On Wed, Sep 16, 2020 at 1:21 PM 孙世龙 sunshilong <[hidden email]> wrote:
> > >will physical damage or monetary loss occur if you miss a deadline, are
> > >your deadlines measured in microseconds?
> > Basically, soft real-time is needed.
>
> You can try to trade speed for jitter if code is fast enough. I mean,
> I have a system which is somehow realtime, I process messages in lua
> in response to VoIP call events. I can take a couple milliseconds, and
> normally finish in a hundreds of microseconds. I experimented by
> running a collection after each message, the mean handling time was
> higher but deviation was lower  ( as I had a network of long lived
> objects implementing the handlers and a bunch of data generated to
> handle the message and expiring after handling ) ( I can try to dig
> out the code, but I zapped it many lua versions ago  as collection
> pauses where very small and I didn't want to maintain the extra code
> ).
>
> Francisco Olarte.
Reply | Threaded
Open this post in threaded view
|

Re: Can Lua run within the real-time kernel?

Tim McCracken
In reply to this post by 孙世龙 sunshilong

I doubt whether Lua could run on the real-time kernel or not.  Did you
achieve it?
Should I run on a real-time OS if I intend to run Lua scripts on the
controller for real-time control?
I think the question of "should you" has been answered correctly by others, with the key question always being how "hard" is each of your tasks that you plan to run in the kernel. You should not use it for tasks that need a hard response time or else bad things happen. However it's fine for "soft" real time tasks. There is no issue with having multiple tasks written in 'C' and running simultaneous Lua tasks subject to the normal RTOS caveats. 

NOTE: I am not familiar with the RTOS you mentioned. I am familiar with FreeRTOS and the uCOS, which are very similar to other pure RTOS kernels - including all the way back to iRMX in the 1980s. (the 'u' in uCOS is actually the greek letter 'mu', but it's not clear to me if the author intended it to be pronounced 'mucous'. 🙂 )

Here is what I did, and yes it worked fine.
  1. Built a thin wrapper around the FreeRTOS API.
  2. Created a task in 'C' that created and ran a Lua interpreter. The Lua script must be an endless loop, just as if you were writing a C task.
  3. Communicated between my Lua task and 'C' tasks using queues.
I would describe it as a fairly trivial process as I had been working with the Lua C API for a while and had some experience with uCOS - a very similar RTOS. You wouldn't even need the full thin wrapper to prove the concept. You could wrap just the RTOS sleep() function, create a 'C' task that creates a Lua interpreter and run a simple script that prints "Hello, World" and then calls the RTOS sleep() function and loops back.


From: 孙世龙 sunshilong <[hidden email]>
Sent: Wednesday, September 16, 2020 8:29 AM
To: Lua mailing list <[hidden email]>; Tim McCracken <[hidden email]>
Subject: Re: Can Lua run within the real-time kernel?
 
Hi, Tim McCracken

>>Can Lua run within the real-time kernel?
>>Does anybody do such a test?
>>Is it possible to run Lua scripts on the controller for real-time control?
>Do you truly want to run it "within" the kernel, or use it for a wrapper around the kernel?
Sorry for misleading you.
I doubt whether Lua could run on the real-time kernel or not.  Did you
achieve it?
Should I run on a real-time OS if I intend to run Lua scripts on the
controller for real-time control?

Best regards
Sunshilong

On Wed, Sep 16, 2020 at 9:08 PM Tim McCracken <[hidden email]> wrote:
>
>
> Can Lua run within the real-time kernel?
> Does anybody do such a test?
>
> Is it possible to run Lua scripts on the controller for real-time control?
>
> Do you truly want to run it "within" the kernel, or use it for a wrapper around the kernel?
>
> The real time kernels I have worked with are pretty complete and rarely need anything added within the kernel for real time control itself. As someone else pointed out garbage collection will make the kernel non-deterministic. However, you can leave the "hard" real time tasks coded in 'C' while providing a Lua thin wrapper around the kernel API (and other APIs such as network) and thereby support "soft" real time tasks that are written in Lua. A pretty good hybrid solution that I experimented with sometime ago. There are a number of commercial products that use this solution to provide end user programmability on a closed source product.
>
> ________________________________
> From: 孙世龙 sunshilong <[hidden email]>
> Sent: Tuesday, September 15, 2020 8:39 PM
> To: Lua mailing list <[hidden email]>
> Subject: Can Lua run within the real-time kernel?
>
> Hi,
>
> Can Lua run within the real-time kernel?
> Does anybody do such a test?
>
> Is it possible to run Lua scripts on the controller for real-time control?
>
> Best regards
> Sunshilong
Reply | Threaded
Open this post in threaded view
|

Re: Can Lua run within the real-time kernel?

Viacheslav Usov
On Wed, Sep 16, 2020 at 5:03 PM Tim McCracken <[hidden email]> wrote:

> (the 'u' in uCOS is actually the greek letter 'mu', but it's not clear to me if the author intended it to be pronounced 'mucous'.  )

Given what Wikipedeia says, viz., "MicroC/OS, stylized as μC/OS", I'd
think otherwise :)

Unless there is some other uCOS.

Cheers,
V.
Reply | Threaded
Open this post in threaded view
|

Re: Can Lua run within the real-time kernel?

Philippe Verdy-2
I read it like "microcosm", i.e. a small isolated and autonomous universes which can continue to like and perform correctly by itself without depending on the outside. However if this evolution includes a growth (and not simply a survival in its existing state), it will fatally start to use external resources and depend on them, and it could fragment itself into competing microcosms...

Compare "uCOS" to "um" (common abbreviation of "micrometer" in US English (or "micrometre" in British English) reduced to the Basic Latin character set: this is not a latin letter u, but the symbol for the "micro-" prefix, borrowing the Greek mu letter used as well to write the same prefix in Greek where it originated).


Le mer. 16 sept. 2020 à 18:10, Viacheslav Usov <[hidden email]> a écrit :
On Wed, Sep 16, 2020 at 5:03 PM Tim McCracken <[hidden email]> wrote:

> (the 'u' in uCOS is actually the greek letter 'mu', but it's not clear to me if the author intended it to be pronounced 'mucous'.  )

Given what Wikipedeia says, viz., "MicroC/OS, stylized as μC/OS", I'd
think otherwise :)

Unless there is some other uCOS.

Cheers,
V.
Reply | Threaded
Open this post in threaded view
|

Re: Can Lua run within the real-time kernel?

孙世龙 sunshilong
In reply to this post by Tim McCracken
Hi,  Tim McCracken

Thank you for the clarification.

>Built a thin wrapper around the FreeRTOS API.
Include the Apis about real-time thread\mutex\conditional_variable?
Please let me know if I missed something.

Thank you for your attention to my question.  

Best regards
Sunshilong

On Wed, Sep 16, 2020 at 11:02 PM Tim McCracken <[hidden email]> wrote:

I doubt whether Lua could run on the real-time kernel or not.  Did you
achieve it?
Should I run on a real-time OS if I intend to run Lua scripts on the
controller for real-time control?
I think the question of "should you" has been answered correctly by others, with the key question always being how "hard" is each of your tasks that you plan to run in the kernel. You should not use it for tasks that need a hard response time or else bad things happen. However it's fine for "soft" real time tasks. There is no issue with having multiple tasks written in 'C' and running simultaneous Lua tasks subject to the normal RTOS caveats. 

NOTE: I am not familiar with the RTOS you mentioned. I am familiar with FreeRTOS and the uCOS, which are very similar to other pure RTOS kernels - including all the way back to iRMX in the 1980s. (the 'u' in uCOS is actually the greek letter 'mu', but it's not clear to me if the author intended it to be pronounced 'mucous'. 🙂 )

Here is what I did, and yes it worked fine.
  1. Built a thin wrapper around the FreeRTOS API.
  2. Created a task in 'C' that created and ran a Lua interpreter. The Lua script must be an endless loop, just as if you were writing a C task.
  3. Communicated between my Lua task and 'C' tasks using queues.
I would describe it as a fairly trivial process as I had been working with the Lua C API for a while and had some experience with uCOS - a very similar RTOS. You wouldn't even need the full thin wrapper to prove the concept. You could wrap just the RTOS sleep() function, create a 'C' task that creates a Lua interpreter and run a simple script that prints "Hello, World" and then calls the RTOS sleep() function and loops back.


From: 孙世龙 sunshilong <[hidden email]>
Sent: Wednesday, September 16, 2020 8:29 AM
To: Lua mailing list <[hidden email]>; Tim McCracken <[hidden email]>
Subject: Re: Can Lua run within the real-time kernel?
 
Hi, Tim McCracken

>>Can Lua run within the real-time kernel?
>>Does anybody do such a test?
>>Is it possible to run Lua scripts on the controller for real-time control?
>Do you truly want to run it "within" the kernel, or use it for a wrapper around the kernel?
Sorry for misleading you.
I doubt whether Lua could run on the real-time kernel or not.  Did you
achieve it?
Should I run on a real-time OS if I intend to run Lua scripts on the
controller for real-time control?

Best regards
Sunshilong

On Wed, Sep 16, 2020 at 9:08 PM Tim McCracken <[hidden email]> wrote:
>
>
> Can Lua run within the real-time kernel?
> Does anybody do such a test?
>
> Is it possible to run Lua scripts on the controller for real-time control?
>
> Do you truly want to run it "within" the kernel, or use it for a wrapper around the kernel?
>
> The real time kernels I have worked with are pretty complete and rarely need anything added within the kernel for real time control itself. As someone else pointed out garbage collection will make the kernel non-deterministic. However, you can leave the "hard" real time tasks coded in 'C' while providing a Lua thin wrapper around the kernel API (and other APIs such as network) and thereby support "soft" real time tasks that are written in Lua. A pretty good hybrid solution that I experimented with sometime ago. There are a number of commercial products that use this solution to provide end user programmability on a closed source product.
>
> ________________________________
> From: 孙世龙 sunshilong <[hidden email]>
> Sent: Tuesday, September 15, 2020 8:39 PM
> To: Lua mailing list <[hidden email]>
> Subject: Can Lua run within the real-time kernel?
>
> Hi,
>
> Can Lua run within the real-time kernel?
> Does anybody do such a test?
>
> Is it possible to run Lua scripts on the controller for real-time control?
>
> Best regards
> Sunshilong
Reply | Threaded
Open this post in threaded view
|

Re: Can Lua run within the real-time kernel?

Paul Ducklin
In reply to this post by 孙世龙 sunshilong
I use NodeMCU on an Espressif ESP32.

It’s basically a Lua-based OS for the ESP and a few other related microcontroller boards.

Check nodemcu/nodemcu-firmware on Github.

It consists of Lua and a bunch of relevant libraries (e.g. Wi-Fi, basic BLE, GPIO twiddling, outputting to various popular microcontroller displays) that are built using the Espressif IoT Development Framework that is based on FreeRTOS.

I really like it but I only use it for fun. How good it is for soft real-time programming I have no idea - I have just used it to play around with Bluetooth and Wi-Fi sniffing.

If you want to see what is possible using pure Lua-based firmware on a microcontroller you might as well try it.

There is an ESP8266 version (where you can choose Lua 5.1 or 5.3) and and ESP32 version (5.1 only). Suitable development test boards are a couple of dollars each, USB powered and with a USB UART so you don’t even need to put them on a breadboard.

I have also tried Whitecatboard, a Lua-based RTOS firmware for a range of different boards (also ESP-based), but haven’t done anything serious with it.

Check whitecatboard/Lua-RTOS-ESP32 on Github.







> On 16 Sep 2020, at 02:40, 孙世龙 sunshilong <[hidden email]> wrote:
>
> Hi,
>
> Can Lua run within the real-time kernel?
> Does anybody do such a test?
>
> Is it possible to run Lua scripts on the controller for real-time control?
>
> Best regards
> Sunshilong
Reply | Threaded
Open this post in threaded view
|

RE: Can Lua run within the real-time kernel?

Tom Becker
Wow! That looks like a great little device.


-----Original Message-----
From: Paul Ducklin <[hidden email]>
Sent: Saturday, September 19, 2020 4:04 PM
To: Lua mailing list <[hidden email]>
Subject: Re: Can Lua run within the real-time kernel?

I use NodeMCU on an Espressif ESP32.

It’s basically a Lua-based OS for the ESP and a few other related microcontroller boards.

Check nodemcu/nodemcu-firmware on Github.

It consists of Lua and a bunch of relevant libraries (e.g. Wi-Fi, basic BLE, GPIO twiddling, outputting to various popular microcontroller displays) that are built using the Espressif IoT Development Framework that is based on FreeRTOS.

I really like it but I only use it for fun. How good it is for soft real-time programming I have no idea - I have just used it to play around with Bluetooth and Wi-Fi sniffing.

If you want to see what is possible using pure Lua-based firmware on a microcontroller you might as well try it.

There is an ESP8266 version (where you can choose Lua 5.1 or 5.3) and and ESP32 version (5.1 only). Suitable development test boards are a couple of dollars each, USB powered and with a USB UART so you don’t even need to put them on a breadboard.

I have also tried Whitecatboard, a Lua-based RTOS firmware for a range of different boards (also ESP-based), but haven’t done anything serious with it.

Check whitecatboard/Lua-RTOS-ESP32 on Github.







> On 16 Sep 2020, at 02:40, 孙世龙 sunshilong <[hidden email]> wrote:
>
> Hi,
>
> Can Lua run within the real-time kernel?
> Does anybody do such a test?
>
> Is it possible to run Lua scripts on the controller for real-time control?
>
> Best regards
> Sunshilong
*******************************************************************
IMPORTANT MESSAGE FOR RECIPIENTS IN THE U.S.A.:
This message may constitute an advertisement of a BD group's products or services or a solicitation of interest in them. If this is such a message and you would like to opt out of receiving future advertisements or solicitations from this BD group, please forward this e-mail to [hidden email]. [BD.v1.0]
*******************************************************************
This message (which includes any attachments) is intended only for the designated recipient(s). It may contain confidential or proprietary information and may be subject to the attorney-client privilege or other confidentiality protections. If you are not a designated recipient, you may not review, use, copy or distribute this message. If you received this in error, please notify the sender by reply e-mail and delete this message. Thank you.
*******************************************************************
Corporate Headquarters Mailing Address: BD (Becton, Dickinson and Company) 1 Becton Drive Franklin Lakes, NJ 07417 U.S.A.
Reply | Threaded
Open this post in threaded view
|

Re: Can Lua run within the real-time kernel?

孙世龙 sunshilong
In reply to this post by Paul Ducklin
Hi, Paul Ducklin

> There is an ESP8266 version (where you can choose Lua 5.1 or 5.3) and ESP32 version (5.1 only).
So Lua runs on FreeRTOS for ESP8266?
There is a folder named as FreeRTOS.

Best regards
Sunshilong

On Sun, Sep 20, 2020 at 7:20 AM Paul Ducklin <[hidden email]> wrote:

>
> I use NodeMCU on an Espressif ESP32.
>
> It’s basically a Lua-based OS for the ESP and a few other related microcontroller boards.
>
> Check nodemcu/nodemcu-firmware on Github.
>
> It consists of Lua and a bunch of relevant libraries (e.g. Wi-Fi, basic BLE, GPIO twiddling, outputting to various popular microcontroller displays) that are built using the Espressif IoT Development Framework that is based on FreeRTOS.
>
> I really like it but I only use it for fun. How good it is for soft real-time programming I have no idea - I have just used it to play around with Bluetooth and Wi-Fi sniffing.
>
> If you want to see what is possible using pure Lua-based firmware on a microcontroller you might as well try it.
>
> There is an ESP8266 version (where you can choose Lua 5.1 or 5.3) and and ESP32 version (5.1 only). Suitable development test boards are a couple of dollars each, USB powered and with a USB UART so you don’t even need to put them on a breadboard.
>
> I have also tried Whitecatboard, a Lua-based RTOS firmware for a range of different boards (also ESP-based), but haven’t done anything serious with it.
>
> Check whitecatboard/Lua-RTOS-ESP32 on Github.
>
>
>
>
>
>
>
> > On 16 Sep 2020, at 02:40, 孙世龙 sunshilong <[hidden email]> wrote:
> >
> > Hi,
> >
> > Can Lua run within the real-time kernel?
> > Does anybody do such a test?
> >
> > Is it possible to run Lua scripts on the controller for real-time control?
> >
> > Best regards
> > Sunshilong
Reply | Threaded
Open this post in threaded view
|

Re: Can Lua run within the real-time kernel?

Paul Ducklin
Yes, they basically ported Lua to the Espressif  Development Framework, which is based on FreeRTOS.

They modified the package system so you can require() code that runs directly out of flash memory, thus saving RAM, which is limited. Also they got rid of parts of Lua that were not useful or possible on FreeRTOS, such as ox.execute() and io.popen(). And they converted the I/O libraries and the default programming style to an event driven mode, like Node.js.

If you want to see how they did it, try diffing the Lua files in the NodeMCU code with the official release from PUC-Rio.



> On 21 Sep 2020, at 09:21, 孙世龙 sunshilong <[hidden email]> wrote:
>
> Hi, Paul Ducklin
>
>> There is an ESP8266 version (where you can choose Lua 5.1 or 5.3) and ESP32 version (5.1 only).
> So Lua runs on FreeRTOS for ESP8266?
> There is a folder named as FreeRTOS.
>
> Best regards
> Sunshilong
>
>> On Sun, Sep 20, 2020 at 7:20 AM Paul Ducklin <[hidden email]> wrote:
>>
>> I use NodeMCU on an Espressif ESP32.
>>
>> It’s basically a Lua-based OS for the ESP and a few other related microcontroller boards.
>>
>> Check nodemcu/nodemcu-firmware on Github.
>>
>> It consists of Lua and a bunch of relevant libraries (e.g. Wi-Fi, basic BLE, GPIO twiddling, outputting to various popular microcontroller displays) that are built using the Espressif IoT Development Framework that is based on FreeRTOS.
>>
>> I really like it but I only use it for fun. How good it is for soft real-time programming I have no idea - I have just used it to play around with Bluetooth and Wi-Fi sniffing.
>>
>> If you want to see what is possible using pure Lua-based firmware on a microcontroller you might as well try it.
>>
>> There is an ESP8266 version (where you can choose Lua 5.1 or 5.3) and and ESP32 version (5.1 only). Suitable development test boards are a couple of dollars each, USB powered and with a USB UART so you don’t even need to put them on a breadboard.
>>
>> I have also tried Whitecatboard, a Lua-based RTOS firmware for a range of different boards (also ESP-based), but haven’t done anything serious with it.
>>
>> Check whitecatboard/Lua-RTOS-ESP32 on Github.
>>
>>
>>
>>
>>
>>
>>
>>> On 16 Sep 2020, at 02:40, 孙世龙 sunshilong <[hidden email]> wrote:
>>>
>>> Hi,
>>>
>>> Can Lua run within the real-time kernel?
>>> Does anybody do such a test?
>>>
>>> Is it possible to run Lua scripts on the controller for real-time control?
>>>
>>> Best regards
>>> Sunshilong
Reply | Threaded
Open this post in threaded view
|

Re: Can Lua run within the real-time kernel?

孙世龙 sunshilong
Hi, Paul Ducklin

Thank you for your generous help.

>If you want to see how they did it, try diffing the Lua files in the NodeMCU code with the official release from PUC-Rio.
PUC-Rio?
Do you mean https://github.com/PUC-Rio (which is a user name on
Github, and there are no public repositories for it.)
 or
the code released by https://www.lua.org/?
I think you mean the latter one.

I want to make Lua run on real-time OS, so I think maybe
whitecatboard/Lua-RTOS-ESP32 is better for me to study since it
implements
a module named as sys which can create/resume/stop RTOS thread.
For NodeMCU, I didn't find such a implementation.
Please let me know if I miss something.

Best regards
Sunshilong

Thank you for your attention to my question.

On Tue, Sep 22, 2020 at 12:56 AM Paul Ducklin <[hidden email]> wrote:

>
> Yes, they basically ported Lua to the Espressif  Development Framework, which is based on FreeRTOS.
>
> They modified the package system so you can require() code that runs directly out of flash memory, thus saving RAM, which is limited. Also they got rid of parts of Lua that were not useful or possible on FreeRTOS, such as ox.execute() and io.popen(). And they converted the I/O libraries and the default programming style to an event driven mode, like Node.js.
>
> If you want to see how they did it, try diffing the Lua files in the NodeMCU code with the official release from PUC-Rio.
>
>
>
> > On 21 Sep 2020, at 09:21, 孙世龙 sunshilong <[hidden email]> wrote:
> >
> > Hi, Paul Ducklin
> >
> >> There is an ESP8266 version (where you can choose Lua 5.1 or 5.3) and ESP32 version (5.1 only).
> > So Lua runs on FreeRTOS for ESP8266?
> > There is a folder named as FreeRTOS.
> >
> > Best regards
> > Sunshilong
> >
> >> On Sun, Sep 20, 2020 at 7:20 AM Paul Ducklin <[hidden email]> wrote:
> >>
> >> I use NodeMCU on an Espressif ESP32.
> >>
> >> It’s basically a Lua-based OS for the ESP and a few other related microcontroller boards.
> >>
> >> Check nodemcu/nodemcu-firmware on Github.
> >>
> >> It consists of Lua and a bunch of relevant libraries (e.g. Wi-Fi, basic BLE, GPIO twiddling, outputting to various popular microcontroller displays) that are built using the Espressif IoT Development Framework that is based on FreeRTOS.
> >>
> >> I really like it but I only use it for fun. How good it is for soft real-time programming I have no idea - I have just used it to play around with Bluetooth and Wi-Fi sniffing.
> >>
> >> If you want to see what is possible using pure Lua-based firmware on a microcontroller you might as well try it.
> >>
> >> There is an ESP8266 version (where you can choose Lua 5.1 or 5.3) and and ESP32 version (5.1 only). Suitable development test boards are a couple of dollars each, USB powered and with a USB UART so you don’t even need to put them on a breadboard.
> >>
> >> I have also tried Whitecatboard, a Lua-based RTOS firmware for a range of different boards (also ESP-based), but haven’t done anything serious with it.
> >>
> >> Check whitecatboard/Lua-RTOS-ESP32 on Github.
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>> On 16 Sep 2020, at 02:40, 孙世龙 sunshilong <[hidden email]> wrote:
> >>>
> >>> Hi,
> >>>
> >>> Can Lua run within the real-time kernel?
> >>> Does anybody do such a test?
> >>>
> >>> Is it possible to run Lua scripts on the controller for real-time control?
> >>>
> >>> Best regards
> >>> Sunshilong
Reply | Threaded
Open this post in threaded view
|

Re: Can Lua run within the real-time kernel?

孙世龙 sunshilong
Hi, Paul Ducklin

Sorry, I missed post the URL in the last email.

For details, see
Lua-RTOS-ESP32/components/lua/modules/sys/thread.c

It implements a module named as sys which can create/resume/stop RTOS thread.

Please let me know if I miss something.

Best Regards
Sunshilong

On Tue, Sep 22, 2020 at 11:18 AM 孙世龙 sunshilong <[hidden email]> wrote:

>
> Hi, Paul Ducklin
>
> Thank you for your generous help.
>
> >If you want to see how they did it, try diffing the Lua files in the NodeMCU code with the official release from PUC-Rio.
> PUC-Rio?
> Do you mean https://github.com/PUC-Rio (which is a user name on
> Github, and there are no public repositories for it.)
>  or
> the code released by https://www.lua.org/?
> I think you mean the latter one.
>
> I want to make Lua run on real-time OS, so I think maybe
> whitecatboard/Lua-RTOS-ESP32 is better for me to study since it
> implements
> a module named as sys which can create/resume/stop RTOS thread.
> For NodeMCU, I didn't find such a implementation.
> Please let me know if I miss something.
>
> Best regards
> Sunshilong
>
> Thank you for your attention to my question.
>
> On Tue, Sep 22, 2020 at 12:56 AM Paul Ducklin <[hidden email]> wrote:
> >
> > Yes, they basically ported Lua to the Espressif  Development Framework, which is based on FreeRTOS.
> >
> > They modified the package system so you can require() code that runs directly out of flash memory, thus saving RAM, which is limited. Also they got rid of parts of Lua that were not useful or possible on FreeRTOS, such as ox.execute() and io.popen(). And they converted the I/O libraries and the default programming style to an event driven mode, like Node.js.
> >
> > If you want to see how they did it, try diffing the Lua files in the NodeMCU code with the official release from PUC-Rio.
> >
> >
> >
> > > On 21 Sep 2020, at 09:21, 孙世龙 sunshilong <[hidden email]> wrote:
> > >
> > > Hi, Paul Ducklin
> > >
> > >> There is an ESP8266 version (where you can choose Lua 5.1 or 5.3) and ESP32 version (5.1 only).
> > > So Lua runs on FreeRTOS for ESP8266?
> > > There is a folder named as FreeRTOS.
> > >
> > > Best regards
> > > Sunshilong
> > >
> > >> On Sun, Sep 20, 2020 at 7:20 AM Paul Ducklin <[hidden email]> wrote:
> > >>
> > >> I use NodeMCU on an Espressif ESP32.
> > >>
> > >> It’s basically a Lua-based OS for the ESP and a few other related microcontroller boards.
> > >>
> > >> Check nodemcu/nodemcu-firmware on Github.
> > >>
> > >> It consists of Lua and a bunch of relevant libraries (e.g. Wi-Fi, basic BLE, GPIO twiddling, outputting to various popular microcontroller displays) that are built using the Espressif IoT Development Framework that is based on FreeRTOS.
> > >>
> > >> I really like it but I only use it for fun. How good it is for soft real-time programming I have no idea - I have just used it to play around with Bluetooth and Wi-Fi sniffing.
> > >>
> > >> If you want to see what is possible using pure Lua-based firmware on a microcontroller you might as well try it.
> > >>
> > >> There is an ESP8266 version (where you can choose Lua 5.1 or 5.3) and and ESP32 version (5.1 only). Suitable development test boards are a couple of dollars each, USB powered and with a USB UART so you don’t even need to put them on a breadboard.
> > >>
> > >> I have also tried Whitecatboard, a Lua-based RTOS firmware for a range of different boards (also ESP-based), but haven’t done anything serious with it.
> > >>
> > >> Check whitecatboard/Lua-RTOS-ESP32 on Github.
> > >>
> > >>
> > >>
> > >>
> > >>
> > >>
> > >>
> > >>> On 16 Sep 2020, at 02:40, 孙世龙 sunshilong <[hidden email]> wrote:
> > >>>
> > >>> Hi,
> > >>>
> > >>> Can Lua run within the real-time kernel?
> > >>> Does anybody do such a test?
> > >>>
> > >>> Is it possible to run Lua scripts on the controller for real-time control?
> > >>>
> > >>> Best regards
> > >>> Sunshilong