source: trunk/MagicSoft/Cosy/incl/nmts.h@ 770

Last change on this file since 770 was 731, checked in by tbretz, 24 years ago
*** empty log message ***
File size: 7.0 KB
Line 
1/*-----------------------------------------------------------------------------
2nmts.h -- NMT Slave, Node
3
4Copyright (c) 1994 JANZ Computer AG
5All Rights Reserved
6
7Created 94/10/11 by Soenke Hansen
8Version 1.17 of 99/04/26
9
10Various definitions: NMT Address type, NMT command specifiers, node states,
11macros for data indicated to the NMT User.
12Prototypes of functions defined in nmts.c.
13
14-----------------------------------------------------------------------------*/
15
16
17#ifndef nmts_DEFINED
18#define nmts_DEFINED
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24#include "defs.h"
25#include "msg.h"
26
27/* Components of service confirmation message */
28#define nmts_state u.m1.w[0] /* Node State */
29#define nmts_error u.m1.w[0] /* Node Error */
30#define nmts_errcode u.m1.w[1] /* error code ident. from BCAN_EVENT */
31#define nmts_errcode_e0 u.m1.w[2] /* BCAN_EVENT additional infos */
32#define nmts_errcode_e1 u.m1.w[3] /* BCAN_EVENT additional infos */
33#define nmts_errcode_e2 u.m1.w[4] /* BCAN_EVENT additional infos */
34#define nmts_errcode_e3 u.m1.w[5] /* BCAN_EVENT additional infos */
35#define nmts_keep u.m2.b[2] /* Node Prepare Protocol */
36
37/* Values of node error flag nmts_error */
38#define NE_LOCAL_OCCURRED 0x0003 /* local error occurred */
39#define NE_LOCAL_RESOLVED 0x0002 /* local error resolved */
40#define NE_REMOTE_OCCURRED 0x000c /* remote error occurred */
41#define NE_REMOTE_RESOLVED 0x0008 /* remote error resolved */
42
43/* Components of configuration message (spec == M_NMTS_*) */
44#define nmts_conf_subspec_lo u.m1.w[0] /* subspec low */
45#define nmts_conf_subspec_hi u.m1.w[1] /* subspec high */
46
47#define nmts_conf_errspec u.m1.w[2] /* error specifier */
48
49#define nmts_conf_fail_reason u.m1.w[2] /* failure reason */
50#define nmts_conf_appl_spec_a u.m1.w[3] /* application specific a */
51#define nmts_conf_appl_spec_b u.m1.w[4] /* application specific b */
52#define nmts_conf_appl_spec_c u.m1.w[5] /* application specific c */
53#define nmts_conf_appl_spec_d u.m1.w[6] /* application specific d */
54
55#define nmts_conf_verify_cs_a u.m1.w[2] /* verify checksum a */
56#define nmts_conf_verify_cs_b u.m1.w[3] /* verify checksum b */
57#define nmts_conf_verify_cs_c u.m1.w[4] /* verify checksum c */
58#define nmts_conf_verify_cs_d u.m1.w[5] /* verify checksum d */
59
60/* Type definition of NMT address */
61struct nmt_addr {
62 BYTE_t modname[8]; /* module name */
63 BYTE_t modid; /* module Id */
64};
65#if TYPEDEFS == 1
66typedef struct nmt_addr NmtAddr;
67#else
68#define NmtAddr struct nmt_addr
69#endif
70
71/* Copy an NMT Address */
72extern void NmtAddrCopy(
73 NmtAddr *, /* target address */
74 NmtAddr * /* source address */
75);
76
77/* The Node State */
78extern int NodeState;
79
80/* Node State values */
81#define DISCONNECTED 1
82#define CONNECTING 2
83#define PREPARING 3
84#define PREPARED 4
85#define OPERATIONAL 5
86#define PRE_OPERATIONAL 127
87
88/* The Node Id */
89extern BYTE_t NodeId;
90
91/* There are three CAL Objects associated with the NMT Slave */
92extern struct calo *NodeO; /* receives COBs with Id=0 */
93extern struct calo *NmtSlave; /* receives COBs with Id=2026 */
94extern struct calo *NodeErrO; /* receives guarding COBs, Node Events */
95
96/* Command specifiers in NMT Protocol with COB-ID=0 */
97#define NMT_CS_START 1 /* Start Node, COB-ID=0 */
98#define NMT_CS_STOP 2 /* Stop Node, COB-ID=0 */
99#define NMT_CS_DISCONNECT 3 /* Disconnect Node, COB-ID=0 */
100
101/* Command specifiers in NMT Protocol with COB-ID=0 relevant for CANopen */
102#define NMT_CS_ENTER_PRE_OPERATIONAL 128 /* enter pre-operational state */
103#define NMT_CS_RESET_NODE 129 /* Reset Node */
104#define NMT_CS_RESET_COMMUNICATION 130 /* Reset Communication */
105
106/* Command specifiers in NMT Protocol with COB-IDs=2025,2026 */
107#define NMT_CS_CONNECT_NAME 1 /* Node Connect, Module Name */
108#define NMT_CS_CONNECT_ID 4 /* Node Connect, Module Id */
109#define NMT_CS_CONNECT_ASSIGN 2 /* Node Connect, assign phase */
110#define NMT_CS_PREPARE 3 /* Node Prepare */
111#define NMT_CS_CONFIG 5 /* Configuration Service */
112#define NMT_CS_IDENTIFY 6 /* Node Identify */
113
114/* Nil command specifier */
115#define NMT_CS_NIL 0 /* not used by protocols */
116
117
118 /* timepoint of guard start: */
119#define START_AT_IDENTIFY 0x01 /* receiving of a identify msg */
120#define START_AT_GUARD_ID_RX 0x02 /* receiving on guard ID */
121
122#define NMTS_CONF_DOWNLOAD_ACK 0x01 /* mux: configure nmt slave to use */
123 /* acknowledge at configuration */
124 /* download */
125#define NMTS_CONF_DL_ACK_OFF 0x00 /* flag: use acknowledge */
126#define NMTS_CONF_DL_ACK_ON 0x01 /* flag: don't use acknowledge (dflt.)*/
127
128/* Subsequent command (sub-) specifiers in Nmt Configuration protocol */
129#define NMT_CONF_DIR_NO 0
130#define NMT_CONF_DIR_UPLOAD 1
131#define NMT_CONF_DIR_DOWNLOAD 2
132/* master commands */
133#define NMT_MCS_DL_SEGMENT_REQ 0
134#define NMT_MCS_INITIATE_DL_REQ 0x20
135#define NMT_MCS_INITIATE_UL_REQ 0x40
136#define NMT_MCS_UL_SEGMENT_REQ 0x60
137#define NMT_MCS_ABORT_CONF_REQ 0x80
138#define NMT_MCS_VERIFY_CONF_REQ 0xa0
139#define MCS_MASK 0xe0
140
141/* slave commands */
142#define NMT_SCS_UL_SEGMENT_RES 0
143#define NMT_SCS_DL_SEGMENT_RES 0x20
144#define NMT_SCS_INITIATE_UL_RES 0x40
145#define NMT_SCS_INITIATE_DL_RES 0x60
146#define NMT_SCS_ABORT_CONF_REQ 0x80
147#define NMT_SCS_VERIFY_CONF_RES 0xa0
148#define SCS_MASK 0xe0
149
150#define NMT_CONFIG_TOGGLE 0x10
151
152/* leaving place for 2 byte subspec, 4 byte whole */
153/* size, 1 byte dblk-size and 1 byte cs */
154#define NMT_CONFIG_HEAD_SIZE 8
155#define NMT_CONFIG_DBLK_SIZE MSGLEN - NMT_CONFIG_HEAD_SIZE
156#define NMT_CONFIG_MORE_SEG_INDICATOR 0x01 /* bit position in protocol */
157#define NMT_CONFIG_MORE_BYTES 0
158#define NMT_CONFIG_NOMORE_BYTES 1
159
160#define NMT_CONFIG_MAX_SEG_DATA 5
161#define NMT_CONFIG_SIZE_INDICATOR 0x01
162
163/* bitpositions in cs to user */
164#define NMT_MORE 1 /* more date will follow */
165#define NMT_SUCCESS 4 /* success indication */
166
167/* indication of success/fail of last nmt transfer */
168#define NMT_CONFIG_TRANSFER_FAILED 0
169#define NMT_CONFIG_TRANSFER_SUCCESS 1
170#define XFER_FAIL NMT_CONFIG_TRANSFER_FAILED
171#define XFER_SUCC NMT_CONFIG_TRANSFER_SUCCESS
172
173/* Allocate and initialize NMT Slave */
174extern void InitNmtS(
175 WORD_t , /* timeout interval */
176 void (*)() /* user handler indication/confirmation */
177);
178
179/* Deallocate NMT Slave */
180extern void DeleteNmtS(void);
181
182/* Create Node Service */
183extern void CreateNode(NmtAddr *, unsigned);
184
185/* Create CANopen Node Service */
186extern void CreateCOPNode(NmtAddr *, unsigned);
187
188/* Config CANopen Node Service */
189extern void ConfigCOPNode(WORD_t, int, BYTE_t);
190
191/* Delete Node Service */
192extern void DeleteNode(void);
193
194/* Identify Node Service */
195extern void IdentifyNode(void);
196
197/* Disconnect Node Service */
198extern void DisconnectNode(void);
199
200/* Connect Node Service */
201extern int ConnectNode(int, WORD_t, BYTE_t);
202
203/* Respond Prepare Remote Node Service */
204extern int PrepareRemoteNodeRes(unsigned);
205
206/* Configure Configuration download acknowledge */
207extern void NsConfigConfDownloadAck(WORD_t);
208
209/* nmt configuration download acknowledge from user */
210extern void NsConfAckUser(void);
211
212/* Request Abort Configuration */
213extern int NsAbortConfigTransferReq(int,int);
214
215/* Response Verify Configuration */
216extern int NsVerifyConfigTransferRes(BYTE_t, BYTE_t);
217
218#ifdef __cplusplus
219}
220#endif
221
222#endif /* !nmts_DEFINED */
Note: See TracBrowser for help on using the repository browser.