1 |
/*! \file avrlibdefs.h \brief AVRlib global defines and macros. */ |
1 |
/*! \file avrlibdefs.h \brief AVRlib global defines and macros. */ |
2 |
//***************************************************************************** |
2 |
//***************************************************************************** |
3 |
// |
3 |
// |
4 |
// File Name : 'avrlibdefs.h' |
4 |
// File Name : 'avrlibdefs.h' |
5 |
// Title : AVRlib global defines and macros include file |
5 |
// Title : AVRlib global defines and macros include file |
6 |
// Author : Pascal Stang |
6 |
// Author : Pascal Stang |
7 |
// Created : 7/12/2001 |
7 |
// Created : 7/12/2001 |
8 |
// Revised : 9/30/2002 |
8 |
// Revised : 9/30/2002 |
9 |
// Version : 1.1 |
9 |
// Version : 1.1 |
10 |
// Target MCU : Atmel AVR series |
10 |
// Target MCU : Atmel AVR series |
11 |
// Editor Tabs : 4 |
11 |
// Editor Tabs : 4 |
12 |
// |
12 |
// |
13 |
// Description : This include file is designed to contain items useful to all |
13 |
// Description : This include file is designed to contain items useful to all |
14 |
// code files and projects, regardless of specific implementation. |
14 |
// code files and projects, regardless of specific implementation. |
15 |
// |
15 |
// |
16 |
// This code is distributed under the GNU Public License |
16 |
// This code is distributed under the GNU Public License |
17 |
// which can be found at http://www.gnu.org/licenses/gpl.txt |
17 |
// which can be found at http://www.gnu.org/licenses/gpl.txt |
18 |
// |
18 |
// |
19 |
//***************************************************************************** |
19 |
//***************************************************************************** |
20 |
|
20 |
|
21 |
|
21 |
|
22 |
#ifndef AVRLIBDEFS_H |
22 |
#ifndef AVRLIBDEFS_H |
23 |
#define AVRLIBDEFS_H |
23 |
#define AVRLIBDEFS_H |
24 |
|
24 |
|
25 |
// Code compatibility to new AVR-libc |
25 |
// Code compatibility to new AVR-libc |
26 |
// outb(), inb(), inw(), outw(), BV(), sbi(), cbi(), sei(), cli() |
26 |
// outb(), inb(), inw(), outw(), BV(), sbi(), cbi(), sei(), cli() |
27 |
#ifndef outb |
27 |
#ifndef outb |
28 |
#define outb(addr, data) addr = (data) |
28 |
#define outb(addr, data) addr = (data) |
29 |
#endif |
29 |
#endif |
30 |
#ifndef inb |
30 |
#ifndef inb |
31 |
#define inb(addr) (addr) |
31 |
#define inb(addr) (addr) |
32 |
#endif |
32 |
#endif |
33 |
#ifndef outw |
33 |
#ifndef outw |
34 |
#define outw(addr, data) addr = (data) |
34 |
#define outw(addr, data) addr = (data) |
35 |
#endif |
35 |
#endif |
36 |
#ifndef inw |
36 |
#ifndef inw |
37 |
#define inw(addr) (addr) |
37 |
#define inw(addr) (addr) |
38 |
#endif |
38 |
#endif |
39 |
#ifndef BV |
39 |
#ifndef BV |
40 |
#define BV(bit) (1<<(bit)) |
40 |
#define BV(bit) (1<<(bit)) |
41 |
#endif |
41 |
#endif |
42 |
#ifndef cbi |
42 |
#ifndef cbi |
43 |
#define cbi(reg,bit) reg &= ~(BV(bit)) |
43 |
#define cbi(reg,bit) reg &= ~(BV(bit)) |
44 |
#endif |
44 |
#endif |
45 |
#ifndef sbi |
45 |
#ifndef sbi |
46 |
#define sbi(reg,bit) reg |= (BV(bit)) |
46 |
#define sbi(reg,bit) reg |= (BV(bit)) |
47 |
#endif |
47 |
#endif |
48 |
#ifndef cli |
48 |
#ifndef cli |
49 |
#define cli() __asm__ __volatile__ ("cli" ::) |
49 |
#define cli() __asm__ __volatile__ ("cli" ::) |
50 |
#endif |
50 |
#endif |
51 |
#ifndef sei |
51 |
#ifndef sei |
52 |
#define sei() __asm__ __volatile__ ("sei" ::) |
52 |
#define sei() __asm__ __volatile__ ("sei" ::) |
53 |
#endif |
53 |
#endif |
54 |
|
54 |
|
55 |
// support for individual port pin naming in the mega128 |
55 |
// support for individual port pin naming in the mega128 |
56 |
// see port128.h for details |
56 |
// see port128.h for details |
57 |
#ifdef __AVR_ATmega128__ |
57 |
#ifdef __AVR_ATmega128__ |
58 |
// not currently necessary due to inclusion |
58 |
// not currently necessary due to inclusion |
59 |
// of these defines in newest AVR-GCC |
59 |
// of these defines in newest AVR-GCC |
60 |
// do a quick test to see if include is needed |
60 |
// do a quick test to see if include is needed |
61 |
#ifndef PD0 |
61 |
#ifndef PD0 |
62 |
#include "port128.h" |
62 |
#include "port128.h" |
63 |
#endif |
63 |
#endif |
64 |
#endif |
64 |
#endif |
65 |
|
65 |
|
66 |
// use this for packed structures |
66 |
// use this for packed structures |
67 |
// (this is seldom necessary on an 8-bit architecture like AVR, |
67 |
// (this is seldom necessary on an 8-bit architecture like AVR, |
68 |
// but can assist in code portability to AVR) |
68 |
// but can assist in code portability to AVR) |
69 |
#define GNUC_PACKED __attribute__((packed)) |
69 |
#define GNUC_PACKED __attribute__((packed)) |
70 |
|
70 |
|
71 |
// port address helpers |
71 |
// port address helpers |
72 |
#define DDR(x) ((x)-1) // address of data direction register of port x |
72 |
#define DDR(x) ((x)-1) // address of data direction register of port x |
73 |
#define PIN(x) ((x)-2) // address of input register of port x |
73 |
#define PIN(x) ((x)-2) // address of input register of port x |
74 |
|
74 |
|
75 |
// MIN/MAX/ABS macros |
75 |
// MIN/MAX/ABS macros |
76 |
#define MIN(a,b) ((a<b)?(a):(b)) |
76 |
#define MIN(a,b) ((a<b)?(a):(b)) |
77 |
#define MAX(a,b) ((a>b)?(a):(b)) |
77 |
#define MAX(a,b) ((a>b)?(a):(b)) |
78 |
#define ABS(x) ((x>0)?(x):(-x)) |
78 |
#define ABS(x) ((x>0)?(x):(-x)) |
79 |
|
79 |
|
80 |
// constants |
80 |
// constants |
81 |
#define PI 3.14159265359 |
81 |
#define PI 3.14159265359 |
82 |
|
82 |
|
83 |
#endif |
83 |
#endif |