OpenCores
URL https://opencores.org/ocsvn/rio/rio/trunk

Subversion Repositories rio

[/] [rio/] [trunk/] [sw/] [stack/] [riostack.h] - Blame information for rev 49

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 20 magro732
/*******************************************************************************
2
 *
3
 * RapidIO IP Library Core
4
 *
5
 * This file is part of the RapidIO IP library project
6
 * http://www.opencores.org/cores/rio/
7
 *
8
 * Description:
9 49 magro732
 * This file contains the API of the riostack.c module.
10 20 magro732
 *
11
 * To Do:
12
 * -
13
 *
14
 * Author(s):
15
 * - Magnus Rosenius, magro732@opencores.org
16
 *
17
 *******************************************************************************
18
 *
19 49 magro732
 * Copyright (C) 2015 Authors and OPENCORES.ORG
20 20 magro732
 *
21
 * This source file may be used and distributed without
22
 * restriction provided that this copyright statement is not
23
 * removed from the file and that any derivative work contains
24
 * the original copyright notice and the associated disclaimer.
25
 *
26
 * This source file is free software; you can redistribute it
27
 * and/or modify it under the terms of the GNU Lesser General
28
 * Public License as published by the Free Software Foundation;
29
 * either version 2.1 of the License, or (at your option) any
30
 * later version.
31
 *
32
 * This source is distributed in the hope that it will be
33
 * useful, but WITHOUT ANY WARRANTY; without even the implied
34
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
35
 * PURPOSE. See the GNU Lesser General Public License for more
36
 * details.
37
 *
38
 * You should have received a copy of the GNU Lesser General
39
 * Public License along with this source; if not, download it
40
 * from http://www.opencores.org/lgpl.shtml
41
 *
42
 *******************************************************************************/
43
 
44
/**
45
 * \file riostack.h
46
 */
47
 
48
#ifndef _RIOSTACK_H
49
#define _RIOSTACK_H
50
 
51
/*******************************************************************************
52
 * Includes
53
 *******************************************************************************/
54
 
55
#include "rioconfig.h"
56 49 magro732
#include "riopacket.h"
57 20 magro732
 
58
 
59
/*******************************************************************************
60
 * Global typedefs
61
 *******************************************************************************/
62
 
63
/* The size of a maximum sized RapidIO packet when stored in memory. */
64
/* One entry contains a header with the used buffer size. */
65 49 magro732
#define RIOSTACK_BUFFER_SIZE (RIOPACKET_SIZE_MAX+1u)
66 20 magro732
 
67
 
68
/* Define the different types of RioSymbols. */
69
typedef enum
70 49 magro732
  {
71
    RIOSTACK_SYMBOL_TYPE_IDLE, RIOSTACK_SYMBOL_TYPE_CONTROL,
72
    RIOSTACK_SYMBOL_TYPE_DATA, RIOSTACK_SYMBOL_TYPE_ERROR
73
  } RioSymbolType_t;
74 20 magro732
 
75
 
76
/*
77
 * RapidIO symbol definition.
78
 * Idle symbol: Sent when nothing else to send. Does not use the data field.
79
 * Control symbol: Sent when starting, ending and acknowleding a packet. Data
80
 * is right aligned, (Unused, C0, C1, C2) where C0 is transmitted/received first.
81
 * Data symbol: Sent to transfer packets. Uses the full data field, (D0, D1,
82
 * D2, D3) where D0 is transmitted/received first.
83
 * Error symbols are created when a symbols could not be created and the stack
84
 * should know about it.
85
 */
86
typedef struct
87
{
88 49 magro732
  RioSymbolType_t type;
89 20 magro732
  uint32_t data;
90 49 magro732
} RioSymbol_t;
91 20 magro732
 
92
 
93
/* Receiver states. */
94
typedef enum
95 49 magro732
  {
96
    RX_STATE_UNINITIALIZED, RX_STATE_PORT_INITIALIZED, RX_STATE_LINK_INITIALIZED,
97
    RX_STATE_INPUT_RETRY_STOPPED, RX_STATE_INPUT_ERROR_STOPPED
98
  } RioReceiverState_t;
