forked from OSCSYS/freemodbus
-
Notifications
You must be signed in to change notification settings - Fork 1
/
port.h
149 lines (120 loc) · 4.09 KB
/
port.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
* FreeModbus Libary: AVR Port
* Copyright (C) 2006 Christian Walter <[email protected]>
* - Initial version + ATmega168 support
* Modfications Copyright (C) 2006 Tran Minh Hoang:
* - ATmega8, ATmega16, ATmega32 support
* - RS485 support for DS75176
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* File: $Id: port.h,v 1.6 2006/09/17 16:45:52 wolti Exp $
*/
#ifndef _PORT_H
#define _PORT_H
/* ----------------------- Platform includes --------------------------------*/
#include <avr/io.h>
#include <avr/interrupt.h>
/* ----------------------- Defines ------------------------------------------*/
#define INLINE inline
#define PR_BEGIN_EXTERN_C extern "C" {
#define PR_END_EXTERN_C }
#define ENTER_CRITICAL_SECTION( ) cli()
#define EXIT_CRITICAL_SECTION( ) sei()
#define RTS_ENABLE
#define assert( x )
typedef char BOOL;
typedef unsigned char UCHAR;
typedef char CHAR;
typedef unsigned short USHORT;
typedef short SHORT;
typedef unsigned long ULONG;
typedef long LONG;
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
/* ----------------------- AVR platform specifics ---------------------------*/
#if defined (__AVR_ATmega168__)
#define UCSRB UCSR0B
#define TXEN TXEN0
#define RXEN RXEN0
#define RXCIE RXCIE0
#define TXCIE TXCIE0
#define UDRE UDRE0
#define UBRR UBRR0
#define UCSRC UCSR0C
#define UPM1 UPM01
#define UPM0 UPM00
#define UCSZ0 UCSZ00
#define UCSZ1 UCSZ01
#define UDR UDR0
#define SIG_UART_TRANS SIG_USART_TRANS
#elif defined (__AVR_ATmega169__)
#define SIG_UART_TRANS SIG_USART_TRANS
#elif defined (__AVR_ATmega8__)
#define UBRR UBRRL
#define TCCR1C TCCR1A /* dummy */
#define TIMSK1 TIMSK
#define TIFR1 TIFR
#define SIG_USART_DATA SIG_UART_DATA
#define SIG_USART_RECV SIG_UART_RECV
#elif defined (__AVR_ATmega16__)
#define UBRR UBRRL
#define TCCR1C TCCR1A /* dummy */
#define TIMSK1 TIMSK
#define TIFR1 TIFR
#elif defined (__AVR_ATmega32__)
#define UBRR UBRRL
#define TCCR1C TCCR1A /* dummy */
#define TIMSK1 TIMSK
#define TIFR1 TIFR
#elif defined (__AVR_ATmega128__)
#define UCSRB UCSR0B
#define UBRR UBRR0L
#define UDR UDR0
#define TIMSK1 TIMSK
#define TIFR1 TIFR
#define SIG_UART_TRANS SIG_USART0_TRANS
#define SIG_USART_DATA SIG_USART0_DATA
#define SIG_USART_RECV SIG_USART0_RECV
#define UCSZ0 UCSZ00
#define UCSZ1 UCSZ01
#define UPM0 UPM00
#define UPM1 UPM01
#define UCSRC UCSR0C
#endif
/* ----------------------- RS485 specifics ----------------------------------*/
#ifdef RTS_ENABLE
#define RTS_PIN PD2
#define RTS_DDR DDRD
#define RTS_PORT PORTD
#define RTS_INIT \
do { \
RTS_DDR |= _BV( RTS_PIN ); \
RTS_PORT &= ~( _BV( RTS_PIN ) ); \
} while( 0 );
#define RTS_HIGH \
do { \
RTS_PORT |= _BV( RTS_PIN ); \
} while( 0 );
#define RTS_LOW \
do { \
RTS_PORT &= ~( _BV( RTS_PIN ) ); \
} while( 0 );
#endif
#endif