unix.h

Go to the documentation of this file.
00001 #ifndef _ARCH_UNIX_H_
00002 #define _ARCH_UNIX_H_
00003 
00004 /*
00005  * Copyright (C) 2000-2004 by ETH Zurich
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions
00009  * are met:
00010  *
00011  * 1. Redistributions of source code must retain the above copyright
00012  *    notice, this list of conditions and the following disclaimer.
00013  * 2. Redistributions in binary form must reproduce the above copyright
00014  *    notice, this list of conditions and the following disclaimer in the
00015  *    documentation and/or other materials provided with the distribution.
00016  * 3. Neither the name of the copyright holders nor the names of
00017  *    contributors may be used to endorse or promote products derived
00018  *    from this software without specific prior written permission.
00019  *
00020  * THIS SOFTWARE IS PROVIDED BY ETH ZURICH AND CONTRIBUTORS
00021  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00022  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00023  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ETH ZURICH
00024  *  OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00025  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00026  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00027  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00028  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00029  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00030  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00031  * SUCH DAMAGE.
00032  *
00033  * For additional information see http://www.ethernut.de/
00034  *
00035  */
00036 
00037 /*
00038  * unix.h.c - types and defines for unix emulation
00039  *
00040  * 2004.04.01 Matthias Ringwald <matthias.ringwald@inf.ethz.ch>
00041  *
00042  */
00043 
00044 
00045 #if !defined(__linux__) && !defined(__APPLE__) && !defined(__CYGWIN__)
00046 #error "Nut/OS emulation currently runs only on Linux and MAC OS X systems."
00047 #endif
00048 
00049 /* -------------------------------------------------------------------------
00050  * map some AVR types/defines to something else
00051  * ------------------------------------------------------------------------- */
00052 
00053 #define CONST      const
00054 #define INLINE     inline
00055 
00056 #define PSTR(p)    (p)
00057 #define PRG_RDB(p) (*((const char *)(p)))
00058 
00059 #define prog_char  const char
00060 #define PGM_P      prog_char *
00061 
00062 /* -------------------------------------------------------------------------
00063  * now we can include types (and time.h)
00064  * ------------------------------------------------------------------------- */
00065 
00066 #include <sys/types.h>
00067 #include <dev/mweeprom.h>
00068 #include <termios.h>
00069 #include <unistd_orig.h>
00070 
00071 
00072 /* -------------------------------------------------------------------------
00073  * redefine main
00074  * ------------------------------------------------------------------------- */
00075 
00076 #define main(...)       NutAppMain(__VA_ARGS__)
00077 
00078 /* -------------------------------------------------------------------------
00079  * map harvard specific calls to normal ones
00080  * ------------------------------------------------------------------------- */
00081 
00082 
00083 #define strlen_P(x)             strlen(x)
00084 #define strcpy_P(x,y)           strcpy(x,y)
00085 #define strcmp_P(x, y)          strcmp(x, y)
00086 #define memcpy_P(x, y, z)       memcpy(x, y, z)
00087 
00088 /* -------------------------------------------------------------------------
00089  * emulated IRQs
00090  * ------------------------------------------------------------------------- */
00091 enum {
00092     IRQ_TIMER0,
00093     IRQ_UART0_RX,
00094     IRQ_UART1_RX,
00095     IRQ_UART2_RX,
00096     IRQ_MAX
00097 };
00098 
00099 /* -------------------------------------------------------------------------
00100  * emulated heap
00101  * ------------------------------------------------------------------------- */
00102 
00103 /* RAMSTART could be zero, but RAMSTART < 3 leads to a crash in freopen (stdout) */
00104 #define RAMSTART    ((void *)0x00100)
00105 
00106 /* on linux our malloc function makes the init section crash, so we better rename it */
00107 #define malloc(...)     NUT_malloc(__VA_ARGS__)
00108 #define realloc(...)    NUT_realloc(__VA_ARGS__)
00109 #define free(...)       NUT_free(__VA_ARGS__)
00110 
00111 /* -------------------------------------------------------------------------
00112  * parsing of command line options
00113  * ------------------------------------------------------------------------- */
00114 
00115 /*
00116  * options of one uart 
00117  * usbnum: a negative usbnum is used to indicate that device name is used
00118  */
00119 
00120 typedef struct {
00121 
00122     char *device;
00123     u_long bautrate;
00124     u_char flowcontrol;
00125     signed char usbnum;
00126 } uart_options_t;
00127 
00128 /* 
00129  * all command line options
00130  */
00131 typedef struct {
00132 
00133     // debug output
00134     int verbose;
00135 
00136     uart_options_t uart_options[3];
00137     struct termios saved_termios;
00138 } emulation_options_t;
00139 
00140 /* the command line options are stored here */
00141 extern emulation_options_t emulation_options;
00142 
00143 /* -------------------------------------------------------------------------
00144  * function declarations
00145  * ------------------------------------------------------------------------- */
00146 void emulation_options_parse(int argc, char *argv[]);
00147 
00149 #define eeprom_rb(addr) eeprom_read_byte       ((u_char  *)(u_long) (addr))
00150 #define eeprom_rw(addr) eeprom_read_word       ((u_short *)(u_long) (addr))
00151 #define eeprom_wb(addr, val) eeprom_write_byte ((u_char  *)(u_long) (addr), (val))
00152 // fake ATmega128 has 0xfff eeprom
00153 #define    E2END    0x0FFF
00154 
00158 #define eeprom_is_ready() TRUE
00159 
00160 #endif                          /* #ifndef _CPU_UNIX_H_ */

© 2000-2007 by egnite Software GmbH - visit http://www.ethernut.de/