99 20 magro732
 
100
 
101
/* Transmitter states. */
102
typedef enum
103 49 magro732
  {
104
    TX_STATE_UNINITIALIZED, TX_STATE_PORT_INITIALIZED, TX_STATE_LINK_INITIALIZED,
105
    TX_STATE_SEND_PACKET_RETRY, TX_STATE_SEND_PACKET_NOT_ACCEPTED, TX_STATE_SEND_LINK_RESPONSE,
106
    TX_STATE_OUTPUT_RETRY_STOPPED, TX_STATE_OUTPUT_ERROR_STOPPED
107
  } RioTransmitterState_t;
108 20 magro732
 
109
 
110
/* Queue definition. */
111
typedef struct
112
{
113
  uint8_t size;
114
  uint8_t available;
115
  uint8_t windowSize;
116
  uint8_t windowIndex;
117
  uint8_t frontIndex;
118
  uint8_t backIndex;
119
  uint32_t *buffer_p;
120
} Queue_t;
121
 
122
 
123
 
124
/* Define the structure to keep all the RapidIO stack variables. */
125 49 magro732
typedef struct
126 20 magro732
{
127
  /* Receiver variables. */
128 49 magro732
  RioReceiverState_t rxState;
129 20 magro732
  uint8_t rxCounter;
130
  uint16_t rxCrc;
131
  uint8_t rxStatusReceived;
132
  uint8_t rxAckId;
133
  uint8_t rxAckIdAcked;
134
  uint8_t rxErrorCause;
135
  Queue_t rxQueue;
136
 
137
  /* Transmitter variables. */
138 49 magro732
  RioTransmitterState_t txState;
139 20 magro732
  uint8_t txCounter;
140
  uint16_t txStatusCounter;
141
  uint8_t txFrameState;
142
  uint32_t txFrameTimeout[32];
143
  uint8_t txAckId;
144
  uint8_t txAckIdWindow;
145
  uint8_t txBufferStatus;
146
  Queue_t txQueue;
147
 
148
  /* Common protocol stack variables. */
149
  uint32_t portTime;
150
  uint32_t portTimeout;
151
 
152
  /** The number of successfully received packets. */
153
  uint32_t statusInboundPacketComplete;
154
 
155
  /** The number of retried received packets.
156
      This will happen if the receiver does not have resources available when an inbound packet is received. */
157
  uint32_t statusInboundPacketRetry;
158
 
159
  /** The number of received erronous control symbols.
160
      This may happen if the inbound link has a high bit-error-rate. */
161
  uint32_t statusInboundErrorControlCrc;
162
 
163
  /** The number of received packets with an unexpected ackId.
164
      This may happen if the inbound link has a high bit-error-rate. */
165
  uint32_t statusInboundErrorPacketAckId;
166
 
167
  /** The number of received packets with a checksum error.
168
      This may happen if the inbound link has a high bit-error-rate. */
169
  uint32_t statusInboundErrorPacketCrc;
170
 
171
  /** The number of received symbols that contains an illegals character.
172
      This may happen if the inbound link has a high bit-error-rate or if characters are missing in the
173
      inbound character stream. */
174
  uint32_t statusInboundErrorIllegalCharacter;
175
 
176
  /** The number of general errors encountered at the receiver that does not fit into the other categories.
177
      This happens if too short or too long packets are received. */
178
  uint32_t statusInboundErrorGeneral;
179
 
180
  /** The number of received packets that were discarded since they were unsupported by the stack.
181
      This will happen if an inbound packet contains information that cannot be accessed using the function API
182
      of the stack. */
183
  uint32_t statusInboundErrorPacketUnsupported;
184
 
185
  /** The number of successfully transmitted packets. */
186
  uint32_t statusOutboundPacketComplete;
187
 
188 49 magro732
  /** The maximum time between a completed outbound packet and the reception of its pcakcet-accepted control-symbol. */
189
  uint32_t statusOutboundLinkLatencyMax;
190
 
191 20 magro732
  /** The number of retried transmitted packets.
192
      This will happen if the receiver at the link-partner does not have resources available when an outbound
193
      packet is received. */
194
  uint32_t statusOutboundPacketRetry;
195
 
196
  /** The number of outbound packets that has had its retransmission timer expired.
197
      This happens if the latency of the system is too high or if a packet is corrupted due to a high
198
      bit-error-rate on the outbound link. */
199
  uint32_t statusOutboundErrorTimeout;
200
 
201
  /** The number of packet-accepted that was received that contained an unexpected ackId.
202
      This happens if the transmitter and the link-partner is out of synchronization, probably due
203
      to a software error. */
204
  uint32_t statusOutboundErrorPacketAccepted;
205
 
206
  /** The number of packet-retry that was received that contained an unexpected ackId.
207
      This happens if the transmitter and the link-partner is out of synchronization, probably due to
208
      a software error. */
209
  uint32_t statusOutboundErrorPacketRetry;
210
 
211
  /** The number of received link-requests.
212
      This happens if the link-partner transmitter has found an error and need to resynchronize itself
213
      to the receiver. */
214
  uint32_t statusPartnerLinkRequest;
215
 
216
  /** The number of received erronous control symbols at the link-partner receiver.
217
      This may happen if the outbound link has a high bit-error-rate. */
218
  uint32_t statusPartnerErrorControlCrc;
219
 
220
  /** The number of received packets with an unexpected ackId at the link-partner receiver.
221
      This may happen if the outbound link has a high bit-error-rate. */
222
  uint32_t statusPartnerErrorPacketAckId;
223
 
224
  /** The number of received packets with a checksum error at the link-partner receiver.
225
      This may happen if the outbound link has a high bit-error-rate. */
226
  uint32_t statusPartnerErrorPacketCrc;
227
 
228
  /** The number of received symbols that contains an illegals character at the link-parter receiver.
229
      This may happen if the outbound link has a high bit-error-rate or if characters are missing in the
230
      outbound character stream. */
231
  uint32_t statusPartnerErrorIllegalCharacter;
232
 
233
  /** The number of general errors encountered at the receiver that does not fit into the other categories.
234
      This happens depending on the link-partner implementation. */
235
  uint32_t statusPartnerErrorGeneral;
236
 
237
  /* Private user data. */
238 49 magro732
  void* private;
239 20 magro732
} RioStack_t;
240
 
