dsm-api-v2
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ds485.h
Go to the documentation of this file.
1 /*
2  This file is part of the digitalSTROM ds485-core library.
3 
4  Copyright (C) 2010 digitalSTROM.org, Schlieren, Switzerland
5 
6  digitalSTROM ds485-core library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License
8  as published by the Free Software Foundation version 2
9  of the License.
10 
11  digitalSTROM ds485-core library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with digitalSTROM ds485-core library; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 
21 #ifndef _ds485_h
22 #define _ds485_h
23 
24 #include <digitalSTROM/ds.h>
25 #include <digitalSTROM/ds485-const.h>
26 #define DS485_MAX_PAYLOAD_SIZE 127
27 #define DS485_MAX_PAYLOAD_SIZE_RAW DS485_MAX_PAYLOAD_SIZE + 1
28 #define DS485_CONTAINER_DATA_LENGTH DS485_MAX_PAYLOAD_SIZE
29 #define DS485_CONTAINER_SIZE (sizeof(ds485_container_t) - (DS485_CONTAINER_DATA_LENGTH))
30 
34 enum {
39 };
40 
44 typedef enum {
50 } bus_state_t;
51 
55 typedef enum {
60 
61 typedef enum {
65 
69 typedef struct ds485_container {
74  uint8_t length;
75  union {
76  struct {
77  unsigned char transactionId;
78  unsigned char data[DS485_MAX_PAYLOAD_SIZE];
79  };
81  };
82 #ifdef SWIG
83 } ds485_container_t;
84 #else
85 } __attribute__ ((packed)) ds485_container_t;
86 #endif
87 
91 typedef struct {
92  /* TX */
93  uint32_t txToken;
94  uint16_t txStartupRequest;
96  uint16_t txJoinRequest;
97  uint16_t txJoinResponse;
104  uint16_t txResponse;
105  uint16_t txDataRequest;
106  uint16_t txDataResponse;
107  uint16_t txDataEvent;
108  /* RX */
109  uint16_t rxResponse;
110  uint16_t rxDataRequest;
111  uint16_t rxDataResponse;
112  uint16_t rxDataEvent;
113  /* Actions */
117  uint16_t successorLost;
119 
120 /***
121  * External references - have to be supplied by platform module
122  */
123 
127 #define RX_FLAG_CRC_ERROR 0x01
128 #define RX_FLAG_FRAME_ERROR 0x02
129 #define RX_FLAG_PROTOCOL_ERROR 0x04
130 #define RX_FLAG_NOTFORME 0x10
131 #define RX_FLAG_INVALID_ADDRESS 0x80
132 
133 #define RX_FLAG_ERRORS (RX_FLAG_CRC_ERROR | RX_FLAG_FRAME_ERROR | RX_FLAG_PROTOCOL_ERROR)
134 
138 #define DS485_FILTER_ALL_RESPONSES 0x01
139 
140 #endif