fork of StateScript

Dependencies:   mbed SOMO_II

Fork of stateScript_v2 by Mattias Karlsson

Files at this revision

API Documentation at this revision

Comitter:
alustig3
Date:
Fri Apr 28 14:47:55 2017 +0000
Parent:
9:f783bce314cd
Commit message:
Code is now compatible with FRDM-K64F.; Replaced SMARTWAV with SOMO-II

Changed in this revision

SMARTWAV.lib Show diff for this revision Revisions of this file
SOMO.lib Show annotated file Show diff for this revision Revisions of this file
behave.cpp Show annotated file Show diff for this revision Revisions of this file
behave.h Show annotated file Show diff for this revision Revisions of this file
hardwareInterface.cpp Show annotated file Show diff for this revision Revisions of this file
hardwareInterface.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbedInterface/mbedInterface.cpp Show annotated file Show diff for this revision Revisions of this file
mbedInterface/mbedInterface.h Show annotated file Show diff for this revision Revisions of this file
--- a/SMARTWAV.lib	Wed Apr 26 16:40:36 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://developer.mbed.org/users/mkarlsso/code/SMARTWAV/#bfb321f3d233
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SOMO.lib	Fri Apr 28 14:47:55 2017 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/alustig3/code/SOMO_II/#5a7359b415c8
--- a/behave.cpp	Wed Apr 26 16:40:36 2017 +0000
+++ b/behave.cpp	Fri Apr 28 14:47:55 2017 +0000
@@ -48,9 +48,10 @@
 __attribute((section("AHBSRAM0"),aligned)) intOperation intOperationBlock[NUMINTOPERATIONS];
 __attribute((section("AHBSRAM0"),aligned)) displayAction displayActionBlock[NUMDISPLAYACTIONS];
 __attribute((section("AHBSRAM0"),aligned)) triggerFunctionAction triggerFunctionActionBlock[NUMTRIGGERACTIONS];
+
 #endif
 
-#ifdef FPGAHARDWARE
+#if defined(FPGAHARDWARE) || defined(K64HARDWARE)
 
 char buffer[256];
 event eventBlock[NUMEVENTS];
@@ -89,8 +90,8 @@
     vInfo.middle = 1;
     vInfo.minor = 2;
 
-    vInfo.updateDay = 30;
-    vInfo.updateMonth = 3;
+    vInfo.updateDay = 28;
+    vInfo.updateMonth = 4;
     vInfo.updateYear = 2017;
 
 
@@ -107,6 +108,13 @@
 
 #endif
 
+#ifdef K64HARDWARE
+    hardware = new MBEDSystem();
+    pc = new MBEDSerialPort();
+    pc->init();
+    textDisplay.setSerial(pc);
+#endif
+
 #ifdef FPGAHARDWARE
        pc = new FPGASerialPort();
        pc->init();
@@ -419,7 +427,7 @@
     thresh(0),
     lastChangeTime(0),
     hasTriggerFunction(false),
-    reportUpdates(false),
+    reportUpdates(true),
     hardwareStatePtr(NULL)
 {
 
@@ -531,7 +539,7 @@
     inPin(NULL) {
 
     portType = analog;
-    
+
 }
 
 void AnalogPort::init(sAnalogIn *IP) {
@@ -539,7 +547,7 @@
     portDir = in;
     inPin = IP;
     hardwareStatePtr = (int*)IP->hardwareStatePtr;
-    
+
 }
 
 void AnalogPort::init(sAnalogOut *OP){
@@ -2988,7 +2996,7 @@
 
 
                         } else {
-                            textDisplay << "Error: function number does not exist\r\n";                           
+                            textDisplay << "Error: function number does not exist\r\n";
                             lineError = true;
                         }
                     } else {
@@ -6159,4 +6167,3 @@
 
 
 }
-
--- a/behave.h	Wed Apr 26 16:40:36 2017 +0000
+++ b/behave.h	Fri Apr 28 14:47:55 2017 +0000
@@ -8,13 +8,16 @@
 #include <queue>
 #include "hardwareInterface.h"
 
+//here is where we define which platform we are compiling for
+#define MBEDHARDWARE
+//#define K64HARDWARE
+//#define FPGAHARDWARE
 
-#define MBEDHARDWARE  //here is where we define which platform we are compiling for
-//#define FPGAHARDWARE
+
 
 #define MAXVARNAMESIZE 30 //The maximum number of characters of a variable name
 
