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

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [sw/] [lib/] [source/] [neorv32_slink.c] - Blame information for rev 61

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 61 zero_gravi
// #################################################################################################
2
// # << NEORV32: neorv32_slink.c - Stream Link Interface HW Driver >>                              #
3
// # ********************************************************************************************* #
4
// # BSD 3-Clause License                                                                          #
5
// #                                                                                               #
6
// # Copyright (c) 2021, Stephan Nolting. All rights reserved.                                     #
7
// #                                                                                               #
8
// # Redistribution and use in source and binary forms, with or without modification, are          #
9
// # permitted provided that the following conditions are met:                                     #
10
// #                                                                                               #
11
// # 1. Redistributions of source code must retain the above copyright notice, this list of        #
12
// #    conditions and the following disclaimer.                                                   #
13
// #                                                                                               #
14
// # 2. Redistributions in binary form must reproduce the above copyright notice, this list of     #
15
// #    conditions and the following disclaimer in the documentation and/or other materials        #
16
// #    provided with the distribution.                                                            #
17
// #                                                                                               #
18
// # 3. Neither the name of the copyright holder nor the names of its contributors may be used to  #
19
// #    endorse or promote products derived from this software without specific prior written      #
20
// #    permission.                                                                                #
21
// #                                                                                               #
22
// # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS   #
23
// # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF               #
24
// # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE    #
25
// # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,     #
26
// # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE #
27
// # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED    #
28
// # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING     #
29
// # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED  #
30
// # OF THE POSSIBILITY OF SUCH DAMAGE.                                                            #
31
// # ********************************************************************************************* #
32
// # The NEORV32 Processor - https://github.com/stnolting/neorv32              (c) Stephan Nolting #
33
// #################################################################################################
34
 
35
 
36
/**********************************************************************//**
37
 * @file neorv32_slink.h
38
 * @author Stephan Nolting
39
 * @brief Stream Link Interface HW driver source file.
40
 **************************************************************************/
41
 
42
#include "neorv32.h"
43
#include "neorv32_slink.h"
44
 
45
 
46
/**********************************************************************//**
47
 * Check if stream link interface was synthesized.
48
 *
49
 * @return 0 if SLINK was not synthesized, 1 if SLINK is available.
50
 **************************************************************************/
51
int neorv32_slink_available(void) {
52
 
53
  if (SYSINFO_FEATURES & (1 << SYSINFO_FEATURES_IO_SLINK)) {
54
    return 1;
55
  }
56
  else {
57
    return 0;
58
  }
59
}
60
 
61
 
62
/**********************************************************************//**
63
 * Activate stream link interface.
64
 **************************************************************************/
65
void neorv32_slink_enable(void) {
66
 
67
  SLINK_CT |= (uint32_t)(1 << SLINK_CT_EN);
68
}
69
 
70
 
71
/**********************************************************************//**
72
 * Deactivate stream link interface.
73
 *
74
 * @note This will also clear all link FIFOs.
75
 **************************************************************************/
76
void neorv32_slink_disable(void) {
77
 
78
  SLINK_CT &= ~(uint32_t)(1 << SLINK_CT_EN);
79
}
80
 
81
 
82
/**********************************************************************//**
83
 * Get number of implemented RX links
84
 *
85
 * @return Number of implemented RX link (0..8).
86
 **************************************************************************/
87
int neorv32_slink_get_rx_num(void) {
88
 
89
  if (neorv32_slink_available()) {
90
    return (int)(((SLINK_CT >> SLINK_CT_RX_NUM0) & 0x07) + 1);
91
  }
92
  else {
93
    return 0;
94
  }
95
}
96
 
97
 
98
/**********************************************************************//**
99
 * Get number of implemented TX links
100
 *
101
 * @return Number of implemented TX link (0..8).
102
 **************************************************************************/
103
int neorv32_slink_get_tx_num(void) {
104
 
105
  if (neorv32_slink_available()) {
106
    return (int)(((SLINK_CT >> SLINK_CT_TX_NUM0) & 0x07) + 1);
107
  }
108
  else {
109
    return 0;
110
  }
111
}
112
 
113
 
114
/**********************************************************************//**
115
 * Get FIFO depth of RX links
116
 *
117
 * @return FIFO depth of RX links (1..32768); 0 if no RX links implemented.
118
 **************************************************************************/
119
int neorv32_slink_get_rx_depth(void) {
120
 
121
  if (neorv32_slink_available()) {
122
    uint32_t tmp = (SLINK_CT >> SLINK_CT_RX_FIFO_S0) & 0x0f;
123
    return (int)(1 << tmp);
124
  }
125
  else {
126
    return 0;
127
  }
128
}
129
 
130
 
131
/**********************************************************************//**
132
 * Get FIFO depth of TX links
133
 *
134
 * @return FIFO depth of TX links (1..32768); 0 if no TX links implemented.
135
 **************************************************************************/
