init
[protos/xbee-avr.git] / aversive / pgmspace.h~
1 /*  
2  *  Copyright Droids Corporation, Microb Technology, Eirbot (2005)
3  * 
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  *
18  *  Revision : $Id: pgmspace.h,v 1.1.2.4 2007-11-21 21:54:38 zer0 Exp $
19  *
20  */
21
22 /**
23  * This file is used for compatibility between host and avr : with
24  * this we can emulate pgmspace on a host.
25  */
26
27 #ifndef _AVERSIVE_PGMSPACE_H_
28 #define _AVERSIVE_PGMSPACE_H_
29
30 #ifndef HOST_VERSION
31
32 #include <avr/pgmspace.h>
33 #define PGMS_FMT "%S"
34
35
36 #else
37
38 #include <stdint.h>
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <stdarg.h>
42 #include <string.h>
43
44 typedef void prog_void;
45 typedef char prog_char;
46 typedef unsigned char prog_uchar;
47 typedef int8_t prog_int8_t;
48 typedef uint8_t prog_uint8_t;
49 typedef int16_t prog_int16_t;
50 typedef uint16_t prog_uint16_t;
51 typedef int32_t prog_int32_t;
52 typedef uint32_t prog_uint32_t;
53 typedef int64_t prog_int64_t;
54
55
56 static inline int memcmp_P(const void *s1,
57                            const prog_void *s2, unsigned n)
58 {
59         return memcmp(s1, s2, n);
60 }
61
62 static inline void *memcpy_P(void *s1,
63                              const prog_void *s2, unsigned n)
64 {
65         return memcpy(s1, s2, n);
66 }
67
68 static inline char *strcat_P(char *s1, const prog_char *s2)
69 {
70         return strcat(s1, s2);
71 }
72
73 static inline char *strcpy_P(char *s1, const prog_char *s2)
74 {
75         return strcpy(s1, s2);
76 }
77
78 static inline char *strncpy_P(char *s1, const prog_char *s2,
79                               unsigned n)
80 {
81         return strncpy(s1, s2, n);
82 }
83
84 static inline int strcmp_P(const char *s1, const prog_char *s2)
85 {
86         return strcmp(s1, s2);
87 }
88
89 static inline int strncmp_P(const char *s1, const prog_char *s2,
90                             unsigned n)
91 {
92         return strncmp(s1, s2, n);
93 }
94
95 static inline unsigned strlen_P(const prog_char *s)
96 {
97         return strlen(s);
98 }
99
100 static inline int vfprintf_P(FILE *stream,
101                              const prog_char *s, va_list ap)
102 {
103         return vfprintf(stream, s, ap);
104 }
105
106 static inline int vsprintf_P(char *buf, const prog_char *s,
107                              va_list ap)
108 {
109         return vsprintf(buf, s, ap);
110 }
111
112 #define PGM_P const char *
113 #define PSTR(x) x
114 #define PROGMEM
115 #define printf_P(args...) printf(args)
116 #define sprintf_P(buf, args...) sprintf(buf, args)
117 #define snprintf_P(buf, n, args...) snprintf(buf, n, args)
118
119 static inline uint32_t pgm_read_dword(const prog_void *x)
120 {
121         return *(uint32_t *)x;
122 }
123
124 static inline uint16_t pgm_read_word(const prog_void *x)
125 {
126         return *(uint16_t *)x;
127 }
128
129 static inline uint8_t pgm_read_byte(const prog_void *x)
130 {
131         return *(uint8_t *)x;
132 }
133
134 #define PGMS_FMT "%s"
135
136 #endif /* HOST_VERSION */
137 #endif /* _AVERSIVE_PGMSPACE_H_ */
138
139