-#ifdef MBEDHARDWARE
+#if defined(MBEDHARDWARE) || defined(K64HARDWARE)
     #include "mbedInterface.h"
 #endif
 #ifdef FPGAHARDWARE
@@ -25,20 +28,6 @@
 #define VARIABLEMEMORYTYPES 2
 #define ENVSETTINGSMEMORYTYPES 4
 
-
-/*
-#define NUMEVENTS 50
-#define NUMCONDITIONS 150
-#define NUMINTCOMPARE 150
-#define NUMACTIONS 150
-#define NUMPORTMESSAGES 150
-#define NUMINTOPERATIONS 150
-#define NUMDISPLAYACTIONS 30
-#define NUMTRIGGERACTIONS 30
-#define NUMFUNCTIONS 50
-#define INPUTCHARBUFFERSIZE 3072
-*/
-
 #define ARITHMATIC_CONDITION    0
 #define OR_CONDITION    1
 #define AND_CONDITION    2
--- a/hardwareInterface.cpp	Wed Apr 26 16:40:36 2017 +0000
+++ b/hardwareInterface.cpp	Fri Apr 28 14:47:55 2017 +0000
@@ -374,5 +374,3 @@
     return tmpOut;
 
 }
-
-
--- a/hardwareInterface.h	Wed Apr 26 16:40:36 2017 +0000
+++ b/hardwareInterface.h	Fri Apr 28 14:47:55 2017 +0000
@@ -161,7 +161,7 @@
 
     //virtual void timerInterrupt() = 0;
 
-    void immediateClockReset();   
+    void immediateClockReset();
     int currentDINPin;
     int currentDOUTPin;
     uint32_t currentDigitalOuputStates;
--- a/main.cpp	Wed Apr 26 16:40:36 2017 +0000
+++ b/main.cpp	Fri Apr 28 14:47:55 2017 +0000
@@ -1,8 +1,24 @@
 #include "behave.h"
 
