tinybasic icon indicating copy to clipboard operation
tinybasic copied to clipboard

Warm Restart

Open EncomLab opened this issue 1 year ago • 2 comments

On the SBC I use I have a button to pin 10 and this in setup:

//interrupt pin
  pinMode(interruptPin, INPUT);
  enableInterrupt(interruptPin, interruptFunction, FALLING);

that calls this function:

void interruptFunction() {
  current_line = 0;
  sp = program + sizeof(program);
  printmsg(okmsg);
}

Obviously this is for the BASIC interpreter I've been using - is there a way to implement something like this in your interpreter? When called it functions like a "break" and leaves the resident program and variable assignments intact.

EncomLab avatar Jul 18 '22 20:07 EncomLab

Transparent interrupt handling from BASIC is on my list for version 1.4. I will complete 1.3. and release it in a while and then start to work on this. It is not really easy to implement this. I have a concept for it but I am unsure which language features to use.

The way it needs to be done is to build an interrupt handler just like the function you show.

Then one has to catch the interrupt condition in the statement() loop and branch there to a new line. This way an interrupt could trigger a GOTO or GOSUB. Problem is that one has to handle infinite loops. If the interrupt comes frequently, the interpreter doesn’t have to to process the code. One would need an interrupt mask function in addition to the mechanism above.

If you want something very specific / quick and dirty, you could just add an interrupt handler and then deposite a value to a variable. Ideally a static variable A-Z. This is done through setvar(). The BASIC code could then poll state changes of this variable. Cleaner would be a new C variable and a function to access it.

Am 18.07.2022 um 22:53 schrieb Encom Lab @.***>:

On the SBC I use I have a button to pin 10 and this in setup:

//interrupt pin pinMode(interruptPin, INPUT); enableInterrupt(interruptPin, interruptFunction, FALLING); that calls this function:

void interruptFunction() { current_line = 0; sp = program + sizeof(program); printmsg(okmsg); } Obviously this is for the BASIC interpreter I've been using - is there a way to implement something like this in your interpreter? When called it functions like a "break" and leaves the resident program and variable assignments intact.

— Reply to this email directly, view it on GitHub https://github.com/slviajero/tinybasic/issues/27, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACSY56BNBSGI3P2M2DO22A3VUW725ANCNFSM535TSHIA. You are receiving this because you are subscribed to this thread.

slviajero avatar Jul 19 '22 05:07 slviajero

I appreciate this detailed description and look forward to the continued development of the interpreter. One of the functions I'm looking to add is the ability to handle data from rotary encoders which will require the implementation of ISR's in some form.

EncomLab avatar Jul 19 '22 12:07 EncomLab

Can you describe what you need / want? If I understand the use case I would be able to do something right away.

Am 19.07.2022 um 14:43 schrieb Encom Lab @.***>:

I appreciate this detailed description and look forward to the continued development of the interpreter. One of the functions I'm looking to add is the ability to handle data from rotary encoders which will require the implementation of ISR's in some form.

— Reply to this email directly, view it on GitHub https://github.com/slviajero/tinybasic/issues/27#issuecomment-1189006332, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACSY56EDXFLLDYHPYZ6FS73VU2PF3ANCNFSM535TSHIA. You are receiving this because you commented.

slviajero avatar Oct 11 '22 07:10 slviajero

Hi Stefan! I created a solution for my use case by adding the Attach Interrupts library and a loop function which calls XBREAK() when a pin is brought LOW. I have a ATmega1284 board that I use for controlling small robot platforms and it has a RESET button which resets the chip and a INTERRUPT button tied to INT0 in MightyCore. So now when I hit the Interrupt button it generates a BREAK which keeps the current program in memory which is ultimately what I wanted as obviously RESET does not.

Thanks for the follow up - I use this nearly every day. The ability to add functions is great - I've added servo commands, motor commands, ultrasonic sensors and soon am adding gyro and compass commands.

