source: trunk/Cosy/incl/msg.h@ 14346

Last change on this file since 14346 was 731, checked in by tbretz, 24 years ago
*** empty log message ***
File size: 6.4 KB
Line 
1/*-----------------------------------------------------------------------------
2msg.h -- Messages and message queues
3
4Copyright (c) 1994 JANZ Computer AG
5All Rights Reserved
6
7Created 94/10/11 by Soenke Hansen
8Version 1.7 of 99/12/07
9
10Messages consist of a specifier for its contents, the (address of its)
11contents, and the relevant length of the contents. Messages are
12allocated from the heap with the maximum length of the contents specified.
13The relevant length is useful when transmitting the message outside
14the local address space.
15Messages can be linked to form message queues or lists.
16
17-----------------------------------------------------------------------------*/
18
19#ifndef msg_DEFINED
20#define msg_DEFINED
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26#include "defs.h"
27
28/* Mode or format type of a message */
29#define MMODE_LOCAL 0x01 /* internal compiler specific format */
30#define MMODE_TRANSFER 0x02 /* external format for transfer */
31
32/* Maximum length definitions */
33#define BCAN_LEN 8 /* max data length in CAN message */
34#define MB_LEN 16 /* max data length in bounded sized message */
35
36/* Message contents types */
37struct m_m1 { /* multiple purpose message (local format) */
38 WORD_t w[6];
39};
40struct m_m2 { /* for BCAN messages (local format) */
41 WORD_t r; /* request id */
42 WORD_t d; /* descriptor */
43 BYTE_t b[BCAN_LEN]; /* data bytes */
44};
45struct m_m3 { /* generic transfer data buffer */
46 BYTE_t len; /* length, number of relevant bytes */
47 BYTE_t gap; /* just to align component b[] */
48 BYTE_t b[MB_LEN]; /* bounded buffer */
49 BYTE_t *pb; /* allocated buffer if len > MB_LEN */
50};
51
52struct m_m4 { /* transfer data buffer for bulk purposes */
53 BYTE_t len; /* length, number of relevant bytes */
54 BYTE_t gap1; /* just to align component b[] */
55
56 BYTE_t available;
57 BYTE_t gap2; /* align */
58 WORD_t actByteCount; /* actual usage of bulk buffer */
59 LWORD_t actTime; /* last write time of this bulk buffer */
60 BYTE_t *pActData; /* pointer to actual write-data location */
61
62 BYTE_t gap3[4]; /* gap */
63 BYTE_t *pb; /* allocated buffer */
64};
65
66/* Message object definition */
67struct message {
68 BYTE_t spec; /* message contents specifier */
69 BYTE_t mode; /* mode (message format type) */
70 union { /* message contents */
71 WORD_t align;
72 /* mode == MMODE_LOCAL */
73 struct m_m1 m1;
74 struct m_m2 m2;
75 /* mode == MMODE_TRANSFER */
76 struct m_m3 m3;
77 /* mode == MMODE_TRANSFER for bulk/sniff buffer */
78 struct m_m4 m4;
79 } u;
80 struct message *next; /* next on list/queue */
81};
82
83#define NIL_MESSAGE (struct message *)0
84
85/* Message components for mode==MMODE_TRANSFER */
86#define mlen u.m3.len /* usage: m->mlen (if: struct message *m) */
87#define fdata u.m3.b /* pointer to fixed length data buffer */
88#define vdata u.m3.pb /* pointer to variable length data buffer */
89/* Pointer to beginning of data buffer */
90#define m_data(m) (((m)->mlen > MB_LEN) ? (m)->vdata : (m)->fdata)
91
92/* definitions for bulk buffer transfer */
93/* (always MMODE_TRANSFER, always variable length data buffer) */
94#define mBulkAvailable u.m4.available /* usage: m->mBulkAvailable */
95#define mBulkActByteCount u.m4.actByteCount /* usage: m->mBulkActByteCount */
96#define mBulkActTim u.m4.actTime /* usage: m->mBulkActTime */
97#define mBulkDataAddr u.m4.pActData /* usage: m->mBulkDataAddr */
98
99/* definitions for sniff buffer transfer */
100/* (always MMODE_TRANSFER, always variable length data buffer) */
101#define mSniffAvailable u.m4.available /* usage: m->mSniffAvailable */
102#define mSniffActByteCount u.m4.actByteCount /* usage: m->mSniffActByteCount */
103#define mSniffActTim u.m4.actTime /* usage: m->mSniffActTime */
104#define mSniffDataAddr u.m4.pActData /* usage: m->mSniffDataAddr */
105
106/* Components of a timer message (struct m_m1) */
107#define timer_period u.m1.w[0]
108#define timer_req u.m1.w[0]
109#define timer_tid u.m1.w[1]
110#define timer_tleft u.m1.w[2]
111
112/* Components of a filter message (struct m_m1) */
113#define afil_id u.m1.w[0]
114#define afil_idlow u.m1.w[0]
115#define afil_idhigh u.m1.w[1]
116
117/* Components of contents of struct m_m1 message */
118#define bcan_reset u.m1.w[0] /* !=0 if reset for M_BCAN_SET*req */
119#define bcan_acm u.m1.w[1] /* M_BCAN_SET_ACM_req */
120#define bcan_btr u.m1.w[1] /* M_BCAN_SET_BTR_req */
121#define bcan_evt u.m1.w[0] /* M_BCAN_EVENT_ind */
122#define bcan_evt_e0 u.m1.w[1] /* M_BCAN_EVENT_ind extended error */
123#define bcan_evt_e1 u.m1.w[2] /* M_BCAN_EVENT_ind extended error*/
124#define bcan_evt_e2 u.m1.w[3] /* M_BCAN_EVENT_ind extended error*/
125#define bcan_evt_e3 u.m1.w[4] /* M_BCAN_EVENT_ind extended error*/
126#define bcan_txreq u.m1.w[0] /* M_BCAN_TX_con */
127#define bcan_txcon u.m1.w[1] /* M_BCAN_TX_con */
128
129/* Components of a BCAN message (struct m_m2) */
130#define bcan_req u.m2.r
131#define bcan_desc u.m2.d
132#define bcan_data u.m2.b
133
134
135/* Message queues */
136struct mqueue {
137 struct message *head; /* first element on queue */
138 struct message *tail; /* last element on queue */
139 struct message *pos; /* current position in queue */
140};
141
142#define NIL_MQUEUE (struct mqueue *)0
143
144/* Get pointer to the first message in a queue */
145#define head_mqueue(q) ((q)->head)
146#define first_mqueue(q) ((q)->head)
147
148/* Remove the head from a non-empty queue */
149#define rmhead_mqueue(q) do { \
150 if ((q)->head != (q)->tail) (q)->head = (q)->head->next; \
151 else (q)->head = (q)->tail = NIL_MESSAGE; \
152 } while (0)
153
154
155/* Allocate a message */
156extern struct message *new_message _PARAMS((int, int));
157
158/* Deallocate a message */
159extern void delete_message _PARAMS((struct message *));
160
161/* Allocate a message queue */
162extern struct mqueue *new_mqueue _PARAMS((void));
163
164/* Deallocate a message queue. Any messages in the queue are also
165 deallocated. */
166extern void delete_mqueue _PARAMS((struct mqueue *));
167
168/* Remove the first message from a queue. The address of the message
169 is returned. */
170extern struct message * extract_mqueue _PARAMS((struct mqueue *));
171
172/* Append a message to a queue */
173extern void append_mqueue _PARAMS((struct mqueue *, struct message *));
174
175/* Rewind queue for looping through its elements */
176extern void rewind_mqueue _PARAMS((struct mqueue *));
177
178/* Get next message from queue */
179extern struct message *getnext_mqueue _PARAMS((struct mqueue *));
180
181/* Delete the successor of a message from a queue. The deleted (not
182 freed!) message is returned. */
183extern struct message *
184delsuc_mqueue _PARAMS((struct mqueue *, struct message *));
185
186/* Insert a message into the queue after a specified message. */
187extern void
188insert_mqueue _PARAMS((struct mqueue *, struct message *, struct message *));
189
190#ifdef __cplusplus
191}
192#endif
193
194#endif /* !msg_DEFINED */
Note: See TracBrowser for help on using the repository browser.