Nut/OS  4.10.3
API Reference
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 #ifndef __NUT_EMULATION__
00046 #error "Nut/OS emulation only runs 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 <stdint.h>
00068 #include <dev/mweeprom.h>
00069 #include <termios.h>
00070 #include <unistd_orig.h>
00071 
00072 
00073 /* -------------------------------------------------------------------------
00074  * redefine main
00075  * ------------------------------------------------------------------------- */
00076 
00077 #define main(...)       NutAppMain(__VA_ARGS__)
00078 
00079 /* -------------------------------------------------------------------------
00080  * map harvard specific calls to normal ones
00081  * ------------------------------------------------------------------------- */
00082 
00083 
00084 #define strlen_P(x)             strlen(x)
00085 #define strcpy_P(x,y)           strcpy(x,y)
00086 #define strcmp_P(x, y)          strcmp(x, y)
00087 #define memcpy_P(x, y, z)       memcpy(x, y, z)
00088 
00089 /* -------------------------------------------------------------------------
00090  * emulated IRQs
00091  * ------------------------------------------------------------------------- */
00092 enum {
00093         IRQ_TIMER0,
00094     IRQ_UART0_RX,
00095     IRQ_UART1_RX,
00096     IRQ_UART2_RX,
00097         IRQ_MAX
00098 };
00099 
00100 /* -------------------------------------------------------------------------
00101  * emulated heap
00102  * ------------------------------------------------------------------------- */
00103 
00104 /* RAMSTART could be zero, but RAMSTART < 3 leads to a crash in freopen (stdout) */
00105 #define RAMSTART    ((void *)0x00100)
00106 
00107 /* on linux our malloc function makes the init section crash, so we better rename it */
00108 #define malloc(...)             NUT_malloc(__VA_ARGS__)
00109 #define realloc(...)    NUT_realloc(__VA_ARGS__)
00110 #define free(...)               NUT_free(__VA_ARGS__)
00111 
00112 /* -------------------------------------------------------------------------
00113  * parsing of command line options
00114  * ------------------------------------------------------------------------- */
00115 
00116 /*
00117  * options of one uart 
00118  * usbnum: a negative usbnum is used to indicate that device name is used
00119  */
00120 
00121 typedef struct {
00122 
00123     char *device;
00124     uint32_t bautrate;
00125     uint8_t flowcontrol;
00126     signed char usbnum;
00127 } uart_options_t;
00128 
00129 /* 
00130  * all command line options
00131  */
00132 typedef struct {
00133 
00134     // debug output
00135     int verbose;
00136 
00137     uart_options_t uart_options[3];
00138     struct termios saved_termios;
00139 } emulation_options_t;
00140 
00141 /* the command line options are stored here */
00142 extern emulation_options_t emulation_options;
00143 
00144 /* -------------------------------------------------------------------------
00145  * function declarations
00146  * ------------------------------------------------------------------------- */
00147 void emulation_options_parse(int argc, char *argv[]);
00148 
00150 #define eeprom_rb(addr) eeprom_read_byte       ((uint8_t  *)(uint32_t) (addr))
00151 #define eeprom_rw(addr) eeprom_read_word       ((uint16_t *)(uint32_t) (addr))
00152 #define eeprom_wb(addr, val) eeprom_write_byte ((uint8_t  *)(uint32_t) (addr), (val))
00153 // fake ATmega128 has 0xfff eeprom
00154 #define    E2END    0x0FFF
00155 
00159 #define eeprom_is_ready() TRUE
00160 
00161 #endif                          /* #ifndef _CPU_UNIX_H_ */