]> rtime.felk.cvut.cz Git - sysless.git/commitdiff
Added .gitignore
authorMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 21 Mar 2008 15:36:24 +0000 (16:36 +0100)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 21 Mar 2008 15:36:24 +0000 (16:36 +0100)
72 files changed:
.gitignore [new file with mode: 0644]
.gitmodules [deleted file]
common [deleted submodule]
common/Doxyfile [new file with mode: 0644]
common/Makefile [new file with mode: 0644]
common/Makefile.omk [new file with mode: 0644]
common/Makefile.rules [new file with mode: 0644]
common/README.makerules [new file with mode: 0644]
common/app/Makefile [new file with mode: 0644]
common/app/Makefile.omk [new file with mode: 0644]
common/arch/Makefile [new file with mode: 0644]
common/arch/Makefile.omk [new file with mode: 0644]
common/arch/generic/Makefile [new file with mode: 0644]
common/arch/generic/Makefile.omk [new file with mode: 0644]
common/arch/generic/defines/Makefile [new file with mode: 0644]
common/arch/generic/defines/Makefile.omk [new file with mode: 0644]
common/arch/generic/defines/byteswap.h [new file with mode: 0644]
common/arch/generic/defines/endian.h [new file with mode: 0644]
common/board/Makefile [new file with mode: 0644]
common/board/Makefile.omk [new file with mode: 0644]
common/doc/TODO [new file with mode: 0644]
common/doc/documentation.xml [new file with mode: 0644]
common/doc/doxygen.css [new file with mode: 0644]
common/libs4c/Makefile [new file with mode: 0644]
common/libs4c/Makefile.omk [new file with mode: 0644]
common/libs4c/cmdproc/Makefile [new file with mode: 0644]
common/libs4c/cmdproc/Makefile.omk [new file with mode: 0644]
common/libs4c/cmdproc/README [new file with mode: 0644]
common/libs4c/cmdproc/cmd_bth.h [new file with mode: 0644]
common/libs4c/cmdproc/cmd_io.c [new file with mode: 0644]
common/libs4c/cmdproc/cmd_io_line.c [new file with mode: 0644]
common/libs4c/cmdproc/cmd_proc.c [new file with mode: 0644]
common/libs4c/cmdproc/cmd_proc.h [new file with mode: 0644]
common/libs4c/cmdproc/cmd_proc_priv.h [new file with mode: 0644]
common/libs4c/cmdproc/cmdio_std.c [new file with mode: 0644]
common/libs4c/cmdproc/cmdio_std.h [new file with mode: 0644]
common/libs4c/cmdproc/cmdio_std_line.c [new file with mode: 0644]
common/libs4c/cmdproc/cmdproc_test.c [new file with mode: 0644]
common/libs4c/cmdprocio/Makefile [new file with mode: 0644]
common/libs4c/cmdprocio/Makefile.omk [new file with mode: 0644]
common/libs4c/cmdprocio/cmdio_bth.c [new file with mode: 0644]
common/libs4c/cmdprocio/cmdio_bth_line.c [new file with mode: 0644]
common/libs4c/cmdprocio/cmdio_rs232.c [new file with mode: 0644]
common/libs4c/cmdprocio/cmdio_rs232_line.c [new file with mode: 0644]
common/libs4c/misc/Makefile [new file with mode: 0644]
common/libs4c/misc/Makefile.omk [new file with mode: 0644]
common/libs4c/misc/utils.c [new file with mode: 0644]
common/libs4c/misc/utils.h [new file with mode: 0644]
common/libs4c/usb/Makefile [new file with mode: 0644]
common/libs4c/usb/Makefile.omk [new file with mode: 0644]
common/libs4c/usb/base/Makefile [new file with mode: 0644]
common/libs4c/usb/base/Makefile.omk [new file with mode: 0644]
common/libs4c/usb/base/usb.c [new file with mode: 0644]
common/libs4c/usb/base/usb/usb.h [new file with mode: 0644]
common/libs4c/usb/base/usb/usb_spec.h [new file with mode: 0644]
common/libs4c/usb/base/usb/usb_stdreq.h [new file with mode: 0644]
common/libs4c/usb/base/usb/usbdebug.h [new file with mode: 0644]
common/libs4c/usb/base/usbdebug.c [new file with mode: 0644]
common/libs4c/usb/more/Makefile [new file with mode: 0644]
common/libs4c/usb/more/Makefile.omk [new file with mode: 0644]
common/libs4c/usb/more/usb/usb_defs.h [new file with mode: 0644]
common/libs4c/usb/more/usb/usb_loader.h [new file with mode: 0644]
common/libs4c/usb/more/usb_loader.c [new file with mode: 0644]
common/libs4c/usb/more/usb_stdreq.c [new file with mode: 0644]
common/libs4c/usb/pdiusb/Makefile [new file with mode: 0644]
common/libs4c/usb/pdiusb/Makefile.omk [new file with mode: 0644]
common/libs4c/usb/pdiusb/pdi.c [new file with mode: 0644]
common/libs4c/usb/pdiusb/pdi4rtems.c [new file with mode: 0644]
common/libs4c/usb/pdiusb/pdiusb.c [new file with mode: 0644]
common/libs4c/usb/pdiusb/usb/pdi.h [new file with mode: 0644]
common/libs4c/usb/pdiusb/usb/pdiusb.h [new file with mode: 0644]
common/linkarch [new file with mode: 0755]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..206a1a5
--- /dev/null
@@ -0,0 +1,24 @@
+_build
+_compiled
+config.omk
+config.omk-default
+Makefile.rules
+doc
+arch/generic
+arch/Makefile.omk
+arch/Makefile
+app/Makefile.omk
+app/Makefile
+README.makerules
+Doxyfile
+linkarch
+Makefile.omk
+board/Makefile.omk
+board/Makefile
+Makefile
+libs4c/usb
+libs4c/misc
+libs4c/Makefile.omk
+libs4c/cmdproc
+libs4c/cmdprocio
+libs4c/Makefile
diff --git a/.gitmodules b/.gitmodules
deleted file mode 100644 (file)
index 1f68022..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-[submodule "common"]
-       path = common
-       url = git://rtime.felk.cvut.cz/sysless-common.git
diff --git a/common b/common
deleted file mode 160000 (submodule)
index ac35209..0000000
--- a/common
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit ac352093650d553235e184cb77792a48fac7a0b5
diff --git a/common/Doxyfile b/common/Doxyfile
new file mode 100644 (file)
index 0000000..d173c6c
--- /dev/null
@@ -0,0 +1,275 @@
+# Doxyfile 1.4.6
+
+#---------------------------------------------------------------------------
+# Project related configuration options
+#---------------------------------------------------------------------------
+PROJECT_NAME           = h8300-boot
+PROJECT_NUMBER         = 
+OUTPUT_DIRECTORY       = ./doc/
+CREATE_SUBDIRS         = NO
+OUTPUT_LANGUAGE        = English
+USE_WINDOWS_ENCODING   = NO
+BRIEF_MEMBER_DESC      = YES
+REPEAT_BRIEF           = YES
+ABBREVIATE_BRIEF       = "The $name class" \
+                         "The $name widget" \
+                         "The $name file" \
+                         is \
+                         provides \
+                         specifies \
+                         contains \
+                         represents \
+                         a \
+                         an \
+                         the
+ALWAYS_DETAILED_SEC    = NO
+INLINE_INHERITED_MEMB  = NO
+FULL_PATH_NAMES        = YES
+STRIP_FROM_PATH        = 
+STRIP_FROM_INC_PATH    = 
+SHORT_NAMES            = NO
+JAVADOC_AUTOBRIEF      = YES
+MULTILINE_CPP_IS_BRIEF = NO
+DETAILS_AT_TOP         = NO
+INHERIT_DOCS           = YES
+SEPARATE_MEMBER_PAGES  = NO
+TAB_SIZE               = 7
+ALIASES                = 
+OPTIMIZE_OUTPUT_FOR_C  = YES
+OPTIMIZE_OUTPUT_JAVA   = NO
+BUILTIN_STL_SUPPORT    = NO
+DISTRIBUTE_GROUP_DOC   = NO
+SUBGROUPING            = YES
+#---------------------------------------------------------------------------
+# Build related configuration options
+#---------------------------------------------------------------------------
+EXTRACT_ALL            = YES
+EXTRACT_PRIVATE        = YES
+EXTRACT_STATIC         = YES
+EXTRACT_LOCAL_CLASSES  = YES
+EXTRACT_LOCAL_METHODS  = NO
+HIDE_UNDOC_MEMBERS     = NO
+HIDE_UNDOC_CLASSES     = NO
+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       = YES
+GENERATE_DEPRECATEDLIST= YES
+ENABLED_SECTIONS       = 
+MAX_INITIALIZER_LINES  = 30
+SHOW_USED_FILES        = YES
+SHOW_DIRECTORIES       = YES
+FILE_VERSION_FILTER    = 
+#---------------------------------------------------------------------------
+# configuration options related to warning and progress messages
+#---------------------------------------------------------------------------
+QUIET                  = NO
+WARNINGS               = YES
+WARN_IF_UNDOCUMENTED   = YES
+WARN_IF_DOC_ERROR      = YES
+WARN_NO_PARAMDOC       = NO
+WARN_FORMAT            = "$file:$line: $text"
+WARN_LOGFILE           = 
+#---------------------------------------------------------------------------
+# configuration options related to the input files
+#---------------------------------------------------------------------------
+INPUT                  = 
+FILE_PATTERNS          = *.c \
+                         *.cc \
+                         *.cxx \
+                         *.cpp \
+                         *.c++ \
+                         *.d \
+                         *.java \
+                         *.ii \
+                         *.ixx \
+                         *.ipp \
+                         *.i++ \
+                         *.inl \
+                         *.h \
+                         *.hh \
+                         *.hxx \
+                         *.hpp \
+                         *.h++ \
+                         *.idl \
+                         *.odl \
+                         *.cs \
+                         *.php \
+                         *.php3 \
+                         *.inc \
+                         *.m \
+                         *.mm \
+                         *.dox \
+                         *.py \
+                         *.C \
+                         *.CC \
+                         *.C++ \
+                         *.II \
+                         *.I++ \
+                         *.H \
+                         *.HH \
+                         *.H++ \
+                         *.CS \
+                         *.PHP \
+                         *.PHP3 \
+                         *.M \
+                         *.MM \
+                         *.PY
+RECURSIVE              = YES
+EXCLUDE                = ./_darcs/ \
+                         ./_compiled/ \
+                         ./_build/
+EXCLUDE_SYMLINKS       = NO
+EXCLUDE_PATTERNS       = 
+EXAMPLE_PATH           = 
+EXAMPLE_PATTERNS       = *
+EXAMPLE_RECURSIVE      = NO
+IMAGE_PATH             = 
+INPUT_FILTER           = 
+FILTER_PATTERNS        = 
+FILTER_SOURCE_FILES    = NO
+#---------------------------------------------------------------------------
+# configuration options related to source browsing
+#---------------------------------------------------------------------------
+SOURCE_BROWSER         = YES
+INLINE_SOURCES         = NO
+STRIP_CODE_COMMENTS    = YES
+REFERENCED_BY_RELATION = YES
+REFERENCES_RELATION    = YES
+USE_HTAGS              = NO
+VERBATIM_HEADERS       = YES
+#---------------------------------------------------------------------------
+# configuration options related to the alphabetical class index
+#---------------------------------------------------------------------------
+ALPHABETICAL_INDEX     = NO
+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        = doc/doxygen.css
+HTML_ALIGN_MEMBERS     = YES
+GENERATE_HTMLHELP      = NO
+CHM_FILE               = 
+HHC_LOCATION           = 
+GENERATE_CHI           = NO
+BINARY_TOC             = NO
+TOC_EXPAND             = NO
+DISABLE_INDEX          = NO
+ENUM_VALUES_PER_LINE   = 4
+GENERATE_TREEVIEW      = NO
+TREEVIEW_WIDTH         = 250
+#---------------------------------------------------------------------------
+# configuration options related to the LaTeX output
+#---------------------------------------------------------------------------
+GENERATE_LATEX         = NO
+LATEX_OUTPUT           = latex
+LATEX_CMD_NAME         = latex
+MAKEINDEX_CMD_NAME     = makeindex
+COMPACT_LATEX          = NO
+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             = 
+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         = YES
+HIDE_UNDOC_RELATIONS   = YES
+HAVE_DOT               = NO
+CLASS_GRAPH            = YES
+COLLABORATION_GRAPH    = YES
+GROUP_GRAPHS           = YES
+UML_LOOK               = NO
+TEMPLATE_RELATIONS     = NO
+INCLUDE_GRAPH          = YES
+INCLUDED_BY_GRAPH      = YES
+CALL_GRAPH             = YES
+GRAPHICAL_HIERARCHY    = YES
+DIRECTORY_GRAPH        = YES
+DOT_IMAGE_FORMAT       = png
+DOT_PATH               = 
+DOTFILE_DIRS           = 
+MAX_DOT_GRAPH_WIDTH    = 1024
+MAX_DOT_GRAPH_HEIGHT   = 1024
+MAX_DOT_GRAPH_DEPTH    = 1000
+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/common/Makefile b/common/Makefile
new file mode 100644 (file)
index 0000000..f595272
--- /dev/null
@@ -0,0 +1,14 @@
+# Generic directory or leaf node makefile for OCERA make framework
+
+ifndef MAKERULES_DIR
+MAKERULES_DIR := $(shell ( old_pwd="" ;  while [ ! -e Makefile.rules ] ; do if [ "$$old_pwd" == `pwd`  ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) )
+endif
+
+ifeq ($(MAKERULES_DIR),)
+all : default
+.DEFAULT::
+       @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
+else   
+include $(MAKERULES_DIR)/Makefile.rules
+endif
+
diff --git a/common/Makefile.omk b/common/Makefile.omk
new file mode 100644 (file)
index 0000000..a295830
--- /dev/null
@@ -0,0 +1,3 @@
+# -*- makefile -*-
+
+SUBDIRS = $(filter-out common,$(ALL_OMK_SUBDIRS))
diff --git a/common/Makefile.rules b/common/Makefile.rules
new file mode 100644 (file)
index 0000000..7522733
--- /dev/null
@@ -0,0 +1,902 @@
+#                   Version for system-less builds.          #OMK@sysless
+#
+#  Makefile.rules - OCERA make framework common project rules -*- makefile -*- #OMK@base
+#
+#  (C) Copyright 2003 by Pavel Pisa - OCERA team member
+#  (C) Copyright 2006 by Michal Sojka - Czech Technical University, FEE, DCE
+#
+#  Homepage: http://rtime.felk.cvut.cz/omk/
+#
+# The OMK build system is distributed under the GNU General Public
+# License.  See file COPYING for details.
+#
+# input variables
+# V                .. if set to 1, full command text is shown else short form is used
+# W                .. whole tree - if set to 1, make is always called from the top-level directory
+# SUBDIRS          .. list of subdirectories intended for make from actual directory
+# default_CONFIG   .. list of default config assignments CONFIG_XXX=y/n ...
+# LN_HEADERS       .. if "y", header files are symbolicaly linked instead of copied. #OMK@include
+#                                                            #OMK@sysless
+# bin_PROGRAMS     .. list of the require binary programs
+# test_PROGRAMS    .. list of the test programs
+# include_HEADERS  .. list of the user-space public header files
+# lib_LIBRARIES    .. list of the user-space libraries
+# lib_LDSCRIPTS    .. list of LD scripts that should be copied to the lib direcotry
+# lib_obj_SOURCES  .. list of source files which should be compiled and
+#                    the produced object file placed to the lib directory (e.g. crt0.S)
+# shared_LIBRARIES .. list of the user-space shared libraries
+# nobase_include_HEADERS .. public headers copied even with directory part
+# renamed_include_HEADERS .. public headers copied to the different target name (xxx.h->yyy.h)
+# utils_PROGRAMS   .. list of the development utility programs (compiled for host computer, this might change in future)
+# xxx_SOURCES      .. list of specific target sources
+# xxx_LIBS         .. list of specific target libraries
+# INCLUDES         .. additional include directories and defines for user-space
+# lib_LOADLIBES    .. list of libraries linked to each executable
+# link_VARIANTS    .. list of ld script suffixes (after hypen `-') that
+#                     should be used for linking (e.g. ram flash). If this is not
+#                    specified, then the value of DEFAULT_LD_SCRIPT_VARIANT from config.target is used.
+# PREFIX_DIR       .. Prefix to  directories in _compiled and _build. Used in config.omk.
+# LOCAL_CONFIG_H   .. name of local config.h file generated from values #OMK@config_h
+#                     of options defined in the current directory
+# config_include_HEADERS .. names of global config files (possibly
+#                     with subdirectories)
+# xxx_DEFINES      .. list of config directives to be included in
+#                     config header file of the name <somedir>/xxx.h
+# DOXYGEN          .. if non-empty, generated headers includes Doxygen's @file
+#                    command, so it is possible to document config
+#                    variables.
+# local_EVALUATE   .. Makefile hook, which is executed at the end of #OMK@localeval
+#                     the Makefile.rules. Used only for dirty hacks.
+                                                             #OMK@sysless-setup
+-include $(MAKERULES_DIR)/config.target
+
+BUILD_DIR_NAME = _build$(addprefix /,$(PREFIX_DIR))
+COMPILED_DIR_NAME = _compiled$(addprefix /,$(PREFIX_DIR))
+
+LOCAL_BUILD_DIR=$(MAKERULES_DIR)/$(BUILD_DIR_NAME)/$(RELATIVE_DIR)
+#$(warning LOCAL_BUILD_DIR = $(LOCAL_BUILD_DIR))
+
+#=====================================================================
+# Common utility rules
+
+link_VARIANTS ?= $(DEFAULT_LD_SCRIPT_VARIANT)
+
+
+#=====================================================================
+# Include correct rules for just running pass
+
+USER_COMPILED_DIR_NAME=$(MAKERULES_DIR)/$(COMPILED_DIR_NAME)
+
+USER_INCLUDE_DIR = $(USER_COMPILED_DIR_NAME)/include
+USER_LIB_DIR     = $(USER_COMPILED_DIR_NAME)/lib
+USER_UTILS_DIR   = $(USER_COMPILED_DIR_NAME)/bin-utils
+USER_TESTS_DIR   = $(USER_COMPILED_DIR_NAME)/bin-tests
+USER_BIN_DIR     = $(USER_COMPILED_DIR_NAME)/bin
+USER_OBJS_DIR    = $(LOCAL_BUILD_DIR)
+
+# Local Variables:
+# mode:makefile
+# End:
+                                                             #OMK@base
+# We need to ensure definition of sources directory first
+ifndef SOURCES_DIR
+SOURCES_DIR := $(shell ( pwd -L ) )
+endif
+
+.PHONY: all default check-make-ver omkize
+
+ifdef W
+  ifeq ("$(origin W)", "command line")
+    OMK_WHOLE_TREE:=$(W)
+  endif
+endif
+ifndef OMK_WHOLE_TREE
+  OMK_WHOLE_TREE:=0
+endif
+
+ifneq ($(OMK_WHOLE_TREE),1)
+all: check-make-ver default
+       @echo "Compilation finished"
+else
+# Run make in the top-level directory
+all:
+       @$(MAKE) -C $(MAKERULES_DIR) OMK_SERIALIZE_INCLUDED=n SOURCES_DIR=$(MAKERULES_DIR) RELATIVE_DIR="" $(MAKECMDGOALS) W=0
+endif
+
+#=========================
+# Include the config file
+
+ifneq ($(CONFIG_FILE_OK),y)
+ifndef CONFIG_FILE
+CONFIG_FILE      := $(MAKERULES_DIR)/config.omk
+endif
+ifneq ($(wildcard $(CONFIG_FILE)-default),)
+-include $(CONFIG_FILE)-default
+else
+ifneq ($(MAKECMDGOALS),default-config)
+$(warning Please, run "make default-config" first)
+endif
+endif
+
+ifneq ($(wildcard $(CONFIG_FILE)),)
+include $(CONFIG_FILE)
+CONFIG_FILE_OK = y
+endif
+endif #$(CONFIG_FILE_OK)
+
+export SOURCES_DIR MAKERULES_DIR RELATIVE_DIR
+export CONFIG_FILE OMK_SERIALIZE_INCLUDED OMK_VERBOSE OMK_SILENT
+# OMK_SERIALIZE_INCLUDED has to be exported to submakes because passes
+# must to be serialized only in the toplevel make.
+
+ifndef RELATIVE_DIR
+RELATIVE_DIR := $(SOURCES_DIR:$(MAKERULES_DIR)%=%)
+endif
+#$(warning  === RELATIVE_DIR = "$(RELATIVE_DIR)" ===)
+override RELATIVE_DIR := $(RELATIVE_DIR:/%=%)
+override RELATIVE_DIR := $(RELATIVE_DIR:\\%=%)
+#$(warning  RELATIVE_DIR = "$(RELATIVE_DIR)")
+override BACK2TOP_DIR := $(shell echo $(RELATIVE_DIR)/ | sed -e 's_//_/_g' -e 's_/\./_/_g' -e 's_^\./__g'  -e 's_\([^/][^/]*\)_.._g' -e 's_/$$__')
+#$(warning  BACK2TOP_DIR = "$(BACK2TOP_DIR)")
+
+#$(warning SOURCES_DIR = "$(SOURCES_DIR)")
+#$(warning MAKERULES_DIR = "$(MAKERULES_DIR)")
+#$(warning RELATIVE_DIR = "$(RELATIVE_DIR)")
+
+# We have to use RELATIVE_PREFIX because of mingw
+override RELATIVE_PREFIX := $(RELATIVE_DIR)/
+override RELATIVE_PREFIX := $(RELATIVE_PREFIX:/%=%)
+
+#vpath %.c $(SOURCES_DIR)
+#vpath %.cc $(SOURCES_DIR)
+#vpath %.cxx $(SOURCES_DIR)
+
+VPATH = $(SOURCES_DIR)
+srcdir = $(SOURCES_DIR)
+
+# Defines for quiet compilation
+ifdef V
+  ifeq ("$(origin V)", "command line")
+    OMK_VERBOSE = $(V)
+  endif
+endif
+ifndef OMK_VERBOSE
+  OMK_VERBOSE = 0
+endif
+ifneq ($(OMK_VERBOSE),0)
+  Q =
+else
+  Q = @
+endif
+ifneq ($(findstring s,$(MAKEFLAGS)),)
+  QUIET_CMD_ECHO = true
+  OMK_SILENT = 1
+else
+  QUIET_CMD_ECHO = echo
+endif
+
+MAKEFILE_OMK=Makefile.omk
+# All subdirectories (even linked ones) containing Makefile.omk
+# Usage in Makefile.omk: SUBDIRS = $(ALL_OMK_SUBDIRS)
+ALL_OMK_SUBDIRS = $(patsubst %/$(MAKEFILE_OMK),%,$(patsubst $(SOURCES_DIR)/%,%,$(wildcard $(SOURCES_DIR)/*/$(MAKEFILE_OMK))))
+
+# ===================================================================
+# We have set up all important variables, so we can check and include
+# real OCERA style Makefile.omk now
+ifndef OMK_INCLUDED
+include $(SOURCES_DIR)/$(MAKEFILE_OMK)
+OMK_INCLUDED := 1
+endif
+
+check-make-ver:
+       @GOOD_MAKE_VERSION=`echo $(MAKE_VERSION) | sed -n -e 's/^[4-9]\..*\|^3\.9[0-9].*\|^3\.8[1-9].*/y/p'` ; \
+       if [ x$$GOOD_MAKE_VERSION != xy ] ; then \
+               echo "Your make program version is too old and does not support OMK system." ; \
+               echo "Please update to make program 3.81beta1 or newer." ; exit 1 ; \
+       fi
+
+distclean dist-clean:
+       @$(QUIET_CMD_ECHO) "  RM      $(COMPILED_DIR_NAME) $(BUILD_DIR_NAME)"
+       @rm -fr $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)  $(MAKERULES_DIR)/$(BUILD_DIR_NAME)
+
+# Common OMK templates
+# ====================
+
+# Syntax: $(call mkdir,<dir name>)
+define mkdir_def
+       [ -d $(1) ] || mkdir -p $(1) || exit 1
+endef
+
+ifneq ($(V),2)
+NO_PRINT_DIRECTORY := --no-print-directory
+endif
+
+# Syntax: $(call omk_pass_template,<pass name>,<build dir>,[<local make flags>],[<local condition>])
+define omk_pass_template
+.PHNOY: $(1) $(1)-local
+$(1):
+       +@$(foreach dir,$(SUBDIRS),$(call mkdir_def,$(2)/$(dir)); \
+               $(MAKE) SOURCES_DIR=$(SOURCES_DIR)/$(dir) $(NO_PRINT_DIRECTORY) \
+               RELATIVE_DIR=$(RELATIVE_PREFIX)$(dir) -C $(2)/$(dir) \
+               -f $(SOURCES_DIR)/$(dir)/Makefile $$@ || exit 1 ;) true
+ifneq ($(4),)
+       @echo "make[omk]: $$@ in $(RELATIVE_DIR)"; \
+       $(call mkdir_def,$(2)); \
+       $(MAKE) $(NO_PRINT_DIRECTORY) SOURCES_DIR=$(SOURCES_DIR) RELATIVE_DIR=$(RELATIVE_DIR) -C $(2) \
+               -f $(SOURCES_DIR)/Makefile $(3) $$(@:%=%-local)
+endif
+endef
+
+# =======================
+# DEFAULT CONFIG PASS
+
+default-config:
+       @echo "# Start of OMK config file" > "$(CONFIG_FILE)-default"
+       @echo "# This file should not be altered manually" >> "$(CONFIG_FILE)-default"
+       @echo "# Overrides should be stored in file $(notdir $(CONFIG_FILE))" >> "$(CONFIG_FILE)-default"
+       @echo >> "$(CONFIG_FILE)-default"
+       @$(MAKE) $(NO_PRINT_DIRECTORY) -C $(MAKERULES_DIR) \
+               RELATIVE_DIR="" SOURCES_DIR=$(MAKERULES_DIR) \
+               -f $(MAKERULES_DIR)/Makefile default-config-pass
+
+$(eval $(call omk_pass_template,default-config-pass,$$(LOCAL_BUILD_DIR),,always))
+
+default-config-pass-local:
+#      @echo Default config for $(RELATIVE_DIR)
+       @echo "# Config for $(RELATIVE_DIR)" >> "$(CONFIG_FILE)-default"
+       @$(foreach x, $(default_CONFIG), echo '$(x)' | \
+               sed -e 's/^[^=]*=x$$/#\0/' >> "$(CONFIG_FILE)-default" ; )
+
+
+omkize:
+       $(Q)if ! grep -q MAKERULES_DIR Makefile; then \
+          echo "Makefile is not OMK leaf makefile!" >&2; exit 1; \
+       fi
+       $(Q)for i in `find -L . -name Makefile.omk` ; do \
+          i=`dirname $${i}`; \
+          if [ x"$$i" != x"." ]; then \
+             rm -f $${i}/Makefile; \
+             cp Makefile $${i}/Makefile; \
+          fi \
+       done
+                                                             #OMK@gcc
+# Rules for compilation of C, C++ and assembler sources using GNU
+# toolchain.
+
+# Interface to other rules:
+
+# Input variables:
+# LIB_DIR - directory where compiled libraries are stored
+# OBJS_DIR - directory where intermediate files (.o, .map, ...) are stored
+# INCLUDE_DIR - where includes can be found
+# from config.omk or Makefile.omk
+# CROSS_COMPILE - 
+# TARGET_ARCH, DEBUG, OPTIMIZE, DEFS - forms CFLAGS
+# from base: SOURCES_DIR
+# from Makefile.omk: lib_LOADLIBES
+
+# Output variables:
+# SOURCES - all the source files that needs to be compiled (except for shared library sources)
+# SOLIB_SOURCES - all the source files that needs to be compiled for a shared library
+# OBJ_EXT - extension of object files
+# LIB_EXT - extension of library files
+# LIB_PREF - prefix for library files
+# ASM_EXT - extension of assembler sources
+
+# Templates:
+# COMPILER_DEFS_template - definitions that should be defined before
+# the following templates can be used. The input variables needs to be
+# defined before evaluating this template
+
+# COMPILE_c_o_template, COMPILE_cc_o_template, COMPILE_S_o_template -
+# templates that create rules for compilation of sources
+
+# CMETRIC_o_h_template - FIXME
+
+# PROGRAM_template, LIBRARY_template, SOLIB_template - templates that
+# create rules for compilation of a program, library and shared
+# library. The rules can use rules produced by COMPILE_xxx_template.
+
+define COMPILER_DEFS_template
+OBJ_EXT = .o
+LIB_EXT = .a
+LIB_PREF = lib
+ASM_EXT = .S
+
+CC = $(CROSS_COMPILE)gcc
+LINK = $(CROSS_COMPILE)ld
+AR = $(CROSS_COMPILE)ar
+OBJCOPY = $(CROSS_COMPILE)objcopy
+NM = $(CROSS_COMPILE)nm
+
+CFLAGS += $(TARGET_ARCH) $(DEBUG) $(OPTIMIZE)
+CFLAGS += -Wall
+CFLAGS += -I$(SOURCES_DIR)
+CFLAGS += -I$(INCLUDE_DIR)
+
+LOADLIBES += -L$(LIB_DIR)
+LOADLIBES += $(lib_LOADLIBES:%=-l%)
+
+
+-include $(OBJS_DIR)/*.d
+
+#%.lo: %.c
+#      $(CC) -o $@ $(LCFLAGS) -c $<
+
+c_o_COMPILE = $$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+       $(CPPFLAGS) $(AM_CFLAGS) $$(CFLAGS)
+
+cc_o_COMPILE = $$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+       $(CPPFLAGS) $(AM_CFLAGS) $$(CFLAGS)
+
+S_o_COMPILE = $$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+       $(CPPFLAGS) $(AM_CFLAGS) $$(CFLAGS) $(ASFLAGS)
+
+
+# Check GCC version for user build
+ifndef CC_MAJOR_VERSION
+CC_MAJOR_VERSION = $$(shell $$(CC) -dumpversion | sed -e 's/\([^.]\)\..*/\1/')
+endif
+# Prepare suitable define for dependency building
+ifeq ($$(CC_MAJOR_VERSION),2)
+CC_DEPFLAGS = -Wp,-MD,"$$@.d.tmp"
+else
+CC_DEPFLAGS = -MT $$@ -MD -MP -MF "$$@.d.tmp"
+endif
+
+endef # COMPILER_DEFS_template
+
+
+# Syntax: $(call COMPILE_c_o_template,<source>,<target>,<additional c-flags>)
+define COMPILE_c_o_template
+$(2): $(1) $$(GEN_HEADERS)
+       @$(QUIET_CMD_ECHO) "  CC      $$@"
+       $(Q) if $$(c_o_COMPILE) $$(CC_DEPFLAGS) $(3) -o $$@ -c $$< ; \
+       then mv -f "$$@.d.tmp" "$$@.d" ; \
+       else rm -f "$$@.d.tmp" ; exit 1; \
+       fi
+endef
+
+
+
+# Syntax: $(call COMPILE_cc_o_template,<source>,<target>,<additional c-flags>)
+define COMPILE_cc_o_template
+$(2): $(1) $$(GEN_HEADERS)
+       @$(QUIET_CMD_ECHO) "  CXX     $$@"
+       $(Q) if $$(cc_o_COMPILE) $$(CC_DEPFLAGS) $(3) -o $$@ -c $$< ; \
+       then mv -f "$$@.d.tmp" "$$@.d" ; \
+       else rm -f "$$@.d.tmp" ; exit 1; \
+       fi
+endef
+
+# Syntax: $(call COMPILE_S_o_template,<source>,<target>,<additional c-flags>)
+define COMPILE_S_o_template
+$(2): $(1) $$(GEN_HEADERS)
+       @$(QUIET_CMD_ECHO) "  AS      $$@"
+       $(Q) if $$(S_o_COMPILE) -D__ASSEMBLY__ $$(CC_DEPFLAGS) $(3) -o $$@ -c $$< ; \
+       then if [ -e "$$@.d.tmp" ] ; then mv -f "$$@.d.tmp" "$$@.d" ; fi ; \
+       else rm -f "$$@.d.tmp" ; exit 1; \
+       fi
+endef
+
+# Syntax: $(call CMETRIC_o_h_template,<object_file>,<target_header>)
+define CMETRIC_o_h_template
+$(2): $(1)
+       @$(QUIET_CMD_ECHO) "  CMETRIC $$@"
+       $(Q)if [ -n `dirname $$@` ] ; then \
+             if [ ! -e `dirname $$@` ] ; then \
+               mkdir -p `dirname $$@` ; fi ; fi
+       $(Q)echo >$$@ '/* Automatically generated from $$< */'
+       $(Q)echo >>$$@ '/* Conditionals to control compilation */'
+       $(Q)set -o pipefail ; $(NM) $$< \
+               | sed -n 's/^ *0*\(0[0-9A-Fa-f]*\) *A *_cmetric2cond_\([A-Za-z_0-9]*\) */#define \2 0x\1/p' \
+               | sort >>$$@
+       $(Q)echo >>$$@ '/* Defines from the values defined to symbols */'
+       $(Q)set -o pipefail ; $(NM) $$< \
+               | sed -n 's/^ *0*\(0[0-9A-Fa-f]*\) *A *_cmetric2def_\([A-Za-z_0-9]*\) */#define \2 0x\1/p' \
+               | sort >>$$@
+endef
+
+# Syntax: $(call PROGRAM_template,<executable-name>,<dir>,<link-variant>)
+define PROGRAM_template
+$(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.c=%.o))
+$(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cc=%.o))
+$(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cxx=%.o))
+$(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.S=%.o))
+$(1)_OBJS += $$(filter %.o,$(1)_SOURCES)
+$(1)_OBJS := $$(sort $$($(1)_OBJS))
+
+SOURCES += $$($(1)_SOURCES)
+
+ifneq ($(LD_SCRIPT),)
+$(1)$(3:%=-%)_LDFLAGS = -Wl,-T,$(LD_SCRIPT).ld$(3:%=-%)
+endif
+
+$(2)/$(1)$(3:%=-%): $$($(1)_OBJS)
+       @$(QUIET_CMD_ECHO) "  LINK    $$@"
+       $(Q) $$(shell if [ -z "$$(filter %.cc,$$($(1)_SOURCES))" ] ; \
+         then echo $$(CC)  $$(CPPFLAGS) $$(AM_CPPFLAGS) $$(AM_CFLAGS)   $$(CFLAGS) ; \
+         else echo $$(CXX) $$(CPPFLAGS) $$(AM_CPPFLAGS) $$(AM_CXXFLAGS) $$(CXXFLAGS) ; fi) \
+         $$(AM_LDFLAGS) $$(LDFLAGS) $$($(1)$(3:%=-%)_LDFLAGS) -Wl,-Map,$(1)$(3:%=-%).map \
+         $$($(1)_OBJS) $$(LOADLIBES) $$($(1)_MOREOBJS) $$($(1)_LIBS:%=-l%) \
+         -o $$@
+       @echo "$(2)/$(1)$(3:%=-%): \\" >$(OBJS_DIR)/$(1)$(3:%=-%).exe.d
+       @if [ -n "$(LD_SCRIPT)" ]; then \
+         echo "  $(LIB_DIR)/$(LD_SCRIPT).ld$(3:%=-%) \\" >>$(OBJS_DIR)/$(1)$(3:%=-%).exe.d; fi
+       @sed -n -e 's/^LOAD \(.*\)$$$$/  \1  \\/p' $(OBJS_DIR)/$(1)$(3:%=-%).map  >>$(OBJS_DIR)/$(1)$(3:%=-%).exe.d
+       @echo >>$(OBJS_DIR)/$(1).exe.d
+endef
+
+# Rules for other output formats (can be specified by OUTPUT_FORMATS)
+%.bin: %
+       @$(QUIET_CMD_ECHO) "  OBJCOPY $@"
+       $(Q) $(OBJCOPY)  --output-target=binary -S $< $@
+
+%.hex: %
+       @$(QUIET_CMD_ECHO) "  OBJCOPY $@"
+       $(Q) $(OBJCOPY)  --output-target=ihex -S $< $@
+
+%.srec: %
+       @$(QUIET_CMD_ECHO) "  OBJCOPY $@"
+       $(Q) $(OBJCOPY)  --output-target=srec -S $< $@
+
+# Syntax: $(call LIBRARY_template,<library-name>)
+define LIBRARY_template
+$(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.c=%.o))
+$(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cc=%.o))
+$(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.cxx=%.o))
+$(1)_OBJS += $$(filter %.o,$$($(1)_SOURCES:%.S=%.o))
+$(1)_OBJS := $$(sort $$($(1)_OBJS))
+
+SOURCES += $$($(1)_SOURCES)
+
+$(LIB_DIR)/lib$(1).a: $$($(1)_OBJS)
+       @$(QUIET_CMD_ECHO) "  AR      $$@"
+       $(Q) $(AR) rcs $$@ $$^
+endef
+
+
+# Syntax: $(call SOLIB_template,<library-name>)
+define SOLIB_template
+$(1)_OBJSLO += $$(filter %.lo,$$($(1)_SOURCES:%.c=%.lo))
+$(1)_OBJSLO += $$(filter %.lo,$$($(1)_SOURCES:%.cc=%.lo))
+$(1)_OBJSLO += $$(filter %.lo,$$($(1)_SOURCES:%.cxx=%.lo))
+$(1)_OBJSLO += $$(filter %.lo,$$($(1)_SOURCES:%.S=%.lo))
+$(1)_OBJSLO := $$(sort $$($(1)_OBJSLO))
+
+SOLIB_OBJS  += $$($(1)_OBJSLO)
+SOLIB_SOURCES += $$($(1)_SOURCES)
+
+$(LIB_DIR)/lib$(1).so: $$($(1)_OBJSLO)
+       @$(QUIET_CMD_ECHO) "  LINK    $$@"
+       $(Q) $(LD) --shared --soname=lib$(1).so -o $$@ $$^
+endef
+
+# Local Variables:
+# mode:makefile
+# End:
+ifeq ($(OMK_VERBOSE),1)                                      #OMK@include
+CPHEADER_FLAGS += -v
+LNHEADER_FLAGS += -v
+endif
+
+ifneq ($(LN_HEADERS),y)
+define cp_cmd
+( echo "  CP      $(1:$(MAKERULES_DIR)/%=%) -> $(2:$(MAKERULES_DIR)/%=%)"; cp $(CPHEADER_FLAGS) $(1) $(2) )
+endef
+else
+define cp_cmd
+( echo "  LN      $(1:$(MAKERULES_DIR)/%=%) -> $(2:$(MAKERULES_DIR)/%=%)"; ln -sf $(LNHEADER_FLAGS) $(1) $(2) )
+endef
+endif
+
+# TODO: Check modification date of changed header files. If it is
+# newer that in source dir, show a warning.
+
+# Syntax: $(call include-pass-template,<include dir>,<keyword>)
+define include-pass-template
+       @$(foreach f, $($(2)_HEADERS), cmp --quiet $(SOURCES_DIR)/$(f) $(1)/$(notdir $(f)) \
+          || $(call cp_cmd,$(SOURCES_DIR)/$(f),$(1)/$(notdir $(f))) || exit 1 ; )
+       @$(foreach f, $(nobase_$(2)_HEADERS), cmp --quiet $(SOURCES_DIR)/$(f) $(1)/$(f) \
+          || ( mkdir -p $(1)/$(dir $(f)) && $(call cp_cmd,$(SOURCES_DIR)/$(f),$(1)/$(f)) ) || exit 1 ; )
+       @$(foreach f, $(renamed_$(2)_HEADERS), \
+          srcfname=`echo '$(f)' | sed -e 's/^\(.*\)->.*$$/\1/'` ; destfname=`echo '$(f)' | sed -e 's/^.*->\(.*\)$$/\1/'` ; \
+          cmp --quiet $(SOURCES_DIR)/$${srcfname} $(1)/$${destfname} \
+          || ( mkdir -p `dirname $(1)/$${destfname}` && $(call cp_cmd,$(SOURCES_DIR)/$${srcfname},$(1)/$${destfname}) ) || exit 1 ; )
+endef
+
+# Local Variables:
+# mode:makefile
+# End:
+                                                             #OMK@sysless
+.PHONY: check-dir
+
+# Some support to serialize some targets for parallel make
+ifneq ($(OMK_SERIALIZE_INCLUDED),y)
+include-pass: check-dir
+library-pass: include-pass
+binary-pass utils-pass: library-pass
+
+override OMK_SERIALIZE_INCLUDED = y
+endif
+
+# -------------------------------------
+# Rules for compilation for target
+ifdef TARGET_RULE_TEMPLATES
+
+LDFLAGS += -nostartfiles
+
+ # FIXME: These are not used. What they are good for?
+LIB_CPPFLAGS += $(CPPFLAGS)
+LIB_CFLAGS   += $(CFLAGS)
+
+SOLIB_PICFLAGS += -shared -fpic
+
+CFLAGS += -DOMK_FOR_TARGET
+
+INCLUDE_DIR := $(USER_INCLUDE_DIR)
+LIB_DIR     := $(USER_LIB_DIR)
+OBJS_DIR    := $(USER_OBJS_DIR)
+
+$(eval $(COMPILER_DEFS_template))
+
+# Special rules for CMETRIC generated headers
+
+$(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call COMPILE_c_o_template,\
+               $(SOURCES_DIR)/$($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES),\
+               $($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%.o),)))
+$(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call CMETRIC_o_h_template,\
+               $($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%.o),\
+               $(addprefix $(USER_INCLUDE_DIR)/,$(cmetrh)))))
+
+GEN_HEADERS+=$(cmetric_include_HEADERS:%=$(USER_INCLUDE_DIR)/%)
+
+# Generate rules for compilation of programs and libraries
+ifneq ($(link_VARIANTS),)
+$(foreach prog,$(bin_PROGRAMS),$(foreach link,$(link_VARIANTS),$(eval $(call PROGRAM_template,$(prog),$(USER_BIN_DIR),$(link)))))
+$(foreach prog,$(test_PROGRAMS),$(foreach link,$(link_VARIANTS),$(eval $(call PROGRAM_template,$(prog),$(USER_TESTS_DIR),$(link)))))
+else
+$(foreach prog,$(bin_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_BIN_DIR))))
+$(foreach prog,$(test_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_TESTS_DIR))))
+endif
+
+$(foreach lib,$(lib_LIBRARIES),$(eval $(call LIBRARY_template,$(lib))))
+$(foreach src,$(lib_obj_SOURCES),$(eval $(call LIBOBJ_template,$(addsuffix $(OBJ_EXT),$(basename $(src))))))
+$(foreach lib,$(shared_LIBRARIES),$(eval $(call SOLIB_template,$(lib))))
+
+
+# lib_obj_SOURCES handling
+lib_OBJS = $(addsuffix $(OBJ_EXT),$(basename $(lib_obj_SOURCES)))
+#$(warning lib_OBJS = $(lib_OBJS))
+SOURCES += $(filter-out %$(OBJ_EXT),$(lib_obj_SOURCES))
+
+$(LIB_DIR)/%$(OBJ_EXT): %$(OBJ_EXT)
+       @echo "  CP      $(^:$(MAKERULES_DIR)/%=%) -> $(@:$(MAKERULES_DIR)/%=%)"
+       $(Q)cp $(CP_FLAGS) $< $@
+
+
+# User-space static libraries and applications object files
+SOURCES := $(sort $(SOURCES))
+#$(warning SOURCES = $(SOURCES))
+
+# User-space shared libraries object files
+SOLIB_SOURCES := $(sort $(SOLIB_SOURCES))
+#$(warning SOLIB_SOURCES = $(SOLIB_SOURCES))
+
+
+# The above generated rules produced $(SOURCES) and $(SOLIB_SOURCES)
+# variables. Now generate rules for compilation of theese sources
+$(foreach src,$(filter %.c,$(SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%$(OBJ_EXT)),)))
+$(foreach src,$(filter %.cc,$(SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%$(OBJ_EXT)),)))
+$(foreach src,$(filter %.cxx,$(SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%$(OBJ_EXT)),)))
+$(foreach src,$(filter %$(ASM_EXT),$(SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%$(ASM_EXT)=%$(OBJ_EXT)),)))
+
+$(foreach src,$(filter %.c,$(SOLIB_SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%.lo),$(SOLIB_PICFLAGS))))
+$(foreach src,$(filter %.cc,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%.lo),$(SOLIB_PICFLAGS))))
+$(foreach src,$(filter %.cxx,$(SOLIB_SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%.lo),$(SOLIB_PICFLAGS))))
+$(foreach src,$(filter %$(ASM_EXT),$(SOLIB_SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%$(ASM_EXT)=%.lo),$(SOLIB_PICFLAGS))))
+
+library-pass-local: $(addprefix $(USER_INCLUDE_DIR)/,$(cmetric_include_HEADERS)) \
+                   $(lib_LIBRARIES:%=$(LIB_DIR)/$(LIB_PREF)%$(LIB_EXT)) $(shared_LIBRARIES:%=$(LIB_DIR)/$(LIB_PREF)%.so) \
+                   $(addprefix $(LIB_DIR)/,$(lib_OBJS))
+
+ifneq ($(link_VARIANTS),)
+binary-pass-local:  $(foreach link,$(link_VARIANTS),$(bin_PROGRAMS:%=$(USER_BIN_DIR)/%-$(link)) $(test_PROGRAMS:%=$(USER_TESTS_DIR)/%-$(link)) \
+                   $(foreach of,$(OUTPUT_FORMATS),$(bin_PROGRAMS:%=$(USER_BIN_DIR)/%-$(link).$(of)) $(test_PROGRAMS:%=$(USER_TESTS_DIR)/%-$(link).$(of))))
+else
+binary-pass-local:  $(bin_PROGRAMS:%=$(USER_BIN_DIR)/%) $(test_PROGRAMS:%=$(USER_TESTS_DIR)/%) \
+                   $(foreach of,$(OUTPUT_FORMATS),$(bin_PROGRAMS:%=$(USER_BIN_DIR)/%.$(of)) $(test_PROGRAMS:%=$(USER_TESTS_DIR)/%.$(of)))
+endif
+
+endif # TARGET_RULE_TEMPLATES
+
+
+# -------------------------------------
+# Rules for compilation utilities for host (user space)
+ifdef HOST_RULE_TEMPLATES
+
+CROSS_COMPILE =
+TARGET_ARCH =
+
+SOLIB_PICFLAGS += -shared -fpic
+
+# For host compilation, we don't use a specfic ld script
+LD_SCRIPT =
+
+# TODO: It is probably better to use different directories for host
+# includes, libraries and objects
+INCLUDE_DIR := $(USER_INCLUDE_DIR)
+LIB_DIR     := $(USER_LIB_DIR)
+OBJS_DIR    := $(USER_OBJS_DIR)
+
+$(eval $(COMPILER_DEFS_template))
+
+ #User-space static libraries and applications object files
+#SOURCES := $(sort $(SOURCES))
+#$(warning SOURCES = $(SOURCES))
+
+# Generate rules for compilation of utility programs
+$(foreach prog,$(utils_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_UTILS_DIR),)))
+
+# The above generated rule produced $(SOURCES) variable. Now generate
+# rules for compilation of theese sources
+$(foreach src,$(filter %.c,$(SOURCES)),$(eval $(call COMPILE_c_o_template,$(SOURCES_DIR)/$(src),$(src:%.c=%$(OBJ_EXT)),)))
+$(foreach src,$(filter %.cc,$(SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cc=%$(OBJ_EXT)),)))
+$(foreach src,$(filter %.cxx,$(SOURCES)),$(eval $(call COMPILE_cc_o_template,$(SOURCES_DIR)/$(src),$(src:%.cxx=%$(OBJ_EXT)),)))
+$(foreach src,$(filter %$(ASM_EXT),$(SOURCES)),$(eval $(call COMPILE_S_o_template,$(SOURCES_DIR)/$(src),$(src:%$(ASM_EXT)=%$(OBJ_EXT)),)))
+
+utils-pass-local: $(utils_PROGRAMS:%=$(USER_UTILS_DIR)/%)
+
+endif # HOST_RULE_TEMPLATES
+
+
+#=====================================================================
+# Automatic loading of compiled program by issuing "make load"
+
+ifneq ($(OUTPUT_FORMATS),)
+# Select a file extension (e.g. .bin) for "make load" command to load.
+LOAD_EXTENSION = .$(firstword $(OUTPUT_FORMATS))
+endif
+
+# Syntax: $(call LOAD_PROGRAM_template,<executable-name>,<dir>,<link-variant>)
+# Used to load program to the target hardware
+define LOAD_PROGRAM_template
+.PHONY: load-$(1)$(3:%=-%)
+load-$(1)$(3:%=-%): $(2)/$(1)$(3:%=-%)$(LOAD_EXTENSION)
+       @$(QUIET_CMD_ECHO) "  LOAD    $$<"
+       @if [ -z "$$(LOAD_CMD$(3:%=-%))" ]; then echo "No command for loading applications to '$(3)' is specified."; exit 1; fi
+       $(Q) $$(LOAD_CMD$(3:%=-%)) $$<
+endef
+
+# Syntax: $(call LOAD__RUN_VARIANT_template,<link-variant>)
+# Used to load and/or run non-default variant of the default program
+define LOAD_RUN_VARIANT_template
+.PHONY: load-$(1) run-$(1)
+
+load-$(1): load-$(firstword $(bin_PROGRAMS) $(test_PROGRAMS))-$(1)
+
+run-$(1):
+       @$(QUIET_CMD_ECHO) "  RUN     $(1)"
+       @if [ -z "$(RUN_CMD-$(1))" ]; then echo "No command for running '$(1)' variant is specified."; exit 1; fi
+       $(Q) $(RUN_CMD-$(1))
+
+endef
+
+$(foreach link,$(link_VARIANTS),$(foreach prog,$(bin_PROGRAMS),$(eval $(call LOAD_PROGRAM_template,$(prog),$(USER_BIN_DIR),$(link)))))
+$(foreach link,$(link_VARIANTS),$(foreach prog,$(test_PROGRAMS),$(eval $(call LOAD_PROGRAM_template,$(prog),$(USER_TEST_DIR),$(link)))))
+$(foreach link,$(link_VARIANTS),$(eval $(call LOAD_RUN_VARIANT_template,$(link))))
+
+.PHONY: load run
+load: $(addprefix load-,$(firstword $(bin_PROGRAMS) $(test_PROGRAMS))-$(firstword $(link_VARIANTS)))
+
+run: run-$(firstword $(link_VARIANTS))
+
+
+
+#=====================================================================
+# Generate pass rules from generic templates
+OTHER_PASSES = dep clean install
+
+$(eval $(call omk_pass_template, include-pass, $(LOCAL_BUILD_DIR),,$(include_HEADERS)$(nobase_include_HEADERS)$(renamed_include_HEADERS)$(lib_LDSCRIPTS)$(config_include_HEADERS)$(LOCAL_CONFIG_H)))
+$(eval $(call omk_pass_template, library-pass, $(LOCAL_BUILD_DIR),TARGET_RULE_TEMPLATES=y,$(lib_LIBRARIES)$(shared_LIBRARIES)$(lib_obj_SOURCES)))
+$(eval $(call omk_pass_template, binary-pass,  $(LOCAL_BUILD_DIR),TARGET_RULE_TEMPLATES=y,$(bin_PROGRAMS) $(test_PROGRAMS)))
+$(eval $(call omk_pass_template, utils-pass,   $(LOCAL_BUILD_DIR),HOST_RULE_TEMPLATES=y,$(utils_PROGRAMS)))
+
+
+$(eval $(call omk_pass_template,$(OTHER_PASSES),$(LOCAL_BUILD_DIR),,always))
+
+
+dep-local:
+
+install-local:
+
+include-pass-local:
+       $(call include-pass-template,$(USER_INCLUDE_DIR),include)
+       @$(foreach f, $(lib_LDSCRIPTS), cmp --quiet $(SOURCES_DIR)/$(f) $(USER_LIB_DIR)/$(notdir $(f)) \
+          || $(call cp_cmd,$(SOURCES_DIR)/$(f),$(USER_LIB_DIR)/$(notdir $(f))) || exit 1 ; )
+
+
+.PHONY: clean-custom
+clean-local: clean-custom
+       $(Q)rm -f $(USER_OBJS_DIR)/*.o $(USER_OBJS_DIR)/*.lo \
+              $(USER_OBJS_DIR)/*.d \
+              $(USER_OBJS_DIR)/*.map \
+              $(LOCAL_CONFIG_H:%=$(USER_OBJS_DIR)/%)
+
+check-dir:
+       @$(call mkdir_def,$(USER_INCLUDE_DIR))
+       @$(call mkdir_def,$(USER_LIB_DIR))
+       @$(call mkdir_def,$(USER_BIN_DIR))
+       @$(call mkdir_def,$(USER_UTILS_DIR))
+       @$(call mkdir_def,$(USER_TESTS_DIR))
+
+# Which passes to pass
+default: include-pass library-pass binary-pass utils-pass
+
+# Local Variables:
+# mode:makefile
+# End:
+                                                             #OMK@config_h
+# Syntax: $(call BUILD_CONFIG_H_template,<stamp_dir>,<header_file_path>,<list_of_options_to_export>,<header_barrier>)
+define BUILD_CONFIG_H_template
+
+$(addprefix $(1)/,$(notdir $(addsuffix .stamp,$(2)))) : $(wildcard $(CONFIG_FILE)) $(wildcard $(CONFIG_FILE)-default)
+       @$(QUIET_CMD_ECHO) "  CONFGEN $$(@:%.stamp=%)"
+       @if [ ! -d `dirname $(2).tmp` ] ; then \
+               mkdir -p `dirname $(2).tmp` ; fi
+       @echo "/* Automatically generated from */" > "$(2).tmp"
+       @echo "/* config file: $$< */" >> "$(2).tmp"
+       $(if $(DOXYGEN),@echo "/** @file */" >> "$(2).tmp")
+       @echo "#ifndef $(4)" >> "$(2).tmp"
+       @echo "#define $(4)" >> "$(2).tmp"
+       @( $(foreach x, $(shell echo '$($(3))' | tr 'x\t ' 'x\n\n' | sed -e 's/^\([^ =]*\)\(=[^ ]\+\|\)$$/\1/' ), \
+               echo '$(x).$($(x))' ; ) echo ; ) | \
+               sed -e '/^[^.]*\.n$$$$/d' -e '/^[^.]*\.$$$$/d' -e 's/^\([^.]*\)\.[ym]$$$$/\1.1/' | \
+               sed -n -e 's/^\([^.]*\)\.\(.*\)$$$$/#define \1 \2/p' \
+                 >> "$(2).tmp"
+       @echo "#endif /*$(4)*/" >> "$(2).tmp"
+       @touch "$$@"
+       @if cmp --quiet "$(2).tmp" "$(2)" ; then rm "$(2).tmp"; \
+       else mv "$(2).tmp" "$(2)" ; \
+       echo "Updated configuration $(2)" ; fi
+
+endef
+
+ifdef LOCAL_CONFIG_H
+
+# This must be declared after the default cflags are assigned!
+# Override is used to override command line assignemnt.
+override CFLAGS += -I.
+$(eval $(call BUILD_CONFIG_H_template,$(USER_OBJS_DIR),$(USER_OBJS_DIR)/$(LOCAL_CONFIG_H),default_CONFIG,_LOCAL_CONFIG_H) )
+
+endif
+
+# Special rules for configuration exported headers
+
+#FIXME: The directory for headers should not be specified here.
+$(foreach confh,$(config_include_HEADERS),$(eval $(call BUILD_CONFIG_H_template,$(USER_OBJS_DIR),$(addprefix $(USER_INCLUDE_DIR)/,$(confh)),$(basename $(notdir $(confh)))_DEFINES,\
+_$(basename $(notdir $(confh)))_H \
+)))
+
+config_h_stamp_files = $(addprefix $(USER_OBJS_DIR)/,$(notdir $(addsuffix .stamp,$(config_include_HEADERS) $(LOCAL_CONFIG_H))))
+
+# Add some hooks to standard passes
+include-pass-local: $(config_h_stamp_files)
+
+ifneq ($(KERN_CONFIG_HEADERS_REQUIRED),)
+
+ifdef LOCAL_CONFIG_H
+$(eval $(call BUILD_CONFIG_H_template,$(KERN_OBJS_DIR),$(KERN_OBJS_DIR)/$(LOCAL_CONFIG_H),default_CONFIG,_LOCAL_CONFIG_H) )
+endif
+
+$(foreach confh,$(config_include_HEADERS),$(eval $(call BUILD_CONFIG_H_template,$(KERN_OBJS_DIR),$(addprefix $(KERN_INCLUDE_DIR)/,$(confh)),$(basename $(notdir $(confh)))_DEFINES,\
+_$(basename $(notdir $(confh)))_H \
+)))
+
+kern_config_h_stamp_files = $(addprefix $(KERN_OBJS_DIR)/,$(notdir $(addsuffix .stamp,$(config_include_HEADERS) $(LOCAL_CONFIG_H))))
+
+# Add some hooks to standard passes
+include-pass-local: $(kern_config_h_stamp_files)
+
+endif
+
+clean-local: clean-local-config-h
+
+clean-local-config-h:
+       @$(foreach confh,$(config_h_stamp_files) $(kern_config_h_stamp_files),\
+           if [ -e $(confh) ] ; then rm $(confh) ; fi ; \
+       )
+
+
+# Local Variables:
+# mode:makefile
+# End:
+                                                             #OMK@sources-list
+# Rules that creates the list of files which are used during
+# compilation. The list reflects conditional compilation depending on
+# config.omk and other variables.
+
+SOURCES_LIST_FN=sources.txt
+ifndef SOURCES_LIST
+SOURCES_LIST_DIR:=$(RELATIVE_DIR)
+SOURCES_LIST:=$(MAKERULES_DIR)/$(SOURCES_LIST_DIR)/$(SOURCES_LIST_FN)
+export SOURCES_LIST SOURCES_LIST_DIR
+endif
+
+ifeq ($(MAKECMDGOALS),sources-list)
+NEED_SOURCES_LIST=y
+endif
+ifeq ($(MAKECMDGOALS),TAGS)
+NEED_SOURCES_LIST=y
+endif
+ifeq ($(MAKECMDGOALS),tags)
+NEED_SOURCES_LIST=y
+endif
+
+ifeq ($(NEED_SOURCES_LIST),y) # avoid execution of find command bellow if it is not useful
+.PHONY: sources-list
+sources-list: $(SOURCES_LIST)
+
+$(SOURCES_LIST): $(CONFIG_FILE) $(CONFIG_FILE)-default $(shell find -name $(MAKEFILE_OMK))
+       @echo -n "" > "$(SOURCES_LIST).tmp"
+       @$(MAKE) --no-print-directory sources-list-pass
+       @echo "# Automatically generated list of files in '$(RELATIVE_DIR)' that are used during OMK compilation" > "$(SOURCES_LIST).tmp2"
+       @cat "$(SOURCES_LIST).tmp"|sort|uniq >> "$(SOURCES_LIST).tmp2"
+       @rm "$(SOURCES_LIST).tmp"
+       @mv "$(SOURCES_LIST).tmp2" "$(SOURCES_LIST)"
+endif
+
+$(eval $(call omk_pass_template,sources-list-pass,$$(LOCAL_BUILD_DIR),,always))
+
+sources-list-pass-local:
+       @$(foreach h,$(include_HEADERS) $(nobase_include_HEADERS) $(kernel_HEADERS),\
+         echo "$(RELATIVE_DIR:$(SOURCES_LIST_DIR)/%=%)/$(h)" >> "$(SOURCES_LIST).tmp";)
+       @$(foreach ch,$(config_include_HEADERS), \
+         echo "$(USER_INCLUDE_DIR:$(MAKERULES_DIR)/$(addsuffix /,$(SOURCES_LIST_DIR))%=%)/$(ch)" >> "$(SOURCES_LIST).tmp";)
+       @$(foreach h,$(renamed_include_HEADERS),echo "$(RELATIVE_DIR:$(SOURCES_LIST_DIR)/%=%)/$(h)"|sed -e 's/\(.*\)->.*/\1/' >> "$(SOURCES_LIST).tmp";)
+       @$(foreach bin,$(lib_LIBRARIES) $(shared_LIBRARIES) $(bin_PROGRAMS) $(test_PROGRAMS) $(utils_PROGRAMS) \
+         $(kernel_LIBRARIES) $(rtlinux_LIBRARIES) $(kernel_MODULES),\
+         $(foreach src,$(filter-out %.o,$($(bin)_SOURCES)),echo "$(RELATIVE_DIR:$(SOURCES_LIST_DIR)/%=%)/$(src)" >> "$(SOURCES_LIST).tmp";))
+
+############ TAGS ###########
+
+ifeq ($(MAKECMDGOALS),TAGS)
+ETAGS=etags
+TAGS_CMD = $(ETAGS)
+TAGS: $(SOURCES_LIST)
+       @$(MAKE) --no-print-directory do-tags
+endif
+ifeq ($(MAKECMDGOALS),tags) 
+CTAGS=ctags -N
+TAGS_CMD = $(CTAGS)
+tags: $(SOURCES_LIST)
+       @$(MAKE) --no-print-directory do-tags
+endif
+export TAGS_CMD
+
+ifeq ($(MAKECMDGOALS),do-tags)
+.PHONY: do-tags
+do-tags: $(shell sed -e '/^\#/d' $(SOURCES_LIST))
+       @$(QUIET_CMD_ECHO) "  TAGS    $(SOURCES_LIST_FN)"
+       $(Q)$(TAGS_CMD) $^
+endif
+
+############ CSCOPE ###########
+
+cscope: $(SOURCES_LIST)
+       @$(QUIET_CMD_ECHO) "  CSCOPE  < $(SOURCES_LIST_FN)"
+       $(Q)sed -e '/^#/d' $(SOURCES_LIST)|cscope -b -i-
+#FIXME: see doc to -i in cscope(1)
+
+# Local Variables:
+# mode:makefile
+# End:
+                                                             #OMK@localeval
+ifneq ($(local_EVALUATE),)
+#$(warning $(local_EVALUATE))
+$(eval $(local_EVALUATE))
+endif
+
+# Local Variables:
+# mode:makefile
+# End:
diff --git a/common/README.makerules b/common/README.makerules
new file mode 100644 (file)
index 0000000..b3db064
--- /dev/null
@@ -0,0 +1,251 @@
+!!! TODO: Modify this to agree with h8300 project
+
+Description of OCERA Make System for CAN Components (OMK)
+=========================================================
+
+Important notice:
+This make system uses features found in recent versions of GNU Make
+program. If you encounter problems with package building,
+check, that you use correct version of Make program.
+The Make older than version 3.80, could not be used.
+Even Make version 3.80 has annoying bug which causes
+building fail with misleading message "virtual memory exhausted".
+Please, upgrade to last version of Make (3.81beta1).
+You can take it from GNU CVS, Paul D. Smith's site or from our local copy
+  http://paulandlesley.org/make/make-3.81beta1.tar.bz2
+  http://cmp.felk.cvut.cz/~pisa/can/make-3.81beta1.tar.gz
+
+
+There is list of features which we want to solve with our makesystem:
+ - central Makefile.rules for most of subcomponents and components
+  (our CAN framework includes more libraries common with our other projects,
+   we need to separate some utility libraries etc.)
+ - the rules in more spread Makefiles are way to the hell,
+  (update for different kernel, RT-Linux etc would be nightmare in other case)
+ - make system should allow to freely move with cross-dependant components
+   without need to update users of moved component
+  (I hate somethink like -I../../sched/rtlshwq/include in CAN makefiles
+   for example. Component could be renamed to different name or version
+   could be added to name and all Makefiles in CAN would require to
+   be updated)
+ - make system should be able to compile mutually cross-dependant libraries
+   and should ensure, that change in one component sources or headers
+   would result in relink or rebuild in components linked against that library
+   or including modified header file
+ - make system has to enable compilation out of OCERA full source tree
+  (we would lost many users of particular components in other case)
+ - compile should be able to do all above work without need to install
+   any files before successful finish of build.
+ - because we use some libraries for RT-Linux build and userspace
+   build, we need to solve how to compile from same sources to both targets.
+ - the build system should allow to call make for particular source
+   subdirectory. Time of recursive make through all subdirectories is
+   unacceptable.
+ - make system should enable to build out of sources tree
+  (else clean or working with CVS sandbox gets fussy and simultaneous
+   multiple targets gets problematic)
+ - it would be good, if there would be possibility to make from read-only
+   media sources
+ - make system should store results of build in some separate directory
+   structure to simple install and testing
+ - Makefiles in sources directories should be simple
+
+There is probably only one alternative fully supporting above requirements
+and it is GNU Autoheader...Automake...Autoconf... system.
+But it is complicated and requires big amount of support files.
+It would be acceptable if it could be easily used for OCERA framework.
+But there are important show stopper for that system:
+ - it would require deep revision of all OCERA CVS contents and agreement
+   on this would be problematic
+ - this system is not well prepared for dual compilation for Linux
+   and RT-Linux sub-targets. It would mean many changes in default
+   autoconf setup to support this. Probably simplest way would be
+   to rebuild GCC tool chain for something like i586-elf-rtlinux.
+   This would require even more space for OCERA development.
+
+The problem calls for same solution, which would have minimal impact
+on other components and would be elegant and would be maintainable
+and small, because our main goal is components development and not
+make systems development.
+
+There is result of our trial. It is OMK make system.
+The Makefile and Makefile.omk files should be in all source
+directories. Common Makefile.rules file is required in the toplevel
+sources directory. Alternatively this file could be moved
+to link tree pointing into readonly media or can be anywhere
+else if MAKERULES_DIR and SOURCES_DIR are specified.
+
+Syntax of Makefile.omk files is for usual cases compatible
+to Automake's Makefile.am descriptions. There are specific targets
+for RT-Linux and Linux kernel related stuff
+
+Makefile.omk user defined variables
+# SUBDIRS          .. list of subdirectories intended for make from actual directory
+# lib_LIBRARIES    .. list of the user-space libraries
+# shared_LIBRARIES .. list of the user-space shared libraries
+# kernel_LIBRARIES .. list of the kernel-space libraries
+# rtlinux_LIBRARIES.. list of the RT-Linux kernel-space libraries
+# include_HEADERS  .. list of the user-space header files
+# nobase_include_HEADERS .. headers copied even with directory part
+# kernel_HEADERS   .. list of the kernel-space  header files
+# rtlinux_HEADERS  .. list of the RT-Linux kernel-space  header files
+# bin_PROGRAMS     .. list of the require binary programs
+# utils_PROGRAMS   .. list of the development utility programs
+# kernel_MODULES   .. list of the kernel side modules/applications
+# rtlinux_MODULES  .. list of RT-Linux the kernel side modules/applications
+# xxx_SOURCES      .. list of specific target sources
+# INCLUDES         .. additional include directories and defines for user-space
+# kernel_INCLUDES  .. additional include directories and defines for kernel-space
+# rtlinux_INCLUDES .. additional include directories and defines for RT-Linux
+# default_CONFIG   .. list of default config assignments CONFIG_XXX=y/n ...
+
+The Makefile is same for all sources directories and is only 14 lines long.
+It is there only for convenience reasons to enable call "make" from
+local directory. It contains code which locates Makefile.rules in actual
+or any parent directory. With standard BASH environment it works such way,
+that if you get into sources directory over symbolic links, it is able to
+unwind yours steps back => you can make links to readonly media component
+directories, copy Makefile.rules, Makefile and toplevel Makefile.omk,
+adjust Makefile.omk to contain only required components and then call
+make in top or even directories after crossing from your tree
+to readonly media.
+
+The system compiles all files out of source directories.
+The actual version of system is adapted even for OCERA tree mode
+if OCERA_DIR variable is defined in Makefile.rules
+
+There are next predefined directory name components,
+which can be adapted if required
+
+BUILD_DIR_NAME = _build
+       prefix of directory, where temporary build files are stored
+COMPILED_DIR_NAME = _compiled
+       prefix of directory, where final compilation results are stored
+GROUP_DIR_NAME = yyy
+       this is used for separation of build sub-trees in OCERA environment
+       where more Makefile.rules is spread in the tree
+
+Next directories are used:
+
+KERN_BUILD_DIR   := $(MAKERULES_DIR)/$(BUILD_DIR_NAME)/kern
+        directory to store intermediate files for kernel-space targets
+USER_BUILD_DIR   := $(MAKERULES_DIR)/$(BUILD_DIR_NAME)/user
+        directory to store intermediate files for user-space targets
+
+USER_INCLUDE_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/include
+        directory to store exported include files which should be installed later
+        on user-space include path
+USER_LIB_DIR     := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/lib
+        same for user-pace libraries
+USER_UTILS_DIR   := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/bin-utils
+        utilities for testing, which would not probably be installed
+USER_BIN_DIR     := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/bin
+        binaries, which should go into directory on standard system PATH
+        (/usr/local/bin, /usr/bin or $(prefix)/bin)
+
+KERN_INCLUDE_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/include-kern
+        directory to store exported include files which should be installed later
+        on kernel-space include path
+KERN_LIB_DIR     := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/lib-kern
+        same for kernel-pace libraries
+KERN_MODULES_DIR := $(MAKERULES_DIR)/$(COMPILED_DIR_NAME)/modules
+        builded modules for Linux kernel or RT-Linux system
+
+There is more recursive passes through directories to enable
+mutual dependant libraries and binaries to compile.
+Next passes are defined
+
+default-config .. generates config.omk-default or xxx-default configuration file
+check-dir      .. checks and creates required build directories
+include-pass   .. copyes header files to USER_INCLUDE_DIR and KERN_INCLUDE_DIR
+library-pass   .. builds objects in USER_BUILD_DIR/<relative path> and creates
+                  libraries in USER_LIB_DIR
+binary-pass and utils-pass .. links respective binaries
+                in USER_{BIN,UTILS}_DIR directory. If some object file is missing
+                it compiles it in  USER_BUILD_DIR/<relative path>
+kernel-lib-pass .. builds libraries for kernel space targets
+kernel-pass    .. builds kernel modules
+
+The amount of passes is relatively high and consumes some time.
+But only other way to support all required features is to assemble
+one big toplevel Makefile, which would contain all components
+and targets cross-dependencies.
+
+Drawbacks of designed make system
+ - the system is not as fast as we would like
+ - it lacks Autoconf and configure extensive support for many systems
+   from UNIX to DOS and WINDOWS
+ - it does not contain support for checking existence of target libraries
+   and functionalities as GNU Autoconf
+ - it is heavily dependant on GNU MAKE program. But it would not be big
+   problem, because even many commercial applications distribute GNU
+   MAKE with them to be able to work in non-friendly systems
+ - the key drawback is dependence on recent MAKE version 3.80 and better
+   and even version 3.80 of MAKE has important bug, which has been
+   corrected in newer sources
+
+The last point is critical. I have not noticed it first, because
+I use Slackware-9.2 and it contains latest released version 
+of MAKE (version 3.80).
+The problem appears when I have tried to build bigger libraries.
+There is bug in version 3.80, which results in misleading
+error "Virtual memory exhausted". It is known bug with ID 1517
+
+    * long prerequisite inside eval(call()) => vm exhausted, Paul D. Smith
+
+I have optimized some rules to not push memory to the edge,
+but there could be still issues with 3.80 version.
+
+I have downloaded latest MAKE CVS sources. The compilation required
+separate lookup and download for .po files and full Autoheader... cycle.
+I have put together package similar to release. Only ./configure --prefix=...
+and make is required. CVS sources contains version 3.81beta1.
+You can download prepared sources archive from
+  http://paulandlesley.org/make/make-3.81beta1.tar.bz2
+Or you can get our local copy from
+  http://cmp.felk.cvut.cz/~pisa/can/make-3.81beta1.tar.gz
+
+The archive contains even "make" binary build by me, which should work
+on other Linux distributions as well. 
+Older version of MAKE (3.79.x released about year 2000) found
+on Mandrake and RedHat are not sufficient and do not support eval feature.
+I do not expect, that Debian would be more up-to-date or contain fixes
+to MAKE vm exhausted bug.
+
+The local CTU archive with our CAN components prepared for inclusion
+into OCERA SF CVS could be found in my "can" directory
+
+  http://cmp.felk.cvut.cz/~pisa/can/ocera-can-031212.tar.gz
+
+The code should build for user-space with new make on most of Linux distros
+when make is updated.
+
+If you want to test compile for RT-Linux targets, line
+
+#RTL_DIR := /home/cvs/ocera/ocera-build/kernel/rtlinux
+
+in "Makefile.rules" has to be activated and updated
+to point RT-Linux directory containing "rtl.mk".
+There is only one library ("ulutrtl") and test utility compiled for RT-Linux
+("can/utils/ulut/ul_rtlchk.c").
+
+The next line ,if enabled, controls compilation in OCERA project tree
+
+#OCERA_DIR := $(shell ( cd -L $(MAKERULES_DIR)/../../.. ; pwd -L ) )
+
+The LinCAN driver has been updated to compile out of source directories.
+
+Please, check, if you could compile CAN package and help us with integration
+into OCERA SF CVS. Send your comments and objections. 
+
+The OMK system has been adapted to support actual OCERA configuration process.
+I am not happy with ocera.mk mix of defines and poor two or three rules,
+but OMK is able to overcome that.
+
+The OMK system has integrated rules (default-config) to build default configuration
+file. The file is named "config.omk-default" for the stand-alone compilation.
+The name corresponds to OCERA config + "-default" if OCERA_DIR is defined.
+This file contains statements from all default_CONFIG lines in all Makefile.omk.
+The file should be used for building of own "config.omk" file, or as list
+for all options if Kconfig is used.
+
diff --git a/common/app/Makefile b/common/app/Makefile
new file mode 100644 (file)
index 0000000..f595272
--- /dev/null
@@ -0,0 +1,14 @@
+# Generic directory or leaf node makefile for OCERA make framework
+
+ifndef MAKERULES_DIR
+MAKERULES_DIR := $(shell ( old_pwd="" ;  while [ ! -e Makefile.rules ] ; do if [ "$$old_pwd" == `pwd`  ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) )
+endif
+
+ifeq ($(MAKERULES_DIR),)
+all : default
+.DEFAULT::
+       @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
+else   
+include $(MAKERULES_DIR)/Makefile.rules
+endif
+
diff --git a/common/app/Makefile.omk b/common/app/Makefile.omk
new file mode 100644 (file)
index 0000000..63b20af
--- /dev/null
@@ -0,0 +1,3 @@
+# -*- makefile -*-
+
+SUBDIRS := $(ALL_OMK_SUBDIRS)
diff --git a/common/arch/Makefile b/common/arch/Makefile
new file mode 100644 (file)
index 0000000..f595272
--- /dev/null
@@ -0,0 +1,14 @@
+# Generic directory or leaf node makefile for OCERA make framework
+
+ifndef MAKERULES_DIR
+MAKERULES_DIR := $(shell ( old_pwd="" ;  while [ ! -e Makefile.rules ] ; do if [ "$$old_pwd" == `pwd`  ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) )
+endif
+
+ifeq ($(MAKERULES_DIR),)
+all : default
+.DEFAULT::
+       @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
+else   
+include $(MAKERULES_DIR)/Makefile.rules
+endif
+
diff --git a/common/arch/Makefile.omk b/common/arch/Makefile.omk
new file mode 100644 (file)
index 0000000..5ba6221
--- /dev/null
@@ -0,0 +1,2 @@
+# -*- makefile -*-
+SUBDIRS = generic $(ARCH)
diff --git a/common/arch/generic/Makefile b/common/arch/generic/Makefile
new file mode 100644 (file)
index 0000000..f595272
--- /dev/null
@@ -0,0 +1,14 @@
+# Generic directory or leaf node makefile for OCERA make framework
+
+ifndef MAKERULES_DIR
+MAKERULES_DIR := $(shell ( old_pwd="" ;  while [ ! -e Makefile.rules ] ; do if [ "$$old_pwd" == `pwd`  ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) )
+endif
+
+ifeq ($(MAKERULES_DIR),)
+all : default
+.DEFAULT::
+       @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
+else   
+include $(MAKERULES_DIR)/Makefile.rules
+endif
+
diff --git a/common/arch/generic/Makefile.omk b/common/arch/generic/Makefile.omk
new file mode 100644 (file)
index 0000000..cea4617
--- /dev/null
@@ -0,0 +1 @@
+SUBDIRS = defines
diff --git a/common/arch/generic/defines/Makefile b/common/arch/generic/defines/Makefile
new file mode 100644 (file)
index 0000000..f595272
--- /dev/null
@@ -0,0 +1,14 @@
+# Generic directory or leaf node makefile for OCERA make framework
+
+ifndef MAKERULES_DIR
+MAKERULES_DIR := $(shell ( old_pwd="" ;  while [ ! -e Makefile.rules ] ; do if [ "$$old_pwd" == `pwd`  ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) )
+endif
+
+ifeq ($(MAKERULES_DIR),)
+all : default
+.DEFAULT::
+       @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
+else   
+include $(MAKERULES_DIR)/Makefile.rules
+endif
+
diff --git a/common/arch/generic/defines/Makefile.omk b/common/arch/generic/defines/Makefile.omk
new file mode 100644 (file)
index 0000000..176b8a6
--- /dev/null
@@ -0,0 +1,2 @@
+# -*- makefile -*-
+include_HEADERS = $(notdir $(wildcard $(SOURCES_DIR)/*.h))
diff --git a/common/arch/generic/defines/byteswap.h b/common/arch/generic/defines/byteswap.h
new file mode 100644 (file)
index 0000000..9a1492a
--- /dev/null
@@ -0,0 +1,14 @@
+#ifndef _BYTESWAP_H
+#define _BYTESWAP_H    1
+
+#define __bswap_16(x) ({unsigned short __x=(x); \
+                       (((__x>>8)&0xff)|((__x&0xff)<<8)); })
+
+#define __bswap_32(x) ({unsigned long __y=(x); \
+                       (__bswap_16(__y>>16)|__bswap_16(__y)<<16); })
+
+#define bswap_16(x) __bswap_16 (x)
+
+#define bswap_32(x) __bswap_32 (x)
+
+#endif /* byteswap.h */
diff --git a/common/arch/generic/defines/endian.h b/common/arch/generic/defines/endian.h
new file mode 100644 (file)
index 0000000..ed59493
--- /dev/null
@@ -0,0 +1,16 @@
+#ifndef        _ENDIAN_H
+#define        _ENDIAN_H       1
+
+#define        __LITTLE_ENDIAN 1234
+#define        __BIG_ENDIAN    4321
+#define        __PDP_ENDIAN    3412
+
+#if defined(__i386__) || defined(SDCC)
+#define __BYTE_ORDER __LITTLE_ENDIAN
+#endif
+
+#if defined(__H8300__) || defined(__H8500__) || defined (__H8300H__) ||  defined(__W65__) || defined (__H8300S__) || defined (__m68k__)
+#define __BYTE_ORDER __BIG_ENDIAN
+#endif
+
+#endif /* endian.h */
diff --git a/common/board/Makefile b/common/board/Makefile
new file mode 100644 (file)
index 0000000..f595272
--- /dev/null
@@ -0,0 +1,14 @@
+# Generic directory or leaf node makefile for OCERA make framework
+
+ifndef MAKERULES_DIR
+MAKERULES_DIR := $(shell ( old_pwd="" ;  while [ ! -e Makefile.rules ] ; do if [ "$$old_pwd" == `pwd`  ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) )
+endif
+
+ifeq ($(MAKERULES_DIR),)
+all : default
+.DEFAULT::
+       @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
+else   
+include $(MAKERULES_DIR)/Makefile.rules
+endif
+
diff --git a/common/board/Makefile.omk b/common/board/Makefile.omk
new file mode 100644 (file)
index 0000000..deeeeb7
--- /dev/null
@@ -0,0 +1,3 @@
+# -*- makefile -*-
+
+SUBDIRS = $(BOARD)
diff --git a/common/doc/TODO b/common/doc/TODO
new file mode 100644 (file)
index 0000000..4b6a6ec
--- /dev/null
@@ -0,0 +1,4 @@
+
+* Check whether the rs232 library installed the interrupt handler
+   properly. If a user forget to call excptvect_init, wired things
+   happens.
diff --git a/common/doc/documentation.xml b/common/doc/documentation.xml
new file mode 100644 (file)
index 0000000..34b18fb
--- /dev/null
@@ -0,0 +1,101 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
+"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd">
+<book>
+  <title>H8S/2638 Software Documentation</title>
+
+  <chapter>
+    <title>Introdution</title>
+
+    <para></para>
+  </chapter>
+
+  <chapter>
+    <title>Make-system</title>
+
+    <para></para>
+
+    <section>
+      <title>Rules structure</title>
+
+      <para></para>
+
+      <section>
+        <title>Configuration files</title>
+
+        <para></para>
+      </section>
+    </section>
+
+    <section>
+      <title>H8S/2638 Specifics</title>
+
+      <para></para>
+    </section>
+  </chapter>
+
+  <chapter>
+    <title>Linking</title>
+
+    <para>Linking of an application is done depending on the linker script.
+    There are several variants of the linker script:</para>
+
+    <variablelist>
+      <varlistentry>
+        <term>bload</term>
+
+        <listitem>
+          <para></para>
+        </listitem>
+      </varlistentry>
+
+      <varlistentry>
+        <term>boot</term>
+
+        <listitem>
+          <para></para>
+        </listitem>
+      </varlistentry>
+
+      <varlistentry>
+        <term>flash</term>
+
+        <listitem>
+          <para></para>
+        </listitem>
+      </varlistentry>
+
+      <varlistentry>
+        <term>ram</term>
+
+        <listitem>
+          <para></para>
+        </listitem>
+      </varlistentry>
+    </variablelist>
+  </chapter>
+
+  <chapter>
+    <title>Booting</title>
+
+    <para></para>
+
+    <section>
+      <title>Bloader</title>
+
+      <para></para>
+    </section>
+  </chapter>
+
+  <chapter>
+    <title>Utilities</title>
+
+    <para></para>
+
+    <section>
+      <title>tohit</title>
+
+      <para></para>
+    </section>
+  </chapter>
+</book>
\ No newline at end of file
diff --git a/common/doc/doxygen.css b/common/doc/doxygen.css
new file mode 100644 (file)
index 0000000..c4b9309
--- /dev/null
@@ -0,0 +1,310 @@
+BODY,H1,H2,H3,H4,H5,H6,P,CENTER,TD,TH,UL,DL,DIV {
+       font-family: Geneva, Arial, Helvetica, sans-serif;
+}
+BODY,TD {
+       font-size: 90%;
+}
+H1 {
+       text-align: center;
+       font-size: 160%;
+}
+H2 {
+       font-size: 120%;
+}
+H3 {
+       font-size: 100%;
+}
+CAPTION { font-weight: bold }
+DIV.qindex {
+       width: 100%;
+       background-color: #e8eef2;
+       border: 1px solid #84b0c7;
+       text-align: center;
+       margin: 2px;
+       padding: 2px;
+       line-height: 140%;
+}
+DIV.nav {
+       width: 100%;
+       background-color: #e8eef2;
+       border: 1px solid #84b0c7;
+       text-align: center;
+       margin: 2px;
+       padding: 2px;
+       line-height: 140%;
+}
+DIV.navtab {
+       background-color: #e8eef2;
+       border: 1px solid #84b0c7;
+       text-align: center;
+       margin: 2px;
+       margin-right: 15px;
+       padding: 2px;
+}
+TD.navtab {
+       font-size: 70%;
+}
+A.qindex {
+       text-decoration: none;
+       font-weight: bold;
+       color: #1A419D;
+}
+A.qindex:visited {
+       text-decoration: none;
+       font-weight: bold;
+       color: #1A419D
+}
+A.qindex:hover {
+       text-decoration: none;
+       background-color: #ddddff;
+}
+A.qindexHL {
+       text-decoration: none;
+       font-weight: bold;
+       background-color: #6666cc;
+       color: #ffffff;
+       border: 1px double #9295C2;
+}
+A.qindexHL:hover {
+       text-decoration: none;
+       background-color: #6666cc;
+       color: #ffffff;
+}
+A.qindexHL:visited { text-decoration: none; background-color: #6666cc; color: #ffffff }
+A.el { text-decoration: none; font-weight: bold }
+A.elRef { font-weight: bold }
+A.code:link { text-decoration: none; font-weight: normal; color: #0000FF}
+A.code:visited { text-decoration: none; font-weight: normal; color: #0000FF}
+A.codeRef:link { font-weight: normal; color: #0000FF}
+A.codeRef:visited { font-weight: normal; color: #0000FF}
+A:hover { text-decoration: none; background-color: #f2f2ff }
+DL.el { margin-left: -1cm }
+.fragment {
+       font-family: monospace;
+       font-size: 95%;
+}
+PRE.fragment {
+       border: 1px solid #CCCCCC;
+       background-color: #f5f5f5;
+       margin-top: 4px;
+       margin-bottom: 4px;
+       margin-left: 2px;
+       margin-right: 8px;
+       padding-left: 6px;
+       padding-right: 6px;
+       padding-top: 4px;
+       padding-bottom: 4px;
+}
+DIV.ah { background-color: black; font-weight: bold; color: #ffffff; margin-bottom: 3px; margin-top: 3px }
+TD.md { background-color: #F4F4FB; font-weight: bold; }
+TD.mdPrefix {
+       background-color: #F4F4FB;
+       color: #606060;
+       font-size: 80%;
+}
+TD.mdname1 { background-color: #F4F4FB; font-weight: bold; color: #602020; }
+TD.mdname { background-color: #F4F4FB; font-weight: bold; color: #602020; width: 600px; }
+DIV.groupHeader {
+       margin-left: 16px;
+       margin-top: 12px;
+       margin-bottom: 6px;
+       font-weight: bold;
+}
+DIV.groupText { margin-left: 16px; font-style: italic; font-size: 90% }
+BODY {
+       background: white;
+       color: black;
+       margin-right: 20px;
+       margin-left: 20px;
+}
+TD.indexkey {
+       background-color: #e8eef2;
+       font-weight: bold;
+       padding-right  : 10px;
+       padding-top    : 2px;
+       padding-left   : 10px;
+       padding-bottom : 2px;
+       margin-left    : 0px;
+       margin-right   : 0px;
+       margin-top     : 2px;
+       margin-bottom  : 2px;
+       border: 1px solid #CCCCCC;
+}
+TD.indexvalue {
+       background-color: #e8eef2;
+       font-style: italic;
+       padding-right  : 10px;
+       padding-top    : 2px;
+       padding-left   : 10px;
+       padding-bottom : 2px;
+       margin-left    : 0px;
+       margin-right   : 0px;
+       margin-top     : 2px;
+       margin-bottom  : 2px;
+       border: 1px solid #CCCCCC;
+}
+TR.memlist {
+   background-color: #f0f0f0; 
+}
+P.formulaDsp { text-align: center; }
+IMG.formulaDsp { }
+IMG.formulaInl { vertical-align: middle; }
+SPAN.keyword       { color: #008000 }
+SPAN.keywordtype   { color: #604020 }
+SPAN.keywordflow   { color: #e08000 }
+SPAN.comment       { color: #800000 }
+SPAN.preprocessor  { color: #806020 }
+SPAN.stringliteral { color: #002080 }
+SPAN.charliteral   { color: #008080 }
+.mdTable {
+       border: 1px solid #868686;
+       background-color: #F4F4FB;
+}
+.mdRow {
+       padding: 8px 10px;
+}
+.mdescLeft {
+       padding: 0px 8px 4px 8px;
+       font-size: 80%;
+       font-style: italic;
+       background-color: #FAFAFA;
+       border-top: 1px none #E0E0E0;
+       border-right: 1px none #E0E0E0;
+       border-bottom: 1px none #E0E0E0;
+       border-left: 1px none #E0E0E0;
+       margin: 0px;
+}
+.mdescRight {
+       padding: 0px 8px 4px 8px;
+       font-size: 80%;
+       font-style: italic;
+       background-color: #FAFAFA;
+       border-top: 1px none #E0E0E0;
+       border-right: 1px none #E0E0E0;
+       border-bottom: 1px none #E0E0E0;
+       border-left: 1px none #E0E0E0;
+       margin: 0px;
+}
+.memItemLeft {
+       padding: 1px 0px 0px 8px;
+       margin: 4px;
+       border-top-width: 1px;
+       border-right-width: 1px;
+       border-bottom-width: 1px;
+       border-left-width: 1px;
+       border-top-color: #E0E0E0;
+       border-right-color: #E0E0E0;
+       border-bottom-color: #E0E0E0;
+       border-left-color: #E0E0E0;
+       border-top-style: solid;
+       border-right-style: none;
+       border-bottom-style: none;
+       border-left-style: none;
+       background-color: #FAFAFA;
+       font-size: 80%;
+}
+.memItemRight {
+       padding: 1px 8px 0px 8px;
+       margin: 4px;
+       border-top-width: 1px;
+       border-right-width: 1px;
+       border-bottom-width: 1px;
+       border-left-width: 1px;
+       border-top-color: #E0E0E0;
+       border-right-color: #E0E0E0;
+       border-bottom-color: #E0E0E0;
+       border-left-color: #E0E0E0;
+       border-top-style: solid;
+       border-right-style: none;
+       border-bottom-style: none;
+       border-left-style: none;
+       background-color: #FAFAFA;
+       font-size: 80%;
+}
+.memTemplItemLeft {
+       padding: 1px 0px 0px 8px;
+       margin: 4px;
+       border-top-width: 1px;
+       border-right-width: 1px;
+       border-bottom-width: 1px;
+       border-left-width: 1px;
+       border-top-color: #E0E0E0;
+       border-right-color: #E0E0E0;
+       border-bottom-color: #E0E0E0;
+       border-left-color: #E0E0E0;
+       border-top-style: none;
+       border-right-style: none;
+       border-bottom-style: none;
+       border-left-style: none;
+       background-color: #FAFAFA;
+       font-size: 80%;
+}
+.memTemplItemRight {
+       padding: 1px 8px 0px 8px;
+       margin: 4px;
+       border-top-width: 1px;
+       border-right-width: 1px;
+       border-bottom-width: 1px;
+       border-left-width: 1px;
+       border-top-color: #E0E0E0;
+       border-right-color: #E0E0E0;
+       border-bottom-color: #E0E0E0;
+       border-left-color: #E0E0E0;
+       border-top-style: none;
+       border-right-style: none;
+       border-bottom-style: none;
+       border-left-style: none;
+       background-color: #FAFAFA;
+       font-size: 80%;
+}
+.memTemplParams {
+       padding: 1px 0px 0px 8px;
+       margin: 4px;
+       border-top-width: 1px;
+       border-right-width: 1px;
+       border-bottom-width: 1px;
+       border-left-width: 1px;
+       border-top-color: #E0E0E0;
+       border-right-color: #E0E0E0;
+       border-bottom-color: #E0E0E0;
+       border-left-color: #E0E0E0;
+       border-top-style: solid;
+       border-right-style: none;
+       border-bottom-style: none;
+       border-left-style: none;
+       color: #606060;
+       background-color: #FAFAFA;
+       font-size: 80%;
+}
+.search     { color: #003399;
+              font-weight: bold;
+}
+FORM.search {
+              margin-bottom: 0px;
+              margin-top: 0px;
+}
+INPUT.search { font-size: 75%;
+               color: #000080;
+               font-weight: normal;
+               background-color: #e8eef2;
+}
+TD.tiny      { font-size: 75%;
+}
+a {
+       color: #1A41A8;
+}
+a:visited {
+       color: #2A3798;
+}
+.dirtab { padding: 4px;
+          border-collapse: collapse;
+          border: 1px solid #84b0c7;
+}
+TH.dirtab { background: #e8eef2;
+            font-weight: bold;
+}
+HR { height: 1px;
+     border: none;
+     border-top: 1px solid black;
+}
+
diff --git a/common/libs4c/Makefile b/common/libs4c/Makefile
new file mode 100644 (file)
index 0000000..f595272
--- /dev/null
@@ -0,0 +1,14 @@
+# Generic directory or leaf node makefile for OCERA make framework
+
+ifndef MAKERULES_DIR
+MAKERULES_DIR := $(shell ( old_pwd="" ;  while [ ! -e Makefile.rules ] ; do if [ "$$old_pwd" == `pwd`  ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) )
+endif
+
+ifeq ($(MAKERULES_DIR),)
+all : default
+.DEFAULT::
+       @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
+else   
+include $(MAKERULES_DIR)/Makefile.rules
+endif
+
diff --git a/common/libs4c/Makefile.omk b/common/libs4c/Makefile.omk
new file mode 100644 (file)
index 0000000..5baf5ed
--- /dev/null
@@ -0,0 +1,3 @@
+# -*- makefile -*-
+
+SUBDIRS = $(ALL_OMK_SUBDIRS)
diff --git a/common/libs4c/cmdproc/Makefile b/common/libs4c/cmdproc/Makefile
new file mode 100644 (file)
index 0000000..f595272
--- /dev/null
@@ -0,0 +1,14 @@
+# Generic directory or leaf node makefile for OCERA make framework
+
+ifndef MAKERULES_DIR
+MAKERULES_DIR := $(shell ( old_pwd="" ;  while [ ! -e Makefile.rules ] ; do if [ "$$old_pwd" == `pwd`  ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) )
+endif
+
+ifeq ($(MAKERULES_DIR),)
+all : default
+.DEFAULT::
+       @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
+else   
+include $(MAKERULES_DIR)/Makefile.rules
+endif
+
diff --git a/common/libs4c/cmdproc/Makefile.omk b/common/libs4c/cmdproc/Makefile.omk
new file mode 100644 (file)
index 0000000..e1dc76a
--- /dev/null
@@ -0,0 +1,8 @@
+lib_LIBRARIES = cmdproc
+cmdproc_SOURCES = cmd_proc.c cmd_io.c cmd_io_line.c cmdio_std.c cmdio_std_line.c
+
+include_HEADERS = cmd_proc.h cmdio_std.h
+
+bin_PROGRAMS = cmdproc_test
+cmdproc_test_SOURCES = cmdproc_test.c
+cmdproc_test_LIBS = cmdproc
diff --git a/common/libs4c/cmdproc/README b/common/libs4c/cmdproc/README
new file mode 100644 (file)
index 0000000..acba9a4
--- /dev/null
@@ -0,0 +1,7 @@
+Platform independent files for command processor.
+
+Besides the main library, you can find here also the definition of
+cmdio which uses standard input/output and an example application,
+which shows almost all features of the command processor.
+
+Platform dependent cmdios should be placed in cmdprocio library.
diff --git a/common/libs4c/cmdproc/cmd_bth.h b/common/libs4c/cmdproc/cmd_bth.h
new file mode 100644 (file)
index 0000000..9df4d62
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef CMD_BTH_H
+#define CMD_BTH_H
+
+/* Bluetooth specific */
+
+cmd_des_t const **cmd_bth;
+
+extern cmd_io_t cmd_io_bth;
+
+int cmd_bth_line_out(cmd_io_t *cmd_io);
+
+int cmd_bth_line_in(cmd_io_t *cmd_io);
+
+char *cmd_bth_rdline(cmd_io_t *cmd_io, int mode);
+
+int cmd_bth_processor_run(void);
+
+#endif
diff --git a/common/libs4c/cmdproc/cmd_io.c b/common/libs4c/cmdproc/cmd_io.c
new file mode 100644 (file)
index 0000000..c9de6bd
--- /dev/null
@@ -0,0 +1,51 @@
+#include <cmd_proc.h>
+#include <string.h>
+#include <types.h>
+
+/** 
+ * Blocking call to print a string.
+ * 
+ * @param cmd_io cmd_io structure.
+ * @param str Zero terminated string to print.
+ * 
+ * @return Upon successful completion, puts() shall return a
+ * non-negative number. In case of error, negative number is returned.
+ */
+int cmd_io_puts(cmd_io_t *cmd_io, const char *str)
+{
+  int ret;
+  unsigned len;
+  if (!str) return 0;
+  len = strlen(str);
+  do {
+      ret = cmd_io_write(cmd_io, str, len);
+      if (ret > 0) {
+          str+=ret;
+          len-=ret;
+      }
+  } while (ret>=0 && len>0);
+  return ret;
+}
+
+int cmd_io_write_bychar(cmd_io_t *cmd_io,const void *buf,int count)
+{
+  int cn=0;
+  __u8* p=(__u8*)buf;
+  while(count--&&(*cmd_io->putc)(cmd_io,*p++)>=0){
+    cn++;
+  }
+  return cn;
+}
+
+int cmd_io_read_bychar(cmd_io_t *cmd_io,void *buf,int count)
+{
+  int cn=0;
+  int ch;
+  __u8* p=(__u8*)buf;
+  while(count--&&(ch=(*cmd_io->getc)(cmd_io))>=0){
+    *p++=ch;
+    cn++;
+  }
+  return cn;
+}
+
diff --git a/common/libs4c/cmdproc/cmd_io_line.c b/common/libs4c/cmdproc/cmd_io_line.c
new file mode 100644 (file)
index 0000000..6e85cdc
--- /dev/null
@@ -0,0 +1,127 @@
+/*******************************************************************
+  Components for embedded applications builded for
+  laboratory and medical instruments firmware  
+  cmd_proc.h - text line command processor
+               designed for instruments control and setup
+              over RS-232 line
+  Copyright (C) 2001 by Pavel Pisa pisa@cmp.felk.cvut.cz
+            (C) 2002 by PiKRON Ltd. http://www.pikron.com
+            (C) 2007 by Michal Sojka <sojkam1@fel.cvut.cz>
+
+  This file can be used and copied according to next
+  license alternatives
+   - MPL - Mozilla Public License
+   - GPL - GNU Public License
+   - other license provided by project originators
+ *******************************************************************/
+
+#include <cmd_proc.h>
+#include "cmd_proc_priv.h"
+#include <string.h>
+
+/* cmd_io line editor */
+
+/** 
+ * Adds new characters to an edit line buffer.
+ * 
+ * @param elb Edit line buffer.
+ * @param ch character to add.
+ * 
+ * @return 1 in case of end of line, 0 otherwise.
+ */
+int cmd_ed_line_buf(ed_line_buf_t *elb, int ch)
+{
+  int lastch=elb->lastch;
+  if (elb->flg&FL_ELB_INSEND)
+    return -1;
+  elb->lastch=ch;
+  if(!lastch){
+    elb->inbuf=0;               /* Start new line */
+  }
+  if((!(elb->flg&FL_ELB_NOCRLF))&&((ch=='\n')||(ch=='\r'))){
+    if((lastch=='\n')&&(ch=='\r')) /* Empty line, ignore it. */
+      return 0;
+    elb->lastch=0;               /* End the string */
+    elb->buf[elb->inbuf]=0;
+    return 1;
+  }
+  if(elb->inbuf>=elb->alloc-1){ 
+    /* try to reallocate buffer len not implemented */
+    return 0;
+  }
+  elb->buf[elb->inbuf++]=ch;  
+  return 0;
+}
+
+int cmd_io_line_putc(cmd_io_t *cmd_io,int ch)
+{
+  return cmd_ed_line_buf(cmd_io->priv.ed_line.out,ch);
+}
+
+/* Process pending output */
+int cmd_io_line_out(cmd_io_t *cmd_io)
+{
+  cmd_io_t* io_stack=cmd_io->priv.ed_line.io_stack;
+  ed_line_buf_t* ed_line_out=cmd_io->priv.ed_line.out;
+  
+  if(!ed_line_out->inbuf) return 0;
+  if(!io_stack)
+    return -1;
+  
+  if(!(ed_line_out->flg&FL_ELB_INSEND)){
+    ed_line_out->flg|=FL_ELB_INSEND;
+    ed_line_out->lastch=0;
+  }
+  while(cmd_io_putc(io_stack, ed_line_out->buf[ed_line_out->lastch])>=0){
+    if(++ed_line_out->lastch >= ed_line_out->inbuf){
+      ed_line_out->lastch=0;
+      ed_line_out->inbuf=0;
+      ed_line_out->flg&=~FL_ELB_INSEND;
+      return 0;
+    }
+  }
+  return 1;
+}
+
+/* process input */
+int cmd_io_line_in(cmd_io_t *cmd_io)
+{
+  int ch;
+  cmd_io_t* io_stack = cmd_io->priv.ed_line.io_stack;
+  ed_line_buf_t *ed_line_in = cmd_io->priv.ed_line.in;
+
+  if(!io_stack)
+      return -1;
+
+  while((ch=cmd_io_getc(io_stack))>=0){
+//    DPRINT("Added %c (%d)\n", ch, ch);
+    int eol = cmd_ed_line_buf(ed_line_in,ch);
+    if(eol){
+      if(ed_line_in->flg&FL_ELB_ECHO){
+        while(cmd_io_putc(io_stack,'\r')<0);
+        while(cmd_io_putc(io_stack,'\n')<0);
+      }
+      return 1;
+    }
+    else 
+      if(ed_line_in->flg&FL_ELB_ECHO) {
+        while(cmd_io_putc(io_stack,ch)<0);
+      }
+  }
+  return 0;
+}
+
+/* char *cmd_io_line_rdline(cmd_io_t *cmd_io, int mode) */
+/* { */
+/*   int ret; */
+/*   while((ret=cmd_rs232_line_in(cmd_io))==0) */
+/*     if(!mode) break; */
+/*   if(ret<=0) return NULL; */
+/*   return cmd_io->priv.ed_line.in->buf; */
+/* } */
+
+/* Local Variables: */
+/* c-basic-offset: 2 */
+/* End */
diff --git a/common/libs4c/cmdproc/cmd_proc.c b/common/libs4c/cmdproc/cmd_proc.c
new file mode 100644 (file)
index 0000000..e8ada3d
--- /dev/null
@@ -0,0 +1,405 @@
+/*******************************************************************
+  Components for embedded applications builded for
+  laboratory and medical instruments firmware  
+  cmd_proc.c - text command processor
+               enables to define multilevel tables of commands
+              which can be received from more inputs and send reply
+              to respective I/O stream output
+  Copyright (C) 2001 by Pavel Pisa pisa@cmp.felk.cvut.cz
+            (C) 2002 by PiKRON Ltd. http://www.pikron.com
+            (C) 2007 by Michal Sojka <sojkam1@fel.cvut.cz>
+
+  This file can be used and copied according to next
+  license alternatives
+   - MPL - Mozilla Public License
+   - GPL - GNU Public License
+   - other license provided by project originators
+ *******************************************************************/
+
+#include <types.h>
+#include <ctype.h>
+#include <string.h>
+#include <stdlib.h>
+#include <cmd_proc.h>
+#include "cmd_proc_priv.h"
+
+/* cmd_line processing */
+
+char *skip_white(char *p)
+{
+  while(isspace((__u8)*p)) p++;
+  return p;
+}
+
+/**
+ *
+ * @return Zero if no command was given in line, -CMDERR_BADCMD if
+ * command is not known or has no function assigned to it. If a
+ * command is executed, then the return value of the command function
+ * is returned.
+ */
+int proc_cmd_line(cmd_io_t *cmd_io, cmd_des_t const **des_arr, char *line)
+{
+  char *p=line, *r, *var;
+  const cmd_des_t *des;
+  cmd_des_t const **arr_stack[CMD_ARR_STACK_SIZE];
+  int arr_stack_sp=0;
+  char *param[10];
+  short cmd_len;
+  int res, i, parcnt; 
+  param[0]=p=skip_white(p);
+  if(!*p) return 0;
+  /* Determine the name of the command */
+  if(!isalnum((__u8)*p)){
+    cmd_len=1;
+    p++;
+  }else{
+    while(isalnum((__u8)*p)) p++;
+    cmd_len=p-param[0];
+  }
+  param[1]=param[2]=skip_white(p);
+  
+  /* Find the command in des_arr */
+  while(1){
+    des=*(des_arr++);
+    if(!des){
+      if(!arr_stack_sp) break;
+      des_arr=arr_stack[--arr_stack_sp];
+      continue;
+    }
+    if(des==CMD_DES_CONTINUE_AT_ID){
+      /* list continues at new address */
+      des_arr=(const cmd_des_t **)*des_arr;continue;
+    }
+    if(des==CMD_DES_INCLUDE_SUBLIST_ID){
+      /* list includes commands from sublists */
+      if(arr_stack_sp>=CMD_ARR_STACK_SIZE){
+        des_arr++;
+      }else{
+        arr_stack[arr_stack_sp++]=des_arr+1;
+        des_arr=(const cmd_des_t **)*des_arr;
+        continue;
+      }
+    }
+    p=param[0];
+    if(!(r=des->name))continue;
+    i=cmd_len;
+    var=NULL;
+    while(*r){
+      while((*p==*r)&&i){i--;r++;p++;};
+      if((i==0)&&!*r) break;    /* We've found the command */
+      if((*r=='?')&&i){
+        if(!var) var=p;
+       p++; r++; i--;
+       continue;
+      }
+      if((*r=='#')&&i&&isdigit((__u8)*p)){
+       if(!var) var=p;
+       p++; r++; i--;
+       continue;
+      }
+      if(*r=='*'){
+       if(!var) var=p;
+       i=0;
+       break;
+      }
+      i=1;
+      break;      
+    }
+    if(i!=0) continue; /* Try next command */
+    if(des->mode&CDESM_OPCHR){
+      if(!param[2])continue;
+      if(!*param[2])continue;
+      param[3]=skip_white(param[2]+1);
+      param[1]=var;
+      parcnt=4;
+    }else{
+      parcnt=1;
+      if(var){param[1]=var;parcnt++;}
+      if(param[parcnt])
+        if(*param[parcnt]) parcnt++;
+    }
+    param[parcnt]=0;
+    if(!des->fnc) return -CMDERR_BADCMD;
+    res=des->fnc(cmd_io,des,param);
+    return res;
+  }
+  return -CMDERR_BADCMD;
+}
+
+/**
+ * Checks whether the the command allows the operation specified by
+ * opchar.
+ *
+ * @return opchar if perimssions allow this operations, -CMDERR_WRPERM
+ * or -CMDERR_RDPERM if the operation is not allows, -CMDERR_OPCHAR,
+ * if the opchar is not ':' or '?'.
+ */
+int cmd_opchar_check(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
+{ 
+  int opchar=*param[2];
+  if(opchar==':'){
+    if(!(des->mode&CDESM_WR)){
+      return -CMDERR_WRPERM;
+    }
+  }else if(opchar=='?'){
+    if(!(des->mode&CDESM_RD)){
+      return -CMDERR_RDPERM;
+    }
+  }
+  else return -CMDERR_OPCHAR;
+  return opchar;
+}
+
+int cmd_do_stamp(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
+{
+  if(*param[2]!=':') return -CMDERR_OPCHAR;
+  cmd_io_write(cmd_io,param[0],param[2]-param[0]);
+  cmd_io_putc(cmd_io,'=');
+  cmd_io_write(cmd_io,param[3],strlen(param[3]));
+  return 0; 
+}
+
+/**
+ * Converts integer to string.
+ * @param s Buffer to store the result.
+ * @param val Value to convert.
+ * @param len Minimal width of the converted strign (padded by ' ').
+ * @param form Unused.
+ * @return 0
+ */
+int i2str(char *s,long val,int len,int form)
+{
+  int sig;
+  int dig=1;
+  int padd=0;
+  unsigned base=10;
+  unsigned long u;
+  unsigned long mag;
+  unsigned long num;
+  if((sig=val<0))num=-val;
+    else num=val;
+  mag=1;
+  u=base*mag;
+  while(num>=u){
+    dig++;
+    mag=u;
+    if(mag>~(unsigned long)0/base) break;
+    u*=base;
+  }
+  
+  if(len){
+    padd=len-dig;
+    if(sig) padd--;
+  }
+  if(padd<0) padd=0;
+  
+  while(padd){*(s++)=' ';padd--;}
+  if(sig) *(s++)='-';
+  
+  while(dig--){
+    *(s++)='0'+num/mag;
+    num=num%mag;
+    mag/=base;
+  }
+  *s=0;
+  return 0;
+}
+
+/**
+ * Implementation of a command that reads or writes short pointed by des->info[0].
+ */
+int cmd_do_rw_short(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
+{
+  short val;
+  short *ptr;
+  int opchar;
+
+  if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
+  ptr=(short*)(des->info[0]);
+  if(opchar==':'){
+    val=atoi(param[3]);
+    *ptr=val;
+  }else{
+    return cmd_opchar_replong(cmd_io, param, (long)*ptr, 0, 0);
+  }
+  return 0; 
+}
+
+/**
+ * Implementation of a command that reads or writes int pointed by des->info[0].
+ */
+int cmd_do_rw_int(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
+{
+  int val;
+  int *ptr;
+  int opchar;
+
+  if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
+  ptr=(int*)(des->info[0]);
+  if(opchar==':'){
+    val=atoi(param[3]);
+    *ptr=val;
+  }else{
+    return cmd_opchar_replong(cmd_io, param, (long)*ptr, 0, 0);
+  }
+  return 0; 
+}
+
+
+/**
+ * Implementation of a command that reads or writes long pointed by des->info[0].
+ */
+int cmd_do_rw_long(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
+{
+  long val;
+  long *ptr;
+  int opchar;
+
+  if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
+  ptr=(long*)(des->info[0]);
+  if(opchar==':'){
+    val=atol(param[3]);
+    *ptr=val;
+  }else{
+    return cmd_opchar_replong(cmd_io, param, (long)*ptr, 0, 0);
+  }
+  return 0; 
+}
+
+/**
+ * Prints name of the command followed by '=' and the value of val.
+ */
+int cmd_opchar_replong(cmd_io_t *cmd_io, char *param[], long val,int len,int form)
+{
+  char str[20];
+  cmd_io_write(cmd_io,param[0],param[2]-param[0]);
+  cmd_io_putc(cmd_io,'=');
+  i2str(str,val,len,form);
+  cmd_io_write(cmd_io,str,strlen(str));
+  return 0;
+}
+
+#if 0
+
+int cmd_do_rw_bitflag(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
+{
+  unsigned val,mask,*pval;
+  int opchar;
+
+  if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
+  pval=(unsigned*)(des->info[0]);
+  mask=(unsigned)(des->info[1]);
+  if(opchar==':'){
+    val=*param[3];
+    if(val=='0')
+      atomic_clear_mask(mask,pval);
+    else if(val=='1')
+      atomic_set_mask(mask,pval);
+    else return -CMDERR_BADPAR;
+  }else{
+    cmd_io_write(cmd_io,param[0],param[2]-param[0]);
+    cmd_io_putc(cmd_io,'=');
+    cmd_io_putc(cmd_io,*pval&mask?'1':'0');
+  }
+  
+  return 0;
+}
+
+#endif
+
+/**
+ * Implementation of help command
+ */
+int cmd_do_help(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
+{
+  char *help;
+  char *filt=param[1];
+  const cmd_des_t **des_arr=*(const cmd_des_t ***)des->info[0];
+  cmd_des_t const **arr_stack[CMD_ARR_STACK_SIZE];
+  int arr_stack_sp=0;
+
+  if (cmd_io->priv.ed_line.io_stack)
+    cmd_io = cmd_io->priv.ed_line.io_stack;
+  
+  if(filt) {
+    filt=skip_white(filt);
+    if(!*filt) filt=NULL;
+  }
+  cmd_io_puts(cmd_io,"Help for commands\n");
+  while(1){
+    des=*(des_arr++);
+    if(!des){
+      if(!arr_stack_sp) break;
+      des_arr=arr_stack[--arr_stack_sp];
+      continue;
+    }
+    if(des==CMD_DES_CONTINUE_AT_ID){
+      /* list continues at new address */
+      des_arr=(const cmd_des_t **)*des_arr;
+      continue;
+    }
+    if(des==CMD_DES_INCLUDE_SUBLIST_ID){
+      /* list includes commands from sublists */
+      if(arr_stack_sp>=CMD_ARR_STACK_SIZE){
+        des_arr++;
+      }else{
+        arr_stack[arr_stack_sp++]=des_arr+1;
+        des_arr=(const cmd_des_t **)*des_arr;
+        continue;
+      }
+    }
+    if(des->name){
+      if(!filt || !strncmp(des->name,filt,strlen(filt))) {
+        help=des->help;
+        if(!help) help="?";
+        cmd_io_puts(cmd_io,des->name);
+        cmd_io_puts(cmd_io," - ");
+        cmd_io_puts(cmd_io,help);
+        cmd_io_puts(cmd_io, "\r\n");
+      }
+    }
+  }
+  return 0;
+}
+
+/**
+ * Executes command processor. This function is usually called from
+ * application's main loop.
+ */
+int cmd_processor_run(cmd_io_t *cmd_io, cmd_des_t const **commands)
+{
+  int val;
+
+  if(cmd_io_line_out(cmd_io))
+    return 1; /* Not all the output has been sent. */
+       
+  if(cmd_io_line_in(cmd_io)<=0)
+    return 0; /* Input line not finished or error. */
+
+  if(commands){
+    val=proc_cmd_line(cmd_io, commands, cmd_io->priv.ed_line.in->buf);
+  }else{
+    val=-CMDERR_BADCMD;
+  }
+
+  if(cmd_io->priv.ed_line.out->inbuf){
+    cmd_io_putc(cmd_io,'\r');
+    cmd_io_putc(cmd_io,'\n');
+  }else if(val<0){
+    char s[20];
+    cmd_io_puts(cmd_io,"ERROR ");
+    i2str(s,-val,0,0);
+    cmd_io_puts(cmd_io,s);
+    cmd_io_putc(cmd_io,'\r');
+    cmd_io_putc(cmd_io,'\n');
+  }
+  return 1; /* Command line processed */
+}
+
+
+/* Local Variables: */
+/* c-basic-offset: 2 */
+/* End */
diff --git a/common/libs4c/cmdproc/cmd_proc.h b/common/libs4c/cmdproc/cmd_proc.h
new file mode 100644 (file)
index 0000000..2284578
--- /dev/null
@@ -0,0 +1,151 @@
+/*******************************************************************
+  Components for embedded applications builded for
+  laboratory and medical instruments firmware  
+  cmd_proc.h - text line command processor
+               designed for instruments control and setup
+              over RS-232 line
+  Copyright (C) 2001 by Pavel Pisa pisa@cmp.felk.cvut.cz
+            (C) 2002 by PiKRON Ltd. http://www.pikron.com
+            (C) 2007 by Michal Sojka <sojkam1@fel.cvut.cz>
+
+  This file can be used and copied according to next
+  license alternatives
+   - MPL - Mozilla Public License
+   - GPL - GNU Public License
+   - other license provided by project originators
+ *******************************************************************/
+
+#ifndef _CMD_PROC_H_
+#define _CMD_PROC_H_
+
+#define FL_ELB_ECHO   0x10      /* Read characters are echoed back */
+#define FL_ELB_INSEND 0x20      /* The line is currently being sent */
+#define FL_ELB_NOCRLF 0x40      /* CR and/or LF will not start the new line */
+#define CMD_DES_CONTINUE_AT_ID ((cmd_des_t*)1)
+#define CMD_DES_INCLUDE_SUBLIST_ID ((cmd_des_t*)2)
+#define CMD_DES_CONTINUE_AT(list)     CMD_DES_CONTINUE_AT_ID,((cmd_des_t*)list)
+#define CMD_DES_INCLUDE_SUBLIST(list) CMD_DES_INCLUDE_SUBLIST_ID,((cmd_des_t*)list)
+/* generic cmd_io tructure */
+
+/* buffer for in/out line collection */
+typedef struct{
+  int  flg;                     /* FL_ELB_xxx */
+  int  inbuf;                   /* Index to store new characters */
+  int  alloc;                   /* Size of the buffer pointed by buf */
+  int  maxlen;
+  int  lastch;                  /* Last characted added to the buffer.
+                                 * If FL_ELB_INSEND is set, lastch is
+                                 * index of last sent char. */
+  char *buf;
+} ed_line_buf_t;
+
+/* Structure for character input output. It is used either for direct
+ * access to IO device or for buffered IO. In the later case,
+ * priv.edline is used to store buffer information. */
+typedef struct cmd_io{
+  int (*putc)(struct cmd_io *cmd_io,int ch);
+  int (*getc)(struct cmd_io *cmd_io);
+  int (*write)(struct cmd_io *cmd_io,const void *buf,int count);
+  int (*read)(struct cmd_io *cmd_io,void *buf,int count);
+  union {
+    struct {
+      ed_line_buf_t *in;
+      ed_line_buf_t *out;
+      struct cmd_io *io_stack;
+    } ed_line;
+    struct {
+      long pos;
+      void *ptr;
+    } device;
+  } priv;
+} cmd_io_t;
+
+static inline int cmd_io_putc(struct cmd_io *cmd_io,int ch)
+{ if(!cmd_io->putc) return -1;
+  return (*cmd_io->putc)(cmd_io,ch);
+}
+
+static inline int cmd_io_getc(struct cmd_io *cmd_io)
+{ if(!cmd_io->getc) return -1;
+  return (*cmd_io->getc)(cmd_io);
+}
+
+static inline int cmd_io_write(struct cmd_io *cmd_io,const void *buf,int count)
+{ if(!cmd_io->write) return -1;
+  return (*cmd_io->write)(cmd_io,buf,count);
+}
+
+static inline int cmd_io_read(struct cmd_io *cmd_io,void *buf,int count)
+{ if(!cmd_io->read) return -1;
+  return (*cmd_io->read)(cmd_io,buf,count);
+}
+
+int cmd_io_puts(cmd_io_t *cmd_io, const char *str);
+
+int cmd_io_line_putc(cmd_io_t *cmd_io,int ch);
+
+int cmd_io_write_bychar(cmd_io_t *cmd_io,const void *buf,int count);
+
+int cmd_io_read_bychar(cmd_io_t *cmd_io,void *buf,int count);
+
+/* command descriptions */
+
+#define CDESM_OPCHR    0x10    /* Command uses operation character */
+#define CDESM_RD       0x01    /* Value read is possible */
+#define CDESM_WR       0x02    /* Value write is possible */
+#define CDESM_RW       (CDESM_RD|CDESM_WR) /* Both */
+
+typedef struct cmd_des{
+  int code;
+  int mode;
+  char *name;
+  char *help;
+  int (*fnc)(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]);
+  char *info[];
+} cmd_des_t;
+
+#define CMDERR_BADCMD 2
+#define CMDERR_OPCHAR 10
+#define CMDERR_WRPERM 11
+#define CMDERR_RDPERM 12
+#define CMDERR_GARBAG 13
+#define CMDERR_BADSEP 14
+#define CMDERR_BADCFG 15
+#define CMDERR_NOMEM  16
+#define CMDERR_BADPAR 20
+#define CMDERR_BADREG 40
+#define CMDERR_BSYREG 41
+#define CMDERR_BADDIO 50
+#define CMDERR_NODEV  60
+#define CMDERR_TIMEOUT 61
+#define CMDERR_EIO    62
+
+int cmd_opchar_check(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]);
+
+int proc_cmd_line(cmd_io_t *cmd_io, cmd_des_t const **des_arr, char *line);
+
+int i2str(char *s,long val,int len,int form);
+
+int cmd_do_stamp(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]);
+
+int cmd_do_help(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]);
+
+int cmd_do_rw_short(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]);
+
+int cmd_do_rw_int(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]);
+
+int cmd_do_rw_long(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]);
+
+int cmd_do_rw_bitflag(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]);
+
+int cmd_opchar_replong(cmd_io_t *cmd_io, char *param[], long val,int len,int form);
+
+int cmd_processor_run(cmd_io_t *cmd_io, cmd_des_t const **commands);
+
+#endif /* _CMD_PROC_H_ */
+
+/* Local Variables: */
+/* c-basic-offset: 2 */
+/* End */
diff --git a/common/libs4c/cmdproc/cmd_proc_priv.h b/common/libs4c/cmdproc/cmd_proc_priv.h
new file mode 100644 (file)
index 0000000..699c127
--- /dev/null
@@ -0,0 +1,14 @@
+#ifndef CMD_PROC_PRIV_H
+#define CMD_PROC_PRIV_H
+
+/* The maximal depth of command arrays nesting (see CMD_DES_INCLUDE_SUBLIST). */
+#define CMD_ARR_STACK_SIZE 4    
+
+char *skip_white(char *p);
+int cmd_io_line_out(cmd_io_t *cmd_io);
+int cmd_io_line_in(cmd_io_t *cmd_io);
+
+#include <stdio.h>
+#define DPRINT(...) fprintf(stderr, __VA_ARGS__)
+
+#endif
diff --git a/common/libs4c/cmdproc/cmdio_std.c b/common/libs4c/cmdproc/cmdio_std.c
new file mode 100644 (file)
index 0000000..e1c2b52
--- /dev/null
@@ -0,0 +1,31 @@
+/* Definitions of IOs */
+#include <unistd.h> 
+#include <cmd_proc.h>
+#include <stdio.h>
+
+static int std_putc(cmd_io_t *cmd_io, int ch) { 
+    int r=putchar(ch);
+    fflush(stdout);
+    return r;
+}
+
+//int _getkey_nb(void);
+static int std_getc(cmd_io_t *cmd_io) { 
+    return getchar();           /* On UNIX, we don't use non-blocking
+                                 * variant. */
+    //return _getkey_nb();
+}
+static int std_write(cmd_io_t *cmd_io, const void *buf, int count) {
+    return write(1, buf, count);
+}
+static int std_read(cmd_io_t *cmd_io, void *buf, int count) {
+    return read(0, buf, count); 
+}
+
+cmd_io_t cmd_io_std={
+    putc:std_putc,
+    getc:std_getc,
+    write:std_write,
+    read:std_read
+};
+
diff --git a/common/libs4c/cmdproc/cmdio_std.h b/common/libs4c/cmdproc/cmdio_std.h
new file mode 100644 (file)
index 0000000..a778d8d
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef CMD_IO_STD_H
+#define CMD_IO_STD_H
+
+const cmd_io_t cmd_io_std_line;
+
+#endif
diff --git a/common/libs4c/cmdproc/cmdio_std_line.c b/common/libs4c/cmdproc/cmdio_std_line.c
new file mode 100644 (file)
index 0000000..2de0865
--- /dev/null
@@ -0,0 +1,42 @@
+#include <cmd_proc.h>
+#include <string.h>
+#include "cmdio_std.h"
+
+#define ED_LINE_CHARS 80
+
+char ed_line_in_std[ED_LINE_CHARS+1];
+char ed_line_out_std[ED_LINE_CHARS+1];
+
+
+ed_line_buf_t ed_line_buf_in_std={
+//    flg:FL_ELB_ECHO,
+    inbuf:0,
+    alloc:sizeof(ed_line_in_std),
+    maxlen:0,
+    lastch:0,
+    buf:ed_line_in_std
+};
+
+ed_line_buf_t ed_line_buf_out_std={
+    flg:FL_ELB_NOCRLF,
+    inbuf:0,
+    alloc:sizeof(ed_line_out_std),
+    maxlen:0,
+    lastch:0,
+    buf:ed_line_out_std
+};
+
+extern cmd_io_t cmd_io_std;
+const cmd_io_t cmd_io_std_line={
+    putc:cmd_io_line_putc,
+    getc:NULL,
+    write:cmd_io_write_bychar,
+    read:NULL,
+    priv:{
+        ed_line:{
+            in: &ed_line_buf_in_std,
+            out:&ed_line_buf_out_std,
+            io_stack:&cmd_io_std
+        }
+    }
+};
diff --git a/common/libs4c/cmdproc/cmdproc_test.c b/common/libs4c/cmdproc/cmdproc_test.c
new file mode 100644 (file)
index 0000000..0db4bd0
--- /dev/null
@@ -0,0 +1,172 @@
+#include <cmd_proc.h>
+#include <stdio.h>
+
+int cmd_do_testopchar(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
+{
+  int opchar;
+
+  opchar=cmd_opchar_check(cmd_io,des,param);
+  if(opchar<0) return opchar;
+
+  printf(
+      "cmd_do_testopchar called\n"
+      "param[0]=%s\n"
+      "param[1]=%s\n"
+      "param[2]=%s\n"
+      "param[3]=%s\n"
+      "opchar=%c\n", 
+      param[0], param[1], param[2], param[3], opchar);
+
+  return 0;
+}
+
+int cmd_do_testparam(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
+{
+  printf(
+      "cmd_do_testparam called\n"
+      "param[0]=%s\n"
+      "param[1]=%s\n"
+      "param[2]=%s\n",
+      param[0], param[1], param[2]);
+
+  return 0;
+}
+
+int cmd_do_testerror(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
+{
+  return -1234;
+}
+
+int cmd_do_test(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
+{
+    printf("This is the simplest command\n");
+    return 0;
+}
+
+int cmd_do_testcmdio(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
+{
+    cmd_io_puts(cmd_io, "The first line of text\n");
+    cmd_io_puts(cmd_io, "The second line of text\n");
+    /* Only ED_LINE_CHARS character can be sent. */
+    return 0;
+}
+
+cmd_des_t const **cmd_list;
+
+cmd_des_t const cmd_des_help={
+    0, 0,
+    "HELP","prints help for commands",
+    cmd_do_help,{(char*)&cmd_list}};
+
+int val;
+cmd_des_t const cmd_des_val={
+    0, CDESM_OPCHR|CDESM_RW,
+    "VAL","use ':' or '?' to store/read value of an integer variable",
+    cmd_do_rw_int, {(char*)&val}};
+
+cmd_des_t const cmd_des_valro={
+    0, CDESM_OPCHR|CDESM_RD,
+    "VALRO","read only access to an integer variable",
+    cmd_do_rw_int, {(char*)&val}};
+
+cmd_des_t const cmd_des_valwo={
+    0, CDESM_OPCHR|CDESM_WR,
+    "VALWO","write only access to an integer variable",
+    cmd_do_rw_int, {(char*)&val}};
+
+cmd_des_t const cmd_des_opchar_test={
+    0, CDESM_OPCHR|CDESM_RW,
+    "OPCHAR","opchar test (use ':' or '?' as suffix)",
+    cmd_do_testopchar};
+
+cmd_des_t const cmd_des_opchar_testro={
+    0, CDESM_OPCHR|CDESM_RD,
+    "OPCHARRO","opchar test (only '?' is allowed)",
+    cmd_do_testopchar};
+
+cmd_des_t const cmd_des_test={
+    0, 0,
+    "TEST","the simplest command",
+    cmd_do_test};
+
+cmd_des_t const cmd_des_testio={
+    0, 0,
+    "TESTIO","test of cmd_io inside functions (universal way to print results)",
+    cmd_do_testcmdio};
+
+cmd_des_t const cmd_des_param={
+    0, 0,
+    "PARAM","test of parameters",
+    cmd_do_testparam};
+
+cmd_des_t const cmd_des_prefix={
+    0, 0,
+    "PREFIX*","suffix of the command is supplied as a parametr",
+    cmd_do_testparam};
+
+cmd_des_t const cmd_des_num={
+    0, 0,
+    "NUM##","suffix of the command (two digits) is supplied as a parametr",
+    cmd_do_testparam};
+
+cmd_des_t const cmd_des_char={
+    0, 0,
+    "CHAR?","suffix of the command (one character) is supplied as a parametr",
+    cmd_do_testparam};
+
+cmd_des_t const cmd_des_charmid={
+    0, 0,
+    "CHAR?MID","middle character of the command is supplied as a parametr",
+    cmd_do_testparam};
+
+cmd_des_t const cmd_des_hiddedn={
+    0, 0,
+    "HIDDEN","should not be available",
+    cmd_do_test};
+
+cmd_des_t const cmd_des_error={
+    0, 0,
+    "TESTERROR","should produce an error",
+    cmd_do_testerror};
+
+/* Command lists */
+
+cmd_des_t const *cmd_list_1[]={
+    &cmd_des_val,
+    &cmd_des_valro,
+    &cmd_des_valwo,
+    &cmd_des_opchar_test,
+    &cmd_des_opchar_testro,
+    NULL
+    };
+
+cmd_des_t const *cmd_list_2[]={
+    &cmd_des_test,
+    &cmd_des_testio,
+    &cmd_des_param,
+    &cmd_des_prefix,
+    &cmd_des_num,
+    &cmd_des_char,
+    &cmd_des_charmid,
+    NULL
+    };
+
+cmd_des_t const *cmd_list_main[]={
+  &cmd_des_help,
+  &cmd_des_error,
+  CMD_DES_INCLUDE_SUBLIST(cmd_list_1),
+  CMD_DES_CONTINUE_AT(cmd_list_2),
+  &cmd_des_hiddedn,
+  NULL
+};
+
+cmd_des_t const **cmd_list = cmd_list_main;
+
+cmd_io_t cmd_io_std_line;
+
+int main()
+{
+    while (1) {
+        cmd_processor_run(&cmd_io_std_line, cmd_list_main);
+    }
+}
diff --git a/common/libs4c/cmdprocio/Makefile b/common/libs4c/cmdprocio/Makefile
new file mode 100644 (file)
index 0000000..f595272
--- /dev/null
@@ -0,0 +1,14 @@
+# Generic directory or leaf node makefile for OCERA make framework
+
+ifndef MAKERULES_DIR
+MAKERULES_DIR := $(shell ( old_pwd="" ;  while [ ! -e Makefile.rules ] ; do if [ "$$old_pwd" == `pwd`  ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) )
+endif
+
+ifeq ($(MAKERULES_DIR),)
+all : default
+.DEFAULT::
+       @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
+else   
+include $(MAKERULES_DIR)/Makefile.rules
+endif
+
diff --git a/common/libs4c/cmdprocio/Makefile.omk b/common/libs4c/cmdprocio/Makefile.omk
new file mode 100644 (file)
index 0000000..3868f55
--- /dev/null
@@ -0,0 +1,7 @@
+lib_LIBRARIES = cmdprocio
+
+cmdprocio_SOURCES += cmdio_rs232.c cmdio_rs232_line.c
+
+ifeq ($(CONFIG_BLUETOOTH),y)
+cmdprocio_SOURCES += cmdio_bth.c cmdio_bth_line.c
+endif
diff --git a/common/libs4c/cmdprocio/cmdio_bth.c b/common/libs4c/cmdprocio/cmdio_bth.c
new file mode 100644 (file)
index 0000000..bd7bb3b
--- /dev/null
@@ -0,0 +1,70 @@
+/*******************************************************************
+  Components for embedded applications builded for
+  laboratory and medical instruments firmware  
+  cmd_bth.c - interconnection of text command processor
+                with RS-232 line
+  Copyright (C) 2001 by Pavel Pisa pisa@cmp.felk.cvut.cz
+            (C) 2002 by PiKRON Ltd. http://www.pikron.com
+
+ *******************************************************************/
+
+#include <cmd_proc.h>
+#include <bth_inface.h>
+
+#define ED_LINE_CHARS 80
+
+/* cmd_io_t cmd_io_bth_dev; */
+
+/* char ed_line_chars_bth_in[ED_LINE_CHARS+1]; */
+/* char ed_line_chars_bth_out[ED_LINE_CHARS+1]; */
+
+/* ed_line_buf_t ed_line_buf_bth_in={ */
+/*   flg:FL_ELB_ECHO, */
+/*   inbuf:0, */
+/*   alloc:sizeof(ed_line_chars_bth_in), */
+/*   maxlen:0, */
+/*   lastch:0, */
+/*   buf:ed_line_chars_bth_in */
+/* }; */
+
+/* ed_line_buf_t ed_line_buf_bth_out={ */
+/*   flg:FL_ELB_NOCRLF, */
+/*   inbuf:0, */
+/*   alloc:sizeof(ed_line_chars_bth_out), */
+/*   maxlen:0, */
+/*   lastch:0, */
+/*   buf:ed_line_chars_bth_out */
+/* }; */
+
+/* cmd_io_t cmd_io_bth={ */
+/*   putc:cmd_io_putc_ed_line, */
+/*   getc:NULL, */
+/*   write:cmd_io_write_bychar, */
+/*   read:NULL, */
+/*   priv:{ */
+/*     ed_line:{ */
+/*       in: &ed_line_buf_bth_in, */
+/*       out:&ed_line_buf_bth_out, */
+/*       io_stack:&cmd_io_bth_dev */
+/*     } */
+/*   } */
+/* }; */
+
+int cmd_io_putc_bth(struct cmd_io *cmd_io,int ch)
+{ 
+  return bth_inface_sendch(ch,0); //=0; //sci_bth_sendch(ch,IMPLIC_NUM_SERIAL_PORT);;
+}
+
+int cmd_io_getc_bth(struct cmd_io *cmd_io)
+{ 
+  return bth_inface_recch(0);//=-1; //sci_bth_recch(IMPLIC_NUM_SERIAL_PORT);
+}
+
+cmd_io_t cmd_io_bth={
+  putc:cmd_io_putc_bth,
+  getc:cmd_io_getc_bth,
+  write:cmd_io_write_bychar,
+  read:cmd_io_read_bychar
+};
diff --git a/common/libs4c/cmdprocio/cmdio_bth_line.c b/common/libs4c/cmdprocio/cmdio_bth_line.c
new file mode 100644 (file)
index 0000000..dd17e0e
--- /dev/null
@@ -0,0 +1,41 @@
+#include <cmd_proc.h>
+#include <string.h>
+
+#define ED_LINE_CHARS 80
+
+char ed_line_in_bth[ED_LINE_CHARS+1];
+char ed_line_out_bth[ED_LINE_CHARS+1];
+
+
+ed_line_buf_t ed_line_buf_in_bth={
+    flg:FL_ELB_ECHO,
+    inbuf:0,
+    alloc:sizeof(ed_line_in_bth),
+    maxlen:0,
+    lastch:0,
+    buf:ed_line_in_bth
+};
+
+ed_line_buf_t ed_line_buf_out_bth={
+    flg:FL_ELB_NOCRLF,
+    inbuf:0,
+    alloc:sizeof(ed_line_out_bth),
+    maxlen:0,
+    lastch:0,
+    buf:ed_line_out_bth
+};
+
+extern cmd_io_t cmd_io_bth;
+const cmd_io_t cmd_io_bth_line={
+    putc:cmd_io_line_putc,
+    getc:NULL,
+    write:cmd_io_write_bychar,
+    read:NULL,
+    priv:{
+        ed_line:{
+            in: &ed_line_buf_in_bth,
+            out:&ed_line_buf_out_bth,
+            io_stack:&cmd_io_bth
+        }
+    }
+};
diff --git a/common/libs4c/cmdprocio/cmdio_rs232.c b/common/libs4c/cmdprocio/cmdio_rs232.c
new file mode 100644 (file)
index 0000000..a1d284a
--- /dev/null
@@ -0,0 +1,38 @@
+/*******************************************************************
+  Components for embedded applications builded for
+  laboratory and medical instruments firmware  
+  cmd_rs232.c - interconnection of text command processor
+                with RS-232 line
+  Copyright (C) 2001 by Pavel Pisa pisa@cmp.felk.cvut.cz
+            (C) 2002 by PiKRON Ltd. http://www.pikron.com
+
+  This file can be used and copied according to next
+  license alternatives
+   - MPL - Mozilla Public License
+   - GPL - GNU Public License
+   - other license provided by project originators
+
+ *******************************************************************/
+
+#include <cmd_proc.h>
+#include <periph/sci_rs232.h>
+
+static int cmd_io_putc_rs232(struct cmd_io *cmd_io,int ch)
+{ 
+  return sci_rs232_sendch(ch, sci_rs232_chan_default);
+}
+
+static int cmd_io_getc_rs232(struct cmd_io *cmd_io)
+{ 
+  return sci_rs232_recch(sci_rs232_chan_default);
+}
+
+cmd_io_t cmd_io_rs232={
+  putc:cmd_io_putc_rs232,
+  getc:cmd_io_getc_rs232,
+  write:cmd_io_write_bychar,
+  read:cmd_io_read_bychar
+};
+
diff --git a/common/libs4c/cmdprocio/cmdio_rs232_line.c b/common/libs4c/cmdprocio/cmdio_rs232_line.c
new file mode 100644 (file)
index 0000000..c32cbc2
--- /dev/null
@@ -0,0 +1,41 @@
+#include <cmd_proc.h>
+#include <string.h>
+
+#define ED_LINE_CHARS 80
+
+char ed_line_in_rs232[ED_LINE_CHARS+1];
+char ed_line_out_rs232[ED_LINE_CHARS+1];
+
+
+ed_line_buf_t ed_line_buf_in_rs232={
+    flg:FL_ELB_ECHO,
+    inbuf:0,
+    alloc:sizeof(ed_line_in_rs232),
+    maxlen:0,
+    lastch:0,
+    buf:ed_line_in_rs232
+};
+
+ed_line_buf_t ed_line_buf_out_rs232={
+    flg:FL_ELB_NOCRLF,
+    inbuf:0,
+    alloc:sizeof(ed_line_out_rs232),
+    maxlen:0,
+    lastch:0,
+    buf:ed_line_out_rs232
+};
+
+extern cmd_io_t cmd_io_rs232;
+const cmd_io_t cmd_io_rs232_line={
+    putc:cmd_io_line_putc,
+    getc:NULL,
+    write:cmd_io_write_bychar,
+    read:NULL,
+    priv:{
+        ed_line:{
+            in: &ed_line_buf_in_rs232,
+            out:&ed_line_buf_out_rs232,
+            io_stack:&cmd_io_rs232
+        }
+    }
+};
diff --git a/common/libs4c/misc/Makefile b/common/libs4c/misc/Makefile
new file mode 100644 (file)
index 0000000..f595272
--- /dev/null
@@ -0,0 +1,14 @@
+# Generic directory or leaf node makefile for OCERA make framework
+
+ifndef MAKERULES_DIR
+MAKERULES_DIR := $(shell ( old_pwd="" ;  while [ ! -e Makefile.rules ] ; do if [ "$$old_pwd" == `pwd`  ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) )
+endif
+
+ifeq ($(MAKERULES_DIR),)
+all : default
+.DEFAULT::
+       @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
+else   
+include $(MAKERULES_DIR)/Makefile.rules
+endif
+
diff --git a/common/libs4c/misc/Makefile.omk b/common/libs4c/misc/Makefile.omk
new file mode 100644 (file)
index 0000000..b2bf2bc
--- /dev/null
@@ -0,0 +1,10 @@
+lib_LIBRARIES = misc
+
+#shared_LIBRARIES = 
+
+#include_HEADERS  = usb.h usb_spec.h usbdebug.h usb_stdreq.h
+
+include_HEADERS = utils.h
+
+misc_SOURCES = utils.c 
+
diff --git a/common/libs4c/misc/utils.c b/common/libs4c/misc/utils.c
new file mode 100644 (file)
index 0000000..87c5036
--- /dev/null
@@ -0,0 +1,128 @@
+/*******************************************************************
+  Components for embedded applications builded for
+  laboratory and medical instruments firmware  
+  utils.c - utilities for reading numbers and parsing of text line
+  Copyright (C) 2001 by Pavel Pisa pisa@cmp.felk.cvut.cz
+            (C) 2002 by PiKRON Ltd. http://www.pikron.com
+
+ *******************************************************************/
+
+#include <types.h>
+#include <system_def.h>
+#include <string.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <stdlib.h>
+
+/* string parse and input routines */
+
+/**
+ * si_skspace - Skip space and blank characters
+ * @ps:                Pointer to character poiter into parsed string
+ *
+ * Functions checks character **@ps by isspace() category and
+ * moves *@ps pointer after last blank character. If there is at least one
+ * blank character, returns 1, else returns 0.
+ */
+int si_skspace(char **ps)
+{
+  char *p=*ps;
+  if (!isspace((__u8)*(p++))) return 0;
+  while(isspace((__u8)*(p++)));
+  *ps=p-1;
+  return 1;
+}
+
+/**
+ * si_fndsep - Finds field separator character
+ * @ps:                Pointer to character pointer into parsed string
+ * @sepchrs:   String of possible separator characters.
+ *
+ * Function skips blanks, then checks, if next character belongs
+ * to @sepchrs list. If character belongs, function returns found
+ * character and *@ps points after separator else returns -1.
+ */
+int si_fndsep(char **ps,char *sepchrs)
+{
+  char c;
+  si_skspace(ps);
+  c=**ps;
+  if(!c) return 0;
+  if(!strchr(sepchrs,c)) return -1;
+  (*ps)++;
+  return c;
+}
+
+/**
+ * si_alnumn - Reads alphanumeric value
+ * @ps:                Pointer to character pointer into parsed string
+ * @pout:      Pointer to read value buffer
+ * @n:         Maximal number of read characters.
+ *
+ * Function reads alphanumeric characters and stores them in @pout,
+ * if there is no more alphanumeric characters or @n is reached,
+ * it returns count of stored characters.
+ */
+int si_alnumn(char **ps,char *pout,int n)
+{
+  char *p=*ps;
+  char c;
+  int ret=0;
+  while(isalnum((__u8)(c=*p))) {
+    p++;
+    *(pout++)=c;
+    if(++ret==n) break;
+  }
+  *pout=0;
+  *ps=p;
+  return ret;
+}
+
+/**
+ * si_alphan - Reads alphabetic value
+ * @ps:                Pointer to character pointer into parsed string
+ * @pout:      Pointer to read value buffer
+ * @n:         Maximal number of read characters.
+ *
+ * Function reads alphabetic characters and stores them in @pout,
+ * if there is no more alphabetic characters or @n is reached,
+ * it returns count of stored characters.
+ */
+int si_alphan(char **ps,char *pout,int n)
+{
+  char *p=*ps;
+  char c;
+  int ret=0;
+  while(isalpha((__u8)(c=*p))) {
+    p++;
+    *(pout++)=c;
+    if(++ret==n) break;
+  }
+  *pout=0;
+  *ps=p;
+  return ret;
+}
+
+/**
+ * si_long - Reads numeric value
+ * @ps:                Pointer to character pointer into parsed string
+ * @val:       Pointer to long integer value buffer
+ * @base:      Base of converted number, 0 means select by C rules
+ *
+ * Function reads digits and converts them to longint value.
+ * It stops at end of the string or if non digit character is reached.
+ * Returns 1 for successful conversion or -1 if no character can be
+ * converted. Pointer *@ps paints after last character belonging to 
+ * numeric input.
+ */
+int si_long(char **ps,long *val,int base)
+{
+  char *p;
+  *val=strtol(*ps,&p,base);
+  if(*ps==p) return -1;
+  *ps=p;
+  return 1;
+}
+
diff --git a/common/libs4c/misc/utils.h b/common/libs4c/misc/utils.h
new file mode 100644 (file)
index 0000000..c4a9288
--- /dev/null
@@ -0,0 +1,23 @@
+#ifndef _UTILS_DEF_H_
+#define _UTILS_DEF_H_
+
+
+/* skip space/blank characters, return 0 if no space found */
+int si_skspace(char **ps);
+
+/* skip spaces and checks for <sepchars>, */
+/* if no such char return -1, else char is returned */
+int si_fndsep(char **ps,char *sepchrs);
+
+/* reads max <n> letters and digits to <pout> */
+/* returns number of readed chars */
+int si_alnumn(char **ps,char *pout,int n);
+
+/* same as above, but only letters are read */
+int si_alphan(char **ps,char *pout,int n);
+
+/* reads long number, if no digit found return -1 */
+int si_long(char **ps,long *val,int base);
+
+#endif /* _UTILS_DEF_H_ */
+
diff --git a/common/libs4c/usb/Makefile b/common/libs4c/usb/Makefile
new file mode 100644 (file)
index 0000000..f595272
--- /dev/null
@@ -0,0 +1,14 @@
+# Generic directory or leaf node makefile for OCERA make framework
+
+ifndef MAKERULES_DIR
+MAKERULES_DIR := $(shell ( old_pwd="" ;  while [ ! -e Makefile.rules ] ; do if [ "$$old_pwd" == `pwd`  ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) )
+endif
+
+ifeq ($(MAKERULES_DIR),)
+all : default
+.DEFAULT::
+       @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
+else   
+include $(MAKERULES_DIR)/Makefile.rules
+endif
+
diff --git a/common/libs4c/usb/Makefile.omk b/common/libs4c/usb/Makefile.omk
new file mode 100644 (file)
index 0000000..5f17698
--- /dev/null
@@ -0,0 +1 @@
+SUBDIRS = base pdiusb more
diff --git a/common/libs4c/usb/base/Makefile b/common/libs4c/usb/base/Makefile
new file mode 100644 (file)
index 0000000..f595272
--- /dev/null
@@ -0,0 +1,14 @@
+# Generic directory or leaf node makefile for OCERA make framework
+
+ifndef MAKERULES_DIR
+MAKERULES_DIR := $(shell ( old_pwd="" ;  while [ ! -e Makefile.rules ] ; do if [ "$$old_pwd" == `pwd`  ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) )
+endif
+
+ifeq ($(MAKERULES_DIR),)
+all : default
+.DEFAULT::
+       @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
+else   
+include $(MAKERULES_DIR)/Makefile.rules
+endif
+
diff --git a/common/libs4c/usb/base/Makefile.omk b/common/libs4c/usb/base/Makefile.omk
new file mode 100644 (file)
index 0000000..c522d2b
--- /dev/null
@@ -0,0 +1,19 @@
+default_CONFIG = CONFIG_USB_BASE=y
+
+ifeq ($(CONFIG_USB_BASE),y) 
+lib_LIBRARIES = usbbase
+
+#shared_LIBRARIES = 
+
+#include_HEADERS  = 
+
+nobase_include_HEADERS = usb/usb.h usb/usb_spec.h usb/usb_stdreq.h usb/usbdebug.h
+
+usbbase_SOURCES = usb.c usbdebug.c 
+
+#lib_LOADLIBES = 
+#bin_PROGRAMS = 
+endif #CONFIG_USB_BASE
+
+
+
diff --git a/common/libs4c/usb/base/usb.c b/common/libs4c/usb/base/usb.c
new file mode 100644 (file)
index 0000000..829e035
--- /dev/null
@@ -0,0 +1,335 @@
+/*****************************************************/
+/***   Module : USB module                         ***/
+/***   Author : Roman Bartosinski (C) 28.04.2002   ***/
+/***   Modify : 08.08.2002, 16.04.2003             ***/
+/*****************************************************/
+
+//#include "hal.h"
+#include <stdio.h>
+#include <string.h>
+#include <system_def.h>
+#include <endian.h>
+#if __BYTE_ORDER == __BIG_ENDIAN
+  #include <byteswap.h>
+#endif
+
+//#include <usb/pdiusb.h> /* to by tu pak nemelo bejt vubec ... */
+#include <usb/usb.h>
+#include <usb/usbdebug.h>
+
+#include <usb/usb_stdreq.h> /* temporary include - standard control request responses */
+
+/* ep0 buffer */
+  xdata unsigned char ep0_buffer[ MAX_CONTROL_XFER_DATA_SIZE];
+
+  
+/* usb initialize */
+  int usb_init( usb_device_t *udev) {
+    int ret = 0;
+    usb_debug_print( DEBUG_LEVEL_LOW, ("init_usb\r\n"));
+    /* create dynamic fields - endpoints */
+
+    udev->ep_events = 0;
+    udev->flags = 0;
+    udev->configuration = 0;
+    //udev->altinterface = 0;
+    udev->ep0.udev = udev;
+    udev->ep0.flags = USB_STATE_IDLE;
+    udev->ep0.epnum = 0;
+
+//    usb_init_stdreq_fnc( udev);
+
+    if ( usb_udev_is_fnc(udev,init)) {
+      ret = usb_udev_init( udev);
+    }
+    return ret;
+  }
+
+  
+// connecting to USB by SoftConnect
+  int usb_connect( usb_device_t *udev) {
+    int ret = 0;
+    usb_debug_print( DEBUG_LEVEL_LOW,("USB:ON\n"));
+
+    udev->ep_events = 0;
+    udev->flags = 0;
+    udev->configuration = 0;
+    //udev->altinterface = 0;
+    udev->ep0.flags &= ~USB_STATE_MASK; //state = USB_STATE_IDLE;
+
+    if ( usb_udev_is_fnc(udev,connect)) {
+      ret = usb_udev_connect( udev);
+    }
+    return ret;
+  }
+
+  
+  int usb_disconnect( usb_device_t *udev) {
+    int ret = 0;
+    usb_debug_print( DEBUG_LEVEL_LOW,("USB:OFF\n"));
+
+    udev->flags &= ~USB_FLAG_CONFIGURED;
+    udev->configuration = 0;
+    udev->ep_events = 0;
+    //udev->altinterface = 0;
+    udev->ep0.flags &= ~USB_STATE_MASK; //state = USB_STATE_IDLE;
+
+    if ( usb_udev_is_fnc(udev,disconnect)) {
+      ret = usb_udev_disconnect( udev);
+    }
+    return ret;
+  }
+
+  
+  void usb_stall( usb_ep_t *ep) {
+    usb_debug_print( DEBUG_LEVEL_HIGH, ("USB:STALL %1d\n", ep->epnum));
+    if ( usb_udev_is_fnc(ep->udev,stall)) {
+      usb_udev_stall( ep);
+    }
+  }
+
+  
+  int usb_check_events( usb_device_t *udev)
+  {
+    int ret = 0;
+    if ( usb_udev_is_fnc( udev, check_events)) {
+      ret = usb_udev_check_events( udev);
+    }
+    return ret;
+  }
+
+
+// ************************************
+// ***  Control transfer functions  ***
+// ************************************
+
+  void usb_complete_control_transfer(usb_ep_t *ep0, int status) {
+    usb_debug_print( DEBUG_LEVEL_HIGH, ( "CCT:st=%d", status));
+   #ifdef USB_WITH_CB_FNC
+    if ( ep0->complete_fnc )
+      ep0->complete_fnc( ep0, status);
+    ep0->next_pkt_fnc = NULL;
+    ep0->complete_fnc = NULL;
+   #endif /*USB_WITH_CB_FNC*/
+    ep0->flags &= ~USB_STATE_MASK; //state = USB_STATE_IDLE;
+  }
+
+/* Send any data in the data phase of the control transfer */
+  void usb_send_control_data( usb_device_t *udev, unsigned char *pData, unsigned short len) {
+    usb_ep_t *ep0 = &(udev->ep0);
+    usb_debug_print( DEBUG_LEVEL_HIGH, ( "SCD:ptr=%p,s=%d\n", pData, len));
+    ep0->efnc = NULL;
+    ep0->ptr = pData;
+    ep0->actual = 0;
+    if ( ep0->size > len) ep0->size = len;
+    
+    /* Schedule TX processing for later execution */
+    ep0->flags = (ep0->flags & ~USB_STATE_MASK) | USB_STATE_TRANSMIT;
+    udev->flags |= USB_FLAG_EVENT_TX0;
+  }
+
+  void usb_set_control_endfnc( usb_device_t *udev, endfnc_t *efnc) { //REENTRANT_SIGN {
+    udev->ep0.efnc = efnc;
+  }
+
+  void usb_ack_setup( usb_ep_t *ep) {
+    usb_udev_ack_setup(ep->udev);
+  }
+
+  
+/*************************************************************
+ *** Control endpoint0 responses
+ *************************************************************/
+  int usb_control_response( usb_device_t *udev) {
+    int ret = 0;
+    usb_ep_t *ep0 = &(udev->ep0);
+    
+/* response to interrupt BusReset */
+    if ( udev->flags & USB_FLAG_BUS_RESET) {
+      udev->flags &= ~(USB_FLAG_BUS_RESET | USB_FLAG_SUSPEND); // usb_flags.bus_reset = 0; usb_flags.configured = 0;
+      usb_debug_print( DEBUG_LEVEL_MEDIUM, ( "USBreset\n"));
+      ret = 1;
+    }
+/* response to interrupt Suspend */
+    if ( udev->flags & USB_FLAG_SUSPEND) {
+      udev->flags &= ~(USB_FLAG_SUSPEND); //usb_flags.suspend = 0;
+      usb_debug_print( DEBUG_LEVEL_MEDIUM, ( "USBsuspend\n"));
+      ret = 1;
+    }
+
+    
+/* response to interrupt SetupPacket execute response to standard device request or vendor request */
+    if ( udev->flags & USB_FLAG_SETUP) {
+      unsigned char type, req;
+      USB_DEVICE_REQUEST *preq = &(udev->request);
+
+      ep0->ptr = NULL;
+      ep0->size = 0;
+      ep0->actual = 0;
+      ep0->efnc = NULL;
+      ep0->flags &= ~USB_STATE_MASK; //state = USB_STATE_IDLE;
+      udev->flags &= ~USB_FLAG_SETUP;   // usb_flags.setup_packet = 0;
+     #ifdef USB_WITH_CB_FNC
+      ep0->next_pkt_fnc = NULL;
+      ep0->complete_fnc = NULL;
+     #endif /*USB_WITH_CB_FNC*/
+      
+      if ( usb_udev_read_endpoint(ep0, preq, sizeof( USB_DEVICE_REQUEST)) 
+                                   != sizeof( USB_DEVICE_REQUEST)) {
+        usb_udev_stall( ep0);
+        return -1;
+      }
+     #if __BYTE_ORDER == __BIG_ENDIAN
+      preq->wValue  = bswap_16( preq->wValue);
+      preq->wIndex  = bswap_16( preq->wIndex);
+      preq->wLength = bswap_16( preq->wLength);
+     #endif
+      usb_debug_print( DEBUG_LEVEL_MEDIUM,( "SePa:x%02X,x%02X,x%04X,x%04X,x%04X\n", preq->bmRequestType, preq->bRequest, preq->wValue, preq->wIndex, preq->wLength));
+      
+      // acknowledge setup here
+      if(usb_udev_is_fnc( udev, ack_control_setup)) {
+        usb_udev_ack_control_setup(udev);
+      }
+      
+      ep0->size = preq->wLength;
+      if ((( preq->bmRequestType & USB_DATA_DIR_MASK) == USB_DATA_DIR_FROM_HOST) && preq->wLength) {
+        ep0->ptr = ep0_buffer;
+        ep0->flags = (ep0->flags & ~USB_STATE_MASK) | USB_STATE_RECEIVE;
+      }
+      
+      type = preq->bmRequestType & USB_REQUEST_TYPE_MASK;
+      req = preq->bRequest & USB_REQUEST_MASK;
+      if ( type == USB_STANDARD_REQUEST) {
+        int ret = -1;
+        usb_debug_print( DEBUG_LEVEL_HIGH, ( "StdReq-%d\n", req));
+/*        
+        if ( (udev->stdreq[ req]) != NULL) {
+          ret = udev->stdreq[ req]( udev);
+        }
+        if( ret < 0)
+          udev->ack_setup( udev);
+*/          
+        switch( req) {
+          case USB_REQUEST_GET_STATUS:        ret=usb_stdreq_get_status( udev); break;
+          case USB_REQUEST_CLEAR_FEATURE:     ret=usb_stdreq_clear_feature( udev); break;
+          case USB_REQUEST_SET_FEATURE:       ret=usb_stdreq_set_feature( udev); break;
+          case USB_REQUEST_SET_ADDRESS:       ret=usb_stdreq_set_address( udev); break;
+
+          case USB_REQUEST_GET_DESCRIPTOR:    ret=usb_stdreq_get_descriptor( udev); break;
+//          case USB_REQUEST_SET_DESCRIPTOR:    break;
+          case USB_REQUEST_GET_CONFIGURATION: ret=usb_stdreq_get_configuration( udev); break;
+          case USB_REQUEST_SET_CONFIGURATION: ret=usb_stdreq_set_configuration( udev); break;
+          case USB_REQUEST_GET_INTERFACE:     ret=usb_stdreq_get_interface( udev); break;
+          case USB_REQUEST_SET_INTERFACE:     ret=usb_stdreq_set_interface( udev); break;
+//          case USB_REQUEST_SYNC_FRAME:        break;
+//          default:                            ret=-1; break;
+        }
+        if (ret<0)
+          usb_udev_stall( ep0);
+      } else {
+        if ( type == USB_VENDOR_REQUEST) {
+//putchar('#');
+         #ifdef USB_WITH_CB_FNC
+          int ret = -1;
+//         if(USBVendorRequestCBFnc != NULL)
+//         ret = USBVendorRequestCBFnc(&usb_ep0, &dreq);
+          if ( udev->vendor_fnc != NULL)
+            ret = udev->vendor_fnc( udev);
+          if ( ret < 0)
+            usb_udev_stall( ep0);
+//         #else /*USB_WITH_CB_FNC*/
+//          if ( USBVendorRequest(&dreq) == -1)
+//          udev->ack_setup( udev);
+         #endif /*USB_WITH_CB_FNC*/
+        } else if ( type == USB_CLASS_REQUEST) {
+         #ifdef USB_WITH_CB_FNC
+          int ret = -1;
+//         if(USBClassRequestCBFnc != NULL)
+//         ret = USBClassRequestCBFnc(&usb_ep0, &dreq);
+          if( udev->class_fnc != NULL)
+            ret = udev->class_fnc( udev);
+          if( ret < 0)
+            usb_udev_stall( ep0);
+//         #else /*USB_WITH_CB_FNC*/
+//          if ( USBClassRequest(&dreq) == -1)
+//          udev->ack_setup( udev);
+         #endif /*USB_WITH_CB_FNC*/
+        } else
+            usb_udev_stall( ep0);
+      }
+      ret = 1;
+    }
+    
+/* response to interrupt Ep0RxInt  - receive data */
+    if ( udev->flags & USB_FLAG_EVENT_RX0) {
+      int i;
+      udev->flags &= ~USB_FLAG_EVENT_RX0;
+      usb_debug_print( DEBUG_LEVEL_MEDIUM, ( "Ep0Rx\n"));
+      if (( ep0->flags & USB_STATE_MASK) == USB_STATE_RECEIVE) {
+        usb_debug_print( DEBUG_LEVEL_HIGH, ( "RCV:p=%04lX,s=%d\n", (unsigned long)ep0->ptr, ep0->size));
+
+        i = usb_udev_read_endpoint(ep0, ep0->ptr, ep0->max_packet_size);
+        ep0->actual += i;
+        ep0->ptr +=i;
+
+       #ifdef USB_WITH_CB_FNC
+       if ( ep0->next_pkt_fnc ) {
+          if( ep0->next_pkt_fnc( ep0, i, USB_NEXT_PKT_REC) < 0) {
+            usb_udev_stall( ep0);
+            return -1;
+          }
+        }
+       #endif /*USB_WITH_CB_FNC*/
+
+        if (( i != ep0->max_packet_size) || ( ep0->actual >= ep0->size)) {
+          usb_complete_control_transfer( ep0, USB_COMPLETE_OK );
+          if ( ep0->efnc) {
+            ep0->efnc(ep0);
+          }
+        }
+      } else {
+        ep0->flags &= ~USB_STATE_MASK; //state = USB_STATE_IDLE;
+      }
+    }
+
+/* response to interrupt Ep0TxInt */
+    if ( udev->flags & USB_FLAG_EVENT_TX0) { 
+      short i = ep0->size - ep0->actual;
+      udev->flags &= ~USB_FLAG_EVENT_TX0;
+//usb_debug_print( DEBUG_LEVEL_LOW, ("0S-%d(%d){%d}\n", ep0->state, ep0->size, ep0->max_packet_size));
+      usb_debug_print( DEBUG_LEVEL_MEDIUM, ( "EP0Tx:i=%d\n", i));
+
+      if (( ep0->flags & USB_STATE_MASK) == USB_STATE_TRANSMIT) {
+      
+        if(i > ep0->max_packet_size) i = ep0->max_packet_size;
+
+        if ( i > 0 ) {
+         #ifdef USB_WITH_CB_FNC
+          if ( ep0->next_pkt_fnc) {
+            if( ep0->next_pkt_fnc( ep0, i, USB_NEXT_PKT_SEND) < 0) {
+              usb_udev_stall( ep0);
+              return -1;
+            }
+          }
+         #endif /*USB_WITH_CB_FNC*/
+    usb_debug_print( DEBUG_LEVEL_HIGH, ("Wr(%d)\n",i));
+          usb_udev_write_endpoint( ep0, ep0->ptr, i);
+          ep0->actual += i;
+          ep0->ptr +=i;
+
+          if( i != ep0->max_packet_size) {
+            /* last packed without full size has been sent, state can change to idle */
+            usb_complete_control_transfer( ep0, USB_COMPLETE_OK );
+          }
+        } else {
+           usb_udev_ack_setup( udev);   // Send zero packet at the end ???
+          usb_complete_control_transfer( ep0, USB_COMPLETE_OK );
+        }
+      }
+      ret = 1;
+    }
+
+    return ret;
+  }
+
+
diff --git a/common/libs4c/usb/base/usb/usb.h b/common/libs4c/usb/base/usb/usb.h
new file mode 100644 (file)
index 0000000..e01e903
--- /dev/null
@@ -0,0 +1,181 @@
+/**************************************************************/
+/***   Module : USB module - header file                    ***/
+/***   Author : Roman Bartosinski (C) 28.04.2002            ***/
+/***   Modify : 08.08.2002                                  ***/
+/***   Rewrite: 05.09.2002                                  ***/
+/**************************************************************/
+
+#ifndef _USB_MODULE_
+  #define _USB_MODULE_
+
+  #include "usb_spec.h"
+  
+#if defined(SDCC) || defined(__KEIL__) || defined(__C51__)
+  /*8051 special handling*/
+  #define REENTRANT_SIGN reentrant
+#else
+  #define xdata           /*nothing*/
+  #define REENTRANT_SIGN  /*nothing*/
+#endif
+
+#define USB_WITH_CB_FNC
+#define USB_WITH_UDEV_FNC
+
+#ifdef USB_WITH_UDEV_FNC
+  #define USB_UDEV_REENTRANT_SIGN REENTRANT_SIGN
+#else /*USB_WITH_UDEV_FNC*/
+  #define USB_UDEV_REENTRANT_SIGN /*nothing*/
+#endif /*USB_WITH_UDEV_FNC*/
+
+/* control endpoint */
+  #define MAX_CONTROL_XFER_DATA_SIZE 8
+
+  struct usb_ep_t;
+  
+  typedef void endfnc_t( struct  usb_ep_t *ep) REENTRANT_SIGN;
+  
+  #define USB_NEXT_PKT_SEND 0
+  #define USB_NEXT_PKT_REC  1
+
+  #define USB_COMPLETE_OK   0
+  #define USB_COMPLETE_FAIL -1
+
+  typedef struct usb_ep_t {
+    struct usb_device_t *udev;      /* pointer to parent device */
+    unsigned short max_packet_size; /* max. size of endpoint package, e.g. PDI_EP0_PACKET_SIZE */
+    unsigned char *ptr;             /* pointer to current transmitted data */
+    unsigned int  size;             /* full size of current transmitted data */
+    unsigned int  actual;           /* transmitted data size */
+    endfnc_t *efnc;                 /* ??? */
+    unsigned char flags;            /* endpoint flags & state - idle,receiving, transmitting  ??? HERE ??? */
+    unsigned char epnum;            /* endpoint number (index) - endpoint0 must be set to 0 */
+    unsigned short event_mask;      /* event(interrupt) mask for this endpoint, e.g. PDI_INT_EP1_IN for pdiusbd1x */
+   #ifdef USB_WITH_CB_FNC
+    int (*next_pkt_fnc)(struct usb_ep_t *ep, int len, int codeval) REENTRANT_SIGN;
+    int (*complete_fnc)(struct usb_ep_t *ep, int status) REENTRANT_SIGN;
+    long user_data;
+   #endif /*USB_WITH_CB_FNC*/
+  } usb_ep_t;
+
+
+/* Vendor & Class functions */
+/*
+ #ifdef USB_WITH_CB_FNC
+  typedef int usb_vendor_extension_fnc_t(usb_ep_t *ep, USB_DEVICE_REQUEST *dreq);
+  extern xdata usb_vendor_extension_fnc_t USBVendorRequestCBFnc;
+
+  typedef int usb_class_extension_fnc_t(usb_ep_t *ep, USB_DEVICE_REQUEST *dreq);
+  extern xdata usb_class_extension_fnc_t USBClassRequestCBFnc;
+ #else //USB_WITH_CB_FNC
+  char USBVendorRequest( USB_DEVICE_REQUEST *dr);
+  char USBClassRequest( USB_DEVICE_REQUEST *dr);
+ #endif //USB_WITH_CB_FNC
+*/
+
+/* USB device */  
+  typedef struct usb_device_t {
+    unsigned char id;               /* device ID ??? */
+    unsigned char flags;            /* usb device flags + endpoint0 events */
+    unsigned char ep_events;        /* one bit for each endpoint (without ep0) event,(bit0 for udev->ep[0], bit1 for udev->ep[1], ...)*/
+    unsigned char configuration;    /* current configuration */
+//    unsigned char interface;        /* current interface */
+//    unsigned char altinterface;     /* current alternative interface */
+
+    //int (stdreq[13])( struct usb_device_t *udev) REENTRANT_SIGN;    /* pointer to array of standard request processing functions */
+    int (*vendor_fnc)( struct usb_device_t *udev) REENTRANT_SIGN;     /* pointer to vendor request processing function */
+    int (*class_fnc)( struct usb_device_t *udev) REENTRANT_SIGN;      /* pointer to class request processing function */
+
+   #ifdef USB_WITH_UDEV_FNC
+    int (*init)( struct usb_device_t *udev) REENTRANT_SIGN;              /* function for hw specific part of initialize usb device */
+    int (*connect)( struct usb_device_t *udev) REENTRANT_SIGN;           /* function for hw specific part of connecting device to usb */
+    int (*disconnect)( struct usb_device_t *udev) REENTRANT_SIGN;        /* function for hw specific part of disconnecting device to usb */
+    void (*ack_setup)( struct usb_device_t *udev) REENTRANT_SIGN;        /* function for hw specific part of control response acknowledge */
+    void (*ack_control_setup)( struct usb_device_t *udev) REENTRANT_SIGN;        /* function for hw specific part of control response acknowledge */
+    int (*check_events)( struct usb_device_t *udev) REENTRANT_SIGN;      /* hw specific part of function for checking events */
+    void (*stall)( usb_ep_t *ep) REENTRANT_SIGN;                         /* hw specific function for stall endpoint */
+    int (*read_endpoint)( usb_ep_t *ep, void *ptr, int size) REENTRANT_SIGN;
+    int (*write_endpoint)( usb_ep_t *ep, const void *ptr, int size) REENTRANT_SIGN;
+   #endif /*USB_WITH_UDEV_FNC*/
+    
+//    USB_DEVICE_REQUEST *request;   /* current usb request - only if there is a valid usb request in processing */
+    USB_DEVICE_REQUEST request;    /* usb device request */
+    
+    unsigned char cntep;           /* number of device endpoints in ep array without EP0 */
+    usb_ep_t ep0;                  /* endpoint 0 */
+    usb_ep_t *ep;                 /* others endpoints in array */
+  } usb_device_t;
+
+
+/* endpoint flags */
+  /* endpoint state */
+  #define USB_STATE_IDLE       0x00
+  #define USB_STATE_TRANSMIT   0x01
+  #define USB_STATE_RECEIVE    0x02
+  #define USB_STATE_MASK       0x03
+
+/* usb_device flags */
+  #define USB_FLAG_CONFIGURED   0x01
+  #define USB_FLAG_BUS_RESET    0x02
+  #define USB_FLAG_SUSPEND      0x04
+  #define USB_FLAG_SETUP        0x08 // setup_packet
+  #define USB_FLAG_REMOTE_WAKE  0x10
+  
+  #define USB_FLAG_EVENT_RX0  0x40
+  #define USB_FLAG_EVENT_TX0  0x80
+  
+
+
+/* device functions - inline ??? */
+  int usb_init( usb_device_t *udev);
+  int usb_connect( usb_device_t *udev);
+  int usb_disconnect( usb_device_t *udev);
+  void usb_stall( usb_ep_t *ep);
+  
+  #define usb_stall_ep0( udev) \
+    do { \
+      usb_stall( &(udev->ep0)); \
+    } while(0)
+
+/* check usb events(interrupts) */
+  int usb_check_events( usb_device_t *udev);
+/* response to standard constrol requests */
+  int usb_control_response( usb_device_t *udev);  
+/* send control data */
+  void usb_send_control_data( usb_device_t *udev, unsigned char *pData, unsigned short len);
+  void usb_set_control_endfnc( usb_device_t *udev, endfnc_t *efnc);// REENTRANT_SIGN;
+  void usb_ack_setup( usb_ep_t *ep);
+
+  
+/* Standard requests functions */
+//  typedef int (*usb_stdreq_fnc_t)( usb_device_t *udev) REENTRANT_SIGN;
+//  extern xdata usb_stdreq_fnc_t usb_standard_requests[13];
+  
+
+#ifdef USB_WITH_UDEV_FNC
+
+  #define usb_udev_is_fnc(_M_udev, _M_fnc) (_M_udev->_M_fnc)
+  
+  #define usb_udev_init(_M_udev) (_M_udev->init(_M_udev))
+  #define usb_udev_connect(_M_udev) (_M_udev->connect(_M_udev))
+  #define usb_udev_disconnect(_M_udev) (_M_udev->disconnect(_M_udev))
+  #define usb_udev_ack_setup(_M_udev) (_M_udev->ack_setup(_M_udev))
+  #define usb_udev_ack_control_setup(_M_udev) (_M_udev->ack_control_setup(_M_udev))
+  #define usb_udev_check_events(_M_udev) (_M_udev->check_events(_M_udev))
+
+  #define usb_udev_stall(_M_ep) ((_M_ep)->udev->stall(_M_ep))
+
+  #define usb_udev_read_endpoint(_M_ep, _M_ptr, _M_size) \
+       ((_M_ep)->udev->read_endpoint(_M_ep, _M_ptr, _M_size))
+
+  #define usb_udev_write_endpoint(_M_ep, _M_ptr, _M_size) \
+       ((_M_ep)->udev->write_endpoint(_M_ep, _M_ptr, _M_size))
+
+#else /*USB_WITH_UDEV_FNC*/
+
+  #define USB_PDI_DIRECT_FNC
+  #include "pdi.h"
+
+#endif /*USB_WITH_UDEV_FNC*/
+#endif
diff --git a/common/libs4c/usb/base/usb/usb_spec.h b/common/libs4c/usb/base/usb/usb_spec.h
new file mode 100644 (file)
index 0000000..73c4859
--- /dev/null
@@ -0,0 +1,228 @@
+/*************************************************/
+/***   Module : USB specification              ***/
+/***   Author : Roman Bartosinski 29.07.2002   ***/
+/***   Modify : 08.08.2002, 14.01.2003         ***/
+/*************************************************/
+
+#ifndef _USB_SPECIFICATIONS_AND_DEFINITIONS_MODULE
+ #define _USB_SPECIFICATIONS_AND_DEFINITIONS_MODULE
+
+/* #include <inttypes.h> */
+#include <types.h>
+
+#ifndef PACKED
+  #ifdef  __GNUC__
+    #define PACKED __attribute__((packed))
+  #else /*__GNUC__*/
+    #define PACKED /*nothing*/
+  #endif /*__GNUC__*/
+#endif
+
+/* this section is from __USB100.H__ and __CHAP9.H__ and define USB constants and structs */
+
+/* *** USB Device Request *** (spec. 9.3) */
+  typedef struct _tag_usb_device_request {
+    uint8_t  bmRequestType;
+    uint8_t  bRequest;
+    uint16_t wValue;
+    uint16_t wIndex;
+    uint16_t wLength;
+  } USB_DEVICE_REQUEST;
+
+/****************************************************************************************/ 
+/*** definitions for USB tranfer standard packets described in USB secif. - chapter 9 ***/
+/****************************************************************************************/
+  #define DEVICE_ADDRESS_MASK   0x7F
+
+/* bmRequestType D7 - Data transfer direction */
+  #define USB_DATA_DIR_MASK        (uint8_t)0x80
+  #define USB_DATA_DIR_FROM_HOST   (uint8_t)0x00
+  #define USB_DATA_DIR_TO_HOST     (uint8_t)0x80
+/* bmRequestType D4..D0 - Recipient */
+  #define USB_RECIPIENT            (uint8_t)0x1F
+  #define USB_RECIPIENT_DEVICE     (uint8_t)0x00
+  #define USB_RECIPIENT_INTERFACE  (uint8_t)0x01
+  #define USB_RECIPIENT_ENDPOINT   (uint8_t)0x02
+  #define USB_RECIPIENT_OTHER      (uint8_t)0x03
+/* bmRequestType D6..D5 - Type */
+  #define USB_REQUEST_TYPE_MASK    (uint8_t)0x60
+  #define USB_STANDARD_REQUEST     (uint8_t)0x00
+  #define USB_CLASS_REQUEST        (uint8_t)0x20
+  #define USB_VENDOR_REQUEST       (uint8_t)0x40
+/* Standard request codes (spec. 9.4) */
+  #define USB_REQUEST_MASK         (uint8_t)0x0F
+  #define USB_REQUEST_GET_STATUS                  0x00
+  #define USB_REQUEST_CLEAR_FEATURE               0x01
+  #define USB_REQUEST_SET_FEATURE                 0x03
+  #define USB_REQUEST_SET_ADDRESS                 0x05
+  #define USB_REQUEST_GET_DESCRIPTOR              0x06
+  #define USB_REQUEST_SET_DESCRIPTOR              0x07
+  #define USB_REQUEST_GET_CONFIGURATION           0x08
+  #define USB_REQUEST_SET_CONFIGURATION           0x09
+  #define USB_REQUEST_GET_INTERFACE               0x0A
+  #define USB_REQUEST_SET_INTERFACE               0x0B
+  #define USB_REQUEST_SYNC_FRAME                  0x0C
+/* Descriptor types (spec. 9.4) */
+  #define USB_DESCRIPTOR_TYPE_DEVICE                    0x01
+  #define USB_DESCRIPTOR_TYPE_CONFIGURATION             0x02
+  #define USB_DESCRIPTOR_TYPE_STRING                    0x03
+  #define USB_DESCRIPTOR_TYPE_INTERFACE                 0x04
+  #define USB_DESCRIPTOR_TYPE_ENDPOINT                  0x05
+  #define USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER          0x06
+  #define USB_DESCRIPTOR_TYPE_OTHER_SPEED_CONFIGURATION 0x07
+  #define USB_DESCRIPTOR_TYPE_POWER                     0x08
+
+/* values for the bits returned by the USB GET_STATUS command (spec. 9.4.5) */
+  #define USB_GETSTATUS_SELF_POWERED                0x01
+  #define USB_GETSTATUS_REMOTE_WAKEUP_ENABLED       0x02
+
+/* values for standard request Clear Feature */
+  #define USB_FEATURE_ENDPOINT_STALL          0x0000
+  #define USB_FEATURE_REMOTE_WAKEUP           0x0001
+
+
+/*******************************************************/
+/*** Standard USB Descriptor Definitions (spec. 9.6) ***/
+/*******************************************************/
+
+/* *** DEVICE *** (spec. 9.6.1) */
+  struct _tag_usb_device_descriptor {
+    uint8_t  bLength;
+    uint8_t  bDescriptorType;
+    uint16_t bcdUSB;
+    uint8_t  bDeviceClass;
+    uint8_t  bDeviceSubClass;
+    uint8_t  bDeviceProtocol;
+    uint8_t  bMaxPacketSize0;
+    uint16_t idVendor;
+    uint16_t idProduct;
+    uint16_t bcdDevice;
+    uint8_t  iManufacturer;
+    uint8_t  iProduct;
+    uint8_t  iSerialNumber;
+    uint8_t  bNumConfigurations;
+  } PACKED;
+  typedef struct _tag_usb_device_descriptor 
+    USB_DEVICE_DESCRIPTOR, *PUSB_DEVICE_DESCRIPTOR;
+
+/* *** DEVICE_QUALIFIER *** (spec. 9.6.2) */
+  struct _tag_usb_device_qualifier_descriptor {
+    uint8_t  bLength;
+    uint8_t  bDescriptorType;
+    uint16_t bcdUSB;
+    uint8_t  bDeviceClass;
+    uint8_t  bDeviceSubClass;
+    uint8_t  bDeviceProtocol;
+    uint8_t  bMaxPacketSize0;
+    uint8_t  bNumConfigurations;
+    uint8_t  bReserved;
+  } PACKED;
+  typedef struct _tag_usb_device_qualifier_descriptor
+    USB_DEVICE_QUALIFIER_DESCRIPTOR, *PUSB_DEVICE_QUALIFIER_DESCRIPTOR;
+
+/* *** CONFIGURATION *** (spec. 9.6.3) */
+  struct _tag_usb_configuration_descriptor {
+    uint8_t  bLength;
+    uint8_t  bDescriptorType;
+    uint16_t wTotalLength;
+    uint8_t  bNumInterfaces;
+    uint8_t  bConfigurationValue;
+    uint8_t  iConfiguration;
+    uint8_t  bmAttributes;
+    uint8_t  MaxPower;
+  } PACKED;
+  typedef struct _tag_usb_configuration_descriptor
+    USB_CONFIGURATION_DESCRIPTOR, *PUSB_CONFIGURATION_DESCRIPTOR;
+/* definitions for bits in the bmAttributes field of a configuration descriptor. (spec. 9.6.3) */
+  #define USB_CONFIG_POWERED_MASK  0xc0
+  #define USB_CONFIG_BUS_POWERED   0x80
+  #define USB_CONFIG_SELF_POWERED  0x40
+  #define USB_CONFIG_REMOTE_WAKEUP 0x20
+  #define BUS_POWERED              0x80
+  #define SELF_POWERED             0x40
+  #define REMOTE_WAKEUP            0x20
+
+/* *** OTHER_SPEED_CONFIGURATION *** (spec. 9.6.4) */
+  struct _tag_usb_other_speed_configuration {
+    uint8_t  bLength;
+    uint8_t  bDescriptorType;
+    uint16_t wTotalLength;
+    uint8_t  bNumInterfaces;
+    uint8_t  bConfigurationValue;
+    uint8_t  iConfiguration;
+    uint8_t  bmAttributes;
+    uint8_t  bMaxPower;
+  } PACKED;
+  typedef struct _tag_usb_other_speed_configuration
+    USB_OTHER_SPEED_CONFIGURATION_DESCRIPTOR, *PUSB_OTHER_SPEED_CONFIGURATION_DESCRIPTOR;
+
+/* *** INTERFACE *** (spec. 9.6.5) */
+  struct _tag_usb_interface_descriptor {
+    uint8_t  bLength;
+    uint8_t  bDescriptorType;
+    uint8_t  bInterfaceNumber;
+    uint8_t  bAlternateSetting;
+    uint8_t  bNumEndpoints;
+    uint8_t  bInterfaceClass;
+    uint8_t  bInterfaceSubClass;
+    uint8_t  bInterfaceProtocol;
+    uint8_t  iInterface;
+  } PACKED;
+  typedef struct _tag_usb_interface_descriptor
+    USB_INTERFACE_DESCRIPTOR, *PUSB_INTERFACE_DESCRIPTOR;
+
+/* *** ENDPOINT *** (spec. 9.6.6) */
+  struct _tag_usb_endpoint_descriptor {
+    uint8_t  bLength;
+    uint8_t  bDescriptorType;
+    uint8_t  bEndpointAddress;
+    uint8_t  bmAttributes;
+    uint16_t wMaxPacketSize;
+    uint8_t  bInterval;
+  } PACKED;
+  typedef struct _tag_usb_endpoint_descriptor
+    USB_ENDPOINT_DESCRIPTOR, *PUSB_ENDPOINT_DESCRIPTOR;
+
+/* Endpoint direction bit, stored in address (spec. 9.6.6) */
+  #define USB_ENDPOINT_DIRECTION_MASK               0x80
+/* test direction bit in the bEndpointAddress field of an endpoint descriptor. */
+  #define USB_ENDPOINT_DIRECTION_OUT(addr)          (!((addr) & USB_ENDPOINT_DIRECTION_MASK))
+  #define USB_ENDPOINT_DIRECTION_IN(addr)           ((addr) & USB_ENDPOINT_DIRECTION_MASK)
+/* Values for bmAttributes field of an endpoint descriptor (spec. 9.6.6) */
+  #define USB_ENDPOINT_TYPE_MASK                    0x03
+  #define USB_ENDPOINT_TYPE_CONTROL                 0x00
+  #define USB_ENDPOINT_TYPE_ISOCHRONOUS             0x01
+  #define USB_ENDPOINT_TYPE_BULK                    0x02
+  #define USB_ENDPOINT_TYPE_INTERRUPT               0x03
+
+/* *** STRING *** (spec. 9.6.7) */
+  struct _tag_usb_string_descriptor {
+    uint8_t  bLength;
+    uint8_t  bDescriptorType;
+    uint8_t  bString[];
+  } PACKED;
+  typedef struct _tag_usb_string_descriptor
+    USB_STRING_DESCRIPTOR, *PUSB_STRING_DESCRIPTOR;
+  
+
+/*******************************************/
+/*** USB_IF - Defined USB device classes ***/
+/*******************************************/
+  #define USB_DEVICE_CLASS_RESERVED             0x00
+  #define USB_DEVICE_CLASS_AUDIO                0x01
+  #define USB_DEVICE_CLASS_COMMUNICATIONS       0x02
+  #define USB_DEVICE_CLASS_HUMAN_INTERFACE      0x03
+  #define USB_DEVICE_CLASS_MONITOR              0x04
+  #define USB_DEVICE_CLASS_PHYSICAL_INTERFACE   0x05
+  #define USB_DEVICE_CLASS_POWER                0x06
+  #define USB_DEVICE_CLASS_PRINTER              0x07
+  #define USB_DEVICE_CLASS_STORAGE              0x08
+  #define USB_DEVICE_CLASS_HUB                  0x09
+  #define USB_DEVICE_CLASS_APPLICATION_SPECIFIC 0xFE
+  #define USB_DEVICE_CLASS_VENDOR_SPECIFIC      0xFF
+
+  /* define application specific device class subclasses */
+  #define USB_APPL_SUBCLASS_FIRMWARE_UPDATE     0x01
+  #define USB_APPL_SUBCLASS_IRDA_USB_BRIDGE     0x02
+                                                           
+#endif
diff --git a/common/libs4c/usb/base/usb/usb_stdreq.h b/common/libs4c/usb/base/usb/usb_stdreq.h
new file mode 100644 (file)
index 0000000..1821ab4
--- /dev/null
@@ -0,0 +1,23 @@
+#ifndef _USB_STDREQ_MODULE_
+  #define _USB_STDREQ_MODULE_
+
+  int usb_stdreq_get_status( usb_device_t *udev);
+  
+  int usb_stdreq_clear_feature( usb_device_t *udev);
+
+  int usb_stdreq_set_feature( usb_device_t *udev);
+
+  int usb_stdreq_set_address( usb_device_t *udev);
+
+  int usb_stdreq_get_configuration( usb_device_t *udev);
+
+  int usb_stdreq_set_configuration( usb_device_t *udev);
+
+  int usb_stdreq_get_interface( usb_device_t *udev);
+
+  int usb_stdreq_set_interface( usb_device_t *udev);
+  int usb_stdreq_get_descriptor( usb_device_t *udev);
+  
+#endif /*_USB_STDREQ_MODULE_*/
+
diff --git a/common/libs4c/usb/base/usb/usbdebug.h b/common/libs4c/usb/base/usb/usbdebug.h
new file mode 100644 (file)
index 0000000..c81adf5
--- /dev/null
@@ -0,0 +1,82 @@
+/* Global debug macros, variables, functions - header file */
+/* R.B. - 23.4.2003 */
+
+#ifndef _USB_DEBUG_H_
+#define _USB_DEBUG_H_
+
+#if 1
+  #include <stdio.h>
+  #define usb_printf printf
+#else
+  int simple_printf(const char *f, ...);
+  #define usb_printf simple_printf
+#endif
+
+/* Debug levels */
+#define DEBUG_LEVEL_NONE    0
+#define DEBUG_LEVEL_LOW     1
+#define DEBUG_LEVEL_MEDIUM  2
+#define DEBUG_LEVEL_HIGH    3
+#define DEBUG_LEVEL_VERBOSE 4
+
+#ifndef DEBUG_STATIC_LEVEL
+/* Global static debug level */
+#define DEBUG_STATIC_LEVEL     DEBUG_LEVEL_NONE
+#endif
+
+/* If it is defined, current global debug level is
+   in 'global_debug_level' variable. Otherwise will
+   be used 'DEBUG_STATIC_LEVEL' as current global
+   debug level
+*/
+#define DEBUG_USE_DYNAMIC_LEVEL
+
+#define DEBUG
+
+
+/*****************************************************************************/
+/*****************************************************************************/
+/*****************************************************************************/
+
+#ifdef DEBUG
+
+/* use static or dynamic global debug level */
+#if defined(DEBUG_USE_DYNAMIC_LEVEL) /* use dynamic debug level */
+  extern unsigned char usb_debug_level;
+#else /* use only static debug level */
+  #define usb_debug_level DEBUG_STATIC_LEVEL
+#endif
+
+
+/* usb_debug_print( level, printargs) print debug info in printargs if
+   level is lower or equal to 'global_debug_level'/'DEBUG_STATIC_LEVEL'.
+   'printargs' is with parenthesis.
+   usage : usb_debug_print( DEBUG_LEVEL_MEDIUM,("i=%d",i));
+*/
+#define usb_debug_print( _lvl_, _prnargs_)      \
+  do {                                          \
+    if ( usb_debug_level >= _lvl_) {            \
+      usb_printf _prnargs_;                     \
+    }                                           \
+  } while(0)
+
+/* usb_debug_info( printargs) print debug info always
+   usage : usb_debug_info( "debug info");
+*/
+#define usb_debug_info usb_printf  /* FIXME: this is not correct */
+
+#else /* DEBUG */
+  #define usb_debug_print( _lvl_, _prnargs_)
+  #define usb_debug_info(...) 
+#endif /* DEBUG */
+
+
+  void usb_debug_set_level(int level);
+
+  char *usb_debug_get_req_recipient( char rqt);
+  char *usb_debug_get_req_type( char rqt);
+  char *usb_debug_get_std_request( char req);
+  char *usb_debug_get_std_descriptor( unsigned char desc);
+
+  
+#endif /* _GLOBAL_DEBUG_H_ */
diff --git a/common/libs4c/usb/base/usbdebug.c b/common/libs4c/usb/base/usbdebug.c
new file mode 100644 (file)
index 0000000..48bee80
--- /dev/null
@@ -0,0 +1,76 @@
+/* Global debug macros, variables, functions - header file */
+/* R.B. - 23.4.2003 */
+
+#include <usb/usbdebug.h>
+#include <usb/usb_spec.h>
+
+#ifdef DEBUG
+
+/* debug can be enabled in run-time */
+#if defined(DEBUG_USE_DYNAMIC_LEVEL) /* use dynamic debug level */
+  unsigned char usb_debug_level = DEBUG_LEVEL_NONE;
+#endif  
+
+/*************************************************************
+ *** Debug infos
+ *************************************************************/
+
+  void usb_debug_set_level(int level) {
+   #if defined(DEBUG_USE_DYNAMIC_LEVEL) /* use dynamic debug level */
+    usb_debug_level = level;
+   #endif  
+  }
+
+  
+  char *usb_debug_get_req_recipient( char rqt) {
+    switch ( rqt & USB_RECIPIENT) {
+      case USB_RECIPIENT_DEVICE:    return "DEVICE";
+      case USB_RECIPIENT_INTERFACE: return "INTERFACE";
+      case USB_RECIPIENT_ENDPOINT:  return "ENDPOINT";
+    }
+    return "OTHER";
+  }
+  char *usb_debug_get_req_type( char rqt) {
+    switch ( rqt & USB_REQUEST_TYPE_MASK) {
+      case USB_STANDARD_REQUEST: return "STANDARD";
+      case USB_CLASS_REQUEST:    return "CLASS";
+      case USB_VENDOR_REQUEST:   return "VENDOR";
+    }
+    return "RESERVED";
+  }
+  char *usb_debug_get_std_request( char req) {
+    switch ( req & USB_REQUEST_MASK) {
+      case USB_REQUEST_GET_STATUS:        return "GET STATUS";
+      case USB_REQUEST_CLEAR_FEATURE:     return "CLEAR FEATURE";
+      case USB_REQUEST_SET_FEATURE:       return "SET FEATURE";
+      case USB_REQUEST_SET_ADDRESS:       return "SET ADDRESS";
+
+      case USB_REQUEST_GET_DESCRIPTOR:    return "GET DESCRIPTOR";
+      case USB_REQUEST_SET_DESCRIPTOR:    return "SET DESCRIPTOR";
+      case USB_REQUEST_GET_CONFIGURATION: return "GET CONFIGURATION";
+      case USB_REQUEST_SET_CONFIGURATION: return "SET CONFIGURATION";
+      case USB_REQUEST_GET_INTERFACE:     return "GET INTERFACE";
+      case USB_REQUEST_SET_INTERFACE:     return "SET INTERFACE";
+      case USB_REQUEST_SYNC_FRAME:        return "SYNC FRAME";
+    }
+    return "UNKNOWN";
+  }
+  char *usb_debug_get_std_descriptor( unsigned char desc) {
+
+    switch ( desc) {
+      case USB_DESCRIPTOR_TYPE_DEVICE:                    return "DEVICE";
+      case USB_DESCRIPTOR_TYPE_CONFIGURATION:             return "CONFIGURATION";
+      case USB_DESCRIPTOR_TYPE_STRING:                    return "STRING";
+      case USB_DESCRIPTOR_TYPE_INTERFACE:                 return "INTERFACE";
+      case USB_DESCRIPTOR_TYPE_ENDPOINT:                  return "ENDPOINT";
+      case USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER:          return "DEVICE_QUALIFIER";
+      case USB_DESCRIPTOR_TYPE_OTHER_SPEED_CONFIGURATION: return "OTHER_SPEED_CONFIG";
+      case USB_DESCRIPTOR_TYPE_POWER:                     return "POWER";
+    }
+    return "UNKNOWN";
+  }
+
+#else /*DEBUG*/  
+  void usb_debug_set_level(int level) {
+  }
+#endif /* DEBUG */
diff --git a/common/libs4c/usb/more/Makefile b/common/libs4c/usb/more/Makefile
new file mode 100644 (file)
index 0000000..f595272
--- /dev/null
@@ -0,0 +1,14 @@
+# Generic directory or leaf node makefile for OCERA make framework
+
+ifndef MAKERULES_DIR
+MAKERULES_DIR := $(shell ( old_pwd="" ;  while [ ! -e Makefile.rules ] ; do if [ "$$old_pwd" == `pwd`  ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) )
+endif
+
+ifeq ($(MAKERULES_DIR),)
+all : default
+.DEFAULT::
+       @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
+else   
+include $(MAKERULES_DIR)/Makefile.rules
+endif
+
diff --git a/common/libs4c/usb/more/Makefile.omk b/common/libs4c/usb/more/Makefile.omk
new file mode 100644 (file)
index 0000000..8c2146c
--- /dev/null
@@ -0,0 +1,16 @@
+default_CONFIG = CONFIG_USB_MORE=y
+
+ifeq ($(CONFIG_USB_MORE),y) 
+lib_LIBRARIES = usbmore
+
+#shared_LIBRARIES = 
+
+#include_HEADERS  = 
+
+usbmore_SOURCES = usb_stdreq.c
+
+#lib_LOADLIBES = 
+#bin_PROGRAMS = 
+
+endif #CONFIG_USB_MORE
+
diff --git a/common/libs4c/usb/more/usb/usb_defs.h b/common/libs4c/usb/more/usb/usb_defs.h
new file mode 100644 (file)
index 0000000..12a17ce
--- /dev/null
@@ -0,0 +1,234 @@
+
+#ifndef USB_DEFS_MODULE
+  #define USB_DEFS_MODULE
+
+  #include <usb/usb_spec.h>
+  #include <usb/pdiusb.h>
+//  #include <cpu_def.h>
+
+  #include <endian.h>
+  #if __BYTE_ORDER == __BIG_ENDIAN
+    #include <byteswap.h>
+    #define SWAP(x) ((((x) & 0xFF) << 8) | (((x) >> 8) & 0xFF))
+  #else /*__LITTLE_ENDIAN*/
+    #define SWAP(x) (x)
+  #endif
+
+//  #define MSB(x) ((unsigned char)(((x) >> 8)& 0xff))
+//  #define LSB(x) ((unsigned char)((x) & 0xff))
+
+  #ifndef CODE
+    #define CODE
+  #endif
+  
+/*****************************************************/
+/*** Static data structures for device descriptors ***/
+/*****************************************************/
+  #define USB_VENDOR_ID      0xDEAD  /* vymyslene cislo ( snad ho nikdo nema ... ;-) */
+//  #define USB_PRODUCT_ID     0x2262  /* Program Uploader(DFU) 8.8.2002 */
+//  #define USB_PRODUCT_ID     0xABCD  /* Program Uploader(DFU) 8.8.2002 */
+  #define USB_PRODUCT_ID     0x0101  /* testing program for m68 */
+  #define USB_RELEASE_VER    0x0100
+
+/*** Class codes for device description ***/
+  #define USB_CLASS_CODE      0xFF
+  #define USB_SUBCLASS_CODE   0x00
+  #define USB_PROTOCOL_CODE   0x00
+  
+  
+  #define NUM_ENDPOINTS  2
+  #define CONFIG_DESCRIPTOR_LENGTH sizeof( USB_CONFIGURATION_DESCRIPTOR) \
+                                     + sizeof( USB_INTERFACE_DESCRIPTOR) \
+                                     + ( NUM_ENDPOINTS * sizeof( USB_ENDPOINT_DESCRIPTOR))
+
+/*** Device descriptor ***/
+  CODE const USB_DEVICE_DESCRIPTOR DeviceDescription = {
+    sizeof( USB_DEVICE_DESCRIPTOR),
+    USB_DESCRIPTOR_TYPE_DEVICE,
+    SWAP( 0x0100),
+    USB_CLASS_CODE,
+    USB_SUBCLASS_CODE,
+    USB_PROTOCOL_CODE,
+    PDI_EP0_PACKET_SIZE,
+    SWAP( USB_VENDOR_ID),
+    SWAP( USB_PRODUCT_ID),  
+    SWAP( USB_RELEASE_VER),
+    1, /* manufacturer string ID */
+    2, /* product string ID */
+    3, /* serial number string ID */
+    1
+  };
+  
+/*** All In Configuration 0 ***/
+  CODE const struct {
+    USB_CONFIGURATION_DESCRIPTOR configuration;
+    USB_INTERFACE_DESCRIPTOR interface;
+    USB_ENDPOINT_DESCRIPTOR endpoint_tx;
+    USB_ENDPOINT_DESCRIPTOR endpoint_rx;
+  } ConfigDescription = {
+    /*** Configuration descriptor ***/
+    {
+      sizeof( USB_CONFIGURATION_DESCRIPTOR),
+      USB_DESCRIPTOR_TYPE_CONFIGURATION,
+      SWAP( CONFIG_DESCRIPTOR_LENGTH),
+      1, /* cnt of interfaces */
+      1, /* this configuration ID */
+      4, /* config.name string ID*/
+      0xa0, /* cfg, in spec is, taha bit 7 must be set to one -> 0xe0 */
+      50    /* device power current from host */
+    },
+    /*** Interface Descriptor ***/
+    {
+      sizeof( USB_INTERFACE_DESCRIPTOR),
+      USB_DESCRIPTOR_TYPE_INTERFACE,
+      0,    /* index of this interface for SetInterface request */
+      0,    /* ID alternate interface */
+      NUM_ENDPOINTS,
+      USB_CLASS_CODE,
+      USB_SUBCLASS_CODE,
+      USB_PROTOCOL_CODE,
+      5
+    },
+    /*** Endpoint 1 - Tx,Bulk ***/
+    {
+      sizeof( USB_ENDPOINT_DESCRIPTOR),
+      USB_DESCRIPTOR_TYPE_ENDPOINT,
+      0x82,
+      USB_ENDPOINT_TYPE_BULK,
+      SWAP( PDI_EP2_PACKET_SIZE),
+      0
+    },
+    /*** Endpoint 2 - Rx,Bulk ***/
+    {
+      sizeof( USB_ENDPOINT_DESCRIPTOR),
+      USB_DESCRIPTOR_TYPE_ENDPOINT,
+      0x02,
+      USB_ENDPOINT_TYPE_BULK,
+      SWAP( PDI_EP2_PACKET_SIZE),
+      0
+    }    
+  };
+  /*** Strings - in unicode ***/
+  CODE const char Str0Desc[] = {  /* supported languages of strings */
+    4, 0x03,  /* 2+2*N , N is count of supported languages */
+    0x09,0x04 /* english 0x0409 */
+  //  0x05,0x04 /* czech 0x0405 */
+  };
+  
+  CODE const char Str1Desc[] = {  /* 1 = manufacturer */
+    58, 0x03,                                               
+    'R',0,
+    'o',0,
+    'm',0,
+    'a',0,
+    'n',0,
+    ' ',0,
+    'B',0,
+    'a',0,
+    'r',0,
+    't',0,
+    'o',0,
+    's',0,
+    'i',0,
+    'n',0,
+    's',0,
+    'k',0,
+    'i',0,
+    ',',0,
+    'C',0,
+    'T',0,
+    'U',0,
+    ' ',0,
+    'P',0,
+    'r',0,
+    'a',0,
+    'g',0,
+    'u',0,
+    'e',0
+  };
+  CODE const char Str2Desc[] = {  /* 2 = product */
+    42, 0x03,                                               
+    'U',0,
+    'S',0,
+    'B',0,
+    ' ',0,
+    'T',0,
+    'e',0,
+    's',0,
+    't',0,
+    'i',0,
+    'n',0,
+    'g',0,
+    ' ',0,
+    'P',0,
+    'r',0,
+    'o',0,
+    'g',0,
+    '.',0,
+    ' ',0,
+    'M',0,
+    '2',0
+  };
+  CODE const char Str3Desc[] = {  /* 3 = version */
+    26, 0x03,                                               
+    '0',0,
+    '4',0,
+    '.',0,
+    '0',0,
+    '5',0,
+    '.',0,
+    '1',0,
+    '1',0,
+    '-',0,
+    '1',0,
+    '.',0,
+    '1',0
+  };
+  CODE const char Str4Desc[] = {  /* 4 = configuration */
+    34, 0x03,                                               
+    'C',0,
+    'o',0,
+    'n',0,
+    'f',0,
+    'i',0,
+    'g',0,
+    'u',0,
+    'r',0,
+    'a',0,
+    't',0,
+    'i',0,
+    'o',0,
+    'n',0,
+    ' ',0,
+    '#',0,
+    '1',0
+  };
+  CODE const char Str5Desc[] = {  /* 5 = interface */
+    26,0x03,                                               
+    'I',0,
+    'n',0,
+    't',0,
+    'e',0,
+    'r',0,
+    'f',0,
+    'a',0,
+    'c',0,
+    'e',0,
+    ' ',0,
+    '#',0,
+    '0',0
+  };
+
+  #define CNT_STRINGS 0x06
+  
+  /* all strings in pointers array */
+  CODE const PUSB_STRING_DESCRIPTOR StringDescriptors[] = {
+    (PUSB_STRING_DESCRIPTOR) Str0Desc,
+    (PUSB_STRING_DESCRIPTOR) Str1Desc,
+    (PUSB_STRING_DESCRIPTOR) Str2Desc,
+    (PUSB_STRING_DESCRIPTOR) Str3Desc,
+    (PUSB_STRING_DESCRIPTOR) Str4Desc,
+    (PUSB_STRING_DESCRIPTOR) Str5Desc
+  };
+
+#endif /* USB_DEFS_MODULE */
diff --git a/common/libs4c/usb/more/usb/usb_loader.h b/common/libs4c/usb/more/usb/usb_loader.h
new file mode 100644 (file)
index 0000000..7b7fddb
--- /dev/null
@@ -0,0 +1,42 @@
+#include <usb/usb.h>
+
+#ifndef _USB_LOADER_H
+#define _USB_LOADER_H
+
+#define USB_VENDOR_GET_CAPABILITIES  0x00 // get capabilities
+#define USB_VENDOR_RESET_DEVICE      0x08
+// #define USB_VENDOR_SET_BYTE          0x10
+// #define USB_VENDOR_SET_WORD          0x20
+#define USB_VENDOR_GET_SET_MEMORY    0x30
+#define USB_VENDOR_ERASE_MEMORY      0x40 // erase memory for 1 Byte
+#define USB_VENDOR_ERASE_1KB_MEMORY  0x48 // erase memory for 1 KB
+#define USB_VENDOR_MASS_ERASE        0x50 // erase all device memory
+#define USB_VENDOR_GOTO              0x60
+#define USB_VENDOR_CALL              0x70
+#define USB_VENDOR_GET_STATUS        0xF0
+#define USB_VENDOR_MASK              0xF8 // mask for vendor commands
+
+#define USB_VENDOR_MEMORY_BY_BULK    0x80
+
+#if 0 /* MSP430 */
+#define USB_VENDOR_TARGET_ADAPTER    0x01
+#define USB_VENDOR_TARGET_MSP430     0x02
+#elif 0 /* MSC1210 */
+#define USB_VENDOR_TARGET_DATA       0x01
+#define USB_VENDOR_TARGET_XDATA      0x02
+#else /* DragonBall MX1 */
+#define USB_VENDOR_TARGET_RAM        0x00
+#define USB_VENDOR_TARGET_FLASH      0x05
+#endif
+
+#define USB_VENDOR_TARGET_MASK       0x07
+
+// bRequest - type of request
+// wValue - lower address word
+// wIndex - higher address word
+// wLength - data or length of data
+
+//int usb_msp430_loader(usb_ep_t *ep, USB_DEVICE_REQUEST *dreq);
+int usb_native_loader(struct usb_device_t *udev);
+
+#endif /*_USB_LOADER_H*/
diff --git a/common/libs4c/usb/more/usb_loader.c b/common/libs4c/usb/more/usb_loader.c
new file mode 100644 (file)
index 0000000..af0c9f8
--- /dev/null
@@ -0,0 +1,276 @@
+#include <types.h>
+//#include <cpu_def.h>
+//#include <h8s2633h.h>
+#include <system_def.h>
+#include <string.h>
+#include <stdio.h>
+
+#include <usb/usb.h>
+//#include <usb/pdiusb.h>
+//#include <msp430-lib/JTAGfunc.h>
+//#include <msp430-lib/LowLevelFunc.h>
+#include "usb_loader.h"
+
+
+#ifdef PDI_EP0_PACKET_SIZE
+  #define LOADER_BUFFER_SIZE PDI_EP0_PACKET_SIZE
+#else /*PDI_EP0_PACKET_SIZE*/
+  #define LOADER_BUFFER_SIZE 128
+#endif /*PDI_EP0_PACKET_SIZE*/
+
+unsigned char loader_buffer[LOADER_BUFFER_SIZE];
+/*
+unsigned long msp430_flash_minaddr=0x1100;
+unsigned long msp430_flash_maxaddr=0xffff;
+
+int usb_msp430_pkt_wrmsp(usb_ep_t *ep, int len, int codeval)
+{
+  unsigned char *ptr=ep->ptr-len;
+  unsigned char c;
+  int i;
+  printf("usb_msp430_pkt_wrmsp bytes %d, loc %lx -> msp %lx\n", len, (long)ptr, ep->user_data);
+  if(!(ep->user_data&1)) {
+    i = len/2;
+    while(i--){
+      // swap endianning
+      c = ptr[0]; ptr[0] = ptr[1]; ptr[1] = c;
+      ptr += 2;
+    }
+    ptr -= len & ~1;
+    
+    if( (ep->user_data<msp430_flash_minaddr) ||
+        (ep->user_data>msp430_flash_maxaddr) ) {
+      WriteMemQuick(ep->user_data, len/2, (word*)ptr);
+    } else {
+      WriteFLASH(ep->user_data, len/2, (word*)ptr);
+      if(VerifyMem(ep->user_data, len/2, (word*)ptr) != STATUS_OK) {
+        ep->ptr=loader_buffer;
+        return USB_COMPLETE_FAIL;
+      }
+    }
+    //ptr += len & ~1;
+    ep->user_data += len & ~1;
+    len &= 1;
+  }
+
+  while(len--){
+    //F_BYTE or F_WORD
+    WriteMem(F_BYTE, ep->user_data++, *(ptr++));
+  }
+  ep->ptr=loader_buffer;
+  return USB_COMPLETE_OK;
+}
+
+int usb_msp430_pkt_rdmsp(usb_ep_t *ep, int len, int codeval) // 'code' must not be used as identifier
+{
+  unsigned char *ptr;
+  unsigned char c;
+  int i;
+  printf("usb_msp430_pkt_rdmsp bytes %d\n", len);  
+  ptr = ep->ptr = loader_buffer;
+  if(!(ep->user_data&1)) {
+    i = len/2;
+    ReadMemQuick(ep->user_data, i, (word*)ptr);
+    while(i--){
+      // swap endianning 
+      c = ptr[0]; ptr[0] = ptr[1]; ptr[1] = c;
+      ptr += 2;
+    }
+    /ptr += len & ~1;
+    ep->user_data += len & ~1;
+    len &= 1;
+  }
+
+  while(len--){
+    //F_BYTE or F_WORD
+    *(ptr++) = ReadMem(F_BYTE, ep->user_data++);
+  }
+  return USB_COMPLETE_OK;
+}
+*/
+
+/*
+
+ERASE_MASS or ERASE_MAIN or ERASE_SGMT
+void EraseFLASH(word EraseMode, word EraseAddr)
+
+*/
+
+//int msp430_erase(unsigned addr, unsigned len)
+int msc1210_erase(unsigned addr, unsigned len)
+{
+  unsigned end = addr + len - 1; 
+  if(addr<0x8000) //0x1000)
+    return -1;
+  
+  while(addr < end) {
+//    EraseFLASH( ERASE_SGMT, addr);
+//    if(addr<0x1100) addr = (addr & ~0x7f) + 0x80;
+//    else addr = (addr & ~0x1ff) + 0x200;
+    *((xdata unsigned char *)addr) = 0;
+  }
+  return 0;
+}
+/*
+int msp430_mass_erase(unsigned mode, unsigned addr)
+{
+  if(mode == 0) mode = ERASE_MASS;  
+  EraseFLASH( mode, addr);
+  return 0;
+}
+*/
+int msc1210_mass_erase(unsigned mode, unsigned addr)
+{
+//  unsigned addr = 0x7fff;
+  while( addr != 0xffff) {
+    addr++;
+    if ( !(addr & 0x00ff)) printf(" erase segm. 0x%X\n", addr);
+    *((xdata unsigned char *)addr) = 0;
+  }
+  return 0;
+}
+
+
+#ifdef SDCC
+void msc1210_goto( unsigned addr)
+{
+  _asm
+    pop  acc
+    pop  acc
+    mov  a,dpl
+    push acc
+    mov  a,dph
+    push acc
+    ret
+  _endasm;
+}
+#else /*SDCC*/
+#pragma asm
+;void msc1210_goto( unsigned addr)
+;{
+       public _msc1210_goto
+_msc1210_goto:
+       pop  acc
+       pop  acc
+       mov  a,r7
+       push acc
+       mov  a,r6
+       push acc
+       ret
+;  return 0;
+;}
+#pragma endasm
+#endif
+
+
+
+void msc1210_reset_device( void)
+{
+  printf("...reset...\n");
+}
+
+
+//int usb_msp430_loader(usb_control_ep_t *ep, USB_DEVICE_REQUEST *dreq)
+
+//int usb_msp430_loader(struct usb_device_t *udev)
+int usb_msc1210_loader(usb_device_t *udev)
+{
+  unsigned long addr;
+  unsigned len;
+
+  switch ( udev->request.bRequest & USB_VENDOR_MASK) {
+
+    case USB_VENDOR_GET_CAPABILITIES:
+      printf("GET_CAPABILITIES\n");
+      loader_buffer[0] = 0xAA; // test
+      usb_send_control_data(udev, loader_buffer, 1);
+      return 1;
+
+    case USB_VENDOR_RESET_DEVICE:
+      printf("RESET_DEVICE\n");
+//      InitController();
+//      InitTarget();
+//      if (!GetDevice()) {
+//        return -1;
+//      }
+      usb_ack_setup(&udev->ep0);
+      msc1210_reset_device();
+      return 1;
+
+    case USB_VENDOR_GOTO:
+      //printf( "GOTO 0x%X\n", udev->request.wValue);
+      usb_ack_setup(&udev->ep0);
+      //msp430_goto(udev->request.wValue);
+      msc1210_goto(udev->request.wValue);
+      return 1;
+
+    case USB_VENDOR_ERASE_MEMORY:
+      printf( "ERASE 0x%X 0x%X\n", udev->request.wValue, udev->request.wIndex);
+      usb_ack_setup(&udev->ep0);
+      //msp430_erase(udev->request.wValue, udev->request.wIndex);
+      msc1210_erase(udev->request.wValue, udev->request.wIndex);
+      return 1;
+
+    case USB_VENDOR_MASS_ERASE:
+      printf( "MASSERASE 0x%X 0x%X\n", udev->request.wIndex, udev->request.wValue);
+      usb_ack_setup(&udev->ep0);
+      //msp430_mass_erase(udev->request.wIndex, udev->request.wValue);
+      msc1210_mass_erase(udev->request.wIndex, udev->request.wValue);
+      return 1;
+      
+    case USB_VENDOR_GET_SET_MEMORY:
+      addr = (udev->request.wValue & 0xffff) | (((unsigned long)udev->request.wIndex&0xffff)<<16);
+      len = udev->request.wLength;
+      //printf("GET_SET_MEMORY, addr=0x%lx, len=%d\n", (long)addr, len);
+      if (( udev->request.bmRequestType & USB_DATA_DIR_MASK) == USB_DATA_DIR_FROM_HOST) {
+        // read from HOST ???
+        switch( udev->request.bRequest & USB_VENDOR_TARGET_MASK) {
+          case USB_VENDOR_TARGET_XDATA:
+            udev->ep0.ptr = (xdata unsigned char *)addr;
+            break;
+          case USB_VENDOR_TARGET_DATA:
+            udev->ep0.ptr = (data unsigned char *)addr;
+            break;
+/*
+          case USB_VENDOR_TARGET_MSP430:
+            if (jtag_check_init(0)<0) {
+                  printf("MSP430 JTAG init ERROR\n");
+                  return -1;
+                }
+            udev->ep0.next_pkt_fnc = usb_msp430_pkt_wrmsp;
+            udev->ep0.user_data=addr;
+            udev->ep0.ptr = loader_buffer; break;
+*/
+          default: return -1;
+        }
+        if ( len) usb_set_control_endfnc( udev, usb_ack_setup);
+        else usb_ack_setup(&udev->ep0);
+        return 1;
+      } else {
+        switch( udev->request.bRequest & USB_VENDOR_TARGET_MASK) {
+          case USB_VENDOR_TARGET_XDATA:
+            usb_send_control_data( udev, (xdata unsigned char *)addr, len); //(void*)addr, len);
+            break;
+          case USB_VENDOR_TARGET_DATA:
+            usb_send_control_data( udev, (data unsigned char *)addr, len); //(void*)addr, len);
+            break;
+/*
+          case USB_VENDOR_TARGET_MSP430:
+            if (jtag_check_init(0)<0) {
+                  printf("MSP430 JTAG init ERROR\n");
+                  return -1;
+                }
+            udev->ep0.next_pkt_fnc = usb_msp430_pkt_rdmsp;
+            udev->ep0.user_data=addr;
+            usb_send_control_data( udev, loader_buffer, len); break;
+*/
+          default: return -1;
+        }
+        return 1;
+      }
+      break;
+  }
+
+
+  return 0;
+}
diff --git a/common/libs4c/usb/more/usb_stdreq.c b/common/libs4c/usb/more/usb_stdreq.c
new file mode 100644 (file)
index 0000000..89ac24a
--- /dev/null
@@ -0,0 +1,223 @@
+/*****************************************************/
+/***   Module : USB module                         ***/
+/***   Author : Roman Bartosinski (C) 28.04.2002   ***/
+/***   Modify : 08.08.2002, 16.04.2003             ***/
+/*****************************************************/
+
+#include <string.h>
+
+#include <system_def.h>
+#include <usb/usb.h>
+#include <usb/usb_spec.h>
+#include <usb/pdiusb.h>
+#include <usb/usbdebug.h>
+#include "usb/usb_defs.h"
+
+  // ****************************
+  int usb_stdreq_get_status( usb_device_t *udev)
+  {
+    unsigned char c, buf[2] = { 0, 0};
+    unsigned char epid = (unsigned char) udev->request.wIndex;
+
+    usb_debug_print( DEBUG_LEVEL_HIGH, ("GetStatus\n"));
+    switch( udev->request.bmRequestType & USB_RECIPIENT) {
+      case USB_RECIPIENT_DEVICE:
+        if ( udev->flags & USB_FLAG_REMOTE_WAKE) //.remote_wake_up == 1)
+          buf[0] = USB_GETSTATUS_REMOTE_WAKEUP_ENABLED | USB_GETSTATUS_SELF_POWERED;
+        else
+          buf[0] = USB_GETSTATUS_SELF_POWERED;
+        break;
+      case USB_RECIPIENT_INTERFACE:
+        break;
+      case USB_RECIPIENT_ENDPOINT:
+        if ( epid & USB_ENDPOINT_DIRECTION_MASK)
+          c = pdiSelectEp(pdiEp2Idx(epid)); // endpoint in
+        else
+          c = pdiSelectEp(pdiEp2Idx(epid));     // endpoint Out
+          #ifdef PDIUSBD12
+          buf[0] = (( c & PDI_SELEP_STALL) == PDI_SELEP_STALL);
+          #else
+          buf[0] = 0;
+          #endif
+        break;
+      default:
+        return USB_COMPLETE_FAIL;
+    }
+    pdiWriteEndpoint( PDI_EP0_TX, 2, buf);
+    return USB_COMPLETE_OK;
+  }
+
+  int usb_stdreq_clear_feature( usb_device_t *udev)
+  {
+    USB_DEVICE_REQUEST *dreq = &(udev->request);
+    unsigned char epid = (unsigned char) dreq->wIndex;
+
+    usb_debug_print( DEBUG_LEVEL_HIGH, ("ClearFeature\n"));
+    switch( dreq->bmRequestType & USB_RECIPIENT) {
+      case USB_RECIPIENT_DEVICE:
+        if ( dreq->wValue == USB_FEATURE_REMOTE_WAKEUP) {
+          udev->flags &= ~USB_FLAG_REMOTE_WAKE; //.remote_wake_up = 0;
+          usb_udev_ack_setup( udev);
+          return USB_COMPLETE_OK;
+        }
+        break;
+      case USB_RECIPIENT_ENDPOINT:
+        if ( dreq->wValue == USB_FEATURE_ENDPOINT_STALL) {
+          if ( epid & USB_ENDPOINT_DIRECTION_MASK)
+            pdiSetEpStatus(pdiEp2Idx(epid), 0); // clear TX stall for IN on EPn
+          else
+            pdiSetEpStatus(pdiEp2Idx(epid), 0); // clear RX stall for OUT on EPn
+          usb_udev_ack_setup( udev);
+          return USB_COMPLETE_OK;
+        }
+        break;
+    }
+    return USB_COMPLETE_FAIL;
+  }
+
+  int usb_stdreq_set_feature( usb_device_t *udev)
+  {
+    USB_DEVICE_REQUEST *dreq = &(udev->request);
+    unsigned char epid = (unsigned char) dreq->wIndex;
+
+    usb_debug_print( DEBUG_LEVEL_HIGH, ("SetFeature\n"));
+    switch( dreq->bmRequestType & USB_RECIPIENT) {
+      case USB_RECIPIENT_DEVICE:
+        if ( dreq->wValue == USB_FEATURE_REMOTE_WAKEUP) {
+          udev->flags |= USB_FLAG_REMOTE_WAKE; //.remote_wake_up = 1;
+          usb_udev_ack_setup( udev);
+          return USB_COMPLETE_OK;
+        }
+        break;
+      case USB_RECIPIENT_ENDPOINT:
+        if ( dreq->wValue == USB_FEATURE_ENDPOINT_STALL) {
+          if ( epid & USB_ENDPOINT_DIRECTION_MASK)
+            pdiSetEpStatus( pdiEp2Idx(epid), 1); // set TX stall for IN on EPn
+          else
+            pdiSetEpStatus( pdiEp2Idx(epid), 1);     // set RX stall for OUT on EPn
+          usb_udev_ack_setup( udev);
+          return USB_COMPLETE_OK;
+        }
+        break;
+    }
+    return USB_COMPLETE_FAIL;
+  }
+
+  int usb_stdreq_set_address( usb_device_t *udev)
+  {
+    USB_DEVICE_REQUEST *dreq = &(udev->request);
+    usb_debug_print( DEBUG_LEVEL_HIGH, ("SetAddr\n"));
+    usb_udev_ack_setup( udev);
+    pdiSetAddressEnable( (dreq->wValue & DEVICE_ADDRESS_MASK) + PDI_ENAD_ENABLE);
+    return USB_COMPLETE_OK;
+  }
+
+  int usb_stdreq_get_configuration( usb_device_t *udev)
+  {
+    unsigned char buf = udev->configuration; //usb_flags.configured;
+    usb_debug_print( DEBUG_LEVEL_HIGH, ("GetConfig\n"));
+    pdiWriteEndpoint( PDI_EP0_TX, 1, &buf);
+    return USB_COMPLETE_OK;
+  }
+
+  int usb_stdreq_set_configuration( usb_device_t *udev)
+  {
+    USB_DEVICE_REQUEST *dreq = &(udev->request);
+    unsigned char iCfg = dreq->wValue & 0xff;
+    usb_debug_print( DEBUG_LEVEL_HIGH, ("SetConfig\n"));
+    if ( iCfg < 2) {       // put device in unconfigured state or set configuration 1 ( no else)
+      usb_udev_ack_setup( udev);
+      pdiSetEndpointEnable( 0); // USBInitUnconfig();
+      if ( iCfg) {
+        pdiSetEndpointEnable( PDI_EPEN_ENABLE); //USBInitConfig();
+        udev->flags |= USB_FLAG_CONFIGURED;
+      } else {
+        udev->flags &= ~USB_FLAG_CONFIGURED;
+      }
+      udev->configuration = iCfg;  //usb_flags.configured = iCfg;
+      return USB_COMPLETE_OK;
+    } else
+      return USB_COMPLETE_FAIL;
+  }
+
+  int usb_stdreq_get_interface( usb_device_t *udev)
+  {
+    unsigned char buf = 0; /// udev->interface
+    usb_debug_print( DEBUG_LEVEL_HIGH, ("GetIface\n"));
+    pdiWriteEndpoint( PDI_EP0_TX, 1, &buf);
+    return USB_COMPLETE_OK;
+  }
+
+  int usb_stdreq_set_interface( usb_device_t *udev)
+  {
+    USB_DEVICE_REQUEST *dreq = &(udev->request);
+    
+    usb_debug_print( DEBUG_LEVEL_HIGH, ("SetIface\n"));
+    if (( dreq->wValue == 0) && ( dreq->wIndex == 0)) {
+      usb_udev_ack_setup( udev);
+      return USB_COMPLETE_OK;
+    } else {
+      return USB_COMPLETE_FAIL;
+    }
+  }
+
+  int usb_stdreq_get_descriptor( usb_device_t *udev)
+  {
+    unsigned char *pDesc;
+    unsigned short Len = 0;
+    USB_DEVICE_REQUEST *dreq = &(udev->request);
+    int i;
+
+    i = (dreq->wValue >> 8) & 0xff; /* MSB part of wValue */
+    usb_debug_print( DEBUG_LEVEL_HIGH, ("GetDesc\n"));
+    usb_debug_print( DEBUG_LEVEL_VERBOSE, ( " - %s desc.\n", /*(unsigned int)*/ usb_debug_get_std_descriptor(i)));
+
+    switch (i) {
+      case USB_DESCRIPTOR_TYPE_DEVICE:
+        pDesc = (unsigned char *)&DeviceDescription;
+        Len = sizeof( USB_DEVICE_DESCRIPTOR);
+        break;
+      case USB_DESCRIPTOR_TYPE_CONFIGURATION:
+        pDesc = (unsigned char *)&ConfigDescription;
+        Len = CONFIG_DESCRIPTOR_LENGTH;
+        break;
+      case USB_DESCRIPTOR_TYPE_INTERFACE:
+        pDesc = (unsigned char *)&ConfigDescription.interface;
+        Len = sizeof( USB_INTERFACE_DESCRIPTOR);
+        break;
+      case USB_DESCRIPTOR_TYPE_STRING:
+        i = dreq->wValue & 0xff; /* LSB part of wValue */
+        /*printf("Get descriptor indx=0x%02x\n", i);*/
+        if ( i < CNT_STRINGS) {
+          pDesc = (unsigned char *) StringDescriptors[ i];
+          Len = *pDesc;
+          /*usb_debug_print(0,("indx=0x%02x ptr=%p len=%d : '%c'\n", i, pDesc, Len, pDesc[2]));*/
+        } else {
+          return USB_COMPLETE_FAIL;
+        }
+        break;
+      default:
+        return USB_COMPLETE_FAIL;
+    }
+    if ( dreq->wLength < Len) Len = dreq->wLength;
+    usb_send_control_data( udev, pDesc, Len);
+    return USB_COMPLETE_OK;
+  }
+
+
+/*  
+  void usb_init_stdreq_fnc( usb_device_t *udev)
+  {
+    // memset( udev->stdreq, 0, sizeof(udev->stdreq));
+    
+    udev->stdreq[USB_REQUEST_GET_STATUS] = usb_stdreq_get_status;
+    udev->stdreq[USB_REQUEST_CLEAR_FEATURE] = usb_stdreq_clear_feature;
+    udev->stdreq[USB_REQUEST_SET_FEATURE] = usb_stdreq_set_feature;
+    udev->stdreq[USB_REQUEST_SET_ADDRESS] = usb_stdreq_set_address;
+    udev->stdreq[USB_REQUEST_GET_DESCRIPTOR] = usb_stdreq_get_descriptor;
+    udev->stdreq[USB_REQUEST_GET_CONFIGURATION] = usb_stdreq_get_configuration;
+    udev->stdreq[USB_REQUEST_SET_CONFIGURATION] = usb_stdreq_set_configuration;
+    udev->stdreq[USB_REQUEST_GET_INTERFACE] = usb_stdreq_get_interface;
+    udev->stdreq[USB_REQUEST_SET_INTERFACE] = usb_stdreq_set_interface;
+  }
+*/
diff --git a/common/libs4c/usb/pdiusb/Makefile b/common/libs4c/usb/pdiusb/Makefile
new file mode 100644 (file)
index 0000000..f595272
--- /dev/null
@@ -0,0 +1,14 @@
+# Generic directory or leaf node makefile for OCERA make framework
+
+ifndef MAKERULES_DIR
+MAKERULES_DIR := $(shell ( old_pwd="" ;  while [ ! -e Makefile.rules ] ; do if [ "$$old_pwd" == `pwd`  ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) )
+endif
+
+ifeq ($(MAKERULES_DIR),)
+all : default
+.DEFAULT::
+       @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n"
+else   
+include $(MAKERULES_DIR)/Makefile.rules
+endif
+
diff --git a/common/libs4c/usb/pdiusb/Makefile.omk b/common/libs4c/usb/pdiusb/Makefile.omk
new file mode 100644 (file)
index 0000000..41e84f9
--- /dev/null
@@ -0,0 +1,10 @@
+default_CONFIG = CONFIG_USB_PDIUSB=y
+
+ifeq ($(CONFIG_USB_PDIUSB),y) 
+lib_LIBRARIES = usbpdi
+
+nobase_include_HEADERS = usb/pdi.h usb/pdiusb.h
+
+usbpdi_SOURCES = pdi.c pdiusb.c
+#usbpdi_SOURCES +=  pdi4rtems.c
+endif #CONFIG_USB_PDIUSB
diff --git a/common/libs4c/usb/pdiusb/pdi.c b/common/libs4c/usb/pdiusb/pdi.c
new file mode 100644 (file)
index 0000000..3229d36
--- /dev/null
@@ -0,0 +1,201 @@
+/*****************************************************/
+/***   Module : USB PDI                            ***/
+/***   Author : Roman Bartosinski (C) 28.04.2002   ***/
+/***   Modify : 08.08.2002, 16.04.2003             ***/
+/*****************************************************/
+
+#include <stdio.h>
+#include <string.h>
+#include <system_def.h>
+
+#define USB_PDI_EXPORT_FNC
+
+#include <usb/pdiusb.h>
+#include <usb/pdi.h>
+#include <usb/usbdebug.h>
+
+
+/* init chip state */
+  void pdiInitChipState( void) {
+   #ifdef PDIUSBD11
+    pdiSetHUBAddressEnable( 0, 0);
+   #endif /*PDIUSBD11*/
+    pdiSetAddressEnable( PDI_ENAD_ENABLE);
+    pdiSetEndpointEnable( PDI_EPEN_ENABLE);
+  }
+#ifdef PDIUSBD11
+
+  #define PDI_MODE_BASE_VALUE (PDI_MODE_MUSTBEONE | \
+  PDI_MODE_REMOTE_WAKEUP | PDI_MODE_NO_LAZY_CLOCK | \
+  PDI_MODE_CLOCK_RUNNING | PDI_CLOCK_4M)
+
+#else /*PDIUSBD11*/
+
+  #define PDI_MODE_BASE_VALUE (PDI_CLOCK_SET_TO_ONE | \
+  PDI_MODE_NO_LAZY_CLOCK | PDI_MODE_CLOCK_RUNNING | \
+  PDI_CLOCK_4M)
+
+#endif /*PDIUSBD11*/
+
+
+/* connect usb */
+  int usb_pdi_connect( usb_device_t *udev) {
+    pdiSetMode( PDI_MODE_BASE_VALUE | PDI_MODE_SOFT_CONNECT );
+    return 0;
+  }
+
+/* disconnect usb */
+  int usb_pdi_disconnect( usb_device_t *udev) {
+    pdiSetMode( PDI_MODE_BASE_VALUE & ~PDI_MODE_SOFT_CONNECT );
+    return 0;
+  }
+
+/* acknowledge control transfer */
+  void usb_pdi_ack_setup( usb_device_t *udev) {
+    pdiWriteEndpoint( PDI_EP0_TX, 0, 0);
+  }
+
+
+/* acknowledge control transfer */
+  void usb_pdi_ack_control_setup( usb_device_t *udev) {
+    pdiAckSetupControl();
+  }
+
+  
+/**
+ * usb_pdi_check events
+ * function reads interrupt register and sets event flags
+ * function returns 1 if there is some new event.
+ * function returns 0 if there isn't new event but all is OK
+ * function returns -1 if there is any error
+*/
+  int usb_pdi_check_events( usb_device_t *udev) {
+    volatile unsigned char LastTrans = 0;
+    volatile unsigned int LastInt;
+    int ret = 0, i;
+
+    LastInt = pdiGetInterrupt();
+if ( LastInt) {
+  usb_debug_print( DEBUG_LEVEL_LOW, ("PI=0x%04X\n", LastInt));
+}
+    usb_debug_print( DEBUG_LEVEL_HIGH, ("PDI Int=0x%04X\n", LastInt));
+    
+    if ( LastInt & PDI_INT_BUSRESET) {                 // D12 - Bus reset reached
+      pdiInitChipState();
+      udev->flags |= USB_FLAG_BUS_RESET;
+      ret = 1;
+    } else {
+      #ifdef PDIUSBD12
+      if ( LastInt & PDI_INT_SUSPEND) {                 // D12 - Suspend flag changed
+        udev->flags |= USB_FLAG_SUSPEND;
+        ret = 1;
+      }
+      #endif
+
+            
+      if ( LastInt & PDI_INT_EP0_OUT) {                // D12 - Ep0RxDone - some data was received in EP0
+        LastTrans = pdiGetLastTransStatus( PDI_EP0_RX);
+        if ( LastTrans & PDI_LTSTAT_SETUP) { // setup packet
+          udev->flags |= USB_FLAG_SETUP;
+        } else {
+          udev->flags |= USB_FLAG_EVENT_RX0;
+        }
+        ret = 1;
+      }      
+      if ( LastInt & PDI_INT_EP0_IN) {                 // D12 - Ep0TxDone - data in EP0 was sended
+        LastTrans = pdiGetLastTransStatus( PDI_EP0_TX);
+        udev->flags |= USB_FLAG_EVENT_TX0;
+        ret = 1;
+      }
+
+      
+      for( i=0; i<udev->cntep; i++) {
+        if ( LastInt & (udev->ep+i)->event_mask) {
+          LastTrans = pdiGetLastTransStatus( (udev->ep+i)->epnum);
+          udev->ep_events |= 1<<i;
+          LastInt &= ~((udev->ep+i)->event_mask);
+          ret = 1;
+        }
+      }
+
+      /* check unsupported endpoints */
+      if ( LastInt & PDI_INT_EP1_OUT) {                // D12 - Ep1RxDone - some data was received in EP1
+        LastTrans = pdiGetLastTransStatus( PDI_EP1_RX);
+        pdiSetEpStatus( PDI_EP1_RX, PDI_SET_EP_STALLED);
+      }
+      if ( LastInt & PDI_INT_EP1_IN) {                 // D12 - Ep1TxDone - data in EP1 was sended
+        LastTrans = pdiGetLastTransStatus( PDI_EP1_TX);
+        pdiSetEpStatus( PDI_EP1_TX, PDI_SET_EP_STALLED);
+      }
+      if ( LastInt & PDI_INT_EP2_OUT) {                // D12 - Ep2RxDone - some data was received in EP2
+        LastTrans = pdiGetLastTransStatus( PDI_EP2_RX);
+        pdiSetEpStatus( PDI_EP2_RX, PDI_SET_EP_STALLED);
+      }
+      if ( LastInt & PDI_INT_EP2_IN) {                 // D12 - Ep2TxDone - data in EP2 was sended
+        LastTrans = pdiGetLastTransStatus( PDI_EP2_TX);
+        pdiSetEpStatus( PDI_EP2_TX, PDI_SET_EP_STALLED);
+      }
+     #if defined(PDIUSBD11) || defined(PDIUSBH11A_SINGLE)  // D11,H11_S
+      if ( LastInt & PDI_INT_EP3_OUT) {                // D11 - Ep3RxDone - some data was received in EP3
+        LastTrans = pdiGetLastTransStatus( PDI_EP3_RX);
+        pdiSetEpStatus( PDI_EP3_RX, PDI_SET_EP_STALLED);
+      }    
+      if ( LastInt & PDI_INT_EP3_IN) {                 // D11 - Ep3TxDone - data in EP3 was sended
+        LastTrans = pdiGetLastTransStatus( PDI_EP3_TX);
+        pdiSetEpStatus( PDI_EP3_TX, PDI_SET_EP_STALLED);
+      }
+     #endif /* D11,H11_S */
+    }
+    return ret;
+  }
+
+
+/* stall endpoint X */
+  void usb_pdi_stall( usb_ep_t *ep) {
+    if ( ep->epnum) {
+      pdiSetEpStatus( ep->epnum, PDI_SET_EP_STALLED);
+    } else { // endpoint0
+      pdiSetEpStatus( PDI_EP0_TX, PDI_SET_EP_STALLED);
+      pdiSetEpStatus( PDI_EP0_RX, PDI_SET_EP_STALLED);    
+    }
+  }
+
+  int usb_pdi_read_endpoint( usb_ep_t *ep, void *ptr, int size) USB_UDEV_REENTRANT_SIGN
+  {
+    if(!ep->epnum)
+       return pdiReadEndpoint( PDI_EP0_RX, size, ptr);
+    else
+       return pdiReadEndpoint( ep->epnum, size, ptr);
+  }
+  int usb_pdi_write_endpoint( usb_ep_t *ep, const void *ptr, int size) USB_UDEV_REENTRANT_SIGN
+  {
+    if(!ep->epnum)
+       pdiWriteEndpoint( PDI_EP0_TX, size, ptr);
+    else
+       pdiWriteEndpoint( ep->epnum, size, ptr);
+    return size;
+  }
+
+    
+/* init usb structures and chip */
+  int usb_pdi_init( usb_device_t *udev) {
+
+   #ifndef USB_PDI_DIRECT_FNC
+    udev->connect = usb_pdi_connect;
+    udev->disconnect = usb_pdi_disconnect;
+    udev->ack_setup = usb_pdi_ack_setup;
+    udev->ack_control_setup = usb_pdi_ack_control_setup;
+    udev->stall = usb_pdi_stall;
+    udev->check_events = usb_pdi_check_events;
+    udev->read_endpoint = usb_pdi_read_endpoint;
+    udev->write_endpoint = usb_pdi_write_endpoint;
+   #endif /*USB_PDI_DIRECT_FNC*/
+
+    udev->ep0.max_packet_size = PDI_EP0_PACKET_SIZE;
+
+    pdiInitChipState();
+    pdiSetMode( PDI_MODE_BASE_VALUE);
+    return 0;
+  }
diff --git a/common/libs4c/usb/pdiusb/pdi4rtems.c b/common/libs4c/usb/pdiusb/pdi4rtems.c
new file mode 100644 (file)
index 0000000..b76dd37
--- /dev/null
@@ -0,0 +1,193 @@
+/*****************************************************/
+/***   Module : USB PDI                            ***/
+/***   Author : Roman Bartosinski (C) 28.04.2002   ***/
+/***   Modify : 08.08.2002, 16.04.2003             ***/
+/*****************************************************/
+
+#include <stdio.h>
+#include <string.h>
+#include <inttypes.h>
+
+#include <system_def.h>
+#include <i2c_ifc.h>
+
+#include <usb/usb.h>
+#include <usb/usb_spec.h>
+#include <usb/pdiusb.h>
+#include <usb/pdi.h>
+#include <usb/usbdebug.h>
+
+#include <rtems.h>
+#include <rtems/io.h>
+#include <rtems/libio.h>
+#include <rtems/error.h>
+
+#undef PDI_I2C_DEBUG
+
+i2c_ifc_t *usb_pdi_i2c_ifc;
+int usb_pdi_i2c_error_cnt;
+int usb_pdi_connected;
+usb_device_t usb_pdi_device;
+static rtems_id usb_pdi_task=(rtems_id)0;
+
+void pdiSendCommand( unsigned char byCmd) {
+  if(i2c_master_transfer(usb_pdi_i2c_ifc, D11_REG_CMD,
+                         1, 0, &byCmd, NULL, NULL, NULL)<0) {
+    usb_pdi_i2c_error_cnt++;
+   #ifdef PDI_I2C_DEBUG
+    usb_debug_print( DEBUG_LEVEL_HIGH, ("uECM\n"));
+   #endif
+    return;
+  }
+ #ifdef PDI_I2C_DEBUG
+  usb_debug_print( DEBUG_LEVEL_HIGH, ("uCM %02x\n",byCmd));
+ #endif
+}
+
+unsigned char pdiReadData( unsigned char byCount, void *pbyData) {
+  int ret;
+
+  if(i2c_master_transfer(usb_pdi_i2c_ifc, D11_REG_DATA_READ,
+                         0, byCount, NULL, pbyData, NULL, &ret)<0) {
+    usb_pdi_i2c_error_cnt++;
+   #ifdef PDI_I2C_DEBUG
+    usb_debug_print( DEBUG_LEVEL_HIGH, ("uERD\n"));
+   #endif
+    return -1;
+  }
+ #ifdef PDI_I2C_DEBUG
+  usb_debug_print( DEBUG_LEVEL_HIGH, ("uRD "));
+  int i;
+  for(i=0;i<byCount;i++) usb_debug_print( DEBUG_LEVEL_HIGH,("%s%02X",i?",":"",((unsigned char*)pbyData)[i]));
+  usb_debug_print( DEBUG_LEVEL_HIGH, ("\n"));
+ #endif
+
+  return ret;
+}
+
+void pdiWriteData( unsigned char byCount, const void *pbyData) {
+  if(i2c_master_transfer(usb_pdi_i2c_ifc, D11_REG_DATA_WRITE,
+                         byCount, 0, &pbyData, NULL, NULL, NULL)<0){
+    usb_pdi_i2c_error_cnt++;
+   #ifdef PDI_I2C_DEBUG
+    usb_debug_print( DEBUG_LEVEL_HIGH, ("uEWR\n"));
+   #endif
+    return -1;
+  }
+
+ #ifdef PDI_I2C_DEBUG
+  usb_debug_print( DEBUG_LEVEL_HIGH, ("uWR "));
+  int i;
+  for(i=0;i<byCount;i++) usb_debug_print( DEBUG_LEVEL_HIGH,("%s%02X",i?",":"",((unsigned char*)pbyData)[i]));
+  usb_debug_print( DEBUG_LEVEL_HIGH, ("\n"));
+ #endif
+}
+
+static rtems_task
+usb_pdi_task_proc(rtems_task_argument argument)
+{
+  rtems_status_code status;
+  int res;
+  usb_device_t *udev=&usb_pdi_device;
+  
+  udev->id = 1;
+  udev->cntep = 0;
+
+ #ifndef USB_PDI_DIRECT_FNC
+  udev->init = usb_pdi_init;
+ #endif /*USB_PDI_DIRECT_FNC*/
+  usb_debug_set_level(DEBUG_LEVEL_HIGH);
+
+  do{
+
+    while(usb_pdi_connected) {
+    
+      //cmd_usb_processor_run();
+
+      if(1 /*check for IRQ there*/) res = usb_check_events(udev);
+
+      res |= usb_control_response(udev);
+
+      if(!res) {
+        status = rtems_task_wake_after(10);
+      }
+     
+      if(usb_pdi_i2c_error_cnt) {
+        usb_debug_print( DEBUG_LEVEL_MEDIUM, ("usb_pdi: I2C errors encountered, disconnecting\n"));
+        break;
+      }
+    }
+
+    if(usb_pdi_connected)
+      usb_disconnect(udev);
+
+    usb_pdi_connected=0;
+    usb_pdi_i2c_error_cnt=0;
+
+    /* wait before new attempt to connect to USB bus */
+    status = rtems_task_wake_after(1000);
+    
+    /* attempt to initialize PDI chip */
+    pdiSendCommand(0);
+    
+    udev->vendor_fnc=NULL;
+    
+    if(!usb_pdi_i2c_error_cnt) {
+
+      rtems_task_wake_after(100);
+
+      /* attempt to initialize PDI chip */
+      usb_pdi_init(udev);
+
+      rtems_task_wake_after(20);
+
+      /*connect to USB bus*/
+      res = usb_connect(udev);
+      if(res>=0) {
+        if(!usb_pdi_i2c_error_cnt) {
+          /*int chip_id;*/
+         usb_debug_print( DEBUG_LEVEL_LOW, ("usb_pdi: connect\n"));
+         usb_pdi_connected=1;
+         /*chip_id=pdiGetChipID();*/
+         /*usb_debug_print( DEBUG_LEVEL_MEDIUM, ("PDIUSB chip id is %04x\n",chip_id));*/
+       }
+      }
+      if(!usb_pdi_connected) {
+        usb_disconnect(udev);
+        usb_debug_print( DEBUG_LEVEL_LOW, ("usb_pdi: connect failed => disconnect\n"));
+      }
+    }
+
+  }while(1);
+}
+
+int usb_pdi4rtems_init(void)
+{
+  rtems_status_code status;
+
+  if(!usb_pdi_i2c_ifc)
+    usb_pdi_i2c_ifc = i2c_find_ifc(NULL, 0);
+
+  if(!usb_pdi_i2c_ifc)
+    return -1;
+
+  status=rtems_task_create (rtems_build_name('U','S','B','P'),
+          /*priority*/ USB_PDI_KWT_PRIORITY,
+          /*stacksize*/ RTEMS_MINIMUM_STACK_SIZE+1024,
+          RTEMS_DEFAULT_MODES /*RTEMS_PREEMPT|RTEMS_NO_TIMESLICE|RTEMS_NO_ASR|RTEMS_INTERRUPT_LEVEL(0)*/,
+          RTEMS_DEFAULT_ATTRIBUTES /*RTEMS_NO_FLOATING_POINT|RTEMS_LOCAL*/,
+          &usb_pdi_task);
+  if (status != RTEMS_SUCCESSFUL){
+    printf("usb_pdi4rtems_init: rtems_task_create %s\n",rtems_status_text(status));
+    return status;
+  }
+
+  status = rtems_task_start (usb_pdi_task, usb_pdi_task_proc, (rtems_task_argument)0);
+  if (status != RTEMS_SUCCESSFUL){
+    printf("usb_pdi4rtems_init: rtems_task_start %s\n",rtems_status_text(status));
+    return status;
+  }
+  
+  return 0;
+}
+
diff --git a/common/libs4c/usb/pdiusb/pdiusb.c b/common/libs4c/usb/pdiusb/pdiusb.c
new file mode 100644 (file)
index 0000000..280717c
--- /dev/null
@@ -0,0 +1,527 @@
+/*********************************************************/
+/***   Module : PDIUSB D11,H11,H11A,D12 - implement.   ***/
+/***   Author : Roman Bartosinski (C) 03.10.2002       ***/
+/***   Description : Integrate common functions for    ***/
+/***                PDIUSBD11,PDIUSBD12,PDIUSBH11(old) ***/
+/***                PDIUSBH11A in Single/Multiple mode ***/
+/***                 to one common file.               ***/
+/***   Modify : 10.10.2002 - add H11                   ***/
+/***            13.10.2002 - add spec.fnc for 'using'  ***/
+/*********************************************************/
+
+#include <system_def.h>
+#include <endian.h>
+#if __BYTE_ORDER == __BIG_ENDIAN
+  #include <byteswap.h>
+#endif
+#include <usb/pdiusb.h>
+#include <usb/usb_spec.h>
+
+  #ifdef PDI_CMD_RWD_INTERNAL
+   #ifndef PDIUSBD12
+     #include <periph/i2c.h>
+   #endif
+  #endif
+
+  #ifndef SDCC
+   #define xdata 
+  #endif
+
+
+/*********************************************************/
+// Function for read and write from/into chip
+
+ #if defined(PDI_CMD_RWD_INTERNAL)
+  #if defined(PDIUSBD12) // parallel interface
+
+   void pdiSendCommand( unsigned char byCmd) {
+     *((volatile xdata unsigned char *) PDIUSB_COMMAND_ADDR) = byCmd;
+   }
+   unsigned char pdiReadData( unsigned char byCount, void *pbyData) {
+     unsigned char out = byCount;
+     while (byCount) {
+       byCount--;
+       *(unsigned char*)pbyData++ = *((volatile xdata unsigned char *) PDIUSB_READ_DATA_ADDR);
+     }
+     return out;
+   }
+   void pdiWriteData( unsigned char byCount, const void *pbyData) {
+     while (byCount) {
+       byCount--;
+       *((volatile xdata unsigned char *) PDIUSB_WRITE_DATA_ADDR) = *(unsigned char*)pbyData++;
+     }
+   }
+
+   #if defined(PDI_USE_USING)
+     unsigned short pdiIntCmdReadData( unsigned char byCmd, unsigned char byShort) _PDI_USING {
+       unsigned char i[2];
+       *((volatile xdata unsigned char *) PDIUSB_COMMAND_ADDR) = byCmd;
+       i[0] = *((volatile xdata unsigned char *) PDIUSB_READ_DATA_ADDR);
+       if ( !byShort) {
+        i[1] = 0;
+        return i[0];
+       }
+       i[1] = *((volatile xdata unsigned char *) PDIUSB_READ_DATA_ADDR);
+       return (((unsigned short) i[1]) << 8) + i[0];
+     }
+   #endif
+
+  #else // serial interface iic
+   #ifndef D11_REG_CMD
+     #define D11_REG_CMD  PDIUSB_COMMAND_ADDR
+   #endif
+   #ifndef D11_REG_DATA_WRITE
+     #define D11_REG_DATA_WRITE PDIUSB_WRITE_DATA_ADDR
+   #endif
+   #ifndef D11_REG_DATA_READ
+     #define D11_REG_DATA_READ PDIUSB_READ_DATA_ADDR
+   #endif
+     
+   void pdiSendCommand( unsigned char byCmd) {
+     I2C_Write( D11_REG_CMD, &byCmd, 1);
+   }
+   unsigned char pdiReadData( unsigned char byCount, void *pbyData) {
+     I2C_Read( D11_REG_DATA_READ, pbyData, byCount);
+     return byCount;
+   }
+   void pdiWriteData( unsigned char byCount, const void *pbyData) {
+     I2C_Write( D11_REG_DATA_WRITE, pbyData, byCount);
+   }
+   #if defined(PDI_USE_USING)
+    unsigned short pdiIntCmdReadData( unsigned char byCmd, unsigned char byShort) _PDI_USING {
+    }
+   #endif
+
+  #endif
+ #endif
+
+
+/*********************************************************/
+/*********************************************************/
+// PDIUSB common commands
+
+#if defined(PDIUSBH11) || defined(PDIUSBH11A) || defined(PDIUSBD11)
+
+ /*********************************************************/
+ // pdiSetHUBAddressEnable
+ // enable HUB function and set address (byAddress is 0-0x7F, byEnable is 0 or 1)
+   void pdiSetHUBAddressEnable( unsigned char byAddress, unsigned char byEnable) {
+// usb_debug_print( DEBUG_LEVEL_HIGH, ("H "));
+     byAddress = (byAddress & 0x7F) | (byEnable << 7);
+     pdiSendCommand( PDI_CMD_HUB_ENB_ADDR);
+     pdiWriteData( 1, &byAddress);
+   }
+
+#endif
+#if !defined(PDIUSBH11A_MULTPLE) // D11,D12,H11,H11A_S(emb.fnc)
+
+ /*********************************************************/
+ // pdiSetAddressEnable
+ // Enable function and set address (byAddress is 0-0x7F, byEnable is 0 or 1)
+   void pdiSetAddressEnable( unsigned char byAddr_Enb) {
+// usb_debug_print( DEBUG_LEVEL_HIGH, ("A "));
+     pdiSendCommand( PDI_CMD_FNC_ENB_ADDR);
+     pdiWriteData( 1, &byAddr_Enb);
+   }
+
+#else
+
+ /*********************************************************/
+ // pdiSetEmbFncAddressEnable
+ // Enable Embedded function and set address (byAddress is 0-0x7F, byEnable is 0 or 1)
+ // byFnc - function index (zero based) 0-3
+   void pdiSetEmbFncAddressEnable( unsigned char byFnc, unsigned char byAddress, unsigned char byEnable) {
+     byAddress = (byAddress & 0x7F) | (byEnable << 7);
+     pdiSendCommand( PDI_CMD_FNC1_ENB_ADDR + byFnc);
+     pdiWriteData( 1, &byAddress);
+   }
+
+#endif
+
+
+
+ /*********************************************************/
+ // pdiSetEndpointEnable
+ // enable/disable endpoints (PDI_EPEN_xxx)
+   void pdiSetEndpointEnable( unsigned char byEnable) {
+// usb_debug_print( DEBUG_LEVEL_HIGH, ("E "));
+     pdiSendCommand( PDI_CMD_EPEN);
+     pdiWriteData( 1, &byEnable);
+   }
+
+
+#if !defined(PDIUSBH11)  // H11 has not it
+
+ /*********************************************************/
+ // pdiSetMode
+ // set chip mode (PDI_MODE_xxx) and clock division factor (PDI_CLOCK_xxx)
+  void pdiSetMode( unsigned short wMode_Clock) {
+     unsigned char sm[2];
+// usb_debug_print( DEBUG_LEVEL_HIGH, ("M%04X ",wMode_Clock));
+     sm[0] = (unsigned char) (wMode_Clock & 0xff);
+     sm[1] = (unsigned char) (wMode_Clock >> 8);
+     pdiSendCommand( PDI_CMD_SET_MODE);
+     pdiWriteData( 2, sm);
+   }
+
+#endif
+
+ #if defined(PDIUSBD12)
+
+ /*********************************************************/
+ // pdiSetDMA
+ // set DMA mode (PDI_DMA_xxx)
+  void pdiSetDMA( unsigned char byDma) {
+    pdiSendCommand( PDI_CMD_SET_DMA);
+    pdiWriteData( 1, &byDma);
+  }
+
+ /*********************************************************/
+ // pdiGetDMA
+ // get current DMA mode
+  unsigned char pdiGetDMA( void) {
+    unsigned char dma;
+    pdiSendCommand( PDI_CMD_GET_DMA);
+    pdiReadData( 1, &dma);
+    return dma;
+  }
+
+ #endif
+
+
+ #if defined(PDIUSBH11)
+
+ /*********************************************************/
+
+ // pdiGetInterrupt - H11 return only one byte
+ // get interrupt register (PDI_INT_xxx)
+  unsigned char pdiGetInterrupt( void) _PDI_USING {
+    unsigned char gin;
+#if defined(PDI_USE_USING)
+    return pdiIntCmdReadData( PDI_CMD_GET_INT_REG, 0);
+#else
+    pdiSendCommand( PDI_CMD_GET_INT_REG);
+    pdiReadData( 1, &gin);
+    return gin;
+#endif
+  }
+
+ #else
+
+ /*********************************************************/
+ // pdiGetInterrupt
+ // get interrupt register (PDI_INT_xxx)
+  unsigned short pdiGetInterrupt( void) _PDI_USING {
+    unsigned short gin;
+#if defined(PDI_USE_USING)
+    return pdiIntCmdReadData( PDI_CMD_GET_INT_REG, 1);
+#else
+    pdiSendCommand( PDI_CMD_GET_INT_REG);
+    pdiReadData( 2, &gin);
+   #if __BYTE_ORDER == __BIG_ENDIAN
+    gin=bswap_16(gin);
+   #endif
+    return gin; //pdiData[0] + (((unsigned short)pdiData[1])<<8);
+#endif
+  }
+
+ #endif
+
+ /*********************************************************/
+ // pdiSelectEp
+ // set internal buffer pointer to selected endpoint (zero based) (PDI_SELEP_xxx)
+  unsigned char pdiSelectEp( unsigned char byEpIdx) {
+    unsigned char sep;
+// usb_debug_print( DEBUG_LEVEL_HIGH, ("e%1d ",byEpIdx));
+    pdiSendCommand( PDI_CMD_SELECT_EP + byEpIdx);
+    pdiReadData( 1, &sep);
+    return sep;
+  }
+
+ /*********************************************************/
+ // pdiGetLastTransStatus
+ // get Last transaction status (PDI_LTSTAT_xxx and PDI_ERR_xxx)
+  unsigned char pdiGetLastTransStatus( unsigned char byEpIdx) _PDI_USING {
+    unsigned char lts;
+// usb_debug_print( DEBUG_LEVEL_HIGH, ("L "));
+#if defined(PDI_USE_USING)
+    return pdiIntCmdReadData( PDI_CMD_GET_LAST_STAT + byEpIdx, 0);
+#else
+    pdiSendCommand( PDI_CMD_GET_LAST_STAT + byEpIdx);
+    pdiReadData( 1, &lts);
+    return lts;
+#endif
+  }
+
+
+ #if defined(PDIUSBD11) || defined(PDIUSBH11) || defined(PDIUSBH11A)
+
+ /*********************************************************/
+ // pdiGetEpStatus
+ // get Endpoint Status (PDI_EPSTAT_xxx)
+  unsigned char pdiGetEpStatus( unsigned char byEpIdx) {
+    unsigned char ges;
+// usb_debug_print( DEBUG_LEVEL_HIGH, ("G "));
+    pdiSendCommand( PDI_CMD_GET_EP_STAT + byEpIdx);
+    pdiReadData( 1, &ges);
+    return ges;
+  }
+
+ #endif
+
+ /*********************************************************/
+ // pdiReadFromEpBuffer - raw reading
+ // read data from selected internal chip buffer
+ // if byLength < length of buffer data, so we read only byLength data)
+  unsigned char pdiReadFromEpBuffer( unsigned char byLength, unsigned char *pToBuff) {
+    unsigned char rdep[2];
+// usb_debug_print( DEBUG_LEVEL_HIGH, ("R "));
+    pdiSendCommand( PDI_CMD_READ_BUFFER);
+    pdiReadData( 2, rdep);
+    if ( rdep[1]) { // there is some data
+      if ( byLength < rdep[1]) // we need less data then is received
+        rdep[1] = byLength;
+      pdiReadData( rdep[1], pToBuff);
+    }
+    return rdep[1];
+  }
+
+ /*********************************************************/
+ // pdiWriteToEpBuffer - raw writing
+ // write data to selected internal chip buffer
+  void pdiWriteToEpBuffer( unsigned char byLength, const unsigned char *pFromBuff) {
+    unsigned char hd[2];
+// usb_debug_print( DEBUG_LEVEL_HIGH, ("W "));
+    pdiSendCommand( PDI_CMD_WRITE_BUFFER);
+    hd[0] = 0; hd[1] = byLength;
+    pdiWriteData( 2, hd);
+    if ( byLength) {
+      pdiWriteData( byLength, pFromBuff);
+    }
+  }
+
+ /*********************************************************/
+ // pdiSetEpStatus
+ // set endpoint stall flag
+  void pdiSetEpStatus( unsigned char byEpIdx, unsigned char byStatus) {
+// usb_debug_print( DEBUG_LEVEL_HIGH, ("T "));
+    pdiSendCommand( PDI_CMD_SET_EP_STAT + byEpIdx);
+    pdiWriteData( 1, &byStatus);
+  }
+
+ /*********************************************************/
+ // pdiAcknowledgeSetup
+ // chip disable fncs Validate and Clear after SETUP packet,
+ // this cmd re-enable these fncs
+  void pdiAcknowledgeSetup( void) {
+// usb_debug_print( DEBUG_LEVEL_HIGH, ("C "));
+    pdiSendCommand( PDI_CMD_ACK_SETUP);
+  }
+
+ /*********************************************************/
+ // pdiClearBuffer
+ // set endpoint flag 'empty' and next data can be receive
+  void pdiClearBuffer( void) {
+// usb_debug_print( DEBUG_LEVEL_HIGH, ("B "));
+    pdiSendCommand( PDI_CMD_CLEAR_BUFFER);
+  }
+
+
+ /*********************************************************/
+ // pdiValidateBuffer
+ // set endpoint flag 'full' and data can be send
+  void pdiValidateBuffer( void) {
+// usb_debug_print( DEBUG_LEVEL_HIGH, ("V "));
+    pdiSendCommand( PDI_CMD_VALID_BUFFER);
+  }
+
+ /*********************************************************/
+ // pdiSendResume
+ // send an upstream resume signal for 10ms
+  void pdiSendResume( void) {
+// usb_debug_print( DEBUG_LEVEL_HIGH, ("M "));
+    pdiSendCommand( PDI_CMD_SEND_RESUME);
+  }
+
+ /*********************************************************/
+ // pdiGetFrameNumber
+ // return frame number of last successfully received SOF
+  unsigned short pdiGetFrameNumber( void) {
+    unsigned short gfn;
+    pdiSendCommand( PDI_CMD_GET_FRAME);
+    pdiReadData( 2, &gfn);
+   #if __BYTE_ORDER == __BIG_ENDIAN
+    gfn=bswap_16(gfn);
+   #endif
+    return gfn; //pdiData[0] + (((unsigned short)pdiData[1])<<8);
+  }
+  
+ /*********************************************************/
+ // pdiGetChipID  - this function is undocumented
+ // read chip ID (not documented function) ( LSB is maybe type of chip in hex (0x12,0x11))
+  unsigned short pdiGetChipID( void) {
+    unsigned short gid;
+    pdiSendCommand( PDI_CMD_GET_CHIP_ID);
+    pdiReadData( 2, &gid);
+   #if __BYTE_ORDER == __BIG_ENDIAN
+    gid=bswap_16(gid);
+   #endif
+    return gid; //pdiData[0] + (((unsigned short)pdiData[1])<<8);
+  }    
+
+
+ /*********************************************************/
+ /*********************************************************/
+ // HUB command
+#if defined(PDIUSBH11) || defined(PDIUSBH11A)
+ /*********************************************************/
+ // pdiClearPortFeature
+ // clear feature 'byFeature' in downstream port 2-5 'byEpIdx' (zero based)
+  void pdiClearPortFeature( unsigned char byEpIdx, unsigned char byFeature) {
+    pdiSendCommand( PDI_CMD_P2_CLR_FEATURE + byEpIdx);
+    pdiWriteData( 1, &byFeature);
+  }
+
+ /*********************************************************/
+ // pdiSetPortFeature
+ // set feature 'byFeature' in downstream port 2-5 'byEpIdx' (zero based)
+  void pdiSetPortFeature( unsigned char byEpIdx, unsigned char byFeature) {
+    pdiSendCommand( PDI_CMD_P2_SET_FEATURE + byEpIdx);
+    pdiWriteData( 1, &byFeature);
+  }
+  
+ /*********************************************************/
+ // pdiGetPortFeature
+ // get port status (port status byte and port status change byte)
+  unsigned short pdiGetPortFeature( unsigned char byEpIdx) {
+    unsigned short gpf;
+    pdiSendCommand( PDI_CMD_P2_GET_STATUS + byEpIdx);
+    pdiReadData( 2, &gpf);
+   #if __BYTE_ORDER == __BIG_ENDIAN
+    gpf=bswap_16(gpf);
+   #endif
+    return gpf; //pdiData[0] + (((unsigned short)pdiData[1])<<8);
+  }
+  
+ /*********************************************************/
+ // pdiSetStatusChangeBits
+ // set local power change bits status
+  void pdiSetStatusChangeBits( unsigned char byBits) {
+    pdiSendCommand( PDI_CMD_SET_CHNG_BITS);
+    pdiWriteData( 1, &byBits);
+  }
+  
+#endif
+
+
+
+/*********************************************************/
+/*********************************************************/
+// PDIUSB other commands
+
+ // complex function for select endpoint, write data and validate data in endpoint buffer
+ void pdiWriteEndpoint( unsigned char byEpIdx, unsigned char byLength, const unsigned char *pbyData) {
+   pdiSelectEp( byEpIdx);
+   pdiWriteToEpBuffer( byLength, pbyData);
+   pdiValidateBuffer();
+ }
+
+ // complex function for select endpoint, read data and clear endpoint buffer
+ // byMaxLength means how many bytes will be maximally read.
+ unsigned char pdiReadEndpoint( unsigned char byEpIdx, unsigned char byMaxLength, unsigned char *pbyData) {
+   unsigned char cnt = 0, sep;
+   sep = pdiSelectEp( byEpIdx);
+   if ( sep & PDI_SELEP_FULL) {
+    cnt = pdiReadFromEpBuffer( byMaxLength, pbyData);
+    pdiClearBuffer();
+   }
+   return cnt;
+ }
+
+ // complex universal function for select command and read/write data to/from PDIUSB
+ unsigned char pdiCmdData( unsigned char byCmd, unsigned char *pbyData,
+                           unsigned char byCount, unsigned char byRead) {
+   pdiSendCommand( byCmd);
+   if ( byCount) {
+     if( byRead) byCount = pdiReadData( byCount, pbyData);  // Read Data
+     else pdiWriteData( byCount, pbyData);                  // Write Data
+   }
+   return byCount;   
+ }
+
+#if !defined(PDIUSBH11A_MULTIPLE)
+ // complex function for acknowledge control endpoint
+ void pdiAckSetupControl( void) {
+   pdiSendCommand( PDI_CMD_SELECT_EP + PDI_EP0_RX);
+   pdiSendCommand( PDI_CMD_ACK_SETUP);
+   pdiSendCommand( PDI_CMD_CLEAR_BUFFER);
+   pdiSendCommand( PDI_CMD_SELECT_EP + PDI_EP0_TX);
+   pdiSendCommand( PDI_CMD_ACK_SETUP);
+ }
+#else
+ // complex function for acknowledge control endpoint ( for one emb.fnc. 1,6,7) (zero-based 0,1,2)
+ void pdiAckSetupFncControl( unsigned char Fnc) {
+   unsigned char FncTab[3] = { PDI_F1_EP0_RX, PDI_F6_EP0_RX, PDI_F7_EP0_RX};
+   pdiSendCommand( PDI_CMD_SELECT_EP + FncTab[Fnc]);
+   pdiSendCommand( PDI_CMD_ACK_SETUP);
+   pdiSendCommand( PDI_CMD_CLEAR_BUFFER);
+   pdiSendCommand( PDI_CMD_SELECT_EP + FncTab[Fnc] + 1);
+   pdiSendCommand( PDI_CMD_ACK_SETUP);
+ }
+#endif
+
+#if defined(PDIUSBD12) // parallel interface
+ void pdiInit( void) {
+   pdiSetAddressEnable( PDI_ENAD_ENABLE);
+   pdiSetEndpointEnable( PDI_EPEN_ENABLE);
+   pdiSetDMA( PDI_DMA_EP4_INT | PDI_DMA_EP5_INT);
+   pdiSetMode( PDI_MODE_NO_LAZY_CLOCK | PDI_MODE_CLOCK_RUNNING |
+               PDI_MODE_SOFT_CONNECT | PDI_CLOCK_12M);
+ }
+#endif
+
+#if defined(PDIUSBH11A_SINGLE) // serial interface
+ void pdiInit( void) {
+   pdiSetHUBAddressEnable( 0, 0); // disable HUB
+   pdiSetAddressEnable( PDI_ENAD_ENABLE);    // enable emb.function
+   pdiSetEndpointEnable( PDI_EPEN_FNC_ENB);
+   pdiSetMode( PDI_MODE_REMOTE_WAKEUP | PDI_MODE_NO_LAZY_CLOCK | PDI_MODE_CLOCK_RUNNING |
+               PDI_MODE_SOFT_CONNECT | PDI_MODE_SINGLE_FNC | PDI_CLOCK_12M);
+ }
+#endif
+
+/*********************************************************/
+
+ static const unsigned char epin2idx[]={
+   PDI_EP0_IN,
+   PDI_EP1_IN,
+  #if PDI_CNT_EP > 1
+   PDI_EP2_IN,
+  #if PDI_CNT_EP > 2
+   PDI_EP3_IN,
+  #endif
+  #endif
+ };
+
+ static const unsigned char epout2idx[]={
+   PDI_EP0_OUT,
+   PDI_EP1_OUT,
+  #if PDI_CNT_EP > 1
+   PDI_EP2_OUT,
+  #if PDI_CNT_EP > 2
+   PDI_EP3_OUT,
+  #endif
+  #endif
+ };
+
+ // pdiEp2Idx
+ // convert endpoint number to pdi index number
+ unsigned char pdiEp2Idx(unsigned char ep) {
+   if(ep & USB_ENDPOINT_DIRECTION_MASK)
+     return epin2idx[ep & 0xf];
+   else
+     return epout2idx[ep & 0xf];
+ }
+
+ /*********************************************************/
+ /*********************************************************/
diff --git a/common/libs4c/usb/pdiusb/usb/pdi.h b/common/libs4c/usb/pdiusb/usb/pdi.h
new file mode 100644 (file)
index 0000000..21bb5db
--- /dev/null
@@ -0,0 +1,49 @@
+/*****************************************************/
+/***   Module : USB PDI - header file              ***/
+/***   Author : Roman Bartosinski (C) 28.04.2002   ***/
+/***   Modify : 08.08.2002, 16.04.2003             ***/
+/*****************************************************/
+
+#ifndef _USB_PDI_SUBMODULE_HEADER_FILE_
+  #define _USB_PDI_SUBMODULE_HEADER_FILE_
+
+  #include <usb/usb.h>
+//  int usb_pdi_init( usb_device_t *udev) REENTRANT_SIGN;
+  int usb_pdi_init( usb_device_t *udev);
+  
+  #ifdef USB_PDI_DIRECT_FNC
+    #define USB_PDI_EXPORT_FNC
+
+    #define usb_udev_is_fnc(_M_udev, _M_fnc) (1)
+
+    #define usb_udev_init usb_pdi_init
+    #define usb_udev_connect usb_pdi_connect
+    #define usb_udev_disconnect usb_pdi_disconnect
+    #define usb_udev_ack_setup usb_pdi_ack_setup
+    #define usb_udev_ack_control_setup usb_pdi_ack_control_setup
+    #define usb_udev_check_events usb_pdi_check_events
+
+    #define usb_udev_stall usb_pdi_stall
+    #define usb_udev_read_endpoint usb_pdi_read_endpoint
+    #define usb_udev_write_endpoint usb_pdi_write_endpoint
+
+  #endif /*USB_PDI_DIRECT_FNC*/
+
+  #ifdef USB_PDI_EXPORT_FNC
+
+    int usb_pdi_init( usb_device_t *udev);
+    int usb_pdi_connect( usb_device_t *udev);
+    int usb_pdi_disconnect( usb_device_t *udev);
+    void usb_pdi_ack_setup( usb_device_t *udev);
+    void usb_pdi_ack_control_setup( usb_device_t *udev);
+    int usb_pdi_check_events( usb_device_t *udev);
+
+    void usb_pdi_stall( usb_ep_t *ep);
+    int usb_pdi_read_endpoint( usb_ep_t *ep, void *ptr, int size) USB_UDEV_REENTRANT_SIGN;
+    int usb_pdi_write_endpoint( usb_ep_t *ep, const void *ptr, int size) USB_UDEV_REENTRANT_SIGN;
+
+  #endif /*USB_PDI_EXPORT_FNC*/
+
+#endif /* _USB_PDI_SUBMODULE_HEADER_FILE_ */
+
diff --git a/common/libs4c/usb/pdiusb/usb/pdiusb.h b/common/libs4c/usb/pdiusb/usb/pdiusb.h
new file mode 100644 (file)
index 0000000..f006cb8
--- /dev/null
@@ -0,0 +1,674 @@
+/*********************************************************/
+/***   Module : PDIUSB D11,H11,H11A,D12 - header file  ***/
+/***   Author : Roman Bartosinski (C) 03.10.2002       ***/
+/***   Description : Integrate common functions for    ***/
+/***                PDIUSBD11,PDIUSBD12,PDIUSBH11(old) ***/
+/***                PDIUSBH11A in Single/Multiple mode ***/
+/***                 to one common file.               ***/
+/***   Modify : 10.10.2002 - add H11                   ***/
+/***            13.10.2002 - add spec.fnc for 'using'  ***/
+/***            22.12.2002 - rebuild for smaller out   ***/
+/*********************************************************/
+
+#ifndef _PDIUSB_BASE_MODULE
+ #define _PDIUSB_BASE_MODULE
+
+/*********************************************************/
+// Comments - !!! Please, read this section !!!
+//
+//
+// If you can use included functions for read and write
+//  byte from/to PDIUSB, please uncomment defined PDI_CMD_RWD_INTERNAL
+//  and check defined addresses for communication with PDIUSB.
+// Else you must uncomment defined PDI_CMD_RWD_EXTERNAL and declare
+//  and implement next functions :
+//     void pdiSendCommand( unsigned char byCmd);
+//     unsigned char pdiReadData( unsigned char byCount, void *pbyData);
+//     void pdiWriteData( unsigned char byCount, const void *pbyData);
+//  - if you want use 'using' (see below), you must implement next function(on i51 is NEEDED).
+//     unsigned short pdiIntCmdReadData( unsigned char byCmd, unsigned char byShort) _PDI_USING;
+// -- all in section 'External functions'
+//
+//
+// Next you must select type of chip.(uncomment line with defined type)
+// -- in section 'Type of PDIUSB'
+//
+//
+// If you want use functions 'pdiGetInterrupt' and 'pdiGetLastTransStatus'
+// with keyword 'using' (for i51 it means using spec.reg.bank), uncomment
+// define 'USING'. Only these two functions need pdiIntCmdReadData.
+// -- in section 'Use using in interrupt functions'
+//
+// ***   External choice   ***
+// Or you can make all previous choises externally before including this file
+// by defining one of PDIUSBD11,PDIUSBD12,PDIUSBH11,PDIUSBH11A_SINGLE,PDIUSBH11A_MULTIPLE
+//
+// defining one of PDI_CMD_RWD_INTERNAL,PDI_CMD_RWD_EXTERNAL
+// (you can define externally PDIUSB_COMMAND_ADDR, PDIUSB_READ_DATA_ADDR, PDIUSB_WRITE_DATA_ADDR)
+//
+// and defining one of PDI_USE_USING,PDI_DONTUSE_USING
+// (you can define externally _PDI_USING_NUMBER)
+
+
+
+/*********************************************************/ 
+// Type of PDIUSB
+
+
+//
+//   PDIUSBD11           - USB device with serial interface
+//   PDIUSBH11           - USB hub with one embedded fnc and serial interface
+//   PDIUSBH11A_SINGLE   - USB hub with one embedded fnc, serial interface and additional functions
+//   PDIUSBH11A_MULTIPLE - USB hub with multiple(3) embedded fncs, serial interface and add.fncs
+//   - H11A_SINGLE and H11A_MULTIPLE is divided by pdiusb command SetMode (bit is set automatically)
+//   PDIUSBD12           - USB device with parallel interface
+//
+
+// uncomment right chip type below
+
+//#define PDIUSBD11
+//#define PDIUSBH11
+//#define PDIUSBH11A_SINGLE
+//#define PDIUSBH11A_MULTIPLE
+#define PDIUSBD12
+
+                                                              
+/*********************************************************/
+// Create common type PDIUSBH11A for SINGLE and MULTIPLE
+// for mux H11A_S & H11A_M
+#if defined(PDIUSBH11A_SINGLE) || defined(PDIUSBH11A_MULTIPLE)
+  #define PDIUSBH11A
+#else
+  #undef  PDIUSBH11A
+#endif
+
+
+
+/*********************************************************/
+//  Use using in interrupt functions
+
+  // If you want use keyword 'using' in function
+  // 'pdiGetInterrupt' and 'pdiGetLastTransStatus',
+  // uncomment next line.(and check and correct number in _PDI_USING_NUMBER)
+//#define PDI_USE_USING
+  // If you don't want use keyword 'using',
+  // uncomment next line.
+#define PDI_DONTUSE_USING
+
+ #if defined(PDI_USE_USING)
+  #if !defined(_PDI_USING_NUMBER)
+   #define _PDI_USING_NUMBER  2
+  #endif
+  #define _PDI_USING   using _PDI_USING_NUMBER
+ #else
+  #define _PDI_USING
+ #endif
+
+
+/*********************************************************/
+//  External functions
+
+  // If you want use internal functions, uncomment next line.
+//#define PDI_CMD_RWD_INTERNAL
+  // If you want use your own external functions, uncomment next line.
+//#define PDI_CMD_RWD_EXTERNAL
+
+// this is automatically selected by your choice
+
+ #if defined(PDI_CMD_RWD_INTERNAL)
+  #if !defined(PDIUSB_COMMAND_ADDR)       // if not defined address for select command
+   #if defined(PDIUSBD12)
+    #define PDIUSB_COMMAND_ADDR    0x7001 // sel.cmd address for D12 (this is address for my application)
+   #else
+    #define PDIUSB_COMMAND_ADDR    0x36   // sel.cmd address for all other
+   #endif
+  #endif
+  #if !defined(PDIUSB_READ_DATA_ADDR)     // if not defined address for read data from chip
+   #if defined(PDIUSBD12)
+    #define PDIUSB_READ_DATA_ADDR  0x7000 // read data address for D12
+   #else
+    #define PDIUSB_READ_DATA_ADDR  0x35   // read data address for all other
+   #endif
+  #endif
+  #if !defined(PDIUSB_WRITE_DATA_ADDR)    // if not defined address for write data to chip
+   #if defined(PDIUSBD12)
+    #define PDIUSB_WRITE_DATA_ADDR 0x7000 // write data address for D12
+   #else
+    #define PDIUSB_WRITE_DATA_ADDR 0x34   // write data address for all other
+   #endif
+  #endif
+
+ #endif  
+
+/* Build internal version of functions, but do not define addresses */
+#define PDI_CMD_RWD_INTERNAL
+
+  extern void pdiSendCommand( unsigned char byCmd);
+  extern unsigned char pdiReadData( unsigned char byCount, void *pbyData);
+  extern void pdiWriteData( unsigned char byCount, const void *pbyData);
+#if defined(PDI_USE_USING)
+  extern unsigned short pdiIntCmdReadData( unsigned char byCmd, unsigned char byShort) _PDI_USING;
+#endif
+
+
+/*********************************************************/
+// Check chip selection, int/ext rw functions, using
+
+#if !defined(PDIUSBD11) && !defined(PDIUSBH11) && !defined(PDIUSBH11A) && !defined(PDIUSBD12)
+  #define _PDI_ERROR_NO_CONTINUE
+  #error "!!! Any type of PDIUSB wasn't selected !!!"
+  #error "Please select one of PDIUSB in file pdiusb.h in section 'Type of PDIUSB'."  
+#endif
+#if !defined(PDI_CMD_RWD_INTERNAL) && !defined(PDI_CMD_RWD_EXTERNAL)
+  #define _PDI_ERROR_NO_CONTINUE
+  #error "!!! You must select if you want use internal or external basic fncs for PDIUSB !!!"
+  #error "Please select your choice in file pdiusb.h in section 'External functions'."
+#endif
+#if !defined(PDI_USE_USING) && !defined(PDI_DONTUSE_USING)
+  #define _PDI_ERROR_NO_CONTINUE
+  #error "!!! You must choose if you want keyword 'using' !!!"
+  #error "Please see into file pdiusb.h in section 'Use using in interrupt functions'."
+#endif
+
+#if defined(_PDI_ERROR_NO_CONTINUE)
+  #error " For help ... read in file pdiusb.h section 'Comments'."
+#endif
+
+
+/*********************************************************/
+/*********************************************************/
+#if !defined(_PDI_ERROR_NO_CONTINUE)
+
+/*********************************************************/    
+// Endpoints - size and index defines
+
+  //  PDI_CNT_EP - number of endpoints without control endpoints
+#if defined(PDIUSBD11) || defined(PDIUSBH11A_SINGLE)       // D11, H11A_S
+  #define PDI_CNT_EP    0x03
+#elif defined(PDIUSBH11) || defined(PDIUSBH11A_MULTIPLE)  // H11, H11A_M
+  #define PDI_CNT_EP    0x01
+#elif defined(PDIUSBD12)                                  // D12
+  #define PDI_CNT_EP    0x02
+#endif
+
+  //  PDI_EPx_yyyy_SIZE - max packet size for endpoint x  
+#if defined(PDIUSBH11) || defined(PDIUSBH11A)             // H11, H11A
+  #define PDI_HUB_TX_SIZE      8
+  #define PDI_HUB_RX_SIZE      8
+  #define PDI_HUB_PACKET_SIZE  8
+ #if defined(PDIUSBH11)
+  #define PDI_HUB_INT_SIZE     1
+ #endif
+#endif
+
+
+#if !defined(PDIUSBD12)                     // D11,H11,H11A
+  #define PDI_EP0_TX_SIZE      8
+  #define PDI_EP0_RX_SIZE      8
+  #define PDI_EP0_PACKET_SIZE  8
+  #define PDI_EP1_TX_SIZE      8
+  #define PDI_EP1_RX_SIZE      8
+  #define PDI_EP1_PACKET_SIZE  8
+ #if defined(PDIUSBD11) || defined(PDIUSBH11A_SINGLE)
+  #define PDI_EP2_TX_SIZE      8
+  #define PDI_EP2_RX_SIZE      8
+  #define PDI_EP2_PACKET_SIZE  8
+  #define PDI_EP3_TX_SIZE      8
+  #define PDI_EP3_RX_SIZE      8
+  #define PDI_EP3_PACKET_SIZE  8
+ #endif
+#else                                       // D12
+  #define PDI_EP0_TX_SIZE      16
+  #define PDI_EP0_RX_SIZE      16
+  #define PDI_EP0_PACKET_SIZE  16
+  #define PDI_EP1_TX_SIZE      16
+  #define PDI_EP1_RX_SIZE      16
+  #define PDI_EP1_PACKET_SIZE  16
+  #define PDI_EP2_TX_SIZE      64
+  #define PDI_EP2_RX_SIZE      64
+  #define PDI_EP2_PACKET_SIZE  64
+#endif
+
+  //  PDI_EPx_TX, PDI_EPx_RX - index for endpoint x (write/read)
+#if defined(PDIUSBH11) || defined(PDIUSBH11A)                                        // H11
+  #define PDI_HUB_EP0_RX  0
+  #define PDI_HUB_EP0_TX  1
+  // another index names
+  #define PDI_HUB_EP0_OUT  PDI_HUB_EP0_RX
+  #define PDI_HUB_EP0_IN   PDI_HUB_EP0_TX
+#endif
+
+#if defined(PDIUSBH11)
+  #define PDI_EP0_RX  2
+  #define PDI_EP0_TX  3
+  #define PDI_EP1_TX  4
+  // another index names
+  #define PDI_EP0_OUT  PDI_EP0_RX
+  #define PDI_EP0_IN   PDI_EP0_TX
+  #define PDI_EP1_IN   PDI_EP1_TX
+#elif defined(PDIUSBD11) || defined(PDIUSBH11A_SINGLE)          // D11,H11A_S
+  #define PDI_EP0_RX  2
+  #define PDI_EP0_TX  3
+  #define PDI_EP1_RX  5
+  #define PDI_EP1_TX  4
+  #define PDI_EP2_RX  6
+  #define PDI_EP2_TX  7
+  #define PDI_EP3_RX  8
+  #define PDI_EP3_TX  9
+  // another index names
+  #define PDI_EP0_OUT  PDI_EP0_RX
+  #define PDI_EP0_IN   PDI_EP0_TX
+  #define PDI_EP1_OUT  PDI_EP1_RX
+  #define PDI_EP1_IN   PDI_EP1_TX
+  #define PDI_EP2_OUT  PDI_EP2_RX
+  #define PDI_EP2_IN   PDI_EP2_TX
+  #define PDI_EP3_OUT  PDI_EP3_RX
+  #define PDI_EP3_IN   PDI_EP3_TX
+#elif defined(PDIUSBH11A_MULTIPLE)                            // H11_M
+  #define PDI_F1_EP0_RX   2
+  #define PDI_F1_EP0_TX   3
+  #define PDI_F1_EP1_RX   5
+  #define PDI_F1_EP1_TX   4
+  #define PDI_F6_EP0_RX  10
+  #define PDI_F6_EP0_TX  11
+  #define PDI_F6_EP1_RX   6
+  #define PDI_F6_EP1_TX   7
+  #define PDI_F7_EP0_RX  12
+  #define PDI_F7_EP0_TX  13
+  #define PDI_F7_EP1_RX   8
+  #define PDI_F7_EP1_TX   9
+  // another index names
+  #define PDI_F1_EP0_OUT  PDI_F1_EP0_RX
+  #define PDI_F1_EP0_IN   PDI_F1_EP0_TX
+  #define PDI_F1_EP1_OUT  PDI_F1_EP1_RX
+  #define PDI_F1_EP1_IN   PDI_F1_EP1_TX
+  #define PDI_F6_EP0_OUT  PDI_F6_EP0_RX
+  #define PDI_F6_EP0_IN   PDI_F6_EP0_TX
+  #define PDI_F6_EP1_OUT  PDI_F6_EP1_RX
+  #define PDI_F6_EP1_IN   PDI_F6_EP1_TX
+  #define PDI_F7_EP0_OUT  PDI_F7_EP0_RX
+  #define PDI_F7_EP0_IN   PDI_F7_EP0_TX
+  #define PDI_F7_EP1_OUT  PDI_F7_EP1_RX
+  #define PDI_F7_EP1_IN   PDI_F7_EP1_TX
+#elif defined(PDIUSBD12)                                     // D12
+  #define PDI_EP0_RX  0
+  #define PDI_EP0_TX  1
+  #define PDI_EP1_RX  2
+  #define PDI_EP1_TX  3
+  #define PDI_EP2_RX  4
+  #define PDI_EP2_TX  5
+  // another index names
+  #define PDI_EP0_OUT  PDI_EP0_RX
+  #define PDI_EP0_IN   PDI_EP0_TX
+  #define PDI_EP1_OUT  PDI_EP1_RX
+  #define PDI_EP1_IN   PDI_EP1_TX
+  #define PDI_EP2_OUT  PDI_EP2_RX
+  #define PDI_EP2_IN   PDI_EP2_TX
+#endif
+
+/*********************************************************/
+//  Commands - index and bits, description
+
+  // Set Address/Enable
+#if defined(PDIUSBH11) || defined(PDIUSBH11A) || defined(PDIUSBD11)         // only H11 or H11A
+  #define PDI_CMD_HUB_ENB_ADDR  0x00D0
+ #if defined(PDIUSBH11) || defined(PDIUSBH11A_SINGLE)  // for H11 and H11A_SINGLE
+  #define PDI_CMD_FNC_ENB_ADDR  0x00D1
+ #else                                                 // for H11A_MULTIPLE
+  #define PDI_CMD_FNC1_ENB_ADDR 0x00D1
+  #define PDI_CMD_FNC6_ENB_ADDR 0x00D2
+  #define PDI_CMD_FNC7_ENB_ADDR 0x00D3
+// for compatible with H11A_SINGLE and other
+  #define PDI_CMD_FNC_ENB_ADDR  PDI_CMD_FNC1_ENB_ADDR
+ #endif
+#elif defined(PDIUSBD11)             // for D11
+  #define PDI_CMD_FNC_ENB_ADDR  0x00D1
+#elif defined(PDIUSBD12)             // for D12
+  #define PDI_CMD_FNC_ENB_ADDR  0x00D0
+#endif
+    // set address/enable bits - for all
+    #define PDI_ENAD_ENABLE   0x0080
+    #define PDI_ENAD_ADDRMASK 0x007F
+
+  // Set Endpoint enable
+  #define PDI_CMD_EPEN          0x00D8
+    // set endpoint enable bits
+   #if defined(PDIUSBD12)             // D12 - generic ep
+    #define PDI_EPEN_ENABLE       0x0001
+   #elif defined(PDIUSBD11)           // D11 - generic ep
+    #define PDI_EPEN_ENABLE       0x0002
+   #elif defined(PDIUSBH11A) || defined(PDIUSBH11)   // H11,H11A
+    #define PDI_EPEN_HUB_ENB      0x0001
+     #if defined(PDIUSBH11A_MULTIPLE)  // H11A_M
+    #define PDI_EPEN_FNC1_ENB       0x0002     
+    #define PDI_EPEN_FNC6_ENB       0x0004
+    #define PDI_EPEN_FNC7_ENB       0x0008
+     #else                            // H11,H11A_S
+    #define PDI_EPEN_FNC_ENB      0x0002
+     #endif 
+   #endif
+
+ #if !defined(PDIUSBH11)
+  // Set Mode
+  #define PDI_CMD_SET_MODE      0x00F3
+    // set mode bits - configuration
+   #if !defined(PDIUSBD12)
+    #define PDI_MODE_REMOTE_WAKEUP   0x0001  // D11,H11A
+   #endif
+    #define PDI_MODE_NO_LAZY_CLOCK   0x0002  // all
+    #define PDI_MODE_CLOCK_RUNNING   0x0004  // all
+   #if defined(PDIUSBD12)
+    #define PDI_MODE_INTERRUPT_MODE  0x0008  // D12
+   #else
+    #define PDI_MODE_DEBUG_MODE      0x0008  // D11,H11A
+   #endif
+    #define PDI_MODE_SOFT_CONNECT    0x0010  // all
+   #if defined(PDIUSBH11A)
+    #define PDI_MODE_DWN_RESISTORS   0x0020  // H11A
+    #define PDI_MODE_NONBLINK_LED    0x0040  // H11A
+    #define PDI_MODE_SINGLE_FNC      0x0080  // H11A
+   #elif defined(PDIUSBD11)
+    #define PDI_MODE_MUSTBEONE       0x0080  // D11
+   #else
+    #define PDI_MODE_EP_NONISO       0x0000  // D12
+    #define PDI_MODE_EP_ISOOUT       0x0040
+    #define PDI_MODE_EP_ISOIN        0x0080
+    #define PDI_MODE_EP_ISOIO        0x00C0
+
+   #endif
+   // set mode bits - clock div factor  [48Mhz/(N+1)]
+   #if defined(PDIUSBH11A)
+    #define PDI_CLOCK_CRYSTAL_12M    0x3000  // for 12Mhz crystal
+    #define PDI_CLOCK_CRYSTAL_48M    0x0000  // for 48Mhz crystal
+   #endif
+   #if defined(PDIUSBD12)                  // D12
+    #define PDI_CLOCK_48M            0x0000    // 48 Mhz
+   #endif                                  // all
+    #define PDI_CLOCK_24M            0x0100    // 24 Mhz
+    #define PDI_CLOCK_16M            0x0200    // 16 Mhz
+    #define PDI_CLOCK_12M            0x0300    // 12 Mhz    
+    #define PDI_CLOCK_9M6            0x0400    //  9.6 Mhz
+    #define PDI_CLOCK_8M             0x0500    //  8 Mhz
+    #define PDI_CLOCK_6M8            0x0600    //  6.857142857 Mhz
+    #define PDI_CLOCK_6M             0x0700    //  6 Mhz
+    #define PDI_CLOCK_5M3            0x0800    //  5.333333333 Mhz
+    #define PDI_CLOCK_4M8            0x0900    //  4.8 Mhz
+    #define PDI_CLOCK_4M3            0x0A00    //  4.363636364 Mhz
+    #define PDI_CLOCK_4M             0x0B00    //  4 Mhz
+   #if defined(PDIUSBD12)                  // D12
+    #define PDI_CLOCK_SET_TO_ONE     0x4000
+    #define PDI_CLOCK_SOF_ONLY       0x8000
+   #endif
+ #endif
+   
+  // Set DMA
+ #if defined(PDIUSBD12)
+  #define PDI_CMD_SET_DMA       0x00FB
+  #define PDI_CMD_GET_DMA       0x00FB
+    // set dma bits
+    #define PDI_DMA_SINGLE_DMA    0x0000
+    #define PDI_DMA_BURST_4       0x0001
+    #define PDI_DMA_BURST_8       0x0002
+    #define PDI_DMA_BURST_16      0x0003
+    #define PDI_DMA_ENABLE        0x0004
+    #define PDI_DMA_DIRECTION     0x0008
+    #define PDI_DMA_AUTOLOAD      0x0010
+    #define PDI_DMA_INT_SOF       0x0020
+    #define PDI_DMA_EP4_INT       0x0040
+    #define PDI_DMA_EP5_INT       0x0080
+ #endif
+
+  // Read Interrupt Register
+  // be careful with PDIUSBH11 - you must read only 1 byte
+  #define PDI_CMD_GET_INT_REG   0x00F4
+    // read interrupt register bits
+   #if defined(PDIUSBD11) || defined(PDIUSBH11) || defined(PDIUSBH11A) // D11,H11,H11A
+     #if defined(PDIUSBH11) || defined(PDIUSBH11A)
+    #define PDI_INT_HUB_OUT       0x0001
+    #define PDI_INT_HUB_IN        0x0002
+     #endif
+     #if defined(PDIUSBH11)
+    #define PDI_INT_EP0_OUT       0x0004
+    #define PDI_INT_EP0_IN        0x0008
+    #define PDI_INT_EP1_IN        0x0010
+     #elif defined(PDIUSBD11) || defined(PDIUSBH11A_SINGLE)  // D11,H11_S
+    #define PDI_INT_EP0_OUT       0x0004
+    #define PDI_INT_EP0_IN        0x0008
+    #define PDI_INT_EP1_OUT       0x0020
+    #define PDI_INT_EP1_IN        0x0010
+    #define PDI_INT_EP2_OUT       0x0040
+    #define PDI_INT_EP2_IN        0x0080
+    #define PDI_INT_EP3_OUT       0x0100
+    #define PDI_INT_EP3_IN        0x0200
+     #else                                                // H11_M
+    #define PDI_INT_F1_EP0_OUT    0x0004
+    #define PDI_INT_F1_EP0_IN     0x0008
+    #define PDI_INT_F1_EP1_OUT    0x0020
+    #define PDI_INT_F1_EP1_IN     0x0010
+    #define PDI_INT_F6_EP0_OUT    0x0400
+    #define PDI_INT_F6_EP0_IN     0x0800
+
+    #define PDI_INT_F6_EP1_OUT    0x0040
+    #define PDI_INT_F6_EP1_IN     0x0080
+    #define PDI_INT_F7_EP0_OUT    0x1000
+    #define PDI_INT_F7_EP0_IN     0x2000
+    #define PDI_INT_F7_EP1_OUT    0x0100
+    #define PDI_INT_F7_EP1_IN     0x0200
+     #endif
+    #define PDI_INT_BUSRESET      0x4000
+   #elif defined(PDIUSBD12)
+    #define PDI_INT_EP0_OUT       0x0001
+    #define PDI_INT_EP0_IN        0x0002
+    #define PDI_INT_EP1_OUT       0x0004
+    #define PDI_INT_EP1_IN        0x0008
+    #define PDI_INT_EP2_OUT       0x0010
+    #define PDI_INT_EP2_IN        0x0020
+    #define PDI_INT_BUSRESET      0x0040
+    #define PDI_INT_SUSPEND       0x0080
+    #define PDI_INT_DMA_EOT       0x0100
+   #endif
+
+  // Select Endpoint
+  #define PDI_CMD_SELECT_EP     0x0000  // base index for select endpoint
+    // select endpoint bits
+    #define PDI_SELEP_FULL        0x0001
+   #if defined(PDIUSBD12)
+    #define PDI_SELEP_STALL       0x0002
+   #endif
+
+  // Read Last Transaction Status Register
+  #define PDI_CMD_GET_LAST_STAT 0x0040  // base index for read last transaction
+    // read last transaction bits and errors
+    #define PDI_LTSTAT_RXTX_OK    0x0001
+    #define PDI_LTSTAT_ERR_MASK   0x001E
+    #define PDI_LTSTAT_SETUP      0x0020
+    #define PDI_LTSTAT_DATA1      0x0040
+    #define PDI_LTSTAT_PREV_NRD   0x0080
+      // error codes
+      #define PDI_ERR_NO_ERROR      0x0000
+      #define PDI_ERR_PID_ENCODING  0x0001
+      #define PDI_ERR_PID_UNKNOWN   0x0002
+      #define PDI_ERR_UNEXPECT_PKT  0x0003
+
+      #define PDI_ERR_TOKEN_CRC     0x0004
+      #define PDI_ERR_DATA_CRC      0x0005
+      #define PDI_ERR_TIME_OUT      0x0006
+      #define PDI_ERR_NEVER_HAPPENS 0x0007
+      #define PDI_ERR_UNEXPECT_EOP  0x0008
+      #define PDI_ERR_NAK           0x0009
+      #define PDI_ERR_STALL         0x000A
+      #define PDI_ERR_OVERFLOW      0x000B
+      #define PDI_ERR_BITSTUFF      0x000D
+      #define PDI_ERR_DATA_PID      0x000F
+
+  // Read Endpoint Status
+ #if defined(PDIUSBD11) || defined(PDIUSBH11) || defined(PDIUSBH11A)
+   #define PDI_CMD_GET_EP_STAT   0x0080  // base index for read ep status
+    // read ep status bits
+     #define PDI_EPSTAT_SETUP      0x0004
+     #define PDI_EPSTAT_STALL      0x0008
+     #define PDI_EPSTAT_DATA1      0x0010
+     #define PDI_EPSTAT_FULL       0x0020
+ #endif
+
+  // Read Buffer
+  #define PDI_CMD_READ_BUFFER   0x00F0
+  
+  // Write Buffer
+  #define PDI_CMD_WRITE_BUFFER  0x00F0
+
+  // Clear Buffer
+  #define PDI_CMD_CLEAR_BUFFER  0x00F2
+
+  // Validate Buffer
+  #define PDI_CMD_VALID_BUFFER  0x00FA
+
+
+  // Set Endpoint Status
+  #define PDI_CMD_SET_EP_STAT   0x0040  // base index for endpoint status
+    // set endpoint status bits
+    #define PDI_SET_EP_STALLED    0x0001
+
+  // Acknowledge Setup
+  #define PDI_CMD_ACK_SETUP     0x00F1
+
+  // Send Resume
+  #define PDI_CMD_SEND_RESUME   0x00F6
+
+  // Read Current Frame Number
+  #define PDI_CMD_GET_FRAME     0x00F5
+
+  // Get Chip ID
+  #define PDI_CMD_GET_CHIP_ID   0x00FD
+
+// HUB commands
+#if defined(PDIUSBH11) || defined(PDIUSBH11A)
+  // Clear Port Feature
+  #define PDI_CMD_P2_CLR_FEATURE 0x00E0
+  #define PDI_CMD_P3_CLR_FEATURE 0x00E1
+  #define PDI_CMD_P4_CLR_FEATURE 0x00E2
+  #define PDI_CMD_P5_CLR_FEATURE 0x00E3
+  // Set Port Feature
+  #define PDI_CMD_P2_SET_FEATURE 0x00E8
+  #define PDI_CMD_P3_SET_FEATURE 0x00E9
+  #define PDI_CMD_P4_SET_FEATURE 0x00EA
+  #define PDI_CMD_P5_SET_FEATURE 0x00EB
+    // Feature code
+    #define PDI_F_PORT_ENABLE       0
+    #define PDI_F_PORT_SUSPEND      1
+    #define PDI_FC_PORT_RESET       2
+    #define PDI_F_PORT_POWER        3
+    #define PDI_C_PORT_CONNECTION   4
+    #define PDI_C_PORT_ENABLE       5
+    #define PDI_C_PORT_SUSPEND      6
+    #define PDI_C_PORT_OVERCURRENT  7
+   
+  // Get Port Status
+  #define PDI_CMD_P2_GET_STATUS  0x00E0
+  #define PDI_CMD_P3_GET_STATUS  0x00E1
+  #define PDI_CMD_P4_GET_STATUS  0x00E2
+  #define PDI_CMD_P5_GET_STATUS  0x00E3
+    // get port status bits - port status byte
+    #define PDI_PSTAT_CONNECT        0x0001
+    #define PDI_PSTAT_ENABLED        0x0002
+    #define PDI_PSTAT_SUSPEND        0x0004
+    #define PDI_PSTAT_OVERCUR        0x0008
+    #define PDI_PSTAT_RESET          0x0010
+    #define PDI_PSTAT_POWER          0x0020
+    #define PDI_PSTAT_LOWSPEED       0x0040
+    // get port status bits - port status change byte
+    #define PDI_PSTAT_CHANGE_CONNECT 0x0100
+    #define PDI_PSTAT_CHANGE_ENABLED 0x0200
+    #define PDI_PSTAT_CHANGE_SUSPEND 0x0400
+    #define PDI_PSTAT_CHANGE_OVERCUR 0x0800
+    #define PDI_PSTAT_CHANGE_RESET   0x1000
+  // Set Status Change Bits
+  #define PDI_CMD_SET_CHNG_BITS  0x00F7
+    // set status change bits - bits
+    #define PDI_SCHB_LOCAL_POWER    0x0001
+    #define PDI_SCHB_FNC1           0x0002
+   #if !defined(PDIUSBH11) && !defined(PDIUSBH11A_SINGLE)
+    #define PDI_SCHB_FNC6           0x0004
+    #define PDI_SCHB_FNC7           0x0008
+   #endif
+#endif
+
+
+/*********************************************************/
+//  Function prototypes
+//
+// PDIUSB common commands
+ #if defined(PDIUSBH11) || defined(PDIUSBH11A) || defined(PDIUSBD11)
+  void pdiSetHUBAddressEnable( unsigned char byAddress, unsigned char byEnable);
+ #endif
+ #if !defined(PDIUSBH11A_MULTIPLE) // D11,D12,H11,H11A_S(emb.fnc)
+  void pdiSetAddressEnable( unsigned char byAddr_Enb);
+//  void pdiSetAddressEnable( unsigned char byAddress, unsigned char byEnable);
+ #else
+  void pdiSetEmbFncAddressEnable( unsigned char byFnc, unsigned char byAddress, unsigned char byEnable);
+ #endif
+
+  void pdiSetEndpointEnable( unsigned char byEnable);
+  
+ #if !defined(PDIUSBH11)  // H11 has not it ( !!! is great - try give single quote mark into comments ;-)
+  void pdiSetMode( unsigned short wMode_Clock);
+ #endif
+ #if defined(PDIUSBD12)
+  void pdiSetDMA( unsigned char byDma);
+  unsigned char pdiGetDMA( void);
+ #endif
+
+ #if defined(PDIUSBH11)
+  unsigned char pdiGetInterrupt( void) _PDI_USING;
+ #else
+  unsigned short pdiGetInterrupt( void) _PDI_USING;
+ #endif
+  
+  unsigned char pdiSelectEp( unsigned char byEpIdx);
+  unsigned char pdiGetLastTransStatus( unsigned char byEpIdx) _PDI_USING;
+
+ #if defined(PDIUSBD11) || defined(PDIUSBH11) || defined(PDIUSBH11A)
+  unsigned char pdiGetEpStatus( unsigned char byEpIdx);
+ #endif
+
+  unsigned char pdiReadFromEpBuffer( unsigned char byLength, unsigned char *pToBuff);
+  void pdiWriteToEpBuffer( unsigned char byLength, const unsigned char *pFromBuff);
+  void pdiSetEpStatus( unsigned char byEpIdx, unsigned char byStatus);
+  void pdiAcknowledgeSetup( void);
+  void pdiClearBuffer( void);
+  void pdiValidateBuffer( void);
+
+  void pdiSendResume( void);
+  unsigned short pdiGetFrameNumber( void);
+  unsigned short pdiGetChipID( void); // this function is undocumented
+  
+ // HUB command
+ #if defined(PDIUSBH11) || defined(PDIUSBH11A)
+  void pdiClearPortFeature( unsigned char byEpIdx, unsigned char byFeature);
+  void pdiSetPortFeature( unsigned char byEpIdx, unsigned char byFeature);
+  unsigned short pdiGetPortFeature( unsigned char byEpIdx);
+  void pdiSetStatusChangeBits( unsigned char byBits);
+ #endif
+
+// PDIUSB other commands
+ void pdiWriteEndpoint( unsigned char byEpIdx, unsigned char byLength, const unsigned char *pbyData);
+ unsigned char pdiReadEndpoint( unsigned char byEpIdx, unsigned char byMaxLength, unsigned char *pbyData);
+ unsigned char pdiCmdData( unsigned char byCmd, unsigned char *pbyData,
+                           unsigned char byCount, unsigned char byRead);
+ void pdiInit( void);
+#if !defined(PDIUSBH11A_MULTIPLE)
+ void pdiAckSetupControl( void);
+#else
+ void pdiAckSetupFncControl( unsigned char Fnc);
+#endif
+
+unsigned char pdiEp2Idx(unsigned char ep);
+
+/*********************************************************/
+#endif // from _PDI_ERROR_NO_CONTINUE
+/*********************************************************/
+#endif // from _PDI_BASE_MODULE
diff --git a/common/linkarch b/common/linkarch
new file mode 100755 (executable)
index 0000000..4a4c038
--- /dev/null
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+# This script recursively creates links to files from common directory
+# in the current tree.
+
+function make_links
+{
+    SRC_DIR=$1
+    if [ ! -d $SRC_DIR ]; then
+        echo "Error: Can't find $SRC_DIR in current directory";
+        exit 1;
+    fi
+    for f in $SRC_DIR/*; do
+       bf=`basename $f`
+        if [ ! -e $bf ]; then
+           ln -sf $f $bf
+       else
+           if [ -d $bf -a ! -L $bf ]; then
+               (cd $bf; make_links ../$f)
+           fi
+       fi
+    done
+
+}
+
+# Maybe we should delete existing links
+#find -lname '*common/*'
+
+make_links common