2014 Freescale / Hack A Day Make It Challenge FRDM-K64 Internet of "Thing"

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
emh203
Date:
Thu Apr 10 21:14:23 2014 +0000
Commit message:
1st add. Used for final demo

Changed in this revision

Main.cpp Show annotated file Show diff for this revision Revisions of this file
Queue.cpp Show annotated file Show diff for this revision Revisions of this file
Queue.h Show annotated file Show diff for this revision Revisions of this file
System.h Show annotated file Show diff for this revision Revisions of this file
Terminal.cpp Show annotated file Show diff for this revision Revisions of this file
Terminal.h Show annotated file Show diff for this revision Revisions of this file
Types.h Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Main.cpp	Thu Apr 10 21:14:23 2014 +0000
@@ -0,0 +1,143 @@
+/*
+
+--------------------------------------------
+|                                          |
+|                     ....                 |
+|                    7OO$?I78.             |
+|                   .?8++++7+II?D.         |
+|                   .?O++=I++II+?=         |
+|                   .IO++?7==I??$.         |
+|                   .8++=$===?+I$          |
+|                   ?+++===+===+           |
+|                   ???=+I++==+?           |
+|                 .??++====+==++           |
+|                 ?+++==========~          |
+|                $+++==========+=          |
+|              =?+===+==+I========         |
+|           ..++======~~~~========?        |
+|         .$?I??+=~~===~~~===~===++.       |
+|       .+==.+=~~~=~==~~~~==~~=~==+?       |
+|      ?===I+====~~=~~~=~~=====~~~=?.      |
+|     .=~~~+==~==..~~~~~~=    ~~~~=7=      |
+|     +=~~?+~~=.  ==~~~~=.     ~~~~=?.     |
+|     =~~~=~~~   ?===~~+.       ~~~~+      |
+|     +~~:+~~=    =~~==.        =~~+.      |
+|     ~:~ =~~=    =~~~=         ~===       |
+|         I=~~   ,=~~=            ,.       |
+|          ~~.   ,====                     |
+|                 ====                     |
+|                 =~~.                     |
+|                                          |
+|------------------------------------------|                                                          
+|              Internet Of Thing           |
+|                  Eli Hughes              |
+| Freescale / Hack-a-day Make-It-Challenge |
+|              FTF 2014 - Dallas, Tx       |
+|------------------------------------------|
+
+*/
+#include "mbed.h"
+#include "Queue.h"
+#include "Terminal.h"
+#include "System.h"
+ 
+
+ //Note --   Seems that there is a bug with the new K64 firmware.    When I enable 2 serial port objects there seems to be some cross mojination going on.   We use a 
+ //macro to select wifi or com port for debug
+ 
+#define USE_WIFI
+
+#define DATA_BUFFER_MAX_SIZE    128
+ 
+DigitalOut   SPIN_CCW (PTA2);
+DigitalOut   SPIN_CW  (PTC2);
+DigitalOut   GO_FORWARD (PTC3);
+DigitalOut   GO_REVERSE (PTB23);
+ 
+#ifdef USE_USB
+    Serial PC(USBTX, USBRX); // tx, rx
+#endif
+
+#ifdef USE_WIFI
+    Serial WIFI(PTC17,PTC16);
+#endif
+
+uint8_t DataBuffer[DATA_BUFFER_MAX_SIZE];
+ 
+int main (void)
+{
+    uint32_t i;
+    uint8_t DataOut;
+    uint32_t BytesToSend;
+    
+    #ifdef USE_WIFI
+       
+        WIFI.baud(115200);
+    
+    #endif
+    
+    #ifdef USE_USB
+    
+        PC.baud(115200);
+    
+    #endif
+
+        
+    TFC_InitTerminal();
+
+    while(1)
+    {
+
+        //Shuffle Datafrom the terminal Queue to the USB port or TCP Port
+        //Inefficient but workable
+        BytesToSend = BytesInQueue(&TERMINAL_OUTPUT_QUEUE);
+        
+        if(BytesToSend >0)
+        {
+            //Limit to maximum chunk size
+            
+            if(BytesToSend > DATA_BUFFER_MAX_SIZE)
+                BytesToSend = DATA_BUFFER_MAX_SIZE;
+
+            for(i=0 ; i< BytesToSend; i++)
+            {
+                ByteDequeue(&TERMINAL_OUTPUT_QUEUE,&DataOut);
+               
+               #ifdef USE_USB
+                     PC.putc(DataOut);
+               #endif
+               
+                #ifdef USE_WIFI
+                  WIFI.putc(DataOut);
+                #endif
+             }   
+        }
+        
+        
+     
+ 
+        #ifdef USE_USB
+        if(PC.readable())
+            {
+            
+               ByteEnqueue(&TERMINAL_INPUT_QUEUE,PC.getc());
+            }
+        #endif
+       
+      #ifdef USE_WIFI
+            
+        if(WIFI.readable())
+        {
+            DataOut = WIFI.getc();
+            ByteEnqueue(&TERMINAL_INPUT_QUEUE,DataOut);
+          
+         }
+        #endif
+    
+    TFC_ProcessTerminal();
+        
+    }
+  
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Queue.cpp	Thu Apr 10 21:14:23 2014 +0000
@@ -0,0 +1,135 @@
+/*
+
+--------------------------------------------
+|                                          |
+|                     ....                 |
+|                    7OO$?I78.             |
+|                   .?8++++7+II?D.         |
+|                   .?O++=I++II+?=         |
+|                   .IO++?7==I??$.         |
+|                   .8++=$===?+I$          |
+|                   ?+++===+===+           |
+|                   ???=+I++==+?           |
+|                 .??++====+==++           |
+|                 ?+++==========~          |
+|                $+++==========+=          |
+|              =?+===+==+I========         |
+|           ..++======~~~~========?        |
+|         .$?I??+=~~===~~~===~===++.       |
+|       .+==.+=~~~=~==~~~~==~~=~==+?       |
+|      ?===I+====~~=~~~=~~=====~~~=?.      |
+|     .=~~~+==~==..~~~~~~=    ~~~~=7=      |
+|     +=~~?+~~=.  ==~~~~=.     ~~~~=?.     |
+|     =~~~=~~~   ?===~~+.       ~~~~+      |
+|     +~~:+~~=    =~~==.        =~~+.      |
+|     ~:~ =~~=    =~~~=         ~===       |
+|         I=~~   ,=~~=            ,.       |
+|          ~~.   ,====                     |
+|                 ====                     |
+|                 =~~.                     |
+|                                          |
+|------------------------------------------|                                                          
+|              Internet Of Thing           |
+|                  Eli Hughes              |
+| Freescale / Hack-a-day Make-It-Challenge |
+|              FTF 2014 - Dallas, Tx       |
+|------------------------------------------|
+
+*/
+#include "stdint.h"
+#include "Queue.h"
+#include <string.h>
+
+static char StringBuffer[256];
+
+void InitByteQueue(ByteQueue *BQ,uint16_t Size,uint8_t * Storage) {
+    uint16_t i;
+
+    BQ->QueueSize = Size;
+    BQ->ReadPtr=0;
+    BQ->WritePtr=0;
+    BQ->QueueStorage = Storage;
+
+    for (i=0;i<BQ->QueueSize;i++) {
+        BQ->QueueStorage[i] = 0;
+    }
+}
+
+uint16_t BytesInQueue(ByteQueue *BQ) {
+    if (BQ->ReadPtr > BQ->WritePtr) {
+        return (BQ->QueueSize - BQ->ReadPtr + BQ->WritePtr);
+    } else if (BQ->WritePtr > BQ->ReadPtr) {
+        return     (BQ->WritePtr - BQ->ReadPtr);
+    } else {
+        return 0;
+    }
+}
+
+int16_t ByteEnqueue(ByteQueue *BQ,uint8_t Val) {
+    if (BytesInQueue(BQ) == BQ->QueueSize - 1) {
+        return QUEUE_FULL;
+    } else {
+        BQ->QueueStorage[BQ->WritePtr] = Val;
+        BQ->WritePtr++;
+
+        if (BQ->WritePtr >= BQ->QueueSize) {
+            BQ->WritePtr = 0;
+        }
+        return QUEUE_OK;
+    }
+}
+
+int16_t ByteArrayEnqueue(ByteQueue *BQ,uint8_t *Buf,uint16_t Len) {
+    uint16_t i;
+    for (i=0;i<Len;i++) {
+        ByteEnqueue(BQ,Buf[i]);
+    }
+    return QUEUE_OK;
+}
+
+
+int16_t Qprintf(ByteQueue *BQ, const char *FormatString,...)
+{
+ 
+     va_list argptr; 
+     va_start(argptr,FormatString); 
+     vsprintf((char *)StringBuffer,FormatString,argptr);
+     va_end(argptr);   
+           
+    return ByteArrayEnqueue(BQ,(uint8_t *)StringBuffer,strlen(StringBuffer));
+}
+
+
+int16_t ByteDequeue(ByteQueue *BQ,uint8_t *Val) {
+
+    if (BytesInQueue(BQ) == 0) {
+        return QUEUE_EMPTY;
+    } else {
+        *Val  = BQ->QueueStorage[BQ->ReadPtr];
+
+        BQ->ReadPtr++;
+
+        if (BQ->ReadPtr >= BQ->QueueSize) {
+            BQ->ReadPtr = 0;
+        }
+        return QUEUE_OK;
+    }
+}
+
+uint8_t ForcedByteDequeue(ByteQueue *BQ)
+{
+    uint8_t RetVal;
+
+    if (BytesInQueue(BQ) == 0) {
+        return 0;
+    } else {
+        RetVal  = BQ->QueueStorage[BQ->ReadPtr];
+
+        BQ->ReadPtr++;
+
+        if (BQ->ReadPtr >= BQ->QueueSize) {
+            BQ->ReadPtr = 0;
+        }
+        return RetVal;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Queue.h	Thu Apr 10 21:14:23 2014 +0000
@@ -0,0 +1,72 @@
+/*
+
+--------------------------------------------
+|                                          |
+|                     ....                 |
+|                    7OO$?I78.             |
+|                   .?8++++7+II?D.         |
+|                   .?O++=I++II+?=         |
+|                   .IO++?7==I??$.         |
+|                   .8++=$===?+I$          |
+|                   ?+++===+===+           |
+|                   ???=+I++==+?           |
+|                 .??++====+==++           |
+|                 ?+++==========~          |
+|                $+++==========+=          |
+|              =?+===+==+I========         |
+|           ..++======~~~~========?        |
+|         .$?I??+=~~===~~~===~===++.       |
+|       .+==.+=~~~=~==~~~~==~~=~==+?       |
+|      ?===I+====~~=~~~=~~=====~~~=?.      |
+|     .=~~~+==~==..~~~~~~=    ~~~~=7=      |
+|     +=~~?+~~=.  ==~~~~=.     ~~~~=?.     |
+|     =~~~=~~~   ?===~~+.       ~~~~+      |
+|     +~~:+~~=    =~~==.        =~~+.      |
+|     ~:~ =~~=    =~~~=         ~===       |
+|         I=~~   ,=~~=            ,.       |
+|          ~~.   ,====                     |
+|                 ====                     |
+|                 =~~.                     |
+|                                          |
+|------------------------------------------|                                                          
+|              Internet Of Thing           |
+|                  Eli Hughes              |
+| Freescale / Hack-a-day Make-It-Challenge |
+|              FTF 2014 - Dallas, Tx       |
+|------------------------------------------|
+
+*/
+#include <stdio.h>
+#include <stdarg.h>
+#include <stdint.h>
+
+#ifndef TFC_QUEUE_H_
+#define TFC_QUEUE_H_
+
+
+typedef struct {
+    
+    uint16_t ReadPtr;
+    uint16_t WritePtr;
+    uint16_t QueueSize;
+    uint8_t *QueueStorage;
+    
+} ByteQueue;
+
+#define QUEUE_FULL       -1
+#define QUEUE_EMPTY      -2
+#define QUEUE_OK          0
+
+
+void InitByteQueue(ByteQueue *BQ,uint16_t Size,uint8_t * Storage); 
+uint16_t BytesInQueue(ByteQueue *BQ);
+int16_t ByteEnqueue(ByteQueue *BQ,uint8_t Val);
+int16_t ByteArrayEnqueue(ByteQueue *BQ,uint8_t *Buf,uint16_t);
+int16_t ByteDequeue(ByteQueue *BQ,uint8_t *Val);
+uint8_t ForcedByteDequeue(ByteQueue *BQ);
+int16_t Qprintf(ByteQueue *BQ, const char *FormatString,...);
+
+
+
+
+#endif /* TFC_QUEUE_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/System.h	Thu Apr 10 21:14:23 2014 +0000
@@ -0,0 +1,51 @@
+/*
+
+--------------------------------------------
+|                                          |
+|                     ....                 |
+|                    7OO$?I78.             |
+|                   .?8++++7+II?D.         |
+|                   .?O++=I++II+?=         |
+|                   .IO++?7==I??$.         |
+|                   .8++=$===?+I$          |
+|                   ?+++===+===+           |
+|                   ???=+I++==+?           |
+|                 .??++====+==++           |
+|                 ?+++==========~          |
+|                $+++==========+=          |
+|              =?+===+==+I========         |
+|           ..++======~~~~========?        |
+|         .$?I??+=~~===~~~===~===++.       |
+|       .+==.+=~~~=~==~~~~==~~=~==+?       |
+|      ?===I+====~~=~~~=~~=====~~~=?.      |
+|     .=~~~+==~==..~~~~~~=    ~~~~=7=      |
+|     +=~~?+~~=.  ==~~~~=.     ~~~~=?.     |
+|     =~~~=~~~   ?===~~+.       ~~~~+      |
+|     +~~:+~~=    =~~==.        =~~+.      |
+|     ~:~ =~~=    =~~~=         ~===       |
+|         I=~~   ,=~~=            ,.       |
+|          ~~.   ,====                     |
+|                 ====                     |
+|                 =~~.                     |
+|                                          |
+|------------------------------------------|                                                          
+|              Internet Of Thing           |
+|                  Eli Hughes              |
+| Freescale / Hack-a-day Make-It-Challenge |
+|              FTF 2014 - Dallas, Tx       |
+|------------------------------------------|
+
+*/
+#include "mbed.h"
+
+#ifndef SYSTEM_H
+#define SYSTEM_H
+
+
+extern DigitalOut   SPIN_CCW;
+extern  DigitalOut   SPIN_CW;
+
+extern DigitalOut   GO_FORWARD;
+extern DigitalOut   GO_REVERSE;
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Terminal.cpp	Thu Apr 10 21:14:23 2014 +0000
@@ -0,0 +1,340 @@
+/*
+
+--------------------------------------------
+|                                          |
+|                     ....                 |
+|                    7OO$?I78.             |
+|                   .?8++++7+II?D.         |
+|                   .?O++=I++II+?=         |
+|                   .IO++?7==I??$.         |
+|                   .8++=$===?+I$          |
+|                   ?+++===+===+           |
+|                   ???=+I++==+?           |
+|                 .??++====+==++           |
+|                 ?+++==========~          |
+|                $+++==========+=          |
+|              =?+===+==+I========         |
+|           ..++======~~~~========?        |
+|         .$?I??+=~~===~~~===~===++.       |
+|       .+==.+=~~~=~==~~~~==~~=~==+?       |
+|      ?===I+====~~=~~~=~~=====~~~=?.      |
+|     .=~~~+==~==..~~~~~~=    ~~~~=7=      |
+|     +=~~?+~~=.  ==~~~~=.     ~~~~=?.     |
+|     =~~~=~~~   ?===~~+.       ~~~~+      |
+|     +~~:+~~=    =~~==.        =~~+.      |
+|     ~:~ =~~=    =~~~=         ~===       |
+|         I=~~   ,=~~=            ,.       |
+|          ~~.   ,====                     |
+|                 ====                     |
+|                 =~~.                     |
+|                                          |
+|------------------------------------------|                                                          
+|              Internet Of Thing           |
+|                  Eli Hughes              |
+| Freescale / Hack-a-day Make-It-Challenge |
+|              FTF 2014 - Dallas, Tx       |
+|------------------------------------------|
+
+*/
+#include "Terminal.h"
+#include "Types.h"
+#include "Queue.h"
+#include <string.h>
+#include <stdint.h>
+#include "System.h"
+
+//*****************************************************************
+//Terminal Configuration
+//*****************************************************************
+
+#define MAX_TERMINAL_LINE_CHARS 64
+#define MAX_TERMINAL_CMD_CHARS  32
+
+ByteQueue TERMINAL_OUTPUT_QUEUE;
+ByteQueue TERMINAL_INPUT_QUEUE;
+
+#define TERMINAL_QUEUE_SIZE     2048
+
+uint8_t TERMINAL_OUTPUT_QUEUE_Storage[TERMINAL_QUEUE_SIZE];
+uint8_t TERMINAL_INPUT_QUEUE_Storage[TERMINAL_QUEUE_SIZE];
+
+typedef void (*TerminalCallback)(char *);
+
+
+typedef struct 
+{
+    const char *CommandString;
+    TerminalCallback Callback;
+    const char *HelpString;
+        
+} TerminalCallbackRecord;
+
+//Callback function prototypes
+void TerminalCmd_Help(char *arg);
+void TerminalCmd_Go(char *arg);
+void TerminalCmd_SpinCW(char *arg);
+void TerminalCmd_SpinCCW(char *arg);
+void TerminalCmd_Stop(char *arg);
+
+void TerminalCmd_Reboot(char *arg);
+void TerminalCmd_Back(char *arg);
+
+//Populate this array with the callback functions and their terminal command string
+TerminalCallbackRecord MyTerminalCallbackRecords[] ={   {"help",TerminalCmd_Help,"Lists available commands"},
+                                                        {"thing_go",TerminalCmd_Go," Tells the thing to go forward"},
+                                                        {"thing_cw",TerminalCmd_SpinCW," Tells the thing to spin clock-wise"},
+                                                        {"thing_ccw",TerminalCmd_SpinCCW," Tells the thing to spin counter clockwise"},
+                                                        {"thing_stop",TerminalCmd_Stop,"Tells the thing to stop"},
+                                                        {"thing_back",TerminalCmd_Back,"Tells the thing to go"},
+                                                        };
+
+//*****************************************************************
+//Plumbing.....
+//*****************************************************************
+
+#define NUM_TERMINAL_COMMANDS  (sizeof(MyTerminalCallbackRecords)/sizeof(TerminalCallbackRecord))
+
+char TerminalLineBuf[MAX_TERMINAL_LINE_CHARS];
+uint8_t TerminalPos;
+char TerminalCmdBuf[MAX_TERMINAL_CMD_CHARS+1];
+char TerminalArgs[MAX_TERMINAL_LINE_CHARS-MAX_TERMINAL_CMD_CHARS];
+uint8_t NextCharIn;
+uint8_t CmdFound;
+ 
+void TerminalBootMsg()
+{
+TERMINAL_PRINTF("-------------------------------------------- \r\n");
+TERMINAL_PRINTF("|                                          |\r\n");
+TERMINAL_PRINTF("|                     ....                 | \r\n");
+TERMINAL_PRINTF("|                    7OO$?I78.             | \r\n");
+TERMINAL_PRINTF("|                   .?8++++7+II?D.         | \r\n");
+TERMINAL_PRINTF("|                   .?O++=I++II+?=         | \r\n");
+TERMINAL_PRINTF("|                   .IO++?7==I??$.         | \r\n");
+TERMINAL_PRINTF("|                   .8++=$===?+I$          | \r\n");
+TERMINAL_PRINTF("|                   ?+++===+===+           | \r\n");
+TERMINAL_PRINTF("|                   ???=+I++==+?           | \r\n");
+TERMINAL_PRINTF("|                 .??++====+==++           | \r\n");
+TERMINAL_PRINTF("|                 ?+++==========~          | \r\n");
+TERMINAL_PRINTF("|                $+++==========+=          | \r\n");
+TERMINAL_PRINTF("|              =?+===+==+I========         | \r\n");
+TERMINAL_PRINTF("|           ..++======~~~~========?        | \r\n");
+TERMINAL_PRINTF("|         .$?I??+=~~===~~~===~===++.       | \r\n");
+TERMINAL_PRINTF("|       .+==.+=~~~=~==~~~~==~~=~==+?       | \r\n");
+TERMINAL_PRINTF("|      ?===I+====~~=~~~=~~=====~~~=?.      | \r\n");
+TERMINAL_PRINTF("|     .=~~~+==~==..~~~~~~=    ~~~~=7=      | \r\n");
+TERMINAL_PRINTF("|     +=~~?+~~=.  ==~~~~=.     ~~~~=?.     | \r\n");
+TERMINAL_PRINTF("|     =~~~=~~~   ?===~~+.       ~~~~+      | \r\n");
+TERMINAL_PRINTF("|     +~~:+~~=    =~~==.        =~~+.      | \r\n");
+TERMINAL_PRINTF("|     ~:~ =~~=    =~~~=         ~===       | \r\n");
+TERMINAL_PRINTF("|         I=~~   ,=~~=            ,.       | \r\n");
+TERMINAL_PRINTF("|          ~~.   ,====                     | \r\n");
+TERMINAL_PRINTF("|                 ====                     | \r\n");
+TERMINAL_PRINTF("|                 =~~.                     | \r\n");
+TERMINAL_PRINTF("|                                          |\r\n");
+TERMINAL_PRINTF("|------------------------------------------|\r\n");                                                                
+TERMINAL_PRINTF("|              Internet Of Thing           |\r\n");
+TERMINAL_PRINTF("|                  Eli Hughes              |\r\n");
+TERMINAL_PRINTF("| Freescale / Hack-a-day Make-It-Challenge |\r\n"); 
+TERMINAL_PRINTF("|              FTF 2014 - Dallas, Tx       |\r\n");
+TERMINAL_PRINTF("|------------------------------------------|\r\n\r\n>"); 
+}
+
+void TFC_InitTerminal()
+{
+    TerminalPos = 0;
+    CmdFound = 0;
+    
+    InitByteQueue(&TERMINAL_OUTPUT_QUEUE,TERMINAL_QUEUE_SIZE,&TERMINAL_OUTPUT_QUEUE_Storage[0]); 
+    InitByteQueue(&TERMINAL_INPUT_QUEUE,TERMINAL_QUEUE_SIZE,&TERMINAL_INPUT_QUEUE_Storage[0]); 
+    
+    
+    TerminalBootMsg();
+}
+
+void TerminalCmd_Help(char *arg)
+{
+    uint8_t i;
+
+    TERMINAL_PRINTF("\r\n\r\nCommand List:\r\n");
+    TERMINAL_PRINTF("----------------------\r\n");
+
+    for(i=0;i<NUM_TERMINAL_COMMANDS;i++)
+    {
+         TERMINAL_PRINTF("%s  ---->  %s\r\n",MyTerminalCallbackRecords[i].CommandString,MyTerminalCallbackRecords[i].HelpString);    
+    }
+
+    TERMINAL_PRINTF("\r\n\r\n");
+}
+
+
+void TerminalCmd_Go(char *arg)
+{
+    SPIN_CCW = 0;
+    SPIN_CW = 0;
+    GO_FORWARD = 1;
+    GO_REVERSE = 0;
+    
+}
+
+void TerminalCmd_Back(char *arg)
+{
+    SPIN_CCW = 0;
+    SPIN_CW = 0;
+    GO_FORWARD = 0;
+    GO_REVERSE = 1;
+    
+}
+    
+void TerminalCmd_SpinCW(char *arg)
+{
+    SPIN_CCW = 0;
+    SPIN_CW = 1;
+    GO_FORWARD = 0;
+    GO_REVERSE = 0;
+
+}
+void TerminalCmd_SpinCCW(char *arg)
+{
+    SPIN_CCW = 1;
+    SPIN_CW = 0;
+    GO_FORWARD = 0;
+    GO_REVERSE = 0;
+}
+
+void TerminalCmd_Stop(char *arg)
+{
+
+    SPIN_CCW = 0;
+    SPIN_CW = 0;
+    GO_FORWARD = 0;
+    GO_REVERSE = 0;
+
+}
+    
+
+void TerminalCmd_Reboot(char *arg)
+{
+      TerminalBootMsg();
+}
+
+
+void TFC_ProcessTerminal()
+{
+     uint8_t i,j;
+     uint8_t ArgsFound;
+        
+    if(TERMINAL_READABLE)
+    {
+       NextCharIn = TERMINAL_GETC;
+       
+        switch(NextCharIn)
+        {
+            case '\r':
+             
+             TerminalLineBuf[TerminalPos++] = 0x0;
+             TERMINAL_PUTC(NextCharIn);
+           
+             if(TerminalPos > 1)
+             {
+                 //find the command
+                 i=0;
+                 while(TerminalLineBuf[i]>0x20 &&  TerminalLineBuf[i]<0x7f)
+                 {
+                      TerminalCmdBuf[i] = TerminalLineBuf[i];
+                      i++;
+    
+                    if(i==MAX_TERMINAL_CMD_CHARS)
+                        {
+                         break;
+                        }
+                 }
+                    
+                TerminalCmdBuf[i] = 0;
+                TerminalCmdBuf[i+1] = 0;
+                
+                
+                ArgsFound = TRUE;
+                memset(TerminalArgs,0x00,sizeof(TerminalArgs));
+                //scan for num terminator or next non whitespace
+                while(TerminalLineBuf[i]<=0x20 && (i<MAX_TERMINAL_LINE_CHARS))
+                {
+                    if(TerminalLineBuf[i] == 0x00)
+                    {
+                    
+                        //if we find a NULL terminator before a non whitespace character they flag for no arguments
+                        ArgsFound = FALSE;
+                        break;
+                    }   
+                    i++; 
+                }
+                
+                if(ArgsFound == TRUE)
+                {
+                    strcpy(TerminalArgs,&TerminalLineBuf[i]);
+                    
+                    //trim trailing whitespace
+                    i = sizeof(TerminalArgs)-1;
+                    
+                    while((TerminalArgs[i]<0x21) && (i>0))
+                    {
+                        TerminalArgs[i]= 0x00;
+                        i--;
+                    }       
+                }
+                
+                CmdFound = FALSE;
+                for(j=0;j<NUM_TERMINAL_COMMANDS;j++)
+                {           
+                    if(strcmp(TerminalCmdBuf,MyTerminalCallbackRecords[j].CommandString) == 0)
+                    {
+                        TERMINAL_PRINTF("\r\n");
+                        if(MyTerminalCallbackRecords[j].Callback != NULL)
+                            MyTerminalCallbackRecords[j].Callback(TerminalArgs);
+                    
+                        CmdFound = TRUE;
+                        break;
+                    }             
+                }        
+                if(CmdFound == FALSE)
+                {
+                  TERMINAL_PRINTF("\r\n%s command not recognized.\r\n\r\n",TerminalCmdBuf);
+                  TerminalCmd_Help("no arg");
+                  
+                }
+              }    
+             TERMINAL_PRINTF("\r\n>");
+             TerminalPos = 0;
+            
+            break;
+            
+            case '\b':
+                if(TerminalPos > 0)
+                {
+                    TerminalPos--;    
+                    TERMINAL_PUTC(NextCharIn);
+                }
+            break;
+            
+            default:
+                
+                if(TerminalPos == 0 && NextCharIn == 0x020)
+                {
+                     //Do nothing if space bar is pressed at beginning of line    
+                }
+                   else if(NextCharIn >= 0x20 && NextCharIn<0x7F)
+                {
+                    
+                    if(TerminalPos < MAX_TERMINAL_LINE_CHARS-1)
+                    {
+                         TerminalLineBuf[TerminalPos++] = NextCharIn;
+                        TERMINAL_PUTC(NextCharIn);
+                    }
+                }
+            
+            break;
+        
+        }
+    }
+ 
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Terminal.h	Thu Apr 10 21:14:23 2014 +0000
@@ -0,0 +1,58 @@
+/*
+
+--------------------------------------------
+|                                          |
+|                     ....                 |
+|                    7OO$?I78.             |
+|                   .?8++++7+II?D.         |
+|                   .?O++=I++II+?=         |
+|                   .IO++?7==I??$.         |
+|                   .8++=$===?+I$          |
+|                   ?+++===+===+           |
+|                   ???=+I++==+?           |
+|                 .??++====+==++           |
+|                 ?+++==========~          |
+|                $+++==========+=          |
+|              =?+===+==+I========         |
+|           ..++======~~~~========?        |
+|         .$?I??+=~~===~~~===~===++.       |
+|       .+==.+=~~~=~==~~~~==~~=~==+?       |
+|      ?===I+====~~=~~~=~~=====~~~=?.      |
+|     .=~~~+==~==..~~~~~~=    ~~~~=7=      |
+|     +=~~?+~~=.  ==~~~~=.     ~~~~=?.     |
+|     =~~~=~~~   ?===~~+.       ~~~~+      |
+|     +~~:+~~=    =~~==.        =~~+.      |
+|     ~:~ =~~=    =~~~=         ~===       |
+|         I=~~   ,=~~=            ,.       |
+|          ~~.   ,====                     |
+|                 ====                     |
+|                 =~~.                     |
+|                                          |
+|------------------------------------------|                                                          
+|              Internet Of Thing           |
+|                  Eli Hughes              |
+| Freescale / Hack-a-day Make-It-Challenge |
+|              FTF 2014 - Dallas, Tx       |
+|------------------------------------------|
+
+*/
+#include "Queue.h"
+
+#ifndef TFC_TERMINAL_H_
+#define TFC_TERMINAL_H_
+
+
+extern ByteQueue TERMINAL_OUTPUT_QUEUE;
+extern ByteQueue TERMINAL_INPUT_QUEUE;
+
+
+void TFC_InitTerminal();
+void TFC_ProcessTerminal();
+
+    #define TERMINAL_PRINTF(...)        Qprintf(&TERMINAL_OUTPUT_QUEUE,__VA_ARGS__)  
+    #define TERMINAL_PUTC(c)            ByteEnqueue(&TERMINAL_OUTPUT_QUEUE,c)
+    #define TERMINAL_READABLE           BytesInQueue(&TERMINAL_INPUT_QUEUE)
+    #define TERMINAL_GETC               ForcedByteDequeue(&TERMINAL_INPUT_QUEUE)
+
+
+#endif /* TFC_TERMINAL_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Types.h	Thu Apr 10 21:14:23 2014 +0000
@@ -0,0 +1,50 @@
+/*
+
+--------------------------------------------
+|                                          |
+|                     ....                 |
+|                    7OO$?I78.             |
+|                   .?8++++7+II?D.         |
+|                   .?O++=I++II+?=         |
+|                   .IO++?7==I??$.         |
+|                   .8++=$===?+I$          |
+|                   ?+++===+===+           |
+|                   ???=+I++==+?           |
+|                 .??++====+==++           |
+|                 ?+++==========~          |
+|                $+++==========+=          |
+|              =?+===+==+I========         |
+|           ..++======~~~~========?        |
+|         .$?I??+=~~===~~~===~===++.       |
+|       .+==.+=~~~=~==~~~~==~~=~==+?       |
+|      ?===I+====~~=~~~=~~=====~~~=?.      |
+|     .=~~~+==~==..~~~~~~=    ~~~~=7=      |
+|     +=~~?+~~=.  ==~~~~=.     ~~~~=?.     |
+|     =~~~=~~~   ?===~~+.       ~~~~+      |
+|     +~~:+~~=    =~~==.        =~~+.      |
+|     ~:~ =~~=    =~~~=         ~===       |
+|         I=~~   ,=~~=            ,.       |
+|          ~~.   ,====                     |
+|                 ====                     |
+|                 =~~.                     |
+|                                          |
+|------------------------------------------|                                                          
+|              Internet Of Thing           |
+|                  Eli Hughes              |
+| Freescale / Hack-a-day Make-It-Challenge |
+|              FTF 2014 - Dallas, Tx       |
+|------------------------------------------|
+
+*/
+#ifndef TFC_TYPES_H_
+#define TFC_TYPES_H_
+
+#ifndef TRUE
+#define TRUE    1
+#endif
+
+#ifndef FALSE
+#define FALSE  0
+#endif
+
+#endif /* TFC_TYPES_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Apr 10 21:14:23 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/6473597d706e
\ No newline at end of file