EncomLab avatar Oct 11 '22 11:10 EncomLab

Super! Can you send me the code with the interrupt routine? I would like to take a look at it. Currently I mostly work on hardware but will return to software during the winter. Then it is time for interrupt handling in the code. Best, Stefan

Am 11.10.2022 um 13:31 schrieb Encom Lab @.***>:

Hi Stefan! I created a solution for my use case by adding the Attach Interrupts library and a loop function which calls XBREAK() when a pin is brought LOW. I have a ATmega1284 board that I use for controlling small robot platforms and it has a RESET button which resets the chip and a INTERRUPT button tied to INT0 in MightyCore. So now when I hit the Interrupt button it generates a BREAK which keeps the current program in memory which is ultimately what I wanted as obviously RESET does not.

Thanks for the follow up - I use this nearly every day. The ability to add functions is great - I've added servo commands, motor commands, ultrasonic sensors and soon am adding gyro and compass commands.

— Reply to this email directly, view it on GitHub https://github.com/slviajero/tinybasic/issues/27#issuecomment-1274538378, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACSY56F2RJR52DXU67SQR4DWCVFZVANCNFSM535TSHIA. You are receiving this because you modified the open/close state.

slviajero avatar Oct 12 '22 19:10 slviajero

Hi Stefan! This is a pretty hacky implementation on my part but here goes - First I'm using my own SBC with the ATmega 1284 running Mightycore. On the PCB I have a tactile button connected to D10 for use as a Warm Reset on the previous version of BASIC I was using which is where the code I posted above comes from.
For this case I added the Arduino Library "EnableInterrupt". In the void loop I added: /* soft interrupt */ pinMode(10, INPUT_PULLUP); enableInterrupt(10, interruptFunctionSR, FALLING);

and then just call xbreak(): //soft reset void interruptFunctionSR() { xbreak(); } The main purpose for me is being able to break a loop without losing the program as would happen if I used a regular reset.

EncomLab avatar Oct 14 '22 21:10 EncomLab

That is pretty brutal. It works because most of the interpreter logic is stateless and xbreak() only changes „here“ i.e. the program execution cursor. This works almost always.There may be (very rare) situation where this breaks the interpreter.

By the way, BASIC can always be interrupted by sending the BREAKCHAR through the serial line. By default, BREAKCHAR is #. This is a clean way coming to interactive mode.

I will think about a clean way to implement your idea.

Am 14.10.2022 um 23:17 schrieb Encom Lab @.***>:

Hi Stefan! This is a pretty hacky implementation on my part but here goes - First I'm using my own SBC with the ATmega 1284 running Mightycore. On the PCB I have a tactile button connected to D10 for use as a Warm Reset on the previous version of BASIC I was using which is where the code I posted above comes from. For this case I added the Arduino Library "EnableInterrupt". In the void loop I added: /* soft interrupt */ pinMode(10, INPUT_PULLUP); enableInterrupt(10, interruptFunctionSR, FALLING);

and then just call xbreak(): //soft reset void interruptFunctionSR() { xbreak(); } The main purpose for me is being able to break a loop without losing the program as would happen if I used a regular reset.

— Reply to this email directly, view it on GitHub https://github.com/slviajero/tinybasic/issues/27#issuecomment-1279476868, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACSY56HBREVDW433QIVBRQTWDHEVFANCNFSM535TSHIA. You are receiving this because you modified the open/close state.

slviajero avatar Oct 15 '22 20:10 slviajero

20221015_171025 This is the platform I am using - no keyboard or serial while operating hence the crash to break;)

EncomLab avatar Oct 15 '22 23:10 EncomLab

The difference between the hardware guy and the software guy. Sent from my iPhone

On Oct 16, 2022, at 1:40 AM, Encom Lab @.***> wrote:



This is the platform I am using - no keyboard or serial while operating hence the crash to break;)

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you modified the open/close state.

slviajero avatar Oct 16 '22 06:10 slviajero