241
 
242
/*******************************************************************************
243
 * Global function prototypes
244
 *******************************************************************************/
245
 
246
/**
247
 * \brief Open the RapidIO stack for operation.
248
 *
249
 * \param[in] stack Stack instance to operate on.
250
 * \param[in] private Pointer to an opaque data area containing private user data.
251
 * \param[in] rxPacketBufferSize Number of words to use as reception buffer. This
252
 *            argument specifies the size of rxPacketBuffer.
253
 * \param[in] rxPacketBuffer Pointer to buffer to store inbound packets in.
254
 * \param[in] txPacketBufferSize Number of words to use as transmission buffer. This
255
 *            argument specifies the size of txPacketBuffer.
256
 * \param[in] txPacketBuffer Pointer to buffer to store outbound packets in.
257
 *
258
 * This function initializes all internally used variables in the stack. The stack will
259
 * however not be operational until the transcoder has signalled that it is ready for
260 49 magro732
 * other symbols than idle. This is done using the function RIOSTACK_setPortStatus(). Once
261 20 magro732
 * this function has been called it is possible to get and set symbols and to issue
262
 * requests. The requests will be transmitted once the link initialization has
263
 * been completed.
264
 *
265
 * The rxPacket/txPacket arguments are word buffers that are used internally to store the
266
 * inbound and outbound packet queues.
267
 *
268
 * The config argument constants are used as identification when maintenance packets
269
 * are received and replied to. They should be set to make the device where the stack
270
 * is used easily identifiable on the net.
271
 *
272
 * \note The reception buffers can only support maximum 31 buffers.
273
 */
274 49 magro732
void RIOSTACK_open(RioStack_t *stack, void *private,
275
                   const uint32_t rxPacketBufferSize, uint32_t *rxPacketBuffer,
276
                   const uint32_t txPacketBufferSize, uint32_t *txPacketBuffer);