136
int neorv32_slink_get_tx_depth(void) {
137
 
138
  if (neorv32_slink_available()) {
139
    uint32_t tmp = (SLINK_CT >> SLINK_CT_TX_FIFO_S0) & 0x0f;
140
    return (int)(1 << tmp);
141
  }
142
  else {
143
    return 0;
144
  }
145
}
146
 
147
 
148
/**********************************************************************//**
149
 * Write data to TX stream link 0 (non-blocking)
150
 *
151
 * @param[in] tx_data Data to send to link.
152
 * @return 0 if data was send, 1 if link is still busy.
153
 **************************************************************************/
154
int neorv32_slink_tx0_nonblocking(uint32_t tx_data) {
155
 
156
  if (SLINK_CT & (1 << SLINK_CT_TX0_FREE)) {
157
    SLINK_CH0 = tx_data;
158
    return 0;
159
  }
160
  return 1;
161
}
162
 
163
 
164
/**********************************************************************//**
165
 * Write data to TX stream link 1 (non-blocking)
166
 *
167
 * @param[in] tx_data Data to send to link.
168
 * @return 0 if data was send, 1 if link is still busy.
169
 **************************************************************************/
170
int neorv32_slink_tx1_nonblocking(uint32_t tx_data) {
171
 
172
  if (SLINK_CT & (1 << SLINK_CT_TX1_FREE)) {
173
    SLINK_CH1 = tx_data;
174
    return 0;
175
  }
176
  return 1;
177
}
178
 
179
 
180
/**********************************************************************//**
181
 * Write data to TX stream link 2 (non-blocking)
182
 *
183
 * @param[in] tx_data Data to send to link.
184
 * @return 0 if data was send, 1 if link is still busy.
185
 **************************************************************************/
186
int neorv32_slink_tx2_nonblocking(uint32_t tx_data) {
187
 
188
  if (SLINK_CT & (1 << SLINK_CT_TX2_FREE)) {
189
    SLINK_CH2 = tx_data;
190
    return 0;
191
  }
192
  return 1;
193
}
194
 
195
 
196
/**********************************************************************//**
197
 * Write data to TX stream link 3 (non-blocking)
198
 *
199
 * @param[in] tx_data Data to send to link.
200
 * @return 0 if data was send, 1 if link is still busy.
201
 **************************************************************************/
202
int neorv32_slink_tx3_nonblocking(uint32_t tx_data) {
203
 
204
  if (SLINK_CT & (1 << SLINK_CT_TX3_FREE)) {
205
    SLINK_CH3 = tx_data;
206
    return 0;
207
  }
208
  return 1;
209
}
210
 
211
 
212
/**********************************************************************//**
213
 * Write data to TX stream link 4 (non-blocking)
214
 *
215
 * @param[in] tx_data Data to send to link.
216
 * @return 0 if data was send, 1 if link is still busy.
217
 **************************************************************************/
218
int neorv32_slink_tx4_nonblocking(uint32_t tx_data) {
219
 
220
  if (SLINK_CT & (1 << SLINK_CT_TX4_FREE)) {
221
    SLINK_CH4 = tx_data;
222
    return 0;
223
  }
224
  return 1;
225
}
226
 
227
 
228
/**********************************************************************//**
229
 * Write data to TX stream link 5 (non-blocking)
230
 *
231
 * @param[in] tx_data Data to send to link.
232
 * @return 0 if data was send, 1 if link is still busy.
233
 **************************************************************************/
234
int neorv32_slink_tx5_nonblocking(uint32_t tx_data) {
235
 
236
  if (SLINK_CT & (1 << SLINK_CT_TX5_FREE)) {
237
    SLINK_CH5 = tx_data;
238
    return 0;
239
  }
240
  return 1;
241
}
242
 
243
 
244
/**********************************************************************//**
245
 * Write data to TX stream link 6 (non-blocking)
246
 *
247
 * @param[in] tx_data Data to send to link.
248
 * @return 0 if data was send, 1 if link is still busy.
249
 **************************************************************************/
250
int neorv32_slink_tx6_nonblocking(uint32_t tx_data) {
251
 
252
  if (SLINK_CT & (1 << SLINK_CT_TX6_FREE)) {
253
    SLINK_CH6 = tx_data;
254
    return 0;
255
  }
256
  return 1;
257
}
258
 
259
 
260
/**********************************************************************//**
261
 * Write data to TX stream link 7 (non-blocking)
262
 *
263
 * @param[in] tx_data Data to send to link.
264
 * @return 0 if data was send, 1 if link is still busy.
265
 **************************************************************************/
266
int neorv32_slink_tx7_nonblocking(uint32_t tx_data) {
267
 
268
  if (SLINK_CT & (1 << SLINK_CT_TX7_FREE)) {
269
    SLINK_CH7 = tx_data;
270
    return 0;
271
  }
272
  return 1;
273
}
274
 
275
 
