summaryrefslogtreecommitdiffstats
path: root/c/src/exec
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>1998-07-17 15:17:29 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>1998-07-17 15:17:29 +0000
commitfa21a8439f23b608448f1ce5f1f01c51a63ed258 (patch)
tree28962a606999f09246988d4a8cbcc2cfa4410789 /c/src/exec
parentPatch from Dario Alcocer <alcocer@connectnet.com>. His comments: (diff)
downloadrtems-fa21a8439f23b608448f1ce5f1f01c51a63ed258.tar.bz2
New files from Ralf Corsepius <corsepiu@faw.uni-ulm.de>. His comments:
* c/src/exec/score/tools/sh - NEW DIRECTORY - contains shgen Most of it should be self-explanatory. I am a little bit concerned about host-dependent features (getopt, floating point libraries). This shouldn't disturb much now, as this tool should be compileable on all gnu-based hosts and is only applicable for the sh. But in case somebody complains, we may need to add autoconf checks or even restructurize parts of rtems (IMO, rtems needs to be restructurized - remember the "turning rtems upside down" issue).
Diffstat (limited to 'c/src/exec')
-rw-r--r--c/src/exec/score/tools/sh/AUTHORS3
-rw-r--r--c/src/exec/score/tools/sh/COPYING19
-rw-r--r--c/src/exec/score/tools/sh/Makefile.in62
-rw-r--r--c/src/exec/score/tools/sh/TODO13
-rw-r--r--c/src/exec/score/tools/sh/sci.c157
-rw-r--r--c/src/exec/score/tools/sh/sci.h11
-rw-r--r--c/src/exec/score/tools/sh/shgen.c65
7 files changed, 330 insertions, 0 deletions
diff --git a/c/src/exec/score/tools/sh/AUTHORS b/c/src/exec/score/tools/sh/AUTHORS
new file mode 100644
index 0000000000..225c2fa974
--- /dev/null
+++ b/c/src/exec/score/tools/sh/AUTHORS
@@ -0,0 +1,3 @@
+Ralf Corsepius (corsepiu@faw.uni-ulm.de)
+ * Initial implementation
+ * generator for sci bitrate table
diff --git a/c/src/exec/score/tools/sh/COPYING b/c/src/exec/score/tools/sh/COPYING
new file mode 100644
index 0000000000..805cdd8ffc
--- /dev/null
+++ b/c/src/exec/score/tools/sh/COPYING
@@ -0,0 +1,19 @@
+
+ shgen - code generator for the Hitachi SH microcontroller family
+
+ Copyright (C) 1998 Ralf Corsepius (corsepiu@faw.uni-ulm.de)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
diff --git a/c/src/exec/score/tools/sh/Makefile.in b/c/src/exec/score/tools/sh/Makefile.in
new file mode 100644
index 0000000000..c35743adea
--- /dev/null
+++ b/c/src/exec/score/tools/sh/Makefile.in
@@ -0,0 +1,62 @@
+#
+# $Id$
+#
+# FIXME: $ARCH shouldn't be used inside of host-tools.
+#
+
+@SET_MAKE@
+srcdir = @srcdir@
+VPATH = @srcdir@
+RTEMS_ROOT = @top_srcdir@
+PROJECT_ROOT = @PROJECT_ROOT@
+
+# we use the host compiler here
+USE_HOST_COMPILER=yes
+
+# C source names, if any, go here -- minus the .c
+C_PIECES=shgen sci
+C_FILES=$(C_PIECES:%=%.c)
+C_O_FILES=$(C_PIECES:%=${ARCH}/%.o)
+
+H_FILES=sci.h
+
+SRCS=$(C_FILES) $(H_FILES)
+OBJS=$(C_O_FILES)
+
+PGMS=${ARCH}/shgen@EXEEXT@
+
+include $(RTEMS_ROOT)/make/custom/$(RTEMS_BSP).cfg
+include $(RTEMS_ROOT)/make/leaf.cfg
+
+#
+# Add local stuff here using +=
+#
+
+DEFINES += -Wall
+CPPFLAGS += -I.
+CFLAGS +=
+
+LD_PATHS +=
+LD_LIBS += -lm
+LDFLAGS +=
+
+#
+# Add your list of files to delete here.
+#
+
+CLEAN_ADDITIONS +=
+CLOBBER_ADDITIONS +=
+
+DESTDIR=${PROJECT_RELEASE}/bin
+
+all: $(ARCH) $(PGMS)
+
+${PGMS}: $(OBJS) $(LINK_FILES)
+ $(make-exe)
+
+$(DESTDIR):
+ $(BSDINSTALL) $(INSTDIRFLAGS) $@
+
+# Install the program
+install: $(DESTDIR) $(PGMS)
+ $(BSDINSTALL) $(INSTBINFLAGS) ${PGMS} $(DESTDIR)
diff --git a/c/src/exec/score/tools/sh/TODO b/c/src/exec/score/tools/sh/TODO
new file mode 100644
index 0000000000..bcdd1bf6df
--- /dev/null
+++ b/c/src/exec/score/tools/sh/TODO
@@ -0,0 +1,13 @@
+* Add support for more drivers to shgen !!!!
+
+* shgen relies on having a gnu-compatible getopt, which should be
+ available on all hosts using gcc/egcs/binutils.
+ Using other getopt-variants may produce faulty results or shgen may also
+ refuse to compile. Probably the easiest solution to this problem would be
+ to integrate libiberty into rtems.
+
+* shgen uses floating point mathematics. Therefore Makefile.in contains a
+ reference to libm. In case the host doesn't have its floating point
+ support in libm, shgen will fail to compile. If we should ever meet such
+ a host, checks for floating point libraries have to be added to rtems'
+ autoconf support.
diff --git a/c/src/exec/score/tools/sh/sci.c b/c/src/exec/score/tools/sh/sci.c
new file mode 100644
index 0000000000..58be0e68bf
--- /dev/null
+++ b/c/src/exec/score/tools/sh/sci.c
@@ -0,0 +1,157 @@
+/*
+ * Copyright (c) 1998 Ralf Corsepius (corsepiu@faw.uni-ulm.de)
+ *
+ * See the file COPYING for copyright notice.
+ */
+
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "sci.h"
+
+/*
+ n .. baudrate generator source 0,1,2,3
+
+ N .. BRR setting (0..255)
+
+ Phi .. processor baud rate
+
+ B .. bitrate
+ */
+
+typedef struct sci_tab {
+ unsigned int B ;
+ unsigned int n ;
+ int N ;
+ double err ;
+ } sci_tab_t ;
+
+static unsigned int bitrate [] = {
+ 50,
+ 75,
+ 110,
+ 134,
+ 150,
+ 200,
+ 300,
+ 600,
+ 1200,
+ 1800,
+ 2400,
+ 4800,
+ 9600,
+ 19200,
+ 38400,
+ 57600,
+ 115200,
+ 230400,
+ 460800
+};
+
+static sci_tab_t test_array[4] ;
+
+static void Compute(
+ unsigned int n,
+ unsigned int B,
+ unsigned int Phi,
+ struct sci_tab *entry )
+{
+ int a = ( 32 << ( 2 * n ) ) * B ;
+
+ entry->n = n ;
+ entry->B = B ;
+ entry->N = rint( ( Phi / a ) - 1.0 ) ;
+
+ if ( ( entry->N > 0 ) && ( entry->N < 256 ) )
+ entry->err =
+ ( ( Phi / ( (entry->N + 1) * a ) - 1.0 ) * 100.0 );
+ else
+ entry->err = 100.0 ;
+}
+
+static sci_tab_t *SelectN(
+ unsigned int B,
+ double Phi )
+{
+ unsigned int i ;
+ struct sci_tab* best = NULL ;
+
+ for ( i = 0 ; i < 4 ; i++ )
+ {
+ double err ;
+
+ Compute( i, B, Phi, &test_array[i] );
+ err = fabs( test_array[i].err );
+
+ if ( best )
+ {
+ if ( err < fabs( best->err ) )
+ best = &test_array[i] ;
+ }
+ else
+ best = &test_array[i] ;
+ }
+
+ return best ;
+}
+
+int shgen_gensci(
+ FILE *file,
+ double Phi ) /* Processor frequency [Hz] */
+{
+ unsigned int i ;
+
+ fprintf( file,
+ "/*\n * Bitrate table for the serial devices (sci) of the SH at %.3f MHz\n"
+ " */\n\n", Phi / 1000000.0 );
+ fprintf( file,
+ "/*\n"
+ " * n .. SMR bits 0,1 : baud rate generator clock source\n"
+ " * N .. BRR bits 0..7: setting for baud rate generator\n"
+ " * error .. percentual error to nominal bitrate\n"
+ " * Hitachi's HW manual recommends bitrates with an error less than 1%%\n"
+ " * We experienced values less than 2%% to be stable\n"
+ " */\n\n" );
+ fprintf( file, "#include <termios.h>\n\n" );
+ fprintf( file,
+ "static struct sci_bitrate_t {\n"
+ " unsigned char n ;\n"
+ " unsigned char N ;\n"
+ "} _sci_bitrates[] = {\n"
+ "/* n N error */\n" );
+
+ for ( i = 0 ; i < sizeof(bitrate)/sizeof(int) ; i++ )
+ {
+ struct sci_tab* best = SelectN( bitrate[i], Phi );
+
+ if ( i > 0 )
+ fprintf( file, ",\n" );
+ fprintf( file, " { %1d, %3d } /* %+7.2f%% ; B%d */",
+ best->n,
+ best->N,
+ best->err,
+ best->B );
+ }
+
+ fprintf( file, "\n};\n\n" );
+
+ fprintf( file,
+ "int _sci_get_brparms( \n"
+ " tcflag_t cflag,\n"
+ " unsigned char *smr,\n"
+ " unsigned char *brr )\n"
+ "{\n"
+ " unsigned int offset ;\n\n"
+ " offset = ( cflag & ( CBAUD & ~CBAUDEX ) )\n"
+ " + ( ( cflag & CBAUDEX ) ? B38400 : 0 );\n"
+ " if ( offset == 0 ) return -1 ;\n"
+ " offset-- ;\n\n"
+ " *smr &= ~0x03;\n"
+ " *smr |= _sci_bitrates[offset].n;\n"
+ " *brr = _sci_bitrates[offset].N;\n\n"
+ " return 0;\n"
+ "}\n" );
+
+ return 0 ;
+}
diff --git a/c/src/exec/score/tools/sh/sci.h b/c/src/exec/score/tools/sh/sci.h
new file mode 100644
index 0000000000..b55bbfb670
--- /dev/null
+++ b/c/src/exec/score/tools/sh/sci.h
@@ -0,0 +1,11 @@
+#ifndef _shgen_sci_h
+#define _shgen_sci_h
+
+#include <stdio.h>
+
+extern int shgen_gensci(
+ FILE *file,
+ double Phi /* Processor frequency [Hz] */
+ );
+
+#endif
diff --git a/c/src/exec/score/tools/sh/shgen.c b/c/src/exec/score/tools/sh/shgen.c
new file mode 100644
index 0000000000..3fa6ae9b75
--- /dev/null
+++ b/c/src/exec/score/tools/sh/shgen.c
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 1998 Ralf Corsepius (corsepiu@faw.uni-ulm.de)
+ *
+ * See the file COPYING for copyright notice.
+ */
+
+#include <stdio.h>
+#include <string.h> /* strcmp, strerror */
+#include <errno.h>
+#include <getopt.h>
+
+#include "sci.h"
+
+static void usage( char *prog )
+{
+ fprintf( stderr, "usage: %s [options] driver\n", prog );
+ fprintf( stderr, "options:\n" );
+ fprintf( stderr, "\t-M Phi .. processor frequency [MHz] default: 20\n" );
+ fprintf( stderr, "driver:\n" );
+ fprintf( stderr, "\tsci .. bitrate table for sci\n" );
+ exit ( 1 );
+}
+
+static void shgen_header( FILE *file )
+{
+ fprintf( file,
+ "/*\n * DO NOT EDIT - this file is automatically generated by shgen\n" );
+ fprintf( file,
+ " * Copyright (c) 1998, Ralf Corsepius (corsepiu@faw.uni-ulm.de)\n */\n" );
+ fprintf( file,
+ "\n/* This file is not copyrighted */\n\n" );
+}
+
+int main( int argc, char *argv[] )
+{
+ double Phi = 20.0 ;
+
+ while ( ( optopt = getopt( argc, argv, "M:" ) ) > 0 )
+ {
+ switch ( optopt )
+ {
+ case 'M' :
+ sscanf( optarg, "%lf", &Phi );
+ Phi = Phi * 1000000.0;
+ break ;
+ default :
+ usage( argv[0] );
+ break ;
+ }
+ }
+
+ if ( argc - optind != 1 )
+ usage( argv[0] );
+
+ shgen_header( stdout );
+
+ if ( strcmp( argv[optind], "sci" ) == 0 )
+ {
+ shgen_gensci( stdout, Phi );
+ }
+ else
+ usage( argv[0] );
+
+ return 0 ;
+}