Insight-Pro™

Ask Us: support@ee101.com
Contact Us: support@ee101.com


EE101 Insight-Pro™ Users Manual

This document details the operation of the EE101 Insight-Pro™.

 



System Overview




An EE101 Insight-Pro™ is a tool for debugging todays embedded firmware systems. It gives you clear, concise insight into your designs operation so you can find and fix bugs quickly.  It captures and displays Logic Analyzer digital data, Oscilloscope analog data, I2C, SPI and UART decoded data and the new EE101 interface.  The EE101 Insight-Pro™ uses a simple 1-wire (UART) or 2-wire (GPIO) interface to your firmware using simple "printf" like calls.  This gives you access to data that is not contained on an external bus and shows you the internal information that only your embedded firmware knows.  It also streams data to disk allowing captures that can outlast you and ensure your elusive bug is captured.

The EE101 Insight-Pro™ pod is a box that attaches to your computer using a USB cable.  It also attaches to your circuit under test using the provided test leads and clips.  Your microprocessor then sends debug information to be displayed using the EE101 Insight-Pro™ Software.

 

The EE101 Insight-Pro™ can capture Logic Analyzer digital inputs, Oscilloscope analog inputs, I2C, SPI, UART Decoded data and the new EE101 Insight-Pro™ Bus. 



The EE101 Bus




There are 2 types of data captured over the EE101 bus: EE101 Text and EE101 Value (as well as the standard logic and analog inputs)

EE101 Text is character strings and are identical to traditional "printf" output.  They are graphed over time as well as listed vertically.

Each debug text output is created by a simple source code line such as:

or

EE101 Value is value data that is then graphed versus time for a visual representation of the data.

Each data point on the waveform is created by a simple source code line such as:

The label on the left of each waveline can also be set from your firmware by calling the EE101TextLabel and EE101ValueLabel functions.  These functions send the label every 256 times this routine is called so that it does not use bandwidth but is updated periodically on the display.

 



Choose 1-Wire (UART) or 2-Wire (GPIO) Mode




The EE101 Bus can be a 1-Wire or 2-Wire bus. Depending on your design and available resources, you can choose either interface.

Below is a summary of the two available modes. 

  1-Wire UART Mode 2-Wire GPIO Mode
Number of Processor Pins Used 1 2
Requires a UART on your processor  
Requires GPIO pins (only output used)  
Maximum bit rate 3MBaud (Auto baud detection) 10MHz clock
Protocol Async Serial N, 8, 1 Sync clock and data
EE101 connections Pin 0 for Device A
Pin 2 for Device B
Pins 0,1 for Device A
Pins 2,3 for Device B


Typical Applications




The EE101 Insight-Pro™ makes it a One Source Line Change and One Button Press to automatically view:

  • Accelerometer Data read from the I2C or SPI Bus graphed over time

  • Temperature Data measured over the entire weekend

  • Battery Voltage during extended operation

  • RSSI Values for each received packet graphed over time

  • Transmit Channel Frequency while frequency hopping

  • System State, memory level, FIFO depth or bit error counts over time

... and ANY other firmware knowledge such as value, result, informative message, error condition, sensor data, link status, button press, etc.



Installing the Software




To install the EE101 Insight-Pro™ software on your computer you must download the installation package from below.

The current software version is 3.3.

Windows download - On Windows Vista and 7 you can also install drivers from the executable directory after installation.  Win 8 and later do not require drivers.

MAC OS X download - OS X does not require drivers.

Linux download is planned for a future version.



Connecting the Hardware




To connect the EE101 Insight-Pro™ to your computer, use the included USB A to micro-B cable and plug it into any available USB port.  Your computer will find and install the appropriate driver (the CDC USB Com Port Driver).  On earlier Windows versions you will need to update the driver using the one included in the Drivers directory of the installation.  If your circuit is also attached to the same computer over USB, make sure that it is on a different USB Hub.

