Is it possible to extend setWatch to include timer interrupts? #5346
Replies: 1 comment
-
Posted at 2016-06-04 by @allObjects ...sacrificing 2 pins... one output based on the timer event connected to the other one with input and setWatch... but it would be nice setWatch can determine whether the argument is a pin or a timer... Posted at 2016-06-04 by DrAzzy Oooh... extending set watch to other interrupt sources would really open new doors... Posted at 2016-06-04 by @gfwilliams I think you know this, but As @allObjects says, if you can get it to output to a pin, you could loop back and use setWatch that way - but I'm not sure you can. We could however modify Espruino to add some functions that put an event (USER1, USER2, etc?) into the queue when they are called, and could get them to call I kind of wonder how many people would use the functionality though ;) Posted at 2016-06-05 by ClearMemory041063 Lots of ideas here. Here is an outline subject to everyone's revisions; The watch action and queue code: When ClearWatch is called the old address would be restored to the interrupt table As far as the external wire method between the OTpulse timer and the counting timer in gate mode, I think that works as far as the timers are concerned but I will have to see if the setWatch still works in that setup. The OTpulse pin is setup as an output. The gated timer gate would be an input. I'm a couple of steps from being able to try that in the timer thread. Posted at 2016-06-05 by @allObjects The Posted at 2016-06-06 by @gfwilliams
Yes to both... Good point about clearing the interrupt flag. Personally I'd probably leave To be honest it all starts to get quite complicated. There are around 30 possible interrupts I think - I wonder whether it makes sense to just add built-in handlers for all the common ones which automatically clear the relevant flags. Then you could just do Just to add, if you're so inclined I think you can hack things together with Espruino as-is:
Posted at 2016-06-06 by ClearMemory041063 Thanks for all the good ideas. It would be nice to be able to use the internal wires between the timers instead of an external wire. This is done by setting up one timer as a master with output TRGO and the second timer as a slave with input on the appropriate line ITR0..ITR3. The problem is telling the Javascript code when the timer process is finished so that the Javascript can peek at the results. As far as to which Javascript verb to use do E.on('IRQ15', function() { ... }) Do you have a link to obtain a copy of the assembler? Posted at 2016-06-06 by @gfwilliams
You best bet is to upload it, then hit up-arrow to see a copy of what was uploaded. Eg.
Gives and you can just use
You don't actually have to disable interrupts - I believe the ARM does this for you (the only thing that will interrupt you is an interrupt of higher priority, which you should probably allow anyway).
It's just a simple
I don't think that is possible for now... You'd have to toggle the state of a pin, feed it back, and then use Posted at 2016-06-06 by ClearMemory041063 Thanks that helps. On the queue problem here's what I've been looking at based on the E.on('IRQ15', function() { ... }) that you've been suggesting.
So either place the call to a.emit in the assembly code or call the assembly code from the a.on() function and place the corresponding address in the interrupt table. Posted at 2016-06-07 by @gfwilliams Calling One issue is that JS functions don't exist as something you can just 'jump' to from Assembler, but also the JS interpreter isn't designed to be reentrant... Even allocating JS vars (for instance the string 'hello') can be a pain. Posted at 2016-06-07 by ClearMemory041063 Thanks @gfwilliams. I was just thinking about calling interpreted text like it is machine code really doesn't make sense. Perhaps the best approach other than the pin joining is to have the ISR set a flag and use a setinterval() to check the flag and do the emit. On a different note, after typing in the asm code and doing the upload you said, Posted at 2016-06-07 by Wilberforce Up arrow in the left hand side,after uploading on the right... Posted at 2016-06-07 by @gfwilliams
Ahh, but if you're doing that, it's almost as easy to just check the interrupt flag and reset it right from Posted at 2016-06-07 by ClearMemory041063 Thanks @wilberforce the up arrow in left pane more than once did the trick. @gfwilliams in a previous post suggested this example:
Gives var adder = E.nativeCall(1, "int(int)", atob("AyFAGHBH")) The "AyFAGHBH" is the 64 bit encoded version of the code. Some confusion about where to poke the string.
The assembler page suggests after the stack end address.
So I’ve tried it both ways and both crash.
Which displays
Posted at 2016-06-07 by ClearMemory041063 Found it
Outputs
Posted at 2016-06-08 by ClearMemory041063 Here is a link to help with Thumb code Posted at 2016-06-08 by ClearMemory041063 One last try. If a javascript function is compiled, is it possible to call it from assembled code? Posted at 2016-06-08 by ClearMemory041063 Yes you can!
Run the program and use the up arrow in the left pane a couple of times to get the native call string. fooHelloThmbcode.js
and the output
Attachments: Posted at 2016-06-15 by @gfwilliams Great! Yes, sorry, I forgot about that. On ARM, the bottom bit of the address determines whether you're jumping to ARM 16 bit 'thumb' assembler, or normal non-thumb 32 bit code. Unfortunately the Cortex Ms used for Espruino don't support normal ARM instructions, so you have to set the bottom bit to 1 (while keeping the instructions aligned to 2 byte boundaries) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2016-06-04 by ClearMemory041063
Is it possible to extend setWatch to include timer interrupts?
The scenario:
One counter is being used to count external pulses and is being gated by a second timer in one time pulse mode (OTP). The program starts the one time pulse. If setWatch were able to detect the finished interrupt from the OTP then the program would know that the measured count is available to read and process.
Beta Was this translation helpful? Give feedback.
All reactions