277 20 magro732
 
278
/*******************************************************************************************
279
 * Stack status functions.
280
 * Note that status counters are access directly in the stack-structure.
281
 *******************************************************************************************/
282
 
283
/**
284
 * \brief Get the status of the link.
285
 *
286
 * \param[in] stack The stack to operate on.
287 49 magro732
 * \return Returns the status of the link, zero if link is uninitialized and non-zero if
288
 * the link is initialized.
289 20 magro732
 *
290 49 magro732
 * This function indicates if the link is up and ready to relay packets.
291 20 magro732
 */
292 49 magro732
int RIOSTACK_getStatus(RioStack_t *stack);
293 20 magro732
 
294
/**
295 49 magro732
 * \brief Clear outbound queue.
296 20 magro732
 *
297
 * \param[in] stack The stack to operate on.
298
 *
299 49 magro732
 * This function clears all pending packet in the outbound queue.
300 20 magro732
 */
301 49 magro732
void RIOSTACK_clearOutboundQueue(RioStack_t *stack);
302 20 magro732
 
303
/**
304 49 magro732
 * \brief Get the number of pending outbound packets.
305 20 magro732
 *
306
 * \param[in] stack The stack to operate on.
307 49 magro732
 * \return Returns the number of pending outbound packets.
308 20 magro732
 *
309 49 magro732
 * This function checks the outbound queue and returns the number of packets
310
 * that are pending to be transmitted onto the link.
311 20 magro732
 */
312 49 magro732
uint8_t RIOSTACK_getOutboundQueueLength(RioStack_t *stack);
313 20 magro732
 
314
/**
315 49 magro732
 * \brief Get the number of available outbound packets.
316 20 magro732
 *
317
 * \param[in] stack The stack to operate on.
318 49 magro732
 * \return Returns the number of available outbound packets.
319 20 magro732
 *
320 49 magro732
 * This function checks the outbound queue and returns the number of packets
321
 * that are available before the queue is full.
322 20 magro732
 */
323 49 magro732
uint8_t RIOSTACK_getOutboundQueueAvailable(RioStack_t *stack);
324 20 magro732
 
325
/**
326 49 magro732
 * \brief Add a packet to the outbound queue.
327 20 magro732
 *
328
 * \param[in] stack The stack to operate on.
329 49 magro732
 * \param[in] packet The packet to send.
330 20 magro732
 *
331 49 magro732
 * This function sends a packet.
332 20 magro732
 *
333 49 magro732
 * \note The packet CRC is not checked. It must have been checked before it is used as
334
 * argument to this function.
335 20 magro732
 *
336 49 magro732
 * \note Call RIOSTACK_outboundQueueAvailable() before this function is called to make sure
337 20 magro732
 * the outbound queue has transmission buffers available.
338
 *
339 49 magro732
 * \note Use RIOSTACK_getStatus() to know when a packet is allowed to be transmitted.
340 20 magro732
 */
341 49 magro732
void RIOSTACK_setOutboundPacket(RioStack_t *stack, RioPacket_t *packet);
342 20 magro732
 
343
/**
344 49 magro732
 * \brief Clear inbound queue.
345 20 magro732
 *
346
 * \param[in] stack The stack to operate on.
347
 *
348 49 magro732
 * This function clears all pending packet in the inbound queue.
349 20 magro732
 */
350 49 magro732
void RIOSTACK_clearInboundQueue(RioStack_t *stack);
351 20 magro732
 
352
/**
353 49 magro732
 * \brief Get the number of pending inbound packets.
354 20 magro732
 *
355
 * \param[in] stack The stack to operate on.
356 49 magro732
 * \return Returns the number of pending inbound packets.
357 20 magro732
 *
358 49 magro732
 * This function checks the inbound queue and returns the number of packets
359
 * that has been received but not read by the user yet.
360 20 magro732
 */
361 49 magro732
uint8_t RIOSTACK_getInboundQueueLength(RioStack_t *stack);
362 20 magro732
 