276
/**********************************************************************//**
277
 * Read data from RX stream link 0 (non-blocking)
278
 *
279
 * @param[in,out] rx_data Pointer to return read data. Only valid if function return value = 0.
280
 * @return 0 if data was received, 1 if there is no data to fetch.
281
 **************************************************************************/
282
int neorv32_slink_rx0_nonblocking(uint32_t *rx_data) {
283
 
284
  if (SLINK_CT & (1 << SLINK_CT_RX0_AVAIL)) {
285
    *rx_data = SLINK_CH0;
286
    return 0;
287
  }
288
  return 1;
289
}
290
 
291
 
292
/**********************************************************************//**
293
 * Read data from RX stream link 1 (non-blocking)
294
 *
295
 * @param[in,out] rx_data Pointer to return read data. Only valid if function return value = 0.
296
 * @return 0 if data was received, 1 if there is no data to fetch.
297
 **************************************************************************/
298
int neorv32_slink_rx1_nonblocking(uint32_t *rx_data) {
299
 
300
  if (SLINK_CT & (1 << SLINK_CT_RX1_AVAIL)) {
301
    *rx_data = SLINK_CH1;
302
    return 0;
303
  }
304
  return 1;
305
}
306
 
307
 
308
/**********************************************************************//**
309
 * Read data from RX stream link 2 (non-blocking)
310
 *
311
 * @param[in,out] rx_data Pointer to return read data. Only valid if function return value = 0.
312
 * @return 0 if data was received, 1 if there is no data to fetch.
313
 **************************************************************************/
314
int neorv32_slink_rx2_nonblocking(uint32_t *rx_data) {
315
 
316
  if (SLINK_CT & (1 << SLINK_CT_RX2_AVAIL)) {
317
    *rx_data = SLINK_CH2;
318
    return 0;
319
  }
320
  return 1;
321
}
322
 
323
 
324
/**********************************************************************//**
325
 * Read data from RX stream link 3 (non-blocking)
326
 *
327
 * @param[in,out] rx_data Pointer to return read data. Only valid if function return value = 0.
328
 * @return 0 if data was received, 1 if there is no data to fetch.
329
 **************************************************************************/
330
int neorv32_slink_rx3_nonblocking(uint32_t *rx_data) {
331
 
332
  if (SLINK_CT & (1 << SLINK_CT_RX3_AVAIL)) {
333
    *rx_data = SLINK_CH3;
334
    return 0;
335
  }
336
  return 1;
337
}
338
 
339
 
340
/**********************************************************************//**
341
 * Read data from RX stream link 4 (non-blocking)
342
 *
343
 * @param[in,out] rx_data Pointer to return read data. Only valid if function return value = 0.
344
 * @return 0 if data was received, 1 if there is no data to fetch.
345
 **************************************************************************/
346
int neorv32_slink_rx4_nonblocking(uint32_t *rx_data) {
347
 
348
  if (SLINK_CT & (1 << SLINK_CT_RX4_AVAIL)) {
349
    *rx_data = SLINK_CH4;
350
    return 0;
351
  }
352
  return 1;
353
}
354
 
355
 
356
/**********************************************************************//**
357
 * Read data from RX stream link 5 (non-blocking)
358
 *
359
 * @param[in,out] rx_data Pointer to return read data. Only valid if function return value = 0.
360
 * @return 0 if data was received, 1 if there is no data to fetch.
361
 **************************************************************************/
362
int neorv32_slink_rx5_nonblocking(uint32_t *rx_data) {
363
 
364
  if (SLINK_CT & (1 << SLINK_CT_RX5_AVAIL)) {
365
    *rx_data = SLINK_CH5;
366
    return 0;
367
  }
368
  return 1;
369
}
370
 
371
 
372
/**********************************************************************//**
373
 * Read data from RX stream link 6 (non-blocking)
374
 *
375
 * @param[in,out] rx_data Pointer to return read data. Only valid if function return value = 0.
376
 * @return 0 if data was received, 1 if there is no data to fetch.
377
 **************************************************************************/
378
int neorv32_slink_rx6_nonblocking(uint32_t *rx_data) {
379
 
380
  if (SLINK_CT & (1 << SLINK_CT_RX6_AVAIL)) {
381
    *rx_data = SLINK_CH6;
382
    return 0;
383
  }
384
  return 1;
385
}
386
 
387
 
388
/**********************************************************************//**
389
 * Read data from RX stream link 7 (non-blocking)
390
 *
391
 * @param[in,out] rx_data Pointer to return read data. Only valid if function return value = 0.
392
 * @return 0 if data was received, 1 if there is no data to fetch.
393
 **************************************************************************/
394
int neorv32_slink_rx7_nonblocking(uint32_t *rx_data) {
395
 
396
  if (SLINK_CT & (1 << SLINK_CT_RX7_AVAIL)) {
397
    *rx_data = SLINK_CH7;
398
    return 0;
399
  }
400
  return 1;
401
}

powered by: WebSVN 2.1.0

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