Now connect the EE101 Insight-Pro™ to your target device.  Below are the pinouts of the EE101 Insight-Pro™ pod.

 

  • GND - You MUST connect this signal to the ground of your circuit.  This provides the reference 0 level for the entire device.
  • Device A inputs are shown in Blue and Device B are shown in Yellow.
  • EE101 device inputs - Each device (A or B) uses 1 (UART) or 2 (GPIO) signals for communication.  In 1-wire mode connect to channel 0 for device A and 2 for device B.  In 2-wire mode, the two signals for each device are automatically determined and swapped so you do not need to determine which is which.
  • I2C inputs - Clock (SCL) and Data (SDA) 
  • SPI inputs - Select (SS#), Clock (SCK), Output (MOSI) and Input (MISO).  Both data lines are actually inputs to the EE101 device. 
  • UART - 1 and 2 channel.  You can use one or both at a time for each device.
  • Channels not used by Device A or Device B (set to Logic) become General Purpose Logic Analyzer Inputs
  • Analog In 1 and 2 - Analog Input channels
  • Analog Out 1 - Analog Output Channel (AWG)

The included test leads have matching colors for most of the the label colors.  These colors are important as they match the colors on the software display.  To connect the lead to the EE101 Insight-Pro™, plug the square end of the wire onto the pin inside the EE101 through the slot on the top.  Then use the clip to connect to your circuit IC's, headers or discrete components you want to measure.  If you have the luxury of designing a board, you can put a 3 pin header for easy access to the GND and two EE101 signals.



Specifications




The following are the technical specifications of the EE101 Insight-Pro™ System.

Number of EE101 Debug Ports: 2 (Device A and Device B)
EE101 Debug Pins Per Port: 1 (UART) or 2 (GPIO - one clock and one data)
EE101 Debug Port Input Range: -0.5 to 7.0V
EE101 Debug Port Logic Threshold: Variable between 0V and 4V with 0.1V hysteresis.
EE101 Debug Pins Drive current required: 1mA
EE101 Debug Lines Input Impedance: >10K ohm || 10pF
EE101 Debug Port 1-Wire Mode: Async N, 8, 1. Autobaud detection up to 3MBaud
EE101 Debug Port 2-Wire Maximum Clock Frequency: 10MHz
EE101 Debug Port Maximum Text Debug Message Length: 250 characters
EE101 Debug Port Number Of Text Channels: 8 per device
EE101 Debug Port Number Of Data Channels: 8 per device
EE101 Debug Port Data Channel Output Values: --2,147,483,648 to 2,147,483,647
EE101 Debug Timestamp Resolution: 1us

I2C Maximum Clock Rate: 10MHz
I2C Maximum Ports: 2
I2C Signals Required: SCL and SDA
I2C Input Range: -0.5 to 7.0V
I2C Logic Threshold: Variable between 0V and 4V with 0.1V hysteresis.
I2C Input Impedance: >10K || 10pF
I2C Maximum Data Transfer Size Decoded per Transaction: 30 bytes

SPI Maximum Clock Rate: 10MHz
SPI Maximum Ports: 2
SPI Signals Required: SS, SCK and at least one data line
SPI Input Range: -0.5 to 7.0V
SPI Logic Threshold: Variable between 0V and 4V with 0.1V hysteresis.
SPI Input Impedance: >10K || 10pF
SPI Maximum Data Transfer Size Decoded per Transaction: 250 bytes
SPI Polarity Settings: SCK Sample Edge Falling or Rising, SS Active Low
SPI Number Of Data Channels: 2, MOSI and MISO

UART Maximum Baud Rate: 3Mbaud
UART Baud Rate Selection Method: Autobaud determines baud rate Automatically
UART Settings: 8 Data Bits, No Parity
UART Input Range: -0.5 to 7.0V
UART Logic Threshold: Variable between 0V and 4V with 0.1V hysteresis.
UART Input Impedance: >10K || 10pF
UART Maximum Transfer Size per Transaction: 250 bytes
UART Number Of Data Channels: 2, Tx and Rx

Logic Analyzer Inputs: Up to 8.  2 inputs are used by each of the EE101 Debug Ports.
Logic Analyzer Input Range: -0.5 to 7.0V
Logic Analyzer Threshold: Variable between 0V and 4V with 0.1V hysteresis.
Logic Analyzer Input Impedance: >10K || 10pF
Logic Analyzer Sample Rate: Up to 90k samples per second.  Samples are taken when no other EE101 Debug Data is available.

Analog Inputs: 2
Analog Input Range: 0V to 5V measurable. -0.5 to 7.0V tolerant.
Analog Measurement Resolution: 1.22mV (12 bit ADC over 5V)
Analog Sample Rate: Up to 90k samples per second.  Samples are taken when no other EE101 Debug Data is available.

Size: 2.75" x 1.5" x 0.6"
Package: Custom Designed ABS plastic
Overcurrent Protection: Resettable Polyfuse
Connection to computer: USB Full Speed A to micro-B cable (included)
Test Leads and Clips: Ten 9" leads with Minigrabber text clips (included)

Sample Storage Location During Capture:  Disk Drive
Maximum Number of Samples: Unlimited up to the size of your disk drive storage limit
Maximum Data Transfer Rate: 500,000 bytes per second (All channels captured)

Supported Operating Systems:  Windows Vista, 7, 8.x, 10, 32 and 64 bit, OS X.  Linux support is planned future release.



Software Operation




The EE101 Insight-Pro™ Software runs and displays the captured data from your embedded system.  The software comes up in the following state, ready to capture and visualize your data.

Capture

To capture data from your circuit, make sure the EE101 Insight-Pro™ is connected via USB and press the Capture button.  You will see the data being captured scrolling into view. 

Prior to capture you can select what data to capture.  Select the type of data you want Device A or Device B to capture.

Available Device Capture Types for each device A and B are:

  • Logic Inputs
  • EE101 Data (1-Wire Mode)
  • EE101 Data (2-Wire Mode)
  • I2C
  • SPI Rising or Falling Edge Clock
  • UART

Check the Analog Checkbox to measure the 2 analog input channels when the pod is not busy reading EE101 data.  Check the Logic Checkbox to capture the digital level of the Logic Analyzer signals when the pod is not busy reading EE101 data.  Below is a trace capturing just the 2 analog inputs.

Changing the type of bus for Device A and B may require a short delay while the EE101 downloads a new configuration to the device.   The download occurs when the Capture Button is pressed. 

The Logic Voltage Threshold level can also be chosen by selecting the logic family you are using (1V to 5V) in the bottom right.  This level affects the Logic Analyzer Inputs as well as the EE101 Device Inputs.

Once the Capture is in progress you can scroll and view it as it is being captured.  Be aware that all of the data is continuously being stored to your disk (in your Users/AppData or Users/Library directory).  The total number of captured bytes is displayed at the bottom during capture.

If you have an older, slow computer or a slow disk drive, you can uncheck the Live Checkbox to capture the data without the real-time view active.  This will allow capture without dropping data.

Only signals and channels that are used are shown on the display automatically.  So if your firmware only outputs data on one channel, only that channel will be shown.  This eliminates any setup of the wavelines displayed.  Selecting Analog will automatically show the two Analog Inputs.  Selecting Logic will automatically show the Logic Analyzer Inputs.

When you have gathered enough data to your liking, you press the same button (now labeled Stop) to terminate the capture. 

Pressing Capture again will erase the previous capture and start a new capture.

Navigating the Trace

Once you have a trace captured you can navigate around the trace a number of ways. 

To view the entire trace in a single window, press the Zoom All button.  This will scale the data so it all fits from the first sample to the last on the timeline.

Press the Zoom Cursors button to zoom to the data between the two cursors.

To zoom in or out on the data, hover over the waveforms and use the mouse scroll wheel or scroll up and down with two fingers on the trackpad. 

To pan the waveforms to the left or right, click and drag the waveforms with the mouse or scroll sideways with two fingers on the trackpad.

It is much quicker to navigate by zooming out and back in than to pan long distances.

You can reorder the wavelines by clicking and dragging them by the left tab.  You can rename the wavelines by selecting and entering new text.

Navigating the EE101 Text and Values List

All of the EE101 Text or Value output is displayed as well in a vertical window on the right side of the screen.  Data that is displayed starts at the current mouse position.  The vertical scrollbar can be changed to widen the list to view all of your data.  The Device A output is aligned on the left side, while the Device B output is aligned on the right.  They are listed in chronological order starting at the left of the waveform data.

To scroll the EE101 Text and Values output window, first click on the waveforms to lock the current cursor position, then use the scroll wheel to scroll up and down.  You can also use the arrow up/down and the Page Up/Down buttons on the keyboard.

This window can be moved and undocked by clicking and dragging the top of the window.  To put it back just move it back to the original position.

Measurements

Measurements are done using two cursors that you can place anywhere in the trace buffer.  You place the cursors by hovering over the timeline bar at the top of the window and pressing either the Left (for X1) or Right (for X2) mouse buttons.  You can also place the cursors by double clicking on the waveforms, Left double-click for X1 and Right double-click for X2.

The resulting time delta and equivalent frequency is then displayed between the cursors.

Each Analog line (either Analog input or EE101 Value waveform) can also have a measurement marker that shows the value at that sample.  Simply double-click on the waveform to place the cursor.

 

Filter

In the EE101 Text or Values List you can filter the results based on the channel.  To turn on or off that channel click the color boxes at the top of the text window.

Search

To search the EE101 Text output for a certain value, type your search string in the edit box at the bottom and press Enter or click Search.  It will search forward in time from the left side of the waveform screen and find the next occurrence of the search string.  If it finds it it will place it at the left side of the screen with the text line at the top of the text window.

The search obeys the filters set in the text window for its search algorithm.

If you want to search the entire trace, press Zoom All first.

The text search is a partial match algorithm.  If the entered text matches anywhere in the debug string it will declare it a match. 

File Open and Save

Once you have a trace that contains valuable information, you can save that to a file by pressing the Save Button at the bottom.

You can then Open that file by pressing the Open Button at the bottom.

File Export

The EE101 Text and Values output that is between the cursors can also be Exported to a CSV (comma delimited text) file by pressing the Export Button.  The Export saves all of the Text and Values channel output that is between the two cursors in order to save disk space.

CSV files can be easily opened in Excel or Numbers for sorting, filtering or further analysis.

Hot Keys

The following Hot Keys can be used:

SPACE Start and Stop a capture
I Zoom In
O Zoom Out
1 Place Cursor X1 at the current mouse position
2 Place Cursor X2 at the current mouse position
Left Arrow Pan Left
Right Arrow Pan Right
Up Arrow One Line Up in the right list window
Down Arrow One Line Down in the right list window
Page Up One Page Up in the right list window
Page Down One Page Down in the right list window
C Change the Color Scheme

 



Firmware Routines and Control Commands




The EE101 Insight-Pro™ captures the debug data from your firmware when you call the following routines.

Routines

EE101Text ( unsigned char channel, unsigned char * string );

This routine outputs the given text on the Text Channel specified.

channel = 0 thru 7

string is the \0 terminated string to output.  These can also be special Control Commands to control various features of the host capture software.

Example: EE101Text ( 2, "It Happened!");      // Displays "It Happened!" on channel 2 at the current time

 

EE101printf ( unsigned char channel, unsigned char * printfformatstring, ... );

This routine outputs the printf-like text on the Text Channel specified. 

channel = 0 thru 7

printfformatstring is the \0 terminated string to use as in the standard C printf routine

... are the parameters that are used by the format string

Example: EE101printf ( 4, "%d: %d", index, data);      // Displays "23: 15432" on channel 4 if index = 23 and data = 15432

 

EE101Value ( unsigned char channel, signed long value );

This routine outputs the given value on the Value Channel specified to be graphed over time.

channel = 0 thru 7

value is the value to output on the graph.  value is a signed long and can therefore range from –2,147,483,648 to 2,147,483,647

Example: EE101Value ( 2,  ADCValue );      // Adds a graphed point at the value 123 on channel 2 at the current time if ADCValue = 123

 

EE101TextLabel( unsigned char channel, unsigned char * string );

This routine sets the label for the Text Channel specified.

channel = 0 thru 7

string is the \0 terminated string that becomes the new channel label.

Example: EE101TextLabel( 2, "State");      // Changes the Text Channel 2 label to "State"

 

EE101ValueLabel( unsigned char channel, unsigned char * string );

This routine sets the label for the Value Channel specified.

channel = 0 thru 7

string is the \0 terminated string that becomes the new channel label.

Example: EE101ValueLabel( 2, "X Axis");      // Changes the Value Channel 2 label to "X Axis"

 

Control Commands

These commands are sent using the string parameter in the call to EE101Text().

Play Beep:   EE101Text( channel, "?cmd=beep");

This command generates an audible BEEP on the computer when it is sent.

channel = 0 thru 7,  ignored

Example: EE101Text( 2, "?cmd=beep");      // plays a beep on the computer

 

Send Email:   EE101Text( channel, "?cmd=email&to=toemail&msg=message");

This command sends an email to the email address specified.

channel = 0 thru 7,  ignored

toemail = the email address to send the email message to

message = the message included in the email

Example: EE101Text( 2, "?cmd=email&to=support@ee101.com&msg=The Test Has Passed!");      // sends an email to support@usbee.com

 

Change Color:   EE101Text( channel, "?cmd=color&fg=foregoundcolor&bg=backgroundcolor&tc=textcolor&all=1");

This command changes the color of the channel specified.  All parameters after "color" are optional.

channel = 0 thru 7,  which channel to change the color of on the display

foregroundcolor = the color of the waveform or text boxes of this channel.  Allowed values are here.

backgroundcolor = the color of the background of this channel.  Allowed values are here.

textcolor = the color of the text of this channel.  Allowed values are here.

all=1 = the colors of all of the channels are set

Examples:

EE101Text( 2, "?cmd=color&fg=red");        // changes channel 2 waveforms or text boxes to red

EE101Text( 2, "?cmd=color&bg=red");       // changes channel 2 background to red

EE101Text( 2, "?cmd=color&tc=yellow");    // changes channel 2 text to yellow

EE101Text( 2, "?cmd=color&fg=red&bg=blue&tc=yellow");      // changes channel 2 to red waveforms on blue background with yellow text

EE101Text( 2, "?cmd=color&bg=red&all=1");       // changes ALL channel backgrounds to red

 

Stop Capture:   EE101Text( channel, "?cmd=stop");

This command stops the capture in progress and displays the trace that has been stored to disk.

channel = 0 thru 7,  ignored

Example: EE101Text( 2, "?cmd=stop");      // stops the capture

 

Restart Capture:   EE101Text( channel, "?cmd=restart");

This command stops and restarts the capture.  This discards the trace that was previously stored to disk.

channel = 0 thru 7,  ignored

Example: EE101Text( 2, "?cmd=restart");      // stops and restarts the capture, discarding the previous trace.

 



Embedded Firmware




A key component to the EE101 Insight-Pro™ system is the firmware that runs on your embedded microcontroller.  The microcontroller sends debug information out a pair of general purpose I/O lines (GPIO) whenever you want to see a state, location or variable of your code in real-time operation.  To send out this data you call one of 3 API routines that we provide below. 

The firmware source code below is embedded in your firmware project and provides simple API routines that can be called any time your firmware wants to output information.  Similar to printf(...), you can quickly add single lines of code to output a new set of information at exactly the correct time.

To use this firmware source code, copy the source into your project (either inline or in a new source file).  Then modify the contents between the MAKE YOUR CHANGES comments.  These modifications define how to set the output level of the two GPIO signals as well as other platform specific settings.  See the source code comments below for more details.

Program and Data Usage

The following source code uses the following resources (ROM and RAM) for these various processors and compilers.

             (ROM)    (RAM)
 Processor   Program  Data   Notes
 ----------  -------  ----   -------------------------------------
 Arduino       2132    268   With VARIABLE_ARGUMENT_SUPPORT
 Arduino        554     14   Without VARIABLE_ARGUMENT_SUPPORT
 PSoC 5LP      3072    368   With VARIABLE_ARGUMENT_SUPPORT
 PSoC 5LP       512     19   Without VARIABLE_ARGUMENT_SUPPORT
 STM EFM32     3152    315   With VARIABLE_ARGUMENT_SUPPORT
 STM EFM32      920      9   Without VARIABLE_ARGUMENT_SUPPORT
 PIC XC32     15684    628   With VARIABLE_ARGUMENT_SUPPORT
 PIC XC32      2096     16   Without VARIABLE_ARGUMENT_SUPPORT

Source Code

The following is the source code to include in your firmware project.  To save the files to your PC, right click on the link below and choose Save As.  Then add them to your firmware project.

ee101.c - C source file that includes the code below

ee101.h - C Header file that declares the routines for use in your files

 

/* =============================================================
EE101 Insight-Pro™
Firmware Library
Provided by EE101.com

This file is to be included in your embedded firmware project to
send debug information to the EE101 Embedded Insight-Pro™.

It can operate in a 1-wire (UART) mode, or a 2-wire (GPIO) mode.

In 1-wire mode, you will use your onboard UART set to N,8,1 at any
baud rate up to 3MBaud.

In 2-wire mode, it uses 2 signals (a clock and data line).
The EE101 Insight-Pro™ autoselects the correct polarity. The 2
signals are General Purpose I/O pins (GPIO) which are
available on most microprocessors. Only output is required.
The output high voltage level can be anywhere from 1V to 5V.

You must modify this file in a few places to specify how to set
and clear the GPIO and how to enable/disable interrupts (if you
need to).

ONLY MODIFY THE CODE BELOW BETWEEN THE FLAGS.

If you have any questions or issues, please email us at
support@ee101.com.
===============================================================*/

//************** MAKE YOUR CHANGES BELOW ONLY *************************
// These defines are an example using the Cypress PSoC5LP Microcontroller

#define EE101_DEBUG_ON // Comment this line out to turn off the EE101 Debug outputs

// Change #1 - Add any includes that you need for the below defines
#include "project.h"

// CHANGE #2 - How to disable Interrupts. Only needed if you have debug
// output in interrupts. Make sure if you do disable interrupts that it
// is done in a way that does not lose the interrupts (keeps the interrupt
// flags active) so that when the interrupt is re-enabled the interrupt will
// be serviced.
#define EE101IntDisable ; // No interrupt debug
#define EE101IntEnable ;
//#define EE101IntDisable CyGlobalIntDisable; // Interrupt Debugging
//#define EE101IntEnable CyGlobalIntEnable;

// CHANGE #3 - Choose if you're using 2 wire (GPIO) or 1 wire (UART) EE101 interface
#define EE101_ONE_WIRE // Uncomment this line if you are using a single signal UART interface for EE101 debug data
//#define EE101_TWO_WIRE // Uncomment this if you are using 2 wire sync interface for EE101 debug data

// CHANGE #4 - FOR 2-wire EE101 Mode: Defines that set the GPIO pins to High and Low levels and Toggles
// These should be as fast as possible, but not faster than 50ns (20MHz)
// These two GPIO are a Clock and a Data line. They must be setup as outputs
// elsewhere in your firmware during system initialization.
// The Data line toggle must invert the current state of the GPIO line
#define EE101ClockLow EE101_CLOCK_DR &= ~(1 << EE101_CLOCK_SHIFT); // PSoC Version
#define EE101ClockHigh EE101_CLOCK_DR |= (1 << EE101_CLOCK_SHIFT); // PSoC Version
#define EE101DataLow EE101_DATA_DR &= ~(1 << EE101_DATA_SHIFT); // PSoC Version
#define EE101DataHigh EE101_DATA_DR |= (1 << EE101_DATA_SHIFT); // PSoC Version
#define EE101DataToggle EE101_DATA_DR ^= (1 << EE101_DATA_SHIFT); // PSoC Version
//#define EE101ClockLow digitalWrite(10, LOW); // Arduino Version
//#define EE101ClockHigh digitalWrite(10, HIGH); // Arduino Version
//#define EE101DataLow digitalWrite(11, LOW); // Arduino Version
//#define EE101DataHigh digitalWrite(11, HIGH); // Arduino Version
//#define EE101DataToggle digitalWrite(11, !digitalRead(11)); // Arduino Version
//#define EE101ClockLow GPIO_PinOutClear(EE101_CLOCK_PORT, EE101_CLOCK_PIN) // STM EFM32 Version
//#define EE101ClockHigh GPIO_PinOutSet(EE101_CLOCK_PORT, EE101_CLOCK_PIN) // STM EFM32 Version
//#define EE101DataLow GPIO_PinOutClear(EE101_DATA_PORT, EE101_DATA_PIN) // STM EFM32 Version
//#define EE101DataHigh GPIO_PinOutSet(EE101_DATA_PORT, EE101_DATA_PIN) // STM EFM32 Version
//#define EE101DataToggle GPIO_PinOutToggle(EE101_DATA_PORT, EE101_DATA_PIN) // STM EFM32 Version
//#define EE101ClockLow PORTCbits.RC12 = 0; // PIC X32 Version
//#define EE101ClockHigh PORTCbits.RC12 = 1; // PIC X32 Version
//#define EE101DataLow PORTCbits.RC13 = 0; // PIC X32 Version
//#define EE101DataHigh PORTCbits.RC13 = 1; // PIC X32 Version
//#define EE101DataToggle PORTCbits.RC13 = !PORTCbits.RC13; // PIC X32 Version

// CHANGE #5 - FOR 1-wire EE101 Mode: Defines your routine name to send a single byte to the UART
// The UART must be configured and enabled elsewhere in your firmware.
#define EE101UartTx(x) UART_PutChar(x)

// CHANGE #6 - Enable/Disable Variable Argument support for SendEE101printf
#define VARIABLE_ARGUMENT_SUPPORT // Comment out this line if your compiler does not
// have va_list, va_start, vsprintf, and va_end support
// as defined in stdarg.h

#define MAX_STRING_LENGTH 250 // How much RAM to use for the SendEE101printf buffer
// This must not be greater than 250
// This defines the maximum length of any debug text message

#ifdef VARIABLE_ARGUMENT_SUPPORT // Includes required by the va_list, va_start, vsprintf, and va_end
#include <stdio.h> // vsprintf
#include <stdarg.h> // va_list, va_start, and va_end
#endif

// CHANGE #7 - Type defines for your platform
// Copy these defines and function prototypes to your header files to define the API
#define euint8 unsigned char // unsigned 8 bit value
#define eint8 signed char // signed 8 bit value
#define eint32 signed long // signed 32 bit value
#define echar char // bytes within a string
void EE101Value( euint8 channel, eint32 value ); // Output a Value for this channel
void EE101Text( euint8 channel, echar *string ); // Output Text for this channel
void EE101ValueLabel( euint8 channel, echar *string ); // Set the label for this Value Channel (sent every 256 times)
void EE101TextLabel( euint8 channel, echar *string ); // Set the label for this Text Channel (sent every 256 times)
#ifdef VARIABLE_ARGUMENT_SUPPORT
void EE101printf( euint8 channel, echar *format, ... ); // printf-like function with variable argument list
#endif

//************** MAKE YOUR CHANGES ABOVE ONLY *************************

#define EE101_SYNC 0x50
#define EE101_VALUE_TYPE 0x80
#define EE101_TEXT_TYPE 0x00
#define EE101_LABEL 0x08

#ifdef EE101_ONE_WIRE // This is a 1-wire interface

void SendEE101Byte( euint8 value )
{
EE101UartTx( value );
}

void EE101Value( euint8 channel, eint32 value )
{
#ifdef EE101_DEBUG_ON
EE101IntDisable;

SendEE101Byte( (channel & 0x07) | EE101_VALUE_TYPE | EE101_SYNC);
SendEE101Byte( value >> 24);
SendEE101Byte( value >> 16);
SendEE101Byte( value >> 8);
SendEE101Byte( value );

EE101IntEnable;
#endif
};

void EE101Text( euint8 channel, echar *string )
{
#ifdef EE101_DEBUG_ON
euint8 bytes = 1;

EE101IntDisable;

SendEE101Byte( (channel&0x07) | EE101_SYNC | EE101_TEXT_TYPE);
while(*string)
{
if (bytes++ > MAX_STRING_LENGTH)
break;
SendEE101Byte( *string++ );
}
SendEE101Byte( 0 );

EE101IntEnable;
#endif
};

void EE101TextLabel( euint8 channel, echar *string )
{
#ifdef EE101_DEBUG_ON
static euint8 timeout[8] = {0,0,0,0,0,0,0,0};
euint8 bytes = 1;

channel &= 0x07;
timeout[channel]++;
if ( timeout[channel] != 1 ) return;
EE101IntDisable;
SendEE101Byte( channel | EE101_SYNC | EE101_TEXT_TYPE | EE101_LABEL);
while(*string)
{
if (bytes++ > MAX_STRING_LENGTH)
break;
SendEE101Byte( *string++ );
}
SendEE101Byte( 0 );
EE101IntEnable;
#endif
};

void EE101ValueLabel( euint8 channel, echar *string )
{
#ifdef EE101_DEBUG_ON
static euint8 timeout[8] = {0,0,0,0,0,0,0,0};
euint8 bytes = 1;

channel &= 0x07;
timeout[channel]++;
if ( timeout[channel] != 1 ) return;
EE101IntDisable;
SendEE101Byte( channel | EE101_SYNC | EE101_VALUE_TYPE | EE101_LABEL);
while(*string)
{
if (bytes++ > MAX_STRING_LENGTH)
break;
SendEE101Byte( *string++ );
}
SendEE101Byte( 0 );
EE101IntEnable;
#endif
};

#else // Otherwise it is a 2-wire interface
void SendEE101Byte( euint8 value )
{
if (value & 0x80) {EE101DataHigh;} else {EE101DataLow;} EE101ClockHigh; EE101ClockLow;
if (value & 0x40) {EE101DataHigh;} else {EE101DataLow;} EE101ClockHigh; EE101ClockLow;
if (value & 0x20) {EE101DataHigh;} else {EE101DataLow;} EE101ClockHigh; EE101ClockLow;
if (value & 0x10) {EE101DataHigh;} else {EE101DataLow;} EE101ClockHigh; EE101ClockLow;
if (value & 0x08) {EE101DataHigh;} else {EE101DataLow;} EE101ClockHigh; EE101ClockLow;
if (value & 0x04) {EE101DataHigh;} else {EE101DataLow;} EE101ClockHigh; EE101ClockLow;
if (value & 0x02) {EE101DataHigh;} else {EE101DataLow;} EE101ClockHigh; EE101ClockLow;
if (value & 0x01) {EE101DataHigh;} else {EE101DataLow;} EE101ClockHigh; EE101ClockLow;
}

void EE101Value( euint8 channel, eint32 value )
{
#ifdef EE101_DEBUG_ON
EE101IntDisable;
SendEE101Byte( (channel & 0x07) | EE101_VALUE_TYPE | EE101_SYNC);
if ((value > 32767L) || (value < -32768L))
{
SendEE101Byte( value >> 24);
SendEE101Byte( value >> 16);
}
if ((value > 127L) || (value < -128L))
SendEE101Byte( value >> 8);
SendEE101Byte( value );
EE101DataToggle;EE101DataToggle;
EE101IntEnable;
#endif
};

void EE101Text( euint8 channel, echar *string )
{
#ifdef EE101_DEBUG_ON
euint8 bytes = 1;

EE101IntDisable;
SendEE101Byte( (channel&0x07) | EE101_SYNC | EE101_TEXT_TYPE);
while(*string)
{
if (bytes++ > MAX_STRING_LENGTH)
break;
SendEE101Byte( *string++ );
}
EE101DataToggle;EE101DataToggle;
EE101IntEnable;
#endif
};

void EE101TextLabel( euint8 channel, echar *string )
{
#ifdef EE101_DEBUG_ON
static euint8 timeout[8] = {0,0,0,0,0,0,0,0};
euint8 bytes = 1;

channel &= 0x07;
timeout[channel]++;
if ( timeout[channel] != 1 ) return;
EE101IntDisable;
SendEE101Byte( channel | EE101_SYNC | EE101_TEXT_TYPE | EE101_LABEL);
while(*string)
{
if (bytes++ > MAX_STRING_LENGTH)
break;
SendEE101Byte( *string++ );
}
EE101DataToggle;EE101DataToggle;
EE101IntEnable;
#endif
};

void EE101ValueLabel( euint8 channel, echar *string )
{
#ifdef EE101_DEBUG_ON
static euint8 timeout[8] = {0,0,0,0,0,0,0,0};
euint8 bytes = 1;

channel &= 0x07;
timeout[channel]++;
if ( timeout[channel] != 1 ) return;
EE101IntDisable;
SendEE101Byte( channel | EE101_SYNC | EE101_VALUE_TYPE | EE101_LABEL);
while(*string)
{
if (bytes++ > MAX_STRING_LENGTH)
break;
SendEE101Byte( *string++ );
}
EE101DataToggle;EE101DataToggle;
EE101IntEnable;
#endif
};

#endif


#ifdef VARIABLE_ARGUMENT_SUPPORT
echar EE101str[MAX_STRING_LENGTH];
void EE101printf( euint8 channel, echar *format, ... )
{
#ifdef EE101_DEBUG_ON
va_list arglist;
va_start( arglist, format );
vsprintf( EE101str, format, arglist );
va_end( arglist );
EE101Text( channel, EE101str );
#endif
};
#endif