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 12:54:53 2014 +0000
Revision:
0:6f55c7651ccc
Child:
1:540008bb92a2
Added README.txt;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jhnwkmn 0:6f55c7651ccc 1 /*
jhnwkmn 0:6f55c7651ccc 2 @License@
jhnwkmn 0:6f55c7651ccc 3 */
jhnwkmn 0:6f55c7651ccc 4
jhnwkmn 0:6f55c7651ccc 5 #include <sqmbed/trigger.h>
jhnwkmn 0:6f55c7651ccc 6 #include <sqmbed/pointerstorage.h>
jhnwkmn 0:6f55c7651ccc 7
jhnwkmn 0:6f55c7651ccc 8 namespace
jhnwkmn 0:6f55c7651ccc 9 {
jhnwkmn 0:6f55c7651ccc 10
jhnwkmn 0:6f55c7651ccc 11 class Triggers : public SqMbed::PointerStorage<SqMbed::Trigger>
jhnwkmn 0:6f55c7651ccc 12 {
jhnwkmn 0:6f55c7651ccc 13 public:
jhnwkmn 0:6f55c7651ccc 14 static void notify()
jhnwkmn 0:6f55c7651ccc 15 {
jhnwkmn 0:6f55c7651ccc 16 // Do not store pointers here. Who knows, maybe the handler creates a
jhnwkmn 0:6f55c7651ccc 17 // new InterruptIn and then both s_nSpace and s_ppInterrupts may change.
jhnwkmn 0:6f55c7651ccc 18 for (uint32_t i = 0; i < s_nSpace; ++i) {
jhnwkmn 0:6f55c7651ccc 19 SqMbed::Trigger* pTrigger = s_ppObjects[i];
jhnwkmn 0:6f55c7651ccc 20
jhnwkmn 0:6f55c7651ccc 21 if (pTrigger) {
jhnwkmn 0:6f55c7651ccc 22 pTrigger->call();
jhnwkmn 0:6f55c7651ccc 23 }
jhnwkmn 0:6f55c7651ccc 24 }
jhnwkmn 0:6f55c7651ccc 25 }
jhnwkmn 0:6f55c7651ccc 26 };
jhnwkmn 0:6f55c7651ccc 27
jhnwkmn 0:6f55c7651ccc 28 }
jhnwkmn 0:6f55c7651ccc 29
jhnwkmn 0:6f55c7651ccc 30 namespace SqMbed
jhnwkmn 0:6f55c7651ccc 31 {
jhnwkmn 0:6f55c7651ccc 32
jhnwkmn 0:6f55c7651ccc 33 Trigger::Trigger(HSQUIRRELVM vm)
jhnwkmn 0:6f55c7651ccc 34 : m_vm(vm)
jhnwkmn 0:6f55c7651ccc 35 , m_triggered(false)
jhnwkmn 0:6f55c7651ccc 36 {
jhnwkmn 0:6f55c7651ccc 37 m_object._type = OT_NULL;
jhnwkmn 0:6f55c7651ccc 38
jhnwkmn 0:6f55c7651ccc 39 Triggers::add(this);
jhnwkmn 0:6f55c7651ccc 40 }
jhnwkmn 0:6f55c7651ccc 41
jhnwkmn 0:6f55c7651ccc 42 Trigger::~Trigger()
jhnwkmn 0:6f55c7651ccc 43 {
jhnwkmn 0:6f55c7651ccc 44 Triggers::remove(this);
jhnwkmn 0:6f55c7651ccc 45 }
jhnwkmn 0:6f55c7651ccc 46
jhnwkmn 0:6f55c7651ccc 47 bool Trigger::reserve()
jhnwkmn 0:6f55c7651ccc 48 {
jhnwkmn 0:6f55c7651ccc 49 return Triggers::reserve();
jhnwkmn 0:6f55c7651ccc 50 }
jhnwkmn 0:6f55c7651ccc 51
jhnwkmn 0:6f55c7651ccc 52 void Trigger::call()
jhnwkmn 0:6f55c7651ccc 53 {
jhnwkmn 0:6f55c7651ccc 54 if (m_triggered) {
jhnwkmn 0:6f55c7651ccc 55 m_triggered = false; // Should be atomic.
jhnwkmn 0:6f55c7651ccc 56
jhnwkmn 0:6f55c7651ccc 57 int top = sq_gettop(m_vm);
jhnwkmn 0:6f55c7651ccc 58 sq_pushobject(m_vm, m_object); // The function
jhnwkmn 0:6f55c7651ccc 59 sq_pushroottable(m_vm); // This
jhnwkmn 0:6f55c7651ccc 60 sq_call(m_vm, 1, 0, 0); // Only this as argument.
jhnwkmn 0:6f55c7651ccc 61 sq_settop(m_vm, top); // Restore the stack.
jhnwkmn 0:6f55c7651ccc 62 }
jhnwkmn 0:6f55c7651ccc 63 }
jhnwkmn 0:6f55c7651ccc 64
jhnwkmn 0:6f55c7651ccc 65 // static
jhnwkmn 0:6f55c7651ccc 66 void Trigger::flushTriggers()
jhnwkmn 0:6f55c7651ccc 67 {
jhnwkmn 0:6f55c7651ccc 68 Triggers::notify();
jhnwkmn 0:6f55c7651ccc 69 }
jhnwkmn 0:6f55c7651ccc 70
jhnwkmn 0:6f55c7651ccc 71 void Trigger::attach(HSQOBJECT o)
jhnwkmn 0:6f55c7651ccc 72 {
jhnwkmn 0:6f55c7651ccc 73 if (m_object._type != OT_NULL) {
jhnwkmn 0:6f55c7651ccc 74 sq_release(m_vm, &m_object);
jhnwkmn 0:6f55c7651ccc 75 m_object._type = OT_NULL;
jhnwkmn 0:6f55c7651ccc 76 }
jhnwkmn 0:6f55c7651ccc 77
jhnwkmn 0:6f55c7651ccc 78 m_object = o;
jhnwkmn 0:6f55c7651ccc 79 sq_addref(m_vm, &m_object);
jhnwkmn 0:6f55c7651ccc 80 }
jhnwkmn 0:6f55c7651ccc 81
jhnwkmn 0:6f55c7651ccc 82 // static
jhnwkmn 0:6f55c7651ccc 83 void Trigger::triggered()
jhnwkmn 0:6f55c7651ccc 84 {
jhnwkmn 0:6f55c7651ccc 85 // TODO: Should be atomic.
jhnwkmn 0:6f55c7651ccc 86 m_triggered = true;
jhnwkmn 0:6f55c7651ccc 87 }
jhnwkmn 0:6f55c7651ccc 88
jhnwkmn 0:6f55c7651ccc 89 }