Statistics
| Branch: | Revision:

root / freemodbus / port / port.h @ 20e5429c

History | View | Annotate | Download (4.74 KB)

1
/*
2
 * FreeModbus Libary: AVR Port
3
 * Copyright (C) 2006 Christian Walter <wolti@sil.at>
4
 *   - Initial version + ATmega168 support
5
 * Modfications Copyright (C) 2006 Tran Minh Hoang:
6
 *   - ATmega8, ATmega16, ATmega32 support
7
 *   - RS485 support for DS75176
8
 *
9
 * This library is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU Lesser General Public
11
 * License as published by the Free Software Foundation; either
12
 * version 2.1 of the License, or (at your option) any later version.
13
 *
14
 * This library is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
 * Lesser General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Lesser General Public
20
 * License along with this library; if not, write to the Free Software
21
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22
 *
23
 * File: $Id: port.h,v 1.6 2006/09/17 16:45:52 wolti Exp $
24
 */
25

    
26
#ifndef _PORT_H
27
#define _PORT_H
28

    
29
/* ----------------------- Platform includes --------------------------------*/
30

    
31
#include <avr/io.h>
32
#include <avr/interrupt.h>
33

    
34
/* ----------------------- Defines ------------------------------------------*/
35
#define        INLINE                      inline
36
#define PR_BEGIN_EXTERN_C           extern "C" {
37
#define        PR_END_EXTERN_C             }
38

    
39
#define ENTER_CRITICAL_SECTION( )   cli()
40
#define EXIT_CRITICAL_SECTION( )    sei()
41

    
42
#define assert( x )
43

    
44
typedef char    BOOL;
45

    
46
typedef unsigned char UCHAR;
47
typedef char    CHAR;
48

    
49
typedef unsigned short USHORT;
50
typedef short   SHORT;
51

    
52
typedef unsigned long ULONG;
53
typedef long    LONG;
54

    
55
#ifndef TRUE
56
#define TRUE            1
57
#endif
58

    
59
#ifndef FALSE
60
#define FALSE           0
61
#endif
62

    
63
/* ----------------------- AVR platform specifics ---------------------------*/
64

    
65
#if defined (__AVR_ATmega168__)
66
#define UCSRB           UCSR0B
67
#define TXEN            TXEN0
68
#define RXEN            RXEN0
69
#define RXCIE           RXCIE0
70
#define TXCIE           TXCIE0
71
#define UDRE            UDRE0
72
#define UBRR            UBRR0
73
#define UCSRC           UCSR0C
74
#define UPM1            UPM01
75
#define UPM0            UPM00
76
#define UCSZ0           UCSZ00
77
#define UCSZ1           UCSZ01
78
#define UDR             UDR0
79
#define SIG_UART_TRANS  SIG_USART_TRANS
80

    
81
#elif defined (__AVR_ATmega169__)
82

    
83
#define SIG_UART_TRANS  SIG_USART_TRANS
84

    
85
#elif defined (__AVR_ATmega8__)
86
#define UBRR            UBRRL
87
#define TCCR1C          TCCR1A  /* dummy */
88
#define TIMSK1          TIMSK
89
#define TIFR1           TIFR
90
#define SIG_USART_DATA  SIG_UART_DATA
91
#define SIG_USART_RECV  SIG_UART_RECV
92

    
93
#elif defined (__AVR_ATmega16__)
94
#define UBRR            UBRRL
95
#define TCCR1C          TCCR1A  /* dummy */
96
#define TIMSK1          TIMSK
97
#define TIFR1           TIFR
98

    
99
#elif defined (__AVR_ATmega32__)
100
#define UBRR            UBRRL
101
#define TCCR1C          TCCR1A  /* dummy */
102
#define TIMSK1          TIMSK
103
#define TIFR1           TIFR
104

    
105
#elif defined (__AVR_ATmega128__)
106
#define UCSRB           UCSR0B
107
#define UBRR            UBRR0L
108
#define UDR             UDR0
109
#define TIMSK1          TIMSK
110
#define TIFR1           TIFR
111
#define SIG_UART_TRANS  SIG_USART0_TRANS
112
#define SIG_USART_DATA  SIG_USART0_DATA
113
#define SIG_USART_RECV  SIG_USART0_RECV
114
#define UCSZ0           UCSZ00
115
#define UCSZ1           UCSZ01
116
#define UPM0            UPM00
117
#define UPM1            UPM01
118
#define UCSRC           UCSR0C
119

    
120
#elif defined (__AVR_ATtiny1634__)
121
#define UCSRB           UCSR0B
122
#define UBRR            UBRR0L
123
#define UDR             UDR0
124
#define UDRE            UDRE0
125
#define TIMSK1          TIMSK
126
#define TIFR1           TIFR
127
#define UCSZ0           UCSZ00
128
#define UCSZ1           UCSZ01
129
#define UPM0            UPM00
130
#define UPM1            UPM01
131
#define UCSRC           UCSR0C
132
#define SIG_UART_TRANS  USART0_TX_vect
133
#define SIG_USART_DATA  USART0_UDRE_vect
134
#define SIG_USART_RECV  USART0_RX_vect
135
#define SIG_OUTPUT_COMPARE1A TIMER1_COMPA_vect
136

    
137
#define RXEN            RXEN0
138
#define RXCIE           RXCIE0
139
#define TXEN            TXEN0
140
#define TXCIE           TXCIE0
141

    
142
#endif
143

    
144
/* ----------------------- RS485 specifics ----------------------------------*/
145
#ifdef  RTS_ENABLE
146

    
147
#define RTS_PIN         PC2
148
#define RTS_DDR         DDRC
149
#define RTS_PORT        PORTC
150

    
151
#define RTS_INIT        \
152
    do { \
153
        RTS_DDR |= _BV( RTS_PIN ); \
154
        RTS_PORT &= ~( _BV( RTS_PIN ) ); \
155
    } while( 0 );
156

    
157
#define RTS_HIGH        \
158
    do { \
159
        RTS_PORT |= _BV( RTS_PIN ); \
160
    } while( 0 );
161

    
162
#define RTS_LOW         \
163
    do { \
164
        RTS_PORT &= ~( _BV( RTS_PIN ) ); \
165
    } while( 0 );
166

    
167
#endif
168

    
169
#endif