The Squirrel interpreter for FRDM-K64F, extended with a set of classes that provide access to the mbed functionality (currently DigitalIn, DigitalInOut, DigitalOut, InterruptIn, PwmOut, Ticker, Timeout, Timer).

Dependencies:   SQUIRREL3 mbed sqbind-0_99

The Squirrel interpreter for FRDM-K64F.

NOTE: Currently of POC quality.

See http://www.squirrel-lang.org/ for information about the Squirrel language.

Currently the following (a subset of their functionality) mbed classes are available from within Squirrel:

  • DigitalIn
  • DigitalOut
  • DigitalInOut
  • PwmOut
  • Ticker
  • Timeout
  • Timer

In addition, InterruptIn is supported, but interrupts are noted when they occur, but only delivered from the main loop of the interpreter.

See also README.txt in the root of the project.

Committer:
jhnwkmn
Date:
Tue Dec 16 13:12:34 2014 +0000
Revision:
1:540008bb92a2
Parent:
0:6f55c7651ccc
Updated license.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jhnwkmn 0:6f55c7651ccc 1 /*
jhnwkmn 1:540008bb92a2 2 Copyright 2014 Johan Wikman
jhnwkmn 1:540008bb92a2 3
jhnwkmn 1:540008bb92a2 4 Licensed under the Apache License, Version 2.0 (the "License");
jhnwkmn 1:540008bb92a2 5 you may not use this file except in compliance with the License.
jhnwkmn 1:540008bb92a2 6 You may obtain a copy of the License at
jhnwkmn 1:540008bb92a2 7
jhnwkmn 1:540008bb92a2 8 http://www.apache.org/licenses/LICENSE-2.0
jhnwkmn 1:540008bb92a2 9
jhnwkmn 1:540008bb92a2 10 Unless required by applicable law or agreed to in writing, software
jhnwkmn 1:540008bb92a2 11 distributed under the License is distributed on an "AS IS" BASIS,
jhnwkmn 1:540008bb92a2 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
jhnwkmn 1:540008bb92a2 13 See the License for the specific language governing permissions and
jhnwkmn 1:540008bb92a2 14 limitations under the License.
jhnwkmn 0:6f55c7651ccc 15 */
jhnwkmn 0:6f55c7651ccc 16
jhnwkmn 0:6f55c7651ccc 17 #include <sqmbed/trigger.h>
jhnwkmn 0:6f55c7651ccc 18 #include <sqmbed/pointerstorage.h>
jhnwkmn 0:6f55c7651ccc 19
jhnwkmn 0:6f55c7651ccc 20 namespace
jhnwkmn 0:6f55c7651ccc 21 {
jhnwkmn 0:6f55c7651ccc 22
jhnwkmn 0:6f55c7651ccc 23 class Triggers : public SqMbed::PointerStorage<SqMbed::Trigger>
jhnwkmn 0:6f55c7651ccc 24 {
jhnwkmn 0:6f55c7651ccc 25 public:
jhnwkmn 0:6f55c7651ccc 26 static void notify()
jhnwkmn 0:6f55c7651ccc 27 {
jhnwkmn 0:6f55c7651ccc 28 // Do not store pointers here. Who knows, maybe the handler creates a
jhnwkmn 0:6f55c7651ccc 29 // new InterruptIn and then both s_nSpace and s_ppInterrupts may change.
jhnwkmn 0:6f55c7651ccc 30 for (uint32_t i = 0; i < s_nSpace; ++i) {
jhnwkmn 0:6f55c7651ccc 31 SqMbed::Trigger* pTrigger = s_ppObjects[i];
jhnwkmn 0:6f55c7651ccc 32
jhnwkmn 0:6f55c7651ccc 33 if (pTrigger) {
jhnwkmn 0:6f55c7651ccc 34 pTrigger->call();
jhnwkmn 0:6f55c7651ccc 35 }
jhnwkmn 0:6f55c7651ccc 36 }
jhnwkmn 0:6f55c7651ccc 37 }
jhnwkmn 0:6f55c7651ccc 38 };
jhnwkmn 0:6f55c7651ccc 39
jhnwkmn 0:6f55c7651ccc 40 }
jhnwkmn 0:6f55c7651ccc 41
jhnwkmn 0:6f55c7651ccc 42 namespace SqMbed
jhnwkmn 0:6f55c7651ccc 43 {
jhnwkmn 0:6f55c7651ccc 44
jhnwkmn 0:6f55c7651ccc 45 Trigger::Trigger(HSQUIRRELVM vm)
jhnwkmn 0:6f55c7651ccc 46 : m_vm(vm)
jhnwkmn 0:6f55c7651ccc 47 , m_triggered(false)
jhnwkmn 0:6f55c7651ccc 48 {
jhnwkmn 0:6f55c7651ccc 49 m_object._type = OT_NULL;
jhnwkmn 0:6f55c7651ccc 50
jhnwkmn 0:6f55c7651ccc 51 Triggers::add(this);
jhnwkmn 0:6f55c7651ccc 52 }
jhnwkmn 0:6f55c7651ccc 53
jhnwkmn 0:6f55c7651ccc 54 Trigger::~Trigger()
jhnwkmn 0:6f55c7651ccc 55 {
jhnwkmn 0:6f55c7651ccc 56 Triggers::remove(this);
jhnwkmn 0:6f55c7651ccc 57 }
jhnwkmn 0:6f55c7651ccc 58
jhnwkmn 0:6f55c7651ccc 59 bool Trigger::reserve()
jhnwkmn 0:6f55c7651ccc 60 {
jhnwkmn 0:6f55c7651ccc 61 return Triggers::reserve();
jhnwkmn 0:6f55c7651ccc 62 }
jhnwkmn 0:6f55c7651ccc 63
jhnwkmn 0:6f55c7651ccc 64 void Trigger::call()
jhnwkmn 0:6f55c7651ccc 65 {
jhnwkmn 0:6f55c7651ccc 66 if (m_triggered) {
jhnwkmn 0:6f55c7651ccc 67 m_triggered = false; // Should be atomic.
jhnwkmn 0:6f55c7651ccc 68
jhnwkmn 0:6f55c7651ccc 69 int top = sq_gettop(m_vm);
jhnwkmn 0:6f55c7651ccc 70 sq_pushobject(m_vm, m_object); // The function
jhnwkmn 0:6f55c7651ccc 71 sq_pushroottable(m_vm); // This
jhnwkmn 0:6f55c7651ccc 72 sq_call(m_vm, 1, 0, 0); // Only this as argument.
jhnwkmn 0:6f55c7651ccc 73 sq_settop(m_vm, top); // Restore the stack.
jhnwkmn 0:6f55c7651ccc 74 }
jhnwkmn 0:6f55c7651ccc 75 }
jhnwkmn 0:6f55c7651ccc 76
jhnwkmn 0:6f55c7651ccc 77 // static
jhnwkmn 0:6f55c7651ccc 78 void Trigger::flushTriggers()
jhnwkmn 0:6f55c7651ccc 79 {
jhnwkmn 0:6f55c7651ccc 80 Triggers::notify();
jhnwkmn 0:6f55c7651ccc 81 }
jhnwkmn 0:6f55c7651ccc 82
jhnwkmn 0:6f55c7651ccc 83 void Trigger::attach(HSQOBJECT o)
jhnwkmn 0:6f55c7651ccc 84 {
jhnwkmn 0:6f55c7651ccc 85 if (m_object._type != OT_NULL) {
jhnwkmn 0:6f55c7651ccc 86 sq_release(m_vm, &m_object);
jhnwkmn 0:6f55c7651ccc 87 m_object._type = OT_NULL;
jhnwkmn 0:6f55c7651ccc 88 }
jhnwkmn 0:6f55c7651ccc 89
jhnwkmn 0:6f55c7651ccc 90 m_object = o;
jhnwkmn 0:6f55c7651ccc 91 sq_addref(m_vm, &m_object);
jhnwkmn 0:6f55c7651ccc 92 }
jhnwkmn 0:6f55c7651ccc 93
jhnwkmn 0:6f55c7651ccc 94 // static
jhnwkmn 0:6f55c7651ccc 95 void Trigger::triggered()
jhnwkmn 0:6f55c7651ccc 96 {
jhnwkmn 0:6f55c7651ccc 97 // TODO: Should be atomic.
jhnwkmn 0:6f55c7651ccc 98 m_triggered = true;
jhnwkmn 0:6f55c7651ccc 99 }
jhnwkmn 0:6f55c7651ccc 100
jhnwkmn 0:6f55c7651ccc 101 }