+#ifdef K64HARDWARE
+extern uint32_t timeKeeper; //the master clock
+extern bool resetTimer;
+void tick(){
+    timeKeeper++;
+    if (resetTimer){
+        timeKeeper = 0;
+        resetTimer = false;
+    }
+}
+Ticker keeptime;
+
+int main() {
+    keeptime.attach_us(&tick,1000);
+#else
 using namespace std;
 
 int main() {
+#endif
     mainLoop m;
     m.init();
     m.exec();
--- a/mbedInterface/mbedInterface.cpp	Wed Apr 26 16:40:36 2017 +0000
+++ b/mbedInterface/mbedInterface.cpp	Fri Apr 28 14:47:55 2017 +0000
@@ -1,8 +1,6 @@
 #include "mbedInterface.h"
 #include "mbed.h"
 
-
-
 //--------------------------------------------------------------
 //--------------------------------------------------------------
 //This section is required for all custom harware interfaces
@@ -49,9 +47,16 @@
 bool RFSyncReadable = false;
 bool RFSyncWritable = true;
 
+#ifdef LPC1768
 //Recieve clock signal from RF system
 InterruptIn RFClock(p28);
 DigitalIn RFData(p27);
+#endif
+
+#ifdef K64
+InterruptIn RFClock(PTA1);
+DigitalIn RFData(PTB9);
+#endif
 
 
 void callback_RFClock(void) {
@@ -134,61 +139,58 @@
 //---------------------------------------------------------------------
 
 //translate pin numbers to hardware pins
-//PinName dOutPins[NUMDIGOUTPORTS] = {p11,p13,p15,p18,p21,p23,p25,p29,p20,p6}; //Old board output pins
 
-//PinName dOutPins[NUMDIGOUTPORTS] = {p18,p15,p13,p11,p29,p25,p23,p21,p20}; //New board output pins
-//PinName dInPins[NUMDIGINPORTS] = {p12,p14,p16,p17,p22,p24,p26,p30,p7};
-//PinName aInPins[NUMANINPORTS] = {};
-//PinName aOutPins[NUMANOUTPORTS] = {};
-
+#ifdef LPC1768
+PinName dInPins[NUMDIGINPORTS] = {p5,p14,p16,p17,p22,p24,p26,p30};
 PinName dOutPins[NUMDIGOUTPORTS] = {p7,p15,p13,p11,p29,p25,p23,p21}; //With analog pins
-PinName dInPins[NUMDIGINPORTS] = {p12,p14,p16,p17,p22,p24,p26,p30};
 PinName aInPins[NUMANINPORTS] = {p20};
 PinName aOutPins[NUMANOUTPORTS] = {p18};
+// SOMO II sound module  http://www.4dsystems.com.au/product/SOMO_II/
+// Datasheet http://www.4dsystems.com.au/productpages/SOMO-II/downloads/SOMO-II_datasheet_R_1_2.pdf
+SOMO audio(p9,p10);        //(TX,RX)
+#endif
+
+#ifdef K64
+PinName dInPins[NUMDIGINPORTS]  =  {PTB2, PTB9, PTC10, PTA1, PTD1};
+PinName dOutPins[NUMDIGOUTPORTS] = {PTB11, PTC14, PTC11, PTC15,  PTE24, PTD4, PTC9, PTB18, PTD0};
+PinName aInPins[NUMANINPORTS] = {};
+PinName aOutPins[NUMANOUTPORTS] = {};
+
+SOMO audio(PTC17,PTC16);        //(TX,RX,Reset)
+#endif
 
 
-//The sound output uses a SmartWav device and their simple serial library
-SMARTWAV sWav(p9,p10,p19);   //(TX,RX,Reset);
-
+#ifdef LPC1768
 //This is the callback for the MBED timer
 extern "C" void TIMER0_IRQHandler (void) {
-
-    /*if (clockSlave) {
-
-        //The function is called every 100 us
-        if((LPC_TIM0->IR & 0x01) == 0x01) {  // if MR0 interrupt, proceed
-
-            LPC_TIM0->IR |= 1 << 0;         // Clear MR0 interrupt flag
-            uSec_SinceLastClockInc = uSec_SinceLastClockInc+100;
-            uSec_SinceLastReset = uSec_SinceLastReset+100;
-
-        }
-
+    //The function is called every 1 ms
+    if((LPC_TIM0->IR & 0x01) == 0x01) {  // if MR0 interrupt, proceed
+        LPC_TIM0->IR |= 1 << 0;         // Clear MR0 interrupt flag
+        timeKeeper++;
 
-    } else {*/
-        //The function is called every 1 ms
-        if((LPC_TIM0->IR & 0x01) == 0x01) {  // if MR0 interrupt, proceed
-
-            LPC_TIM0->IR |= 1 << 0;         // Clear MR0 interrupt flag
-            timeKeeper++;
-
-            if (resetTimer) {
-                timeKeeper = 0;
-                resetTimer = false;
-            }
+        if (resetTimer) {
+            timeKeeper = 0;
+            resetTimer = false;
         }
-    //}
-
+    }
 }
 //-----------------------------------------------------------------------
-
+#endif
 
 
 MBEDSystem::MBEDSystem():
+    #ifdef LPC1768
     clockResetInt(p5),
     clockExternalIncrement(p8) {
+    clockResetInt.rise(this, &MBEDSystem::externalClockReset);
 
-    clockResetInt.rise(this, &MBEDSystem::externalClockReset);
+    #endif
+    #ifdef K64
+    clockResetInt(PTD4),
+    clockExternalIncrement(PTD6) {
+    clockResetInt.rise(callback(this, &MBEDSystem::externalClockReset));
+    #endif
+
     clockResetInt.fall(&externalResetDown);
     clockResetInt.mode(PullDown);
 
@@ -218,11 +220,12 @@
 
 
 
-    sWav.reset();
+    audio.reset();
 
 }
 
 void MBEDSystem::timerinit() {
+    #ifdef LPC1768
     //intiatiation of timer (specific to the LPC17xx chip). This is used in
     //standalone mode to increment the clock every ms.
     //----------------------------------------------------
@@ -230,7 +233,7 @@
     //LPC_SC->PCLKSEL1 |= (1 << 12); //sets it to 1*SystemCoreClock - table 42 (page 57 in user manual)
     //LPC_SC->PCLKSEL0 &= (3 << 3); //mask
     //LPC_SC->PCLKSEL0 |= (1 << 3); //sets it to 1*SystemCoreClock - table 42 (page 57 in user manual)
-    LPC_SC->PCONP |=1<1;            //timer0 power on   
+    LPC_SC->PCONP |=1<1;            //timer0 power on
 
 
     LPC_TIM0->MR0 = 23980;        //1 msec
@@ -245,6 +248,7 @@
     NVIC_EnableIRQ(TIMER0_IRQn);    //enable timer0 interrupt
     LPC_TIM0->TCR = 1;              //enable Timer0
     //--------------------------------------------------------------
+    #endif
 }
 
 void MBEDSystem::pauseInterrupts() {
@@ -324,7 +328,9 @@
 
 
     if (clockSlave) {
+    #ifdef LPC1768
         LPC_TIM0->TCR = 0x02;    // reset timer
+    #endif
         externalIncrementCounter = 0;
 
         immediateClockReset();
@@ -334,7 +340,9 @@
 
 void MBEDSystem::setStandAloneClock() {
     clockSlave = false;
+#ifdef LPC1768
     NVIC_DisableIRQ(TIMER0_IRQn); // Disable the interrupt
+#endif
     timerinit(); //set up and enable interrupt
     clockExternalIncrement.rise(NULL); //remove the callback to the external interrupt
     //clockExternalIncrement.fall(NULL);
@@ -344,10 +352,14 @@
 
 void MBEDSystem::setSlaveClock() {
     clockSlave = true;
+#ifdef LPC1768
     NVIC_DisableIRQ(TIMER0_IRQn); // Disable the interrupt
-    //timerinit(); //set up and enable interrupt
     clockExternalIncrement.rise(this, &MBEDSystem::incrementClock);
-    //clockExternalIncrement.fall(&externalClockIncDown);
+#endif
+#ifdef K64
+    clockExternalIncrement.rise(callback(this, &MBEDSystem::incrementClock));
+#endif
+
     clockSlave = true;
     changeToSlave = false;
     changeToStandAlone = false;
@@ -387,20 +399,20 @@
 
 void MBEDSound::execute() {
     if (reset) {
-        sWav.reset();
+        audio.reset();
     } else if (!play) {
-        sWav.stopTrack();
+        audio.stopTrack();
     } else {
         if (volume > -1) {
-            sWav.volume(volume);
+            audio.volume(volume);
         } else if (volumePtr != NULL) {
-            sWav.volume(*volumePtr);
+            audio.volume(*volumePtr);
         }
 
         if (fileNameExists) {
-            //sWav.playTracks();
-            sWav.stopTrack();
-            sWav.playTrackName(fileName);
+            //audio.playTracks();
+            audio.stopTrack();
+            audio.playTrackName(fileName);
         }
     }
 }
@@ -501,8 +513,14 @@
         inpin_interrupt = new InterruptIn(dInPins[pin]);
         inpin->mode(PullDown);
         //Set up callbacks for the port interrupts
+    #ifdef LPC1768
         inpin_interrupt->rise(this, &MBEDDigitalIn::interrupt_up_callback);
         inpin_interrupt->fall(this, &MBEDDigitalIn::interrupt_down_callback);
+    #endif
+    #ifdef K64
+        inpin_interrupt->rise(callback(this, &MBEDDigitalIn::interrupt_up_callback));
+        inpin_interrupt->fall(callback(this, &MBEDDigitalIn::interrupt_down_callback));
+    #endif
         pinExists = true;
     }
 }
--- a/mbedInterface/mbedInterface.h	Wed Apr 26 16:40:36 2017 +0000
+++ b/mbedInterface/mbedInterface.h	Fri Apr 28 14:47:55 2017 +0000
@@ -4,7 +4,7 @@
 #include "hardwareInterface.h"
 #include "mbed.h"
 #include <stdint.h>
-#include "SMARTWAV.h"
+#include "SOMO.h"
 #include <string.h>
 #include <string>
 #include <vector>
@@ -14,8 +14,12 @@
 
 //#define MBED_RF
 
+//Define which mbed board
+#define LPC1768
+//#define K64
 
-//#define NUMPORTS 10 //the number of ports available on this hardware
+
+//the number of ports available on this hardware
 #define NUMDIGINPORTS 8
 #define NUMDIGOUTPORTS 8
 #define NUMANINPORTS 1
@@ -169,6 +173,7 @@
     void incrementClock();
     void externalClockReset(); //needs to reset harware timer before calling immediateClockReset();
     void mainLoopToDo();
+    void tick();
 
 protected: