AvrIO  1.4.5
Bibliothèque C modulaire pour ATMEL AVR
defs.h
1 
18 #ifndef _AVRIO_DEFS_H_
19 #define _AVRIO_DEFS_H_
20 
21 /* constants ============================================================== */
27 # define ERROR_SUCCESS 0x00
29 /* =======================Fin Codes d'erreur système======================= */
30 
38 #define KEY_ENTER '\n'
39 
44 #define KEY_LEFT 0x80
45 
50 #define KEY_RIGHT 0x81
51 
56 #define KEY_UP 0x82
57 
62 #define KEY_DOWN 0x83
63 
68 #define KEY_HOME 0x84
69 
70 /* macros ================================================================= */
71 #ifndef _BV
72 
76 #define _BV(n) (1<<n)
77 #endif
78 
83 #define SECONDS(s) (1000L*s)
84 
89 #define MINUTES(m) (m*SECONDS(60))
90 
95 #define HOURS(h) (h*MINUTES(60))
96 
101 #define DAYS(d) (d*HOURS(24))
102 
107 #define WEEKS(w) (w*DAYS(7))
108 
114 #define HMS(h,m,s) (HOURS(h)+MINUTES(m)+SECONDS(s))
115 
121 #define DHMS(d,h,m,s) (DAYS(d)+HOURS(h)+MINUTES(m)+SECONDS(s))
122 
128 #define WDHMS(w,d,h,m,s) (WEEKS(w)+DAYS(d)+HOURS(h)+MINUTES(m)+SECONDS(s))
129 
135 # define TIMER16_STOPPED (0)
136 # define TIMER16_CLK1 (1)
137 # define TIMER16_CLK8 (2)
138 # define TIMER16_CLK64 (3)
139 # define TIMER16_CLK256 (4)
140 # define TIMER16_CLK1024 (5)
142 /* =================Fin Définitions pour le timer 16 bits================== */
143 
152 # define KEYB_IFACE_TYPE_MSK 0x0070
153 # define KEYB_IFACE_PIO 0x0000
154 # define KEYB_IFACE_BUS 0x0010
155 # define KEYB_IFACE_PCF8574 0x0020
156 # define KEYB_IFACE_TYPE(_keyb_setup) ((_keyb_setup) & KEYB_IFACE_TYPE_MSK)
157 
158 # define KEYB_IFACE_DO_MSK 0x0100
159 # define KEYB_IFACE_SORTED 0x0000
160 # define KEYB_IFACE_USORTED 0x0100
161 # define KEYB_IFACE_DO(_keyb_setup) ((_keyb_setup) & KEYB_IFACE_DO_MSK)
162 
163 /* =================Fin Définitions pour le driver KEYB==================== */
168 #if ! defined(__DOXYGEN__)
169 /* ======================================================================== */
170 #if defined(__cplusplus)
171 #define __BEGIN_C_DECLS extern "C" {
172 #define __END_C_DECLS }
173 #else
174 #define __BEGIN_C_DECLS
175 #define __END_C_DECLS
176 #endif
177 
178 #ifndef AVRIO_CPU_FREQ
179 #ifdef F_CPU
180 #define AVRIO_CPU_FREQ F_CPU
181 #else
182 #warning AVRIO_CPU_FREQ non definie ! Valeur par defaut affectee: AVRIO_CPU_FREQ = 8000000UL
183 #define AVRIO_CPU_FREQ 8000000UL
184 #endif
185 #endif
186 
187 #define OUI 1
188 #define YES 1
189 #define NON 0
190 #define NO 0
191 #define WAIT_INFINITE 0
192 
193 #ifndef TRUE
194 # define TRUE 1
195 #endif
196 
197 #ifndef FALSE
198 # define FALSE 0
199 #endif
200 
201 #ifndef __ORDER_LITTLE_ENDIAN__
202 #define __ORDER_LITTLE_ENDIAN__ 1234
203 #endif
204 #ifndef __ORDER_BIG_ENDIAN__
205 #define __ORDER_BIG_ENDIAN__ 4321
206 #endif
207 #ifndef __BYTE_ORDER__
208 #define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
209 #endif
210 
211 #ifndef RAMSIZE
212 #define RAMSIZE (RAMEND+1-((RAMEND+1) & (-1-RAMEND)))
213 #endif
214 
215 #include <errno.h>
216 #ifndef ENOENT
217 #define ENOENT 2 /* No such file or directory */
218 #endif
219 #ifndef EIO
220 #define EIO 5 /* I/O error */
221 #endif
222 #ifndef ENOMEM
223 #define ENOMEM 12 /* Out of memory */
224 #endif
225 #ifndef EFAULT
226 #define EFAULT 14 /* Bad address */
227 #endif
228 #ifndef EBUSY
229 #define EBUSY 16 /* Device or resource busy */
230 #endif
231 #ifndef EBADMSG
232 #define EBADMSG 74 /* Not a data message */
233 #endif
234 #ifndef ETIMEDOUT
235 #define ETIMEDOUT 110 /* Connection timed out */
236 #endif
237 #ifndef EINVAL
238 #define EINVAL 22 /* Invalid argument */
239 #endif
240 
241 #endif /* __DOXYGEN__ not defined */
242 
243 #ifndef __ASSEMBLER__
244  __BEGIN_C_DECLS
245 /* ==========================Partie Langage C============================== */
246 #define __need_NULL
247 #define __need_size_t
248 #include <stddef.h>
249 #include <stdint.h>
250 #include <stdbool.h>
251 #include <math.h>
252 
253 /* types ================================================================== */
254 #ifndef AVRIO_TIME_UINT32
255 
262  typedef uint16_t time_t;
263 
271  typedef uint16_t ticks_t;
272 #else
273 
280  typedef uint32_t time_t;
281 
289  typedef uint32_t ticks_t;
290 #endif
291 
292 /* macros ================================================================= */
293 #ifndef cbi
294 
299 #define cbi(var,n) do { var &= ~_BV(n); } while(0)
300 #endif
301 
302 #ifndef sbi
303 
308 #define sbi(var,n) do { var |= _BV(n); } while(0)
309 #endif
310 
311 #ifndef tbi
312 
317 #define tbi(var,n) do { var ^= _BV(n); } while(0)
318 #endif
319 
320 #ifndef outp
321 
326 #define outp(reg,value) do { reg = (value); } while(0)
327 #endif
328 
329 #ifndef inp
330 
335 #define inp(reg)(reg)
336 #endif
337 
338 #ifndef MSB16
339 
343 #define MSB16(x) ((uint8_t) (x >> 8) & 0xFF)
344 #endif
345 
346 #ifndef LSB
347 
351 #define LSB(x) ((uint8_t) (x & 0xFF))
352 #endif
353 
354 #ifndef PUINT8
355 
359 #define PUINT8(p) ((uint8_t *)(p))
360 #endif
361 
362 #ifndef PUINT16
363 
367 #define PUINT16(p) ((uint16_t *)(p))
368 #endif
369 
370 #ifndef PUINT32
371 
375 #define PUINT32(p) ((uint32_t *)(p))
376 #endif
377 
378 #ifndef PUINT64
379 
383 #define PUINT64(p) ((uint64_t *)(p))
384 #endif
385 
386 #ifndef ABS
387 
391 #define ABS(n) (((n) < 0) ? -(n) : (n))
392 #endif
393 
394 #ifndef MIN
395 
399 #define MIN(a,b) (((a) < (b)) ? (a) : (b))
400 #endif
401 
402 #ifndef MAX
403 
407 #define MAX(a,b) (((a) > (b)) ? (a) : (b))
408 #endif
409 
410 #ifndef NOP
411 
415 #define NOP() __asm__ volatile ("nop")
416 #endif
417 
418 #ifndef STRUCT_FIELD_OFFSET
419 
423 #define STRUCT_FIELD_OFFSET(s,f) ((size_t)&(((s *)0)->f))
424 #endif
425 
430 #define DEG_TO_RAD(a) ((a) * M_PI / 180.0f)
431 
436 #define RAD_TO_DEG(a) ((a) * 180.0f / M_PI)
437 
443 #define DIV_ROUND(dividend, divisor) (((dividend) + (divisor) / 2) / (divisor))
444 
449 #define DIV_ROUNDUP(dividend, divisor) (((dividend) + (divisor) - 1) / (divisor))
450 
452 #define ROUND_UP2(x, pad) (((x) + ((pad) - 1)) & ~((pad) - 1))
453 
461 #define ROUND_DOWN(x, base) ( (x) - ((x) % (base)) )
462 #define ROUND_UP(x, base) ( ((x) + (base) - 1) - (((x) + (base) - 1) % (base)) )
463 #define ROUND_NEAREST(x, base) ( ((x) + (base) / 2) - (((x) + (base) / 2) % (base)) )
464 
466 #define IS_POW2(x) (!(bool)((x) & ((x)-1)))
467 
468 #ifndef offsetof
469 
475 #define offsetof(s,m) (size_t)&(((s *)0)->m)
476 #endif
477 
478 #ifndef alignof
479 
486 #define alignof(type) offsetof(struct { char c; type member; }, member)
487 #endif
488 
489 #define countof(a) (sizeof(a) / sizeof(*(a)))
490 
491 /* GCC attributes */
492 #define FORMAT(type,fmt,first) __attribute__((__format__(type, fmt, first)))
493 #define NORETURN __attribute__((__noreturn__))
494 #define UNUSED_ARG(type,arg) __attribute__((__unused__)) type arg
495 #define UNUSED_VAR(type,name) __attribute__((__unused__)) type name
496 #define USED_VAR(type,name) __attribute__((__used__)) type name
497 #define INLINE static inline __attribute__((__always_inline__))
498 #define NOINLINE __attribute__((noinline))
499 #define LIKELY(x) __builtin_expect(!!(x), 1)
500 #define UNLIKELY(x) __builtin_expect(!!(x), 0)
501 #define PURE_FUNC __attribute__((pure))
502 #define CONST_FUNC __attribute__((const))
503 #define UNUSED_FUNC __attribute__((unused))
504 #define USED_FUNC __attribute__((__used__))
505 #define RESTRICT __restrict__
506 #define MUST_CHECK __attribute__((warn_unused_result))
507 #define PACKED __attribute__((packed))
508 #define ALIGNED(x) __attribute__ ((__aligned__(x)))
509 
510 #define STATIC_ASSERT(exp, message_identifier) \
511  struct compile_time_assertion { \
512  char message_identifier : 8 + !(exp); \
513  };
514 
515 #if !defined(__DOXYGEN__)
516 /* ======================================================================== */
517 
518 #define FLASH __attribute__ ((progmem))
519 #define EEPROM __attribute__ ((section(".eeprom")))
520 #define NAKED __attribute__ ((naked))
521 #define CTASK __attribute__ ((noreturn))
522 
523 /* macros ================================================================= */
524 #ifdef DEBUG_ENABLE
525 #define DEBUG_BLOCK()
526 #else
527 #define DEBUG_BLOCK() if(0)
528 /* Le compilateur supprimera le bloc suivant à l'optimisation */
529 #endif
530 
531 #define __STATIC_ALWAYS_INLINE(func) \
532  static __inline__ func __attribute__ ((always_inline));\
533  func
534 
535 /* types ================================================================== */
536 #ifndef _SSIZE_T_
537 #define _SSIZE_T_
538 typedef int ssize_t;
539 #endif /* _SSIZE_T_ not defined */
540 
541 #endif /* __DOXYGEN__ not defined */
542 
543 __END_C_DECLS
544 /* ========================Fin Partie Langage C============================ */
545 #endif /* __ASSEMBLER__ not defined */
546 
547 /* ==========================Partie Assembleur============================= */
548 #if defined (__ASSEMBLER__) && !defined(__DOXYGEN__)
549 
550 # define GLOBAL(__label__) \
551  .global __label__
552 
553 # define GLOBAL_DATA(__label__,__size__) \
554  .comm __label__,__size__,1
555 
556 # define LOCAL_DATA(__label__,__size__) \
557  .lcomm __label__,__size__
558 
559 # define STATIC_DATA(__label__,__size__) \
560  .section .bss. ## __label__,"aw",@nobits $ \
561 __label__: $ \
562  .skip __size__,0
563 
564 # define EEPROM_STRING(__label__,__string__) \
565  .section .eeprom,"aw",@progbits $ \
566 __label__: $ \
567  .string __string__
568 
569 # define FLASH_STRING(__label__,__string__) \
570  .section .progmem.data,"a",@progbits $ \
571 __label__: $ \
572  .string __string__
573 
574 # define GLOBAL_SECTION(__label__) \
575  .section .text.##__label__,"ax",@progbits
576 
577 # define FUNCTION(__label__) \
578  GLOBAL_SECTION(__label__) $ \
579  GLOBAL(__label__) $ \
580 __label__: $
581 
582 # define MODULE(__label__) GLOBAL_SECTION(__label__)
583 
584 /* ========================Fin Partie Assembleur=========================== */
585 #endif /* __ASSEMBLER__ defined and __DOXYGEN__ not defined */
586 
587 #endif /* _AVRIO_DEFS_H_ */