Generate up to 8 different digital waeforms from serial port

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
jm
Date:
Sat Feb 12 16:41:07 2011 +0000
Commit message:
jmPulse Command Line Interface Module

Changed in this revision

jmCommands.c Show annotated file Show diff for this revision Revisions of this file
jmCommands.h Show annotated file Show diff for this revision Revisions of this file
jmInterpreter.c Show annotated file Show diff for this revision Revisions of this file
jmInterpreter.h Show annotated file Show diff for this revision Revisions of this file
jmMessages.c Show annotated file Show diff for this revision Revisions of this file
jmMessages.h Show annotated file Show diff for this revision Revisions of this file
jmPulse.c Show annotated file Show diff for this revision Revisions of this file
jmPulse.h Show annotated file Show diff for this revision Revisions of this file
jmRingBuffer.c Show annotated file Show diff for this revision Revisions of this file
jmRingBuffer.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
main.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/jmCommands.c	Sat Feb 12 16:41:07 2011 +0000
@@ -0,0 +1,76 @@
+/** @file  jmCommands.c
+ *  Auto Generated by jmCLIG
+ *  Saturday, February 12, 2011  10:43 AM
+ *  @version  2011.01.05
+ */
+
+#include "main.h"
+#include "jmCommands.h"
+#include "jmMessages.h"
+#include "jmRingBuffer.h"
+#include "jmPulse.h"
+
+const char jmCLIG[] = {"\njmCLIG Version  2011.01.05 \nInstance Saturday, February 12, 2011  10:43 AM\n"};
+
+// Command Name Table
+const char cmdNames[]=
+   {
+      'l','i','s','t',0,
+      'v','e','r',0,
+      'h','e','l','p',0,
+      'f','e','e','d','b','a','c','k',0,
+      'e','c','h','o',0,
+      'p','u','l','s','e',0,
+      'p','u','l','s','e','I','n','i','t',0,
+      'p','u','l','s','e','S','t','o','p',0,
+      'G','P','P','P','0',0,
+      'i','n','i','t',0,
+      0
+   };
+
+//  Section Definitions
+#define list 0
+#define ver 1
+#define help 2
+#define feedback 3
+#define echo 4
+#define pulse 5
+#define pulseInit 6
+#define pulseStop 7
+#define GPPP0 8
+#define init 9
+
+
+/***********************************************************************
+ * @brief	Command steering
+ * Command Associated with Command Number is Executed
+ * @param[in]	cmdNum Command Number
+ * @return		none
+ **********************************************************************/
+void Action(int cmdNum){
+   switch(cmdNum){
+     case list   : cli_list();
+             break;
+     case ver   : cli_version();
+             break;
+     case help   : cli_help();
+             break;
+     case feedback   : cli_feedback();
+             break;
+     case echo   : cli_echo();
+             break;
+     case pulse   : cli_Pulse();
+             break;
+     case pulseInit   : PulseInit();
+             break;
+     case pulseStop   : cli_PulseStop();
+             break;
+     case GPPP0   : cli_GPPP0();
+             break;
+     case init   : Inits();
+             break;
+     default : UnknownCommand();
+               NextCommand(nl,pLine);
+   }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmCommands.h	Sat Feb 12 16:41:07 2011 +0000
@@ -0,0 +1,18 @@
+/** @file  jmCommands.h
+*  Auto Generated by jmCLIG
+*  @version  Saturday, February 12, 2011  10:43 AM
+*/
+
+#ifndef jmCommandsdef
+   #define jmCommandsdef 1
+
+   #define nbCommands 10
+
+   // Strings
+   extern const char jmCLIG[77];
+   extern const char cmdNames[66];
+
+#endif
+
+// Prototypes
+void Action(int);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmInterpreter.c	Sat Feb 12 16:41:07 2011 +0000
@@ -0,0 +1,46 @@
+/*************************************************************************
+ * @file     jmInterpreter.c
+ * @brief    Command Line Interpreter
+ *                  
+ * @date    December 27,2010 
+*/
+
+#include "jmInterpreter.h"
+#include "jmRingBuffer.h"
+#include "jmCommands.h"
+
+/** @brief Interpret a command line.
+ * Interpreter uses Command Line Buffer to fecth command name
+ * and redirects execution to associated function.
+ * @param none
+ * @returns none
+ */
+void Interpret(void){ 
+  unsigned int i,k;
+  unsigned char Command, found;
+  char Word[WordMaxSize];
+  Command =0;
+  found = 0;
+  
+  if(NotEmpty(pLine)){
+     ExtractWord(pLine,Word);              // Command name extraction 
+     for(i=0, k=0;i<sizeof(cmdNames);i++){ // lookup in names array
+         if(cmdNames[i]!=Word[k]){         // if different
+            while(cmdNames[i]!=0)i++;      // next entry in names array
+            Command++;                     // update command index
+            k=0;
+         }
+         else{
+           if(Word[k]==0){             
+              found=1; 
+            } 
+           else k++;
+         } //else
+    
+         if(found)break; 
+     }  //for
+   }
+  
+  // Command execution
+  Action(Command);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmInterpreter.h	Sat Feb 12 16:41:07 2011 +0000
@@ -0,0 +1,9 @@
+/*************************************************************************
+ * @file     jmInterpreter.h
+ * @brief    Command Line Interpreter
+ *                  
+ * @date    December 27,2010 
+*/
+
+// Prototypes
+void Interpret(void);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmMessages.c	Sat Feb 12 16:41:07 2011 +0000
@@ -0,0 +1,125 @@
+/*************************************************************************
+ * @file     jmMessages.c
+ * @brief    Control System Messages
+ *                  
+ * @date    December 27,2010 
+*/
+
+#include "jmCommands.h"
+#include "jmRingBuffer.h"
+#include "stdio.h"
+#include "jmMessages.h"
+#include "stdint.h"
+
+uint8_t Help;
+uint8_t Feedback;
+uint8_t Echo;
+
+
+/** @brief Enable only help messages
+ * @param none
+ * @returns none
+ */
+void InitMessages(void){
+   Help = 1;
+   Echo = 0;
+   Feedback = 0;
+}
+ 
+/** @brief Send all command names in a project
+ * @param none
+ * @returns none
+ */
+void cli_list(void){
+   int i,j;
+   printf("Commands:\n");
+   printf(".......................\n");
+   // for each command 
+   for(i=0,j=0; i<nbCommands; i++,j++){
+      // print name
+      while(cmdNames[j]) printf("%c",cmdNames[j++]); 
+      printf("\n"); 
+   }
+   printf("........................\n");
+}
+
+/** @brief Send Message Unknown Command from interpreter
+ * @param none
+ * @returns none
+ */
+void UnknownCommand(void){
+   printf("\n?\n");
+}
+
+/** @brief Send Build Version Message
+ * @param none
+ * @returns none
+ */
+void cli_version(void){
+    printf(jmCLIG);
+}
+
+/** @brief Help Command Line Control.
+ * Enable/disable help messages
+ * When enabled, Typing name only prints Command Format
+ * @param none
+ * @returns none 
+ */
+void cli_help(void){
+    unsigned int  value;
+   if(ExtractUInteger(pLine,&value,0,1)){
+      if(value == 1)  printf("Help Enabled ! type command name to print its format\n");
+       else printf("Help Disabled !\n");
+        
+        Help = (uint8_t) value;                // save status
+        return;
+   } 
+   // Error on input, show format
+   if(Help)printf("help  (value)0..1\n");
+   // Ignore pending command line
+   NextCommand(nl,pLine);
+}
+
+/** @brief Feedback Command Line Control. 
+ * Enable/disable feedback messages
+ * When enabled, feedback from user input commands are returned
+ * @param none
+ * @returns none 
+ */
+void cli_feedback(void){
+    unsigned int  value;
+   if(ExtractUInteger(pLine,&value,0,1)){
+      if(value == 1)  printf("Feedback Enabled !\n");
+       else    printf("Feedback Disabled !\n");
+       
+        Feedback = (uint8_t)value;        // save status
+        return;
+   } 
+
+   // Error on input, show format
+   if(Help)printf("feedback  (value)0..1\n");
+   // Ignore pending command line
+   NextCommand(nl,pLine);
+}
+
+/** @brief Echo Command Line Control.
+ * Enable/disable communication echoes
+ * When enabled, user inputs are echoed back
+ * @param none
+ * @returns none 
+ */
+void cli_echo(void){
+    unsigned int  value;
+   if(ExtractUInteger(pLine,&value,0,1)){
+      if(value == 1)  printf("Echo Enabled !\n");
+       else    printf("Echo Disabled !\n");
+        
+        Echo = (uint8_t)value;         // save status
+       return;
+   } 
+
+   // Error on input, show format
+   if(Help)printf("echo  (value)0..1\n");
+   // Ignore pending command line
+   NextCommand(nl,pLine);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmMessages.h	Sat Feb 12 16:41:07 2011 +0000
@@ -0,0 +1,35 @@
+/*************************************************************************
+ * @file     jmMessages.h
+ * @brief    Control System Messages
+ *                  
+ * @date    December 27,2010 
+*/
+
+#include "stdint.h"
+
+// variables to enable/disable messages
+extern   uint8_t Help;
+extern   uint8_t Feedback;
+extern   uint8_t Echo;
+
+// Prototypes
+void InitMessages(void);
+void cli_list(void);
+void cli_version(void);
+void UnknownCommand(void);
+void cli_help(void);
+void cli_feedback(void);
+void cli_echo(void);
+
+
+//-------------------------- CLIG PLUGS --------------------
+// CLIG-CMD
+/*
+list cli_list();
+ver cli_version();
+help cli_help();
+feedback cli_feedback();
+echo cli_echo();
+*/
+
+//------------------------ END CLIG PLUGS -----------------
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmPulse.c	Sat Feb 12 16:41:07 2011 +0000
@@ -0,0 +1,247 @@
+/**
+ * @file    jmPulse.c                 
+ * @version    1.0
+ * @date    Feb 12, 2011
+ */
+
+#include "jmPulse.h"
+#include "jmRingBuffer.h"
+#include "LPC17xx.h"
+#include "main.h"
+#include "jmCommands.h"
+#include "jmMessages.h"
+#include "jmRingBuffer.h"
+#include "stdio.h"
+
+#ifndef nonStop
+  #define nonStop 65535  // for continuous mode operation
+#endif
+
+// output defenitions
+#define Low 0
+#define High 1
+#define StatusOffset 3
+
+// State definitions
+#define puNotInit    0
+#define puStopped 2
+#define Pulse 1
+
+struct StructPulse sPulse[pulseQty]; // static creation
+
+/** Module Data Structure Initialization
+ * @brief   All State Machines put to sleep.
+ * @param[in]    none
+ * @returns none
+ */
+void PulseInit(void){
+   int i;
+   for(i=0;i<pulseQty;i++){
+     sPulse[i].state = puNotInit;
+   }
+}
+
+/** 
+ * @brief   Stop one or all pulse Machines
+ * @param[in] Extracted from command line (Pulse Number)0..7 255 for all
+ * @returns   Return Message: GPPP0 id pin tOn tOff status
+ */
+void cli_PulseStop(void){
+   unsigned int id,i;
+
+   if(ExtractUInteger(pLine,&id,0,255)){    // extract pulseNumber
+       // put id pulse machine to sleep 
+      if(id < pulseQty){
+          sPulse[id].cycles = 0;
+          sPulse[id].state = puStopped;
+          rGPPP0(id);
+          return;
+      }
+
+      if(id == 255){
+          // stop all controllers
+          for(i=0;i<pulseQty;i++){
+              sPulse[i].cycles = 0;
+              sPulse[i].state = puStopped;
+          }
+      }
+
+      cli_GPPP0();    // Return 8 Messages: GPPP0 id pin tOn tOff status
+      return;
+    }
+  if(Help)printf("pulseStop (Pulse number)0..%d \n",pulseQty-1);  
+  // Ignore pending command line
+  NextCommand(nl,pLine);
+}
+
+
+/** Module Pulse Command Line Interface
+ * @brief        Command Line Interface to control PWM/Pulse on output pins.
+ * @param[in]    Extracted from command line (Pulse Controller Number)0..7 (Pin id)0..432 (tOn)0..255 (tOff)0..255) (cycles)1..65535
+ * @returns    none
+ */
+void cli_Pulse(void){
+   unsigned int pulseNum, pinNumber,tOn,tOff,cycles;
+   if(ExtractUInteger(pLine,&pulseNum,0,pulseQty-1)){    // extract pulseNumber
+      if(ExtractUInteger(pLine,&pinNumber,0,432)){       // extract pin id
+         if(ExtractUInteger(pLine,&tOn,0,255)){          // extract tOn
+            if(ExtractUInteger(pLine,&tOff,0,255)){      // extract tOff
+               // extract cycles and test for nonStop mode
+               if(!ExtractUInteger(pLine,&cycles,1,65535))cycles = nonStop;
+
+               SetPulseParam(pulseNum, pinNumber, tOn, tOff, cycles);
+               if(Feedback)printf("pulse %d Pin%d tOn:%d  tOff:%d  Cycles:%d\n",pulseNum,pinNumber,tOn,tOff,cycles); 
+               return;
+           }
+        }
+      }
+    }
+  if(Help)printf("pulse (Pulse number)0..%d (Pin id)0..432 (tOn)0..255 (tOff)0..255 (Cycles)[1..0xFFFF]\n",pulseQty-1);  
+  // Ignore pending command line
+  NextCommand(nl,pLine);
+}
+
+/** Module Parameter Setting Function
+ * @brief   Enables PWM/pulse State Machine,
+ * Also sets mbed pin as outputs.
+ * @param[in]    num      pulse controller number (value)0..7  
+ * @param[in]    pin      pin id (value)0..432
+ * @param[in]    tOn      on time interval in ticks (tOn)0..255
+ * @param[in]    tOff     off time interval in ticks (tOff)0..255
+ * @param[in]    cycles   repetition number of tOn-tOff cycles
+ * @param[in]    state    set state: inactive, pulse, high, low
+ * @returns     Return Message: GPPP0 id pin state
+ */
+void SetPulseParam(uint8_t num, uint16_t pin, uint8_t tOn, uint8_t tOff, uint16_t cycles){
+   // Get port and bit for that pin
+   uint32_t bitValue;
+   uint8_t port;
+
+   // Get port, bit and bit value
+   port = pin/100;
+   bitValue = 1<<(pin%100);
+
+   sPulse[num].port = jmGPIO[port];
+   sPulse[num].pin = (uint8_t)pin;
+   sPulse[num].bitValue = bitValue;
+   
+   // set mbed pin direction as output
+   jmGPIO[port]->FIODIR |= bitValue;
+   // make sure FIOMASK bit is enable
+   jmGPIO[port]->FIOMASK &= ~bitValue;
+
+   
+   // Low State
+   if(tOn == 0 && tOff != 0)
+   {
+        jmGPIO[port]->FIOPIN &= ~bitValue; // reset pin low 
+        sPulse[num].output = Low;
+        sPulse[num].state = puStopped;
+   }
+   // High State 
+   if(tOn != 0 && tOff == 0)     
+   {
+        jmGPIO[port]->FIOPIN |= bitValue;  // set pin High
+        sPulse[num].output = High;
+        sPulse[num].state = puStopped;
+   }
+   // Toggle output
+   if(tOn == 0 && tOff == 0) 
+   {
+       jmGPIO[port]->FIOPIN ^= bitValue; // toggle pin 
+       // Toggle state
+       if(sPulse[num].output == High)sPulse[num].output = Low;
+       else sPulse[num].output = High;
+       sPulse[num].state = puStopped;
+   }
+   // Start Pulse controller
+   if(tOn != 0 && tOff != 0 && cycles !=0){             
+       sPulse[num].state = Pulse;    
+       sPulse[num].tOn = (uint8_t)tOn;
+       sPulse[num].tOff = (uint8_t)tOff;
+       sPulse[num].cycles = (uint16_t)cycles;
+       sPulse[num].eggTimer = 0;
+   }
+      // Stop Pulse controller
+   if(tOn != 0 && tOff != 0 && cycles ==0){             
+       sPulse[num].cycles = 0;
+       sPulse[num].state = puStopped;
+   }
+
+   // Report process modification
+   rGPPP0(num);    //Return Message: GPPP0 id pin tOn tOff status
+}
+
+/***********************************************************************
+ * @brief    Module State Machine.  
+ * Enable different pwm/pulse rates concurrently.
+ * @param none
+ * @returns    When cycles Done, Return Message: GPPP0 id pin tOn tOff status
+ */ 
+void PulseSM(void){
+  int i;
+   for(i=0;i<pulseQty;i++){ // for each SM define by pins
+     
+     if(sPulse[i].state == puStopped) continue; //controller running ?
+         
+     if(sPulse[i].cycles!=0){  // Cycles to DO ?
+       switch(sPulse[i].output){       
+
+         // output is low
+         case  Low: if(sPulse[i].eggTimer==0){                      // time to change ?     
+                     sPulse[i].port->FIOPIN |= sPulse[i].bitValue;  // set pin High         
+                     sPulse[i].eggTimer=sPulse[i].tOn;              // load timer with tOn   
+                     sPulse[i].output=High;                         // udpate structure
+                  }
+                  break;
+
+         // output is High
+         case  High: if(sPulse[i].eggTimer==0){                           // time to change ?
+                     sPulse[i].port->FIOPIN &= ~sPulse[i].bitValue;    // reset pin low  
+                     sPulse[i].output=Low;                             // update structure    
+                     sPulse[i].eggTimer=sPulse[i].tOff;                // load timer with tOff  
+                     if(sPulse[i].cycles != nonStop){                  // continuous mode ?
+                        if(--sPulse[i].cycles == 0){      // decrease qty if not continuous mode
+                            sPulse[i].state = puStopped;                    // stop controller
+                            // report end of cycles
+                            rGPPP0(i); //Message: GPPP0 id pin tOn tOff status
+                        }
+                     }
+                  }
+                  break;
+         }//switch
+     }//if cycles
+  }//for
+}//PulseSM
+
+/** Module Get Module Process Properties Command Line Interface
+ * @brief        Command Line Interface to Get Module Public Process Properties
+ * @param[in]    Extracted from command line GPPP0 id
+ * @returns    Message: GPPP0 id pin tOn tOff status
+ */
+void cli_GPPP0(void)
+{    unsigned int id;
+   if(ExtractUInteger(pLine,&id,0,7)){    // extract pulse id Number
+       rGPPP0(id); //Message: GPPP0 id pin tOn tOff status
+       return;
+    }
+
+    if(Help)printf("GPPP0 (Pulse id)0..%d\n",pulseQty-1);  
+    // Ignore pending command line
+    NextCommand(nl,pLine);
+}
+
+/** Public Properties Message
+ * @brief    Send Process Properties to update GUI
+ * @param[in] id Process identification
+ * @returns   Message: GPPP0 id pin tOn tOff status
+ */
+void rGPPP0(unsigned int id ){
+    int status;
+    if(id < pulseQty){
+       if( sPulse[id].state == puStopped)status = sPulse[id].output +StatusOffset;
+       else  status = sPulse[id].state;
+       printf("GPPP0 %d %d %d %d %d\n",id,sPulse[id].pin,sPulse[id].tOn,sPulse[id].tOff,status);
+
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmPulse.h	Sat Feb 12 16:41:07 2011 +0000
@@ -0,0 +1,92 @@
+/*************************************************************************
+ * @file	jmPulse.h
+ * @brief	Control pulse duration and repetition on digital mbed pins
+ *          Up to 8 pins can be controlled at the same time.
+ *          Single pulse or PWM like waveforms can be generated.
+ *             
+ * @version	1.1
+ * @date	Feb 12, 2011
+ */
+
+/*
+   * Module Command Line Interface 
+     Format: command name (arg info)min..max values [optional argument]
+     
+     pulse (pulse number)0..3 (pin number)0..432 (tOn)0..255 (tOff)0..255 (Cycles)[1..65535]
+      Ex: pulse 0 118 5 10 20     Pulse Port1 Bit 18 High for 5 tick units, then Low for 10 ticks and repeat 20 times,
+                                 then Return Message: GPPP0 id pin tOn tOff status
+
+      Ex: pulse 0 118 1 0	Set output Port1 Bit 18 High
+      Ex: pulse 0 118 0 1	Reset output Port1 Bit 18 Low
+	  Ex: pulse 0 118 0 0	Toggle Port1 Bit 18 state
+
+   * Module Events
+         On terminating pulse cycles, Return Message: GPPP0 id pin tOn tOff status
+
+   *  Module Feedback and Help messages may be enabled/disabled by Command Lines.
+         feedback (enable/disable)0..1
+         help (enable/disable)0..1
+*/
+
+#ifndef Pulsedef
+  #define Pulsedef 1
+
+  #define pulseQty 8 // number of pins for pulse
+
+  #include "LPC17xx.h"
+
+  // Module Data Structure
+  extern struct StructPulse{
+     uint16_t pin;
+	 uint8_t tOff;       
+     uint8_t tOn;
+	 uint8_t output;
+     uint8_t state;
+     uint16_t eggTimer;
+     uint16_t cycles;
+     uint32_t bitValue;
+	 LPC_GPIO_TypeDef * port;
+  }sPulse[pulseQty];
+
+
+#endif
+
+// Module Prototypes
+void PulseInit(void);
+void cli_Pulse(void);
+void PulseSM(void);
+void SetPulseParam(uint8_t pulseNum, uint16_t pin, uint8_t tOn, uint8_t tOff, uint16_t cycles);
+void cli_GPPP0(void);
+void rGPPP0(unsigned int id);
+void cli_PulseStop(void);
+
+//-------------------------- CLIG PLUGS --------------------
+// CLIG-INCLUDE
+/*
+#include "jmPulse.h"
+*/
+
+// CLIG-CMD
+/*
+pulse cli_Pulse();
+pulseInit PulseInit();
+pulseStop cli_PulseStop();
+GPPP0 cli_GPPP0();
+*/
+
+// CLIG-INIT
+/*
+   PulseInit();
+*/
+
+// CLIG-TIMER
+/*
+   // Module jmPulse
+   for(i=0;i<pulseQty;i++)if(sPulse[i].eggTimer>0)sPulse[i].eggTimer--;
+*/
+
+// CLIG-SM
+/*
+     PulseSM();
+*/
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmRingBuffer.c	Sat Feb 12 16:41:07 2011 +0000
@@ -0,0 +1,215 @@
+/*************************************************************************
+ * @file     jmRingBuffer.c
+ * @brief    Command Line Rx Ring Buffer
+ *                  
+ * @date    Feb 12, 2011 
+*/
+
+
+#include "jmRingBuffer.h"
+#include "stdio.h"
+
+// static creation of Command Line Buffer
+struct RingBuffer  Line, *pLine; 
+
+/** @brief Command line ring buffer initialization.
+ * @param none
+ * @returns none 
+ */
+void InitCommandLineRingBuffer(void){
+ pLine = &Line;
+ FlushRingBuffer(pLine);
+}
+
+/** @brief Move ring head pointer foward.
+ * @param *p pointer to ring buffer
+ * @returns none 
+ */
+void NextHead(struct RingBuffer *p)              
+{    p->head++;            
+    if(p->head >= DimRingBuffer) 
+       p->head=0;          
+}
+
+/** @brief Move ring tail pointer foward.
+ * @param pointer to ring buffer
+ * @returns none 
+ */
+void NextTail(struct RingBuffer *p)              
+{    p->tail++;              
+    if(p->tail >= DimRingBuffer)   
+       p->tail=0;            
+}
+      
+/** @brief Check if buffer full.
+ * @param *p pointer to ring buffer
+ * @returns true if full, false otherwise 
+ */ 
+bool Full(struct RingBuffer *p)
+{  if(p->qty >= DimRingBuffer)         
+       return true;
+   else
+      return false;
+}
+  
+/** @brief Insert a char in buffer.
+ * @param c unsigned char to be inserted
+ * @param *p pointer to ring buffer
+ * @returns none 
+ */
+void Insert(unsigned char c, struct RingBuffer *p)
+{  if(Full(p))              
+      NextHead(p);            
+   else
+      p->qty++;                  
+ 
+   p->Buffer[p->tail]=c;          
+   NextTail(p);                   
+}
+
+/** @brief Check if ring buffer not empty.
+ * @param *p pointer to ring buffer
+ * @returns true if full, false otherwise
+ */ 
+bool NotEmpty(struct RingBuffer *p)
+{  if(p->qty == 0)                
+      return false ;                          
+   else 
+      return true;                          
+}
+
+/** @brief Extract a char from ring buffer.
+ * @param *p pointer to ring buffer
+ * @returns unsigned char
+ */
+unsigned char Extract(struct RingBuffer *p)      
+{  unsigned char c;
+   c = p->Buffer[p->head];     
+   if(NotEmpty(p))            
+   {  NextHead(p);            
+      p->qty--;                
+   }
+   return c;
+}
+
+/** @brief Flush ring buffer.
+ * @param *p pointer to ring buffer
+ * @returns none
+ */
+void FlushRingBuffer(struct RingBuffer *p)    
+{  int i;
+   p->head = 0;
+   p->tail = 0;
+   p->qty = 0;
+   for(i=0;i<DimRingBuffer;i++)p->Buffer[i]=0;
+}
+
+/** @brief Delete last char from ring buffer.
+ * @param *p pointer to ring buffer
+ * @returns none
+ */
+void DelChar(struct RingBuffer *p)
+{ if(p->qty != 0){
+     if(p->tail==0)p->tail=DimRingBuffer;
+     else p->tail--;  
+     p->qty--;    
+   }
+}
+
+/** @brief Remove a command line from ring buffer. 
+ * @param c end command identifier unsigned char
+ * @param *p pointer to ring buffer
+ * @returns none
+ */
+void NextCommand(unsigned char c, struct RingBuffer *p){
+   // remove all char till end identifier is found
+   while(NotEmpty(p) && p->Buffer[p->head] != c)
+   {  NextHead(p);            
+      p->qty--;                 
+   }
+
+   // remove end identifier
+   if(NotEmpty(p)&& p->Buffer[p->head] == c)               
+   {  NextHead(p);             
+      p->qty--;                 
+   }
+}
+
+/** @brief View ring buffer content.
+ * Print ring buffer content
+ * @param *p pointer to ring buffer
+ * @returns none
+ */
+void ViewRingBuffer(struct RingBuffer *p){
+   int i,j;
+
+   printf("\nRingBuffer Qty: %d \nContent: ",p->qty);
+
+   for(j=0,i=p->head;j<p->qty;j++){
+      printf("%c",p->Buffer[i]); 
+      if(i++>DimRingBuffer)i=0; 
+   }
+   printf("\n");
+}
+
+/** @brief Extract a word from ring buffer.
+ * The extracted word is put in the array pointed by word
+ * @param p pointer to a ring buffer 
+ * @param word pointer to array of char
+ * @returns true if a word is extracted otherwise returns false
+ */ 
+bool ExtractWord(struct RingBuffer *p, char * word){   
+   unsigned char c;
+   int i,j;
+   j=0;
+
+   if(NotEmpty(p)){
+        for(i=0;i<WordMaxSize-1;i++){
+          // extract a char from Rx ring buffer
+          c=Extract(p);
+    
+          // remove leading blanks
+          if(c==' ' && j==0)continue;
+    
+          // end of word or end of command line
+          if(c==' ' || c==nl)break;
+    
+          // build the Word
+          word[j++]=c;
+       }
+       // 0 string termination
+       word[j]=0;
+       if(j>0)return true;
+    }
+    return false;
+}
+
+/** @brief Extract an unsigned int from ring buffer.
+ * Convert a word from buffer into an integer between min and max values
+ * Value converted should be between min and max values.
+ * Value should be decimal or hexadecimal (beginning by 0x or 0X)
+ * @param p pointer to ring buffer
+ * @param result pointer to unsigned int
+ * @param min minimum limit
+ * @param max maximum limit
+ * @returns true if value is converted beetween limits, including limits.
+ */
+bool ExtractUInteger(struct RingBuffer *p, unsigned int *result, unsigned int min, unsigned int max){
+   unsigned int i ;
+   char word[WordMaxSize-1];
+
+   if(ExtractWord(p,word)){       // Extract string value
+      if(word[0]=='0' && (word[1]=='x' || word[1]=='X')) {
+         sscanf(word,"%x",&i);  // convert hexadecimal input
+      }
+      else
+         sscanf(word,"%d",&i);  // convert decimal input
+
+      if(i>=min && i<=max){
+         *result = i;
+         return true;
+      }
+   }
+   *result = 0;
+   return false;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmRingBuffer.h	Sat Feb 12 16:41:07 2011 +0000
@@ -0,0 +1,36 @@
+/*************************************************************************
+ * @file     jmRingBuffer.h
+ * @brief    Command Line Rx Ring Buffer
+ *                  
+ * @date  Feb12, 2011
+*/
+
+#ifndef jmRingBufferDef
+ #define jmRingBufferDef 1 
+ 
+ #define nl 10 // new line
+ #define WordMaxSize 21
+ #define DimRingBuffer  41    
+     
+
+ // Ring Buffer data structure
+ extern  struct RingBuffer                 
+  {  unsigned char  Buffer[DimRingBuffer];      
+     unsigned char  head;               
+     unsigned char  tail;                 
+     unsigned char  qty;   
+  }Line, *pLine;
+#endif
+
+// Prototypes
+bool Full(struct RingBuffer *p);
+void Insert(unsigned char c, struct RingBuffer *p);
+bool NotEmpty(struct RingBuffer *p);
+unsigned char Extract(struct RingBuffer *p);      
+void FlushRingBuffer(struct RingBuffer *p); 
+void DelChar(struct RingBuffer *p);
+void InitCommandLineRingBuffer(void);
+void NextCommand(unsigned char c, struct RingBuffer *p);
+void ViewRingBuffer(struct RingBuffer *p);
+bool ExtractWord(struct RingBuffer *p, char *param);
+bool ExtractUInteger(struct RingBuffer *p, unsigned int *result, unsigned int min, unsigned int max);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Feb 12 16:41:07 2011 +0000
@@ -0,0 +1,76 @@
+/*************************************************************************
+ * @file         main.cpp
+ *                  
+ * @version      1.0
+ * @date         Feb 12, 2011
+*/
+
+#include "mbed.h"
+
+// Basic includes
+#include "jmInterpreter.h"
+#include "jmRingBuffer.h"
+#include "jmCommands.h"
+#include "jmMessages.h"
+#include "LPC17xx.h"
+
+LPC_GPIO_TypeDef *jmGPIO[5] ={LPC_GPIO0,LPC_GPIO1,LPC_GPIO2,LPC_GPIO3,LPC_GPIO4};
+
+// CLIG-INCLUDE
+#include "jmPulse.h"
+
+
+// Initializations
+void Inits(){
+   InitCommandLineRingBuffer();
+   InitMessages();
+   cli_version();
+
+   // CLIG-INIT
+   PulseInit();
+
+}
+
+// EggTimer tickers for modules
+void eggTimers(){
+   int i;
+   // CLIG-TIMER
+   // Module jmPulse
+   for(i=0;i<pulseQty;i++)if(sPulse[i].eggTimer>0)sPulse[i].eggTimer--;
+
+}
+
+int main() {
+   unsigned char c;
+   Serial pc(USBTX, USBRX);          // communication medium
+   pc.baud(115200);                  // 115200 bauds, 8bits, 1 stop, no control flow
+   Ticker tick;                      // enable system ticks
+   tick.attach_us(&eggTimers,1000);  // enable and select granularity for egg timers
+   Inits();                          // initialization
+
+   while(true){
+     if( pc.readable()){             // something to read ?
+        c= pc.getc();                // read one char   
+
+        if(Echo) printf("%c",c);     // echo it ?
+
+        switch(c){                   // process it
+
+          case  8 : DelChar(pLine);  // remove last one
+                    break;
+          case 10 : Insert(c,pLine); // end of line
+                         Interpret();// process line 
+                    break;
+          default : Insert(c,pLine); // insert char in command line buffer
+        }
+     } // if
+
+     // CLIG-SM
+     PulseSM();
+
+
+   }// while
+}// main
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.h	Sat Feb 12 16:41:07 2011 +0000
@@ -0,0 +1,18 @@
+/*************************************************************************
+ * @file       main.h
+ * @version    1.0
+ * @date       Feb 12, 2011
+ */
+
+#include "LPC17xx.h"
+
+// registers
+extern LPC_GPIO_TypeDef *jmGPIO[5];
+
+// Prototypes
+void Inits(void);
+
+// CLIG-CMD
+/*
+init Inits();
+*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Feb 12 16:41:07 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/63bcd7ba4912