unix.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #ifndef _ARCH_UNIX_H_
  2. #define _ARCH_UNIX_H_
  3. /*
  4. * Copyright (C) 2000-2004 by ETH Zurich
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the copyright holders nor the names of
  16. * contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY ETH ZURICH AND CONTRIBUTORS
  20. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ETH ZURICH
  23. * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  27. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  29. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. *
  32. * For additional information see http://www.ethernut.de/
  33. *
  34. */
  35. /*
  36. * unix.h.c - types and defines for unix emulation
  37. *
  38. * 2004.04.01 Matthias Ringwald <matthias.ringwald@inf.ethz.ch>
  39. *
  40. */
  41. #if !defined(__linux__) && !defined(__APPLE__) && !defined(__CYGWIN__)
  42. #error "Nut/OS emulation currently runs only on Linux and MAC OS X systems."
  43. #endif
  44. /* -------------------------------------------------------------------------
  45. * map some AVR types/defines to something else
  46. * ------------------------------------------------------------------------- */
  47. #define CONST const
  48. #define INLINE inline
  49. #define PSTR(p) (p)
  50. #define PRG_RDB(p) (*((const char *)(p)))
  51. #define prog_char const char
  52. #define PGM_P prog_char *
  53. /* -------------------------------------------------------------------------
  54. * now we can include types (and time.h)
  55. * ------------------------------------------------------------------------- */
  56. #include <sys/types.h>
  57. #include <dev/mweeprom.h>
  58. #include <termios.h>
  59. #include <unistd_orig.h>
  60. /* -------------------------------------------------------------------------
  61. * redefine main
  62. * ------------------------------------------------------------------------- */
  63. #define main(...) NutAppMain(__VA_ARGS__)
  64. /* -------------------------------------------------------------------------
  65. * map harvard specific calls to normal ones
  66. * ------------------------------------------------------------------------- */
  67. #define strlen_P(x) strlen(x)
  68. #define strcpy_P(x,y) strcpy(x,y)
  69. #define strcmp_P(x, y) strcmp(x, y)
  70. #define memcpy_P(x, y, z) memcpy(x, y, z)
  71. /* -------------------------------------------------------------------------
  72. * emulated IRQs
  73. * ------------------------------------------------------------------------- */
  74. enum {
  75. IRQ_TIMER0,
  76. IRQ_UART0_RX,
  77. IRQ_UART1_RX,
  78. IRQ_UART2_RX,
  79. IRQ_MAX
  80. };
  81. /* -------------------------------------------------------------------------
  82. * emulated heap
  83. * ------------------------------------------------------------------------- */
  84. /* RAMSTART could be zero, but RAMSTART < 3 leads to a crash in freopen (stdout) */
  85. #define RAMSTART ((void *)0x00100)
  86. /* on linux our malloc function makes the init section crash, so we better rename it */
  87. #define malloc(...) NUT_malloc(__VA_ARGS__)
  88. #define free(...) NUT_free(__VA_ARGS__)
  89. /* -------------------------------------------------------------------------
  90. * parsing of command line options
  91. * ------------------------------------------------------------------------- */
  92. /*
  93. * options of one uart
  94. * usbnum: a negative usbnum is used to indicate that device name is used
  95. */
  96. typedef struct {
  97. char *device;
  98. u_long bautrate;
  99. u_char flowcontrol;
  100. signed char usbnum;
  101. } uart_options_t;
  102. /*
  103. * all command line options
  104. */
  105. typedef struct {
  106. // debug output
  107. int verbose;
  108. uart_options_t uart_options[3];
  109. struct termios saved_termios;
  110. } emulation_options_t;
  111. /* the command line options are stored here */
  112. extern emulation_options_t emulation_options;
  113. /* -------------------------------------------------------------------------
  114. * function declarations
  115. * ------------------------------------------------------------------------- */
  116. void emulation_options_parse(int argc, char *argv[]);
  117. /** \name Backwards compatibility defines */
  118. #define eeprom_rb(addr) eeprom_read_byte ((u_char *)(u_long) (addr))
  119. #define eeprom_rw(addr) eeprom_read_word ((u_short *)(u_long) (addr))
  120. #define eeprom_wb(addr, val) eeprom_write_byte ((u_char *)(u_long) (addr), (val))
  121. // fake ATmega128 has 0xfff eeprom
  122. #define E2END 0x0FFF
  123. /** \def eeprom_is_ready
  124. \ingroup unix_eeprom
  125. always returns 1, as eeprom = unix_file is always ready */
  126. #define eeprom_is_ready() TRUE
  127. #endif /* #ifndef _CPU_UNIX_H_ */