diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 000000000..a491beb33
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,12 @@
+# Set the default behavior, in case people don't have core.autocrlf set.
+* text=auto whitespace=trailing-space
+
+# Explicitly declare text files you want to always be normalized and converted
+# to native line endings on checkout.
+*.c text
+*.h text
+*.java text
+
+# Denote all files that are truly binary and should not be modified.
+*.png binary
+*.jpg binary
diff --git a/apps/webserver-nano/httpd-fs/makefsdata.ignore/ttt/index.shtml b/apps/webserver-nano/httpd-fs/makefsdata.ignore/ttt/index.shtml
index 3a23b43ed..f2891b8f1 100644
--- a/apps/webserver-nano/httpd-fs/makefsdata.ignore/ttt/index.shtml
+++ b/apps/webserver-nano/httpd-fs/makefsdata.ignore/ttt/index.shtml
@@ -1,3 +1,3 @@
-
-%! tictac
+
+%! tictac
\ No newline at end of file
diff --git a/apps/webserver-nano/httpd-fs/makefsdata.ignore/ttt/ttt.shtml b/apps/webserver-nano/httpd-fs/makefsdata.ignore/ttt/ttt.shtml
index 3a23b43ed..f2891b8f1 100644
--- a/apps/webserver-nano/httpd-fs/makefsdata.ignore/ttt/ttt.shtml
+++ b/apps/webserver-nano/httpd-fs/makefsdata.ignore/ttt/ttt.shtml
@@ -1,3 +1,3 @@
-
-%! tictac
+
+%! tictac
\ No newline at end of file
diff --git a/examples/ipv6/slip-radio/slip-radio-rf230.c b/examples/ipv6/slip-radio/slip-radio-rf230.c
index 1f254386d..67c3ecc33 100644
--- a/examples/ipv6/slip-radio/slip-radio-rf230.c
+++ b/examples/ipv6/slip-radio/slip-radio-rf230.c
@@ -1,72 +1,72 @@
-/*
- * Copyright (c) 2011, Swedish Institute of Computer Science
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the Institute nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * This file is part of the Contiki operating system.
- *
- * Sets up some commands for the RF230 radio.
- */
-
-#include "contiki.h"
-#include "cmd.h"
-
-#include "radio/rf230/radio.h"
-#include "radio/rf230bb/rf230bb.h"
-
-
-#define DEBUG 0
-#if DEBUG
-#include
-#define PRINTF(FORMAT,args...) printf_P(PSTR(FORMAT),##args)
-#define PRINTSHORT(FORMAT,args...) printf_P(PSTR(FORMAT),##args)
-#else
-#define PRINTF(...)
-#define PRINTSHORT(...)
-#endif
-
-int
-cmd_handler_rf230(const uint8_t *data, int len)
-{
- if(data[0] == '!') {
- if(data[1] == 'C') {
- PRINTF("CMD: Setting channel: %d\n", data[2]);
- rf230_set_channel(data[2]);
- return 1;
- }
- } else if(data[0] == '?') {
- if(data[1] == 'C') {
- uint8_t buf[4];
- PRINTF("CMD: Getting channel: %d\n", data[2]);
- buf[0] = '!';
- buf[1] = 'C';
- buf[2] = rf230_get_channel();
- cmd_send(buf, 3);
- return 1;
- }
- }
- return 0;
-}
+/*
+ * Copyright (c) 2011, Swedish Institute of Computer Science
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the Institute nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * This file is part of the Contiki operating system.
+ *
+ * Sets up some commands for the RF230 radio.
+ */
+
+#include "contiki.h"
+#include "cmd.h"
+
+#include "radio/rf230/radio.h"
+#include "radio/rf230bb/rf230bb.h"
+
+
+#define DEBUG 0
+#if DEBUG
+#include
+#define PRINTF(FORMAT,args...) printf_P(PSTR(FORMAT),##args)
+#define PRINTSHORT(FORMAT,args...) printf_P(PSTR(FORMAT),##args)
+#else
+#define PRINTF(...)
+#define PRINTSHORT(...)
+#endif
+
+int
+cmd_handler_rf230(const uint8_t *data, int len)
+{
+ if(data[0] == '!') {
+ if(data[1] == 'C') {
+ PRINTF("CMD: Setting channel: %d\n", data[2]);
+ rf230_set_channel(data[2]);
+ return 1;
+ }
+ } else if(data[0] == '?') {
+ if(data[1] == 'C') {
+ uint8_t buf[4];
+ PRINTF("CMD: Getting channel: %d\n", data[2]);
+ buf[0] = '!';
+ buf[1] = 'C';
+ buf[2] = rf230_get_channel();
+ cmd_send(buf, 3);
+ return 1;
+ }
+ }
+ return 0;
+}
diff --git a/examples/rssi-scanner/ViewRSSI.java b/examples/rssi-scanner/ViewRSSI.java
index 0b881ef7e..deb17dc8d 100644
--- a/examples/rssi-scanner/ViewRSSI.java
+++ b/examples/rssi-scanner/ViewRSSI.java
@@ -1,161 +1,161 @@
-/*
- * Copyright (c) 2007, Swedish Institute of Computer Science.
- * Copyright (c) 2010, University of Luebeck, Germany.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the Institute nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/**
- * \file
- * ViewRSSI java application
- * \author
- * Joakim Eriksson
- * Carlo Alberto Boano
- */
-
-import javax.swing.*;
-import java.awt.*;
-import java.io.*;
-
-public class ViewRSSI extends JPanel{
- // Constants
- public static int TOTAL = 86; // Number of channel of 1 MHz sampled
- public static int DECREASE_RSSI = 2; // How many dBm the grey RSSI falls each sample
- public static int RSSI_MAX_VALUE = 100; // Maximum value obtainable from RSSI readings of CC2420.
- public static int MARGIN_BOTTOM = 20; // Margin from the bottom
- public static int MARGIN_RIGHT = 75; // Margin from the right
- public static int MARGIN_TOP = 12; // Margin from the top
- public static int INTERFERED_CHANNEL = 24; // Interfered channel
-
- public InputStream inputstr;
- private int[] rssi = new int[TOTAL]; // Array of current Noise floor values (black line)
- private int[] rssiMax = new int[TOTAL]; // Array with past Noise floor values (grey line)
-
-
- public ViewRSSI() {
- }
-
- public void paint(Graphics g) {
- Graphics2D g2 = (Graphics2D) g;
- int h = getHeight();
- int w = getWidth();
- double factor = (h - (MARGIN_BOTTOM*1.0)) / RSSI_MAX_VALUE;
- double sSpacing = (w - MARGIN_RIGHT) / (TOTAL*1.0);
- int sWidth = (int) (sSpacing - 1);
- if (sWidth == 0) sWidth = 1;
-
- // Set white background in the plot
- g.setColor(Color.white);
- g.fillRect(0, 0, w, h);
-
- // Gradient example (ytics background)
- GradientPaint greytowhite = new GradientPaint(w-MARGIN_RIGHT,0,Color.WHITE,w, 0,Color.lightGray, false);
- g2.setPaint(greytowhite);
- g2.fillRect(w-MARGIN_RIGHT, 0, w, h);
-
- // Draw the light grey channels from 11 to 26
- double xpos = 10;
- for(int i=4;i rssiMax[i]) rssiMax[i] = rssi[i];
- else if (rssiMax[i] > 0) rssiMax[i] = rssiMax[i] - DECREASE_RSSI;
- }
- } catch (Exception e) {
- e.printStackTrace(); /* Report error, but do not fail... */
- }
- repaint();
- }
- }
- }
-
-
- public static void main(String[] args) throws IOException {
- JFrame win = new JFrame("RSSI Viewer");
- ViewRSSI panel;
- win.setBounds(10, 10, 590, 590);
- win.getContentPane().add(panel = new ViewRSSI());
- win.setVisible(true);
- win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- panel.handleInput();
- }
-
-}
+/*
+ * Copyright (c) 2007, Swedish Institute of Computer Science.
+ * Copyright (c) 2010, University of Luebeck, Germany.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the Institute nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/**
+ * \file
+ * ViewRSSI java application
+ * \author
+ * Joakim Eriksson
+ * Carlo Alberto Boano
+ */
+
+import javax.swing.*;
+import java.awt.*;
+import java.io.*;
+
+public class ViewRSSI extends JPanel{
+ // Constants
+ public static int TOTAL = 86; // Number of channel of 1 MHz sampled
+ public static int DECREASE_RSSI = 2; // How many dBm the grey RSSI falls each sample
+ public static int RSSI_MAX_VALUE = 100; // Maximum value obtainable from RSSI readings of CC2420.
+ public static int MARGIN_BOTTOM = 20; // Margin from the bottom
+ public static int MARGIN_RIGHT = 75; // Margin from the right
+ public static int MARGIN_TOP = 12; // Margin from the top
+ public static int INTERFERED_CHANNEL = 24; // Interfered channel
+
+ public InputStream inputstr;
+ private int[] rssi = new int[TOTAL]; // Array of current Noise floor values (black line)
+ private int[] rssiMax = new int[TOTAL]; // Array with past Noise floor values (grey line)
+
+
+ public ViewRSSI() {
+ }
+
+ public void paint(Graphics g) {
+ Graphics2D g2 = (Graphics2D) g;
+ int h = getHeight();
+ int w = getWidth();
+ double factor = (h - (MARGIN_BOTTOM*1.0)) / RSSI_MAX_VALUE;
+ double sSpacing = (w - MARGIN_RIGHT) / (TOTAL*1.0);
+ int sWidth = (int) (sSpacing - 1);
+ if (sWidth == 0) sWidth = 1;
+
+ // Set white background in the plot
+ g.setColor(Color.white);
+ g.fillRect(0, 0, w, h);
+
+ // Gradient example (ytics background)
+ GradientPaint greytowhite = new GradientPaint(w-MARGIN_RIGHT,0,Color.WHITE,w, 0,Color.lightGray, false);
+ g2.setPaint(greytowhite);
+ g2.fillRect(w-MARGIN_RIGHT, 0, w, h);
+
+ // Draw the light grey channels from 11 to 26
+ double xpos = 10;
+ for(int i=4;i rssiMax[i]) rssiMax[i] = rssi[i];
+ else if (rssiMax[i] > 0) rssiMax[i] = rssiMax[i] - DECREASE_RSSI;
+ }
+ } catch (Exception e) {
+ e.printStackTrace(); /* Report error, but do not fail... */
+ }
+ repaint();
+ }
+ }
+ }
+
+
+ public static void main(String[] args) throws IOException {
+ JFrame win = new JFrame("RSSI Viewer");
+ ViewRSSI panel;
+ win.setBounds(10, 10, 590, 590);
+ win.getContentPane().add(panel = new ViewRSSI());
+ win.setVisible(true);
+ win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ panel.handleInput();
+ }
+
+}
diff --git a/platform/avr-ravenlcd/doc/Doxyfile b/platform/avr-ravenlcd/doc/Doxyfile
index e87bf474f..e8c4027d1 100644
--- a/platform/avr-ravenlcd/doc/Doxyfile
+++ b/platform/avr-ravenlcd/doc/Doxyfile
@@ -1,240 +1,240 @@
-# Doxyfile 1.4.1
-
-#---------------------------------------------------------------------------
-# Project related configuration options
-#---------------------------------------------------------------------------
-PROJECT_NAME = "Contiki 6LoWPAN Menu"
-PROJECT_NUMBER =
-OUTPUT_DIRECTORY = .
-CREATE_SUBDIRS = NO
-OUTPUT_LANGUAGE = English
-USE_WINDOWS_ENCODING = NO
-BRIEF_MEMBER_DESC = YES
-REPEAT_BRIEF = YES
-ABBREVIATE_BRIEF =
-ALWAYS_DETAILED_SEC = NO
-INLINE_INHERITED_MEMB = NO
-FULL_PATH_NAMES = YES
-STRIP_FROM_PATH = ../
-STRIP_FROM_INC_PATH =
-SHORT_NAMES = YES
-JAVADOC_AUTOBRIEF = YES
-MULTILINE_CPP_IS_BRIEF = NO
-DETAILS_AT_TOP = YES
-INHERIT_DOCS = YES
-DISTRIBUTE_GROUP_DOC = NO
-TAB_SIZE = 8
-ALIASES =
-OPTIMIZE_OUTPUT_FOR_C = YES
-OPTIMIZE_OUTPUT_JAVA = NO
-SUBGROUPING = YES
-#---------------------------------------------------------------------------
-# Build related configuration options
-#---------------------------------------------------------------------------
-EXTRACT_ALL = NO
-EXTRACT_PRIVATE = NO
-EXTRACT_STATIC = YES
-EXTRACT_LOCAL_CLASSES = NO
-EXTRACT_LOCAL_METHODS = NO
-HIDE_UNDOC_MEMBERS = YES
-HIDE_UNDOC_CLASSES = YES
-HIDE_FRIEND_COMPOUNDS = NO
-HIDE_IN_BODY_DOCS = NO
-INTERNAL_DOCS = NO
-CASE_SENSE_NAMES = YES
-HIDE_SCOPE_NAMES = NO
-SHOW_INCLUDE_FILES = YES
-INLINE_INFO = YES
-SORT_MEMBER_DOCS = YES
-SORT_BRIEF_DOCS = NO
-SORT_BY_SCOPE_NAME = NO
-GENERATE_TODOLIST = YES
-GENERATE_TESTLIST = YES
-GENERATE_BUGLIST = NO
-GENERATE_DEPRECATEDLIST= NO
-ENABLED_SECTIONS =
-MAX_INITIALIZER_LINES = 30
-SHOW_USED_FILES = NO
-SHOW_DIRECTORIES = YES
-FILE_VERSION_FILTER =
-#---------------------------------------------------------------------------
-# configuration options related to warning and progress messages
-#---------------------------------------------------------------------------
-QUIET = NO
-WARNINGS = YES
-WARN_IF_UNDOCUMENTED = NO
-WARN_IF_DOC_ERROR = YES
-WARN_NO_PARAMDOC = NO
-WARN_FORMAT = "$file:$line: $text"
-WARN_LOGFILE =
-#---------------------------------------------------------------------------
-# configuration options related to the input files
-#---------------------------------------------------------------------------
-INPUT = ../adc.c \
- ../beep.c \
- ../key.c \
- ../lcd.c \
- ../menu.c \
- ../raven3290.c \
- ../sleep.c \
- ../temp.c \
- ../timer.c \
- ../uart.c \
- ../adc.h \
- ../beep.h \
- ../key.h \
- ../lcd.h \
- ../menu.h \
- ../main.h \
- ../sleep.h \
- ../temp.h \
- ../timer.h \
- ../uart.h
-
-FILE_PATTERNS =
-RECURSIVE = NO
-EXCLUDE =
-EXCLUDE_SYMLINKS = NO
-EXCLUDE_PATTERNS =
-EXAMPLE_PATH =
-EXAMPLE_PATTERNS =
-EXAMPLE_RECURSIVE = NO
-IMAGE_PATH = ./pics
-INPUT_FILTER =
-FILTER_PATTERNS =
-FILTER_SOURCE_FILES = NO
-#---------------------------------------------------------------------------
-# configuration options related to source browsing
-#---------------------------------------------------------------------------
-SOURCE_BROWSER = YES
-INLINE_SOURCES = NO
-STRIP_CODE_COMMENTS = NO
-REFERENCED_BY_RELATION = YES
-REFERENCES_RELATION = YES
-VERBATIM_HEADERS = YES
-#---------------------------------------------------------------------------
-# configuration options related to the alphabetical class index
-#---------------------------------------------------------------------------
-ALPHABETICAL_INDEX = YES
-COLS_IN_ALPHA_INDEX = 5
-IGNORE_PREFIX =
-#---------------------------------------------------------------------------
-# configuration options related to the HTML output
-#---------------------------------------------------------------------------
-GENERATE_HTML = YES
-HTML_OUTPUT = html
-HTML_FILE_EXTENSION = .html
-HTML_HEADER =
-HTML_FOOTER =
-HTML_STYLESHEET =
-HTML_ALIGN_MEMBERS = YES
-GENERATE_HTMLHELP = YES
-CHM_FILE =
-HHC_LOCATION =
-GENERATE_CHI = YES
-BINARY_TOC = YES
-TOC_EXPAND = YES
-DISABLE_INDEX = NO
-ENUM_VALUES_PER_LINE = 4
-GENERATE_TREEVIEW = YES
-TREEVIEW_WIDTH = 250
-#---------------------------------------------------------------------------
-# configuration options related to the LaTeX output
-#---------------------------------------------------------------------------
-GENERATE_LATEX = YES
-LATEX_OUTPUT = latex
-LATEX_CMD_NAME = latex
-MAKEINDEX_CMD_NAME = makeindex
-COMPACT_LATEX = YES
-PAPER_TYPE = a4wide
-EXTRA_PACKAGES =
-LATEX_HEADER =
-PDF_HYPERLINKS = YES
-USE_PDFLATEX = YES
-LATEX_BATCHMODE = NO
-LATEX_HIDE_INDICES = NO
-#---------------------------------------------------------------------------
-# configuration options related to the RTF output
-#---------------------------------------------------------------------------
-GENERATE_RTF = NO
-RTF_OUTPUT = rtf
-COMPACT_RTF = NO
-RTF_HYPERLINKS = NO
-RTF_STYLESHEET_FILE =
-RTF_EXTENSIONS_FILE =
-#---------------------------------------------------------------------------
-# configuration options related to the man page output
-#---------------------------------------------------------------------------
-GENERATE_MAN = NO
-MAN_OUTPUT = man
-MAN_EXTENSION = .3
-MAN_LINKS = NO
-#---------------------------------------------------------------------------
-# configuration options related to the XML output
-#---------------------------------------------------------------------------
-GENERATE_XML = NO
-XML_OUTPUT = xml
-XML_SCHEMA =
-XML_DTD =
-XML_PROGRAMLISTING = YES
-#---------------------------------------------------------------------------
-# configuration options for the AutoGen Definitions output
-#---------------------------------------------------------------------------
-GENERATE_AUTOGEN_DEF = NO
-#---------------------------------------------------------------------------
-# configuration options related to the Perl module output
-#---------------------------------------------------------------------------
-GENERATE_PERLMOD = NO
-PERLMOD_LATEX = NO
-PERLMOD_PRETTY = YES
-PERLMOD_MAKEVAR_PREFIX =
-#---------------------------------------------------------------------------
-# Configuration options related to the preprocessor
-#---------------------------------------------------------------------------
-ENABLE_PREPROCESSING = YES
-MACRO_EXPANSION = NO
-EXPAND_ONLY_PREDEF = NO
-SEARCH_INCLUDES = YES
-INCLUDE_PATH =
-INCLUDE_FILE_PATTERNS =
-PREDEFINED = DOXYGEN
-EXPAND_AS_DEFINED =
-SKIP_FUNCTION_MACROS = YES
-#---------------------------------------------------------------------------
-# Configuration::additions related to external references
-#---------------------------------------------------------------------------
-TAGFILES =
-GENERATE_TAGFILE =
-ALLEXTERNALS = NO
-EXTERNAL_GROUPS = YES
-PERL_PATH = /usr/bin/perl
-#---------------------------------------------------------------------------
-# Configuration options related to the dot tool
-#---------------------------------------------------------------------------
-CLASS_DIAGRAMS = NO
-HIDE_UNDOC_RELATIONS = YES
-HAVE_DOT = YES
-CLASS_GRAPH = NO
-COLLABORATION_GRAPH = NO
-GROUP_GRAPHS = NO
-UML_LOOK = NO
-TEMPLATE_RELATIONS = NO
-INCLUDE_GRAPH = NO
-INCLUDED_BY_GRAPH = NO
-CALL_GRAPH = NO
-GRAPHICAL_HIERARCHY = NO
-DIRECTORY_GRAPH = NO
-DOT_IMAGE_FORMAT = png
-DOT_PATH =
-DOTFILE_DIRS =
-MAX_DOT_GRAPH_WIDTH = 1024
-MAX_DOT_GRAPH_HEIGHT = 1024
-MAX_DOT_GRAPH_DEPTH = 0
-DOT_TRANSPARENT = NO
-DOT_MULTI_TARGETS = NO
-GENERATE_LEGEND = YES
-DOT_CLEANUP = YES
-#---------------------------------------------------------------------------
-# Configuration::additions related to the search engine
-#---------------------------------------------------------------------------
-SEARCHENGINE = NO
+# Doxyfile 1.4.1
+
+#---------------------------------------------------------------------------
+# Project related configuration options
+#---------------------------------------------------------------------------
+PROJECT_NAME = "Contiki 6LoWPAN Menu"
+PROJECT_NUMBER =
+OUTPUT_DIRECTORY = .
+CREATE_SUBDIRS = NO
+OUTPUT_LANGUAGE = English
+USE_WINDOWS_ENCODING = NO
+BRIEF_MEMBER_DESC = YES
+REPEAT_BRIEF = YES
+ABBREVIATE_BRIEF =
+ALWAYS_DETAILED_SEC = NO
+INLINE_INHERITED_MEMB = NO
+FULL_PATH_NAMES = YES
+STRIP_FROM_PATH = ../
+STRIP_FROM_INC_PATH =
+SHORT_NAMES = YES
+JAVADOC_AUTOBRIEF = YES
+MULTILINE_CPP_IS_BRIEF = NO
+DETAILS_AT_TOP = YES
+INHERIT_DOCS = YES
+DISTRIBUTE_GROUP_DOC = NO
+TAB_SIZE = 8
+ALIASES =
+OPTIMIZE_OUTPUT_FOR_C = YES
+OPTIMIZE_OUTPUT_JAVA = NO
+SUBGROUPING = YES
+#---------------------------------------------------------------------------
+# Build related configuration options
+#---------------------------------------------------------------------------
+EXTRACT_ALL = NO
+EXTRACT_PRIVATE = NO
+EXTRACT_STATIC = YES
+EXTRACT_LOCAL_CLASSES = NO
+EXTRACT_LOCAL_METHODS = NO
+HIDE_UNDOC_MEMBERS = YES
+HIDE_UNDOC_CLASSES = YES
+HIDE_FRIEND_COMPOUNDS = NO
+HIDE_IN_BODY_DOCS = NO
+INTERNAL_DOCS = NO
+CASE_SENSE_NAMES = YES
+HIDE_SCOPE_NAMES = NO
+SHOW_INCLUDE_FILES = YES
+INLINE_INFO = YES
+SORT_MEMBER_DOCS = YES
+SORT_BRIEF_DOCS = NO
+SORT_BY_SCOPE_NAME = NO
+GENERATE_TODOLIST = YES
+GENERATE_TESTLIST = YES
+GENERATE_BUGLIST = NO
+GENERATE_DEPRECATEDLIST= NO
+ENABLED_SECTIONS =
+MAX_INITIALIZER_LINES = 30
+SHOW_USED_FILES = NO
+SHOW_DIRECTORIES = YES
+FILE_VERSION_FILTER =
+#---------------------------------------------------------------------------
+# configuration options related to warning and progress messages
+#---------------------------------------------------------------------------
+QUIET = NO
+WARNINGS = YES
+WARN_IF_UNDOCUMENTED = NO
+WARN_IF_DOC_ERROR = YES
+WARN_NO_PARAMDOC = NO
+WARN_FORMAT = "$file:$line: $text"
+WARN_LOGFILE =
+#---------------------------------------------------------------------------
+# configuration options related to the input files
+#---------------------------------------------------------------------------
+INPUT = ../adc.c \
+ ../beep.c \
+ ../key.c \
+ ../lcd.c \
+ ../menu.c \
+ ../raven3290.c \
+ ../sleep.c \
+ ../temp.c \
+ ../timer.c \
+ ../uart.c \
+ ../adc.h \
+ ../beep.h \
+ ../key.h \
+ ../lcd.h \
+ ../menu.h \
+ ../main.h \
+ ../sleep.h \
+ ../temp.h \
+ ../timer.h \
+ ../uart.h
+
+FILE_PATTERNS =
+RECURSIVE = NO
+EXCLUDE =
+EXCLUDE_SYMLINKS = NO
+EXCLUDE_PATTERNS =
+EXAMPLE_PATH =
+EXAMPLE_PATTERNS =
+EXAMPLE_RECURSIVE = NO
+IMAGE_PATH = ./pics
+INPUT_FILTER =
+FILTER_PATTERNS =
+FILTER_SOURCE_FILES = NO
+#---------------------------------------------------------------------------
+# configuration options related to source browsing
+#---------------------------------------------------------------------------
+SOURCE_BROWSER = YES
+INLINE_SOURCES = NO
+STRIP_CODE_COMMENTS = NO
+REFERENCED_BY_RELATION = YES
+REFERENCES_RELATION = YES
+VERBATIM_HEADERS = YES
+#---------------------------------------------------------------------------
+# configuration options related to the alphabetical class index
+#---------------------------------------------------------------------------
+ALPHABETICAL_INDEX = YES
+COLS_IN_ALPHA_INDEX = 5
+IGNORE_PREFIX =
+#---------------------------------------------------------------------------
+# configuration options related to the HTML output
+#---------------------------------------------------------------------------
+GENERATE_HTML = YES
+HTML_OUTPUT = html
+HTML_FILE_EXTENSION = .html
+HTML_HEADER =
+HTML_FOOTER =
+HTML_STYLESHEET =
+HTML_ALIGN_MEMBERS = YES
+GENERATE_HTMLHELP = YES
+CHM_FILE =
+HHC_LOCATION =
+GENERATE_CHI = YES
+BINARY_TOC = YES
+TOC_EXPAND = YES
+DISABLE_INDEX = NO
+ENUM_VALUES_PER_LINE = 4
+GENERATE_TREEVIEW = YES
+TREEVIEW_WIDTH = 250
+#---------------------------------------------------------------------------
+# configuration options related to the LaTeX output
+#---------------------------------------------------------------------------
+GENERATE_LATEX = YES
+LATEX_OUTPUT = latex
+LATEX_CMD_NAME = latex
+MAKEINDEX_CMD_NAME = makeindex
+COMPACT_LATEX = YES
+PAPER_TYPE = a4wide
+EXTRA_PACKAGES =
+LATEX_HEADER =
+PDF_HYPERLINKS = YES
+USE_PDFLATEX = YES
+LATEX_BATCHMODE = NO
+LATEX_HIDE_INDICES = NO
+#---------------------------------------------------------------------------
+# configuration options related to the RTF output
+#---------------------------------------------------------------------------
+GENERATE_RTF = NO
+RTF_OUTPUT = rtf
+COMPACT_RTF = NO
+RTF_HYPERLINKS = NO
+RTF_STYLESHEET_FILE =
+RTF_EXTENSIONS_FILE =
+#---------------------------------------------------------------------------
+# configuration options related to the man page output
+#---------------------------------------------------------------------------
+GENERATE_MAN = NO
+MAN_OUTPUT = man
+MAN_EXTENSION = .3
+MAN_LINKS = NO
+#---------------------------------------------------------------------------
+# configuration options related to the XML output
+#---------------------------------------------------------------------------
+GENERATE_XML = NO
+XML_OUTPUT = xml
+XML_SCHEMA =
+XML_DTD =
+XML_PROGRAMLISTING = YES
+#---------------------------------------------------------------------------
+# configuration options for the AutoGen Definitions output
+#---------------------------------------------------------------------------
+GENERATE_AUTOGEN_DEF = NO
+#---------------------------------------------------------------------------
+# configuration options related to the Perl module output
+#---------------------------------------------------------------------------
+GENERATE_PERLMOD = NO
+PERLMOD_LATEX = NO
+PERLMOD_PRETTY = YES
+PERLMOD_MAKEVAR_PREFIX =
+#---------------------------------------------------------------------------
+# Configuration options related to the preprocessor
+#---------------------------------------------------------------------------
+ENABLE_PREPROCESSING = YES
+MACRO_EXPANSION = NO
+EXPAND_ONLY_PREDEF = NO
+SEARCH_INCLUDES = YES
+INCLUDE_PATH =
+INCLUDE_FILE_PATTERNS =
+PREDEFINED = DOXYGEN
+EXPAND_AS_DEFINED =
+SKIP_FUNCTION_MACROS = YES
+#---------------------------------------------------------------------------
+# Configuration::additions related to external references
+#---------------------------------------------------------------------------
+TAGFILES =
+GENERATE_TAGFILE =
+ALLEXTERNALS = NO
+EXTERNAL_GROUPS = YES
+PERL_PATH = /usr/bin/perl
+#---------------------------------------------------------------------------
+# Configuration options related to the dot tool
+#---------------------------------------------------------------------------
+CLASS_DIAGRAMS = NO
+HIDE_UNDOC_RELATIONS = YES
+HAVE_DOT = YES
+CLASS_GRAPH = NO
+COLLABORATION_GRAPH = NO
+GROUP_GRAPHS = NO
+UML_LOOK = NO
+TEMPLATE_RELATIONS = NO
+INCLUDE_GRAPH = NO
+INCLUDED_BY_GRAPH = NO
+CALL_GRAPH = NO
+GRAPHICAL_HIERARCHY = NO
+DIRECTORY_GRAPH = NO
+DOT_IMAGE_FORMAT = png
+DOT_PATH =
+DOTFILE_DIRS =
+MAX_DOT_GRAPH_WIDTH = 1024
+MAX_DOT_GRAPH_HEIGHT = 1024
+MAX_DOT_GRAPH_DEPTH = 0
+DOT_TRANSPARENT = NO
+DOT_MULTI_TARGETS = NO
+GENERATE_LEGEND = YES
+DOT_CLEANUP = YES
+#---------------------------------------------------------------------------
+# Configuration::additions related to the search engine
+#---------------------------------------------------------------------------
+SEARCHENGINE = NO
diff --git a/platform/avr-ravenlcd/ravenlcd_3290.aps b/platform/avr-ravenlcd/ravenlcd_3290.aps
index 75c9cf036..b6fec0fe2 100644
--- a/platform/avr-ravenlcd/ravenlcd_3290.aps
+++ b/platform/avr-ravenlcd/ravenlcd_3290.aps
@@ -1 +1 @@
-ravenlcd_329025-Apr-2008 11:07:1628-Aug-2008 17:12:52241025-Apr-2008 11:07:1644, 13, 0, 569AVR GCCdefault\ravenlcd_3290.elfC:\Atmel\cisco\branches\macipv6\apps\ravenlcd_3290\JTAGICE mkIIATmega3290PfalseR00R01R02R03R04R05R06R07R08R09R10R11R12R13R14R15R16R17R18R19R20R21R22R23R24R25R26R27R28R29R30R31Auto00menuresultstrpnpayloadnumb0uart.cadc.ckey.clcd.cmenu.craven3290.csleep.cbeep.ctimer.ctemp.cdefault\ravenlcd_3290.lssdefault\ravenlcd_3290.mapdefaultNOatmega3290p11ravenlcd_3290.elfdefault\0.\-Wall -gdwarf-2 -std=gnu99 -DF_CPU=8000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enumsdefault1C:\Programme\WinAVR-20080610\bin\avr-gcc.exeC:\Programme\WinAVR-20080610\utils\bin\make.exeC:\Atmel\cisco\branches\macipv6\apps\ravenlcd_3290\uart.cC:\Atmel\cisco\branches\macipv6\apps\ravenlcd_3290\adc.cC:\Atmel\cisco\branches\macipv6\apps\ravenlcd_3290\key.cC:\Atmel\cisco\branches\macipv6\apps\ravenlcd_3290\lcd.cC:\Atmel\cisco\branches\macipv6\apps\ravenlcd_3290\menu.cC:\Atmel\cisco\branches\macipv6\apps\ravenlcd_3290\raven3290.cC:\Atmel\cisco\branches\macipv6\apps\ravenlcd_3290\sleep.cC:\Atmel\cisco\branches\macipv6\apps\ravenlcd_3290\beep.cC:\Atmel\cisco\branches\macipv6\apps\ravenlcd_3290\timer.cC:\Atmel\cisco\branches\macipv6\apps\ravenlcd_3290\temp.c00000raven3290.c25900001sleep.c25700002lcd.c25900003timer.c25900004adc.c25900005menu.c25900006temp.c25900007key.c25900008uart.c259
+ravenlcd_329025-Apr-2008 11:07:1628-Aug-2008 17:12:52241025-Apr-2008 11:07:1644, 13, 0, 569AVR GCCdefault\ravenlcd_3290.elfC:\Atmel\cisco\branches\macipv6\apps\ravenlcd_3290\JTAGICE mkIIATmega3290PfalseR00R01R02R03R04R05R06R07R08R09R10R11R12R13R14R15R16R17R18R19R20R21R22R23R24R25R26R27R28R29R30R31Auto00menuresultstrpnpayloadnumb0uart.cadc.ckey.clcd.cmenu.craven3290.csleep.cbeep.ctimer.ctemp.cdefault\ravenlcd_3290.lssdefault\ravenlcd_3290.mapdefaultNOatmega3290p11ravenlcd_3290.elfdefault\0.\-Wall -gdwarf-2 -std=gnu99 -DF_CPU=8000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enumsdefault1C:\Programme\WinAVR-20080610\bin\avr-gcc.exeC:\Programme\WinAVR-20080610\utils\bin\make.exeC:\Atmel\cisco\branches\macipv6\apps\ravenlcd_3290\uart.cC:\Atmel\cisco\branches\macipv6\apps\ravenlcd_3290\adc.cC:\Atmel\cisco\branches\macipv6\apps\ravenlcd_3290\key.cC:\Atmel\cisco\branches\macipv6\apps\ravenlcd_3290\lcd.cC:\Atmel\cisco\branches\macipv6\apps\ravenlcd_3290\menu.cC:\Atmel\cisco\branches\macipv6\apps\ravenlcd_3290\raven3290.cC:\Atmel\cisco\branches\macipv6\apps\ravenlcd_3290\sleep.cC:\Atmel\cisco\branches\macipv6\apps\ravenlcd_3290\beep.cC:\Atmel\cisco\branches\macipv6\apps\ravenlcd_3290\timer.cC:\Atmel\cisco\branches\macipv6\apps\ravenlcd_3290\temp.c00000raven3290.c25900001sleep.c25700002lcd.c25900003timer.c25900004adc.c25900005menu.c25900006temp.c25900007key.c25900008uart.c259
diff --git a/platform/cooja-ip64/subplatform-conf.h b/platform/cooja-ip64/subplatform-conf.h
index 14afc2ad2..773100051 100644
--- a/platform/cooja-ip64/subplatform-conf.h
+++ b/platform/cooja-ip64/subplatform-conf.h
@@ -1,54 +1,54 @@
-/*
- * Copyright (c) 2013, Thingsquare, http://www.thingsquare.com/.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the copyright holder nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
- * OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-#ifndef __PLATFORM_CONF_H__
-#define __PLATFORM_CONF_H__
-
-#if WITH_IP64
-#define WITH_SLIP 1
-#ifndef UIP_FALLBACK_INTERFACE
-#define UIP_FALLBACK_INTERFACE ip64_uip_fallback_interface
-#endif
-#endif /* WITH_IP64 */
-
-#ifndef UIP_CONF_ND6_RA_RDNSS
-#define UIP_CONF_ND6_RA_RDNSS 1
-#endif
-
-#ifndef UIP_CONF_ND6_SEND_RA
-#define UIP_CONF_ND6_SEND_RA 1
-#endif
-
-#ifndef UIP_CONF_ROUTER
-#define UIP_CONF_ROUTER 1
-#endif
-
-#endif /* __PLATFORM_CONF_H__ */
+/*
+ * Copyright (c) 2013, Thingsquare, http://www.thingsquare.com/.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef __PLATFORM_CONF_H__
+#define __PLATFORM_CONF_H__
+
+#if WITH_IP64
+#define WITH_SLIP 1
+#ifndef UIP_FALLBACK_INTERFACE
+#define UIP_FALLBACK_INTERFACE ip64_uip_fallback_interface
+#endif
+#endif /* WITH_IP64 */
+
+#ifndef UIP_CONF_ND6_RA_RDNSS
+#define UIP_CONF_ND6_RA_RDNSS 1
+#endif
+
+#ifndef UIP_CONF_ND6_SEND_RA
+#define UIP_CONF_ND6_SEND_RA 1
+#endif
+
+#ifndef UIP_CONF_ROUTER
+#define UIP_CONF_ROUTER 1
+#endif
+
+#endif /* __PLATFORM_CONF_H__ */
diff --git a/platform/exp5438/hal_MSP-EXP430F5438.h b/platform/exp5438/hal_MSP-EXP430F5438.h
index 8b64313bb..d03162066 100644
--- a/platform/exp5438/hal_MSP-EXP430F5438.h
+++ b/platform/exp5438/hal_MSP-EXP430F5438.h
@@ -1,15 +1,15 @@
-/*******************************************************************************
- Filename: hal_MSP-EXP430F5438.h
-
- Copyright 2008 Texas Instruments, Inc.
-
-This is the master header file and also the only necessary file to be included
-in order to use MSP-EXP430F548 HAL.
-***************************************************************************/
-
-#ifndef HAL_MSP_EXP430F5438_H
-#define HAL_MSP_EXP430F5438_H
-
-#include "hal_lcd.h"
-
-#endif
+/*******************************************************************************
+ Filename: hal_MSP-EXP430F5438.h
+
+ Copyright 2008 Texas Instruments, Inc.
+
+This is the master header file and also the only necessary file to be included
+in order to use MSP-EXP430F548 HAL.
+***************************************************************************/
+
+#ifndef HAL_MSP_EXP430F5438_H
+#define HAL_MSP_EXP430F5438_H
+
+#include "hal_lcd.h"
+
+#endif
diff --git a/platform/exp5438/hal_lcd.c b/platform/exp5438/hal_lcd.c
index fdaf32203..62b36b414 100644
--- a/platform/exp5438/hal_lcd.c
+++ b/platform/exp5438/hal_lcd.c
@@ -1,1198 +1,1197 @@
-/*******************************************************************************
- *
- * hal_lcd.c
- *
- * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of Texas Instruments Incorporated nor the names of
- * its contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- ******************************************************************************/
-
-#include "contiki-conf.h"
-
-#include "hal_MSP-EXP430F5438.h"
-#include "hal_lcd_fonts.h"
-
-unsigned char LcdInitMacro[] = {
- 0x74, 0x00, 0x00, 0x76, 0x00, 0x01, // R00 start oscillation
- 0x74, 0x00, 0x01, 0x76, 0x00, 0x0D, // R01 driver output control
- 0x74, 0x00, 0x02, 0x76, 0x00, 0x4C, // R02 LCD - driving waveform control
- 0x74, 0x00, 0x03, 0x76, 0x12, 0x14, // R03 Power control
- 0x74, 0x00, 0x04, 0x76, 0x04, 0x66, // R04 Contrast control
- 0x74, 0x00, 0x05, 0x76, 0x00, 0x10, // R05 Entry mode
- 0x74, 0x00, 0x06, 0x76, 0x00, 0x00, // R06 RAM data write mask
- 0x74, 0x00, 0x07, 0x76, 0x00, 0x15, // R07 Display control
- 0x74, 0x00, 0x08, 0x76, 0x00, 0x03, // R08 Cursor Control
- 0x74, 0x00, 0x09, 0x76, 0x00, 0x00, // R09 RAM data write mask
- 0x74, 0x00, 0x0A, 0x76, 0x00, 0x15, // R0A
- 0x74, 0x00, 0x0B, 0x76, 0x00, 0x03, // R0B Horizontal Cursor Position
- 0x74, 0x00, 0x0C, 0x76, 0x00, 0x03, // R0C Vertical Cursor Position
- 0x74, 0x00, 0x0D, 0x76, 0x00, 0x00, // R0D
- 0x74, 0x00, 0x0E, 0x76, 0x00, 0x15, // R0E
- 0x74, 0x00, 0x0F, 0x76, 0x00, 0x03, // R0F
- 0x74, 0x00, 0x10, 0x76, 0x00, 0x15, // R0E
- 0x74, 0x00, 0x11, 0x76, 0x00, 0x03, // R0F
-};
-
-unsigned char Read_Block_Address_Macro[] = {0x74, 0x00, 0x12, 0x77, 0x00, 0x00};
-unsigned char Draw_Block_Value_Macro[] = {0x74, 0x00, 0x12, 0x76, 0xFF, 0xFF};
-unsigned char Draw_Block_Address_Macro[] = {0x74, 0x00, 0x11, 0x76, 0x00, 0x00};
-
-unsigned int LcdAddress = 0, LcdTableAddress = 0;
-unsigned char contrast = 0x66;
-unsigned char backlight = 8;
-int LCD_MEM[110 * 17]; //This array stores a copy of all data on the LCD
-//screen. If memory is an issue though, this array
-//can be eliminated and the halLcdReadBlock()
-//command can be used instead whenever you are
-//manipulating the currently displayed data.
-
-/**********************************************************************//**
- * @brief Sends 3+3 bytes of data to the LCD using the format specified
- * by the LCD Guide.
- *
- * @param Data[] Data array for transmission
- *
- * @return none
- *************************************************************************/
-
-void halLcdSendCommand(unsigned char Data[])
-{
- unsigned char i;
-
- LCD_CS_RST_OUT &= ~LCD_CS_PIN; //CS = 0 --> Start Transfer
- for (i = 0; i < 6; i++)
- {
- while (!(UCB2IFG & UCTXIFG)) ; // Wait for TXIFG
- UCB2TXBUF = Data[i]; // Load data
-
- if (i == 2) //Pull CS up after 3 bytes
- {
- while (UCB2STAT & UCBUSY) ;
- LCD_CS_RST_OUT |= LCD_CS_PIN; //CS = 1 --> Stop Transfer
- LCD_CS_RST_OUT &= ~LCD_CS_PIN; //CS = 0 --> Start Transfer
- }
- }
- while (UCB2STAT & UCBUSY) ;
- LCD_CS_RST_OUT |= LCD_CS_PIN; //CS = 1 --> Stop Transfer
-}
-
-/**********************************************************************//**
- * @brief Initializes the USCI module, LCD device for communication.
- *
- * - Sets up the SPI2C Communication Module
- * - Performs Hitachi LCD Initialization Procedure
- *
- * @param none
- *
- * @return none
- *************************************************************************/
-
-void halLcdInit(void)
-{
- volatile unsigned int i = 0;
-
- LCD_CS_RST_OUT |= LCD_CS_PIN | LCD_RESET_PIN;
- LCD_CS_RST_DIR |= LCD_CS_PIN | LCD_RESET_PIN;
-
- LCD_BACKLT_SEL |= LCD_BACKLIGHT_PIN;
-
- LCD_CS_RST_OUT &= ~LCD_RESET_PIN; // Reset LCD
- __delay_cycles(0x47FF); //Reset Pulse
- LCD_CS_RST_OUT |= LCD_RESET_PIN;
-
- // UCLK,MOSI setup, SOMI cleared
- LCD_SPI_SEL |= LCD_MOSI_PIN + LCD_CLK_PIN;
- LCD_SPI_SEL &= ~LCD_MISO_PIN;
- LCD_SPI_DIR &= ~(LCD_MISO_PIN + LCD_MOSI_PIN); // Pin direction controlled by module,
- // Set both pins to input as default
-
- // Initialize the USCI_B2 module for SPI operation
- UCB2CTL1 = UCSWRST; // Hold USCI in SW reset mode while configuring
- // it
- UCB2CTL0 = UCMST + UCSYNC + UCCKPL + UCMSB; // 3-pin, 8-bit SPI master
- UCB2CTL1 |= UCSSEL_2; // SMCLK
- UCB2BR0 = 4; // Note: Do not exceed D/S spec for UCLK!
- UCB2BR1 = 0;
- UCB2CTL1 &= ~UCSWRST; // Release USCI state machine
- UCB2IFG &= ~UCRXIFG;
-
- // Wake-up the LCD as per datasheet specifications
- halLcdActive();
-
- // LCD Initialization Routine Using Predefined Macros
- halLcdSendCommand(&LcdInitMacro[1 * 6]);
- halLcdSendCommand(&LcdInitMacro[2 * 6]);
- halLcdSendCommand(&LcdInitMacro[4 * 6]);
- halLcdSendCommand(&LcdInitMacro[5 * 6]);
- halLcdSendCommand(&LcdInitMacro[6 * 6]);
- halLcdSendCommand(&LcdInitMacro[7 * 6]);
-
-}
-
-/**********************************************************************//**
- * @brief Shuts down the LCD display and hdisables the USCI communication.
- *
- * @param none
- *
- * @return none
- *************************************************************************/
-
-void halLcdShutDown(void)
-{
- halLcdStandby();
-
- LCD_CS_RST_DIR |= LCD_CS_PIN | LCD_RESET_PIN;
- LCD_CS_RST_OUT &= ~(LCD_CS_PIN | LCD_RESET_PIN);
- LCD_CS_RST_OUT &= ~LCD_RESET_PIN;
-
- LCD_SPI_SEL &= ~(LCD_MOSI_PIN + LCD_CLK_PIN + LCD_MISO_PIN);
- LCD_CS_RST_DIR |= LCD_MOSI_PIN + LCD_CLK_PIN + LCD_MISO_PIN;
- LCD_CS_RST_OUT &= ~(LCD_MOSI_PIN + LCD_CLK_PIN + LCD_MISO_PIN);
-
- UCB2CTL0 = UCSWRST;
-}
-
-/**********************************************************************//**
- * @brief Initializes the LCD backlight PWM signal.
- *
- * @param none
- *
- * @return none
- *
- *************************************************************************/
-
-void halLcdBackLightInit(void)
-{
- LCD_BACKLT_DIR |= LCD_BACKLIGHT_PIN;
- LCD_BACKLT_OUT |= LCD_BACKLIGHT_PIN;
- LCD_BACKLT_SEL |= LCD_BACKLIGHT_PIN;
-
- TA0CCTL3 = OUTMOD_7;
- TA0CCR3 = TA0CCR0 >> 1;
- backlight = 8;
-
- TA0CCR0 = 400;
- TA0CTL = TASSEL_2 + MC_1;
-}
-
-/**********************************************************************//**
- * @brief Get function for the backlight PWM's duty cycle.
- *
- * @param none
- *
- * @return backlight One of the the 17 possible settings - valued 0 to 16.
- *
- *************************************************************************/
-
-unsigned int halLcdGetBackLight(void)
-{
- return backlight;
-}
-
-/**********************************************************************//**
- * @brief Set function for the backlight PWM's duty cycle
- *
- * @param BackLightLevel The target backlight duty cycle - valued 0 to 16.
- *
- * @return none
- *************************************************************************/
-
-void halLcdSetBackLight(unsigned char BackLightLevel)
-{
- unsigned int dutyCycle = 0, i, dummy;
-
- if (BackLightLevel > 0)
- {
- TA0CCTL3 = OUTMOD_7;
- dummy = (TA0CCR0 >> 4);
-
- for (i = 0; i < BackLightLevel; i++)
- dutyCycle += dummy;
-
- TA0CCR3 = dutyCycle;
-
- // If the backlight was previously turned off, turn it on.
- if (!backlight)
- TA0CTL |= MC0;
- }
- else
- {
- TA0CCTL3 = 0;
- TA0CTL &= ~MC0;
- }
- backlight = BackLightLevel;
-}
-
-/**********************************************************************//**
- * @brief Turns off the backlight.
- *
- * Clears the respective GPIO and timer settings.
- *
- * @param none
- *
- * @return none
- *************************************************************************/
-
-void halLcdShutDownBackLight(void)
-{
- LCD_BACKLT_DIR |= LCD_BACKLIGHT_PIN;
- LCD_BACKLT_OUT &= ~(LCD_BACKLIGHT_PIN);
- LCD_BACKLT_SEL &= ~LCD_BACKLIGHT_PIN;
-
- TA0CCTL3 = 0;
- TA0CTL = 0;
-
- backlight = 0;
-}
-
-/**********************************************************************//**
- * @brief Set function for the contrast level of the LCD.
- *
- * @param ContrastLevel The target contrast level
- *
- * @return none
- *************************************************************************/
-
-void halLcdSetContrast(unsigned char ContrastLevel)
-{
- if (ContrastLevel > 127) ContrastLevel = 127;
- if (ContrastLevel < 70) ContrastLevel = 70;
- LcdInitMacro[0x04 * 6 + 5] = ContrastLevel;
- halLcdSendCommand(&LcdInitMacro[0x04 * 6]);
-}
-
-/**********************************************************************//**
- * @brief Get function for the contrast level of the LCD.
- *
- * @param none
- *
- * @return ContrastLevel The LCD constrast level
- *************************************************************************/
-
-unsigned char halLcdGetContrast(void)
-{
- return LcdInitMacro[0x04 * 6 + 5];
-}
-
-/**********************************************************************//**
- * @brief Turns the LCD cursor on at the current text position.
- *
- * @param none
- *
- * @return none
- *************************************************************************/
-
-void halLcdCursor(void)
-{
- LcdInitMacro[8 * 6 + 5] ^= BIT2;
- halLcdSendCommand(&LcdInitMacro[8 * 6]);
-
- LcdInitMacro[0x0B * 6 + 5] = ((LcdAddress & 0x1F) << 3);
- LcdInitMacro[0x0B * 6 + 4] = ((LcdAddress & 0x1F) << 3) + 3;
- LcdInitMacro[0x0C * 6 + 5] = (LcdAddress >> 5);
- LcdInitMacro[0x0C * 6 + 4] = (LcdAddress >> 5) + 7;
- halLcdSendCommand(&LcdInitMacro[0x0B * 6]);
- halLcdSendCommand(&LcdInitMacro[0x0C * 6]);
-
- halLcdSetAddress(LcdAddress);
-}
-
-/**********************************************************************//**
- * @brief Turns off the LCD cursor.
- *
- * @param none
- *
- * @return none
- *************************************************************************/
-
-void halLcdCursorOff(void)
-{
- LcdInitMacro[8 * 6 + 5] &= ~BIT2;
- halLcdSendCommand(&LcdInitMacro[8 * 6]);
-}
-
-/**********************************************************************//**
- * @brief Inverts the grayscale values of the LCD display (Black <> white).
- *
- * @param none
- *
- * @return none
- *************************************************************************/
-
-void halLcdReverse(void)
-{
- LcdInitMacro[7 * 6 + 5] ^= BIT1;
- halLcdSendCommand(&LcdInitMacro[7 * 6]);
-}
-
-/**********************************************************************//**
- * @brief Sets the LCD in standby mode to reduce power consumption.
- *
- * @param none
- *
- * @return none
- *************************************************************************/
-
-void halLcdStandby(void)
-{
- LcdInitMacro[3 * 6 + 5] &= (~BIT3) & (~BIT2);
- LcdInitMacro[3 * 6 + 5] |= BIT0;
- halLcdSendCommand(&LcdInitMacro[3 * 6]);
-}
-
-/**********************************************************************//**
- * @brief Puts the LCD into active mode.
- *
- * @param none
- *
- * @return none
- *************************************************************************/
-
-void halLcdActive(void)
-{
- halLcdSendCommand(LcdInitMacro); // R00 start oscillation
-
- // Wait a minimum of 25ms after issuing "start oscillation"
- // command (to accomodate for MCLK up to 25MHz)
- {
- int i;
- for(i = 0; i < 5; ++i) {
- __delay_cycles(50000);
- }
- }
-
- LcdInitMacro[3 * 6 + 5] |= BIT3;
- LcdInitMacro[3 * 6 + 5] &= ~BIT0;
- halLcdSendCommand(&LcdInitMacro[3 * 6]); // R03 Power control
-}
-
-/**********************************************************************//**
- * @brief Sets the pointer location in the LCD.
- *
- * - LcdAddress = Address
- * - LcdTableAddress = Correct Address Row + Column
- * = (Address / 0x20)* 17 + Column
- *
- * @param Address The target pointer location in the LCD.
- *
- * @return none
- *************************************************************************/
-
-void halLcdSetAddress(int Address)
-{
- int temp;
-
- Draw_Block_Address_Macro[4] = Address >> 8;
- Draw_Block_Address_Macro[5] = Address & 0xFF;
- halLcdSendCommand(Draw_Block_Address_Macro);
- LcdAddress = Address;
- temp = Address >> 5; // Divided by 0x20
- temp = temp + (temp << 4);
- //Multiplied by (1+16) and added by the offset
- LcdTableAddress = temp + (Address & 0x1F);
-}
-
-/**********************************************************************//**
- * @brief Draws a block at the specified LCD address.
- *
- * A block is the smallest addressable memory on the LCD and is
- * equivalent to 8 pixels, each of which is represented by 2 bits
- * that represent a grayscale value between 00b and 11b.
- *
- * @param Address The address at which to draw the block.
- *
- * @param Value The value of the block
- *
- * @return none
- *************************************************************************/
-
-void halLcdDrawBlock(unsigned int Address, unsigned int Value)
-{
- halLcdSetAddress(Address);
- halLcdDrawCurrentBlock(Value);
-}
-
-/**********************************************************************//**
- * @brief Writes Value to LCD CGram and MSP430 internal LCD table.
- *
- * Also updates the LcdAddress and LcdTableAddress to the correct values.
- *
- * @param Value The value of the block to be written to the LCD.
- *
- * @return none
- *************************************************************************/
-
-void halLcdDrawCurrentBlock(unsigned int Value)
-{
- int temp;
-
- Draw_Block_Value_Macro[4] = Value >> 8;
- Draw_Block_Value_Macro[5] = Value & 0xFF;
- LCD_MEM[LcdTableAddress] = Value;
-
- halLcdSendCommand(Draw_Block_Value_Macro);
-
- LcdAddress++;
- temp = LcdAddress >> 5; // Divided by 0x20
- temp = temp + (temp << 4);
- // Multiplied by (1+16) and added by the offset
- LcdTableAddress = temp + (LcdAddress & 0x1F);
-
- // If LcdAddress gets off the right edge, move to next line
- if ((LcdAddress & 0x1F) > 0x11)
- halLcdSetAddress((LcdAddress & 0xFFE0) + 0x20);
- if (LcdAddress == LCD_Size)
- halLcdSetAddress(0);
-}
-
-/**********************************************************************//**
- * @brief Returns the LCD CGRAM value at location Address.
- *
- * @param Address The address of the block to be read from the LCD.
- *
- * @return Value The value held at the specified address.
- *************************************************************************/
-
-int halLcdReadBlock(unsigned int Address)
-{
- int i = 0, Value = 0, ReadData[7];
-
- halLcdSetAddress(Address);
- halLcdSendCommand(Read_Block_Address_Macro);
-
- LCD_CS_RST_OUT &= ~LCD_CS_PIN; // start transfer CS=0
- UCB2TXBUF = 0x77; // Transmit first character 0x77
-
- while (!(UCB2IFG & UCTXIFG)) ;
- while (UCB2STAT & UCBUSY) ;
-
- //Read 5 dummies values and 2 valid address data
- LCD_SPI_SEL &= ~LCD_MOSI_PIN; //Change SPI2C Dir
- LCD_SPI_SEL |= LCD_MISO_PIN;
-
- for (i = 0; i < 7; i++)
- {
- UCB2IFG &= ~UCRXIFG;
- UCB2TXBUF = 1; // load dummy byte 1 for clk
- while (!(UCB2IFG & UCRXIFG)) ;
- ReadData[i] = UCB2RXBUF;
- }
- LCD_CS_RST_OUT |= LCD_CS_PIN; // Stop Transfer CS = 1
-
- LCD_SPI_SEL |= LCD_MOSI_PIN; //Change SPI2C Dir
- LCD_SPI_SEL &= ~LCD_MISO_PIN;
- LCD_CS_RST_DIR |= LCD_MOSI_PIN + LCD_CLK_PIN;
- LCD_CS_RST_DIR &= ~LCD_MISO_PIN;
-
- Value = (ReadData[5] << 8) + ReadData[6];
- return Value;
-}
-
-/**********************************************************************//**
- * @brief Draw a Pixel of grayscale at coordinate (x,y) to LCD
- *
- * @param x x-coordinate for grayscale value
- *
- * @param y y-coordinate for grayscale value
- *
- * @param GrayScale The intended grayscale value of the pixel - one of
- * four possible settings.
- *
- * @return none
- *************************************************************************/
-
-void halLcdPixel(int x, int y, unsigned char GrayScale)
-{
- int Address, Value;
- unsigned char offset;
-
- //Each line increments by 0x20
- if ((x >= 0) && (x < LCD_COL) && (y >= 0) && (y < LCD_ROW))
- {
- Address = (y << 5) + (x >> 3); //Narrow down to 8 possible pixels
-
- Value = LCD_MEM[(y << 4) + y + (x >> 3)]; //y * 17 --> row. x>>3 --> column
-
- offset = (x & 0x07) << 1; //3 LSBs = pos. within the 8 columns
- Value &= ~(3 << offset); //clear out the corresponding bits
- Value |= GrayScale << offset; //set pixel to GrayScale level
-
- halLcdDrawBlock(Address, Value);
- }
-}
-
-/**********************************************************************//**
- * @brief Clears entire LCD CGRAM as well as LCD_MEM.
- *
- * @param none
- *
- * @return none
- *************************************************************************/
-
-void halLcdClearScreen(void)
-{
- int i, j, k, Current_Location = 0;
-
- halLcdSetAddress(0);
-
- for (i = 0; i < 110; i++)
- {
- //prepare to send image
- LCD_CS_RST_OUT &= ~LCD_CS_PIN; //CS = 0 --> Start Transfer
- for (k = 0; k < 3; k++)
- {
- while (!(UCB2IFG & UCTXIFG)) ; // Wait for TXIFG
- UCB2TXBUF = Draw_Block_Value_Macro[k]; // Load data
- }
- while (UCB2STAT & UCBUSY) ;
- LCD_CS_RST_OUT |= LCD_CS_PIN; //CS = 1 --> Stop Transfer
- LCD_CS_RST_OUT &= ~LCD_CS_PIN; //CS = 0 --> Start Transfer
- while (!(UCB2IFG & UCTXIFG)) ; // Wait for TXIFG
- UCB2TXBUF = Draw_Block_Value_Macro[3]; // Load data
-
- //send blank line
- for (j = 0; j < 17; j++)
- {
- LCD_MEM[LcdTableAddress++] = 0x00;
- while (!(UCB2IFG & UCTXIFG)) ; // Wait for TXIFG
- UCB2TXBUF = 0x00; // Load data
- while (!(UCB2IFG & UCTXIFG)) ; // Wait for TXIFG
- UCB2TXBUF = 0x00; // Load data
- }
- //Clear the partially visible block at the edge of the screen
- while (!(UCB2IFG & UCTXIFG)) ; // Wait for TXIFG
- UCB2TXBUF = 0x00; // Load data
- while (!(UCB2IFG & UCTXIFG)) ; // Wait for TXIFG
- UCB2TXBUF = 0x00; // Load data
- while (UCB2STAT & UCBUSY) ;
- LCD_CS_RST_OUT |= LCD_CS_PIN; //CS = 1 --> Stop Transfer
-
- Current_Location += 0x20;
- halLcdSetAddress(Current_Location);
- }
-
- halLcdSetAddress(0);
-}
-
-/**********************************************************************//**
- * @brief Loads an image of size = rows * columns, starting at the
- * coordinate (x,y).
- *
- * @param Image[] The image to be loaded
- *
- * @param Rows The number of rows in the image. Size = Rows * Columns.
- *
- * @param Columns The number of columns in the image. Size = Rows * Columns.
- *
- * @param x x-coordinate of the image's starting location
- *
- * @param y y-coordinate of the image's starting location
- *
- * @return none
- *************************************************************************/
-
-void halLcdImage(const unsigned int Image[], int Columns, int Rows, int x, int y)
-{
- int i, CurrentLocation;
-
- CurrentLocation = (y << 5) + (x >> 3);
- halLcdSetAddress(CurrentLocation);
- for (i = 0; i < Rows; i++)
- {
- halLcdDrawCurrentLine(Image, Columns);
- Image += Columns;
- CurrentLocation += 0x20;
- halLcdSetAddress(CurrentLocation);
- }
-}
-
-/**********************************************************************//**
- * @brief Writes Value to LCD CGram and MSP430 internal LCD table.
- *
- * Also updates the LcdAddress and LcdTableAddress to the correct values.
- *
- * @param *value Pointer to the line to be written to the LCD.
- *
- * @return none
- *************************************************************************/
-
-void halLcdDrawCurrentLine(const unsigned int *value, int Columns)
-{
- unsigned char i;
-
- //prepare to send image
- LCD_CS_RST_OUT &= ~LCD_CS_PIN; //CS = 0 --> Start Transfer
- for (i = 0; i < 3; i++)
- {
- while (!(UCB2IFG & UCTXIFG)) ; // Wait for TXIFG
- UCB2TXBUF = Draw_Block_Value_Macro[i]; // Load data
- }
- while (UCB2STAT & UCBUSY) ;
- LCD_CS_RST_OUT |= LCD_CS_PIN; //CS = 1 --> Stop Transfer
- LCD_CS_RST_OUT &= ~LCD_CS_PIN; //CS = 0 --> Start Transfer
- while (!(UCB2IFG & UCTXIFG)) ; // Wait for TXIFG
- UCB2TXBUF = Draw_Block_Value_Macro[3]; // Load data
-
- //send the image
- for (i = 0; i < Columns; i++)
- {
- // Make sure we are not writing outside LCD_MEM[]
- if (LcdTableAddress >= sizeof(LCD_MEM)){
- break;
- }
- LCD_MEM[LcdTableAddress++] = *value;
- while (!(UCB2IFG & UCTXIFG)) ; // Wait for TXIFG
- UCB2TXBUF = (*value) >> 8; // Load data
- while (!(UCB2IFG & UCTXIFG)) ; // Wait for TXIFG
- UCB2TXBUF = (*value++) & 0xFF; // Load data
- }
-
- while (UCB2STAT & UCBUSY) ;
- LCD_CS_RST_OUT |= LCD_CS_PIN; //CS = 1 --> Stop Transfer
-}
-
-/**********************************************************************//**
- * @brief Clears an image of size rows x columns starting at (x, y).
- *
- * @param Columns The size, in columns, of the image to be cleared.
- *
- * @param Rows The size, in rows, of the image to be cleared.
- *
- * @param x x-coordinate of the image to be cleared
- *
- * @param y y-coordinate of the image to be cleared
- *
- * @return none
- *************************************************************************/
-
-void halLcdClearImage(int Columns, int Rows, int x, int y)
-{
- int i, j, k, Current_Location;
-
- Current_Location = (y << 5) + (x >> 3);
- halLcdSetAddress(Current_Location);
-
- for (i = 0; i < Rows; i++)
- {
- //prepare to send image
- LCD_CS_RST_OUT &= ~LCD_CS_PIN; //CS = 0 --> Start Transfer
- for (k = 0; k < 3; k++)
- {
- while (!(UCB2IFG & UCTXIFG)) ; // Wait for TXIFG
- UCB2TXBUF = Draw_Block_Value_Macro[k]; // Load data
- }
- while (UCB2STAT & UCBUSY) ;
- LCD_CS_RST_OUT |= LCD_CS_PIN; //CS = 1 --> Stop Transfer
- LCD_CS_RST_OUT &= ~LCD_CS_PIN; //CS = 0 --> Start Transfer
- while (!(UCB2IFG & UCTXIFG)) ; // Wait for TXIFG
- UCB2TXBUF = Draw_Block_Value_Macro[3]; // Load data
-
- //send blank line
- for (j = 0; j < Columns; j++)
- {
- LCD_MEM[LcdTableAddress++] = 0x00;
- while (!(UCB2IFG & UCTXIFG)) ; // Wait for TXIFG
- UCB2TXBUF = 0x00; // Load data
- while (!(UCB2IFG & UCTXIFG)) ; // Wait for TXIFG
- UCB2TXBUF = 0x00; // Load data
- }
- while (UCB2STAT & UCBUSY) ;
- LCD_CS_RST_OUT |= LCD_CS_PIN; //CS = 1 --> Stop Transfer
-
- Current_Location += 0x20;
- halLcdSetAddress(Current_Location);
- }
-}
-
-/**********************************************************************//**
- * @brief Writes Value to LCD CGRAM. Pointers internal to the LCD
- * are also updated.
- *
- * @param Value The value to be written to the current LCD pointer
- *
- * @return none
- *************************************************************************/
-
-void halLcdDrawTextBlock(unsigned int Value)
-{
- int temp;
-
- Draw_Block_Value_Macro[4] = Value >> 8;
- Draw_Block_Value_Macro[5] = Value & 0xFF;
- LCD_MEM[LcdTableAddress] = Value;
-
- halLcdSendCommand(Draw_Block_Value_Macro);
-
- LcdAddress++;
- temp = LcdAddress >> 5; // Divided by 0x20
- temp = temp + (temp << 4);
- //Multiplied by (1+16) and added by the offset
- LcdTableAddress = temp + (LcdAddress & 0x1F);
-
- // If LcdAddress gets off the right edge, move to next line
- if ((LcdAddress & 0x1F) > 0x10)
- halLcdSetAddress((LcdAddress & 0xFFE0) + 0x20);
-
- if (LcdAddress >= LCD_Size)
- halLcdSetAddress(0);
-}
-
-/**********************************************************************//**
- * @brief Displays the string to the LCD starting at current location.
- *
- * Writes all the data to LCD_MEM first, then updates all corresponding
- * LCD CGRAM locations at once, in a continuous fashion.
- *
- * @param String[] The string to be displayed on LCD.
- *
- * @param TextStyle Value that specifies whether the string is to be
- * inverted or overwritten.
- * - Invert = 0x01
- * - Overwrite = 0x04
- *
- * @return none
- *************************************************************************/
-
-void halLcdPrint(char String[], unsigned char TextStyle)
-{
- int i, j, Counter = 0, BlockValue;
- int Address, LCD_MEM_Add, ActualAddress;
- int temp;
- char LookUpChar;
-
- ActualAddress = LcdAddress;
- Counter = LcdAddress & 0x1F;
- i = 0;
-
- while (String[i] != 0) // Stop on null character
- {
- LookUpChar = fonts_lookup[String[i]];
-
- for (j = 0; j < FONT_HEIGHT; j++)
- {
- Address = ActualAddress + j * 0x20;
- temp = Address >> 5;
- temp += (temp << 4);
-
- LCD_MEM_Add = temp + (Address & 0x1F);
-
- BlockValue = LCD_MEM[LCD_MEM_Add];
-
- if (TextStyle & GRAYSCALE_TEXT)
- {
- if (TextStyle & INVERT_TEXT)
- if (TextStyle & OVERWRITE_TEXT)
- BlockValue = 0xAAAA - GrayScale_fonts[LookUpChar * (FONT_HEIGHT + 1) + j];
- else
- BlockValue |= 0xAAAA - GrayScale_fonts[LookUpChar * (FONT_HEIGHT + 1) + j];
- else
- if (TextStyle & OVERWRITE_TEXT)
- BlockValue = GrayScale_fonts[LookUpChar * (FONT_HEIGHT + 1) + j];
- else
- BlockValue |= GrayScale_fonts[LookUpChar * (FONT_HEIGHT + 1) + j];
- }
- else
- {
- if (TextStyle & INVERT_TEXT)
- if (TextStyle & OVERWRITE_TEXT)
- BlockValue = 0xFFFF - fonts[LookUpChar * 13 + j];
- else
- BlockValue |= 0xFFFF - fonts[LookUpChar * 13 + j];
-
- else
- if (TextStyle & OVERWRITE_TEXT)
- BlockValue = fonts[LookUpChar * (FONT_HEIGHT + 1) + j];
- else
- BlockValue |= fonts[LookUpChar * (FONT_HEIGHT + 1) + j];
- }
- halLcdDrawBlock(Address, BlockValue);
- }
-
- Counter++;
- if (Counter == 17)
- {
- Counter = 0;
- ActualAddress += 0x20 * FONT_HEIGHT - 16;
- if (ActualAddress > LCD_Last_Pixel - 0x20 * FONT_HEIGHT)
- ActualAddress = 0;
- }
- else
- ActualAddress++;
- i++;
- }
- halLcdSetAddress(ActualAddress);
-
-}
-
-/**********************************************************************//**
- * @brief Displays the string to the LCD starting at (x,y) location.
- *
- * Writes all the data to LCD_MEM first, then updates all corresponding
- * LCD CGRAM locations at once, in a continuous fashion.
- *
- * @param String[] String to be displayed on LCD
- *
- * @param x x-coordinate of the write location on the LCD
- *
- * @param y y-coordinate of the write location on the LCD
- *
- * @param TextStyle Value that specifies whether the string is to be
- * inverted or overwritten.
- * - Invert = 0x01
- * - Overwrite = 0x04
- *************************************************************************/
-
-void halLcdPrintXY(char String[], int x, int y, unsigned char TextStyle)
-{
- //Each line increments by 0x20
- halLcdSetAddress((y << 5) + (x >> 3)); //Narrow down to 8 possible pixels
- halLcdPrint(String, TextStyle);
-}
-
-/**********************************************************************//**
- * @brief Displays a string on the LCD on the specified line.
- *
- * @param String[] The string to be displayed on LCD.
- *
- * @param Line The line on the LCD on which to print the string.
- *
- * @param TextStyle Value that specifies whether the string is to be
- * inverted or overwritten.
- * - Invert = 0x01
- * - Overwrite = 0x04
- *
- * @return none
- *************************************************************************/
-
-void halLcdPrintLine(char String[], unsigned char Line, unsigned char TextStyle)
-{
- int temp;
-
- temp = Line * FONT_HEIGHT;
- halLcdSetAddress(temp << 5); // 0x20 = 2^5
- halLcdPrint(String, TextStyle);
-}
-
-/**********************************************************************//**
- * @brief Prints a string beginning on a given line and column.
- *
- * @param String[] The string to be displayed on LCD.
- *
- * @param Line The line on which to print the string of text
- *
- * @param Col The column on which to print the string of text
- *
- * @param TextStyle Value that specifies whether the string is to be
- * inverted or overwritten.
- * - Invert = 0x01
- * - Overwrite = 0x04
- *
- * @return none
- *************************************************************************/
-
-void halLcdPrintLineCol(char String[], unsigned char Line, unsigned char Col,
- unsigned char TextStyle)
-{
- int temp;
-
- temp = Line * FONT_HEIGHT;
- temp <<= 5;
- temp += Col;
-
- halLcdSetAddress(temp); // 0x20 = 2^5
- halLcdPrint(String, TextStyle);
-}
-
-/**********************************************************************//**
- * @brief Draws a horizontral line from (x1,y) to (x2,y) of GrayScale level
- *
- * @param x1 x-coordinate of the first point
- *
- * @param x2 x-coordinate of the second point
- *
- * @param y y-coordinate of both points
- *
- * @param GrayScale Grayscale level of the horizontal line
- *
- * @return none
- *************************************************************************/
-
-void halLcdHLine(int x1, int x2, int y, unsigned char GrayScale)
-{
- int x_dir, x;
-
- if (x1 < x2)
- x_dir = 1;
- else
- x_dir = -1;
- x = x1;
- while (x != x2)
- {
- halLcdPixel(x, y, GrayScale);
- x += x_dir;
- }
-}
-
-/**********************************************************************//**
- * @brief Draws a vertical line from (x,y1) to (x,y2) of GrayScale level
- *
- * @param x x-coordinate of both points
- *
- * @param y1 y-coordinate of the first point
- *
- * @param y2 y-coordinate of the second point
- *
- * @param GrayScale GrayScale level of the vertical line
- *
- * @return none
- *************************************************************************/
-
-void halLcdVLine(int x, int y1, int y2, unsigned char GrayScale)
-{
- int y_dir, y;
-
- if (y1 < y2)
- y_dir = 1;
- else
- y_dir = -1;
- y = y1;
- while (y != y2)
- {
- halLcdPixel(x, y, GrayScale);
- y += y_dir;
- }
-}
-
-/**********************************************************************//**
- * @brief Draws a line from (x1,y1) to (x2,y2) of GrayScale level.
- *
- * Uses Bresenham's line algorithm.
- *
- * @param x1 x-coordinate of the first point
- *
- * @param y1 y-coordinate of the first point
- *
- * @param x2 x-coordinate of the second point
- *
- * @param y2 y-coordinate of the second point
- *
- * @param GrayScale Grayscale level of the line
- *
- * @return none
- *************************************************************************/
-
-void halLcdLine(int x1, int y1, int x2, int y2, unsigned char GrayScale)
-{
- int x, y, deltay, deltax, d;
- int x_dir, y_dir;
-
- if (x1 == x2)
- halLcdVLine(x1, y1, y2, GrayScale);
- else
- {
- if (y1 == y2)
- halLcdHLine(x1, x2, y1, GrayScale);
- else // a diagonal line
- {
- if (x1 > x2)
- x_dir = -1;
- else x_dir = 1;
- if (y1 > y2)
- y_dir = -1;
- else y_dir = 1;
-
- x = x1;
- y = y1;
- deltay = ABS(y2 - y1);
- deltax = ABS(x2 - x1);
-
- if (deltax >= deltay)
- {
- d = (deltay << 1) - deltax;
- while (x != x2)
- {
- halLcdPixel(x, y, GrayScale);
- if (d < 0)
- d += (deltay << 1);
- else
- {
- d += ((deltay - deltax) << 1);
- y += y_dir;
- }
- x += x_dir;
- }
- }
- else
- {
- d = (deltax << 1) - deltay;
- while (y != y2)
- {
- halLcdPixel(x, y, GrayScale);
- if (d < 0)
- d += (deltax << 1);
- else
- {
- d += ((deltax - deltay) << 1);
- x += x_dir;
- }
- y += y_dir;
- }
- }
- }
- }
-}
-
-/**********************************************************************//**
- * @brief Draw a circle of Radius with center at (x,y) of GrayScale level.
- *
- * Uses Bresenham's circle algorithm
- *
- * @param x x-coordinate of the circle's center point
- *
- * @param y y-coordinate of the circle's center point
- *
- * @param Radius Radius of the circle
- *
- * @param GrayScale Grayscale level of the circle
- *************************************************************************/
-
-void halLcdCircle(int x, int y, int Radius, int GrayScale)
-{
- int xx, yy, ddF_x, ddF_y, f;
-
- ddF_x = 0;
- ddF_y = -(2 * Radius);
- f = 1 - Radius;
-
- xx = 0;
- yy = Radius;
- halLcdPixel(x + xx, y + yy, GrayScale);
- halLcdPixel(x + xx, y - yy, GrayScale);
- halLcdPixel(x - xx, y + yy, GrayScale);
- halLcdPixel(x - xx, y - yy, GrayScale);
- halLcdPixel(x + yy, y + xx, GrayScale);
- halLcdPixel(x + yy, y - xx, GrayScale);
- halLcdPixel(x - yy, y + xx, GrayScale);
- halLcdPixel(x - yy, y - xx, GrayScale);
- while (xx < yy)
- {
- if (f >= 0)
- {
- yy--;
- ddF_y += 2;
- f += ddF_y;
- }
- xx++;
- ddF_x += 2;
- f += ddF_x + 1;
- halLcdPixel(x + xx, y + yy, GrayScale);
- halLcdPixel(x + xx, y - yy, GrayScale);
- halLcdPixel(x - xx, y + yy, GrayScale);
- halLcdPixel(x - xx, y - yy, GrayScale);
- halLcdPixel(x + yy, y + xx, GrayScale);
- halLcdPixel(x + yy, y - xx, GrayScale);
- halLcdPixel(x - yy, y + xx, GrayScale);
- halLcdPixel(x - yy, y - xx, GrayScale);
- }
-}
-
-/**********************************************************************//**
- * @brief Scrolls a single row of pixels one column to the left.
- *
- * The column that is scrolled out of the left side of the LCD will be
- * displayed the right side of the LCD.
- *
- * @param y The row of pixels to scroll. y = 0 is at the top-left
- * corner of the LCD.
- *
- * @return none
- *************************************************************************/
-
-void halLcdScrollRow(int y)
-{
- int i, Address, LcdTableAddressTemp;
- unsigned int temp;
-
- Address = y << 5;
-
- halLcdSetAddress(Address);
-
- //Multiplied by (1+16) and added by the offset
- LcdTableAddressTemp = y + (y << 4);
- temp = ((LCD_MEM[LcdTableAddressTemp] & 0x0003) << 14);
-
- for (i = 0; i < 0x10; i++)
- halLcdDrawCurrentBlock(((LCD_MEM[LcdTableAddressTemp + i] & 0xFFFC) >> 2) \
- + ((LCD_MEM[LcdTableAddressTemp + i + 1] & 0x0003) << 14));
-
- halLcdDrawCurrentBlock(((LCD_MEM[LcdTableAddressTemp + 0x10] & 0xFFFC) >> 2) + temp);
-}
-
-/**********************************************************************//**
- * @brief Scrolls multiple rows of pixels, yStart to yEnd,
- * one column to the left.
- *
- * The column that is scrolled out of the left side of the LCD will be
- * displayed the right side of the LCD. y = 0 is at the top-left of the
- * LCD screen.
- *
- * @param yStart The beginning row to be scrolled
- *
- * @param yEnd The last row to be scrolled
- *
- * @return none
- *************************************************************************/
-
-void halLcdHScroll(int yStart, int yEnd)
-{
- int i;
-
- for (i = yStart; i < yEnd + 1; i++)
- halLcdScrollRow(i);
-}
-
-/**********************************************************************//**
- * @brief Scrolls a line of text one column to the left.
- *
- * @param Line The line of text to be scrolled.
- *
- * @return none
- *************************************************************************/
-
-void halLcdScrollLine(int Line)
-{
- int i, Row;
-
- Row = Line * FONT_HEIGHT;
-
- for (i = Row; i < Row + FONT_HEIGHT; i++)
- halLcdScrollRow(i);
-}
-
+/*******************************************************************************
+ *
+ * hal_lcd.c
+ *
+ * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of Texas Instruments Incorporated nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************/
+
+#include "contiki-conf.h"
+
+#include "hal_MSP-EXP430F5438.h"
+#include "hal_lcd_fonts.h"
+
+unsigned char LcdInitMacro[] = {
+ 0x74, 0x00, 0x00, 0x76, 0x00, 0x01, // R00 start oscillation
+ 0x74, 0x00, 0x01, 0x76, 0x00, 0x0D, // R01 driver output control
+ 0x74, 0x00, 0x02, 0x76, 0x00, 0x4C, // R02 LCD - driving waveform control
+ 0x74, 0x00, 0x03, 0x76, 0x12, 0x14, // R03 Power control
+ 0x74, 0x00, 0x04, 0x76, 0x04, 0x66, // R04 Contrast control
+ 0x74, 0x00, 0x05, 0x76, 0x00, 0x10, // R05 Entry mode
+ 0x74, 0x00, 0x06, 0x76, 0x00, 0x00, // R06 RAM data write mask
+ 0x74, 0x00, 0x07, 0x76, 0x00, 0x15, // R07 Display control
+ 0x74, 0x00, 0x08, 0x76, 0x00, 0x03, // R08 Cursor Control
+ 0x74, 0x00, 0x09, 0x76, 0x00, 0x00, // R09 RAM data write mask
+ 0x74, 0x00, 0x0A, 0x76, 0x00, 0x15, // R0A
+ 0x74, 0x00, 0x0B, 0x76, 0x00, 0x03, // R0B Horizontal Cursor Position
+ 0x74, 0x00, 0x0C, 0x76, 0x00, 0x03, // R0C Vertical Cursor Position
+ 0x74, 0x00, 0x0D, 0x76, 0x00, 0x00, // R0D
+ 0x74, 0x00, 0x0E, 0x76, 0x00, 0x15, // R0E
+ 0x74, 0x00, 0x0F, 0x76, 0x00, 0x03, // R0F
+ 0x74, 0x00, 0x10, 0x76, 0x00, 0x15, // R0E
+ 0x74, 0x00, 0x11, 0x76, 0x00, 0x03, // R0F
+};
+
+unsigned char Read_Block_Address_Macro[] = {0x74, 0x00, 0x12, 0x77, 0x00, 0x00};
+unsigned char Draw_Block_Value_Macro[] = {0x74, 0x00, 0x12, 0x76, 0xFF, 0xFF};
+unsigned char Draw_Block_Address_Macro[] = {0x74, 0x00, 0x11, 0x76, 0x00, 0x00};
+
+unsigned int LcdAddress = 0, LcdTableAddress = 0;
+unsigned char contrast = 0x66;
+unsigned char backlight = 8;
+int LCD_MEM[110 * 17]; //This array stores a copy of all data on the LCD
+//screen. If memory is an issue though, this array
+//can be eliminated and the halLcdReadBlock()
+//command can be used instead whenever you are
+//manipulating the currently displayed data.
+
+/**********************************************************************//**
+ * @brief Sends 3+3 bytes of data to the LCD using the format specified
+ * by the LCD Guide.
+ *
+ * @param Data[] Data array for transmission
+ *
+ * @return none
+ *************************************************************************/
+
+void halLcdSendCommand(unsigned char Data[])
+{
+ unsigned char i;
+
+ LCD_CS_RST_OUT &= ~LCD_CS_PIN; //CS = 0 --> Start Transfer
+ for (i = 0; i < 6; i++)
+ {
+ while (!(UCB2IFG & UCTXIFG)) ; // Wait for TXIFG
+ UCB2TXBUF = Data[i]; // Load data
+
+ if (i == 2) //Pull CS up after 3 bytes
+ {
+ while (UCB2STAT & UCBUSY) ;
+ LCD_CS_RST_OUT |= LCD_CS_PIN; //CS = 1 --> Stop Transfer
+ LCD_CS_RST_OUT &= ~LCD_CS_PIN; //CS = 0 --> Start Transfer
+ }
+ }
+ while (UCB2STAT & UCBUSY) ;
+ LCD_CS_RST_OUT |= LCD_CS_PIN; //CS = 1 --> Stop Transfer
+}
+
+/**********************************************************************//**
+ * @brief Initializes the USCI module, LCD device for communication.
+ *
+ * - Sets up the SPI2C Communication Module
+ * - Performs Hitachi LCD Initialization Procedure
+ *
+ * @param none
+ *
+ * @return none
+ *************************************************************************/
+
+void halLcdInit(void)
+{
+ volatile unsigned int i = 0;
+
+ LCD_CS_RST_OUT |= LCD_CS_PIN | LCD_RESET_PIN;
+ LCD_CS_RST_DIR |= LCD_CS_PIN | LCD_RESET_PIN;
+
+ LCD_BACKLT_SEL |= LCD_BACKLIGHT_PIN;
+
+ LCD_CS_RST_OUT &= ~LCD_RESET_PIN; // Reset LCD
+ __delay_cycles(0x47FF); //Reset Pulse
+ LCD_CS_RST_OUT |= LCD_RESET_PIN;
+
+ // UCLK,MOSI setup, SOMI cleared
+ LCD_SPI_SEL |= LCD_MOSI_PIN + LCD_CLK_PIN;
+ LCD_SPI_SEL &= ~LCD_MISO_PIN;
+ LCD_SPI_DIR &= ~(LCD_MISO_PIN + LCD_MOSI_PIN); // Pin direction controlled by module,
+ // Set both pins to input as default
+
+ // Initialize the USCI_B2 module for SPI operation
+ UCB2CTL1 = UCSWRST; // Hold USCI in SW reset mode while configuring
+ // it
+ UCB2CTL0 = UCMST + UCSYNC + UCCKPL + UCMSB; // 3-pin, 8-bit SPI master
+ UCB2CTL1 |= UCSSEL_2; // SMCLK
+ UCB2BR0 = 4; // Note: Do not exceed D/S spec for UCLK!
+ UCB2BR1 = 0;
+ UCB2CTL1 &= ~UCSWRST; // Release USCI state machine
+ UCB2IFG &= ~UCRXIFG;
+
+ // Wake-up the LCD as per datasheet specifications
+ halLcdActive();
+
+ // LCD Initialization Routine Using Predefined Macros
+ halLcdSendCommand(&LcdInitMacro[1 * 6]);
+ halLcdSendCommand(&LcdInitMacro[2 * 6]);
+ halLcdSendCommand(&LcdInitMacro[4 * 6]);
+ halLcdSendCommand(&LcdInitMacro[5 * 6]);
+ halLcdSendCommand(&LcdInitMacro[6 * 6]);
+ halLcdSendCommand(&LcdInitMacro[7 * 6]);
+
+}
+
+/**********************************************************************//**
+ * @brief Shuts down the LCD display and hdisables the USCI communication.
+ *
+ * @param none
+ *
+ * @return none
+ *************************************************************************/
+
+void halLcdShutDown(void)
+{
+ halLcdStandby();
+
+ LCD_CS_RST_DIR |= LCD_CS_PIN | LCD_RESET_PIN;
+ LCD_CS_RST_OUT &= ~(LCD_CS_PIN | LCD_RESET_PIN);
+ LCD_CS_RST_OUT &= ~LCD_RESET_PIN;
+
+ LCD_SPI_SEL &= ~(LCD_MOSI_PIN + LCD_CLK_PIN + LCD_MISO_PIN);
+ LCD_CS_RST_DIR |= LCD_MOSI_PIN + LCD_CLK_PIN + LCD_MISO_PIN;
+ LCD_CS_RST_OUT &= ~(LCD_MOSI_PIN + LCD_CLK_PIN + LCD_MISO_PIN);
+
+ UCB2CTL0 = UCSWRST;
+}
+
+/**********************************************************************//**
+ * @brief Initializes the LCD backlight PWM signal.
+ *
+ * @param none
+ *
+ * @return none
+ *
+ *************************************************************************/
+
+void halLcdBackLightInit(void)
+{
+ LCD_BACKLT_DIR |= LCD_BACKLIGHT_PIN;
+ LCD_BACKLT_OUT |= LCD_BACKLIGHT_PIN;
+ LCD_BACKLT_SEL |= LCD_BACKLIGHT_PIN;
+
+ TA0CCTL3 = OUTMOD_7;
+ TA0CCR3 = TA0CCR0 >> 1;
+ backlight = 8;
+
+ TA0CCR0 = 400;
+ TA0CTL = TASSEL_2 + MC_1;
+}
+
+/**********************************************************************//**
+ * @brief Get function for the backlight PWM's duty cycle.
+ *
+ * @param none
+ *
+ * @return backlight One of the the 17 possible settings - valued 0 to 16.
+ *
+ *************************************************************************/
+
+unsigned int halLcdGetBackLight(void)
+{
+ return backlight;
+}
+
+/**********************************************************************//**
+ * @brief Set function for the backlight PWM's duty cycle
+ *
+ * @param BackLightLevel The target backlight duty cycle - valued 0 to 16.
+ *
+ * @return none
+ *************************************************************************/
+
+void halLcdSetBackLight(unsigned char BackLightLevel)
+{
+ unsigned int dutyCycle = 0, i, dummy;
+
+ if (BackLightLevel > 0)
+ {
+ TA0CCTL3 = OUTMOD_7;
+ dummy = (TA0CCR0 >> 4);
+
+ for (i = 0; i < BackLightLevel; i++)
+ dutyCycle += dummy;
+
+ TA0CCR3 = dutyCycle;
+
+ // If the backlight was previously turned off, turn it on.
+ if (!backlight)
+ TA0CTL |= MC0;
+ }
+ else
+ {
+ TA0CCTL3 = 0;
+ TA0CTL &= ~MC0;
+ }
+ backlight = BackLightLevel;
+}
+
+/**********************************************************************//**
+ * @brief Turns off the backlight.
+ *
+ * Clears the respective GPIO and timer settings.
+ *
+ * @param none
+ *
+ * @return none
+ *************************************************************************/
+
+void halLcdShutDownBackLight(void)
+{
+ LCD_BACKLT_DIR |= LCD_BACKLIGHT_PIN;
+ LCD_BACKLT_OUT &= ~(LCD_BACKLIGHT_PIN);
+ LCD_BACKLT_SEL &= ~LCD_BACKLIGHT_PIN;
+
+ TA0CCTL3 = 0;
+ TA0CTL = 0;
+
+ backlight = 0;
+}
+
+/**********************************************************************//**
+ * @brief Set function for the contrast level of the LCD.
+ *
+ * @param ContrastLevel The target contrast level
+ *
+ * @return none
+ *************************************************************************/
+
+void halLcdSetContrast(unsigned char ContrastLevel)
+{
+ if (ContrastLevel > 127) ContrastLevel = 127;
+ if (ContrastLevel < 70) ContrastLevel = 70;
+ LcdInitMacro[0x04 * 6 + 5] = ContrastLevel;
+ halLcdSendCommand(&LcdInitMacro[0x04 * 6]);
+}
+
+/**********************************************************************//**
+ * @brief Get function for the contrast level of the LCD.
+ *
+ * @param none
+ *
+ * @return ContrastLevel The LCD constrast level
+ *************************************************************************/
+
+unsigned char halLcdGetContrast(void)
+{
+ return LcdInitMacro[0x04 * 6 + 5];
+}
+
+/**********************************************************************//**
+ * @brief Turns the LCD cursor on at the current text position.
+ *
+ * @param none
+ *
+ * @return none
+ *************************************************************************/
+
+void halLcdCursor(void)
+{
+ LcdInitMacro[8 * 6 + 5] ^= BIT2;
+ halLcdSendCommand(&LcdInitMacro[8 * 6]);
+
+ LcdInitMacro[0x0B * 6 + 5] = ((LcdAddress & 0x1F) << 3);
+ LcdInitMacro[0x0B * 6 + 4] = ((LcdAddress & 0x1F) << 3) + 3;
+ LcdInitMacro[0x0C * 6 + 5] = (LcdAddress >> 5);
+ LcdInitMacro[0x0C * 6 + 4] = (LcdAddress >> 5) + 7;
+ halLcdSendCommand(&LcdInitMacro[0x0B * 6]);
+ halLcdSendCommand(&LcdInitMacro[0x0C * 6]);
+
+ halLcdSetAddress(LcdAddress);
+}
+
+/**********************************************************************//**
+ * @brief Turns off the LCD cursor.
+ *
+ * @param none
+ *
+ * @return none
+ *************************************************************************/
+
+void halLcdCursorOff(void)
+{
+ LcdInitMacro[8 * 6 + 5] &= ~BIT2;
+ halLcdSendCommand(&LcdInitMacro[8 * 6]);
+}
+
+/**********************************************************************//**
+ * @brief Inverts the grayscale values of the LCD display (Black <> white).
+ *
+ * @param none
+ *
+ * @return none
+ *************************************************************************/
+
+void halLcdReverse(void)
+{
+ LcdInitMacro[7 * 6 + 5] ^= BIT1;
+ halLcdSendCommand(&LcdInitMacro[7 * 6]);
+}
+
+/**********************************************************************//**
+ * @brief Sets the LCD in standby mode to reduce power consumption.
+ *
+ * @param none
+ *
+ * @return none
+ *************************************************************************/
+
+void halLcdStandby(void)
+{
+ LcdInitMacro[3 * 6 + 5] &= (~BIT3) & (~BIT2);
+ LcdInitMacro[3 * 6 + 5] |= BIT0;
+ halLcdSendCommand(&LcdInitMacro[3 * 6]);
+}
+
+/**********************************************************************//**
+ * @brief Puts the LCD into active mode.
+ *
+ * @param none
+ *
+ * @return none
+ *************************************************************************/
+
+void halLcdActive(void)
+{
+ halLcdSendCommand(LcdInitMacro); // R00 start oscillation
+
+ // Wait a minimum of 25ms after issuing "start oscillation"
+ // command (to accomodate for MCLK up to 25MHz)
+ {
+ int i;
+ for(i = 0; i < 5; ++i) {
+ __delay_cycles(50000);
+ }
+ }
+
+ LcdInitMacro[3 * 6 + 5] |= BIT3;
+ LcdInitMacro[3 * 6 + 5] &= ~BIT0;
+ halLcdSendCommand(&LcdInitMacro[3 * 6]); // R03 Power control
+}
+
+/**********************************************************************//**
+ * @brief Sets the pointer location in the LCD.
+ *
+ * - LcdAddress = Address
+ * - LcdTableAddress = Correct Address Row + Column
+ * = (Address / 0x20)* 17 + Column
+ *
+ * @param Address The target pointer location in the LCD.
+ *
+ * @return none
+ *************************************************************************/
+
+void halLcdSetAddress(int Address)
+{
+ int temp;
+
+ Draw_Block_Address_Macro[4] = Address >> 8;
+ Draw_Block_Address_Macro[5] = Address & 0xFF;
+ halLcdSendCommand(Draw_Block_Address_Macro);
+ LcdAddress = Address;
+ temp = Address >> 5; // Divided by 0x20
+ temp = temp + (temp << 4);
+ //Multiplied by (1+16) and added by the offset
+ LcdTableAddress = temp + (Address & 0x1F);
+}
+
+/**********************************************************************//**
+ * @brief Draws a block at the specified LCD address.
+ *
+ * A block is the smallest addressable memory on the LCD and is
+ * equivalent to 8 pixels, each of which is represented by 2 bits
+ * that represent a grayscale value between 00b and 11b.
+ *
+ * @param Address The address at which to draw the block.
+ *
+ * @param Value The value of the block
+ *
+ * @return none
+ *************************************************************************/
+
+void halLcdDrawBlock(unsigned int Address, unsigned int Value)
+{
+ halLcdSetAddress(Address);
+ halLcdDrawCurrentBlock(Value);
+}
+
+/**********************************************************************//**
+ * @brief Writes Value to LCD CGram and MSP430 internal LCD table.
+ *
+ * Also updates the LcdAddress and LcdTableAddress to the correct values.
+ *
+ * @param Value The value of the block to be written to the LCD.
+ *
+ * @return none
+ *************************************************************************/
+
+void halLcdDrawCurrentBlock(unsigned int Value)
+{
+ int temp;
+
+ Draw_Block_Value_Macro[4] = Value >> 8;
+ Draw_Block_Value_Macro[5] = Value & 0xFF;
+ LCD_MEM[LcdTableAddress] = Value;
+
+ halLcdSendCommand(Draw_Block_Value_Macro);
+
+ LcdAddress++;
+ temp = LcdAddress >> 5; // Divided by 0x20
+ temp = temp + (temp << 4);
+ // Multiplied by (1+16) and added by the offset
+ LcdTableAddress = temp + (LcdAddress & 0x1F);
+
+ // If LcdAddress gets off the right edge, move to next line
+ if ((LcdAddress & 0x1F) > 0x11)
+ halLcdSetAddress((LcdAddress & 0xFFE0) + 0x20);
+ if (LcdAddress == LCD_Size)
+ halLcdSetAddress(0);
+}
+
+/**********************************************************************//**
+ * @brief Returns the LCD CGRAM value at location Address.
+ *
+ * @param Address The address of the block to be read from the LCD.
+ *
+ * @return Value The value held at the specified address.
+ *************************************************************************/
+
+int halLcdReadBlock(unsigned int Address)
+{
+ int i = 0, Value = 0, ReadData[7];
+
+ halLcdSetAddress(Address);
+ halLcdSendCommand(Read_Block_Address_Macro);
+
+ LCD_CS_RST_OUT &= ~LCD_CS_PIN; // start transfer CS=0
+ UCB2TXBUF = 0x77; // Transmit first character 0x77
+
+ while (!(UCB2IFG & UCTXIFG)) ;
+ while (UCB2STAT & UCBUSY) ;
+
+ //Read 5 dummies values and 2 valid address data
+ LCD_SPI_SEL &= ~LCD_MOSI_PIN; //Change SPI2C Dir
+ LCD_SPI_SEL |= LCD_MISO_PIN;
+
+ for (i = 0; i < 7; i++)
+ {
+ UCB2IFG &= ~UCRXIFG;
+ UCB2TXBUF = 1; // load dummy byte 1 for clk
+ while (!(UCB2IFG & UCRXIFG)) ;
+ ReadData[i] = UCB2RXBUF;
+ }
+ LCD_CS_RST_OUT |= LCD_CS_PIN; // Stop Transfer CS = 1
+
+ LCD_SPI_SEL |= LCD_MOSI_PIN; //Change SPI2C Dir
+ LCD_SPI_SEL &= ~LCD_MISO_PIN;
+ LCD_CS_RST_DIR |= LCD_MOSI_PIN + LCD_CLK_PIN;
+ LCD_CS_RST_DIR &= ~LCD_MISO_PIN;
+
+ Value = (ReadData[5] << 8) + ReadData[6];
+ return Value;
+}
+
+/**********************************************************************//**
+ * @brief Draw a Pixel of grayscale at coordinate (x,y) to LCD
+ *
+ * @param x x-coordinate for grayscale value
+ *
+ * @param y y-coordinate for grayscale value
+ *
+ * @param GrayScale The intended grayscale value of the pixel - one of
+ * four possible settings.
+ *
+ * @return none
+ *************************************************************************/
+
+void halLcdPixel(int x, int y, unsigned char GrayScale)
+{
+ int Address, Value;
+ unsigned char offset;
+
+ //Each line increments by 0x20
+ if ((x >= 0) && (x < LCD_COL) && (y >= 0) && (y < LCD_ROW))
+ {
+ Address = (y << 5) + (x >> 3); //Narrow down to 8 possible pixels
+
+ Value = LCD_MEM[(y << 4) + y + (x >> 3)]; //y * 17 --> row. x>>3 --> column
+
+ offset = (x & 0x07) << 1; //3 LSBs = pos. within the 8 columns
+ Value &= ~(3 << offset); //clear out the corresponding bits
+ Value |= GrayScale << offset; //set pixel to GrayScale level
+
+ halLcdDrawBlock(Address, Value);
+ }
+}
+
+/**********************************************************************//**
+ * @brief Clears entire LCD CGRAM as well as LCD_MEM.
+ *
+ * @param none
+ *
+ * @return none
+ *************************************************************************/
+
+void halLcdClearScreen(void)
+{
+ int i, j, k, Current_Location = 0;
+
+ halLcdSetAddress(0);
+
+ for (i = 0; i < 110; i++)
+ {
+ //prepare to send image
+ LCD_CS_RST_OUT &= ~LCD_CS_PIN; //CS = 0 --> Start Transfer
+ for (k = 0; k < 3; k++)
+ {
+ while (!(UCB2IFG & UCTXIFG)) ; // Wait for TXIFG
+ UCB2TXBUF = Draw_Block_Value_Macro[k]; // Load data
+ }
+ while (UCB2STAT & UCBUSY) ;
+ LCD_CS_RST_OUT |= LCD_CS_PIN; //CS = 1 --> Stop Transfer
+ LCD_CS_RST_OUT &= ~LCD_CS_PIN; //CS = 0 --> Start Transfer
+ while (!(UCB2IFG & UCTXIFG)) ; // Wait for TXIFG
+ UCB2TXBUF = Draw_Block_Value_Macro[3]; // Load data
+
+ //send blank line
+ for (j = 0; j < 17; j++)
+ {
+ LCD_MEM[LcdTableAddress++] = 0x00;
+ while (!(UCB2IFG & UCTXIFG)) ; // Wait for TXIFG
+ UCB2TXBUF = 0x00; // Load data
+ while (!(UCB2IFG & UCTXIFG)) ; // Wait for TXIFG
+ UCB2TXBUF = 0x00; // Load data
+ }
+ //Clear the partially visible block at the edge of the screen
+ while (!(UCB2IFG & UCTXIFG)) ; // Wait for TXIFG
+ UCB2TXBUF = 0x00; // Load data
+ while (!(UCB2IFG & UCTXIFG)) ; // Wait for TXIFG
+ UCB2TXBUF = 0x00; // Load data
+ while (UCB2STAT & UCBUSY) ;
+ LCD_CS_RST_OUT |= LCD_CS_PIN; //CS = 1 --> Stop Transfer
+
+ Current_Location += 0x20;
+ halLcdSetAddress(Current_Location);
+ }
+
+ halLcdSetAddress(0);
+}
+
+/**********************************************************************//**
+ * @brief Loads an image of size = rows * columns, starting at the
+ * coordinate (x,y).
+ *
+ * @param Image[] The image to be loaded
+ *
+ * @param Rows The number of rows in the image. Size = Rows * Columns.
+ *
+ * @param Columns The number of columns in the image. Size = Rows * Columns.
+ *
+ * @param x x-coordinate of the image's starting location
+ *
+ * @param y y-coordinate of the image's starting location
+ *
+ * @return none
+ *************************************************************************/
+
+void halLcdImage(const unsigned int Image[], int Columns, int Rows, int x, int y)
+{
+ int i, CurrentLocation;
+
+ CurrentLocation = (y << 5) + (x >> 3);
+ halLcdSetAddress(CurrentLocation);
+ for (i = 0; i < Rows; i++)
+ {
+ halLcdDrawCurrentLine(Image, Columns);
+ Image += Columns;
+ CurrentLocation += 0x20;
+ halLcdSetAddress(CurrentLocation);
+ }
+}
+
+/**********************************************************************//**
+ * @brief Writes Value to LCD CGram and MSP430 internal LCD table.
+ *
+ * Also updates the LcdAddress and LcdTableAddress to the correct values.
+ *
+ * @param *value Pointer to the line to be written to the LCD.
+ *
+ * @return none
+ *************************************************************************/
+
+void halLcdDrawCurrentLine(const unsigned int *value, int Columns)
+{
+ unsigned char i;
+
+ //prepare to send image
+ LCD_CS_RST_OUT &= ~LCD_CS_PIN; //CS = 0 --> Start Transfer
+ for (i = 0; i < 3; i++)
+ {
+ while (!(UCB2IFG & UCTXIFG)) ; // Wait for TXIFG
+ UCB2TXBUF = Draw_Block_Value_Macro[i]; // Load data
+ }
+ while (UCB2STAT & UCBUSY) ;
+ LCD_CS_RST_OUT |= LCD_CS_PIN; //CS = 1 --> Stop Transfer
+ LCD_CS_RST_OUT &= ~LCD_CS_PIN; //CS = 0 --> Start Transfer
+ while (!(UCB2IFG & UCTXIFG)) ; // Wait for TXIFG
+ UCB2TXBUF = Draw_Block_Value_Macro[3]; // Load data
+
+ //send the image
+ for (i = 0; i < Columns; i++)
+ {
+ // Make sure we are not writing outside LCD_MEM[]
+ if (LcdTableAddress >= sizeof(LCD_MEM)){
+ break;
+ }
+ LCD_MEM[LcdTableAddress++] = *value;
+ while (!(UCB2IFG & UCTXIFG)) ; // Wait for TXIFG
+ UCB2TXBUF = (*value) >> 8; // Load data
+ while (!(UCB2IFG & UCTXIFG)) ; // Wait for TXIFG
+ UCB2TXBUF = (*value++) & 0xFF; // Load data
+ }
+
+ while (UCB2STAT & UCBUSY) ;
+ LCD_CS_RST_OUT |= LCD_CS_PIN; //CS = 1 --> Stop Transfer
+}
+
+/**********************************************************************//**
+ * @brief Clears an image of size rows x columns starting at (x, y).
+ *
+ * @param Columns The size, in columns, of the image to be cleared.
+ *
+ * @param Rows The size, in rows, of the image to be cleared.
+ *
+ * @param x x-coordinate of the image to be cleared
+ *
+ * @param y y-coordinate of the image to be cleared
+ *
+ * @return none
+ *************************************************************************/
+
+void halLcdClearImage(int Columns, int Rows, int x, int y)
+{
+ int i, j, k, Current_Location;
+
+ Current_Location = (y << 5) + (x >> 3);
+ halLcdSetAddress(Current_Location);
+
+ for (i = 0; i < Rows; i++)
+ {
+ //prepare to send image
+ LCD_CS_RST_OUT &= ~LCD_CS_PIN; //CS = 0 --> Start Transfer
+ for (k = 0; k < 3; k++)
+ {
+ while (!(UCB2IFG & UCTXIFG)) ; // Wait for TXIFG
+ UCB2TXBUF = Draw_Block_Value_Macro[k]; // Load data
+ }
+ while (UCB2STAT & UCBUSY) ;
+ LCD_CS_RST_OUT |= LCD_CS_PIN; //CS = 1 --> Stop Transfer
+ LCD_CS_RST_OUT &= ~LCD_CS_PIN; //CS = 0 --> Start Transfer
+ while (!(UCB2IFG & UCTXIFG)) ; // Wait for TXIFG
+ UCB2TXBUF = Draw_Block_Value_Macro[3]; // Load data
+
+ //send blank line
+ for (j = 0; j < Columns; j++)
+ {
+ LCD_MEM[LcdTableAddress++] = 0x00;
+ while (!(UCB2IFG & UCTXIFG)) ; // Wait for TXIFG
+ UCB2TXBUF = 0x00; // Load data
+ while (!(UCB2IFG & UCTXIFG)) ; // Wait for TXIFG
+ UCB2TXBUF = 0x00; // Load data
+ }
+ while (UCB2STAT & UCBUSY) ;
+ LCD_CS_RST_OUT |= LCD_CS_PIN; //CS = 1 --> Stop Transfer
+
+ Current_Location += 0x20;
+ halLcdSetAddress(Current_Location);
+ }
+}
+
+/**********************************************************************//**
+ * @brief Writes Value to LCD CGRAM. Pointers internal to the LCD
+ * are also updated.
+ *
+ * @param Value The value to be written to the current LCD pointer
+ *
+ * @return none
+ *************************************************************************/
+
+void halLcdDrawTextBlock(unsigned int Value)
+{
+ int temp;
+
+ Draw_Block_Value_Macro[4] = Value >> 8;
+ Draw_Block_Value_Macro[5] = Value & 0xFF;
+ LCD_MEM[LcdTableAddress] = Value;
+
+ halLcdSendCommand(Draw_Block_Value_Macro);
+
+ LcdAddress++;
+ temp = LcdAddress >> 5; // Divided by 0x20
+ temp = temp + (temp << 4);
+ //Multiplied by (1+16) and added by the offset
+ LcdTableAddress = temp + (LcdAddress & 0x1F);
+
+ // If LcdAddress gets off the right edge, move to next line
+ if ((LcdAddress & 0x1F) > 0x10)
+ halLcdSetAddress((LcdAddress & 0xFFE0) + 0x20);
+
+ if (LcdAddress >= LCD_Size)
+ halLcdSetAddress(0);
+}
+
+/**********************************************************************//**
+ * @brief Displays the string to the LCD starting at current location.
+ *
+ * Writes all the data to LCD_MEM first, then updates all corresponding
+ * LCD CGRAM locations at once, in a continuous fashion.
+ *
+ * @param String[] The string to be displayed on LCD.
+ *
+ * @param TextStyle Value that specifies whether the string is to be
+ * inverted or overwritten.
+ * - Invert = 0x01
+ * - Overwrite = 0x04
+ *
+ * @return none
+ *************************************************************************/
+
+void halLcdPrint(char String[], unsigned char TextStyle)
+{
+ int i, j, Counter = 0, BlockValue;
+ int Address, LCD_MEM_Add, ActualAddress;
+ int temp;
+ char LookUpChar;
+
+ ActualAddress = LcdAddress;
+ Counter = LcdAddress & 0x1F;
+ i = 0;
+
+ while (String[i] != 0) // Stop on null character
+ {
+ LookUpChar = fonts_lookup[String[i]];
+
+ for (j = 0; j < FONT_HEIGHT; j++)
+ {
+ Address = ActualAddress + j * 0x20;
+ temp = Address >> 5;
+ temp += (temp << 4);
+
+ LCD_MEM_Add = temp + (Address & 0x1F);
+
+ BlockValue = LCD_MEM[LCD_MEM_Add];
+
+ if (TextStyle & GRAYSCALE_TEXT)
+ {
+ if (TextStyle & INVERT_TEXT)
+ if (TextStyle & OVERWRITE_TEXT)
+ BlockValue = 0xAAAA - GrayScale_fonts[LookUpChar * (FONT_HEIGHT + 1) + j];
+ else
+ BlockValue |= 0xAAAA - GrayScale_fonts[LookUpChar * (FONT_HEIGHT + 1) + j];
+ else
+ if (TextStyle & OVERWRITE_TEXT)
+ BlockValue = GrayScale_fonts[LookUpChar * (FONT_HEIGHT + 1) + j];
+ else
+ BlockValue |= GrayScale_fonts[LookUpChar * (FONT_HEIGHT + 1) + j];
+ }
+ else
+ {
+ if (TextStyle & INVERT_TEXT)
+ if (TextStyle & OVERWRITE_TEXT)
+ BlockValue = 0xFFFF - fonts[LookUpChar * 13 + j];
+ else
+ BlockValue |= 0xFFFF - fonts[LookUpChar * 13 + j];
+
+ else
+ if (TextStyle & OVERWRITE_TEXT)
+ BlockValue = fonts[LookUpChar * (FONT_HEIGHT + 1) + j];
+ else
+ BlockValue |= fonts[LookUpChar * (FONT_HEIGHT + 1) + j];
+ }
+ halLcdDrawBlock(Address, BlockValue);
+ }
+
+ Counter++;
+ if (Counter == 17)
+ {
+ Counter = 0;
+ ActualAddress += 0x20 * FONT_HEIGHT - 16;
+ if (ActualAddress > LCD_Last_Pixel - 0x20 * FONT_HEIGHT)
+ ActualAddress = 0;
+ }
+ else
+ ActualAddress++;
+ i++;
+ }
+ halLcdSetAddress(ActualAddress);
+
+}
+
+/**********************************************************************//**
+ * @brief Displays the string to the LCD starting at (x,y) location.
+ *
+ * Writes all the data to LCD_MEM first, then updates all corresponding
+ * LCD CGRAM locations at once, in a continuous fashion.
+ *
+ * @param String[] String to be displayed on LCD
+ *
+ * @param x x-coordinate of the write location on the LCD
+ *
+ * @param y y-coordinate of the write location on the LCD
+ *
+ * @param TextStyle Value that specifies whether the string is to be
+ * inverted or overwritten.
+ * - Invert = 0x01
+ * - Overwrite = 0x04
+ *************************************************************************/
+
+void halLcdPrintXY(char String[], int x, int y, unsigned char TextStyle)
+{
+ //Each line increments by 0x20
+ halLcdSetAddress((y << 5) + (x >> 3)); //Narrow down to 8 possible pixels
+ halLcdPrint(String, TextStyle);
+}
+
+/**********************************************************************//**
+ * @brief Displays a string on the LCD on the specified line.
+ *
+ * @param String[] The string to be displayed on LCD.
+ *
+ * @param Line The line on the LCD on which to print the string.
+ *
+ * @param TextStyle Value that specifies whether the string is to be
+ * inverted or overwritten.
+ * - Invert = 0x01
+ * - Overwrite = 0x04
+ *
+ * @return none
+ *************************************************************************/
+
+void halLcdPrintLine(char String[], unsigned char Line, unsigned char TextStyle)
+{
+ int temp;
+
+ temp = Line * FONT_HEIGHT;
+ halLcdSetAddress(temp << 5); // 0x20 = 2^5
+ halLcdPrint(String, TextStyle);
+}
+
+/**********************************************************************//**
+ * @brief Prints a string beginning on a given line and column.
+ *
+ * @param String[] The string to be displayed on LCD.
+ *
+ * @param Line The line on which to print the string of text
+ *
+ * @param Col The column on which to print the string of text
+ *
+ * @param TextStyle Value that specifies whether the string is to be
+ * inverted or overwritten.
+ * - Invert = 0x01
+ * - Overwrite = 0x04
+ *
+ * @return none
+ *************************************************************************/
+
+void halLcdPrintLineCol(char String[], unsigned char Line, unsigned char Col,
+ unsigned char TextStyle)
+{
+ int temp;
+
+ temp = Line * FONT_HEIGHT;
+ temp <<= 5;
+ temp += Col;
+
+ halLcdSetAddress(temp); // 0x20 = 2^5
+ halLcdPrint(String, TextStyle);
+}
+
+/**********************************************************************//**
+ * @brief Draws a horizontral line from (x1,y) to (x2,y) of GrayScale level
+ *
+ * @param x1 x-coordinate of the first point
+ *
+ * @param x2 x-coordinate of the second point
+ *
+ * @param y y-coordinate of both points
+ *
+ * @param GrayScale Grayscale level of the horizontal line
+ *
+ * @return none
+ *************************************************************************/
+
+void halLcdHLine(int x1, int x2, int y, unsigned char GrayScale)
+{
+ int x_dir, x;
+
+ if (x1 < x2)
+ x_dir = 1;
+ else
+ x_dir = -1;
+ x = x1;
+ while (x != x2)
+ {
+ halLcdPixel(x, y, GrayScale);
+ x += x_dir;
+ }
+}
+
+/**********************************************************************//**
+ * @brief Draws a vertical line from (x,y1) to (x,y2) of GrayScale level
+ *
+ * @param x x-coordinate of both points
+ *
+ * @param y1 y-coordinate of the first point
+ *
+ * @param y2 y-coordinate of the second point
+ *
+ * @param GrayScale GrayScale level of the vertical line
+ *
+ * @return none
+ *************************************************************************/
+
+void halLcdVLine(int x, int y1, int y2, unsigned char GrayScale)
+{
+ int y_dir, y;
+
+ if (y1 < y2)
+ y_dir = 1;
+ else
+ y_dir = -1;
+ y = y1;
+ while (y != y2)
+ {
+ halLcdPixel(x, y, GrayScale);
+ y += y_dir;
+ }
+}
+
+/**********************************************************************//**
+ * @brief Draws a line from (x1,y1) to (x2,y2) of GrayScale level.
+ *
+ * Uses Bresenham's line algorithm.
+ *
+ * @param x1 x-coordinate of the first point
+ *
+ * @param y1 y-coordinate of the first point
+ *
+ * @param x2 x-coordinate of the second point
+ *
+ * @param y2 y-coordinate of the second point
+ *
+ * @param GrayScale Grayscale level of the line
+ *
+ * @return none
+ *************************************************************************/
+
+void halLcdLine(int x1, int y1, int x2, int y2, unsigned char GrayScale)
+{
+ int x, y, deltay, deltax, d;
+ int x_dir, y_dir;
+
+ if (x1 == x2)
+ halLcdVLine(x1, y1, y2, GrayScale);
+ else
+ {
+ if (y1 == y2)
+ halLcdHLine(x1, x2, y1, GrayScale);
+ else // a diagonal line
+ {
+ if (x1 > x2)
+ x_dir = -1;
+ else x_dir = 1;
+ if (y1 > y2)
+ y_dir = -1;
+ else y_dir = 1;
+
+ x = x1;
+ y = y1;
+ deltay = ABS(y2 - y1);
+ deltax = ABS(x2 - x1);
+
+ if (deltax >= deltay)
+ {
+ d = (deltay << 1) - deltax;
+ while (x != x2)
+ {
+ halLcdPixel(x, y, GrayScale);
+ if (d < 0)
+ d += (deltay << 1);
+ else
+ {
+ d += ((deltay - deltax) << 1);
+ y += y_dir;
+ }
+ x += x_dir;
+ }
+ }
+ else
+ {
+ d = (deltax << 1) - deltay;
+ while (y != y2)
+ {
+ halLcdPixel(x, y, GrayScale);
+ if (d < 0)
+ d += (deltax << 1);
+ else
+ {
+ d += ((deltax - deltay) << 1);
+ x += x_dir;
+ }
+ y += y_dir;
+ }
+ }
+ }
+ }
+}
+
+/**********************************************************************//**
+ * @brief Draw a circle of Radius with center at (x,y) of GrayScale level.
+ *
+ * Uses Bresenham's circle algorithm
+ *
+ * @param x x-coordinate of the circle's center point
+ *
+ * @param y y-coordinate of the circle's center point
+ *
+ * @param Radius Radius of the circle
+ *
+ * @param GrayScale Grayscale level of the circle
+ *************************************************************************/
+
+void halLcdCircle(int x, int y, int Radius, int GrayScale)
+{
+ int xx, yy, ddF_x, ddF_y, f;
+
+ ddF_x = 0;
+ ddF_y = -(2 * Radius);
+ f = 1 - Radius;
+
+ xx = 0;
+ yy = Radius;
+ halLcdPixel(x + xx, y + yy, GrayScale);
+ halLcdPixel(x + xx, y - yy, GrayScale);
+ halLcdPixel(x - xx, y + yy, GrayScale);
+ halLcdPixel(x - xx, y - yy, GrayScale);
+ halLcdPixel(x + yy, y + xx, GrayScale);
+ halLcdPixel(x + yy, y - xx, GrayScale);
+ halLcdPixel(x - yy, y + xx, GrayScale);
+ halLcdPixel(x - yy, y - xx, GrayScale);
+ while (xx < yy)
+ {
+ if (f >= 0)
+ {
+ yy--;
+ ddF_y += 2;
+ f += ddF_y;
+ }
+ xx++;
+ ddF_x += 2;
+ f += ddF_x + 1;
+ halLcdPixel(x + xx, y + yy, GrayScale);
+ halLcdPixel(x + xx, y - yy, GrayScale);
+ halLcdPixel(x - xx, y + yy, GrayScale);
+ halLcdPixel(x - xx, y - yy, GrayScale);
+ halLcdPixel(x + yy, y + xx, GrayScale);
+ halLcdPixel(x + yy, y - xx, GrayScale);
+ halLcdPixel(x - yy, y + xx, GrayScale);
+ halLcdPixel(x - yy, y - xx, GrayScale);
+ }
+}
+
+/**********************************************************************//**
+ * @brief Scrolls a single row of pixels one column to the left.
+ *
+ * The column that is scrolled out of the left side of the LCD will be
+ * displayed the right side of the LCD.
+ *
+ * @param y The row of pixels to scroll. y = 0 is at the top-left
+ * corner of the LCD.
+ *
+ * @return none
+ *************************************************************************/
+
+void halLcdScrollRow(int y)
+{
+ int i, Address, LcdTableAddressTemp;
+ unsigned int temp;
+
+ Address = y << 5;
+
+ halLcdSetAddress(Address);
+
+ //Multiplied by (1+16) and added by the offset
+ LcdTableAddressTemp = y + (y << 4);
+ temp = ((LCD_MEM[LcdTableAddressTemp] & 0x0003) << 14);
+
+ for (i = 0; i < 0x10; i++)
+ halLcdDrawCurrentBlock(((LCD_MEM[LcdTableAddressTemp + i] & 0xFFFC) >> 2) \
+ + ((LCD_MEM[LcdTableAddressTemp + i + 1] & 0x0003) << 14));
+
+ halLcdDrawCurrentBlock(((LCD_MEM[LcdTableAddressTemp + 0x10] & 0xFFFC) >> 2) + temp);
+}
+
+/**********************************************************************//**
+ * @brief Scrolls multiple rows of pixels, yStart to yEnd,
+ * one column to the left.
+ *
+ * The column that is scrolled out of the left side of the LCD will be
+ * displayed the right side of the LCD. y = 0 is at the top-left of the
+ * LCD screen.
+ *
+ * @param yStart The beginning row to be scrolled
+ *
+ * @param yEnd The last row to be scrolled
+ *
+ * @return none
+ *************************************************************************/
+
+void halLcdHScroll(int yStart, int yEnd)
+{
+ int i;
+
+ for (i = yStart; i < yEnd + 1; i++)
+ halLcdScrollRow(i);
+}
+
+/**********************************************************************//**
+ * @brief Scrolls a line of text one column to the left.
+ *
+ * @param Line The line of text to be scrolled.
+ *
+ * @return none
+ *************************************************************************/
+
+void halLcdScrollLine(int Line)
+{
+ int i, Row;
+
+ Row = Line * FONT_HEIGHT;
+
+ for (i = Row; i < Row + FONT_HEIGHT; i++)
+ halLcdScrollRow(i);
+}
diff --git a/platform/exp5438/hal_lcd.h b/platform/exp5438/hal_lcd.h
index 6842c4952..6f2508b29 100644
--- a/platform/exp5438/hal_lcd.h
+++ b/platform/exp5438/hal_lcd.h
@@ -1,147 +1,147 @@
-/*******************************************************************************
- *
- * hal_lcd.h
- *
- * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of Texas Instruments Incorporated nor the names of
- * its contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- ******************************************************************************/
-
-#ifndef HAL_LCD_H
-#define HAL_LCD_H
-
-#define LCD_BACKLT_OUT P8OUT
-#define LCD_BACKLT_DIR P8DIR
-#define LCD_BACKLT_SEL P8SEL
-#define LCD_BACKLIGHT_PIN BIT3
-#define LCD_CS_RST_DIR P9DIR
-#define LCD_CS_RST_OUT P9OUT
-#define LCD_CS_PIN BIT6
-#define LCD_RESET_PIN BIT7
-#define LCD_SPI_SEL P9SEL
-#define LCD_SPI_DIR P9DIR
-#define LCD_MOSI_PIN BIT1
-#define LCD_MISO_PIN BIT2
-#define LCD_CLK_PIN BIT3
-
-#define LCD_ROW 110
-#define LCD_COL 138
-#define LCD_Size 3505
-#define LCD_MEM_Size 110 * 17
-#define LCD_Max_Column_Offset 0x10
-
-#define LCD_Last_Pixel 3505
-
-#define LCD_MEM_Row 0x11
-#define LCD_Row 0x20
-
-// Grayscale level definitions
-#define PIXEL_OFF 0
-#define PIXEL_LIGHT 1
-#define PIXEL_DARK 2
-#define PIXEL_ON 3
-
-#define INVERT_TEXT BIT0
-#define OVERWRITE_TEXT BIT2
-#define GRAYSCALE_TEXT BIT1
-
-/*-------------------------------------------------------------
- * Function Prototypes
- * ------------------------------------------------------------*/
-extern void halLcdInit(void);
-extern void halLcdShutDown(void);
-extern void halLcdBackLightInit(void);
-extern void halLcdSetBackLight(unsigned char BackLightLevel);
-extern unsigned int halLcdGetBackLight(void);
-extern void halLcdShutDownBackLight(void);
-
-extern void halLcdSendCommand(unsigned char Data[]);
-extern void halLcdSetContrast(unsigned char ContrastLevel);
-extern unsigned char halLcdGetContrast(void);
-extern void halLcdStandby(void);
-extern void halLcdActive(void);
-
-//Move to specified LCD address
-extern void halLcdSetAddress(int Address);
-
-//Draw at current segment location
-extern void halLcdDrawCurrentBlock(unsigned int Value);
-extern void halLcdDrawCurrentLine(const unsigned int *value, int length);
-
-//Draw at specified location by calling
-//LCD_Set_Address(Address) & LCD_Draw_Current_Block( value )
-extern void halLcdDrawBlock(unsigned int Address, unsigned int Value);
-
-//Read value from LCD CGRAM
-extern int halLcdReadBlock(unsigned int Address);
-
-//Clear LCD Screen
-extern void halLcdClearScreen(void);
-
-//Invert black to white and vice versa
-extern void halLcdReverse(void);
-
-// Draw a Pixel @ (x,y) with GrayScale level
-extern void halLcdPixel(int x, int y, unsigned char GrayScale);
-
-//Draw Line from (x1,y1) to (x2,y2) with GrayScale level
-extern void halLcdLine(int x1, int y1, int x2, int y2, unsigned char GrayScale);
-extern void halLcdHLine(int x1, int x2, int y, unsigned char GrayScale);
-extern void halLcdVLine(int x1, int x2, int y, unsigned char GrayScale);
-
-extern void halLcdCircle(int x, int y, int Radius, int GrayScale);
-
-extern void halLcdImage(const unsigned int Image[], int Columns, int Rows, int x, int y);
-extern void halLcdClearImage(int Columns, int Rows, int x, int y);
-
-//Print String of Length starting at current LCD location
-extern void halLcdPrint(char String[], unsigned char TextStyle);
-
-//Print String of Length starting at (x,y)
-extern void halLcdPrintXY(char String[], int x, int y, unsigned char TextStyle);
-
-//Print String of Length starting at (x,y)
-extern void halLcdPrintLine(char String[], unsigned char Line, unsigned char TextStyle);
-extern void halLcdPrintLineCol(char String[], unsigned char Line, unsigned char Col,
- unsigned char TextStyle);
-
-extern void halLcdCursor(void);
-extern void halLcdCursorOff(void);
-
-//Scroll a single row of pixels
-extern void halLcdScrollRow(int y);
-
-//Scroll a number of consecutive rows from yStart to yEnd
-extern void halLcdHScroll(int yStart, int yEnd);
-
-//Scroll a line of text
-extern void halLcdScrollLine(int Line);
-
-#endif /* HAL_LCD_H */
+/*******************************************************************************
+ *
+ * hal_lcd.h
+ *
+ * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of Texas Instruments Incorporated nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************/
+
+#ifndef HAL_LCD_H
+#define HAL_LCD_H
+
+#define LCD_BACKLT_OUT P8OUT
+#define LCD_BACKLT_DIR P8DIR
+#define LCD_BACKLT_SEL P8SEL
+#define LCD_BACKLIGHT_PIN BIT3
+#define LCD_CS_RST_DIR P9DIR
+#define LCD_CS_RST_OUT P9OUT
+#define LCD_CS_PIN BIT6
+#define LCD_RESET_PIN BIT7
+#define LCD_SPI_SEL P9SEL
+#define LCD_SPI_DIR P9DIR
+#define LCD_MOSI_PIN BIT1
+#define LCD_MISO_PIN BIT2
+#define LCD_CLK_PIN BIT3
+
+#define LCD_ROW 110
+#define LCD_COL 138
+#define LCD_Size 3505
+#define LCD_MEM_Size 110 * 17
+#define LCD_Max_Column_Offset 0x10
+
+#define LCD_Last_Pixel 3505
+
+#define LCD_MEM_Row 0x11
+#define LCD_Row 0x20
+
+// Grayscale level definitions
+#define PIXEL_OFF 0
+#define PIXEL_LIGHT 1
+#define PIXEL_DARK 2
+#define PIXEL_ON 3
+
+#define INVERT_TEXT BIT0
+#define OVERWRITE_TEXT BIT2
+#define GRAYSCALE_TEXT BIT1
+
+/*-------------------------------------------------------------
+ * Function Prototypes
+ * ------------------------------------------------------------*/
+extern void halLcdInit(void);
+extern void halLcdShutDown(void);
+extern void halLcdBackLightInit(void);
+extern void halLcdSetBackLight(unsigned char BackLightLevel);
+extern unsigned int halLcdGetBackLight(void);
+extern void halLcdShutDownBackLight(void);
+
+extern void halLcdSendCommand(unsigned char Data[]);
+extern void halLcdSetContrast(unsigned char ContrastLevel);
+extern unsigned char halLcdGetContrast(void);
+extern void halLcdStandby(void);
+extern void halLcdActive(void);
+
+//Move to specified LCD address
+extern void halLcdSetAddress(int Address);
+
+//Draw at current segment location
+extern void halLcdDrawCurrentBlock(unsigned int Value);
+extern void halLcdDrawCurrentLine(const unsigned int *value, int length);
+
+//Draw at specified location by calling
+//LCD_Set_Address(Address) & LCD_Draw_Current_Block( value )
+extern void halLcdDrawBlock(unsigned int Address, unsigned int Value);
+
+//Read value from LCD CGRAM
+extern int halLcdReadBlock(unsigned int Address);
+
+//Clear LCD Screen
+extern void halLcdClearScreen(void);
+
+//Invert black to white and vice versa
+extern void halLcdReverse(void);
+
+// Draw a Pixel @ (x,y) with GrayScale level
+extern void halLcdPixel(int x, int y, unsigned char GrayScale);
+
+//Draw Line from (x1,y1) to (x2,y2) with GrayScale level
+extern void halLcdLine(int x1, int y1, int x2, int y2, unsigned char GrayScale);
+extern void halLcdHLine(int x1, int x2, int y, unsigned char GrayScale);
+extern void halLcdVLine(int x1, int x2, int y, unsigned char GrayScale);
+
+extern void halLcdCircle(int x, int y, int Radius, int GrayScale);
+
+extern void halLcdImage(const unsigned int Image[], int Columns, int Rows, int x, int y);
+extern void halLcdClearImage(int Columns, int Rows, int x, int y);
+
+//Print String of Length starting at current LCD location
+extern void halLcdPrint(char String[], unsigned char TextStyle);
+
+//Print String of Length starting at (x,y)
+extern void halLcdPrintXY(char String[], int x, int y, unsigned char TextStyle);
+
+//Print String of Length starting at (x,y)
+extern void halLcdPrintLine(char String[], unsigned char Line, unsigned char TextStyle);
+extern void halLcdPrintLineCol(char String[], unsigned char Line, unsigned char Col,
+ unsigned char TextStyle);
+
+extern void halLcdCursor(void);
+extern void halLcdCursorOff(void);
+
+//Scroll a single row of pixels
+extern void halLcdScrollRow(int y);
+
+//Scroll a number of consecutive rows from yStart to yEnd
+extern void halLcdHScroll(int yStart, int yEnd);
+
+//Scroll a line of text
+extern void halLcdScrollLine(int Line);
+
+#endif /* HAL_LCD_H */
diff --git a/platform/exp5438/hal_lcd_fonts.c b/platform/exp5438/hal_lcd_fonts.c
index 0bdb419de..4780af9d2 100644
--- a/platform/exp5438/hal_lcd_fonts.c
+++ b/platform/exp5438/hal_lcd_fonts.c
@@ -1,353 +1,353 @@
-/*******************************************************************************
- *
- * hal_lcd_fonts.c
- *
- * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of Texas Instruments Incorporated nor the names of
- * its contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- ******************************************************************************/
-
-const unsigned char fonts_lookup[] = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 64, 65, 0, 69, 0, 68, 67, 0, 0, 1, //'0' = 48 = 0x30
- 2, 3, 4, 5, 6, 7, 8, 9, 66, 0, //'9' = 57 = 0x39
- 0, 70, 0, 62, 0, 10, 11, 12, 13, 14, //'A' --> 'Z'
- 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
- 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
- 35, 0, 0, 0, 71, 0, 0, 36, 37, 38, //'a' = 97
- 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
- 49, 50, 51, 52, 53, 54, 55, 56, 57, 58,
- 59, 60, 61, 62, 0, 0, 0, 72, 73, 74,
- 75, 76, 77, 78, 79, 80, 81 //'z' = 122
-};
-
-const unsigned int fonts[] = {
- 0x0000, 0x0ffc, 0x3c0f, 0x3f0f, 0x3fcf, 0x3ccf, 0x3cff, 0x3c3f,
- 0x3c0f, 0x0ffc, 0x0000, 0x0000, 0x0000, 0x0000, 0x00c0, 0x00f0,
- 0x00ff, 0x00f0, 0x00f0, 0x00f0, 0x00f0, 0x00f0, 0x0fff, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x03fc, 0x0f0f, 0x0f0f, 0x0f00, 0x03c0,
- 0x00f0, 0x003c, 0x0f0f, 0x0fff, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x03fc, 0x0f0f, 0x0f00, 0x0f00, 0x03f0, 0x0f00, 0x0f00, 0x0f0f,
- 0x03fc, 0x0000, 0x0000, 0x0000, 0x0000, 0x0f00, 0x0fc0, 0x0ff0,
- 0x0f3c, 0x0f0f, 0x3fff, 0x0f00, 0x0f00, 0x3fc0, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0fff, 0x000f, 0x000f, 0x000f, 0x03ff, 0x0f00,
- 0x0f00, 0x0f0f, 0x03fc, 0x0000, 0x0000, 0x0000, 0x0000, 0x03f0,
- 0x003c, 0x000f, 0x000f, 0x03ff, 0x0f0f, 0x0f0f, 0x0f0f, 0x03fc,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x3fff, 0x3c0f, 0x3c0f, 0x3c00,
- 0x0f00, 0x03c0, 0x00f0, 0x00f0, 0x00f0, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x03fc, 0x0f0f, 0x0f0f, 0x0f3f, 0x03fc, 0x0fcf, 0x0f0f,
- 0x0f0f, 0x03fc, 0x0000, 0x0000, 0x0000, 0x0000, 0x03fc, 0x0f0f,
- 0x0f0f, 0x0f0f, 0x0ffc, 0x03c0, 0x03c0, 0x00f0, 0x00fc, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x00f0, 0x03fc, 0x0f0f, 0x0f0f, 0x0f0f,
- 0x0fff, 0x0f0f, 0x0f0f, 0x0f0f, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0fff, 0x3c3c, 0x3c3c, 0x3c3c, 0x0ffc, 0x3c3c, 0x3c3c, 0x3c3c,
- 0x0fff, 0x0000, 0x0000, 0x0000, 0x0000, 0x0ff0, 0x3c3c, 0x3c0f,
- 0x000f, 0x000f, 0x000f, 0x3c0f, 0x3c3c, 0x0ff0, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x03ff, 0x0f3c, 0x3c3c, 0x3c3c, 0x3c3c, 0x3c3c,
- 0x3c3c, 0x0f3c, 0x03ff, 0x0000, 0x0000, 0x0000, 0x0000, 0x3fff,
- 0x303c, 0x003c, 0x0c3c, 0x0ffc, 0x0c3c, 0x003c, 0x303c, 0x3fff,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x3fff, 0x3c3c, 0x303c, 0x0c3c,
- 0x0ffc, 0x0c3c, 0x003c, 0x003c, 0x00ff, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0ff0, 0x3c3c, 0x3c0f, 0x000f, 0x000f, 0x3f0f, 0x3c0f,
- 0x3c3c, 0x3ff0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0f0f, 0x0f0f,
- 0x0f0f, 0x0f0f, 0x0fff, 0x0f0f, 0x0f0f, 0x0f0f, 0x0f0f, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x03fc, 0x00f0, 0x00f0, 0x00f0, 0x00f0,
- 0x00f0, 0x00f0, 0x00f0, 0x03fc, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x3fc0, 0x0f00, 0x0f00, 0x0f00, 0x0f00, 0x0f0f, 0x0f0f, 0x0f0f,
- 0x03fc, 0x0000, 0x0000, 0x0000, 0x0000, 0x3c3f, 0x3c3c, 0x0f3c,
- 0x0f3c, 0x03fc, 0x0f3c, 0x0f3c, 0x3c3c, 0x3c3f, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x00ff, 0x003c, 0x003c, 0x003c, 0x003c, 0x303c,
- 0x3c3c, 0x3c3c, 0x3fff, 0x0000, 0x0000, 0x0000, 0x0000, 0x3c0f,
- 0x3f3f, 0x3fff, 0x3fff, 0x3ccf, 0x3c0f, 0x3c0f, 0x3c0f, 0x3c0f,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x3c0f, 0x3c0f, 0x3c3f, 0x3cff,
- 0x3fff, 0x3fcf, 0x3f0f, 0x3c0f, 0x3c0f, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x03f0, 0x0f3c, 0x3c0f, 0x3c0f, 0x3c0f, 0x3c0f, 0x3c0f,
- 0x0f3c, 0x03f0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0fff, 0x3c3c,
- 0x3c3c, 0x3c3c, 0x0ffc, 0x003c, 0x003c, 0x003c, 0x00ff, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x03f0, 0x0f3c, 0x3c0f, 0x3c0f, 0x3c0f,
- 0x3f0f, 0x3fcf, 0x0ffc, 0x0f00, 0x3fc0, 0x0000, 0x0000, 0x0000,
- 0x0fff, 0x3c3c, 0x3c3c, 0x3c3c, 0x0ffc, 0x0f3c, 0x3c3c, 0x3c3c,
- 0x3c3f, 0x0000, 0x0000, 0x0000, 0x0000, 0x03fc, 0x0f0f, 0x0f0f,
- 0x000f, 0x00fc, 0x03c0, 0x0f0f, 0x0f0f, 0x03fc, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0fff, 0x0cf3, 0x00f0, 0x00f0, 0x00f0, 0x00f0,
- 0x00f0, 0x00f0, 0x03fc, 0x0000, 0x0000, 0x0000, 0x0000, 0x0f0f,
- 0x0f0f, 0x0f0f, 0x0f0f, 0x0f0f, 0x0f0f, 0x0f0f, 0x0f0f, 0x03fc,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0f0f, 0x0f0f, 0x0f0f, 0x0f0f,
- 0x0f0f, 0x0f0f, 0x0f0f, 0x03fc, 0x00f0, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x3c0f, 0x3c0f, 0x3c0f, 0x3c0f, 0x3ccf, 0x3ccf, 0x0f3c,
- 0x0f3c, 0x0f3c, 0x0000, 0x0000, 0x0000, 0x0000, 0x0f0f, 0x0f0f,
- 0x0f0f, 0x03fc, 0x00f0, 0x03fc, 0x0f0f, 0x0f0f, 0x0f0f, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0f0f, 0x0f0f, 0x0f0f, 0x0f0f, 0x03fc,
- 0x00f0, 0x00f0, 0x00f0, 0x03fc, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x3fff, 0x3f0f, 0x03c3, 0x03c0, 0x00f0, 0x003c, 0x303c, 0x3c0f,
- 0x3fff, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x03fc, 0x0f00, 0x0ffc, 0x0f0f, 0x0f0f, 0x3cfc, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x003f, 0x003c, 0x003c, 0x0ffc, 0x3c3c, 0x3c3c,
- 0x3c3c, 0x3c3c, 0x0fcf, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x03fc, 0x0f0f, 0x000f, 0x000f, 0x0f0f, 0x03fc,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0fc0, 0x0f00, 0x0f00, 0x0ffc,
- 0x0f0f, 0x0f0f, 0x0f0f, 0x0f0f, 0x3cfc, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x03fc, 0x0f0f, 0x0fff, 0x000f,
- 0x0f0f, 0x03fc, 0x0000, 0x0000, 0x0000, 0x0000, 0x03f0, 0x0f3c,
- 0x003c, 0x003c, 0x03ff, 0x003c, 0x003c, 0x003c, 0x00ff, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x3cfc, 0x0f0f,
- 0x0f0f, 0x0f0f, 0x0ffc, 0x0f00, 0x0f0f, 0x03fc, 0x0000, 0x0000,
- 0x003f, 0x003c, 0x003c, 0x0f3c, 0x3cfc, 0x3c3c, 0x3c3c, 0x3c3c,
- 0x3c3f, 0x0000, 0x0000, 0x0000, 0x0000, 0x03c0, 0x03c0, 0x0000,
- 0x03fc, 0x03c0, 0x03c0, 0x03c0, 0x03c0, 0x3ffc, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0f00, 0x0f00, 0x0000, 0x0ff0, 0x0f00, 0x0f00,
- 0x0f00, 0x0f00, 0x0f0f, 0x0f0f, 0x03fc, 0x0000, 0x0000, 0x003f,
- 0x003c, 0x003c, 0x3c3c, 0x0f3c, 0x03fc, 0x0f3c, 0x3c3c, 0x3c3f,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x03fc, 0x03c0, 0x03c0, 0x03c0,
- 0x03c0, 0x03c0, 0x03c0, 0x03c0, 0x3ffc, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0fff, 0x3ccf, 0x3ccf, 0x3ccf,
- 0x3ccf, 0x3c0f, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x03ff, 0x0f0f, 0x0f0f, 0x0f0f, 0x0f0f, 0x0f0f, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x03fc, 0x0f0f,
- 0x0f0f, 0x0f0f, 0x0f0f, 0x03fc, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0fcf, 0x3c3c, 0x3c3c, 0x3c3c, 0x3c3c,
- 0x0ffc, 0x003c, 0x00ff, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x3cfc, 0x0f0f, 0x0f0f, 0x0f0f, 0x0f0f, 0x0ffc, 0x0f00, 0x3fc0,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0f3f, 0x3f3c, 0x3cfc,
- 0x003c, 0x003c, 0x00ff, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x03fc, 0x0f0f, 0x003c, 0x03c0, 0x0f0f, 0x03fc,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0030, 0x003c, 0x0fff,
- 0x003c, 0x003c, 0x003c, 0x0f3c, 0x03f0, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0f0f, 0x0f0f, 0x0f0f, 0x0f0f,
- 0x0f0f, 0x3cfc, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0f0f, 0x0f0f, 0x0f0f, 0x0f0f, 0x03fc, 0x00f0, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x3c0f, 0x3c0f,
- 0x3ccf, 0x3ccf, 0x0f3c, 0x0f3c, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x3c0f, 0x0f3c, 0x03f0, 0x03f0, 0x0f3c,
- 0x3c0f, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x3c3c, 0x3c3c, 0x3c3c, 0x3c3c, 0x0ff0, 0x0f00, 0x03c0, 0x00ff,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0fff, 0x0f03, 0x03c0,
- 0x003c, 0x0c0f, 0x0fff, 0x0000, 0x0000, 0x0000, 0x0000, 0x03fc,
- 0x0f0f, 0x0f00, 0x03c0, 0x00f0, 0x00f0, 0x0000, 0x00f0, 0x00f0,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0f00, 0x03c0, 0x00f0, 0x003c, 0x003c, 0x003c, 0x00f0,
- 0x03c0, 0x0f00, 0x0000, 0x0000, 0x0000, 0x0000, 0x003c, 0x00f0,
- 0x03c0, 0x0f00, 0x0f00, 0x0f00, 0x03c0, 0x00f0, 0x003c, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x03f0, 0x03f0, 0x0000,
- 0x0000, 0x03f0, 0x03f0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x03f0,
- 0x03f0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x3ffc, 0x3ffc, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x03c0, 0x03c0, 0x3ffc, 0x3ffc,
- 0x03c0, 0x03c0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x3ffc, 0x0000, 0x0000, 0x3ffc, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x03fc, 0x0f0f, 0x0f0f, 0x0f0f,
- 0x03fc, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- //0---------------------------
- 0x0000, 0x0ffc, 0x3c0f, 0x3f0f, 0x3fcf, 0x3ccf, 0x3cff, 0x3c3f,
- 0x3c0f, 0x0ffc, 0x0000, 0x0000, 0x0000,
- //1---------------------------
- 0x0000, 0x00c0, 0x00f0, 0x00ff, 0x00f0, 0x00f0, 0x00f0, 0x00f0,
- 0x00f0, 0x0fff, 0x0000, 0x0000, 0x0000,
- //2---------------------------
- 0x0000, 0x03fc, 0x0f0f, 0x0f0f, 0x0f00, 0x03c0, 0x00f0, 0x003c,
- 0x0f0f, 0x0fff, 0x0000, 0x0000, 0x0000,
- //3---------------------------
- 0x0000, 0x03fc, 0x0f0f, 0x0f00, 0x0f00, 0x03f0, 0x0f00, 0x0f00,
- 0x0f0f, 0x03fc, 0x0000, 0x0000, 0x0000,
- //4---------------------------
- 0x0000, 0x0f00, 0x0fc0, 0x0ff0, 0x0f3c, 0x0f0f, 0x3fff, 0x0f00,
- 0x0f00, 0x3fc0, 0x0000, 0x0000, 0x0000,
- //5---------------------------
- 0x0000, 0x0fff, 0x000f, 0x000f, 0x000f, 0x03ff, 0x0f00, 0x0f00,
- 0x0f0f, 0x03fc, 0x0000, 0x0000, 0x0000,
- //6---------------------------
- 0x0000, 0x03f0, 0x003c, 0x000f, 0x000f, 0x03ff, 0x0f0f, 0x0f0f,
- 0x0f0f, 0x03fc, 0x0000, 0x0000, 0x0000,
- //7---------------------------
- 0x0000, 0x3fff, 0x3c0f, 0x3c0f, 0x3c00, 0x0f00, 0x03c0, 0x00f0,
- 0x00f0, 0x00f0, 0x0000, 0x0000, 0x0000,
- //8---------------------------
- 0x0000, 0x03fc, 0x0f0f, 0x0f0f, 0x0f3f, 0x03fc, 0x0fcf, 0x0f0f,
- 0x0f0f, 0x03fc, 0x0000, 0x0000, 0x0000,
- //9---------------------------
- 0x0000, 0x03fc, 0x0f0f, 0x0f0f, 0x0f0f, 0x0ffc, 0x03c0, 0x03c0,
- 0x00f0, 0x00fc, 0x0000, 0x0000, 0x0000,
-};
-
-
-const unsigned int GrayScale_fonts[] = {
- 0x0000, 0x0aa8, 0x280a, 0x2a0a, 0x2a8a, 0x288a, 0x28aa, 0x282a,
- 0x280a, 0x0aa8, 0x0000, 0x0000, 0x0000, 0x0000, 0x0080, 0x00a0,
- 0x00aa, 0x00a0, 0x00a0, 0x00a0, 0x00a0, 0x00a0, 0x0aaa, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x02a8, 0x0a0a, 0x0a0a, 0x0a00, 0x0280,
- 0x00a0, 0x0028, 0x0a0a, 0x0aaa, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x02a8, 0x0a0a, 0x0a00, 0x0a00, 0x02a0, 0x0a00, 0x0a00, 0x0a0a,
- 0x02a8, 0x0000, 0x0000, 0x0000, 0x0000, 0x0a00, 0x0a80, 0x0aa0,
- 0x0a28, 0x0a0a, 0x2aaa, 0x0a00, 0x0a00, 0x2a80, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0aaa, 0x000a, 0x000a, 0x000a, 0x02aa, 0x0a00,
- 0x0a00, 0x0a0a, 0x02a8, 0x0000, 0x0000, 0x0000, 0x0000, 0x02a0,
- 0x0028, 0x000a, 0x000a, 0x02aa, 0x0a0a, 0x0a0a, 0x0a0a, 0x02a8,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x2aaa, 0x280a, 0x280a, 0x2800,
- 0x0a00, 0x0280, 0x00a0, 0x00a0, 0x00a0, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x02a8, 0x0a0a, 0x0a0a, 0x0a2a, 0x02a8, 0x0a8a, 0x0a0a,
- 0x0a0a, 0x02a8, 0x0000, 0x0000, 0x0000, 0x0000, 0x02a8, 0x0a0a,
- 0x0a0a, 0x0a0a, 0x0aa8, 0x0280, 0x0280, 0x00a0, 0x00a8, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x00a0, 0x02a8, 0x0a0a, 0x0a0a, 0x0a0a,
- 0x0aaa, 0x0a0a, 0x0a0a, 0x0a0a, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0aaa, 0x2828, 0x2828, 0x2828, 0x0aa8, 0x2828, 0x2828, 0x2828,
- 0x0aaa, 0x0000, 0x0000, 0x0000, 0x0000, 0x0aa0, 0x2828, 0x280a,
- 0x000a, 0x000a, 0x000a, 0x280a, 0x2828, 0x0aa0, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x02aa, 0x0a28, 0x2828, 0x2828, 0x2828, 0x2828,
- 0x2828, 0x0a28, 0x02aa, 0x0000, 0x0000, 0x0000, 0x0000, 0x2aaa,
- 0x2028, 0x0028, 0x0828, 0x0aa8, 0x0828, 0x0028, 0x2028, 0x2aaa,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x2aaa, 0x2828, 0x2028, 0x0828,
- 0x0aa8, 0x0828, 0x0028, 0x0028, 0x00aa, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0aa0, 0x2828, 0x280a, 0x000a, 0x000a, 0x2a0a, 0x280a,
- 0x2828, 0x2aa0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0a0a, 0x0a0a,
- 0x0a0a, 0x0a0a, 0x0aaa, 0x0a0a, 0x0a0a, 0x0a0a, 0x0a0a, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x02a8, 0x00a0, 0x00a0, 0x00a0, 0x00a0,
- 0x00a0, 0x00a0, 0x00a0, 0x02a8, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x2a80, 0x0a00, 0x0a00, 0x0a00, 0x0a00, 0x0a0a, 0x0a0a, 0x0a0a,
- 0x02a8, 0x0000, 0x0000, 0x0000, 0x0000, 0x282a, 0x2828, 0x0a28,
- 0x0a28, 0x02a8, 0x0a28, 0x0a28, 0x2828, 0x282a, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x00aa, 0x0028, 0x0028, 0x0028, 0x0028, 0x2028,
- 0x2828, 0x2828, 0x2aaa, 0x0000, 0x0000, 0x0000, 0x0000, 0x280a,
- 0x2a2a, 0x2aaa, 0x2aaa, 0x288a, 0x280a, 0x280a, 0x280a, 0x280a,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x280a, 0x280a, 0x282a, 0x28aa,
- 0x2aaa, 0x2a8a, 0x2a0a, 0x280a, 0x280a, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x02a0, 0x0a28, 0x280a, 0x280a, 0x280a, 0x280a, 0x280a,
- 0x0a28, 0x02a0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0aaa, 0x2828,
- 0x2828, 0x2828, 0x0aa8, 0x0028, 0x0028, 0x0028, 0x00aa, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x02a0, 0x0a28, 0x280a, 0x280a, 0x280a,
- 0x2a0a, 0x2a8a, 0x0aa8, 0x0a00, 0x2a80, 0x0000, 0x0000, 0x0000,
- 0x0aaa, 0x2828, 0x2828, 0x2828, 0x0aa8, 0x0a28, 0x2828, 0x2828,
- 0x282a, 0x0000, 0x0000, 0x0000, 0x0000, 0x02a8, 0x0a0a, 0x0a0a,
- 0x000a, 0x00a8, 0x0280, 0x0a0a, 0x0a0a, 0x02a8, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0aaa, 0x08a2, 0x00a0, 0x00a0, 0x00a0, 0x00a0,
- 0x00a0, 0x00a0, 0x02a8, 0x0000, 0x0000, 0x0000, 0x0000, 0x0a0a,
- 0x0a0a, 0x0a0a, 0x0a0a, 0x0a0a, 0x0a0a, 0x0a0a, 0x0a0a, 0x02a8,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0a0a, 0x0a0a, 0x0a0a, 0x0a0a,
- 0x0a0a, 0x0a0a, 0x0a0a, 0x02a8, 0x00a0, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x280a, 0x280a, 0x280a, 0x280a, 0x288a, 0x288a, 0x0a28,
- 0x0a28, 0x0a28, 0x0000, 0x0000, 0x0000, 0x0000, 0x0a0a, 0x0a0a,
- 0x0a0a, 0x02a8, 0x00a0, 0x02a8, 0x0a0a, 0x0a0a, 0x0a0a, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0a0a, 0x0a0a, 0x0a0a, 0x0a0a, 0x02a8,
- 0x00a0, 0x00a0, 0x00a0, 0x02a8, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x2aaa, 0x2a0a, 0x0282, 0x0280, 0x00a0, 0x0028, 0x2028, 0x280a,
- 0x2aaa, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x02a8, 0x0a00, 0x0aa8, 0x0a0a, 0x0a0a, 0x28a8, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x002a, 0x0028, 0x0028, 0x0aa8, 0x2828, 0x2828,
- 0x2828, 0x2828, 0x0a8a, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x02a8, 0x0a0a, 0x000a, 0x000a, 0x0a0a, 0x02a8,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0a80, 0x0a00, 0x0a00, 0x0aa8,
- 0x0a0a, 0x0a0a, 0x0a0a, 0x0a0a, 0x28a8, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x02a8, 0x0a0a, 0x0aaa, 0x000a,
- 0x0a0a, 0x02a8, 0x0000, 0x0000, 0x0000, 0x0000, 0x02a0, 0x0a28,
- 0x0028, 0x0028, 0x02aa, 0x0028, 0x0028, 0x0028, 0x00aa, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x28a8, 0x0a0a,
- 0x0a0a, 0x0a0a, 0x0aa8, 0x0a00, 0x0a0a, 0x02a8, 0x0000, 0x0000,
- 0x002a, 0x0028, 0x0028, 0x0a28, 0x28a8, 0x2828, 0x2828, 0x2828,
- 0x282a, 0x0000, 0x0000, 0x0000, 0x0000, 0x0280, 0x0280, 0x0000,
- 0x02a8, 0x0280, 0x0280, 0x0280, 0x0280, 0x2aa8, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0a00, 0x0a00, 0x0000, 0x0aa0, 0x0a00, 0x0a00,
- 0x0a00, 0x0a00, 0x0a0a, 0x0a0a, 0x02a8, 0x0000, 0x0000, 0x002a,
- 0x0028, 0x0028, 0x2828, 0x0a28, 0x02a8, 0x0a28, 0x2828, 0x282a,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x02a8, 0x0280, 0x0280, 0x0280,
- 0x0280, 0x0280, 0x0280, 0x0280, 0x2aa8, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0aaa, 0x288a, 0x288a, 0x288a,
- 0x288a, 0x280a, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x02aa, 0x0a0a, 0x0a0a, 0x0a0a, 0x0a0a, 0x0a0a, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x02a8, 0x0a0a,
- 0x0a0a, 0x0a0a, 0x0a0a, 0x02a8, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0a8a, 0x2828, 0x2828, 0x2828, 0x2828,
- 0x0aa8, 0x0028, 0x00aa, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x28a8, 0x0a0a, 0x0a0a, 0x0a0a, 0x0a0a, 0x0aa8, 0x0a00, 0x2a80,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0a2a, 0x2a28, 0x28a8,
- 0x0028, 0x0028, 0x00aa, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x02a8, 0x0a0a, 0x0028, 0x0280, 0x0a0a, 0x02a8,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0020, 0x0028, 0x0aaa,
- 0x0028, 0x0028, 0x0028, 0x0a28, 0x02a0, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0a0a, 0x0a0a, 0x0a0a, 0x0a0a,
- 0x0a0a, 0x28a8, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0a0a, 0x0a0a, 0x0a0a, 0x0a0a, 0x02a8, 0x00a0, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x280a, 0x280a,
- 0x288a, 0x288a, 0x0a28, 0x0a28, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x280a, 0x0a28, 0x02a0, 0x02a0, 0x0a28,
- 0x280a, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x2828, 0x2828, 0x2828, 0x2828, 0x0aa0, 0x0a00, 0x0280, 0x00aa,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0aaa, 0x0a02, 0x0280,
- 0x0028, 0x080a, 0x0aaa, 0x0000, 0x0000, 0x0000, 0x0000, 0x02a8,
- 0x0a0a, 0x0a00, 0x0280, 0x00a0, 0x00a0, 0x0000, 0x00a0, 0x00a0,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0a00, 0x0280, 0x00a0, 0x0028, 0x0028, 0x0028, 0x00a0,
- 0x0280, 0x0a00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0028, 0x00a0,
- 0x0280, 0x0a00, 0x0a00, 0x0a00, 0x0280, 0x00a0, 0x0028, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x02a0, 0x02a0, 0x0000,
- 0x0000, 0x02a0, 0x02a0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x02a0,
- 0x02a0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x2aa8, 0x2aa8, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0280, 0x0280, 0x2aa8, 0x2aa8,
- 0x0280, 0x0280, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x2aa8, 0x0000, 0x0000, 0x2aa8, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x02a8, 0x0a0a, 0x0a0a, 0x0a0a,
- 0x02a8, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- //0---------------------------
- 0x0000, 0x0aa8, 0x280a, 0x2a0a, 0x2a8a, 0x288a, 0x28aa, 0x282a,
- 0x280a, 0x0aa8, 0x0000, 0x0000, 0x0000,
- //1---------------------------
- 0x0000, 0x0080, 0x00a0, 0x00aa, 0x00a0, 0x00a0, 0x00a0, 0x00a0,
- 0x00a0, 0x0aaa, 0x0000, 0x0000, 0x0000,
- //2---------------------------
- 0x0000, 0x02a8, 0x0a0a, 0x0a0a, 0x0a00, 0x0280, 0x00a0, 0x0028,
- 0x0a0a, 0x0aaa, 0x0000, 0x0000, 0x0000,
- //2---------------------------
- 0x0000, 0x02a8, 0x0a0a, 0x0a00, 0x0a00, 0x02a0, 0x0a00, 0x0a00,
- 0x0a0a, 0x02a8, 0x0000, 0x0000, 0x0000,
- //4---------------------------
- 0x0000, 0x0a00, 0x0a80, 0x0aa0, 0x0a28, 0x0a0a, 0x2aaa, 0x0a00,
- 0x0a00, 0x2a80, 0x0000, 0x0000, 0x0000,
- //5---------------------------
- 0x0000, 0x0aaa, 0x000a, 0x000a, 0x000a, 0x02aa, 0x0a00, 0x0a00,
- 0x0a0a, 0x02a8, 0x0000, 0x0000, 0x0000,
- //6---------------------------
- 0x0000, 0x02a0, 0x0028, 0x000a, 0x000a, 0x02aa, 0x0a0a, 0x0a0a,
- 0x0a0a, 0x02a8, 0x0000, 0x0000, 0x0000,
- //7---------------------------
- 0x0000, 0x2aaa, 0x280a, 0x280a, 0x2800, 0x0a00, 0x0280, 0x00a0,
- 0x00a0, 0x00a0, 0x0000, 0x0000, 0x0000,
- //8---------------------------
- 0x0000, 0x02a8, 0x0a0a, 0x0a0a, 0x0a2a, 0x02a8, 0x0a8a, 0x0a0a,
- 0x0a0a, 0x02a8, 0x0000, 0x0000, 0x0000,
- //9---------------------------
- 0x0000, 0x02a8, 0x0a0a, 0x0a0a, 0x0a0a, 0x0aa8, 0x0280, 0x0280,
- 0x00a0, 0x00a8, 0x0000, 0x0000, 0x0000,
-};
+/*******************************************************************************
+ *
+ * hal_lcd_fonts.c
+ *
+ * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of Texas Instruments Incorporated nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************/
+
+const unsigned char fonts_lookup[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 64, 65, 0, 69, 0, 68, 67, 0, 0, 1, //'0' = 48 = 0x30
+ 2, 3, 4, 5, 6, 7, 8, 9, 66, 0, //'9' = 57 = 0x39
+ 0, 70, 0, 62, 0, 10, 11, 12, 13, 14, //'A' --> 'Z'
+ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
+ 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
+ 35, 0, 0, 0, 71, 0, 0, 36, 37, 38, //'a' = 97
+ 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
+ 49, 50, 51, 52, 53, 54, 55, 56, 57, 58,
+ 59, 60, 61, 62, 0, 0, 0, 72, 73, 74,
+ 75, 76, 77, 78, 79, 80, 81 //'z' = 122
+};
+
+const unsigned int fonts[] = {
+ 0x0000, 0x0ffc, 0x3c0f, 0x3f0f, 0x3fcf, 0x3ccf, 0x3cff, 0x3c3f,
+ 0x3c0f, 0x0ffc, 0x0000, 0x0000, 0x0000, 0x0000, 0x00c0, 0x00f0,
+ 0x00ff, 0x00f0, 0x00f0, 0x00f0, 0x00f0, 0x00f0, 0x0fff, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x03fc, 0x0f0f, 0x0f0f, 0x0f00, 0x03c0,
+ 0x00f0, 0x003c, 0x0f0f, 0x0fff, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x03fc, 0x0f0f, 0x0f00, 0x0f00, 0x03f0, 0x0f00, 0x0f00, 0x0f0f,
+ 0x03fc, 0x0000, 0x0000, 0x0000, 0x0000, 0x0f00, 0x0fc0, 0x0ff0,
+ 0x0f3c, 0x0f0f, 0x3fff, 0x0f00, 0x0f00, 0x3fc0, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0fff, 0x000f, 0x000f, 0x000f, 0x03ff, 0x0f00,
+ 0x0f00, 0x0f0f, 0x03fc, 0x0000, 0x0000, 0x0000, 0x0000, 0x03f0,
+ 0x003c, 0x000f, 0x000f, 0x03ff, 0x0f0f, 0x0f0f, 0x0f0f, 0x03fc,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x3fff, 0x3c0f, 0x3c0f, 0x3c00,
+ 0x0f00, 0x03c0, 0x00f0, 0x00f0, 0x00f0, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x03fc, 0x0f0f, 0x0f0f, 0x0f3f, 0x03fc, 0x0fcf, 0x0f0f,
+ 0x0f0f, 0x03fc, 0x0000, 0x0000, 0x0000, 0x0000, 0x03fc, 0x0f0f,
+ 0x0f0f, 0x0f0f, 0x0ffc, 0x03c0, 0x03c0, 0x00f0, 0x00fc, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x00f0, 0x03fc, 0x0f0f, 0x0f0f, 0x0f0f,
+ 0x0fff, 0x0f0f, 0x0f0f, 0x0f0f, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0fff, 0x3c3c, 0x3c3c, 0x3c3c, 0x0ffc, 0x3c3c, 0x3c3c, 0x3c3c,
+ 0x0fff, 0x0000, 0x0000, 0x0000, 0x0000, 0x0ff0, 0x3c3c, 0x3c0f,
+ 0x000f, 0x000f, 0x000f, 0x3c0f, 0x3c3c, 0x0ff0, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x03ff, 0x0f3c, 0x3c3c, 0x3c3c, 0x3c3c, 0x3c3c,
+ 0x3c3c, 0x0f3c, 0x03ff, 0x0000, 0x0000, 0x0000, 0x0000, 0x3fff,
+ 0x303c, 0x003c, 0x0c3c, 0x0ffc, 0x0c3c, 0x003c, 0x303c, 0x3fff,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x3fff, 0x3c3c, 0x303c, 0x0c3c,
+ 0x0ffc, 0x0c3c, 0x003c, 0x003c, 0x00ff, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0ff0, 0x3c3c, 0x3c0f, 0x000f, 0x000f, 0x3f0f, 0x3c0f,
+ 0x3c3c, 0x3ff0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0f0f, 0x0f0f,
+ 0x0f0f, 0x0f0f, 0x0fff, 0x0f0f, 0x0f0f, 0x0f0f, 0x0f0f, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x03fc, 0x00f0, 0x00f0, 0x00f0, 0x00f0,
+ 0x00f0, 0x00f0, 0x00f0, 0x03fc, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x3fc0, 0x0f00, 0x0f00, 0x0f00, 0x0f00, 0x0f0f, 0x0f0f, 0x0f0f,
+ 0x03fc, 0x0000, 0x0000, 0x0000, 0x0000, 0x3c3f, 0x3c3c, 0x0f3c,
+ 0x0f3c, 0x03fc, 0x0f3c, 0x0f3c, 0x3c3c, 0x3c3f, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x00ff, 0x003c, 0x003c, 0x003c, 0x003c, 0x303c,
+ 0x3c3c, 0x3c3c, 0x3fff, 0x0000, 0x0000, 0x0000, 0x0000, 0x3c0f,
+ 0x3f3f, 0x3fff, 0x3fff, 0x3ccf, 0x3c0f, 0x3c0f, 0x3c0f, 0x3c0f,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x3c0f, 0x3c0f, 0x3c3f, 0x3cff,
+ 0x3fff, 0x3fcf, 0x3f0f, 0x3c0f, 0x3c0f, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x03f0, 0x0f3c, 0x3c0f, 0x3c0f, 0x3c0f, 0x3c0f, 0x3c0f,
+ 0x0f3c, 0x03f0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0fff, 0x3c3c,
+ 0x3c3c, 0x3c3c, 0x0ffc, 0x003c, 0x003c, 0x003c, 0x00ff, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x03f0, 0x0f3c, 0x3c0f, 0x3c0f, 0x3c0f,
+ 0x3f0f, 0x3fcf, 0x0ffc, 0x0f00, 0x3fc0, 0x0000, 0x0000, 0x0000,
+ 0x0fff, 0x3c3c, 0x3c3c, 0x3c3c, 0x0ffc, 0x0f3c, 0x3c3c, 0x3c3c,
+ 0x3c3f, 0x0000, 0x0000, 0x0000, 0x0000, 0x03fc, 0x0f0f, 0x0f0f,
+ 0x000f, 0x00fc, 0x03c0, 0x0f0f, 0x0f0f, 0x03fc, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0fff, 0x0cf3, 0x00f0, 0x00f0, 0x00f0, 0x00f0,
+ 0x00f0, 0x00f0, 0x03fc, 0x0000, 0x0000, 0x0000, 0x0000, 0x0f0f,
+ 0x0f0f, 0x0f0f, 0x0f0f, 0x0f0f, 0x0f0f, 0x0f0f, 0x0f0f, 0x03fc,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0f0f, 0x0f0f, 0x0f0f, 0x0f0f,
+ 0x0f0f, 0x0f0f, 0x0f0f, 0x03fc, 0x00f0, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x3c0f, 0x3c0f, 0x3c0f, 0x3c0f, 0x3ccf, 0x3ccf, 0x0f3c,
+ 0x0f3c, 0x0f3c, 0x0000, 0x0000, 0x0000, 0x0000, 0x0f0f, 0x0f0f,
+ 0x0f0f, 0x03fc, 0x00f0, 0x03fc, 0x0f0f, 0x0f0f, 0x0f0f, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0f0f, 0x0f0f, 0x0f0f, 0x0f0f, 0x03fc,
+ 0x00f0, 0x00f0, 0x00f0, 0x03fc, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x3fff, 0x3f0f, 0x03c3, 0x03c0, 0x00f0, 0x003c, 0x303c, 0x3c0f,
+ 0x3fff, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x03fc, 0x0f00, 0x0ffc, 0x0f0f, 0x0f0f, 0x3cfc, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x003f, 0x003c, 0x003c, 0x0ffc, 0x3c3c, 0x3c3c,
+ 0x3c3c, 0x3c3c, 0x0fcf, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x03fc, 0x0f0f, 0x000f, 0x000f, 0x0f0f, 0x03fc,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0fc0, 0x0f00, 0x0f00, 0x0ffc,
+ 0x0f0f, 0x0f0f, 0x0f0f, 0x0f0f, 0x3cfc, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x03fc, 0x0f0f, 0x0fff, 0x000f,
+ 0x0f0f, 0x03fc, 0x0000, 0x0000, 0x0000, 0x0000, 0x03f0, 0x0f3c,
+ 0x003c, 0x003c, 0x03ff, 0x003c, 0x003c, 0x003c, 0x00ff, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x3cfc, 0x0f0f,
+ 0x0f0f, 0x0f0f, 0x0ffc, 0x0f00, 0x0f0f, 0x03fc, 0x0000, 0x0000,
+ 0x003f, 0x003c, 0x003c, 0x0f3c, 0x3cfc, 0x3c3c, 0x3c3c, 0x3c3c,
+ 0x3c3f, 0x0000, 0x0000, 0x0000, 0x0000, 0x03c0, 0x03c0, 0x0000,
+ 0x03fc, 0x03c0, 0x03c0, 0x03c0, 0x03c0, 0x3ffc, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0f00, 0x0f00, 0x0000, 0x0ff0, 0x0f00, 0x0f00,
+ 0x0f00, 0x0f00, 0x0f0f, 0x0f0f, 0x03fc, 0x0000, 0x0000, 0x003f,
+ 0x003c, 0x003c, 0x3c3c, 0x0f3c, 0x03fc, 0x0f3c, 0x3c3c, 0x3c3f,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x03fc, 0x03c0, 0x03c0, 0x03c0,
+ 0x03c0, 0x03c0, 0x03c0, 0x03c0, 0x3ffc, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0fff, 0x3ccf, 0x3ccf, 0x3ccf,
+ 0x3ccf, 0x3c0f, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x03ff, 0x0f0f, 0x0f0f, 0x0f0f, 0x0f0f, 0x0f0f, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x03fc, 0x0f0f,
+ 0x0f0f, 0x0f0f, 0x0f0f, 0x03fc, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0fcf, 0x3c3c, 0x3c3c, 0x3c3c, 0x3c3c,
+ 0x0ffc, 0x003c, 0x00ff, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x3cfc, 0x0f0f, 0x0f0f, 0x0f0f, 0x0f0f, 0x0ffc, 0x0f00, 0x3fc0,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0f3f, 0x3f3c, 0x3cfc,
+ 0x003c, 0x003c, 0x00ff, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x03fc, 0x0f0f, 0x003c, 0x03c0, 0x0f0f, 0x03fc,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0030, 0x003c, 0x0fff,
+ 0x003c, 0x003c, 0x003c, 0x0f3c, 0x03f0, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0f0f, 0x0f0f, 0x0f0f, 0x0f0f,
+ 0x0f0f, 0x3cfc, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0f0f, 0x0f0f, 0x0f0f, 0x0f0f, 0x03fc, 0x00f0, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x3c0f, 0x3c0f,
+ 0x3ccf, 0x3ccf, 0x0f3c, 0x0f3c, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x3c0f, 0x0f3c, 0x03f0, 0x03f0, 0x0f3c,
+ 0x3c0f, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x3c3c, 0x3c3c, 0x3c3c, 0x3c3c, 0x0ff0, 0x0f00, 0x03c0, 0x00ff,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0fff, 0x0f03, 0x03c0,
+ 0x003c, 0x0c0f, 0x0fff, 0x0000, 0x0000, 0x0000, 0x0000, 0x03fc,
+ 0x0f0f, 0x0f00, 0x03c0, 0x00f0, 0x00f0, 0x0000, 0x00f0, 0x00f0,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0f00, 0x03c0, 0x00f0, 0x003c, 0x003c, 0x003c, 0x00f0,
+ 0x03c0, 0x0f00, 0x0000, 0x0000, 0x0000, 0x0000, 0x003c, 0x00f0,
+ 0x03c0, 0x0f00, 0x0f00, 0x0f00, 0x03c0, 0x00f0, 0x003c, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x03f0, 0x03f0, 0x0000,
+ 0x0000, 0x03f0, 0x03f0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x03f0,
+ 0x03f0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x3ffc, 0x3ffc, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x03c0, 0x03c0, 0x3ffc, 0x3ffc,
+ 0x03c0, 0x03c0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x3ffc, 0x0000, 0x0000, 0x3ffc, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x03fc, 0x0f0f, 0x0f0f, 0x0f0f,
+ 0x03fc, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ //0---------------------------
+ 0x0000, 0x0ffc, 0x3c0f, 0x3f0f, 0x3fcf, 0x3ccf, 0x3cff, 0x3c3f,
+ 0x3c0f, 0x0ffc, 0x0000, 0x0000, 0x0000,
+ //1---------------------------
+ 0x0000, 0x00c0, 0x00f0, 0x00ff, 0x00f0, 0x00f0, 0x00f0, 0x00f0,
+ 0x00f0, 0x0fff, 0x0000, 0x0000, 0x0000,
+ //2---------------------------
+ 0x0000, 0x03fc, 0x0f0f, 0x0f0f, 0x0f00, 0x03c0, 0x00f0, 0x003c,
+ 0x0f0f, 0x0fff, 0x0000, 0x0000, 0x0000,
+ //3---------------------------
+ 0x0000, 0x03fc, 0x0f0f, 0x0f00, 0x0f00, 0x03f0, 0x0f00, 0x0f00,
+ 0x0f0f, 0x03fc, 0x0000, 0x0000, 0x0000,
+ //4---------------------------
+ 0x0000, 0x0f00, 0x0fc0, 0x0ff0, 0x0f3c, 0x0f0f, 0x3fff, 0x0f00,
+ 0x0f00, 0x3fc0, 0x0000, 0x0000, 0x0000,
+ //5---------------------------
+ 0x0000, 0x0fff, 0x000f, 0x000f, 0x000f, 0x03ff, 0x0f00, 0x0f00,
+ 0x0f0f, 0x03fc, 0x0000, 0x0000, 0x0000,
+ //6---------------------------
+ 0x0000, 0x03f0, 0x003c, 0x000f, 0x000f, 0x03ff, 0x0f0f, 0x0f0f,
+ 0x0f0f, 0x03fc, 0x0000, 0x0000, 0x0000,
+ //7---------------------------
+ 0x0000, 0x3fff, 0x3c0f, 0x3c0f, 0x3c00, 0x0f00, 0x03c0, 0x00f0,
+ 0x00f0, 0x00f0, 0x0000, 0x0000, 0x0000,
+ //8---------------------------
+ 0x0000, 0x03fc, 0x0f0f, 0x0f0f, 0x0f3f, 0x03fc, 0x0fcf, 0x0f0f,
+ 0x0f0f, 0x03fc, 0x0000, 0x0000, 0x0000,
+ //9---------------------------
+ 0x0000, 0x03fc, 0x0f0f, 0x0f0f, 0x0f0f, 0x0ffc, 0x03c0, 0x03c0,
+ 0x00f0, 0x00fc, 0x0000, 0x0000, 0x0000,
+};
+
+
+const unsigned int GrayScale_fonts[] = {
+ 0x0000, 0x0aa8, 0x280a, 0x2a0a, 0x2a8a, 0x288a, 0x28aa, 0x282a,
+ 0x280a, 0x0aa8, 0x0000, 0x0000, 0x0000, 0x0000, 0x0080, 0x00a0,
+ 0x00aa, 0x00a0, 0x00a0, 0x00a0, 0x00a0, 0x00a0, 0x0aaa, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x02a8, 0x0a0a, 0x0a0a, 0x0a00, 0x0280,
+ 0x00a0, 0x0028, 0x0a0a, 0x0aaa, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x02a8, 0x0a0a, 0x0a00, 0x0a00, 0x02a0, 0x0a00, 0x0a00, 0x0a0a,
+ 0x02a8, 0x0000, 0x0000, 0x0000, 0x0000, 0x0a00, 0x0a80, 0x0aa0,
+ 0x0a28, 0x0a0a, 0x2aaa, 0x0a00, 0x0a00, 0x2a80, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0aaa, 0x000a, 0x000a, 0x000a, 0x02aa, 0x0a00,
+ 0x0a00, 0x0a0a, 0x02a8, 0x0000, 0x0000, 0x0000, 0x0000, 0x02a0,
+ 0x0028, 0x000a, 0x000a, 0x02aa, 0x0a0a, 0x0a0a, 0x0a0a, 0x02a8,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x2aaa, 0x280a, 0x280a, 0x2800,
+ 0x0a00, 0x0280, 0x00a0, 0x00a0, 0x00a0, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x02a8, 0x0a0a, 0x0a0a, 0x0a2a, 0x02a8, 0x0a8a, 0x0a0a,
+ 0x0a0a, 0x02a8, 0x0000, 0x0000, 0x0000, 0x0000, 0x02a8, 0x0a0a,
+ 0x0a0a, 0x0a0a, 0x0aa8, 0x0280, 0x0280, 0x00a0, 0x00a8, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x00a0, 0x02a8, 0x0a0a, 0x0a0a, 0x0a0a,
+ 0x0aaa, 0x0a0a, 0x0a0a, 0x0a0a, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0aaa, 0x2828, 0x2828, 0x2828, 0x0aa8, 0x2828, 0x2828, 0x2828,
+ 0x0aaa, 0x0000, 0x0000, 0x0000, 0x0000, 0x0aa0, 0x2828, 0x280a,
+ 0x000a, 0x000a, 0x000a, 0x280a, 0x2828, 0x0aa0, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x02aa, 0x0a28, 0x2828, 0x2828, 0x2828, 0x2828,
+ 0x2828, 0x0a28, 0x02aa, 0x0000, 0x0000, 0x0000, 0x0000, 0x2aaa,
+ 0x2028, 0x0028, 0x0828, 0x0aa8, 0x0828, 0x0028, 0x2028, 0x2aaa,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x2aaa, 0x2828, 0x2028, 0x0828,
+ 0x0aa8, 0x0828, 0x0028, 0x0028, 0x00aa, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0aa0, 0x2828, 0x280a, 0x000a, 0x000a, 0x2a0a, 0x280a,
+ 0x2828, 0x2aa0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0a0a, 0x0a0a,
+ 0x0a0a, 0x0a0a, 0x0aaa, 0x0a0a, 0x0a0a, 0x0a0a, 0x0a0a, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x02a8, 0x00a0, 0x00a0, 0x00a0, 0x00a0,
+ 0x00a0, 0x00a0, 0x00a0, 0x02a8, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x2a80, 0x0a00, 0x0a00, 0x0a00, 0x0a00, 0x0a0a, 0x0a0a, 0x0a0a,
+ 0x02a8, 0x0000, 0x0000, 0x0000, 0x0000, 0x282a, 0x2828, 0x0a28,
+ 0x0a28, 0x02a8, 0x0a28, 0x0a28, 0x2828, 0x282a, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x00aa, 0x0028, 0x0028, 0x0028, 0x0028, 0x2028,
+ 0x2828, 0x2828, 0x2aaa, 0x0000, 0x0000, 0x0000, 0x0000, 0x280a,
+ 0x2a2a, 0x2aaa, 0x2aaa, 0x288a, 0x280a, 0x280a, 0x280a, 0x280a,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x280a, 0x280a, 0x282a, 0x28aa,
+ 0x2aaa, 0x2a8a, 0x2a0a, 0x280a, 0x280a, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x02a0, 0x0a28, 0x280a, 0x280a, 0x280a, 0x280a, 0x280a,
+ 0x0a28, 0x02a0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0aaa, 0x2828,
+ 0x2828, 0x2828, 0x0aa8, 0x0028, 0x0028, 0x0028, 0x00aa, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x02a0, 0x0a28, 0x280a, 0x280a, 0x280a,
+ 0x2a0a, 0x2a8a, 0x0aa8, 0x0a00, 0x2a80, 0x0000, 0x0000, 0x0000,
+ 0x0aaa, 0x2828, 0x2828, 0x2828, 0x0aa8, 0x0a28, 0x2828, 0x2828,
+ 0x282a, 0x0000, 0x0000, 0x0000, 0x0000, 0x02a8, 0x0a0a, 0x0a0a,
+ 0x000a, 0x00a8, 0x0280, 0x0a0a, 0x0a0a, 0x02a8, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0aaa, 0x08a2, 0x00a0, 0x00a0, 0x00a0, 0x00a0,
+ 0x00a0, 0x00a0, 0x02a8, 0x0000, 0x0000, 0x0000, 0x0000, 0x0a0a,
+ 0x0a0a, 0x0a0a, 0x0a0a, 0x0a0a, 0x0a0a, 0x0a0a, 0x0a0a, 0x02a8,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0a0a, 0x0a0a, 0x0a0a, 0x0a0a,
+ 0x0a0a, 0x0a0a, 0x0a0a, 0x02a8, 0x00a0, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x280a, 0x280a, 0x280a, 0x280a, 0x288a, 0x288a, 0x0a28,
+ 0x0a28, 0x0a28, 0x0000, 0x0000, 0x0000, 0x0000, 0x0a0a, 0x0a0a,
+ 0x0a0a, 0x02a8, 0x00a0, 0x02a8, 0x0a0a, 0x0a0a, 0x0a0a, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0a0a, 0x0a0a, 0x0a0a, 0x0a0a, 0x02a8,
+ 0x00a0, 0x00a0, 0x00a0, 0x02a8, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x2aaa, 0x2a0a, 0x0282, 0x0280, 0x00a0, 0x0028, 0x2028, 0x280a,
+ 0x2aaa, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x02a8, 0x0a00, 0x0aa8, 0x0a0a, 0x0a0a, 0x28a8, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x002a, 0x0028, 0x0028, 0x0aa8, 0x2828, 0x2828,
+ 0x2828, 0x2828, 0x0a8a, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x02a8, 0x0a0a, 0x000a, 0x000a, 0x0a0a, 0x02a8,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0a80, 0x0a00, 0x0a00, 0x0aa8,
+ 0x0a0a, 0x0a0a, 0x0a0a, 0x0a0a, 0x28a8, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x02a8, 0x0a0a, 0x0aaa, 0x000a,
+ 0x0a0a, 0x02a8, 0x0000, 0x0000, 0x0000, 0x0000, 0x02a0, 0x0a28,
+ 0x0028, 0x0028, 0x02aa, 0x0028, 0x0028, 0x0028, 0x00aa, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x28a8, 0x0a0a,
+ 0x0a0a, 0x0a0a, 0x0aa8, 0x0a00, 0x0a0a, 0x02a8, 0x0000, 0x0000,
+ 0x002a, 0x0028, 0x0028, 0x0a28, 0x28a8, 0x2828, 0x2828, 0x2828,
+ 0x282a, 0x0000, 0x0000, 0x0000, 0x0000, 0x0280, 0x0280, 0x0000,
+ 0x02a8, 0x0280, 0x0280, 0x0280, 0x0280, 0x2aa8, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0a00, 0x0a00, 0x0000, 0x0aa0, 0x0a00, 0x0a00,
+ 0x0a00, 0x0a00, 0x0a0a, 0x0a0a, 0x02a8, 0x0000, 0x0000, 0x002a,
+ 0x0028, 0x0028, 0x2828, 0x0a28, 0x02a8, 0x0a28, 0x2828, 0x282a,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x02a8, 0x0280, 0x0280, 0x0280,
+ 0x0280, 0x0280, 0x0280, 0x0280, 0x2aa8, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0aaa, 0x288a, 0x288a, 0x288a,
+ 0x288a, 0x280a, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x02aa, 0x0a0a, 0x0a0a, 0x0a0a, 0x0a0a, 0x0a0a, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x02a8, 0x0a0a,
+ 0x0a0a, 0x0a0a, 0x0a0a, 0x02a8, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0a8a, 0x2828, 0x2828, 0x2828, 0x2828,
+ 0x0aa8, 0x0028, 0x00aa, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x28a8, 0x0a0a, 0x0a0a, 0x0a0a, 0x0a0a, 0x0aa8, 0x0a00, 0x2a80,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0a2a, 0x2a28, 0x28a8,
+ 0x0028, 0x0028, 0x00aa, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x02a8, 0x0a0a, 0x0028, 0x0280, 0x0a0a, 0x02a8,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0020, 0x0028, 0x0aaa,
+ 0x0028, 0x0028, 0x0028, 0x0a28, 0x02a0, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0a0a, 0x0a0a, 0x0a0a, 0x0a0a,
+ 0x0a0a, 0x28a8, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0a0a, 0x0a0a, 0x0a0a, 0x0a0a, 0x02a8, 0x00a0, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x280a, 0x280a,
+ 0x288a, 0x288a, 0x0a28, 0x0a28, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x280a, 0x0a28, 0x02a0, 0x02a0, 0x0a28,
+ 0x280a, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x2828, 0x2828, 0x2828, 0x2828, 0x0aa0, 0x0a00, 0x0280, 0x00aa,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0aaa, 0x0a02, 0x0280,
+ 0x0028, 0x080a, 0x0aaa, 0x0000, 0x0000, 0x0000, 0x0000, 0x02a8,
+ 0x0a0a, 0x0a00, 0x0280, 0x00a0, 0x00a0, 0x0000, 0x00a0, 0x00a0,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0a00, 0x0280, 0x00a0, 0x0028, 0x0028, 0x0028, 0x00a0,
+ 0x0280, 0x0a00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0028, 0x00a0,
+ 0x0280, 0x0a00, 0x0a00, 0x0a00, 0x0280, 0x00a0, 0x0028, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x02a0, 0x02a0, 0x0000,
+ 0x0000, 0x02a0, 0x02a0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x02a0,
+ 0x02a0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x2aa8, 0x2aa8, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x0280, 0x0280, 0x2aa8, 0x2aa8,
+ 0x0280, 0x0280, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x2aa8, 0x0000, 0x0000, 0x2aa8, 0x0000, 0x0000,
+ 0x0000, 0x0000, 0x0000, 0x0000, 0x02a8, 0x0a0a, 0x0a0a, 0x0a0a,
+ 0x02a8, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+ //0---------------------------
+ 0x0000, 0x0aa8, 0x280a, 0x2a0a, 0x2a8a, 0x288a, 0x28aa, 0x282a,
+ 0x280a, 0x0aa8, 0x0000, 0x0000, 0x0000,
+ //1---------------------------
+ 0x0000, 0x0080, 0x00a0, 0x00aa, 0x00a0, 0x00a0, 0x00a0, 0x00a0,
+ 0x00a0, 0x0aaa, 0x0000, 0x0000, 0x0000,
+ //2---------------------------
+ 0x0000, 0x02a8, 0x0a0a, 0x0a0a, 0x0a00, 0x0280, 0x00a0, 0x0028,
+ 0x0a0a, 0x0aaa, 0x0000, 0x0000, 0x0000,
+ //2---------------------------
+ 0x0000, 0x02a8, 0x0a0a, 0x0a00, 0x0a00, 0x02a0, 0x0a00, 0x0a00,
+ 0x0a0a, 0x02a8, 0x0000, 0x0000, 0x0000,
+ //4---------------------------
+ 0x0000, 0x0a00, 0x0a80, 0x0aa0, 0x0a28, 0x0a0a, 0x2aaa, 0x0a00,
+ 0x0a00, 0x2a80, 0x0000, 0x0000, 0x0000,
+ //5---------------------------
+ 0x0000, 0x0aaa, 0x000a, 0x000a, 0x000a, 0x02aa, 0x0a00, 0x0a00,
+ 0x0a0a, 0x02a8, 0x0000, 0x0000, 0x0000,
+ //6---------------------------
+ 0x0000, 0x02a0, 0x0028, 0x000a, 0x000a, 0x02aa, 0x0a0a, 0x0a0a,
+ 0x0a0a, 0x02a8, 0x0000, 0x0000, 0x0000,
+ //7---------------------------
+ 0x0000, 0x2aaa, 0x280a, 0x280a, 0x2800, 0x0a00, 0x0280, 0x00a0,
+ 0x00a0, 0x00a0, 0x0000, 0x0000, 0x0000,
+ //8---------------------------
+ 0x0000, 0x02a8, 0x0a0a, 0x0a0a, 0x0a2a, 0x02a8, 0x0a8a, 0x0a0a,
+ 0x0a0a, 0x02a8, 0x0000, 0x0000, 0x0000,
+ //9---------------------------
+ 0x0000, 0x02a8, 0x0a0a, 0x0a0a, 0x0a0a, 0x0aa8, 0x0280, 0x0280,
+ 0x00a0, 0x00a8, 0x0000, 0x0000, 0x0000,
+};
diff --git a/platform/exp5438/hal_lcd_fonts.h b/platform/exp5438/hal_lcd_fonts.h
index bb0a7e1f4..a15ac38ba 100644
--- a/platform/exp5438/hal_lcd_fonts.h
+++ b/platform/exp5438/hal_lcd_fonts.h
@@ -1,46 +1,46 @@
-/*******************************************************************************
- *
- * hal_lcd_fonts.h
- *
- * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of Texas Instruments Incorporated nor the names of
- * its contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- ******************************************************************************/
-
-#ifndef FONTS_H
-#define FONTS_H
-
-#define FONT_HEIGHT 12 // Each character has 13 lines
-
-extern const unsigned char fonts_lookup[];
-extern const unsigned int fonts[];
-extern const unsigned int GrayScale_fonts[];
-
-#endif /* FONTS_H */
+/*******************************************************************************
+ *
+ * hal_lcd_fonts.h
+ *
+ * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the
+ * distribution.
+ *
+ * Neither the name of Texas Instruments Incorporated nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************/
+
+#ifndef FONTS_H
+#define FONTS_H
+
+#define FONT_HEIGHT 12 // Each character has 13 lines
+
+extern const unsigned char fonts_lookup[];
+extern const unsigned int fonts[];
+extern const unsigned int GrayScale_fonts[];
+
+#endif /* FONTS_H */
diff --git a/tools/cooja/apps/avrora/src/org/contikios/cooja/avrmote/AvrMoteMemory.java b/tools/cooja/apps/avrora/src/org/contikios/cooja/avrmote/AvrMoteMemory.java
index 61cd12b8c..d5a2922c4 100644
--- a/tools/cooja/apps/avrora/src/org/contikios/cooja/avrmote/AvrMoteMemory.java
+++ b/tools/cooja/apps/avrora/src/org/contikios/cooja/avrmote/AvrMoteMemory.java
@@ -1,224 +1,224 @@
-/*
- * Copyright (c) 2014, TU Braunschweig. All rights reserved.
- * Copyright (c) 2009, Swedish Institute of Computer Science. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer. 2. Redistributions in
- * binary form must reproduce the above copyright notice, this list of
- * conditions and the following disclaimer in the documentation and/or other
- * materials provided with the distribution. 3. Neither the name of the
- * Institute nor the names of its contributors may be used to endorse or promote
- * products derived from this software without specific prior written
- * permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-package org.contikios.cooja.avrmote;
-
-
-import org.apache.log4j.Logger;
-
-import avrora.arch.avr.AVRProperties;
-import avrora.core.SourceMapping;
-import avrora.core.SourceMapping.Location;
-import avrora.sim.AtmelInterpreter;
-import avrora.sim.Simulator.Watch;
-import avrora.sim.State;
-import java.nio.ByteOrder;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import org.contikios.cooja.mote.memory.MemoryInterface;
-import org.contikios.cooja.mote.memory.MemoryInterface.SegmentMonitor.EventType;
-import org.contikios.cooja.mote.memory.MemoryLayout;
-/**
- * @author Joakim Eriksson, Fredrik Osterlind, David Kopf, Enrico Jorns
- */
-public class AvrMoteMemory implements MemoryInterface {
- private static Logger logger = Logger.getLogger(AvrMoteMemory.class);
- private static final boolean DEBUG = logger.isDebugEnabled();
-
- private final SourceMapping memoryMap;
- private final AVRProperties avrProperties;
- private final AtmelInterpreter interpreter;
- private final ArrayList memoryMonitors = new ArrayList<>();
- private final MemoryLayout memLayout = new MemoryLayout(ByteOrder.LITTLE_ENDIAN, MemoryLayout.ARCH_8BIT, 2);
-
- private boolean coojaIsAccessingMemory;
-
- public AvrMoteMemory(SourceMapping map, AVRProperties avrProperties, AtmelInterpreter interpreter) {
- memoryMap = map;
- this.interpreter = interpreter;
- this.avrProperties = avrProperties;
- }
-
- @Override
- public int getTotalSize() {
- return avrProperties.sram_size;
- }
-
- @Override
- public byte[] getMemory() throws MoteMemoryException {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
-
- @Override
- public byte[] getMemorySegment(long address, int size) throws MoteMemoryException {
- /*logger.info("getMemorySegment(" + String.format("0x%04x", address) +
- ", " + size + ")");*/
- if (!accessInRange(address, size)) {
- throw new MoteMemoryException(
- "Getting memory segment [0x%x,0x%x] failed: Out of range",
- address, address + size - 1);
- }
-
- /* XXX Unsure whether this is the appropriate method to use, as it
- * triggers memoryRead monitor. Right now I'm using a flag to indicate
- * that Cooja (as opposed to Contiki) read the memory, to avoid infinite
- * recursion. */
- coojaIsAccessingMemory = true;
- byte[] data = new byte[(int) size];
- for (int i = 0; i < size; i++) {
- data[i] = (byte) (interpreter.getDataByte((int) address + i) & 0xff);
- }
- coojaIsAccessingMemory = false;
- return data;
- }
-
- @Override
- public void setMemorySegment(long address, byte[] data) throws MoteMemoryException {
- if (!accessInRange(address, data.length)) {
- throw new MoteMemoryException(
- "Writing memory segment [0x%x,0x%x] failed: Out of range",
- address, address + data.length - 1);
- }
-
- /* XXX See comment in getMemorySegment. */
- coojaIsAccessingMemory = true;
- for (int i = 0; i < data.length; i++) {
- interpreter.writeDataByte((int) address + i, data[i]);
- }
- coojaIsAccessingMemory = false;
- if (DEBUG) {
- logger.debug(String.format(
- "Wrote memory segment [0x%x,0x%x]",
- address, address + data.length - 1));
- }
- }
-
- @Override
- public void clearMemory() {
- setMemorySegment(0L, new byte[avrProperties.sram_size]);
- }
-
- private boolean accessInRange(long address, int size) {
- return (address >= 0) && (address + size <= avrProperties.sram_size);
- }
-
- @Override
- public long getStartAddr() {
- return 0;// XXX
- }
-
- @Override
- public Map getSymbolMap() {
- // XXX do not fetch in function!
- Map symbols = new HashMap<>();
- for (Iterator iter = memoryMap.getIterator(); iter.hasNext();) {
- Location loc = iter.next();
- if (loc == null || (loc.section.equals(".text"))) {
- continue;
- }
- symbols.put(loc.name, new Symbol(Symbol.Type.VARIABLE, loc.name, loc.section, loc.vma_addr & 0x7fffff, -1));
- }
- return symbols;
- }
-
-
- @Override
- public MemoryLayout getLayout() {
- return memLayout;
- }
-
- class AvrByteMonitor extends Watch.Empty {
-
- /** start address to monitor */
- final long address;
- /** size to monitor */
- final int size;
- /** Segment monitor to notify */
- final SegmentMonitor mm;
- /** MonitorType we are listening to */
- final EventType flag;
-
- public AvrByteMonitor(long address, int size, SegmentMonitor mm, EventType flag) {
- this.address = address;
- this.size = size;
- this.mm = mm;
- this.flag = flag;
- }
-
- @Override
- public void fireAfterRead(State state, int data_addr, byte value) {
- if (flag == EventType.WRITE || coojaIsAccessingMemory) {
- return;
- }
- mm.memoryChanged(AvrMoteMemory.this, EventType.READ, data_addr);
- }
-
- @Override
- public void fireAfterWrite(State state, int data_addr, byte value) {
- if (flag == EventType.READ || coojaIsAccessingMemory) {
- return;
- }
- mm.memoryChanged(AvrMoteMemory.this, EventType.WRITE, data_addr);
- }
- }
-
- @Override
- public boolean addSegmentMonitor(EventType flag, long address, int size, SegmentMonitor mm) {
- AvrByteMonitor mon = new AvrByteMonitor(address, size, mm, flag);
-
- memoryMonitors.add(mon);
- /* logger.debug("Added AvrByteMonitor " + Integer.toString(mon.hashCode()) + " for addr " + mon.address + " size " + mon.size + " with watch" + mon.watch); */
-
- /* Add byte monitor (watch) for every byte in range */
- for (int idx = 0; idx < mon.size; idx++) {
- interpreter.getSimulator().insertWatch(mon, (int) mon.address + idx);
- /* logger.debug("Inserted watch " + Integer.toString(mon.watch.hashCode()) + " for " + (mon.address + idx)); */
- }
- return true;
- }
-
- @Override
- public boolean removeSegmentMonitor(long address, int size, SegmentMonitor mm) {
- for (AvrByteMonitor mcm : memoryMonitors) {
- if (mcm.mm != mm || mcm.address != address || mcm.size != size) {
- continue;
- }
- for (int idx = 0; idx < mcm.size; idx++) {
- interpreter.getSimulator().removeWatch(mcm, (int) mcm.address + idx);
- /* logger.debug("Removed watch " + Integer.toString(mcm.watch.hashCode()) + " for " + (mcm.address + idx)); */
- }
- memoryMonitors.remove(mcm);
- return true;
- }
- return false;
- }
-
-}
+/*
+ * Copyright (c) 2014, TU Braunschweig. All rights reserved.
+ * Copyright (c) 2009, Swedish Institute of Computer Science. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer. 2. Redistributions in
+ * binary form must reproduce the above copyright notice, this list of
+ * conditions and the following disclaimer in the documentation and/or other
+ * materials provided with the distribution. 3. Neither the name of the
+ * Institute nor the names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+package org.contikios.cooja.avrmote;
+
+
+import org.apache.log4j.Logger;
+
+import avrora.arch.avr.AVRProperties;
+import avrora.core.SourceMapping;
+import avrora.core.SourceMapping.Location;
+import avrora.sim.AtmelInterpreter;
+import avrora.sim.Simulator.Watch;
+import avrora.sim.State;
+import java.nio.ByteOrder;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import org.contikios.cooja.mote.memory.MemoryInterface;
+import org.contikios.cooja.mote.memory.MemoryInterface.SegmentMonitor.EventType;
+import org.contikios.cooja.mote.memory.MemoryLayout;
+/**
+ * @author Joakim Eriksson, Fredrik Osterlind, David Kopf, Enrico Jorns
+ */
+public class AvrMoteMemory implements MemoryInterface {
+ private static Logger logger = Logger.getLogger(AvrMoteMemory.class);
+ private static final boolean DEBUG = logger.isDebugEnabled();
+
+ private final SourceMapping memoryMap;
+ private final AVRProperties avrProperties;
+ private final AtmelInterpreter interpreter;
+ private final ArrayList memoryMonitors = new ArrayList<>();
+ private final MemoryLayout memLayout = new MemoryLayout(ByteOrder.LITTLE_ENDIAN, MemoryLayout.ARCH_8BIT, 2);
+
+ private boolean coojaIsAccessingMemory;
+
+ public AvrMoteMemory(SourceMapping map, AVRProperties avrProperties, AtmelInterpreter interpreter) {
+ memoryMap = map;
+ this.interpreter = interpreter;
+ this.avrProperties = avrProperties;
+ }
+
+ @Override
+ public int getTotalSize() {
+ return avrProperties.sram_size;
+ }
+
+ @Override
+ public byte[] getMemory() throws MoteMemoryException {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+
+ @Override
+ public byte[] getMemorySegment(long address, int size) throws MoteMemoryException {
+ /*logger.info("getMemorySegment(" + String.format("0x%04x", address) +
+ ", " + size + ")");*/
+ if (!accessInRange(address, size)) {
+ throw new MoteMemoryException(
+ "Getting memory segment [0x%x,0x%x] failed: Out of range",
+ address, address + size - 1);
+ }
+
+ /* XXX Unsure whether this is the appropriate method to use, as it
+ * triggers memoryRead monitor. Right now I'm using a flag to indicate
+ * that Cooja (as opposed to Contiki) read the memory, to avoid infinite
+ * recursion. */
+ coojaIsAccessingMemory = true;
+ byte[] data = new byte[(int) size];
+ for (int i = 0; i < size; i++) {
+ data[i] = (byte) (interpreter.getDataByte((int) address + i) & 0xff);
+ }
+ coojaIsAccessingMemory = false;
+ return data;
+ }
+
+ @Override
+ public void setMemorySegment(long address, byte[] data) throws MoteMemoryException {
+ if (!accessInRange(address, data.length)) {
+ throw new MoteMemoryException(
+ "Writing memory segment [0x%x,0x%x] failed: Out of range",
+ address, address + data.length - 1);
+ }
+
+ /* XXX See comment in getMemorySegment. */
+ coojaIsAccessingMemory = true;
+ for (int i = 0; i < data.length; i++) {
+ interpreter.writeDataByte((int) address + i, data[i]);
+ }
+ coojaIsAccessingMemory = false;
+ if (DEBUG) {
+ logger.debug(String.format(
+ "Wrote memory segment [0x%x,0x%x]",
+ address, address + data.length - 1));
+ }
+ }
+
+ @Override
+ public void clearMemory() {
+ setMemorySegment(0L, new byte[avrProperties.sram_size]);
+ }
+
+ private boolean accessInRange(long address, int size) {
+ return (address >= 0) && (address + size <= avrProperties.sram_size);
+ }
+
+ @Override
+ public long getStartAddr() {
+ return 0;// XXX
+ }
+
+ @Override
+ public Map getSymbolMap() {
+ // XXX do not fetch in function!
+ Map symbols = new HashMap<>();
+ for (Iterator iter = memoryMap.getIterator(); iter.hasNext();) {
+ Location loc = iter.next();
+ if (loc == null || (loc.section.equals(".text"))) {
+ continue;
+ }
+ symbols.put(loc.name, new Symbol(Symbol.Type.VARIABLE, loc.name, loc.section, loc.vma_addr & 0x7fffff, -1));
+ }
+ return symbols;
+ }
+
+
+ @Override
+ public MemoryLayout getLayout() {
+ return memLayout;
+ }
+
+ class AvrByteMonitor extends Watch.Empty {
+
+ /** start address to monitor */
+ final long address;
+ /** size to monitor */
+ final int size;
+ /** Segment monitor to notify */
+ final SegmentMonitor mm;
+ /** MonitorType we are listening to */
+ final EventType flag;
+
+ public AvrByteMonitor(long address, int size, SegmentMonitor mm, EventType flag) {
+ this.address = address;
+ this.size = size;
+ this.mm = mm;
+ this.flag = flag;
+ }
+
+ @Override
+ public void fireAfterRead(State state, int data_addr, byte value) {
+ if (flag == EventType.WRITE || coojaIsAccessingMemory) {
+ return;
+ }
+ mm.memoryChanged(AvrMoteMemory.this, EventType.READ, data_addr);
+ }
+
+ @Override
+ public void fireAfterWrite(State state, int data_addr, byte value) {
+ if (flag == EventType.READ || coojaIsAccessingMemory) {
+ return;
+ }
+ mm.memoryChanged(AvrMoteMemory.this, EventType.WRITE, data_addr);
+ }
+ }
+
+ @Override
+ public boolean addSegmentMonitor(EventType flag, long address, int size, SegmentMonitor mm) {
+ AvrByteMonitor mon = new AvrByteMonitor(address, size, mm, flag);
+
+ memoryMonitors.add(mon);
+ /* logger.debug("Added AvrByteMonitor " + Integer.toString(mon.hashCode()) + " for addr " + mon.address + " size " + mon.size + " with watch" + mon.watch); */
+
+ /* Add byte monitor (watch) for every byte in range */
+ for (int idx = 0; idx < mon.size; idx++) {
+ interpreter.getSimulator().insertWatch(mon, (int) mon.address + idx);
+ /* logger.debug("Inserted watch " + Integer.toString(mon.watch.hashCode()) + " for " + (mon.address + idx)); */
+ }
+ return true;
+ }
+
+ @Override
+ public boolean removeSegmentMonitor(long address, int size, SegmentMonitor mm) {
+ for (AvrByteMonitor mcm : memoryMonitors) {
+ if (mcm.mm != mm || mcm.address != address || mcm.size != size) {
+ continue;
+ }
+ for (int idx = 0; idx < mcm.size; idx++) {
+ interpreter.getSimulator().removeWatch(mcm, (int) mcm.address + idx);
+ /* logger.debug("Removed watch " + Integer.toString(mcm.watch.hashCode()) + " for " + (mcm.address + idx)); */
+ }
+ memoryMonitors.remove(mcm);
+ return true;
+ }
+ return false;
+ }
+
+}
diff --git a/tools/cooja/apps/mspsim/README.md b/tools/cooja/apps/mspsim/README.md
index 11eb149d3..62c7f44fc 100644
--- a/tools/cooja/apps/mspsim/README.md
+++ b/tools/cooja/apps/mspsim/README.md
@@ -1,7 +1,7 @@
-MSPSim support for the COOJA Simulator
---------------------------------------
-
-MSPSim source code access: Standalone MSPSim is available from
-[http://sourceforge.net/projects/mspsim](http://sourceforge.net/projects/mspsim).
-
--- Fredrik Österlind, 18/3 2008
+MSPSim support for the COOJA Simulator
+--------------------------------------
+
+MSPSim source code access: Standalone MSPSim is available from
+[http://sourceforge.net/projects/mspsim](http://sourceforge.net/projects/mspsim).
+
+-- Fredrik Österlind, 18/3 2008
diff --git a/tools/cooja/apps/mspsim/src/org/contikios/cooja/mspmote/interfaces/CC1101Radio.java b/tools/cooja/apps/mspsim/src/org/contikios/cooja/mspmote/interfaces/CC1101Radio.java
index cedf0435c..5b9367d7a 100644
--- a/tools/cooja/apps/mspsim/src/org/contikios/cooja/mspmote/interfaces/CC1101Radio.java
+++ b/tools/cooja/apps/mspsim/src/org/contikios/cooja/mspmote/interfaces/CC1101Radio.java
@@ -1,422 +1,422 @@
-/*
- * Copyright (c) 2012, Thingsquare.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the Institute nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- */
-
-package org.contikios.cooja.mspmote.interfaces;
-
-import java.util.Collection;
-
-import org.apache.log4j.Logger;
-import org.jdom.Element;
-
-import org.contikios.cooja.ClassDescription;
-import org.contikios.cooja.Mote;
-import org.contikios.cooja.RadioPacket;
-import org.contikios.cooja.Simulation;
-import org.contikios.cooja.interfaces.CustomDataRadio;
-import org.contikios.cooja.interfaces.Position;
-import org.contikios.cooja.interfaces.Radio;
-import org.contikios.cooja.mspmote.MspMote;
-import org.contikios.cooja.mspmote.MspMoteTimeEvent;
-import se.sics.mspsim.chip.CC1101;
-import se.sics.mspsim.chip.CC1101.ReceiverListener;
-import se.sics.mspsim.chip.ChannelListener;
-import se.sics.mspsim.chip.RFListener;
-import se.sics.mspsim.chip.Radio802154;
-
-/**
- * @author Fredrik Osterlind
- */
-@ClassDescription("TI CC1101")
-public class CC1101Radio extends Radio implements CustomDataRadio {
- private static Logger logger = Logger.getLogger(CC1101Radio.class);
-
- /**
- * Cross-level:
- * Inter-byte delay for delivering cross-level packet bytes.
- */
- public static final long DELAY_BETWEEN_BYTES =
- (long) (1000.0*Simulation.MILLISECOND/(250000.0/8.0)); /* us. Corresponds to 250kbit/s */
-
- private RadioEvent lastEvent = RadioEvent.UNKNOWN;
-
- private final MspMote mote;
- private final CC1101 cc1101;
-
- private boolean isInterfered = false;
- private boolean isTransmitting = false;
- private boolean isReceiving = false;
-
- private byte lastOutgoingByte;
- private byte lastIncomingByte;
-
- private RadioPacket lastOutgoingPacket = null;
- private RadioPacket lastIncomingPacket = null;
-
- public CC1101Radio(Mote m) {
- this.mote = (MspMote)m;
- Radio802154 r = this.mote.getCPU().getChip(Radio802154.class);
- if (r == null || !(r instanceof CC1101)) {
- throw new IllegalStateException("Mote is not equipped with an CC1101 radio");
- }
- this.cc1101 = (CC1101) r;
-
- cc1101.addRFListener(new RFListener() {
- int len = 0;
- int expLen = 0;
- byte[] buffer = new byte[256 + 15];
- private boolean gotSynchbyte = false;
- public void receivedByte(byte data) {
- if (!isTransmitting()) {
- /* Start transmission */
- lastEvent = RadioEvent.TRANSMISSION_STARTED;
- isTransmitting = true;
- len = 0;
- gotSynchbyte = false;
- /*logger.debug("----- CC1101 TRANSMISSION STARTED -----");*/
- setChanged();
- notifyObservers();
- }
- if (len >= buffer.length) {
- /* Bad size packet, too large */
- logger.debug("Error: bad size: " + len + ", dropping outgoing byte: " + data);
- return;
- }
-
- /* send this byte to all nodes */
- lastOutgoingByte = data;
- lastEvent = RadioEvent.CUSTOM_DATA_TRANSMITTED;
- setChanged();
- notifyObservers();
-
- /* Await synch byte */
- if (!gotSynchbyte) {
- if (lastOutgoingByte == CC1101.SYNCH_BYTE_LAST) {
- gotSynchbyte = true;
- }
- return;
- }
-
- final int HEADERLEN = 1; /* 1x Length byte */
- final int FOOTERLEN = 2; /* TODO Fix CRC in Mspsim's CC1101.java */
- if (len == 0) {
- expLen = (0xff&data) + HEADERLEN + FOOTERLEN;
- }
- buffer[len++] = data;
-
- if (len == expLen) {
- /*logger.debug("----- CC1101 CUSTOM DATA TRANSMITTED -----");*/
-
- final byte[] buf = new byte[expLen];
- System.arraycopy(buffer, 0, buf, 0, expLen);
- lastOutgoingPacket = new RadioPacket() {
- public byte[] getPacketData() {
- return buf;
- }
- };
-
- lastEvent = RadioEvent.PACKET_TRANSMITTED;
- /*logger.debug("----- CC1101 PACKET TRANSMITTED -----");*/
- setChanged();
- notifyObservers();
-
- /*logger.debug("----- CC1101 TRANSMISSION FINISHED -----");*/
- isTransmitting = false;
- lastEvent = RadioEvent.TRANSMISSION_FINISHED;
- setChanged();
- notifyObservers();
- len = 0;
- }
- }
- });
-
- cc1101.setReceiverListener(new ReceiverListener() {
- public void newState(boolean on) {
- if (cc1101.isReadyToReceive()) {
- lastEvent = RadioEvent.HW_ON;
- setChanged();
- notifyObservers();
- } else {
- radioOff();
- }
- }
- });
-
- cc1101.addChannelListener(new ChannelListener() {
- public void channelChanged(int channel) {
- /* XXX Currently assumes zero channel switch time */
- lastEvent = RadioEvent.UNKNOWN;
- setChanged();
- notifyObservers();
- }
- });
- }
-
- private void radioOff() {
- /* Radio was turned off during transmission.
- * May for example happen if watchdog triggers */
- if (isTransmitting()) {
- logger.warn("Turning off radio while transmitting, ending packet prematurely");
-
- /* Simulate end of packet */
- lastOutgoingPacket = new RadioPacket() {
- public byte[] getPacketData() {
- return new byte[0];
- }
- };
-
- lastEvent = RadioEvent.PACKET_TRANSMITTED;
- /*logger.debug("----- CC1101 PACKET TRANSMITTED -----");*/
- setChanged();
- notifyObservers();
-
- /* Register that transmission ended in radio medium */
- /*logger.debug("----- CC1101 TRANSMISSION FINISHED -----");*/
- isTransmitting = false;
- lastEvent = RadioEvent.TRANSMISSION_FINISHED;
- setChanged();
- notifyObservers();
- }
-
- lastEvent = RadioEvent.HW_OFF;
- setChanged();
- notifyObservers();
- }
-
- /* Packet radio support */
- public RadioPacket getLastPacketTransmitted() {
- return lastOutgoingPacket;
- }
-
- public RadioPacket getLastPacketReceived() {
- return lastIncomingPacket;
- }
-
- public void setReceivedPacket(RadioPacket packet) {
- lastIncomingPacket = packet;
-
- /* TODO XXX Need support in CC1101.java */
- /*if (!radio.isReadyToReceive()) {
- logger.warn("Radio receiver not ready, dropping packet data");
- return;
- }*/
-
- /* Delivering packet bytes with delays */
- byte[] packetData = packet.getPacketData();
- long deliveryTime = getMote().getSimulation().getSimulationTime();
- for (byte b: packetData) {
- if (isInterfered()) {
- b = (byte) 0xFF;
- }
-
- final byte byteToDeliver = b;
- getMote().getSimulation().scheduleEvent(new MspMoteTimeEvent(mote, 0) {
- public void execute(long t) {
- super.execute(t);
- cc1101.receivedByte(byteToDeliver);
- mote.requestImmediateWakeup();
- }
- }, deliveryTime);
- deliveryTime += DELAY_BETWEEN_BYTES;
- }
- }
-
- /* Custom data radio support */
- public Object getLastCustomDataTransmitted() {
- return lastOutgoingByte;
- }
-
- public Object getLastCustomDataReceived() {
- return lastIncomingByte;
- }
-
- public void receiveCustomData(Object data) {
- if (!(data instanceof Byte)) {
- logger.fatal("Bad custom data: " + data);
- return;
- }
- lastIncomingByte = (Byte) data;
-
- final byte inputByte;
- if (isInterfered()) {
- inputByte = (byte)0xFF;
- } else {
- inputByte = lastIncomingByte;
- }
- mote.getSimulation().scheduleEvent(new MspMoteTimeEvent(mote, 0) {
- public void execute(long t) {
- super.execute(t);
- cc1101.receivedByte(inputByte);
- mote.requestImmediateWakeup();
- }
- }, mote.getSimulation().getSimulationTime());
-
- }
-
- /* General radio support */
- public boolean isTransmitting() {
- return isTransmitting;
- }
-
- public boolean isReceiving() {
- return isReceiving;
- }
-
- public boolean isInterfered() {
- return isInterfered;
- }
-
- public int getChannel() {
- return cc1101.getActiveChannel();
- }
-
- public int getFrequency() {
- return cc1101.getActiveFrequency();
- }
-
- public void signalReceptionStart() {
- isReceiving = true;
-
- lastEvent = RadioEvent.RECEPTION_STARTED;
- /*logger.debug("----- CC1101 RECEPTION STARTED -----");*/
- setChanged();
- notifyObservers();
- }
-
- public void signalReceptionEnd() {
- /* Deliver packet data */
- isReceiving = false;
- isInterfered = false;
-
- lastEvent = RadioEvent.RECEPTION_FINISHED;
- /*logger.debug("----- CC1101 RECEPTION FINISHED -----");*/
- setChanged();
- notifyObservers();
- }
-
- public RadioEvent getLastEvent() {
- return lastEvent;
- }
-
- public void interfereAnyReception() {
- isInterfered = true;
- isReceiving = false;
- lastIncomingPacket = null;
-
- lastEvent = RadioEvent.RECEPTION_INTERFERED;
- /*logger.debug("----- CC1101 RECEPTION INTERFERED -----");*/
- setChanged();
- notifyObservers();
- }
-
- public double getCurrentOutputPower() {
- /* TODO XXX Need support in CC1101.java */
- return 1;
- }
- public int getCurrentOutputPowerIndicator() {
- /* TODO XXX Need support in CC1101.java */
- return 10;
- }
- public int getOutputPowerIndicatorMax() {
- /* TODO XXX Need support in CC1101.java */
- return 10;
- }
-
-
- /**
- * Last 8 received signal strengths
- */
- double currentSignalStrength = 0;
- private double[] rssiLast = new double[8];
- private int rssiLastCounter = 0;
-
- public double getCurrentSignalStrength() {
- return currentSignalStrength;
- }
-
- public void setCurrentSignalStrength(final double signalStrength) {
- if (signalStrength == currentSignalStrength) {
- return; /* ignored */
- }
- currentSignalStrength = signalStrength;
- if (rssiLastCounter == 0) {
- getMote().getSimulation().scheduleEvent(new MspMoteTimeEvent(mote, 0) {
- public void execute(long t) {
- super.execute(t);
-
- /* Update average */
- System.arraycopy(rssiLast, 1, rssiLast, 0, 7);
- rssiLast[7] = currentSignalStrength;
- double avg = 0;
- for (double v: rssiLast) {
- avg += v;
- }
- avg /= rssiLast.length;
-
- cc1101.setRSSI((int) avg);
-
- rssiLastCounter--;
- if (rssiLastCounter > 0) {
- mote.getSimulation().scheduleEvent(this, t+DELAY_BETWEEN_BYTES/2);
- }
- }
- }, mote.getSimulation().getSimulationTime());
- }
- rssiLastCounter = 8;
- }
-
- public Mote getMote() {
- return mote;
- }
-
- public Position getPosition() {
- return mote.getInterfaces().getPosition();
- }
-
- public Collection getConfigXML() {
- return null;
- }
-
- public void setConfigXML(Collection configXML, boolean visAvailable) {
- }
-
- public boolean isRadioOn() {
- return cc1101.isReadyToReceive();
- }
-
- public boolean canReceiveFrom(CustomDataRadio radio) {
- if (radio.getClass().equals(this.getClass())) {
- return true;
- }
- if (radio.getClass().equals(CC430Radio.class)) {
- return true;
- }
- return false;
- }
-}
+/*
+ * Copyright (c) 2012, Thingsquare.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the Institute nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+package org.contikios.cooja.mspmote.interfaces;
+
+import java.util.Collection;
+
+import org.apache.log4j.Logger;
+import org.jdom.Element;
+
+import org.contikios.cooja.ClassDescription;
+import org.contikios.cooja.Mote;
+import org.contikios.cooja.RadioPacket;
+import org.contikios.cooja.Simulation;
+import org.contikios.cooja.interfaces.CustomDataRadio;
+import org.contikios.cooja.interfaces.Position;
+import org.contikios.cooja.interfaces.Radio;
+import org.contikios.cooja.mspmote.MspMote;
+import org.contikios.cooja.mspmote.MspMoteTimeEvent;
+import se.sics.mspsim.chip.CC1101;
+import se.sics.mspsim.chip.CC1101.ReceiverListener;
+import se.sics.mspsim.chip.ChannelListener;
+import se.sics.mspsim.chip.RFListener;
+import se.sics.mspsim.chip.Radio802154;
+
+/**
+ * @author Fredrik Osterlind
+ */
+@ClassDescription("TI CC1101")
+public class CC1101Radio extends Radio implements CustomDataRadio {
+ private static Logger logger = Logger.getLogger(CC1101Radio.class);
+
+ /**
+ * Cross-level:
+ * Inter-byte delay for delivering cross-level packet bytes.
+ */
+ public static final long DELAY_BETWEEN_BYTES =
+ (long) (1000.0*Simulation.MILLISECOND/(250000.0/8.0)); /* us. Corresponds to 250kbit/s */
+
+ private RadioEvent lastEvent = RadioEvent.UNKNOWN;
+
+ private final MspMote mote;
+ private final CC1101 cc1101;
+
+ private boolean isInterfered = false;
+ private boolean isTransmitting = false;
+ private boolean isReceiving = false;
+
+ private byte lastOutgoingByte;
+ private byte lastIncomingByte;
+
+ private RadioPacket lastOutgoingPacket = null;
+ private RadioPacket lastIncomingPacket = null;
+
+ public CC1101Radio(Mote m) {
+ this.mote = (MspMote)m;
+ Radio802154 r = this.mote.getCPU().getChip(Radio802154.class);
+ if (r == null || !(r instanceof CC1101)) {
+ throw new IllegalStateException("Mote is not equipped with an CC1101 radio");
+ }
+ this.cc1101 = (CC1101) r;
+
+ cc1101.addRFListener(new RFListener() {
+ int len = 0;
+ int expLen = 0;
+ byte[] buffer = new byte[256 + 15];
+ private boolean gotSynchbyte = false;
+ public void receivedByte(byte data) {
+ if (!isTransmitting()) {
+ /* Start transmission */
+ lastEvent = RadioEvent.TRANSMISSION_STARTED;
+ isTransmitting = true;
+ len = 0;
+ gotSynchbyte = false;
+ /*logger.debug("----- CC1101 TRANSMISSION STARTED -----");*/
+ setChanged();
+ notifyObservers();
+ }
+ if (len >= buffer.length) {
+ /* Bad size packet, too large */
+ logger.debug("Error: bad size: " + len + ", dropping outgoing byte: " + data);
+ return;
+ }
+
+ /* send this byte to all nodes */
+ lastOutgoingByte = data;
+ lastEvent = RadioEvent.CUSTOM_DATA_TRANSMITTED;
+ setChanged();
+ notifyObservers();
+
+ /* Await synch byte */
+ if (!gotSynchbyte) {
+ if (lastOutgoingByte == CC1101.SYNCH_BYTE_LAST) {
+ gotSynchbyte = true;
+ }
+ return;
+ }
+
+ final int HEADERLEN = 1; /* 1x Length byte */
+ final int FOOTERLEN = 2; /* TODO Fix CRC in Mspsim's CC1101.java */
+ if (len == 0) {
+ expLen = (0xff&data) + HEADERLEN + FOOTERLEN;
+ }
+ buffer[len++] = data;
+
+ if (len == expLen) {
+ /*logger.debug("----- CC1101 CUSTOM DATA TRANSMITTED -----");*/
+
+ final byte[] buf = new byte[expLen];
+ System.arraycopy(buffer, 0, buf, 0, expLen);
+ lastOutgoingPacket = new RadioPacket() {
+ public byte[] getPacketData() {
+ return buf;
+ }
+ };
+
+ lastEvent = RadioEvent.PACKET_TRANSMITTED;
+ /*logger.debug("----- CC1101 PACKET TRANSMITTED -----");*/
+ setChanged();
+ notifyObservers();
+
+ /*logger.debug("----- CC1101 TRANSMISSION FINISHED -----");*/
+ isTransmitting = false;
+ lastEvent = RadioEvent.TRANSMISSION_FINISHED;
+ setChanged();
+ notifyObservers();
+ len = 0;
+ }
+ }
+ });
+
+ cc1101.setReceiverListener(new ReceiverListener() {
+ public void newState(boolean on) {
+ if (cc1101.isReadyToReceive()) {
+ lastEvent = RadioEvent.HW_ON;
+ setChanged();
+ notifyObservers();
+ } else {
+ radioOff();
+ }
+ }
+ });
+
+ cc1101.addChannelListener(new ChannelListener() {
+ public void channelChanged(int channel) {
+ /* XXX Currently assumes zero channel switch time */
+ lastEvent = RadioEvent.UNKNOWN;
+ setChanged();
+ notifyObservers();
+ }
+ });
+ }
+
+ private void radioOff() {
+ /* Radio was turned off during transmission.
+ * May for example happen if watchdog triggers */
+ if (isTransmitting()) {
+ logger.warn("Turning off radio while transmitting, ending packet prematurely");
+
+ /* Simulate end of packet */
+ lastOutgoingPacket = new RadioPacket() {
+ public byte[] getPacketData() {
+ return new byte[0];
+ }
+ };
+
+ lastEvent = RadioEvent.PACKET_TRANSMITTED;
+ /*logger.debug("----- CC1101 PACKET TRANSMITTED -----");*/
+ setChanged();
+ notifyObservers();
+
+ /* Register that transmission ended in radio medium */
+ /*logger.debug("----- CC1101 TRANSMISSION FINISHED -----");*/
+ isTransmitting = false;
+ lastEvent = RadioEvent.TRANSMISSION_FINISHED;
+ setChanged();
+ notifyObservers();
+ }
+
+ lastEvent = RadioEvent.HW_OFF;
+ setChanged();
+ notifyObservers();
+ }
+
+ /* Packet radio support */
+ public RadioPacket getLastPacketTransmitted() {
+ return lastOutgoingPacket;
+ }
+
+ public RadioPacket getLastPacketReceived() {
+ return lastIncomingPacket;
+ }
+
+ public void setReceivedPacket(RadioPacket packet) {
+ lastIncomingPacket = packet;
+
+ /* TODO XXX Need support in CC1101.java */
+ /*if (!radio.isReadyToReceive()) {
+ logger.warn("Radio receiver not ready, dropping packet data");
+ return;
+ }*/
+
+ /* Delivering packet bytes with delays */
+ byte[] packetData = packet.getPacketData();
+ long deliveryTime = getMote().getSimulation().getSimulationTime();
+ for (byte b: packetData) {
+ if (isInterfered()) {
+ b = (byte) 0xFF;
+ }
+
+ final byte byteToDeliver = b;
+ getMote().getSimulation().scheduleEvent(new MspMoteTimeEvent(mote, 0) {
+ public void execute(long t) {
+ super.execute(t);
+ cc1101.receivedByte(byteToDeliver);
+ mote.requestImmediateWakeup();
+ }
+ }, deliveryTime);
+ deliveryTime += DELAY_BETWEEN_BYTES;
+ }
+ }
+
+ /* Custom data radio support */
+ public Object getLastCustomDataTransmitted() {
+ return lastOutgoingByte;
+ }
+
+ public Object getLastCustomDataReceived() {
+ return lastIncomingByte;
+ }
+
+ public void receiveCustomData(Object data) {
+ if (!(data instanceof Byte)) {
+ logger.fatal("Bad custom data: " + data);
+ return;
+ }
+ lastIncomingByte = (Byte) data;
+
+ final byte inputByte;
+ if (isInterfered()) {
+ inputByte = (byte)0xFF;
+ } else {
+ inputByte = lastIncomingByte;
+ }
+ mote.getSimulation().scheduleEvent(new MspMoteTimeEvent(mote, 0) {
+ public void execute(long t) {
+ super.execute(t);
+ cc1101.receivedByte(inputByte);
+ mote.requestImmediateWakeup();
+ }
+ }, mote.getSimulation().getSimulationTime());
+
+ }
+
+ /* General radio support */
+ public boolean isTransmitting() {
+ return isTransmitting;
+ }
+
+ public boolean isReceiving() {
+ return isReceiving;
+ }
+
+ public boolean isInterfered() {
+ return isInterfered;
+ }
+
+ public int getChannel() {
+ return cc1101.getActiveChannel();
+ }
+
+ public int getFrequency() {
+ return cc1101.getActiveFrequency();
+ }
+
+ public void signalReceptionStart() {
+ isReceiving = true;
+
+ lastEvent = RadioEvent.RECEPTION_STARTED;
+ /*logger.debug("----- CC1101 RECEPTION STARTED -----");*/
+ setChanged();
+ notifyObservers();
+ }
+
+ public void signalReceptionEnd() {
+ /* Deliver packet data */
+ isReceiving = false;
+ isInterfered = false;
+
+ lastEvent = RadioEvent.RECEPTION_FINISHED;
+ /*logger.debug("----- CC1101 RECEPTION FINISHED -----");*/
+ setChanged();
+ notifyObservers();
+ }
+
+ public RadioEvent getLastEvent() {
+ return lastEvent;
+ }
+
+ public void interfereAnyReception() {
+ isInterfered = true;
+ isReceiving = false;
+ lastIncomingPacket = null;
+
+ lastEvent = RadioEvent.RECEPTION_INTERFERED;
+ /*logger.debug("----- CC1101 RECEPTION INTERFERED -----");*/
+ setChanged();
+ notifyObservers();
+ }
+
+ public double getCurrentOutputPower() {
+ /* TODO XXX Need support in CC1101.java */
+ return 1;
+ }
+ public int getCurrentOutputPowerIndicator() {
+ /* TODO XXX Need support in CC1101.java */
+ return 10;
+ }
+ public int getOutputPowerIndicatorMax() {
+ /* TODO XXX Need support in CC1101.java */
+ return 10;
+ }
+
+
+ /**
+ * Last 8 received signal strengths
+ */
+ double currentSignalStrength = 0;
+ private double[] rssiLast = new double[8];
+ private int rssiLastCounter = 0;
+
+ public double getCurrentSignalStrength() {
+ return currentSignalStrength;
+ }
+
+ public void setCurrentSignalStrength(final double signalStrength) {
+ if (signalStrength == currentSignalStrength) {
+ return; /* ignored */
+ }
+ currentSignalStrength = signalStrength;
+ if (rssiLastCounter == 0) {
+ getMote().getSimulation().scheduleEvent(new MspMoteTimeEvent(mote, 0) {
+ public void execute(long t) {
+ super.execute(t);
+
+ /* Update average */
+ System.arraycopy(rssiLast, 1, rssiLast, 0, 7);
+ rssiLast[7] = currentSignalStrength;
+ double avg = 0;
+ for (double v: rssiLast) {
+ avg += v;
+ }
+ avg /= rssiLast.length;
+
+ cc1101.setRSSI((int) avg);
+
+ rssiLastCounter--;
+ if (rssiLastCounter > 0) {
+ mote.getSimulation().scheduleEvent(this, t+DELAY_BETWEEN_BYTES/2);
+ }
+ }
+ }, mote.getSimulation().getSimulationTime());
+ }
+ rssiLastCounter = 8;
+ }
+
+ public Mote getMote() {
+ return mote;
+ }
+
+ public Position getPosition() {
+ return mote.getInterfaces().getPosition();
+ }
+
+ public Collection getConfigXML() {
+ return null;
+ }
+
+ public void setConfigXML(Collection configXML, boolean visAvailable) {
+ }
+
+ public boolean isRadioOn() {
+ return cc1101.isReadyToReceive();
+ }
+
+ public boolean canReceiveFrom(CustomDataRadio radio) {
+ if (radio.getClass().equals(this.getClass())) {
+ return true;
+ }
+ if (radio.getClass().equals(CC430Radio.class)) {
+ return true;
+ }
+ return false;
+ }
+}
diff --git a/tools/cooja/apps/mspsim/src/org/contikios/cooja/mspmote/interfaces/CC1120Radio.java b/tools/cooja/apps/mspsim/src/org/contikios/cooja/mspmote/interfaces/CC1120Radio.java
index 9d2a5e333..8e4cfc51e 100644
--- a/tools/cooja/apps/mspsim/src/org/contikios/cooja/mspmote/interfaces/CC1120Radio.java
+++ b/tools/cooja/apps/mspsim/src/org/contikios/cooja/mspmote/interfaces/CC1120Radio.java
@@ -1,421 +1,421 @@
-/*
- * Copyright (c) 2012, Thingsquare.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the Institute nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- */
-
-package org.contikios.cooja.mspmote.interfaces;
-
-import java.util.Collection;
-
-import org.apache.log4j.Logger;
-import org.jdom.Element;
-
-import org.contikios.cooja.ClassDescription;
-import org.contikios.cooja.Mote;
-import org.contikios.cooja.RadioPacket;
-import org.contikios.cooja.Simulation;
-import org.contikios.cooja.interfaces.CustomDataRadio;
-import org.contikios.cooja.interfaces.Position;
-import org.contikios.cooja.interfaces.Radio;
-import org.contikios.cooja.mspmote.MspMote;
-import org.contikios.cooja.mspmote.MspMoteTimeEvent;
-import se.sics.mspsim.chip.CC1120;
-import se.sics.mspsim.chip.CC1120.ReceiverListener;
-import se.sics.mspsim.chip.ChannelListener;
-import se.sics.mspsim.chip.RFListener;
-import se.sics.mspsim.chip.Radio802154;
-
-/**
- * @author Fredrik Osterlind
- */
-@ClassDescription("TI CC1120")
-public class CC1120Radio extends Radio implements CustomDataRadio {
- private static Logger logger = Logger.getLogger(CC1120Radio.class);
-
- /**
- * Cross-level:
- * Inter-byte delay for delivering cross-level packet bytes.
- */
- /* TODO XXX Fix me as well as symbol duration in CC1120.java */
- public static final long DELAY_BETWEEN_BYTES =
- (long) (1000.0*Simulation.MILLISECOND/(200000.0/8.0)); /* us. Corresponds to 200kbit/s */
-
- private RadioEvent lastEvent = RadioEvent.UNKNOWN;
-
- private final MspMote mote;
- private final CC1120 cc1120;
-
- private boolean isInterfered = false;
- private boolean isTransmitting = false;
- private boolean isReceiving = false;
-
- private byte lastOutgoingByte;
- private byte lastIncomingByte;
-
- private RadioPacket lastOutgoingPacket = null;
- private RadioPacket lastIncomingPacket = null;
-
- public CC1120Radio(Mote m) {
- this.mote = (MspMote)m;
- Radio802154 r = this.mote.getCPU().getChip(Radio802154.class);
- if (r == null || !(r instanceof CC1120)) {
- throw new IllegalStateException("Mote is not equipped with an CC1120 radio");
- }
- this.cc1120 = (CC1120) r;
-
- cc1120.addRFListener(new RFListener() {
- int len = 0;
- int expLen = 0;
- byte[] buffer = new byte[256 + 15];
- private boolean gotSynchbyte = false;
- public void receivedByte(byte data) {
- if (!isTransmitting()) {
- /* Start transmission */
- lastEvent = RadioEvent.TRANSMISSION_STARTED;
- isTransmitting = true;
- len = 0;
- gotSynchbyte = false;
- /*logger.debug("----- CCC1120 TRANSMISSION STARTED -----");*/
- setChanged();
- notifyObservers();
- }
- if (len >= buffer.length) {
- /* Bad size packet, too large */
- logger.debug("Error: bad size: " + len + ", dropping outgoing byte: " + data);
- return;
- }
-
- /* send this byte to all nodes */
- lastOutgoingByte = data;
- lastEvent = RadioEvent.CUSTOM_DATA_TRANSMITTED;
- setChanged();
- notifyObservers();
-
- /* Await synch byte */
- if (!gotSynchbyte) {
- if (lastOutgoingByte == CC1120.SYNCH_BYTE_LAST) {
- gotSynchbyte = true;
- }
- return;
- }
-
- final int HEADERLEN = 1; /* 1x Length byte */
- final int FOOTERLEN = 2; /* TODO Fix CRC in Mspsim's CCC1120.java */
- if (len == 0) {
- expLen = (0xff&data) + HEADERLEN + FOOTERLEN;
- }
- buffer[len++] = data;
-
- if (len == expLen) {
- /*logger.debug("----- CCC1120 CUSTOM DATA TRANSMITTED -----");*/
-
- final byte[] buf = new byte[expLen];
- System.arraycopy(buffer, 0, buf, 0, expLen);
- lastOutgoingPacket = new RadioPacket() {
- public byte[] getPacketData() {
- return buf;
- }
- };
-
- lastEvent = RadioEvent.PACKET_TRANSMITTED;
- /*logger.debug("----- CCC1120 PACKET TRANSMITTED -----");*/
- setChanged();
- notifyObservers();
-
- /*logger.debug("----- CCC1120 TRANSMISSION FINISHED -----");*/
- isTransmitting = false;
- lastEvent = RadioEvent.TRANSMISSION_FINISHED;
- setChanged();
- notifyObservers();
- len = 0;
- }
- }
- });
-
- cc1120.setReceiverListener(new ReceiverListener() {
- public void newState(boolean on) {
- if (cc1120.isReadyToReceive()) {
- lastEvent = RadioEvent.HW_ON;
- setChanged();
- notifyObservers();
- } else {
- radioOff();
- }
- }
- });
-
- cc1120.addChannelListener(new ChannelListener() {
- public void channelChanged(int channel) {
- /* XXX Currently assumes zero channel switch time */
- lastEvent = RadioEvent.UNKNOWN;
- setChanged();
- notifyObservers();
- }
- });
- }
-
- private void radioOff() {
- /* Radio was turned off during transmission.
- * May for example happen if watchdog triggers */
- if (isTransmitting()) {
- logger.warn("Turning off radio while transmitting, ending packet prematurely");
-
- /* Simulate end of packet */
- lastOutgoingPacket = new RadioPacket() {
- public byte[] getPacketData() {
- return new byte[0];
- }
- };
-
- lastEvent = RadioEvent.PACKET_TRANSMITTED;
- /*logger.debug("----- CCC1120 PACKET TRANSMITTED -----");*/
- setChanged();
- notifyObservers();
-
- /* Register that transmission ended in radio medium */
- /*logger.debug("----- CCC1120 TRANSMISSION FINISHED -----");*/
- isTransmitting = false;
- lastEvent = RadioEvent.TRANSMISSION_FINISHED;
- setChanged();
- notifyObservers();
- }
-
- lastEvent = RadioEvent.HW_OFF;
- setChanged();
- notifyObservers();
- }
-
- /* Packet radio support */
- public RadioPacket getLastPacketTransmitted() {
- return lastOutgoingPacket;
- }
-
- public RadioPacket getLastPacketReceived() {
- return lastIncomingPacket;
- }
-
- public void setReceivedPacket(RadioPacket packet) {
- lastIncomingPacket = packet;
-
- /* TODO XXX Need support in CCC1120.java */
- /*if (!radio.isReadyToReceive()) {
- logger.warn("Radio receiver not ready, dropping packet data");
- return;
- }*/
-
- /* Delivering packet bytes with delays */
- byte[] packetData = packet.getPacketData();
- long deliveryTime = getMote().getSimulation().getSimulationTime();
- for (byte b: packetData) {
- if (isInterfered()) {
- b = (byte) 0xFF;
- }
-
- final byte byteToDeliver = b;
- getMote().getSimulation().scheduleEvent(new MspMoteTimeEvent(mote, 0) {
- public void execute(long t) {
- super.execute(t);
- cc1120.receivedByte(byteToDeliver);
- mote.requestImmediateWakeup();
- }
- }, deliveryTime);
- deliveryTime += DELAY_BETWEEN_BYTES;
- }
- }
-
- /* Custom data radio support */
- public Object getLastCustomDataTransmitted() {
- return lastOutgoingByte;
- }
-
- public Object getLastCustomDataReceived() {
- return lastIncomingByte;
- }
-
- public void receiveCustomData(Object data) {
- if (!(data instanceof Byte)) {
- logger.fatal("Bad custom data: " + data);
- return;
- }
- lastIncomingByte = (Byte) data;
-
- final byte inputByte;
- if (isInterfered()) {
- inputByte = (byte)0xFF;
- } else {
- inputByte = lastIncomingByte;
- }
- mote.getSimulation().scheduleEvent(new MspMoteTimeEvent(mote, 0) {
- public void execute(long t) {
- super.execute(t);
- cc1120.receivedByte(inputByte);
- mote.requestImmediateWakeup();
- }
- }, mote.getSimulation().getSimulationTime());
-
- }
-
- /* General radio support */
- public boolean isTransmitting() {
- return isTransmitting;
- }
-
- public boolean isReceiving() {
- return isReceiving;
- }
-
- public boolean isInterfered() {
- return isInterfered;
- }
-
- public int getChannel() {
- return cc1120.getActiveChannel()+1000;
- }
-
- public int getFrequency() {
- return cc1120.getActiveFrequency();
- }
-
- public void signalReceptionStart() {
- isReceiving = true;
-
- lastEvent = RadioEvent.RECEPTION_STARTED;
- /*logger.debug("----- CCC1120 RECEPTION STARTED -----");*/
- setChanged();
- notifyObservers();
- }
-
- public void signalReceptionEnd() {
- /* Deliver packet data */
- isReceiving = false;
- isInterfered = false;
-
- lastEvent = RadioEvent.RECEPTION_FINISHED;
- /*logger.debug("----- CCC1120 RECEPTION FINISHED -----");*/
- setChanged();
- notifyObservers();
- }
-
- public RadioEvent getLastEvent() {
- return lastEvent;
- }
-
- public void interfereAnyReception() {
- isInterfered = true;
- isReceiving = false;
- lastIncomingPacket = null;
-
- lastEvent = RadioEvent.RECEPTION_INTERFERED;
- /*logger.debug("----- CCC1120 RECEPTION INTERFERED -----");*/
- setChanged();
- notifyObservers();
- }
-
- public double getCurrentOutputPower() {
- /* TODO XXX Need support in CCC1120.java */
- return 1;
- }
- public int getCurrentOutputPowerIndicator() {
- /* TODO XXX Need support in CCC1120.java */
- return 10;
- }
- public int getOutputPowerIndicatorMax() {
- /* TODO XXX Need support in CCC1120.java */
- return 10;
- }
-
-
- /**
- * Last 8 received signal strengths
- */
- double currentSignalStrength = 0;
- private double[] rssiLast = new double[8];
- private int rssiLastCounter = 0;
-
- public double getCurrentSignalStrength() {
- return currentSignalStrength;
- }
-
- public void setCurrentSignalStrength(final double signalStrength) {
- if (signalStrength == currentSignalStrength) {
- return; /* ignored */
- }
- currentSignalStrength = signalStrength;
- if (rssiLastCounter == 0) {
- getMote().getSimulation().scheduleEvent(new MspMoteTimeEvent(mote, 0) {
- public void execute(long t) {
- super.execute(t);
-
- /* Update average */
- System.arraycopy(rssiLast, 1, rssiLast, 0, 7);
- rssiLast[7] = currentSignalStrength;
- double avg = 0;
- for (double v: rssiLast) {
- avg += v;
- }
- avg /= rssiLast.length;
-
- cc1120.setRSSI((int) avg);
-
- rssiLastCounter--;
- if (rssiLastCounter > 0) {
- mote.getSimulation().scheduleEvent(this, t+DELAY_BETWEEN_BYTES/2);
- }
- }
- }, mote.getSimulation().getSimulationTime());
- }
- rssiLastCounter = 8;
- }
-
- public Mote getMote() {
- return mote;
- }
-
- public Position getPosition() {
- return mote.getInterfaces().getPosition();
- }
-
- public Collection getConfigXML() {
- return null;
- }
-
- public void setConfigXML(Collection configXML, boolean visAvailable) {
- }
-
- public boolean isRadioOn() {
- return cc1120.isReadyToReceive();
- }
-
- public boolean canReceiveFrom(CustomDataRadio radio) {
- if (radio.getClass().equals(this.getClass())) {
- return true;
- }
- return false;
- }
-
-}
+/*
+ * Copyright (c) 2012, Thingsquare.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the Institute nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+package org.contikios.cooja.mspmote.interfaces;
+
+import java.util.Collection;
+
+import org.apache.log4j.Logger;
+import org.jdom.Element;
+
+import org.contikios.cooja.ClassDescription;
+import org.contikios.cooja.Mote;
+import org.contikios.cooja.RadioPacket;
+import org.contikios.cooja.Simulation;
+import org.contikios.cooja.interfaces.CustomDataRadio;
+import org.contikios.cooja.interfaces.Position;
+import org.contikios.cooja.interfaces.Radio;
+import org.contikios.cooja.mspmote.MspMote;
+import org.contikios.cooja.mspmote.MspMoteTimeEvent;
+import se.sics.mspsim.chip.CC1120;
+import se.sics.mspsim.chip.CC1120.ReceiverListener;
+import se.sics.mspsim.chip.ChannelListener;
+import se.sics.mspsim.chip.RFListener;
+import se.sics.mspsim.chip.Radio802154;
+
+/**
+ * @author Fredrik Osterlind
+ */
+@ClassDescription("TI CC1120")
+public class CC1120Radio extends Radio implements CustomDataRadio {
+ private static Logger logger = Logger.getLogger(CC1120Radio.class);
+
+ /**
+ * Cross-level:
+ * Inter-byte delay for delivering cross-level packet bytes.
+ */
+ /* TODO XXX Fix me as well as symbol duration in CC1120.java */
+ public static final long DELAY_BETWEEN_BYTES =
+ (long) (1000.0*Simulation.MILLISECOND/(200000.0/8.0)); /* us. Corresponds to 200kbit/s */
+
+ private RadioEvent lastEvent = RadioEvent.UNKNOWN;
+
+ private final MspMote mote;
+ private final CC1120 cc1120;
+
+ private boolean isInterfered = false;
+ private boolean isTransmitting = false;
+ private boolean isReceiving = false;
+
+ private byte lastOutgoingByte;
+ private byte lastIncomingByte;
+
+ private RadioPacket lastOutgoingPacket = null;
+ private RadioPacket lastIncomingPacket = null;
+
+ public CC1120Radio(Mote m) {
+ this.mote = (MspMote)m;
+ Radio802154 r = this.mote.getCPU().getChip(Radio802154.class);
+ if (r == null || !(r instanceof CC1120)) {
+ throw new IllegalStateException("Mote is not equipped with an CC1120 radio");
+ }
+ this.cc1120 = (CC1120) r;
+
+ cc1120.addRFListener(new RFListener() {
+ int len = 0;
+ int expLen = 0;
+ byte[] buffer = new byte[256 + 15];
+ private boolean gotSynchbyte = false;
+ public void receivedByte(byte data) {
+ if (!isTransmitting()) {
+ /* Start transmission */
+ lastEvent = RadioEvent.TRANSMISSION_STARTED;
+ isTransmitting = true;
+ len = 0;
+ gotSynchbyte = false;
+ /*logger.debug("----- CCC1120 TRANSMISSION STARTED -----");*/
+ setChanged();
+ notifyObservers();
+ }
+ if (len >= buffer.length) {
+ /* Bad size packet, too large */
+ logger.debug("Error: bad size: " + len + ", dropping outgoing byte: " + data);
+ return;
+ }
+
+ /* send this byte to all nodes */
+ lastOutgoingByte = data;
+ lastEvent = RadioEvent.CUSTOM_DATA_TRANSMITTED;
+ setChanged();
+ notifyObservers();
+
+ /* Await synch byte */
+ if (!gotSynchbyte) {
+ if (lastOutgoingByte == CC1120.SYNCH_BYTE_LAST) {
+ gotSynchbyte = true;
+ }
+ return;
+ }
+
+ final int HEADERLEN = 1; /* 1x Length byte */
+ final int FOOTERLEN = 2; /* TODO Fix CRC in Mspsim's CCC1120.java */
+ if (len == 0) {
+ expLen = (0xff&data) + HEADERLEN + FOOTERLEN;
+ }
+ buffer[len++] = data;
+
+ if (len == expLen) {
+ /*logger.debug("----- CCC1120 CUSTOM DATA TRANSMITTED -----");*/
+
+ final byte[] buf = new byte[expLen];
+ System.arraycopy(buffer, 0, buf, 0, expLen);
+ lastOutgoingPacket = new RadioPacket() {
+ public byte[] getPacketData() {
+ return buf;
+ }
+ };
+
+ lastEvent = RadioEvent.PACKET_TRANSMITTED;
+ /*logger.debug("----- CCC1120 PACKET TRANSMITTED -----");*/
+ setChanged();
+ notifyObservers();
+
+ /*logger.debug("----- CCC1120 TRANSMISSION FINISHED -----");*/
+ isTransmitting = false;
+ lastEvent = RadioEvent.TRANSMISSION_FINISHED;
+ setChanged();
+ notifyObservers();
+ len = 0;
+ }
+ }
+ });
+
+ cc1120.setReceiverListener(new ReceiverListener() {
+ public void newState(boolean on) {
+ if (cc1120.isReadyToReceive()) {
+ lastEvent = RadioEvent.HW_ON;
+ setChanged();
+ notifyObservers();
+ } else {
+ radioOff();
+ }
+ }
+ });
+
+ cc1120.addChannelListener(new ChannelListener() {
+ public void channelChanged(int channel) {
+ /* XXX Currently assumes zero channel switch time */
+ lastEvent = RadioEvent.UNKNOWN;
+ setChanged();
+ notifyObservers();
+ }
+ });
+ }
+
+ private void radioOff() {
+ /* Radio was turned off during transmission.
+ * May for example happen if watchdog triggers */
+ if (isTransmitting()) {
+ logger.warn("Turning off radio while transmitting, ending packet prematurely");
+
+ /* Simulate end of packet */
+ lastOutgoingPacket = new RadioPacket() {
+ public byte[] getPacketData() {
+ return new byte[0];
+ }
+ };
+
+ lastEvent = RadioEvent.PACKET_TRANSMITTED;
+ /*logger.debug("----- CCC1120 PACKET TRANSMITTED -----");*/
+ setChanged();
+ notifyObservers();
+
+ /* Register that transmission ended in radio medium */
+ /*logger.debug("----- CCC1120 TRANSMISSION FINISHED -----");*/
+ isTransmitting = false;
+ lastEvent = RadioEvent.TRANSMISSION_FINISHED;
+ setChanged();
+ notifyObservers();
+ }
+
+ lastEvent = RadioEvent.HW_OFF;
+ setChanged();
+ notifyObservers();
+ }
+
+ /* Packet radio support */
+ public RadioPacket getLastPacketTransmitted() {
+ return lastOutgoingPacket;
+ }
+
+ public RadioPacket getLastPacketReceived() {
+ return lastIncomingPacket;
+ }
+
+ public void setReceivedPacket(RadioPacket packet) {
+ lastIncomingPacket = packet;
+
+ /* TODO XXX Need support in CCC1120.java */
+ /*if (!radio.isReadyToReceive()) {
+ logger.warn("Radio receiver not ready, dropping packet data");
+ return;
+ }*/
+
+ /* Delivering packet bytes with delays */
+ byte[] packetData = packet.getPacketData();
+ long deliveryTime = getMote().getSimulation().getSimulationTime();
+ for (byte b: packetData) {
+ if (isInterfered()) {
+ b = (byte) 0xFF;
+ }
+
+ final byte byteToDeliver = b;
+ getMote().getSimulation().scheduleEvent(new MspMoteTimeEvent(mote, 0) {
+ public void execute(long t) {
+ super.execute(t);
+ cc1120.receivedByte(byteToDeliver);
+ mote.requestImmediateWakeup();
+ }
+ }, deliveryTime);
+ deliveryTime += DELAY_BETWEEN_BYTES;
+ }
+ }
+
+ /* Custom data radio support */
+ public Object getLastCustomDataTransmitted() {
+ return lastOutgoingByte;
+ }
+
+ public Object getLastCustomDataReceived() {
+ return lastIncomingByte;
+ }
+
+ public void receiveCustomData(Object data) {
+ if (!(data instanceof Byte)) {
+ logger.fatal("Bad custom data: " + data);
+ return;
+ }
+ lastIncomingByte = (Byte) data;
+
+ final byte inputByte;
+ if (isInterfered()) {
+ inputByte = (byte)0xFF;
+ } else {
+ inputByte = lastIncomingByte;
+ }
+ mote.getSimulation().scheduleEvent(new MspMoteTimeEvent(mote, 0) {
+ public void execute(long t) {
+ super.execute(t);
+ cc1120.receivedByte(inputByte);
+ mote.requestImmediateWakeup();
+ }
+ }, mote.getSimulation().getSimulationTime());
+
+ }
+
+ /* General radio support */
+ public boolean isTransmitting() {
+ return isTransmitting;
+ }
+
+ public boolean isReceiving() {
+ return isReceiving;
+ }
+
+ public boolean isInterfered() {
+ return isInterfered;
+ }
+
+ public int getChannel() {
+ return cc1120.getActiveChannel()+1000;
+ }
+
+ public int getFrequency() {
+ return cc1120.getActiveFrequency();
+ }
+
+ public void signalReceptionStart() {
+ isReceiving = true;
+
+ lastEvent = RadioEvent.RECEPTION_STARTED;
+ /*logger.debug("----- CCC1120 RECEPTION STARTED -----");*/
+ setChanged();
+ notifyObservers();
+ }
+
+ public void signalReceptionEnd() {
+ /* Deliver packet data */
+ isReceiving = false;
+ isInterfered = false;
+
+ lastEvent = RadioEvent.RECEPTION_FINISHED;
+ /*logger.debug("----- CCC1120 RECEPTION FINISHED -----");*/
+ setChanged();
+ notifyObservers();
+ }
+
+ public RadioEvent getLastEvent() {
+ return lastEvent;
+ }
+
+ public void interfereAnyReception() {
+ isInterfered = true;
+ isReceiving = false;
+ lastIncomingPacket = null;
+
+ lastEvent = RadioEvent.RECEPTION_INTERFERED;
+ /*logger.debug("----- CCC1120 RECEPTION INTERFERED -----");*/
+ setChanged();
+ notifyObservers();
+ }
+
+ public double getCurrentOutputPower() {
+ /* TODO XXX Need support in CCC1120.java */
+ return 1;
+ }
+ public int getCurrentOutputPowerIndicator() {
+ /* TODO XXX Need support in CCC1120.java */
+ return 10;
+ }
+ public int getOutputPowerIndicatorMax() {
+ /* TODO XXX Need support in CCC1120.java */
+ return 10;
+ }
+
+
+ /**
+ * Last 8 received signal strengths
+ */
+ double currentSignalStrength = 0;
+ private double[] rssiLast = new double[8];
+ private int rssiLastCounter = 0;
+
+ public double getCurrentSignalStrength() {
+ return currentSignalStrength;
+ }
+
+ public void setCurrentSignalStrength(final double signalStrength) {
+ if (signalStrength == currentSignalStrength) {
+ return; /* ignored */
+ }
+ currentSignalStrength = signalStrength;
+ if (rssiLastCounter == 0) {
+ getMote().getSimulation().scheduleEvent(new MspMoteTimeEvent(mote, 0) {
+ public void execute(long t) {
+ super.execute(t);
+
+ /* Update average */
+ System.arraycopy(rssiLast, 1, rssiLast, 0, 7);
+ rssiLast[7] = currentSignalStrength;
+ double avg = 0;
+ for (double v: rssiLast) {
+ avg += v;
+ }
+ avg /= rssiLast.length;
+
+ cc1120.setRSSI((int) avg);
+
+ rssiLastCounter--;
+ if (rssiLastCounter > 0) {
+ mote.getSimulation().scheduleEvent(this, t+DELAY_BETWEEN_BYTES/2);
+ }
+ }
+ }, mote.getSimulation().getSimulationTime());
+ }
+ rssiLastCounter = 8;
+ }
+
+ public Mote getMote() {
+ return mote;
+ }
+
+ public Position getPosition() {
+ return mote.getInterfaces().getPosition();
+ }
+
+ public Collection getConfigXML() {
+ return null;
+ }
+
+ public void setConfigXML(Collection configXML, boolean visAvailable) {
+ }
+
+ public boolean isRadioOn() {
+ return cc1120.isReadyToReceive();
+ }
+
+ public boolean canReceiveFrom(CustomDataRadio radio) {
+ if (radio.getClass().equals(this.getClass())) {
+ return true;
+ }
+ return false;
+ }
+
+}
diff --git a/tools/cooja/apps/mspsim/src/org/contikios/cooja/mspmote/interfaces/CC2520Radio.java b/tools/cooja/apps/mspsim/src/org/contikios/cooja/mspmote/interfaces/CC2520Radio.java
index d219f9171..49d86c451 100644
--- a/tools/cooja/apps/mspsim/src/org/contikios/cooja/mspmote/interfaces/CC2520Radio.java
+++ b/tools/cooja/apps/mspsim/src/org/contikios/cooja/mspmote/interfaces/CC2520Radio.java
@@ -1,378 +1,378 @@
-
-package org.contikios.cooja.mspmote.interfaces;
-
-import java.util.Collection;
-
-import org.apache.log4j.Logger;
-import org.jdom.Element;
-
-import org.contikios.cooja.ClassDescription;
-import org.contikios.cooja.Mote;
-import org.contikios.cooja.RadioPacket;
-import org.contikios.cooja.Simulation;
-import org.contikios.cooja.interfaces.CustomDataRadio;
-import org.contikios.cooja.interfaces.Position;
-import org.contikios.cooja.interfaces.Radio;
-import org.contikios.cooja.mspmote.MspMote;
-import org.contikios.cooja.mspmote.MspMoteTimeEvent;
-import org.contikios.cooja.mspmote.interfaces.CC2420RadioPacketConverter;
-import se.sics.mspsim.chip.CC2520;
-import se.sics.mspsim.chip.ChannelListener;
-import se.sics.mspsim.chip.RFListener;
-import se.sics.mspsim.core.Chip;
-import se.sics.mspsim.core.OperatingModeListener;
-
-/**
- * MSPSim CC2520 radio to COOJA wrapper.
- *
- * @author Fredrik Osterlind
- */
-@ClassDescription("IEEE CC2520 Radio")
-public class CC2520Radio extends Radio implements CustomDataRadio {
- private static Logger logger = Logger.getLogger(CC2520Radio.class);
-
- /**
- * Cross-level:
- * Inter-byte delay for delivering cross-level packet bytes.
- */
- public static final long DELAY_BETWEEN_BYTES =
- (long) (1000.0*Simulation.MILLISECOND/(250000.0/8.0)); /* us. Corresponds to 250kbit/s */
-
- private RadioEvent lastEvent = RadioEvent.UNKNOWN;
-
- private final MspMote mote;
- private final CC2520 radio;
-
- private boolean isInterfered = false;
- private boolean isTransmitting = false;
- private boolean isReceiving = false;
-
- private byte lastOutgoingByte;
- private byte lastIncomingByte;
-
- private RadioPacket lastOutgoingPacket = null;
- private RadioPacket lastIncomingPacket = null;
-
- public CC2520Radio(Mote m) {
- this.mote = (MspMote)m;
- this.radio = this.mote.getCPU().getChip(CC2520.class);
- if (radio == null) {
- throw new IllegalStateException("Mote is not equipped with an IEEE CC2520 radio");
- }
-
- radio.addRFListener(new RFListener() {
- int len = 0;
- int expLen = 0;
- byte[] buffer = new byte[127 + 15];
- public void receivedByte(byte data) {
- if (!isTransmitting()) {
- lastEvent = RadioEvent.TRANSMISSION_STARTED;
- isTransmitting = true;
- len = 0;
- /*logger.debug("----- CC2520 TRANSMISSION STARTED -----");*/
- setChanged();
- notifyObservers();
- }
-
- if (len >= buffer.length) {
- /* Bad size packet, too large */
- logger.debug("Error: bad size: " + len + ", dropping outgoing byte: " + data);
- return;
- }
-
- /* send this byte to all nodes */
- lastOutgoingByte = data;
- lastEvent = RadioEvent.CUSTOM_DATA_TRANSMITTED;
- setChanged();
- notifyObservers();
-
- buffer[len++] = data;
-
- if (len == 6) {
-// System.out.println("## CC2520 Packet of length: " + data + " expected...");
- expLen = data + 6;
- }
-
- if (len == expLen) {
- /*logger.debug("----- CC2520 CUSTOM DATA TRANSMITTED -----");*/
- len -= 4; /* preamble */
- len -= 1; /* synch */
- len -= radio.getFooterLength(); /* footer */
- final byte[] packetdata = new byte[len];
- System.arraycopy(buffer, 4+1, packetdata, 0, len);
- lastOutgoingPacket = new RadioPacket() {
- public byte[] getPacketData() {
- return packetdata;
- }
- };
-
- /*logger.debug("----- CC2520 PACKET TRANSMITTED -----");*/
- setChanged();
- notifyObservers();
-
- /*logger.debug("----- CC2520 TRANSMISSION FINISHED -----");*/
- isTransmitting = false;
- lastEvent = RadioEvent.TRANSMISSION_FINISHED;
- setChanged();
- notifyObservers();
- len = 0;
- }
- }
- });
-
- radio.addOperatingModeListener(new OperatingModeListener() {
- public void modeChanged(Chip source, int mode) {
- if (radio.isReadyToReceive()) {
- lastEvent = RadioEvent.HW_ON;
- setChanged();
- notifyObservers();
- } else {
- radioOff();
- }
- }
- });
-
- radio.addChannelListener(new ChannelListener() {
- public void channelChanged(int channel) {
- /* XXX Currently assumes zero channel switch time */
- lastEvent = RadioEvent.UNKNOWN;
- setChanged();
- notifyObservers();
- }
- });
- }
-
- private void radioOff() {
- /* Radio was turned off during transmission.
- * May for example happen if watchdog triggers */
- if (isTransmitting()) {
- logger.warn("Turning off radio while transmitting, ending packet prematurely");
-
- /* Simulate end of packet */
- lastOutgoingPacket = new RadioPacket() {
- public byte[] getPacketData() {
- return new byte[0];
- }
- };
-
- lastEvent = RadioEvent.PACKET_TRANSMITTED;
- /*logger.debug("----- CC2520 PACKET TRANSMITTED -----");*/
- setChanged();
- notifyObservers();
-
- /* Register that transmission ended in radio medium */
- /*logger.debug("----- CC2520 TRANSMISSION FINISHED -----");*/
- isTransmitting = false;
- lastEvent = RadioEvent.TRANSMISSION_FINISHED;
- setChanged();
- notifyObservers();
- }
-
- lastEvent = RadioEvent.HW_OFF;
- setChanged();
- notifyObservers();
- }
-
- /* Packet radio support */
- public RadioPacket getLastPacketTransmitted() {
- return lastOutgoingPacket;
- }
-
- public RadioPacket getLastPacketReceived() {
- return lastIncomingPacket;
- }
-
- public void setReceivedPacket(RadioPacket packet) {
- logger.fatal("TODO Implement me!");
- }
-
- /* Custom data radio support */
- public Object getLastCustomDataTransmitted() {
- return lastOutgoingByte;
- }
-
- public Object getLastCustomDataReceived() {
- return lastIncomingByte;
- }
-
- public void receiveCustomData(Object data) {
- if (!(data instanceof Byte)) {
- logger.fatal("Bad custom data: " + data);
- return;
- }
- lastIncomingByte = (Byte) data;
-
- final byte inputByte;
- if (isInterfered()) {
- inputByte = (byte)0xFF;
- } else {
- inputByte = lastIncomingByte;
- }
- mote.getSimulation().scheduleEvent(new MspMoteTimeEvent(mote, 0) {
- public void execute(long t) {
- super.execute(t);
- radio.receivedByte(inputByte);
- mote.requestImmediateWakeup();
- }
- }, mote.getSimulation().getSimulationTime());
-
- }
-
- /* General radio support */
- public boolean isTransmitting() {
- return isTransmitting;
- }
-
- public boolean isReceiving() {
- return isReceiving;
- }
-
- public boolean isInterfered() {
- return isInterfered;
- }
-
- public int getChannel() {
- return radio.getActiveChannel();
- }
-
- public int getFrequency() {
- return radio.getActiveFrequency();
- }
-
- public void signalReceptionStart() {
- isReceiving = true;
-
- lastEvent = RadioEvent.RECEPTION_STARTED;
- /*logger.debug("----- CC2520 RECEPTION STARTED -----");*/
- setChanged();
- notifyObservers();
- }
-
- public void signalReceptionEnd() {
- /* Deliver packet data */
- isReceiving = false;
- isInterfered = false;
-
- lastEvent = RadioEvent.RECEPTION_FINISHED;
- /*logger.debug("----- CC2520 RECEPTION FINISHED -----");*/
- setChanged();
- notifyObservers();
- }
-
- public RadioEvent getLastEvent() {
- return lastEvent;
- }
-
- public void interfereAnyReception() {
- isInterfered = true;
- isReceiving = false;
- lastIncomingPacket = null;
-
- lastEvent = RadioEvent.RECEPTION_INTERFERED;
- /*logger.debug("----- CC2520 RECEPTION INTERFERED -----");*/
- setChanged();
- notifyObservers();
- }
-
- public double getCurrentOutputPower() {
- return radio.getOutputPower();
- }
-
- public int getCurrentOutputPowerIndicator() {
- return 100;
-// return radio.getOutputPowerIndicator();
- }
-
- public int getOutputPowerIndicatorMax() {
- return 100;
-// return 31;
- }
-
- double currentSignalStrength = 0;
-
- /**
- * Last 8 received signal strengths
- */
- private double[] rssiLast = new double[8];
- private int rssiLastCounter = 0;
-
- public double getCurrentSignalStrength() {
- return currentSignalStrength;
- }
-
- public void setCurrentSignalStrength(final double signalStrength) {
- if (signalStrength == currentSignalStrength) {
- return; /* ignored */
- }
- currentSignalStrength = signalStrength;
- if (rssiLastCounter == 0) {
- getMote().getSimulation().scheduleEvent(new MspMoteTimeEvent(mote, 0) {
- public void execute(long t) {
- super.execute(t);
-
- /* Update average */
- System.arraycopy(rssiLast, 1, rssiLast, 0, 7);
- rssiLast[7] = currentSignalStrength;
- double avg = 0;
- for (double v: rssiLast) {
- avg += v;
- }
- avg /= rssiLast.length;
-
- radio.setRSSI((int) avg);
-
- rssiLastCounter--;
- if (rssiLastCounter > 0) {
- mote.getSimulation().scheduleEvent(this, t+DELAY_BETWEEN_BYTES/2);
- }
- }
- }, mote.getSimulation().getSimulationTime());
- }
- rssiLastCounter = 8;
- }
-
-
- public void setLQI(int lqi){
- radio.setLQI(lqi);
- }
-
- public int getLQI(){
- return radio.getLQI();
- }
-
-
- public Mote getMote() {
- return mote;
- }
-
- public Position getPosition() {
- return mote.getInterfaces().getPosition();
- }
-
- public Collection getConfigXML() {
- return null;
- }
-
- public void setConfigXML(Collection configXML, boolean visAvailable) {
- }
-
- public boolean isRadioOn() {
- if (radio.isReadyToReceive()) {
- return true;
- }
- if (radio.getMode() == CC2520.MODE_POWER_OFF) {
- return false;
- }
- if (radio.getMode() == CC2520.MODE_TXRX_OFF) {
- return false;
- }
- return true;
- }
-
- public boolean canReceiveFrom(CustomDataRadio radio) {
- if (radio.getClass().equals(this.getClass())) {
- return true;
- }
- return false;
- }
-}
+
+package org.contikios.cooja.mspmote.interfaces;
+
+import java.util.Collection;
+
+import org.apache.log4j.Logger;
+import org.jdom.Element;
+
+import org.contikios.cooja.ClassDescription;
+import org.contikios.cooja.Mote;
+import org.contikios.cooja.RadioPacket;
+import org.contikios.cooja.Simulation;
+import org.contikios.cooja.interfaces.CustomDataRadio;
+import org.contikios.cooja.interfaces.Position;
+import org.contikios.cooja.interfaces.Radio;
+import org.contikios.cooja.mspmote.MspMote;
+import org.contikios.cooja.mspmote.MspMoteTimeEvent;
+import org.contikios.cooja.mspmote.interfaces.CC2420RadioPacketConverter;
+import se.sics.mspsim.chip.CC2520;
+import se.sics.mspsim.chip.ChannelListener;
+import se.sics.mspsim.chip.RFListener;
+import se.sics.mspsim.core.Chip;
+import se.sics.mspsim.core.OperatingModeListener;
+
+/**
+ * MSPSim CC2520 radio to COOJA wrapper.
+ *
+ * @author Fredrik Osterlind
+ */
+@ClassDescription("IEEE CC2520 Radio")
+public class CC2520Radio extends Radio implements CustomDataRadio {
+ private static Logger logger = Logger.getLogger(CC2520Radio.class);
+
+ /**
+ * Cross-level:
+ * Inter-byte delay for delivering cross-level packet bytes.
+ */
+ public static final long DELAY_BETWEEN_BYTES =
+ (long) (1000.0*Simulation.MILLISECOND/(250000.0/8.0)); /* us. Corresponds to 250kbit/s */
+
+ private RadioEvent lastEvent = RadioEvent.UNKNOWN;
+
+ private final MspMote mote;
+ private final CC2520 radio;
+
+ private boolean isInterfered = false;
+ private boolean isTransmitting = false;
+ private boolean isReceiving = false;
+
+ private byte lastOutgoingByte;
+ private byte lastIncomingByte;
+
+ private RadioPacket lastOutgoingPacket = null;
+ private RadioPacket lastIncomingPacket = null;
+
+ public CC2520Radio(Mote m) {
+ this.mote = (MspMote)m;
+ this.radio = this.mote.getCPU().getChip(CC2520.class);
+ if (radio == null) {
+ throw new IllegalStateException("Mote is not equipped with an IEEE CC2520 radio");
+ }
+
+ radio.addRFListener(new RFListener() {
+ int len = 0;
+ int expLen = 0;
+ byte[] buffer = new byte[127 + 15];
+ public void receivedByte(byte data) {
+ if (!isTransmitting()) {
+ lastEvent = RadioEvent.TRANSMISSION_STARTED;
+ isTransmitting = true;
+ len = 0;
+ /*logger.debug("----- CC2520 TRANSMISSION STARTED -----");*/
+ setChanged();
+ notifyObservers();
+ }
+
+ if (len >= buffer.length) {
+ /* Bad size packet, too large */
+ logger.debug("Error: bad size: " + len + ", dropping outgoing byte: " + data);
+ return;
+ }
+
+ /* send this byte to all nodes */
+ lastOutgoingByte = data;
+ lastEvent = RadioEvent.CUSTOM_DATA_TRANSMITTED;
+ setChanged();
+ notifyObservers();
+
+ buffer[len++] = data;
+
+ if (len == 6) {
+// System.out.println("## CC2520 Packet of length: " + data + " expected...");
+ expLen = data + 6;
+ }
+
+ if (len == expLen) {
+ /*logger.debug("----- CC2520 CUSTOM DATA TRANSMITTED -----");*/
+ len -= 4; /* preamble */
+ len -= 1; /* synch */
+ len -= radio.getFooterLength(); /* footer */
+ final byte[] packetdata = new byte[len];
+ System.arraycopy(buffer, 4+1, packetdata, 0, len);
+ lastOutgoingPacket = new RadioPacket() {
+ public byte[] getPacketData() {
+ return packetdata;
+ }
+ };
+
+ /*logger.debug("----- CC2520 PACKET TRANSMITTED -----");*/
+ setChanged();
+ notifyObservers();
+
+ /*logger.debug("----- CC2520 TRANSMISSION FINISHED -----");*/
+ isTransmitting = false;
+ lastEvent = RadioEvent.TRANSMISSION_FINISHED;
+ setChanged();
+ notifyObservers();
+ len = 0;
+ }
+ }
+ });
+
+ radio.addOperatingModeListener(new OperatingModeListener() {
+ public void modeChanged(Chip source, int mode) {
+ if (radio.isReadyToReceive()) {
+ lastEvent = RadioEvent.HW_ON;
+ setChanged();
+ notifyObservers();
+ } else {
+ radioOff();
+ }
+ }
+ });
+
+ radio.addChannelListener(new ChannelListener() {
+ public void channelChanged(int channel) {
+ /* XXX Currently assumes zero channel switch time */
+ lastEvent = RadioEvent.UNKNOWN;
+ setChanged();
+ notifyObservers();
+ }
+ });
+ }
+
+ private void radioOff() {
+ /* Radio was turned off during transmission.
+ * May for example happen if watchdog triggers */
+ if (isTransmitting()) {
+ logger.warn("Turning off radio while transmitting, ending packet prematurely");
+
+ /* Simulate end of packet */
+ lastOutgoingPacket = new RadioPacket() {
+ public byte[] getPacketData() {
+ return new byte[0];
+ }
+ };
+
+ lastEvent = RadioEvent.PACKET_TRANSMITTED;
+ /*logger.debug("----- CC2520 PACKET TRANSMITTED -----");*/
+ setChanged();
+ notifyObservers();
+
+ /* Register that transmission ended in radio medium */
+ /*logger.debug("----- CC2520 TRANSMISSION FINISHED -----");*/
+ isTransmitting = false;
+ lastEvent = RadioEvent.TRANSMISSION_FINISHED;
+ setChanged();
+ notifyObservers();
+ }
+
+ lastEvent = RadioEvent.HW_OFF;
+ setChanged();
+ notifyObservers();
+ }
+
+ /* Packet radio support */
+ public RadioPacket getLastPacketTransmitted() {
+ return lastOutgoingPacket;
+ }
+
+ public RadioPacket getLastPacketReceived() {
+ return lastIncomingPacket;
+ }
+
+ public void setReceivedPacket(RadioPacket packet) {
+ logger.fatal("TODO Implement me!");
+ }
+
+ /* Custom data radio support */
+ public Object getLastCustomDataTransmitted() {
+ return lastOutgoingByte;
+ }
+
+ public Object getLastCustomDataReceived() {
+ return lastIncomingByte;
+ }
+
+ public void receiveCustomData(Object data) {
+ if (!(data instanceof Byte)) {
+ logger.fatal("Bad custom data: " + data);
+ return;
+ }
+ lastIncomingByte = (Byte) data;
+
+ final byte inputByte;
+ if (isInterfered()) {
+ inputByte = (byte)0xFF;
+ } else {
+ inputByte = lastIncomingByte;
+ }
+ mote.getSimulation().scheduleEvent(new MspMoteTimeEvent(mote, 0) {
+ public void execute(long t) {
+ super.execute(t);
+ radio.receivedByte(inputByte);
+ mote.requestImmediateWakeup();
+ }
+ }, mote.getSimulation().getSimulationTime());
+
+ }
+
+ /* General radio support */
+ public boolean isTransmitting() {
+ return isTransmitting;
+ }
+
+ public boolean isReceiving() {
+ return isReceiving;
+ }
+
+ public boolean isInterfered() {
+ return isInterfered;
+ }
+
+ public int getChannel() {
+ return radio.getActiveChannel();
+ }
+
+ public int getFrequency() {
+ return radio.getActiveFrequency();
+ }
+
+ public void signalReceptionStart() {
+ isReceiving = true;
+
+ lastEvent = RadioEvent.RECEPTION_STARTED;
+ /*logger.debug("----- CC2520 RECEPTION STARTED -----");*/
+ setChanged();
+ notifyObservers();
+ }
+
+ public void signalReceptionEnd() {
+ /* Deliver packet data */
+ isReceiving = false;
+ isInterfered = false;
+
+ lastEvent = RadioEvent.RECEPTION_FINISHED;
+ /*logger.debug("----- CC2520 RECEPTION FINISHED -----");*/
+ setChanged();
+ notifyObservers();
+ }
+
+ public RadioEvent getLastEvent() {
+ return lastEvent;
+ }
+
+ public void interfereAnyReception() {
+ isInterfered = true;
+ isReceiving = false;
+ lastIncomingPacket = null;
+
+ lastEvent = RadioEvent.RECEPTION_INTERFERED;
+ /*logger.debug("----- CC2520 RECEPTION INTERFERED -----");*/
+ setChanged();
+ notifyObservers();
+ }
+
+ public double getCurrentOutputPower() {
+ return radio.getOutputPower();
+ }
+
+ public int getCurrentOutputPowerIndicator() {
+ return 100;
+// return radio.getOutputPowerIndicator();
+ }
+
+ public int getOutputPowerIndicatorMax() {
+ return 100;
+// return 31;
+ }
+
+ double currentSignalStrength = 0;
+
+ /**
+ * Last 8 received signal strengths
+ */
+ private double[] rssiLast = new double[8];
+ private int rssiLastCounter = 0;
+
+ public double getCurrentSignalStrength() {
+ return currentSignalStrength;
+ }
+
+ public void setCurrentSignalStrength(final double signalStrength) {
+ if (signalStrength == currentSignalStrength) {
+ return; /* ignored */
+ }
+ currentSignalStrength = signalStrength;
+ if (rssiLastCounter == 0) {
+ getMote().getSimulation().scheduleEvent(new MspMoteTimeEvent(mote, 0) {
+ public void execute(long t) {
+ super.execute(t);
+
+ /* Update average */
+ System.arraycopy(rssiLast, 1, rssiLast, 0, 7);
+ rssiLast[7] = currentSignalStrength;
+ double avg = 0;
+ for (double v: rssiLast) {
+ avg += v;
+ }
+ avg /= rssiLast.length;
+
+ radio.setRSSI((int) avg);
+
+ rssiLastCounter--;
+ if (rssiLastCounter > 0) {
+ mote.getSimulation().scheduleEvent(this, t+DELAY_BETWEEN_BYTES/2);
+ }
+ }
+ }, mote.getSimulation().getSimulationTime());
+ }
+ rssiLastCounter = 8;
+ }
+
+
+ public void setLQI(int lqi){
+ radio.setLQI(lqi);
+ }
+
+ public int getLQI(){
+ return radio.getLQI();
+ }
+
+
+ public Mote getMote() {
+ return mote;
+ }
+
+ public Position getPosition() {
+ return mote.getInterfaces().getPosition();
+ }
+
+ public Collection getConfigXML() {
+ return null;
+ }
+
+ public void setConfigXML(Collection configXML, boolean visAvailable) {
+ }
+
+ public boolean isRadioOn() {
+ if (radio.isReadyToReceive()) {
+ return true;
+ }
+ if (radio.getMode() == CC2520.MODE_POWER_OFF) {
+ return false;
+ }
+ if (radio.getMode() == CC2520.MODE_TXRX_OFF) {
+ return false;
+ }
+ return true;
+ }
+
+ public boolean canReceiveFrom(CustomDataRadio radio) {
+ if (radio.getClass().equals(this.getClass())) {
+ return true;
+ }
+ return false;
+ }
+}
diff --git a/tools/cooja/apps/mspsim/src/org/contikios/cooja/mspmote/interfaces/CC430Radio.java b/tools/cooja/apps/mspsim/src/org/contikios/cooja/mspmote/interfaces/CC430Radio.java
index 692c9996c..68c971e8e 100644
--- a/tools/cooja/apps/mspsim/src/org/contikios/cooja/mspmote/interfaces/CC430Radio.java
+++ b/tools/cooja/apps/mspsim/src/org/contikios/cooja/mspmote/interfaces/CC430Radio.java
@@ -1,50 +1,50 @@
-/*
- * Copyright (c) 2012, Thingsquare.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the Institute nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- */
-
-package org.contikios.cooja.mspmote.interfaces;
-
-import org.apache.log4j.Logger;
-
-import org.contikios.cooja.ClassDescription;
-import org.contikios.cooja.Mote;
-import org.contikios.cooja.interfaces.CustomDataRadio;
-
-/**
- * @author Fredrik Osterlind
- */
-@ClassDescription("TI CC1101 (CC430)")
-public class CC430Radio extends CC1101Radio implements CustomDataRadio {
- private static Logger logger = Logger.getLogger(CC1101Radio.class);
-
- public CC430Radio(Mote m) {
- super(m);
- }
-
-}
+/*
+ * Copyright (c) 2012, Thingsquare.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the Institute nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+package org.contikios.cooja.mspmote.interfaces;
+
+import org.apache.log4j.Logger;
+
+import org.contikios.cooja.ClassDescription;
+import org.contikios.cooja.Mote;
+import org.contikios.cooja.interfaces.CustomDataRadio;
+
+/**
+ * @author Fredrik Osterlind
+ */
+@ClassDescription("TI CC1101 (CC430)")
+public class CC430Radio extends CC1101Radio implements CustomDataRadio {
+ private static Logger logger = Logger.getLogger(CC1101Radio.class);
+
+ public CC430Radio(Mote m) {
+ super(m);
+ }
+
+}
diff --git a/tools/cooja/apps/powertracker/cooja.config b/tools/cooja/apps/powertracker/cooja.config
index 70a4f821c..b59c95ad2 100644
--- a/tools/cooja/apps/powertracker/cooja.config
+++ b/tools/cooja/apps/powertracker/cooja.config
@@ -1,2 +1,2 @@
-org.contikios.cooja.Cooja.PLUGINS = + PowerTracker
-org.contikios.cooja.Cooja.JARFILES = + powertracker.jar
+org.contikios.cooja.Cooja.PLUGINS = + PowerTracker
+org.contikios.cooja.Cooja.JARFILES = + powertracker.jar
diff --git a/tools/cooja/config/cooja.html b/tools/cooja/config/cooja.html
index b2f44de6f..d51ffc847 100644
--- a/tools/cooja/config/cooja.html
+++ b/tools/cooja/config/cooja.html
@@ -1,12 +1,12 @@
-
- The COOJA Simulator (applet)
-
-
-
-
-
-
-
+
+ The COOJA Simulator (applet)
+
+
+
+
+
+
+
diff --git a/tools/cooja/config/cooja.policy b/tools/cooja/config/cooja.policy
index 2fd15c8dd..53a9d407d 100644
--- a/tools/cooja/config/cooja.policy
+++ b/tools/cooja/config/cooja.policy
@@ -1,3 +1,3 @@
-grant {
-permission java.security.AllPermission;
-};
+grant {
+permission java.security.AllPermission;
+};
diff --git a/tools/cooja/config/log4j_config.xml b/tools/cooja/config/log4j_config.xml
index d3d269bb8..d83b38e0f 100644
--- a/tools/cooja/config/log4j_config.xml
+++ b/tools/cooja/config/log4j_config.xml
@@ -1,25 +1,25 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tools/cooja/config/quickhelp.txt b/tools/cooja/config/quickhelp.txt
index cc6de2210..a4514c7da 100644
--- a/tools/cooja/config/quickhelp.txt
+++ b/tools/cooja/config/quickhelp.txt
@@ -1,14 +1,13 @@
-KEYBOARD_SHORTCUTS = \
-Keyboard shortcuts \
- Ctrl+N: New simulation\
- Ctrl+S: Start/pause simulation\
- Ctrl+R: Reload current simulation. If no simulation exists, the last used simulation config is loaded\
- Ctrl+Shift+R: Reload current simulation with another random seed\
- \
- F1: Toggle quick help
-
-GETTING_STARTED = \
-Getting started \
- \
- F1: Toggle quick help
-
+KEYBOARD_SHORTCUTS = \
+Keyboard shortcuts \
+ Ctrl+N: New simulation\
+ Ctrl+S: Start/pause simulation\
+ Ctrl+R: Reload current simulation. If no simulation exists, the last used simulation config is loaded\
+ Ctrl+Shift+R: Reload current simulation with another random seed\
+ \
+ F1: Toggle quick help
+
+GETTING_STARTED = \
+Getting started \
+ \
+ F1: Toggle quick help
diff --git a/tools/cooja/config/scripts/basic.js b/tools/cooja/config/scripts/basic.js
index ebbacaaca..cd454dea0 100644
--- a/tools/cooja/config/scripts/basic.js
+++ b/tools/cooja/config/scripts/basic.js
@@ -1,28 +1,28 @@
-/*
- * Example Contiki test script (JavaScript).
- * A Contiki test script acts on mote output, such as via printf()'s.
- * The script may operate on the following variables:
- * Mote mote, int id, String msg
- */
-
-/* Make test automatically fail (timeout) after 100 simulated seconds */
-//TIMEOUT(100000); /* milliseconds. no action at timeout */
-TIMEOUT(100000, log.log("last msg: " + msg + "\n")); /* milliseconds. print last msg at timeout */
-
-log.log("first mote output: '" + msg + "'\n");
-
-YIELD(); /* wait for another mote output */
-
-log.log("second mote output: '" + msg + "'\n");
-
-log.log("waiting for hello world output from mote 1\n");
-WAIT_UNTIL(id == 1 && msg.equals("Hello, world"));
-
-write(mote, "Hello, mote\n"); /* Write to mote serial port */
-
-GENERATE_MSG(15000, "continue");
-YIELD_THEN_WAIT_UNTIL(msg.equals("continue"));
-
-log.log("ok, reporting success now\n");
-log.testOK(); /* Report test success and quit */
-//log.testFailed(); /* Report test failure and quit */
+/*
+ * Example Contiki test script (JavaScript).
+ * A Contiki test script acts on mote output, such as via printf()'s.
+ * The script may operate on the following variables:
+ * Mote mote, int id, String msg
+ */
+
+/* Make test automatically fail (timeout) after 100 simulated seconds */
+//TIMEOUT(100000); /* milliseconds. no action at timeout */
+TIMEOUT(100000, log.log("last msg: " + msg + "\n")); /* milliseconds. print last msg at timeout */
+
+log.log("first mote output: '" + msg + "'\n");
+
+YIELD(); /* wait for another mote output */
+
+log.log("second mote output: '" + msg + "'\n");
+
+log.log("waiting for hello world output from mote 1\n");
+WAIT_UNTIL(id == 1 && msg.equals("Hello, world"));
+
+write(mote, "Hello, mote\n"); /* Write to mote serial port */
+
+GENERATE_MSG(15000, "continue");
+YIELD_THEN_WAIT_UNTIL(msg.equals("continue"));
+
+log.log("ok, reporting success now\n");
+log.testOK(); /* Report test success and quit */
+//log.testFailed(); /* Report test failure and quit */
diff --git a/tools/cooja/config/scripts/helloworld.js b/tools/cooja/config/scripts/helloworld.js
index 5f6f617b5..6d82a7352 100644
--- a/tools/cooja/config/scripts/helloworld.js
+++ b/tools/cooja/config/scripts/helloworld.js
@@ -1,11 +1,11 @@
-/*
- * Example Contiki test script (JavaScript).
- * A Contiki test script acts on mote output, such as via printf()'s.
- * The script may operate on the following variables:
- * Mote mote, int id, String msg
- */
-
-TIMEOUT(2000, log.log("last message: " + msg + "\n"));
-
-WAIT_UNTIL(msg.equals('Hello, world'));
-log.testOK();
+/*
+ * Example Contiki test script (JavaScript).
+ * A Contiki test script acts on mote output, such as via printf()'s.
+ * The script may operate on the following variables:
+ * Mote mote, int id, String msg
+ */
+
+TIMEOUT(2000, log.log("last message: " + msg + "\n"));
+
+WAIT_UNTIL(msg.equals('Hello, world'));
+log.testOK();
diff --git a/tools/cooja/config/scripts/log_all.js b/tools/cooja/config/scripts/log_all.js
index b0c20069d..d4eb6233f 100644
--- a/tools/cooja/config/scripts/log_all.js
+++ b/tools/cooja/config/scripts/log_all.js
@@ -1,13 +1,13 @@
-/*
- * Example Contiki test script (JavaScript).
- * A Contiki test script acts on mote output, such as via printf()'s.
- * The script may operate on the following variables:
- * Mote mote, int id, String msg
- */
-
-TIMEOUT(60000);
-
-while (true) {
- log.log(time + ":" + id + ":" + msg + "\n");
- YIELD();
-}
+/*
+ * Example Contiki test script (JavaScript).
+ * A Contiki test script acts on mote output, such as via printf()'s.
+ * The script may operate on the following variables:
+ * Mote mote, int id, String msg
+ */
+
+TIMEOUT(60000);
+
+while (true) {
+ log.log(time + ":" + id + ":" + msg + "\n");
+ YIELD();
+}
diff --git a/tools/cooja/config/scripts/plugins.js b/tools/cooja/config/scripts/plugins.js
index 664d14030..4c205aabb 100644
--- a/tools/cooja/config/scripts/plugins.js
+++ b/tools/cooja/config/scripts/plugins.js
@@ -1,66 +1,66 @@
-/*
- * Example showing how to reference and interact with surrounding
- * COOJA plugins from a test script.
- * The code looks up three common plugins and, if found, performs some
- * simple plugin-specific task.
- */
-
-/* Started plugins are available from the GUI object */
-
-TIMEOUT(60000);
-
-counter=0;
-plugins=0;
-
-timeout_function = function my_fun() {
- log.log("Script timed out.\n");
- log.log(plugins + " plugins were referenced\n");
-}
-
-while (counter<10) {
- counter++;
-
- GENERATE_MSG(1000, "wait");
- YIELD_THEN_WAIT_UNTIL(msg.equals("wait"));
-
- /* Toggle Log Listener filter */
- plugin = mote.getSimulation().getCooja().getStartedPlugin("org.contikios.cooja.plugins.LogListener");
- if (plugin != null) {
- plugins++;
- log.log("LogListener: Setting filter: " + plugin.getFilter() + "\n");
- if (plugin.getFilter() == null || !plugin.getFilter().equals("Contiki")) {
- plugin.setFilter("Contiki");
- } else {
- plugin.setFilter("MAC");
- }
- }
-
- GENERATE_MSG(1000, "wait");
- YIELD_THEN_WAIT_UNTIL(msg.equals("wait"));
-
- /* Extract PowerTracker statistics */
- plugin = mote.getSimulation().getCooja().getStartedPlugin("PowerTracker");
- if (plugin != null) {
- plugins++;
- stats = plugin.radioStatistics();
- if (stats.length() > 40) {
- /* Stripping */
- stats = stats.substring(0, 40) + "...";
- }
- log.log("PowerTracker: Extracted statistics:\n" + stats + "\n");
- } else {
- log.log("No PowerTracker plugin\n");
- }
-
- GENERATE_MSG(1000, "wait");
- YIELD_THEN_WAIT_UNTIL(msg.equals("wait"));
-
- /* Select time in Radio Logger */
- plugin = mote.getSimulation().getCooja().getStartedPlugin("org.contikios.cooja.plugins.RadioLogger");
- if (plugin != null) {
- plugins++;
- log.log("RadioLogger: Showing logged radio packet at mid simulation\n");
- plugin.trySelectTime(time/2);
- }
-
-}
+/*
+ * Example showing how to reference and interact with surrounding
+ * COOJA plugins from a test script.
+ * The code looks up three common plugins and, if found, performs some
+ * simple plugin-specific task.
+ */
+
+/* Started plugins are available from the GUI object */
+
+TIMEOUT(60000);
+
+counter=0;
+plugins=0;
+
+timeout_function = function my_fun() {
+ log.log("Script timed out.\n");
+ log.log(plugins + " plugins were referenced\n");
+}
+
+while (counter<10) {
+ counter++;
+
+ GENERATE_MSG(1000, "wait");
+ YIELD_THEN_WAIT_UNTIL(msg.equals("wait"));
+
+ /* Toggle Log Listener filter */
+ plugin = mote.getSimulation().getCooja().getStartedPlugin("org.contikios.cooja.plugins.LogListener");
+ if (plugin != null) {
+ plugins++;
+ log.log("LogListener: Setting filter: " + plugin.getFilter() + "\n");
+ if (plugin.getFilter() == null || !plugin.getFilter().equals("Contiki")) {
+ plugin.setFilter("Contiki");
+ } else {
+ plugin.setFilter("MAC");
+ }
+ }
+
+ GENERATE_MSG(1000, "wait");
+ YIELD_THEN_WAIT_UNTIL(msg.equals("wait"));
+
+ /* Extract PowerTracker statistics */
+ plugin = mote.getSimulation().getCooja().getStartedPlugin("PowerTracker");
+ if (plugin != null) {
+ plugins++;
+ stats = plugin.radioStatistics();
+ if (stats.length() > 40) {
+ /* Stripping */
+ stats = stats.substring(0, 40) + "...";
+ }
+ log.log("PowerTracker: Extracted statistics:\n" + stats + "\n");
+ } else {
+ log.log("No PowerTracker plugin\n");
+ }
+
+ GENERATE_MSG(1000, "wait");
+ YIELD_THEN_WAIT_UNTIL(msg.equals("wait"));
+
+ /* Select time in Radio Logger */
+ plugin = mote.getSimulation().getCooja().getStartedPlugin("org.contikios.cooja.plugins.RadioLogger");
+ if (plugin != null) {
+ plugins++;
+ log.log("RadioLogger: Showing logged radio packet at mid simulation\n");
+ plugin.trySelectTime(time/2);
+ }
+
+}
diff --git a/tools/cooja/config/scripts/shell.js b/tools/cooja/config/scripts/shell.js
index 6dc1a8fdb..6590aa481 100644
--- a/tools/cooja/config/scripts/shell.js
+++ b/tools/cooja/config/scripts/shell.js
@@ -1,27 +1,27 @@
-/*
- * Example Contiki test script (JavaScript).
- * A Contiki test script acts on mote output, such as via printf()'s.
- * The script may operate on the following variables:
- * Mote mote, int id, String msg
- */
-
-/* Wait until node has booted */
-WAIT_UNTIL(msg.startsWith('Starting'));
-log.log("Mote started\n");
-mymote = mote; /* store mote reference */
-
-/* Wait 3 seconds (3000ms) */
-GENERATE_MSG(3000, "continue");
-YIELD_THEN_WAIT_UNTIL(msg.equals("continue"));
-
-/* Write command to serial port */
-log.log("Writing 'ls' to mote serial port\n");
-write(mymote, "ls");
-
-/* Read replies */
-while (true) {
- YIELD();
- if (mote == mymote) {
- log.log("Mote replied: " + msg + "\n");
- }
+/*
+ * Example Contiki test script (JavaScript).
+ * A Contiki test script acts on mote output, such as via printf()'s.
+ * The script may operate on the following variables:
+ * Mote mote, int id, String msg
+ */
+
+/* Wait until node has booted */
+WAIT_UNTIL(msg.startsWith('Starting'));
+log.log("Mote started\n");
+mymote = mote; /* store mote reference */
+
+/* Wait 3 seconds (3000ms) */
+GENERATE_MSG(3000, "continue");
+YIELD_THEN_WAIT_UNTIL(msg.equals("continue"));
+
+/* Write command to serial port */
+log.log("Writing 'ls' to mote serial port\n");
+write(mymote, "ls");
+
+/* Read replies */
+while (true) {
+ YIELD();
+ if (mote == mymote) {
+ log.log("Mote replied: " + msg + "\n");
+ }
}
\ No newline at end of file
diff --git a/tools/cooja/examples/jni_test/README.md b/tools/cooja/examples/jni_test/README.md
index 145d789ab..99b542c8f 100644
--- a/tools/cooja/examples/jni_test/README.md
+++ b/tools/cooja/examples/jni_test/README.md
@@ -1,20 +1,20 @@
-_The JNI tests have been replaced by the Cooja configuration wizard._
-
-The JNI tests assisted in configuring Cooja for compiling and linking Java
-Native Interface (JNI) enabled Contiki libraries. Such Contiki libraries are
-used by Cooja's Contiki Motes: motes simulated at the operating system
-abstraction level.
-
-The new configuration wizard is started from inside Cooja, and exercises the
-same functionality as the JNI tests. In contrast, the wizard is directly
-connected to the current Cooja configuration, removing the need to migrate the
-configuration between JNI tests and Cooja.
-
-To start the wizard:
-
- cd tools/cooja
- ant run # Start COOJA
-
-Menu > Settings > Compiler configuration wizard
-
--- Fredrik Osterlind, fros@sics.se, March 2009
+_The JNI tests have been replaced by the Cooja configuration wizard._
+
+The JNI tests assisted in configuring Cooja for compiling and linking Java
+Native Interface (JNI) enabled Contiki libraries. Such Contiki libraries are
+used by Cooja's Contiki Motes: motes simulated at the operating system
+abstraction level.
+
+The new configuration wizard is started from inside Cooja, and exercises the
+same functionality as the JNI tests. In contrast, the wizard is directly
+connected to the current Cooja configuration, removing the need to migrate the
+configuration between JNI tests and Cooja.
+
+To start the wizard:
+
+ cd tools/cooja
+ ant run # Start COOJA
+
+Menu > Settings > Compiler configuration wizard
+
+-- Fredrik Osterlind, fros@sics.se, March 2009
diff --git a/tools/cooja/java/org/contikios/cooja/interfaces/DirectionalAntennaRadio.java b/tools/cooja/java/org/contikios/cooja/interfaces/DirectionalAntennaRadio.java
index 59373fc68..207c344f4 100644
--- a/tools/cooja/java/org/contikios/cooja/interfaces/DirectionalAntennaRadio.java
+++ b/tools/cooja/java/org/contikios/cooja/interfaces/DirectionalAntennaRadio.java
@@ -1,65 +1,65 @@
-/*
- * Copyright (c) 2011, Swedish Institute of Computer Science. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer. 2. Redistributions in
- * binary form must reproduce the above copyright notice, this list of
- * conditions and the following disclaimer in the documentation and/or other
- * materials provided with the distribution. 3. Neither the name of the
- * Institute nor the names of its contributors may be used to endorse or promote
- * products derived from this software without specific prior written
- * permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-package org.contikios.cooja.interfaces;
-
-/**
- * Directional antenna.
- *
- * @see MRM
- * @author Fredrik Osterlind
- */
-public interface DirectionalAntennaRadio {
-
- /**
- * @return Current direction (radians). Typically direction 0 has the maximum
- * relative gain.
- *
- * @see #getRelativeGain(double)
- */
- public double getDirection();
-
- /**
- * Relative gain (dB) as compared to an omnidirectional antenna.
- * Note that the given angle is relative to the current direction!
- *
- * @see #getDirection()
- * @param radians Angle relative to current direction
- * @param distance Distance from antenna
- * @return
- */
- public double getRelativeGain(double radians, double distance);
-
- public void addDirectionChangeListener(DirectionChangeListener l);
- public void removeDirectionChangeListener(DirectionChangeListener l);
-
- public interface DirectionChangeListener {
- public void newDirection(DirectionalAntennaRadio radio, double direction);
- }
-
-}
+/*
+ * Copyright (c) 2011, Swedish Institute of Computer Science. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer. 2. Redistributions in
+ * binary form must reproduce the above copyright notice, this list of
+ * conditions and the following disclaimer in the documentation and/or other
+ * materials provided with the distribution. 3. Neither the name of the
+ * Institute nor the names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+package org.contikios.cooja.interfaces;
+
+/**
+ * Directional antenna.
+ *
+ * @see MRM
+ * @author Fredrik Osterlind
+ */
+public interface DirectionalAntennaRadio {
+
+ /**
+ * @return Current direction (radians). Typically direction 0 has the maximum
+ * relative gain.
+ *
+ * @see #getRelativeGain(double)
+ */
+ public double getDirection();
+
+ /**
+ * Relative gain (dB) as compared to an omnidirectional antenna.
+ * Note that the given angle is relative to the current direction!
+ *
+ * @see #getDirection()
+ * @param radians Angle relative to current direction
+ * @param distance Distance from antenna
+ * @return
+ */
+ public double getRelativeGain(double radians, double distance);
+
+ public void addDirectionChangeListener(DirectionChangeListener l);
+ public void removeDirectionChangeListener(DirectionChangeListener l);
+
+ public interface DirectionChangeListener {
+ public void newDirection(DirectionalAntennaRadio radio, double direction);
+ }
+
+}
diff --git a/tools/cooja/java/org/contikios/cooja/interfaces/NoiseSourceRadio.java b/tools/cooja/java/org/contikios/cooja/interfaces/NoiseSourceRadio.java
index 6ceb35b55..45b7760c4 100644
--- a/tools/cooja/java/org/contikios/cooja/interfaces/NoiseSourceRadio.java
+++ b/tools/cooja/java/org/contikios/cooja/interfaces/NoiseSourceRadio.java
@@ -1,56 +1,56 @@
-/*
- * Copyright (c) 2011, Swedish Institute of Computer Science. All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer. 2. Redistributions in
- * binary form must reproduce the above copyright notice, this list of
- * conditions and the following disclaimer in the documentation and/or other
- * materials provided with the distribution. 3. Neither the name of the
- * Institute nor the names of its contributors may be used to endorse or promote
- * products derived from this software without specific prior written
- * permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-package org.contikios.cooja.interfaces;
-
-/**
- * The noise source radio is used to simulate ambient background noise or
- * point-sources of external interference (e.g. Wifi basestations).
- *
- * Note that interference generated from these radios are different from
- * transmissions; they will not appear in the radio logger but may still
- * hinder or interfere with ongoing transmissions.
- *
- * Noise source radios require significant processing resources in comparison
- * to only transmission radios.
- *
- * COOJA's radio mediums may or may not choose to respect noise source radios.
- *
- * @see MRM
- * @author Fredrik Osterlind
- */
-public interface NoiseSourceRadio {
- public int getNoiseLevel();
-
- public void addNoiseLevelListener(NoiseLevelListener l);
- public void removeNoiseLevelListener(NoiseLevelListener l);
-
- public interface NoiseLevelListener {
- public void noiseLevelChanged(NoiseSourceRadio radio, int signal);
- }
-}
+/*
+ * Copyright (c) 2011, Swedish Institute of Computer Science. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer. 2. Redistributions in
+ * binary form must reproduce the above copyright notice, this list of
+ * conditions and the following disclaimer in the documentation and/or other
+ * materials provided with the distribution. 3. Neither the name of the
+ * Institute nor the names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+package org.contikios.cooja.interfaces;
+
+/**
+ * The noise source radio is used to simulate ambient background noise or
+ * point-sources of external interference (e.g. Wifi basestations).
+ *
+ * Note that interference generated from these radios are different from
+ * transmissions; they will not appear in the radio logger but may still
+ * hinder or interfere with ongoing transmissions.
+ *
+ * Noise source radios require significant processing resources in comparison
+ * to only transmission radios.
+ *
+ * COOJA's radio mediums may or may not choose to respect noise source radios.
+ *
+ * @see MRM
+ * @author Fredrik Osterlind
+ */
+public interface NoiseSourceRadio {
+ public int getNoiseLevel();
+
+ public void addNoiseLevelListener(NoiseLevelListener l);
+ public void removeNoiseLevelListener(NoiseLevelListener l);
+
+ public interface NoiseLevelListener {
+ public void noiseLevelChanged(NoiseSourceRadio radio, int signal);
+ }
+}
diff --git a/tools/cooja/java/org/contikios/cooja/util/MoteSerialSocketConnection.java b/tools/cooja/java/org/contikios/cooja/util/MoteSerialSocketConnection.java
index c86c03769..75e796c48 100644
--- a/tools/cooja/java/org/contikios/cooja/util/MoteSerialSocketConnection.java
+++ b/tools/cooja/java/org/contikios/cooja/util/MoteSerialSocketConnection.java
@@ -1,190 +1,190 @@
-/*
- * Copyright (c) 2011, Swedish Institute of Computer Science.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the Institute nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-package org.contikios.cooja.util;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.net.Socket;
-import java.util.ArrayList;
-import java.util.Observable;
-import java.util.Observer;
-
-import org.apache.log4j.Logger;
-
-import org.contikios.cooja.Mote;
-import org.contikios.cooja.interfaces.SerialPort;
-
-/**
- * Help class for forwarding serial data between a mote and a socket.
- *
- * @author Fredrik Osterlind
- */
-public class MoteSerialSocketConnection {
- private static final long serialVersionUID = 1L;
- private static Logger logger = Logger.getLogger(MoteSerialSocketConnection.class);
-
- private boolean isConnected = false;
- public int toMote = 0, toSocket = 0;
-
- private SerialPort motePort;
- private Observer moteObserver;
-
- private Socket socket;
- private DataInputStream socketIn;
- private DataOutputStream socketOut;
-
- private ArrayList listeners = null;
-
- public MoteSerialSocketConnection(Mote mote, String server, int serverPort)
- throws IOException {
- isConnected = true;
-
- /* Simulated -> socket */
- motePort = (SerialPort) mote.getInterfaces().getLog();
- motePort.addSerialDataObserver(moteObserver = new Observer() {
- public void update(Observable obs, Object obj) {
- try {
- if (socketOut == null) {
- return;
- }
- socketOut.write(motePort.getLastSerialData());
- socketOut.flush();
- toSocket++;
-
- if (listeners != null) {
- for (MoteSerialSocketConnectionListener dl: listeners) {
- dl.dataTransferred(MoteSerialSocketConnection.this, toMote, toSocket, motePort.getLastSerialData());
- }
- }
- } catch (IOException e) {
- e.printStackTrace();
- logger.fatal("Write to socket error: " + e.getMessage(), e);
- cleanup();
- }
- }
- });
-
- /* Socket -> simulated */
- socket = new Socket(server, serverPort);
- socketIn = new DataInputStream(socket.getInputStream());
- socketOut = new DataOutputStream(socket.getOutputStream());
- socketOut.flush();
- Thread socketThread = new Thread(new Runnable() {
- public void run() {
- int numRead = 0;
- byte[] data = new byte[1024];
- while (true) {
- numRead = -1;
- try {
- numRead = socketIn.read(data);
- } catch (IOException e) {
- e.printStackTrace();
- return;
- }
-
- if (numRead >= 0) {
- for (int i = 0; i < numRead; i++) {
- toMote ++;
- motePort.writeByte(data[i]);
- if (listeners != null) {
- for (MoteSerialSocketConnectionListener dl: listeners) {
- dl.dataTransferred(MoteSerialSocketConnection.this, toMote, toSocket, data[i]);
- }
- }
- }
-
- } else {
- logger.fatal("Incoming data thread shut down");
- cleanup();
- break;
- }
- }
- }
- });
- socketThread.start();
- }
-
- public boolean isConnected() {
- return isConnected;
- }
-
- public void cleanup() {
- if (!isConnected) {
- return;
- }
- isConnected = false;
-
- motePort.deleteSerialDataObserver(moteObserver);
-
- try {
- if (socket != null) {
- socket.close();
- socket = null;
- }
- } catch (IOException e1) {
- }
- try {
- if (socketIn != null) {
- socketIn.close();
- socketIn = null;
- }
- } catch (IOException e) {
- }
- try {
- if (socketOut != null) {
- socketOut.close();
- socketOut = null;
- }
- } catch (IOException e) {
- }
-
- if (listeners != null) {
- for (MoteSerialSocketConnectionListener dl: listeners) {
- dl.wasDisconnected(MoteSerialSocketConnection.this);
- }
- listeners = null;
- }
- }
-
- public void addListener(MoteSerialSocketConnectionListener l) {
- if (listeners == null) {
- listeners = new ArrayList();
- }
-
- listeners.add(l);
- }
-
- public interface MoteSerialSocketConnectionListener {
- public void wasDisconnected(MoteSerialSocketConnection s);
- public void dataTransferred(MoteSerialSocketConnection s, int toMote, int toSocket, byte data);
- }
-
+/*
+ * Copyright (c) 2011, Swedish Institute of Computer Science.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the Institute nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+package org.contikios.cooja.util;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.net.Socket;
+import java.util.ArrayList;
+import java.util.Observable;
+import java.util.Observer;
+
+import org.apache.log4j.Logger;
+
+import org.contikios.cooja.Mote;
+import org.contikios.cooja.interfaces.SerialPort;
+
+/**
+ * Help class for forwarding serial data between a mote and a socket.
+ *
+ * @author Fredrik Osterlind
+ */
+public class MoteSerialSocketConnection {
+ private static final long serialVersionUID = 1L;
+ private static Logger logger = Logger.getLogger(MoteSerialSocketConnection.class);
+
+ private boolean isConnected = false;
+ public int toMote = 0, toSocket = 0;
+
+ private SerialPort motePort;
+ private Observer moteObserver;
+
+ private Socket socket;
+ private DataInputStream socketIn;
+ private DataOutputStream socketOut;
+
+ private ArrayList listeners = null;
+
+ public MoteSerialSocketConnection(Mote mote, String server, int serverPort)
+ throws IOException {
+ isConnected = true;
+
+ /* Simulated -> socket */
+ motePort = (SerialPort) mote.getInterfaces().getLog();
+ motePort.addSerialDataObserver(moteObserver = new Observer() {
+ public void update(Observable obs, Object obj) {
+ try {
+ if (socketOut == null) {
+ return;
+ }
+ socketOut.write(motePort.getLastSerialData());
+ socketOut.flush();
+ toSocket++;
+
+ if (listeners != null) {
+ for (MoteSerialSocketConnectionListener dl: listeners) {
+ dl.dataTransferred(MoteSerialSocketConnection.this, toMote, toSocket, motePort.getLastSerialData());
+ }
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ logger.fatal("Write to socket error: " + e.getMessage(), e);
+ cleanup();
+ }
+ }
+ });
+
+ /* Socket -> simulated */
+ socket = new Socket(server, serverPort);
+ socketIn = new DataInputStream(socket.getInputStream());
+ socketOut = new DataOutputStream(socket.getOutputStream());
+ socketOut.flush();
+ Thread socketThread = new Thread(new Runnable() {
+ public void run() {
+ int numRead = 0;
+ byte[] data = new byte[1024];
+ while (true) {
+ numRead = -1;
+ try {
+ numRead = socketIn.read(data);
+ } catch (IOException e) {
+ e.printStackTrace();
+ return;
+ }
+
+ if (numRead >= 0) {
+ for (int i = 0; i < numRead; i++) {
+ toMote ++;
+ motePort.writeByte(data[i]);
+ if (listeners != null) {
+ for (MoteSerialSocketConnectionListener dl: listeners) {
+ dl.dataTransferred(MoteSerialSocketConnection.this, toMote, toSocket, data[i]);
+ }
+ }
+ }
+
+ } else {
+ logger.fatal("Incoming data thread shut down");
+ cleanup();
+ break;
+ }
+ }
+ }
+ });
+ socketThread.start();
+ }
+
+ public boolean isConnected() {
+ return isConnected;
+ }
+
+ public void cleanup() {
+ if (!isConnected) {
+ return;
+ }
+ isConnected = false;
+
+ motePort.deleteSerialDataObserver(moteObserver);
+
+ try {
+ if (socket != null) {
+ socket.close();
+ socket = null;
+ }
+ } catch (IOException e1) {
+ }
+ try {
+ if (socketIn != null) {
+ socketIn.close();
+ socketIn = null;
+ }
+ } catch (IOException e) {
+ }
+ try {
+ if (socketOut != null) {
+ socketOut.close();
+ socketOut = null;
+ }
+ } catch (IOException e) {
+ }
+
+ if (listeners != null) {
+ for (MoteSerialSocketConnectionListener dl: listeners) {
+ dl.wasDisconnected(MoteSerialSocketConnection.this);
+ }
+ listeners = null;
+ }
+ }
+
+ public void addListener(MoteSerialSocketConnectionListener l) {
+ if (listeners == null) {
+ listeners = new ArrayList();
+ }
+
+ listeners.add(l);
+ }
+
+ public interface MoteSerialSocketConnectionListener {
+ public void wasDisconnected(MoteSerialSocketConnection s);
+ public void dataTransferred(MoteSerialSocketConnection s, int toMote, int toSocket, byte data);
+ }
+
}
\ No newline at end of file
diff --git a/tools/cooja/lib/JSYNTAXPANE_LICENSE b/tools/cooja/lib/JSYNTAXPANE_LICENSE
index 01f0c7c35..a3ac59567 100644
--- a/tools/cooja/lib/JSYNTAXPANE_LICENSE
+++ b/tools/cooja/lib/JSYNTAXPANE_LICENSE
@@ -1,4 +1,4 @@
-Downloaded from http://code.google.com/p/jsyntaxpane/.
-
-Apache License 2.0:
-http://www.apache.org/licenses/LICENSE-2.0
+Downloaded from http://code.google.com/p/jsyntaxpane/.
+
+Apache License 2.0:
+http://www.apache.org/licenses/LICENSE-2.0
diff --git a/tools/sensinode/nano_programmer/README.md b/tools/sensinode/nano_programmer/README.md
index a9ce6d81e..f85a6a2aa 100755
--- a/tools/sensinode/nano_programmer/README.md
+++ b/tools/sensinode/nano_programmer/README.md
@@ -1,38 +1,38 @@
-# Nano Programmer
-
-Programming tool for the Sensinode Nano series using Dxxx development boards.
-
-Copyright 2007-2008 Sensinode Ltd.
-
-## Installation
-
-### Linux
-
-No external libraries required.
-
-### Windows/Cygwin
-
-See the nano_usb_programmer README file on how to install FTDI library
-for nano_usb_programmer. The nano_programmer build system will fetch
-the library from there.
-
-## Usage
-
-Usage info for the Nano Programmer is available with command
-
- ./nano_programmer --help
-
-Note that use might require root/administrator privileges
- depending on system configuration.
-
-## Known problems
-
-Occasional timing failures resulting in "Reinit failed."-messages do come
-up in some PC configurations. If you experience programming failures (the programmer
-is not able to recover), please report your system configuration to Sensinode.
-On Linux, it is known that the "brltty" program causes problems with the FTDI
-serial driver. Uninstalling brltty resolves the problem.
-
-## Version
-
-v1.3 2008-01-31 Martti Huttunen Multi-platform build and created instructions
+# Nano Programmer
+
+Programming tool for the Sensinode Nano series using Dxxx development boards.
+
+Copyright 2007-2008 Sensinode Ltd.
+
+## Installation
+
+### Linux
+
+No external libraries required.
+
+### Windows/Cygwin
+
+See the nano_usb_programmer README file on how to install FTDI library
+for nano_usb_programmer. The nano_programmer build system will fetch
+the library from there.
+
+## Usage
+
+Usage info for the Nano Programmer is available with command
+
+ ./nano_programmer --help
+
+Note that use might require root/administrator privileges
+ depending on system configuration.
+
+## Known problems
+
+Occasional timing failures resulting in "Reinit failed."-messages do come
+up in some PC configurations. If you experience programming failures (the programmer
+is not able to recover), please report your system configuration to Sensinode.
+On Linux, it is known that the "brltty" program causes problems with the FTDI
+serial driver. Uninstalling brltty resolves the problem.
+
+## Version
+
+v1.3 2008-01-31 Martti Huttunen Multi-platform build and created instructions
diff --git a/tools/sensinode/nano_usb_programmer/ftdi_win32/ftd2xx.h b/tools/sensinode/nano_usb_programmer/ftdi_win32/ftd2xx.h
index fd15376f8..3ee1da36d 100644
--- a/tools/sensinode/nano_usb_programmer/ftdi_win32/ftd2xx.h
+++ b/tools/sensinode/nano_usb_programmer/ftdi_win32/ftd2xx.h
@@ -27,897 +27,896 @@
*/
-/*++
-
-Copyright (c) 2001-2006 Future Technology Devices International Ltd.
-
-Module Name:
-
- ftd2xx.h
-
-Abstract:
-
- Native USB device driver for FTDI FT8U232/245
- FTD2XX library definitions
-
-Environment:
-
- kernel & user mode
-
-Revision History:
-
- 13/03/01 awm Created.
- 13/01/03 awm Added device information support.
- 19/03/03 awm Added FT_W32_CancelIo.
- 12/06/03 awm Added FT_StopInTask and FT_RestartInTask.
- 18/09/03 awm Added FT_SetResetPipeRetryCount.
- 10/10/03 awm Added FT_ResetPort.
- 23/01/04 awm Added support for open-by-location.
- 16/03/04 awm Added support for FT2232C.
- 23/09/04 awm Added support for FT232R.
- 20/10/04 awm Added FT_CyclePort.
- 18/01/05 awm Added FT_DEVICE_LIST_INFO_NODE type.
- 11/02/05 awm Added LocId to FT_DEVICE_LIST_INFO_NODE.
- 25/08/05 awm Added FT_SetDeadmanTimeout.
- 02/12/05 awm Removed obsolete references.
- 05/12/05 awm Added FT_GetVersion, FT_GetVersionEx.
- 08/09/06 awm Added FT_W32_GetCommMask.
- 11/09/06 awm Added FT_Rescan.
-
-
---*/
-
-
-#ifndef FTD2XX_H
-#define FTD2XX_H
-
-// The following ifdef block is the standard way of creating macros
-// which make exporting from a DLL simpler. All files within this DLL
-// are compiled with the FTD2XX_EXPORTS symbol defined on the command line.
-// This symbol should not be defined on any project that uses this DLL.
-// This way any other project whose source files include this file see
-// FTD2XX_API functions as being imported from a DLL, whereas this DLL
-// sees symbols defined with this macro as being exported.
-
-#ifdef FTD2XX_EXPORTS
-#define FTD2XX_API __declspec(dllexport)
-#else
-#define FTD2XX_API __declspec(dllimport)
-#endif
-
-
-typedef PVOID FT_HANDLE;
-typedef ULONG FT_STATUS;
-
-//
-// Device status
-//
-enum {
- FT_OK,
- FT_INVALID_HANDLE,
- FT_DEVICE_NOT_FOUND,
- FT_DEVICE_NOT_OPENED,
- FT_IO_ERROR,
- FT_INSUFFICIENT_RESOURCES,
- FT_INVALID_PARAMETER,
- FT_INVALID_BAUD_RATE,
-
- FT_DEVICE_NOT_OPENED_FOR_ERASE,
- FT_DEVICE_NOT_OPENED_FOR_WRITE,
- FT_FAILED_TO_WRITE_DEVICE,
- FT_EEPROM_READ_FAILED,
- FT_EEPROM_WRITE_FAILED,
- FT_EEPROM_ERASE_FAILED,
- FT_EEPROM_NOT_PRESENT,
- FT_EEPROM_NOT_PROGRAMMED,
- FT_INVALID_ARGS,
- FT_NOT_SUPPORTED,
- FT_OTHER_ERROR,
- FT_DEVICE_LIST_NOT_READY,
-};
-
-
-#define FT_SUCCESS(status) ((status) == FT_OK)
-
-//
-// FT_OpenEx Flags
-//
-
-#define FT_OPEN_BY_SERIAL_NUMBER 1
-#define FT_OPEN_BY_DESCRIPTION 2
-#define FT_OPEN_BY_LOCATION 4
-
-//
-// FT_ListDevices Flags (used in conjunction with FT_OpenEx Flags
-//
-
-#define FT_LIST_NUMBER_ONLY 0x80000000
-#define FT_LIST_BY_INDEX 0x40000000
-#define FT_LIST_ALL 0x20000000
-
-#define FT_LIST_MASK (FT_LIST_NUMBER_ONLY|FT_LIST_BY_INDEX|FT_LIST_ALL)
-
-//
-// Baud Rates
-//
-
-#define FT_BAUD_300 300
-#define FT_BAUD_600 600
-#define FT_BAUD_1200 1200
-#define FT_BAUD_2400 2400
-#define FT_BAUD_4800 4800
-#define FT_BAUD_9600 9600
-#define FT_BAUD_14400 14400
-#define FT_BAUD_19200 19200
-#define FT_BAUD_38400 38400
-#define FT_BAUD_57600 57600
-#define FT_BAUD_115200 115200
-#define FT_BAUD_230400 230400
-#define FT_BAUD_460800 460800
-#define FT_BAUD_921600 921600
-
-//
-// Word Lengths
-//
-
-#define FT_BITS_8 (UCHAR) 8
-#define FT_BITS_7 (UCHAR) 7
-#define FT_BITS_6 (UCHAR) 6
-#define FT_BITS_5 (UCHAR) 5
-
-//
-// Stop Bits
-//
-
-#define FT_STOP_BITS_1 (UCHAR) 0
-#define FT_STOP_BITS_1_5 (UCHAR) 1
-#define FT_STOP_BITS_2 (UCHAR) 2
-
-//
-// Parity
-//
-
-#define FT_PARITY_NONE (UCHAR) 0
-#define FT_PARITY_ODD (UCHAR) 1
-#define FT_PARITY_EVEN (UCHAR) 2
-#define FT_PARITY_MARK (UCHAR) 3
-#define FT_PARITY_SPACE (UCHAR) 4
-
-//
-// Flow Control
-//
-
-#define FT_FLOW_NONE 0x0000
-#define FT_FLOW_RTS_CTS 0x0100
-#define FT_FLOW_DTR_DSR 0x0200
-#define FT_FLOW_XON_XOFF 0x0400
-
-//
-// Purge rx and tx buffers
-//
-#define FT_PURGE_RX 1
-#define FT_PURGE_TX 2
-
-//
-// Events
-//
-
-typedef void (*PFT_EVENT_HANDLER)(DWORD,DWORD);
-
-#define FT_EVENT_RXCHAR 1
-#define FT_EVENT_MODEM_STATUS 2
-
-//
-// Timeouts
-//
-
-#define FT_DEFAULT_RX_TIMEOUT 300
-#define FT_DEFAULT_TX_TIMEOUT 300
-
-//
-// Device types
-//
-
-typedef ULONG FT_DEVICE;
-
-enum {
- FT_DEVICE_BM,
- FT_DEVICE_AM,
- FT_DEVICE_100AX,
- FT_DEVICE_UNKNOWN,
- FT_DEVICE_2232C,
- FT_DEVICE_232R
-};
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-FTD2XX_API
-FT_STATUS WINAPI FT_Open(
- int deviceNumber,
- FT_HANDLE *pHandle
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_OpenEx(
- PVOID pArg1,
- DWORD Flags,
- FT_HANDLE *pHandle
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_ListDevices(
- PVOID pArg1,
- PVOID pArg2,
- DWORD Flags
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_Close(
- FT_HANDLE ftHandle
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_Read(
- FT_HANDLE ftHandle,
- LPVOID lpBuffer,
- DWORD nBufferSize,
- LPDWORD lpBytesReturned
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_Write(
- FT_HANDLE ftHandle,
- LPVOID lpBuffer,
- DWORD nBufferSize,
- LPDWORD lpBytesWritten
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_IoCtl(
- FT_HANDLE ftHandle,
- DWORD dwIoControlCode,
- LPVOID lpInBuf,
- DWORD nInBufSize,
- LPVOID lpOutBuf,
- DWORD nOutBufSize,
- LPDWORD lpBytesReturned,
- LPOVERLAPPED lpOverlapped
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_SetBaudRate(
- FT_HANDLE ftHandle,
- ULONG BaudRate
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_SetDivisor(
- FT_HANDLE ftHandle,
- USHORT Divisor
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_SetDataCharacteristics(
- FT_HANDLE ftHandle,
- UCHAR WordLength,
- UCHAR StopBits,
- UCHAR Parity
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_SetFlowControl(
- FT_HANDLE ftHandle,
- USHORT FlowControl,
- UCHAR XonChar,
- UCHAR XoffChar
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_ResetDevice(
- FT_HANDLE ftHandle
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_SetDtr(
- FT_HANDLE ftHandle
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_ClrDtr(
- FT_HANDLE ftHandle
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_SetRts(
- FT_HANDLE ftHandle
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_ClrRts(
- FT_HANDLE ftHandle
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_GetModemStatus(
- FT_HANDLE ftHandle,
- ULONG *pModemStatus
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_SetChars(
- FT_HANDLE ftHandle,
- UCHAR EventChar,
- UCHAR EventCharEnabled,
- UCHAR ErrorChar,
- UCHAR ErrorCharEnabled
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_Purge(
- FT_HANDLE ftHandle,
- ULONG Mask
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_SetTimeouts(
- FT_HANDLE ftHandle,
- ULONG ReadTimeout,
- ULONG WriteTimeout
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_GetQueueStatus(
- FT_HANDLE ftHandle,
- DWORD *dwRxBytes
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_SetEventNotification(
- FT_HANDLE ftHandle,
- DWORD Mask,
- PVOID Param
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_GetStatus(
- FT_HANDLE ftHandle,
- DWORD *dwRxBytes,
- DWORD *dwTxBytes,
- DWORD *dwEventDWord
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_SetBreakOn(
- FT_HANDLE ftHandle
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_SetBreakOff(
- FT_HANDLE ftHandle
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_SetWaitMask(
- FT_HANDLE ftHandle,
- DWORD Mask
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_WaitOnMask(
- FT_HANDLE ftHandle,
- DWORD *Mask
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_GetEventStatus(
- FT_HANDLE ftHandle,
- DWORD *dwEventDWord
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_ReadEE(
- FT_HANDLE ftHandle,
- DWORD dwWordOffset,
- LPWORD lpwValue
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_WriteEE(
- FT_HANDLE ftHandle,
- DWORD dwWordOffset,
- WORD wValue
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_EraseEE(
- FT_HANDLE ftHandle
- );
-
-//
-// structure to hold program data for FT_Program function
-//
-typedef struct ft_program_data {
-
- DWORD Signature1; // Header - must be 0x00000000
- DWORD Signature2; // Header - must be 0xffffffff
- DWORD Version; // Header - FT_PROGRAM_DATA version
- // 0 = original
- // 1 = FT2232C extensions
- // 2 = FT232R extensions
-
- WORD VendorId; // 0x0403
- WORD ProductId; // 0x6001
- char *Manufacturer; // "FTDI"
- char *ManufacturerId; // "FT"
- char *Description; // "USB HS Serial Converter"
- char *SerialNumber; // "FT000001" if fixed, or NULL
- WORD MaxPower; // 0 < MaxPower <= 500
- WORD PnP; // 0 = disabled, 1 = enabled
- WORD SelfPowered; // 0 = bus powered, 1 = self powered
- WORD RemoteWakeup; // 0 = not capable, 1 = capable
- //
- // Rev4 extensions
- //
- UCHAR Rev4; // non-zero if Rev4 chip, zero otherwise
- UCHAR IsoIn; // non-zero if in endpoint is isochronous
- UCHAR IsoOut; // non-zero if out endpoint is isochronous
- UCHAR PullDownEnable; // non-zero if pull down enabled
- UCHAR SerNumEnable; // non-zero if serial number to be used
- UCHAR USBVersionEnable; // non-zero if chip uses USBVersion
- WORD USBVersion; // BCD (0x0200 => USB2)
- //
- // FT2232C extensions
- //
- UCHAR Rev5; // non-zero if Rev5 chip, zero otherwise
- UCHAR IsoInA; // non-zero if in endpoint is isochronous
- UCHAR IsoInB; // non-zero if in endpoint is isochronous
- UCHAR IsoOutA; // non-zero if out endpoint is isochronous
- UCHAR IsoOutB; // non-zero if out endpoint is isochronous
- UCHAR PullDownEnable5; // non-zero if pull down enabled
- UCHAR SerNumEnable5; // non-zero if serial number to be used
- UCHAR USBVersionEnable5; // non-zero if chip uses USBVersion
- WORD USBVersion5; // BCD (0x0200 => USB2)
- UCHAR AIsHighCurrent; // non-zero if interface is high current
- UCHAR BIsHighCurrent; // non-zero if interface is high current
- UCHAR IFAIsFifo; // non-zero if interface is 245 FIFO
- UCHAR IFAIsFifoTar; // non-zero if interface is 245 FIFO CPU target
- UCHAR IFAIsFastSer; // non-zero if interface is Fast serial
- UCHAR AIsVCP; // non-zero if interface is to use VCP drivers
- UCHAR IFBIsFifo; // non-zero if interface is 245 FIFO
- UCHAR IFBIsFifoTar; // non-zero if interface is 245 FIFO CPU target
- UCHAR IFBIsFastSer; // non-zero if interface is Fast serial
- UCHAR BIsVCP; // non-zero if interface is to use VCP drivers
- //
- // FT232R extensions
- //
- UCHAR UseExtOsc; // Use External Oscillator
- UCHAR HighDriveIOs; // High Drive I/Os
- UCHAR EndpointSize; // Endpoint size
-
- UCHAR PullDownEnableR; // non-zero if pull down enabled
- UCHAR SerNumEnableR; // non-zero if serial number to be used
-
- UCHAR InvertTXD; // non-zero if invert TXD
- UCHAR InvertRXD; // non-zero if invert RXD
- UCHAR InvertRTS; // non-zero if invert RTS
- UCHAR InvertCTS; // non-zero if invert CTS
- UCHAR InvertDTR; // non-zero if invert DTR
- UCHAR InvertDSR; // non-zero if invert DSR
- UCHAR InvertDCD; // non-zero if invert DCD
- UCHAR InvertRI; // non-zero if invert RI
-
- UCHAR Cbus0; // Cbus Mux control
- UCHAR Cbus1; // Cbus Mux control
- UCHAR Cbus2; // Cbus Mux control
- UCHAR Cbus3; // Cbus Mux control
- UCHAR Cbus4; // Cbus Mux control
-
- UCHAR RIsD2XX; // non-zero if using D2XX driver
-
-} FT_PROGRAM_DATA, *PFT_PROGRAM_DATA;
-
-FTD2XX_API
-FT_STATUS WINAPI FT_EE_Program(
- FT_HANDLE ftHandle,
- PFT_PROGRAM_DATA pData
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_EE_ProgramEx(
- FT_HANDLE ftHandle,
- PFT_PROGRAM_DATA pData,
- char *Manufacturer,
- char *ManufacturerId,
- char *Description,
- char *SerialNumber
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_EE_Read(
- FT_HANDLE ftHandle,
- PFT_PROGRAM_DATA pData
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_EE_ReadEx(
- FT_HANDLE ftHandle,
- PFT_PROGRAM_DATA pData,
- char *Manufacturer,
- char *ManufacturerId,
- char *Description,
- char *SerialNumber
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_EE_UASize(
- FT_HANDLE ftHandle,
- LPDWORD lpdwSize
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_EE_UAWrite(
- FT_HANDLE ftHandle,
- PUCHAR pucData,
- DWORD dwDataLen
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_EE_UARead(
- FT_HANDLE ftHandle,
- PUCHAR pucData,
- DWORD dwDataLen,
- LPDWORD lpdwBytesRead
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_SetLatencyTimer(
- FT_HANDLE ftHandle,
- UCHAR ucLatency
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_GetLatencyTimer(
- FT_HANDLE ftHandle,
- PUCHAR pucLatency
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_SetBitMode(
- FT_HANDLE ftHandle,
- UCHAR ucMask,
- UCHAR ucEnable
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_GetBitMode(
- FT_HANDLE ftHandle,
- PUCHAR pucMode
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_SetUSBParameters(
- FT_HANDLE ftHandle,
- ULONG ulInTransferSize,
- ULONG ulOutTransferSize
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_SetDeadmanTimeout(
- FT_HANDLE ftHandle,
- ULONG ulDeadmanTimeout
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_GetDeviceInfo(
- FT_HANDLE ftHandle,
- FT_DEVICE *lpftDevice,
- LPDWORD lpdwID,
- PCHAR SerialNumber,
- PCHAR Description,
- LPVOID Dummy
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_StopInTask(
- FT_HANDLE ftHandle
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_RestartInTask(
- FT_HANDLE ftHandle
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_SetResetPipeRetryCount(
- FT_HANDLE ftHandle,
- DWORD dwCount
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_ResetPort(
- FT_HANDLE ftHandle
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_CyclePort(
- FT_HANDLE ftHandle
- );
-
-
-//
-// Win32-type functions
-//
-
-FTD2XX_API
-FT_HANDLE WINAPI FT_W32_CreateFile(
- LPCTSTR lpszName,
- DWORD dwAccess,
- DWORD dwShareMode,
- LPSECURITY_ATTRIBUTES lpSecurityAttributes,
- DWORD dwCreate,
- DWORD dwAttrsAndFlags,
- HANDLE hTemplate
- );
-
-FTD2XX_API
-BOOL WINAPI FT_W32_CloseHandle(
- FT_HANDLE ftHandle
- );
-
-FTD2XX_API
-BOOL WINAPI FT_W32_ReadFile(
- FT_HANDLE ftHandle,
- LPVOID lpBuffer,
- DWORD nBufferSize,
- LPDWORD lpBytesReturned,
- LPOVERLAPPED lpOverlapped
- );
-
-FTD2XX_API
-BOOL WINAPI FT_W32_WriteFile(
- FT_HANDLE ftHandle,
- LPVOID lpBuffer,
- DWORD nBufferSize,
- LPDWORD lpBytesWritten,
- LPOVERLAPPED lpOverlapped
- );
-
-FTD2XX_API
-DWORD WINAPI FT_W32_GetLastError(
- FT_HANDLE ftHandle
- );
-
-FTD2XX_API
-BOOL WINAPI FT_W32_GetOverlappedResult(
- FT_HANDLE ftHandle,
- LPOVERLAPPED lpOverlapped,
- LPDWORD lpdwBytesTransferred,
- BOOL bWait
- );
-
-FTD2XX_API
-BOOL WINAPI FT_W32_CancelIo(
- FT_HANDLE ftHandle
- );
-
-
-//
-// Win32 COMM API type functions
-//
-typedef struct _FTCOMSTAT {
- DWORD fCtsHold : 1;
- DWORD fDsrHold : 1;
- DWORD fRlsdHold : 1;
- DWORD fXoffHold : 1;
- DWORD fXoffSent : 1;
- DWORD fEof : 1;
- DWORD fTxim : 1;
- DWORD fReserved : 25;
- DWORD cbInQue;
- DWORD cbOutQue;
-} FTCOMSTAT, *LPFTCOMSTAT;
-
-typedef struct _FTDCB {
- DWORD DCBlength; /* sizeof(FTDCB) */
- DWORD BaudRate; /* Baudrate at which running */
- DWORD fBinary: 1; /* Binary Mode (skip EOF check) */
- DWORD fParity: 1; /* Enable parity checking */
- DWORD fOutxCtsFlow:1; /* CTS handshaking on output */
- DWORD fOutxDsrFlow:1; /* DSR handshaking on output */
- DWORD fDtrControl:2; /* DTR Flow control */
- DWORD fDsrSensitivity:1; /* DSR Sensitivity */
- DWORD fTXContinueOnXoff: 1; /* Continue TX when Xoff sent */
- DWORD fOutX: 1; /* Enable output X-ON/X-OFF */
- DWORD fInX: 1; /* Enable input X-ON/X-OFF */
- DWORD fErrorChar: 1; /* Enable Err Replacement */
- DWORD fNull: 1; /* Enable Null stripping */
- DWORD fRtsControl:2; /* Rts Flow control */
- DWORD fAbortOnError:1; /* Abort all reads and writes on Error */
- DWORD fDummy2:17; /* Reserved */
- WORD wReserved; /* Not currently used */
- WORD XonLim; /* Transmit X-ON threshold */
- WORD XoffLim; /* Transmit X-OFF threshold */
- BYTE ByteSize; /* Number of bits/byte, 4-8 */
- BYTE Parity; /* 0-4=None,Odd,Even,Mark,Space */
- BYTE StopBits; /* 0,1,2 = 1, 1.5, 2 */
- char XonChar; /* Tx and Rx X-ON character */
- char XoffChar; /* Tx and Rx X-OFF character */
- char ErrorChar; /* Error replacement char */
- char EofChar; /* End of Input character */
- char EvtChar; /* Received Event character */
- WORD wReserved1; /* Fill for now. */
-} FTDCB, *LPFTDCB;
-
-typedef struct _FTTIMEOUTS {
- DWORD ReadIntervalTimeout; /* Maximum time between read chars. */
- DWORD ReadTotalTimeoutMultiplier; /* Multiplier of characters. */
- DWORD ReadTotalTimeoutConstant; /* Constant in milliseconds. */
- DWORD WriteTotalTimeoutMultiplier; /* Multiplier of characters. */
- DWORD WriteTotalTimeoutConstant; /* Constant in milliseconds. */
-} FTTIMEOUTS,*LPFTTIMEOUTS;
-
-
-FTD2XX_API
-BOOL WINAPI FT_W32_ClearCommBreak(
- FT_HANDLE ftHandle
- );
-
-FTD2XX_API
-BOOL WINAPI FT_W32_ClearCommError(
- FT_HANDLE ftHandle,
- LPDWORD lpdwErrors,
- LPFTCOMSTAT lpftComstat
- );
-
-FTD2XX_API
-BOOL WINAPI FT_W32_EscapeCommFunction(
- FT_HANDLE ftHandle,
- DWORD dwFunc
- );
-
-FTD2XX_API
-BOOL WINAPI FT_W32_GetCommModemStatus(
- FT_HANDLE ftHandle,
- LPDWORD lpdwModemStatus
- );
-
-FTD2XX_API
-BOOL WINAPI FT_W32_GetCommState(
- FT_HANDLE ftHandle,
- LPFTDCB lpftDcb
- );
-
-FTD2XX_API
-BOOL WINAPI FT_W32_GetCommTimeouts(
- FT_HANDLE ftHandle,
- FTTIMEOUTS *pTimeouts
- );
-
-FTD2XX_API
-BOOL WINAPI FT_W32_PurgeComm(
- FT_HANDLE ftHandle,
- DWORD dwMask
- );
-
-FTD2XX_API
-BOOL WINAPI FT_W32_SetCommBreak(
- FT_HANDLE ftHandle
- );
-
-FTD2XX_API
-BOOL WINAPI FT_W32_SetCommMask(
- FT_HANDLE ftHandle,
- ULONG ulEventMask
- );
-
-FTD2XX_API
-BOOL WINAPI FT_W32_GetCommMask(
- FT_HANDLE ftHandle,
- LPDWORD lpdwEventMask
- );
-
-FTD2XX_API
-BOOL WINAPI FT_W32_SetCommState(
- FT_HANDLE ftHandle,
- LPFTDCB lpftDcb
- );
-
-FTD2XX_API
-BOOL WINAPI FT_W32_SetCommTimeouts(
- FT_HANDLE ftHandle,
- FTTIMEOUTS *pTimeouts
- );
-
-FTD2XX_API
-BOOL WINAPI FT_W32_SetupComm(
- FT_HANDLE ftHandle,
- DWORD dwReadBufferSize,
- DWORD dwWriteBufferSize
- );
-
-FTD2XX_API
-BOOL WINAPI FT_W32_WaitCommEvent(
- FT_HANDLE ftHandle,
- PULONG pulEvent,
- LPOVERLAPPED lpOverlapped
- );
-
-
-//
-// Device information
-//
-
-typedef struct _ft_device_list_info_node {
- ULONG Flags;
- ULONG Type;
- ULONG ID;
- DWORD LocId;
- char SerialNumber[16];
- char Description[64];
- FT_HANDLE ftHandle;
-} FT_DEVICE_LIST_INFO_NODE;
-
-
-FTD2XX_API
-FT_STATUS WINAPI FT_CreateDeviceInfoList(
- LPDWORD lpdwNumDevs
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_GetDeviceInfoList(
- FT_DEVICE_LIST_INFO_NODE *pDest,
- LPDWORD lpdwNumDevs
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_GetDeviceInfoDetail(
- DWORD dwIndex,
- LPDWORD lpdwFlags,
- LPDWORD lpdwType,
- LPDWORD lpdwID,
- LPDWORD lpdwLocId,
- LPVOID lpSerialNumber,
- LPVOID lpDescription,
- FT_HANDLE *pftHandle
- );
-
-
-//
-// Version information
-//
-
-FTD2XX_API
-FT_STATUS WINAPI FT_GetDriverVersion(
- FT_HANDLE ftHandle,
- LPDWORD lpdwVersion
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_GetLibraryVersion(
- LPDWORD lpdwVersion
- );
-
-
-FTD2XX_API
-FT_STATUS WINAPI FT_Rescan(
- void
- );
-
-FTD2XX_API
-FT_STATUS WINAPI FT_Reload(
- WORD wVid,
- WORD wPid
- );
-
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif /* FTD2XX_H */
-
+/*++
+
+Copyright (c) 2001-2006 Future Technology Devices International Ltd.
+
+Module Name:
+
+ ftd2xx.h
+
+Abstract:
+
+ Native USB device driver for FTDI FT8U232/245
+ FTD2XX library definitions
+
+Environment:
+
+ kernel & user mode
+
+Revision History:
+
+ 13/03/01 awm Created.
+ 13/01/03 awm Added device information support.
+ 19/03/03 awm Added FT_W32_CancelIo.
+ 12/06/03 awm Added FT_StopInTask and FT_RestartInTask.
+ 18/09/03 awm Added FT_SetResetPipeRetryCount.
+ 10/10/03 awm Added FT_ResetPort.
+ 23/01/04 awm Added support for open-by-location.
+ 16/03/04 awm Added support for FT2232C.
+ 23/09/04 awm Added support for FT232R.
+ 20/10/04 awm Added FT_CyclePort.
+ 18/01/05 awm Added FT_DEVICE_LIST_INFO_NODE type.
+ 11/02/05 awm Added LocId to FT_DEVICE_LIST_INFO_NODE.
+ 25/08/05 awm Added FT_SetDeadmanTimeout.
+ 02/12/05 awm Removed obsolete references.
+ 05/12/05 awm Added FT_GetVersion, FT_GetVersionEx.
+ 08/09/06 awm Added FT_W32_GetCommMask.
+ 11/09/06 awm Added FT_Rescan.
+
+
+--*/
+
+
+#ifndef FTD2XX_H
+#define FTD2XX_H
+
+// The following ifdef block is the standard way of creating macros
+// which make exporting from a DLL simpler. All files within this DLL
+// are compiled with the FTD2XX_EXPORTS symbol defined on the command line.
+// This symbol should not be defined on any project that uses this DLL.
+// This way any other project whose source files include this file see
+// FTD2XX_API functions as being imported from a DLL, whereas this DLL
+// sees symbols defined with this macro as being exported.
+
+#ifdef FTD2XX_EXPORTS
+#define FTD2XX_API __declspec(dllexport)
+#else
+#define FTD2XX_API __declspec(dllimport)
+#endif
+
+
+typedef PVOID FT_HANDLE;
+typedef ULONG FT_STATUS;
+
+//
+// Device status
+//
+enum {
+ FT_OK,
+ FT_INVALID_HANDLE,
+ FT_DEVICE_NOT_FOUND,
+ FT_DEVICE_NOT_OPENED,
+ FT_IO_ERROR,
+ FT_INSUFFICIENT_RESOURCES,
+ FT_INVALID_PARAMETER,
+ FT_INVALID_BAUD_RATE,
+
+ FT_DEVICE_NOT_OPENED_FOR_ERASE,
+ FT_DEVICE_NOT_OPENED_FOR_WRITE,
+ FT_FAILED_TO_WRITE_DEVICE,
+ FT_EEPROM_READ_FAILED,
+ FT_EEPROM_WRITE_FAILED,
+ FT_EEPROM_ERASE_FAILED,
+ FT_EEPROM_NOT_PRESENT,
+ FT_EEPROM_NOT_PROGRAMMED,
+ FT_INVALID_ARGS,
+ FT_NOT_SUPPORTED,
+ FT_OTHER_ERROR,
+ FT_DEVICE_LIST_NOT_READY,
+};
+
+
+#define FT_SUCCESS(status) ((status) == FT_OK)
+
+//
+// FT_OpenEx Flags
+//
+
+#define FT_OPEN_BY_SERIAL_NUMBER 1
+#define FT_OPEN_BY_DESCRIPTION 2
+#define FT_OPEN_BY_LOCATION 4
+
+//
+// FT_ListDevices Flags (used in conjunction with FT_OpenEx Flags
+//
+
+#define FT_LIST_NUMBER_ONLY 0x80000000
+#define FT_LIST_BY_INDEX 0x40000000
+#define FT_LIST_ALL 0x20000000
+
+#define FT_LIST_MASK (FT_LIST_NUMBER_ONLY|FT_LIST_BY_INDEX|FT_LIST_ALL)
+
+//
+// Baud Rates
+//
+
+#define FT_BAUD_300 300
+#define FT_BAUD_600 600
+#define FT_BAUD_1200 1200
+#define FT_BAUD_2400 2400
+#define FT_BAUD_4800 4800
+#define FT_BAUD_9600 9600
+#define FT_BAUD_14400 14400
+#define FT_BAUD_19200 19200
+#define FT_BAUD_38400 38400
+#define FT_BAUD_57600 57600
+#define FT_BAUD_115200 115200
+#define FT_BAUD_230400 230400
+#define FT_BAUD_460800 460800
+#define FT_BAUD_921600 921600
+
+//
+// Word Lengths
+//
+
+#define FT_BITS_8 (UCHAR) 8
+#define FT_BITS_7 (UCHAR) 7
+#define FT_BITS_6 (UCHAR) 6
+#define FT_BITS_5 (UCHAR) 5
+
+//
+// Stop Bits
+//
+
+#define FT_STOP_BITS_1 (UCHAR) 0
+#define FT_STOP_BITS_1_5 (UCHAR) 1
+#define FT_STOP_BITS_2 (UCHAR) 2
+
+//
+// Parity
+//
+
+#define FT_PARITY_NONE (UCHAR) 0
+#define FT_PARITY_ODD (UCHAR) 1
+#define FT_PARITY_EVEN (UCHAR) 2
+#define FT_PARITY_MARK (UCHAR) 3
+#define FT_PARITY_SPACE (UCHAR) 4
+
+//
+// Flow Control
+//
+
+#define FT_FLOW_NONE 0x0000
+#define FT_FLOW_RTS_CTS 0x0100
+#define FT_FLOW_DTR_DSR 0x0200
+#define FT_FLOW_XON_XOFF 0x0400
+
+//
+// Purge rx and tx buffers
+//
+#define FT_PURGE_RX 1
+#define FT_PURGE_TX 2
+
+//
+// Events
+//
+
+typedef void (*PFT_EVENT_HANDLER)(DWORD,DWORD);
+
+#define FT_EVENT_RXCHAR 1
+#define FT_EVENT_MODEM_STATUS 2
+
+//
+// Timeouts
+//
+
+#define FT_DEFAULT_RX_TIMEOUT 300
+#define FT_DEFAULT_TX_TIMEOUT 300
+
+//
+// Device types
+//
+
+typedef ULONG FT_DEVICE;
+
+enum {
+ FT_DEVICE_BM,
+ FT_DEVICE_AM,
+ FT_DEVICE_100AX,
+ FT_DEVICE_UNKNOWN,
+ FT_DEVICE_2232C,
+ FT_DEVICE_232R
+};
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+FTD2XX_API
+FT_STATUS WINAPI FT_Open(
+ int deviceNumber,
+ FT_HANDLE *pHandle
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_OpenEx(
+ PVOID pArg1,
+ DWORD Flags,
+ FT_HANDLE *pHandle
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_ListDevices(
+ PVOID pArg1,
+ PVOID pArg2,
+ DWORD Flags
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_Close(
+ FT_HANDLE ftHandle
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_Read(
+ FT_HANDLE ftHandle,
+ LPVOID lpBuffer,
+ DWORD nBufferSize,
+ LPDWORD lpBytesReturned
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_Write(
+ FT_HANDLE ftHandle,
+ LPVOID lpBuffer,
+ DWORD nBufferSize,
+ LPDWORD lpBytesWritten
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_IoCtl(
+ FT_HANDLE ftHandle,
+ DWORD dwIoControlCode,
+ LPVOID lpInBuf,
+ DWORD nInBufSize,
+ LPVOID lpOutBuf,
+ DWORD nOutBufSize,
+ LPDWORD lpBytesReturned,
+ LPOVERLAPPED lpOverlapped
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_SetBaudRate(
+ FT_HANDLE ftHandle,
+ ULONG BaudRate
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_SetDivisor(
+ FT_HANDLE ftHandle,
+ USHORT Divisor
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_SetDataCharacteristics(
+ FT_HANDLE ftHandle,
+ UCHAR WordLength,
+ UCHAR StopBits,
+ UCHAR Parity
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_SetFlowControl(
+ FT_HANDLE ftHandle,
+ USHORT FlowControl,
+ UCHAR XonChar,
+ UCHAR XoffChar
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_ResetDevice(
+ FT_HANDLE ftHandle
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_SetDtr(
+ FT_HANDLE ftHandle
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_ClrDtr(
+ FT_HANDLE ftHandle
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_SetRts(
+ FT_HANDLE ftHandle
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_ClrRts(
+ FT_HANDLE ftHandle
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_GetModemStatus(
+ FT_HANDLE ftHandle,
+ ULONG *pModemStatus
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_SetChars(
+ FT_HANDLE ftHandle,
+ UCHAR EventChar,
+ UCHAR EventCharEnabled,
+ UCHAR ErrorChar,
+ UCHAR ErrorCharEnabled
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_Purge(
+ FT_HANDLE ftHandle,
+ ULONG Mask
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_SetTimeouts(
+ FT_HANDLE ftHandle,
+ ULONG ReadTimeout,
+ ULONG WriteTimeout
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_GetQueueStatus(
+ FT_HANDLE ftHandle,
+ DWORD *dwRxBytes
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_SetEventNotification(
+ FT_HANDLE ftHandle,
+ DWORD Mask,
+ PVOID Param
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_GetStatus(
+ FT_HANDLE ftHandle,
+ DWORD *dwRxBytes,
+ DWORD *dwTxBytes,
+ DWORD *dwEventDWord
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_SetBreakOn(
+ FT_HANDLE ftHandle
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_SetBreakOff(
+ FT_HANDLE ftHandle
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_SetWaitMask(
+ FT_HANDLE ftHandle,
+ DWORD Mask
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_WaitOnMask(
+ FT_HANDLE ftHandle,
+ DWORD *Mask
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_GetEventStatus(
+ FT_HANDLE ftHandle,
+ DWORD *dwEventDWord
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_ReadEE(
+ FT_HANDLE ftHandle,
+ DWORD dwWordOffset,
+ LPWORD lpwValue
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_WriteEE(
+ FT_HANDLE ftHandle,
+ DWORD dwWordOffset,
+ WORD wValue
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_EraseEE(
+ FT_HANDLE ftHandle
+ );
+
+//
+// structure to hold program data for FT_Program function
+//
+typedef struct ft_program_data {
+
+ DWORD Signature1; // Header - must be 0x00000000
+ DWORD Signature2; // Header - must be 0xffffffff
+ DWORD Version; // Header - FT_PROGRAM_DATA version
+ // 0 = original
+ // 1 = FT2232C extensions
+ // 2 = FT232R extensions
+
+ WORD VendorId; // 0x0403
+ WORD ProductId; // 0x6001
+ char *Manufacturer; // "FTDI"
+ char *ManufacturerId; // "FT"
+ char *Description; // "USB HS Serial Converter"
+ char *SerialNumber; // "FT000001" if fixed, or NULL
+ WORD MaxPower; // 0 < MaxPower <= 500
+ WORD PnP; // 0 = disabled, 1 = enabled
+ WORD SelfPowered; // 0 = bus powered, 1 = self powered
+ WORD RemoteWakeup; // 0 = not capable, 1 = capable
+ //
+ // Rev4 extensions
+ //
+ UCHAR Rev4; // non-zero if Rev4 chip, zero otherwise
+ UCHAR IsoIn; // non-zero if in endpoint is isochronous
+ UCHAR IsoOut; // non-zero if out endpoint is isochronous
+ UCHAR PullDownEnable; // non-zero if pull down enabled
+ UCHAR SerNumEnable; // non-zero if serial number to be used
+ UCHAR USBVersionEnable; // non-zero if chip uses USBVersion
+ WORD USBVersion; // BCD (0x0200 => USB2)
+ //
+ // FT2232C extensions
+ //
+ UCHAR Rev5; // non-zero if Rev5 chip, zero otherwise
+ UCHAR IsoInA; // non-zero if in endpoint is isochronous
+ UCHAR IsoInB; // non-zero if in endpoint is isochronous
+ UCHAR IsoOutA; // non-zero if out endpoint is isochronous
+ UCHAR IsoOutB; // non-zero if out endpoint is isochronous
+ UCHAR PullDownEnable5; // non-zero if pull down enabled
+ UCHAR SerNumEnable5; // non-zero if serial number to be used
+ UCHAR USBVersionEnable5; // non-zero if chip uses USBVersion
+ WORD USBVersion5; // BCD (0x0200 => USB2)
+ UCHAR AIsHighCurrent; // non-zero if interface is high current
+ UCHAR BIsHighCurrent; // non-zero if interface is high current
+ UCHAR IFAIsFifo; // non-zero if interface is 245 FIFO
+ UCHAR IFAIsFifoTar; // non-zero if interface is 245 FIFO CPU target
+ UCHAR IFAIsFastSer; // non-zero if interface is Fast serial
+ UCHAR AIsVCP; // non-zero if interface is to use VCP drivers
+ UCHAR IFBIsFifo; // non-zero if interface is 245 FIFO
+ UCHAR IFBIsFifoTar; // non-zero if interface is 245 FIFO CPU target
+ UCHAR IFBIsFastSer; // non-zero if interface is Fast serial
+ UCHAR BIsVCP; // non-zero if interface is to use VCP drivers
+ //
+ // FT232R extensions
+ //
+ UCHAR UseExtOsc; // Use External Oscillator
+ UCHAR HighDriveIOs; // High Drive I/Os
+ UCHAR EndpointSize; // Endpoint size
+
+ UCHAR PullDownEnableR; // non-zero if pull down enabled
+ UCHAR SerNumEnableR; // non-zero if serial number to be used
+
+ UCHAR InvertTXD; // non-zero if invert TXD
+ UCHAR InvertRXD; // non-zero if invert RXD
+ UCHAR InvertRTS; // non-zero if invert RTS
+ UCHAR InvertCTS; // non-zero if invert CTS
+ UCHAR InvertDTR; // non-zero if invert DTR
+ UCHAR InvertDSR; // non-zero if invert DSR
+ UCHAR InvertDCD; // non-zero if invert DCD
+ UCHAR InvertRI; // non-zero if invert RI
+
+ UCHAR Cbus0; // Cbus Mux control
+ UCHAR Cbus1; // Cbus Mux control
+ UCHAR Cbus2; // Cbus Mux control
+ UCHAR Cbus3; // Cbus Mux control
+ UCHAR Cbus4; // Cbus Mux control
+
+ UCHAR RIsD2XX; // non-zero if using D2XX driver
+
+} FT_PROGRAM_DATA, *PFT_PROGRAM_DATA;
+
+FTD2XX_API
+FT_STATUS WINAPI FT_EE_Program(
+ FT_HANDLE ftHandle,
+ PFT_PROGRAM_DATA pData
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_EE_ProgramEx(
+ FT_HANDLE ftHandle,
+ PFT_PROGRAM_DATA pData,
+ char *Manufacturer,
+ char *ManufacturerId,
+ char *Description,
+ char *SerialNumber
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_EE_Read(
+ FT_HANDLE ftHandle,
+ PFT_PROGRAM_DATA pData
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_EE_ReadEx(
+ FT_HANDLE ftHandle,
+ PFT_PROGRAM_DATA pData,
+ char *Manufacturer,
+ char *ManufacturerId,
+ char *Description,
+ char *SerialNumber
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_EE_UASize(
+ FT_HANDLE ftHandle,
+ LPDWORD lpdwSize
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_EE_UAWrite(
+ FT_HANDLE ftHandle,
+ PUCHAR pucData,
+ DWORD dwDataLen
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_EE_UARead(
+ FT_HANDLE ftHandle,
+ PUCHAR pucData,
+ DWORD dwDataLen,
+ LPDWORD lpdwBytesRead
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_SetLatencyTimer(
+ FT_HANDLE ftHandle,
+ UCHAR ucLatency
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_GetLatencyTimer(
+ FT_HANDLE ftHandle,
+ PUCHAR pucLatency
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_SetBitMode(
+ FT_HANDLE ftHandle,
+ UCHAR ucMask,
+ UCHAR ucEnable
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_GetBitMode(
+ FT_HANDLE ftHandle,
+ PUCHAR pucMode
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_SetUSBParameters(
+ FT_HANDLE ftHandle,
+ ULONG ulInTransferSize,
+ ULONG ulOutTransferSize
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_SetDeadmanTimeout(
+ FT_HANDLE ftHandle,
+ ULONG ulDeadmanTimeout
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_GetDeviceInfo(
+ FT_HANDLE ftHandle,
+ FT_DEVICE *lpftDevice,
+ LPDWORD lpdwID,
+ PCHAR SerialNumber,
+ PCHAR Description,
+ LPVOID Dummy
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_StopInTask(
+ FT_HANDLE ftHandle
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_RestartInTask(
+ FT_HANDLE ftHandle
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_SetResetPipeRetryCount(
+ FT_HANDLE ftHandle,
+ DWORD dwCount
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_ResetPort(
+ FT_HANDLE ftHandle
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_CyclePort(
+ FT_HANDLE ftHandle
+ );
+
+
+//
+// Win32-type functions
+//
+
+FTD2XX_API
+FT_HANDLE WINAPI FT_W32_CreateFile(
+ LPCTSTR lpszName,
+ DWORD dwAccess,
+ DWORD dwShareMode,
+ LPSECURITY_ATTRIBUTES lpSecurityAttributes,
+ DWORD dwCreate,
+ DWORD dwAttrsAndFlags,
+ HANDLE hTemplate
+ );
+
+FTD2XX_API
+BOOL WINAPI FT_W32_CloseHandle(
+ FT_HANDLE ftHandle
+ );
+
+FTD2XX_API
+BOOL WINAPI FT_W32_ReadFile(
+ FT_HANDLE ftHandle,
+ LPVOID lpBuffer,
+ DWORD nBufferSize,
+ LPDWORD lpBytesReturned,
+ LPOVERLAPPED lpOverlapped
+ );
+
+FTD2XX_API
+BOOL WINAPI FT_W32_WriteFile(
+ FT_HANDLE ftHandle,
+ LPVOID lpBuffer,
+ DWORD nBufferSize,
+ LPDWORD lpBytesWritten,
+ LPOVERLAPPED lpOverlapped
+ );
+
+FTD2XX_API
+DWORD WINAPI FT_W32_GetLastError(
+ FT_HANDLE ftHandle
+ );
+
+FTD2XX_API
+BOOL WINAPI FT_W32_GetOverlappedResult(
+ FT_HANDLE ftHandle,
+ LPOVERLAPPED lpOverlapped,
+ LPDWORD lpdwBytesTransferred,
+ BOOL bWait
+ );
+
+FTD2XX_API
+BOOL WINAPI FT_W32_CancelIo(
+ FT_HANDLE ftHandle
+ );
+
+
+//
+// Win32 COMM API type functions
+//
+typedef struct _FTCOMSTAT {
+ DWORD fCtsHold : 1;
+ DWORD fDsrHold : 1;
+ DWORD fRlsdHold : 1;
+ DWORD fXoffHold : 1;
+ DWORD fXoffSent : 1;
+ DWORD fEof : 1;
+ DWORD fTxim : 1;
+ DWORD fReserved : 25;
+ DWORD cbInQue;
+ DWORD cbOutQue;
+} FTCOMSTAT, *LPFTCOMSTAT;
+
+typedef struct _FTDCB {
+ DWORD DCBlength; /* sizeof(FTDCB) */
+ DWORD BaudRate; /* Baudrate at which running */
+ DWORD fBinary: 1; /* Binary Mode (skip EOF check) */
+ DWORD fParity: 1; /* Enable parity checking */
+ DWORD fOutxCtsFlow:1; /* CTS handshaking on output */
+ DWORD fOutxDsrFlow:1; /* DSR handshaking on output */
+ DWORD fDtrControl:2; /* DTR Flow control */
+ DWORD fDsrSensitivity:1; /* DSR Sensitivity */
+ DWORD fTXContinueOnXoff: 1; /* Continue TX when Xoff sent */
+ DWORD fOutX: 1; /* Enable output X-ON/X-OFF */
+ DWORD fInX: 1; /* Enable input X-ON/X-OFF */
+ DWORD fErrorChar: 1; /* Enable Err Replacement */
+ DWORD fNull: 1; /* Enable Null stripping */
+ DWORD fRtsControl:2; /* Rts Flow control */
+ DWORD fAbortOnError:1; /* Abort all reads and writes on Error */
+ DWORD fDummy2:17; /* Reserved */
+ WORD wReserved; /* Not currently used */
+ WORD XonLim; /* Transmit X-ON threshold */
+ WORD XoffLim; /* Transmit X-OFF threshold */
+ BYTE ByteSize; /* Number of bits/byte, 4-8 */
+ BYTE Parity; /* 0-4=None,Odd,Even,Mark,Space */
+ BYTE StopBits; /* 0,1,2 = 1, 1.5, 2 */
+ char XonChar; /* Tx and Rx X-ON character */
+ char XoffChar; /* Tx and Rx X-OFF character */
+ char ErrorChar; /* Error replacement char */
+ char EofChar; /* End of Input character */
+ char EvtChar; /* Received Event character */
+ WORD wReserved1; /* Fill for now. */
+} FTDCB, *LPFTDCB;
+
+typedef struct _FTTIMEOUTS {
+ DWORD ReadIntervalTimeout; /* Maximum time between read chars. */
+ DWORD ReadTotalTimeoutMultiplier; /* Multiplier of characters. */
+ DWORD ReadTotalTimeoutConstant; /* Constant in milliseconds. */
+ DWORD WriteTotalTimeoutMultiplier; /* Multiplier of characters. */
+ DWORD WriteTotalTimeoutConstant; /* Constant in milliseconds. */
+} FTTIMEOUTS,*LPFTTIMEOUTS;
+
+
+FTD2XX_API
+BOOL WINAPI FT_W32_ClearCommBreak(
+ FT_HANDLE ftHandle
+ );
+
+FTD2XX_API
+BOOL WINAPI FT_W32_ClearCommError(
+ FT_HANDLE ftHandle,
+ LPDWORD lpdwErrors,
+ LPFTCOMSTAT lpftComstat
+ );
+
+FTD2XX_API
+BOOL WINAPI FT_W32_EscapeCommFunction(
+ FT_HANDLE ftHandle,
+ DWORD dwFunc
+ );
+
+FTD2XX_API
+BOOL WINAPI FT_W32_GetCommModemStatus(
+ FT_HANDLE ftHandle,
+ LPDWORD lpdwModemStatus
+ );
+
+FTD2XX_API
+BOOL WINAPI FT_W32_GetCommState(
+ FT_HANDLE ftHandle,
+ LPFTDCB lpftDcb
+ );
+
+FTD2XX_API
+BOOL WINAPI FT_W32_GetCommTimeouts(
+ FT_HANDLE ftHandle,
+ FTTIMEOUTS *pTimeouts
+ );
+
+FTD2XX_API
+BOOL WINAPI FT_W32_PurgeComm(
+ FT_HANDLE ftHandle,
+ DWORD dwMask
+ );
+
+FTD2XX_API
+BOOL WINAPI FT_W32_SetCommBreak(
+ FT_HANDLE ftHandle
+ );
+
+FTD2XX_API
+BOOL WINAPI FT_W32_SetCommMask(
+ FT_HANDLE ftHandle,
+ ULONG ulEventMask
+ );
+
+FTD2XX_API
+BOOL WINAPI FT_W32_GetCommMask(
+ FT_HANDLE ftHandle,
+ LPDWORD lpdwEventMask
+ );
+
+FTD2XX_API
+BOOL WINAPI FT_W32_SetCommState(
+ FT_HANDLE ftHandle,
+ LPFTDCB lpftDcb
+ );
+
+FTD2XX_API
+BOOL WINAPI FT_W32_SetCommTimeouts(
+ FT_HANDLE ftHandle,
+ FTTIMEOUTS *pTimeouts
+ );
+
+FTD2XX_API
+BOOL WINAPI FT_W32_SetupComm(
+ FT_HANDLE ftHandle,
+ DWORD dwReadBufferSize,
+ DWORD dwWriteBufferSize
+ );
+
+FTD2XX_API
+BOOL WINAPI FT_W32_WaitCommEvent(
+ FT_HANDLE ftHandle,
+ PULONG pulEvent,
+ LPOVERLAPPED lpOverlapped
+ );
+
+
+//
+// Device information
+//
+
+typedef struct _ft_device_list_info_node {
+ ULONG Flags;
+ ULONG Type;
+ ULONG ID;
+ DWORD LocId;
+ char SerialNumber[16];
+ char Description[64];
+ FT_HANDLE ftHandle;
+} FT_DEVICE_LIST_INFO_NODE;
+
+
+FTD2XX_API
+FT_STATUS WINAPI FT_CreateDeviceInfoList(
+ LPDWORD lpdwNumDevs
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_GetDeviceInfoList(
+ FT_DEVICE_LIST_INFO_NODE *pDest,
+ LPDWORD lpdwNumDevs
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_GetDeviceInfoDetail(
+ DWORD dwIndex,
+ LPDWORD lpdwFlags,
+ LPDWORD lpdwType,
+ LPDWORD lpdwID,
+ LPDWORD lpdwLocId,
+ LPVOID lpSerialNumber,
+ LPVOID lpDescription,
+ FT_HANDLE *pftHandle
+ );
+
+
+//
+// Version information
+//
+
+FTD2XX_API
+FT_STATUS WINAPI FT_GetDriverVersion(
+ FT_HANDLE ftHandle,
+ LPDWORD lpdwVersion
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_GetLibraryVersion(
+ LPDWORD lpdwVersion
+ );
+
+
+FTD2XX_API
+FT_STATUS WINAPI FT_Rescan(
+ void
+ );
+
+FTD2XX_API
+FT_STATUS WINAPI FT_Reload(
+ WORD wVid,
+ WORD wPid
+ );
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* FTD2XX_H */
diff --git a/tools/wpcapslip/wpcapstdio.c b/tools/wpcapslip/wpcapstdio.c
index 88f1eace4..287ab07a0 100644
--- a/tools/wpcapslip/wpcapstdio.c
+++ b/tools/wpcapslip/wpcapstdio.c
@@ -1,597 +1,597 @@
-/*
- * Copyright (c) 2012, Thingsquare, www.thingsquare.com.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the Institute nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * This file is part of the Contiki operating system.
- *
- * Author: Fredrik Osterlind
- * Based on wpcapslip.c by : Oliver Schmidt
- */
-
-/* This is a stripped-down version of wpcapslip: Instead of reading from and writing
- * to a serial port, this program just reads and writes to stdin/stdout. To
- * achieve the same functionality as wpcapslip, this program can hence be connected
- * to serialdump. But, in contrast to wpcapslip, this program can easily be connected
- * to networked or simulated serial ports. -- Fredrik, 2012 */
-
-#include
-#include
-#include
-#ifdef __CYGWIN__
-#include
-#else /* __CYGWIN__ */
-#include
-#endif /* __CYGWIN__ */
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include
-
-#include
-#include
-
-#define PROGRESS(x)
-
-void wpcap_start(char *ethifaddr, char *netaddr, char *netmask, int logging);
-
-void wpcap_send(void *buf, int len);
-void raw_send(void *buf, int len);
-
-uint16_t wpcap_poll(char **buf, int eth);
-
-#include "net/tcpdump.h"
-static int should_print = 0;
-
-static int send_eth = 0; /* Sends ethernet frames or IP packets */
-
-#define IP_HLEN 20
-
-/*---------------------------------------------------------------------------*/
-uint16_t
-uip_htons(uint16_t val)
-{
- return UIP_HTONS(val);
-}
-/*---------------------------------------------------------------------------*/
-uint32_t
-uip_htonl(uint32_t val)
-{
- return UIP_HTONL(val);
-}
-/*---------------------------------------------------------------------------*/
-static void
-print_packet(char* prefix, uint8_t *packet, int len)
-{
- char buf[2000];
- if(should_print) {
- tcpdump_format(packet, len, buf, sizeof(buf));
- fprintf(stderr, "%s: %s\n", prefix, buf);
- }
-}
-/*---------------------------------------------------------------------------*/
-void cleanup(void);
-/*---------------------------------------------------------------------------*/
-void
-sigcleanup(int signo)
-{
- fprintf(stderr, "signal %d\n", signo);
- exit(0); /* exit(0) will call cleanup() */
-}
-/*---------------------------------------------------------------------------*/
-#define SLIP_END 0300
-#define SLIP_ESC 0333
-#define SLIP_ESC_END 0334
-#define SLIP_ESC_ESC 0335
-
-struct ip {
- u_int8_t ip_vhl; /* version and header length */
-#define IP_V4 0x40
-#define IP_V 0xf0
-#define IP_HL 0x0f
- u_int8_t ip_tos; /* type of service */
- u_int16_t ip_len; /* total length */
- u_int16_t ip_id; /* identification */
- u_int16_t ip_off; /* fragment offset field */
-#define IP_RF 0x8000 /* reserved fragment flag */
-#define IP_DF 0x4000 /* dont fragment flag */
-#define IP_MF 0x2000 /* more fragments flag */
-#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
- u_int8_t ip_ttl; /* time to live */
- u_int8_t ip_p; /* protocol */
- u_int16_t ip_sum; /* checksum */
- u_int32_t ip_src, ip_dst; /* source and dest address */
- u_int16_t uh_sport; /* source port */
- u_int16_t uh_dport; /* destination port */
- u_int16_t uh_ulen; /* udp length */
- u_int16_t uh_sum; /* udp checksum */
-};
-
-static int ip_id, last_id;
-
-int
-ssystem(const char *fmt, ...) __attribute__((__format__ (__printf__, 1, 2)));
-
-int
-ssystem(const char *fmt, ...)
-{
- char cmd[128];
- va_list ap;
- va_start(ap, fmt);
- vsnprintf(cmd, sizeof(cmd), fmt, ap);
- va_end(ap);
- fprintf(stderr, "%s\n", cmd);
- fflush(stderr);
- return system(cmd);
-}
-/*---------------------------------------------------------------------------*/
-int
-is_sensible_string(const unsigned char *s, int len)
-{
- int i;
- for(i = 1; i < len; i++) {
- if(s[i] == 0 || s[i] == '\r' || s[i] == '\n' || s[i] == '\t') {
- continue;
- } else if(s[i] < ' ' || '~' < s[i]) {
- return 0;
- }
- }
- return 1;
-}
-/*---------------------------------------------------------------------------*/
-u_int16_t
-ip4sum(u_int16_t sum, const void *_p, u_int16_t len)
-{
- u_int16_t t;
- const u_int8_t *p = _p;
- const u_int8_t *end = p + len;
-
- while(p < (end - 1)) {
- t = (p[0] << 8) + p[1];
- sum += t;
- if(sum < t)
- sum++;
- p += 2;
- }
- if(p < end) {
- t = (p[0] << 8) + 0;
- sum += t;
- if(sum < t)
- sum++;
- }
- return sum;
-}
-/*---------------------------------------------------------------------------*/
-static uint16_t
-chksum(const void *p, uint16_t len)
-{
- uint16_t sum = ip4sum(0, p, len);
- return (sum == 0) ? 0xffff : uip_htons(sum);
-}
-/*---------------------------------------------------------------------------*/
-int
-check_ip(const struct ip *ip, unsigned ip_len)
-{
- u_int16_t sum, ip_hl;
-
- if(send_eth) {
- return 0;
- }
-
- /* Check IP version and length. */
- if((ip->ip_vhl & IP_V) != IP_V4) {
- return -1;
- }
-
- if(uip_ntohs(ip->ip_len) > ip_len) {
- return -2;
- }
-
- if(uip_ntohs(ip->ip_len) < ip_len) {
- return -3;
- }
-
- /* Check IP header. */
- ip_hl = 4 * (ip->ip_vhl & IP_HL);
- sum = ip4sum(0, ip, ip_hl);
- if(sum != 0xffff && sum != 0x0) {
- return -4;
- }
-
- if(ip->ip_p == 6 || ip->ip_p == 17) { /* Check TCP or UDP header. */
- u_int16_t tcp_len = ip_len - ip_hl;
-
- /* Sum pseudoheader. */
- sum = ip->ip_p + tcp_len; /* proto and len, no carry */
- sum = ip4sum(sum, &ip->ip_src, 8); /* src and dst */
-
- /* Sum TCP/UDP header and data. */
- sum = ip4sum(sum, (u_int8_t*)ip + ip_hl, tcp_len);
-
- /* Failed checksum test? */
- if(sum != 0xffff && sum != 0x0) {
- if(ip->ip_p == 6) { /* TCP == 6 */
- return -5;
- } else { /* UDP */
- /* Deal with disabled UDP checksums. */
- if(ip->uh_sum != 0) {
- return -6;
- }
- }
- }
- } else if(ip->ip_p == 1) { /* ICMP */
- u_int16_t icmp_len = ip_len - ip_hl;
-
- sum = ip4sum(0, (u_int8_t*)ip + ip_hl, icmp_len);
- if(sum != 0xffff && sum != 0x0) {
- return -7;
- }
- }
- return 0;
-}
-/*---------------------------------------------------------------------------*/
-/*
- * Read a single character from stdin. When we have a full packet, write it to
- * the network interface.
- */
-void
-serial_to_wpcap(void)
-{
- static union {
- unsigned char inbuf[2000];
- struct ip iphdr;
- } uip;
- static int inbufptr = 0;
-
- int ret;
- unsigned char c;
-
- if(inbufptr >= sizeof(uip.inbuf)) {
- inbufptr = 0;
- return;
- }
- ret = read(STDIN_FILENO, &c, 1);
-
- if(ret <= 0) {
- err(1, "serial_to_wpcap: read");
- inbufptr = 0;
- return;
- }
-
- switch (c) {
- case SLIP_END:
- if(inbufptr > 0) {
- /*
- * Sanity checks.
- */
-#define DEBUG_LINE_MARKER '\r'
- int ecode;
-
- ecode = check_ip(&uip.iphdr, inbufptr);
- if(ecode < 0 && inbufptr == 8
- && strncmp((const char*)uip.inbuf, "=IPA", 4) == 0) {
- static struct in_addr ipa;
-
- inbufptr = 0;
- if(memcmp(&ipa, &uip.inbuf[4], sizeof(ipa)) == 0) {
- break;
- }
-
- memcpy(&ipa, &uip.inbuf[4], sizeof(ipa));
- break;
- } else if(ecode < 0) {
- /*
- * If sensible ASCII string, print it as debug info!
- */
- /* printf("----------------------------------\n");*/
- if(uip.inbuf[0] == DEBUG_LINE_MARKER) {
- fwrite(uip.inbuf + 1, inbufptr - 1, 1, stderr);
- } else if(is_sensible_string(uip.inbuf, inbufptr)) {
- fwrite(uip.inbuf, inbufptr, 1, stderr);
- } else {
- fprintf(stderr, "serial_to_wpcap: drop packet len=%d ecode=%d\n",
- inbufptr, ecode);
- }
- inbufptr = 0;
- break;
- }
- PROGRESS("s");
-
- if(send_eth) {
- raw_send(uip.inbuf, inbufptr);
- } else {
- /* printf("Sending to wpcap\n");*/
- if(uip.iphdr.ip_id != last_id) {
- last_id = uip.iphdr.ip_id;
- print_packet("to wpcap: ", uip.inbuf, inbufptr);
- wpcap_send(uip.inbuf, inbufptr);
- } else {
- /*print_packet("IGNORED to wpcap: ", uip.inbuf, inbufptr);*/
- }
- }
- /* printf("After sending to wpcap\n");*/
- inbufptr = 0;
- }
- break;
-
- case SLIP_ESC:
- /* TODO We do not actually check that we have another byte incoming, so
- * we may block here */
- read(STDIN_FILENO, &c, 1);
-
- switch (c) {
- case SLIP_ESC_END:
- c = SLIP_END;
- break;
- case SLIP_ESC_ESC:
- c = SLIP_ESC;
- break;
- }
-
- /* FALLTHROUGH */
- default:
- uip.inbuf[inbufptr++] = c;
- break;
- }
-}
-/*---------------------------------------------------------------------------*/
-unsigned char stdout_buf[2000];
-int stdout_buf_cnt;
-/*---------------------------------------------------------------------------*/
-void
-stdout_write(unsigned char c)
-{
- if(stdout_buf_cnt >= sizeof(stdout_buf)) {
- err(1, "stdout_write overflow");
- }
- stdout_buf[stdout_buf_cnt] = c;
- stdout_buf_cnt++;
-}
-/*---------------------------------------------------------------------------*/
-int
-stdout_buf_empty(void)
-{
- return stdout_buf_cnt == 0;
-}
-/*---------------------------------------------------------------------------*/
-void
-stdout_flushbuf(void)
-{
- if(stdout_buf_empty()) {
- return;
- }
-
- fwrite(stdout_buf, stdout_buf_cnt, 1, stdout);
- stdout_buf_cnt = 0;
- fflush(stdout);
-}
-/*---------------------------------------------------------------------------*/
-void
-write_slip_stdout(void *inbuf, int len)
-{
- u_int8_t *p = inbuf;
- int i, ecode;
- struct ip *iphdr = inbuf;
-
- if(!send_eth) {
- /*
- * Sanity checks.
- */
- /*fprintf(stderr, "write_slip_stdout: %d\n", len);*/
- ecode = check_ip(inbuf, len);
- if(ecode < 0) {
- fprintf(stderr, "write_slip_stdout: drop packet %d\n", ecode);
- return;
- }
-
- if(iphdr->ip_id == 0 && iphdr->ip_off & IP_DF) {
- uint16_t nid = uip_htons(ip_id++);
- iphdr->ip_id = nid;
- nid = ~nid; /* negate */
- iphdr->ip_sum += nid; /* add */
- if(iphdr->ip_sum < nid) { /* 1-complement overflow? */
- iphdr->ip_sum++;
- }
- ecode = check_ip(inbuf, len);
- if(ecode < 0) {
- fprintf(stderr, "write_slip_stdout: drop packet %d\n", ecode);
- return;
- }
- }
-
- iphdr->ip_ttl = uip_htons(uip_htons(iphdr->ip_ttl) + 1);
- if(iphdr->ip_ttl == 0) {
- fprintf(stderr, "Packet with ttl %d dropped\n", iphdr->ip_ttl);
- return;
- }
- iphdr->ip_sum = 0;
- iphdr->ip_sum = ~chksum(iphdr, 4 * (iphdr->ip_vhl & IP_HL));
- ecode = check_ip(inbuf, len);
- if(ecode < 0) {
- fprintf(stderr, "write_slip_stdout: drop packet %d\n", ecode);
- return;
- }
- }
-
- for(i = 0; i < len; i++) {
- switch (p[i]) {
- case SLIP_END:
- stdout_write(SLIP_ESC);
- stdout_write(SLIP_ESC_END);
- break;
- case SLIP_ESC:
- stdout_write(SLIP_ESC);
- stdout_write(SLIP_ESC_ESC);
- break;
- default:
- stdout_write(p[i]);
- break;
- }
- }
- stdout_write(SLIP_END);
- /* printf("slip end\n");*/
- PROGRESS("t");
-}
-/*---------------------------------------------------------------------------*/
-/*const char *ipaddr;*/
-/*const char *netmask;*/
-static int got_sigalarm;
-void
-sigalarm(int signo)
-{
- got_sigalarm = 1;
- return;
-}
-/*---------------------------------------------------------------------------*/
-void
-sigalarm_reset(void)
-{
-#ifdef linux
-#define TIMEOUT (997*1000)
-#else
-#define TIMEOUT (2451*1000)
-#endif
- ualarm(TIMEOUT, TIMEOUT);
- got_sigalarm = 0;
-}
-/*---------------------------------------------------------------------------*/
-int
-main(int argc, char **argv)
-{
- int c;
- int ret;
- char buf[4000];
- int logging = 0;
-
- ip_id = getpid() * time(NULL);
-
- while((c = getopt(argc, argv, "E:D:hl:t:T")) != -1) {
- switch (c) {
- case 'E':
- send_eth = 1;
- break;
-
- case 'T':
- should_print = 1;
- break;
-
- case 'l':
- logging = 1;
- break;
-
- case '?':
- case 'h':
- default:
- err(1,
- "usage: wpcapstdio [-E] [-l] [-T] ");
- break;
- }
- }
- argc -= (optind - 1);
- argv += (optind - 1);
-
- if(argc != 4) {
- err(1, "usage: wpcapstdio [-E] [-T] ");
- }
-
- wpcap_start(argv[1], argv[2], argv[3], logging);
- stdout_write(SLIP_END);
-
- atexit(cleanup);
- signal(SIGHUP, sigcleanup);
- signal(SIGTERM, sigcleanup);
- signal(SIGINT, sigcleanup);
- signal(SIGALRM, sigalarm);
-
- while(1) {
- if(got_sigalarm) {
- /* Send "?IPA". */
- stdout_write('?');
- stdout_write('I');
- stdout_write('P');
- stdout_write('A');
- stdout_write(SLIP_END);
- got_sigalarm = 0;
- }
-
- if(stdout_buf_empty()) {
- char *pbuf = buf;
-
- ret = wpcap_poll(&pbuf, send_eth);
- if(ret > 0) {
- if(send_eth) {
- write_slip_stdout(pbuf, ret);
- stdout_flushbuf();
- } else {
- struct ip *iphdr = (struct ip *)pbuf;
- if(iphdr->ip_id != last_id) {
- /*last_id = iphdr->ip_id;*/
- print_packet("to stdout: ", (uint8_t*)pbuf, ret);
- write_slip_stdout(pbuf, ret);
- stdout_flushbuf();
- } else {
- /*print_packet("IGNORED to stdout: ", (uint8_t*)pbuf, ret);*/
- }
- }
- }
- }
-
- if(!stdout_buf_empty()) {
- stdout_flushbuf();
- }
-
- {
- fd_set s_rd;
- struct timeval tv;
-
- tv.tv_sec = 0;
- tv.tv_usec = 100;
-
- do {
- FD_ZERO(&s_rd);
- FD_SET(fileno(stdin), &s_rd);
- select(fileno(stdin) + 1, &s_rd, NULL, NULL, &tv);
- if(FD_ISSET(fileno(stdin), &s_rd)) {
- serial_to_wpcap();
- }
- } while(FD_ISSET(fileno(stdin), &s_rd));
- }
- }
-}
-/*---------------------------------------------------------------------------*/
+/*
+ * Copyright (c) 2012, Thingsquare, www.thingsquare.com.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the Institute nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * This file is part of the Contiki operating system.
+ *
+ * Author: Fredrik Osterlind
+ * Based on wpcapslip.c by : Oliver Schmidt
+ */
+
+/* This is a stripped-down version of wpcapslip: Instead of reading from and writing
+ * to a serial port, this program just reads and writes to stdin/stdout. To
+ * achieve the same functionality as wpcapslip, this program can hence be connected
+ * to serialdump. But, in contrast to wpcapslip, this program can easily be connected
+ * to networked or simulated serial ports. -- Fredrik, 2012 */
+
+#include
+#include
+#include
+#ifdef __CYGWIN__
+#include
+#else /* __CYGWIN__ */
+#include
+#endif /* __CYGWIN__ */
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+
+#include
+#include
+
+#define PROGRESS(x)
+
+void wpcap_start(char *ethifaddr, char *netaddr, char *netmask, int logging);
+
+void wpcap_send(void *buf, int len);
+void raw_send(void *buf, int len);
+
+uint16_t wpcap_poll(char **buf, int eth);
+
+#include "net/tcpdump.h"
+static int should_print = 0;
+
+static int send_eth = 0; /* Sends ethernet frames or IP packets */
+
+#define IP_HLEN 20
+
+/*---------------------------------------------------------------------------*/
+uint16_t
+uip_htons(uint16_t val)
+{
+ return UIP_HTONS(val);
+}
+/*---------------------------------------------------------------------------*/
+uint32_t
+uip_htonl(uint32_t val)
+{
+ return UIP_HTONL(val);
+}
+/*---------------------------------------------------------------------------*/
+static void
+print_packet(char* prefix, uint8_t *packet, int len)
+{
+ char buf[2000];
+ if(should_print) {
+ tcpdump_format(packet, len, buf, sizeof(buf));
+ fprintf(stderr, "%s: %s\n", prefix, buf);
+ }
+}
+/*---------------------------------------------------------------------------*/
+void cleanup(void);
+/*---------------------------------------------------------------------------*/
+void
+sigcleanup(int signo)
+{
+ fprintf(stderr, "signal %d\n", signo);
+ exit(0); /* exit(0) will call cleanup() */
+}
+/*---------------------------------------------------------------------------*/
+#define SLIP_END 0300
+#define SLIP_ESC 0333
+#define SLIP_ESC_END 0334
+#define SLIP_ESC_ESC 0335
+
+struct ip {
+ u_int8_t ip_vhl; /* version and header length */
+#define IP_V4 0x40
+#define IP_V 0xf0
+#define IP_HL 0x0f
+ u_int8_t ip_tos; /* type of service */
+ u_int16_t ip_len; /* total length */
+ u_int16_t ip_id; /* identification */
+ u_int16_t ip_off; /* fragment offset field */
+#define IP_RF 0x8000 /* reserved fragment flag */
+#define IP_DF 0x4000 /* dont fragment flag */
+#define IP_MF 0x2000 /* more fragments flag */
+#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
+ u_int8_t ip_ttl; /* time to live */
+ u_int8_t ip_p; /* protocol */
+ u_int16_t ip_sum; /* checksum */
+ u_int32_t ip_src, ip_dst; /* source and dest address */
+ u_int16_t uh_sport; /* source port */
+ u_int16_t uh_dport; /* destination port */
+ u_int16_t uh_ulen; /* udp length */
+ u_int16_t uh_sum; /* udp checksum */
+};
+
+static int ip_id, last_id;
+
+int
+ssystem(const char *fmt, ...) __attribute__((__format__ (__printf__, 1, 2)));
+
+int
+ssystem(const char *fmt, ...)
+{
+ char cmd[128];
+ va_list ap;
+ va_start(ap, fmt);
+ vsnprintf(cmd, sizeof(cmd), fmt, ap);
+ va_end(ap);
+ fprintf(stderr, "%s\n", cmd);
+ fflush(stderr);
+ return system(cmd);
+}
+/*---------------------------------------------------------------------------*/
+int
+is_sensible_string(const unsigned char *s, int len)
+{
+ int i;
+ for(i = 1; i < len; i++) {
+ if(s[i] == 0 || s[i] == '\r' || s[i] == '\n' || s[i] == '\t') {
+ continue;
+ } else if(s[i] < ' ' || '~' < s[i]) {
+ return 0;
+ }
+ }
+ return 1;
+}
+/*---------------------------------------------------------------------------*/
+u_int16_t
+ip4sum(u_int16_t sum, const void *_p, u_int16_t len)
+{
+ u_int16_t t;
+ const u_int8_t *p = _p;
+ const u_int8_t *end = p + len;
+
+ while(p < (end - 1)) {
+ t = (p[0] << 8) + p[1];
+ sum += t;
+ if(sum < t)
+ sum++;
+ p += 2;
+ }
+ if(p < end) {
+ t = (p[0] << 8) + 0;
+ sum += t;
+ if(sum < t)
+ sum++;
+ }
+ return sum;
+}
+/*---------------------------------------------------------------------------*/
+static uint16_t
+chksum(const void *p, uint16_t len)
+{
+ uint16_t sum = ip4sum(0, p, len);
+ return (sum == 0) ? 0xffff : uip_htons(sum);
+}
+/*---------------------------------------------------------------------------*/
+int
+check_ip(const struct ip *ip, unsigned ip_len)
+{
+ u_int16_t sum, ip_hl;
+
+ if(send_eth) {
+ return 0;
+ }
+
+ /* Check IP version and length. */
+ if((ip->ip_vhl & IP_V) != IP_V4) {
+ return -1;
+ }
+
+ if(uip_ntohs(ip->ip_len) > ip_len) {
+ return -2;
+ }
+
+ if(uip_ntohs(ip->ip_len) < ip_len) {
+ return -3;
+ }
+
+ /* Check IP header. */
+ ip_hl = 4 * (ip->ip_vhl & IP_HL);
+ sum = ip4sum(0, ip, ip_hl);
+ if(sum != 0xffff && sum != 0x0) {
+ return -4;
+ }
+
+ if(ip->ip_p == 6 || ip->ip_p == 17) { /* Check TCP or UDP header. */
+ u_int16_t tcp_len = ip_len - ip_hl;
+
+ /* Sum pseudoheader. */
+ sum = ip->ip_p + tcp_len; /* proto and len, no carry */
+ sum = ip4sum(sum, &ip->ip_src, 8); /* src and dst */
+
+ /* Sum TCP/UDP header and data. */
+ sum = ip4sum(sum, (u_int8_t*)ip + ip_hl, tcp_len);
+
+ /* Failed checksum test? */
+ if(sum != 0xffff && sum != 0x0) {
+ if(ip->ip_p == 6) { /* TCP == 6 */
+ return -5;
+ } else { /* UDP */
+ /* Deal with disabled UDP checksums. */
+ if(ip->uh_sum != 0) {
+ return -6;
+ }
+ }
+ }
+ } else if(ip->ip_p == 1) { /* ICMP */
+ u_int16_t icmp_len = ip_len - ip_hl;
+
+ sum = ip4sum(0, (u_int8_t*)ip + ip_hl, icmp_len);
+ if(sum != 0xffff && sum != 0x0) {
+ return -7;
+ }
+ }
+ return 0;
+}
+/*---------------------------------------------------------------------------*/
+/*
+ * Read a single character from stdin. When we have a full packet, write it to
+ * the network interface.
+ */
+void
+serial_to_wpcap(void)
+{
+ static union {
+ unsigned char inbuf[2000];
+ struct ip iphdr;
+ } uip;
+ static int inbufptr = 0;
+
+ int ret;
+ unsigned char c;
+
+ if(inbufptr >= sizeof(uip.inbuf)) {
+ inbufptr = 0;
+ return;
+ }
+ ret = read(STDIN_FILENO, &c, 1);
+
+ if(ret <= 0) {
+ err(1, "serial_to_wpcap: read");
+ inbufptr = 0;
+ return;
+ }
+
+ switch (c) {
+ case SLIP_END:
+ if(inbufptr > 0) {
+ /*
+ * Sanity checks.
+ */
+#define DEBUG_LINE_MARKER '\r'
+ int ecode;
+
+ ecode = check_ip(&uip.iphdr, inbufptr);
+ if(ecode < 0 && inbufptr == 8
+ && strncmp((const char*)uip.inbuf, "=IPA", 4) == 0) {
+ static struct in_addr ipa;
+
+ inbufptr = 0;
+ if(memcmp(&ipa, &uip.inbuf[4], sizeof(ipa)) == 0) {
+ break;
+ }
+
+ memcpy(&ipa, &uip.inbuf[4], sizeof(ipa));
+ break;
+ } else if(ecode < 0) {
+ /*
+ * If sensible ASCII string, print it as debug info!
+ */
+ /* printf("----------------------------------\n");*/
+ if(uip.inbuf[0] == DEBUG_LINE_MARKER) {
+ fwrite(uip.inbuf + 1, inbufptr - 1, 1, stderr);
+ } else if(is_sensible_string(uip.inbuf, inbufptr)) {
+ fwrite(uip.inbuf, inbufptr, 1, stderr);
+ } else {
+ fprintf(stderr, "serial_to_wpcap: drop packet len=%d ecode=%d\n",
+ inbufptr, ecode);
+ }
+ inbufptr = 0;
+ break;
+ }
+ PROGRESS("s");
+
+ if(send_eth) {
+ raw_send(uip.inbuf, inbufptr);
+ } else {
+ /* printf("Sending to wpcap\n");*/
+ if(uip.iphdr.ip_id != last_id) {
+ last_id = uip.iphdr.ip_id;
+ print_packet("to wpcap: ", uip.inbuf, inbufptr);
+ wpcap_send(uip.inbuf, inbufptr);
+ } else {
+ /*print_packet("IGNORED to wpcap: ", uip.inbuf, inbufptr);*/
+ }
+ }
+ /* printf("After sending to wpcap\n");*/
+ inbufptr = 0;
+ }
+ break;
+
+ case SLIP_ESC:
+ /* TODO We do not actually check that we have another byte incoming, so
+ * we may block here */
+ read(STDIN_FILENO, &c, 1);
+
+ switch (c) {
+ case SLIP_ESC_END:
+ c = SLIP_END;
+ break;
+ case SLIP_ESC_ESC:
+ c = SLIP_ESC;
+ break;
+ }
+
+ /* FALLTHROUGH */
+ default:
+ uip.inbuf[inbufptr++] = c;
+ break;
+ }
+}
+/*---------------------------------------------------------------------------*/
+unsigned char stdout_buf[2000];
+int stdout_buf_cnt;
+/*---------------------------------------------------------------------------*/
+void
+stdout_write(unsigned char c)
+{
+ if(stdout_buf_cnt >= sizeof(stdout_buf)) {
+ err(1, "stdout_write overflow");
+ }
+ stdout_buf[stdout_buf_cnt] = c;
+ stdout_buf_cnt++;
+}
+/*---------------------------------------------------------------------------*/
+int
+stdout_buf_empty(void)
+{
+ return stdout_buf_cnt == 0;
+}
+/*---------------------------------------------------------------------------*/
+void
+stdout_flushbuf(void)
+{
+ if(stdout_buf_empty()) {
+ return;
+ }
+
+ fwrite(stdout_buf, stdout_buf_cnt, 1, stdout);
+ stdout_buf_cnt = 0;
+ fflush(stdout);
+}
+/*---------------------------------------------------------------------------*/
+void
+write_slip_stdout(void *inbuf, int len)
+{
+ u_int8_t *p = inbuf;
+ int i, ecode;
+ struct ip *iphdr = inbuf;
+
+ if(!send_eth) {
+ /*
+ * Sanity checks.
+ */
+ /*fprintf(stderr, "write_slip_stdout: %d\n", len);*/
+ ecode = check_ip(inbuf, len);
+ if(ecode < 0) {
+ fprintf(stderr, "write_slip_stdout: drop packet %d\n", ecode);
+ return;
+ }
+
+ if(iphdr->ip_id == 0 && iphdr->ip_off & IP_DF) {
+ uint16_t nid = uip_htons(ip_id++);
+ iphdr->ip_id = nid;
+ nid = ~nid; /* negate */
+ iphdr->ip_sum += nid; /* add */
+ if(iphdr->ip_sum < nid) { /* 1-complement overflow? */
+ iphdr->ip_sum++;
+ }
+ ecode = check_ip(inbuf, len);
+ if(ecode < 0) {
+ fprintf(stderr, "write_slip_stdout: drop packet %d\n", ecode);
+ return;
+ }
+ }
+
+ iphdr->ip_ttl = uip_htons(uip_htons(iphdr->ip_ttl) + 1);
+ if(iphdr->ip_ttl == 0) {
+ fprintf(stderr, "Packet with ttl %d dropped\n", iphdr->ip_ttl);
+ return;
+ }
+ iphdr->ip_sum = 0;
+ iphdr->ip_sum = ~chksum(iphdr, 4 * (iphdr->ip_vhl & IP_HL));
+ ecode = check_ip(inbuf, len);
+ if(ecode < 0) {
+ fprintf(stderr, "write_slip_stdout: drop packet %d\n", ecode);
+ return;
+ }
+ }
+
+ for(i = 0; i < len; i++) {
+ switch (p[i]) {
+ case SLIP_END:
+ stdout_write(SLIP_ESC);
+ stdout_write(SLIP_ESC_END);
+ break;
+ case SLIP_ESC:
+ stdout_write(SLIP_ESC);
+ stdout_write(SLIP_ESC_ESC);
+ break;
+ default:
+ stdout_write(p[i]);
+ break;
+ }
+ }
+ stdout_write(SLIP_END);
+ /* printf("slip end\n");*/
+ PROGRESS("t");
+}
+/*---------------------------------------------------------------------------*/
+/*const char *ipaddr;*/
+/*const char *netmask;*/
+static int got_sigalarm;
+void
+sigalarm(int signo)
+{
+ got_sigalarm = 1;
+ return;
+}
+/*---------------------------------------------------------------------------*/
+void
+sigalarm_reset(void)
+{
+#ifdef linux
+#define TIMEOUT (997*1000)
+#else
+#define TIMEOUT (2451*1000)
+#endif
+ ualarm(TIMEOUT, TIMEOUT);
+ got_sigalarm = 0;
+}
+/*---------------------------------------------------------------------------*/
+int
+main(int argc, char **argv)
+{
+ int c;
+ int ret;
+ char buf[4000];
+ int logging = 0;
+
+ ip_id = getpid() * time(NULL);
+
+ while((c = getopt(argc, argv, "E:D:hl:t:T")) != -1) {
+ switch (c) {
+ case 'E':
+ send_eth = 1;
+ break;
+
+ case 'T':
+ should_print = 1;
+ break;
+
+ case 'l':
+ logging = 1;
+ break;
+
+ case '?':
+ case 'h':
+ default:
+ err(1,
+ "usage: wpcapstdio [-E] [-l] [-T] ");
+ break;
+ }
+ }
+ argc -= (optind - 1);
+ argv += (optind - 1);
+
+ if(argc != 4) {
+ err(1, "usage: wpcapstdio [-E] [-T] ");
+ }
+
+ wpcap_start(argv[1], argv[2], argv[3], logging);
+ stdout_write(SLIP_END);
+
+ atexit(cleanup);
+ signal(SIGHUP, sigcleanup);
+ signal(SIGTERM, sigcleanup);
+ signal(SIGINT, sigcleanup);
+ signal(SIGALRM, sigalarm);
+
+ while(1) {
+ if(got_sigalarm) {
+ /* Send "?IPA". */
+ stdout_write('?');
+ stdout_write('I');
+ stdout_write('P');
+ stdout_write('A');
+ stdout_write(SLIP_END);
+ got_sigalarm = 0;
+ }
+
+ if(stdout_buf_empty()) {
+ char *pbuf = buf;
+
+ ret = wpcap_poll(&pbuf, send_eth);
+ if(ret > 0) {
+ if(send_eth) {
+ write_slip_stdout(pbuf, ret);
+ stdout_flushbuf();
+ } else {
+ struct ip *iphdr = (struct ip *)pbuf;
+ if(iphdr->ip_id != last_id) {
+ /*last_id = iphdr->ip_id;*/
+ print_packet("to stdout: ", (uint8_t*)pbuf, ret);
+ write_slip_stdout(pbuf, ret);
+ stdout_flushbuf();
+ } else {
+ /*print_packet("IGNORED to stdout: ", (uint8_t*)pbuf, ret);*/
+ }
+ }
+ }
+ }
+
+ if(!stdout_buf_empty()) {
+ stdout_flushbuf();
+ }
+
+ {
+ fd_set s_rd;
+ struct timeval tv;
+
+ tv.tv_sec = 0;
+ tv.tv_usec = 100;
+
+ do {
+ FD_ZERO(&s_rd);
+ FD_SET(fileno(stdin), &s_rd);
+ select(fileno(stdin) + 1, &s_rd, NULL, NULL, &tv);
+ if(FD_ISSET(fileno(stdin), &s_rd)) {
+ serial_to_wpcap();
+ }
+ } while(FD_ISSET(fileno(stdin), &s_rd));
+ }
+ }
+}
+/*---------------------------------------------------------------------------*/