363
/**
364 49 magro732
 * \brief Get the number of available inbound packets.
365 20 magro732
 *
366
 * \param[in] stack The stack to operate on.
367 49 magro732
 * \return Returns the number of available inbound packets.
368 20 magro732
 *
369 49 magro732
 * This function checks the inbound queue and returns the number of packets
370
 * that can be received without the queue is full.
371 20 magro732
 */
372 49 magro732
uint8_t RIOSTACK_getInboundQueueAvailable(RioStack_t *stack);
373 20 magro732
 
374
/**
375 49 magro732
 * \brief Get, remove and return a packet from the inbound queue.
376 20 magro732
 *
377
 * \param[in] stack The stack to operate on.
378 49 magro732
 * \param[in] packet The packet to receive to.
379 20 magro732
 *
380 49 magro732
 * This function moves a packet from the inbound packet queue to the location of the packet
381
 * in the argument list.
382 20 magro732
 */
383 49 magro732
void RIOSTACK_getInboundPacket(RioStack_t *stack, RioPacket_t *packet);
384 20 magro732
 
385
/*******************************************************************************************
386
 * Port functions (backend API towards physical device)
387
 *******************************************************************************************/
388
 
389
/**
390
 * \brief Set a port current time.
391
 *
392
 * \param[in] stack The stack to operate on.
393
 * \param[in] time The current time without unit.
394
 *
395
 * This function indicates to the stack the current time and this is used internally
396 49 magro732
 * to calculate when a packet timeout should be triggered. Use this together with RIOSTACK_setPortTimeout()
397 20 magro732
 * to allow for the stack to handle timeouts.
398
 */
399 49 magro732
void RIOSTACK_portSetTime( RioStack_t *stack, const uint32_t time);
400 20 magro732
 
401
/**
402
 * \brief Set a port timeout limit.
403
 *
404
 * \param[in] stack The stack to operate on.
405
 * \param[in] time The time out threshold.
406
 *
407
 * The time to wait for a response from the link partner. The unit of the
408 49 magro732
 * timeout value should be the same as the time used in RIOSTACK_setPortTime().
409 20 magro732
 *
410
 * This function is used to set a timeout threshold value and is used to know when
411
 * an acknowledge should have been received from a link partner.
412
 */
413 49 magro732
void RIOSTACK_portSetTimeout( RioStack_t *stack, const uint32_t time);
414 20 magro732
 
415
/**
416
 * \brief Set a ports status.
417
 *
418
 * \param[in] stack The stack to operate on.
419
 * \param[in] initialized The state of the port.
420
 *
421
 * If set to non-zero, the symbol encoder/decoder indicates to the stack that
422
 * it is successfully encoding/decoding symbol, i.e. synchronized to the link.
423
 *
424
 * This function indicates to the stack if the port that are encoding/decoding
425
 * symbols are ready to accept other symbols than idle-symbols. If the
426
 * encoding/decoding loses synchronization then this function should be called
427
 * with an argument equal to zero to force the stack to resynchronize the link.
428
 */
429 49 magro732
void RIOSTACK_portSetStatus( RioStack_t *stack, const uint8_t initialized );
430 20 magro732
 
431
/**
432
 * \brief Add a new symbol to the RapidIO stack.
433
 *
434
 * \param[in] stack The stack to operate on.
435
 * \param[in] s A symbol received from a port.
436
 *
437
 * This function is used to insert new data, read from a port, into the stack. The
438
 * symbols will be concatenated to form packets that can be accessed using other
439
 * functions.
440
 */
441 49 magro732
void RIOSTACK_portAddSymbol( RioStack_t *stack, const RioSymbol_t s );
442 20 magro732
 
443
/**
444
 * \brief Get the next symbol to transmit on a port.
445
 *
446
 * \param[in] stack The stack to operate on.
447
 * \return A symbol that should be sent on a port.
448
 *
449
 * This function is used to fetch new symbols to transmit on a port. Packets that
450
 * are inserted are split into symbols that are accessed with this function.
451
 */
452 49 magro732
RioSymbol_t RIOSTACK_portGetSymbol( RioStack_t *stack );
453 20 magro732
 
454 49 magro732
#endif /* _RIOSTACK_H */
455 20 magro732
 
456
/*************************** end of file **************************************/

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.