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

Subversion Repositories neorv32

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

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 62 zero_gravi
    return (int)((SLINK_CT >> SLINK_CT_RX_NUM0) & 0xf);
91 61 zero_gravi
  }
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 62 zero_gravi
    return (int)((SLINK_CT >> SLINK_CT_TX_NUM0) & 0xf);
107 61 zero_gravi
  }
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 62 zero_gravi
 * Check if RX link FIFO fill level is >= half-full
150
 *
151
 * @param[in] link_id Link id (0..7).
152
 * @return 1 if fill level is >= half-full.
153
 **************************************************************************/
154
int neorv32_slink_check_rx_half_full(int link_id) {
155
 
156
  const uint32_t mask = 1 << SLINK_STATUS_RX0_HALF;
157
 
158
  if (SLINK_STATUS & (mask << (link_id & 0x7))) {
159
    return 1;
160
  }
161
  else {
162
    return 0;
163
  }
164
}
165
 
166
 
167
/**********************************************************************//**
168
 * Check if TX link FIFO fill level is > half-full
169
 *
170
 * @param[in] link_id Link id (0..7).
171
 * @return 1 if fill level is > half-full.
172
 **************************************************************************/
173
int neorv32_slink_check_tx_half_full(int link_id) {
174
 
175
  const uint32_t mask = 1 << SLINK_STATUS_TX0_HALF;
176
 
177
  if (SLINK_STATUS & (mask << (link_id & 0x7))) {
178
    return 1;
179
  }
180
  else {
181
    return 0;
182
  }
183
}
184
 
185
 
186
/**********************************************************************//**
187 61 zero_gravi
 * Write data to TX stream link 0 (non-blocking)
188
 *
189
 * @param[in] tx_data Data to send to link.
190
 * @return 0 if data was send, 1 if link is still busy.
191
 **************************************************************************/
192
int neorv32_slink_tx0_nonblocking(uint32_t tx_data) {
193
 
194 62 zero_gravi
  if (SLINK_STATUS & (1 << SLINK_STATUS_TX0_FREE)) {
195 61 zero_gravi
    SLINK_CH0 = tx_data;
196
    return 0;
197
  }
198
  return 1;
199
}
200
 
201
 
202
/**********************************************************************//**
203
 * Write data to TX stream link 1 (non-blocking)
204
 *
205
 * @param[in] tx_data Data to send to link.
206
 * @return 0 if data was send, 1 if link is still busy.
207
 **************************************************************************/
208
int neorv32_slink_tx1_nonblocking(uint32_t tx_data) {
209
 
210 62 zero_gravi
  if (SLINK_STATUS & (1 << SLINK_STATUS_TX1_FREE)) {
211 61 zero_gravi
    SLINK_CH1 = tx_data;
212
    return 0;
213
  }
214
  return 1;
215
}
216
 
217
 
218
/**********************************************************************//**
219
 * Write data to TX stream link 2 (non-blocking)
220
 *
221
 * @param[in] tx_data Data to send to link.
222
 * @return 0 if data was send, 1 if link is still busy.
223
 **************************************************************************/
224
int neorv32_slink_tx2_nonblocking(uint32_t tx_data) {
225
 
226 62 zero_gravi
  if (SLINK_STATUS & (1 << SLINK_STATUS_TX2_FREE)) {
227 61 zero_gravi
    SLINK_CH2 = tx_data;
228
    return 0;
229
  }
230
  return 1;
231
}
232
 
233
 
234
/**********************************************************************//**
235
 * Write data to TX stream link 3 (non-blocking)
236
 *
237
 * @param[in] tx_data Data to send to link.
238
 * @return 0 if data was send, 1 if link is still busy.
239
 **************************************************************************/
240
int neorv32_slink_tx3_nonblocking(uint32_t tx_data) {
241
 
242 62 zero_gravi
  if (SLINK_STATUS & (1 << SLINK_STATUS_TX3_FREE)) {
243 61 zero_gravi
    SLINK_CH3 = tx_data;
244
    return 0;
245
  }
246
  return 1;
247
}
248
 
249
 
250
/**********************************************************************//**
251
 * Write data to TX stream link 4 (non-blocking)
252
 *
253
 * @param[in] tx_data Data to send to link.
254
 * @return 0 if data was send, 1 if link is still busy.
255
 **************************************************************************/
256
int neorv32_slink_tx4_nonblocking(uint32_t tx_data) {
257
 
258 62 zero_gravi
  if (SLINK_STATUS & (1 << SLINK_STATUS_TX4_FREE)) {
259 61 zero_gravi
    SLINK_CH4 = tx_data;
260
    return 0;
261
  }
262
  return 1;
263
}
264
 
265
 
266
/**********************************************************************//**
267
 * Write data to TX stream link 5 (non-blocking)
268
 *
269
 * @param[in] tx_data Data to send to link.
270
 * @return 0 if data was send, 1 if link is still busy.
271
 **************************************************************************/
272
int neorv32_slink_tx5_nonblocking(uint32_t tx_data) {
273
 
274 62 zero_gravi
  if (SLINK_STATUS & (1 << SLINK_STATUS_TX5_FREE)) {
275 61 zero_gravi
    SLINK_CH5 = tx_data;
276
    return 0;
277
  }
278
  return 1;
279
}
280
 
281
 
282
/**********************************************************************//**
283
 * Write data to TX stream link 6 (non-blocking)
284
 *
285
 * @param[in] tx_data Data to send to link.
286
 * @return 0 if data was send, 1 if link is still busy.
287
 **************************************************************************/
288
int neorv32_slink_tx6_nonblocking(uint32_t tx_data) {
289
 
290 62 zero_gravi
  if (SLINK_STATUS & (1 << SLINK_STATUS_TX6_FREE)) {
291 61 zero_gravi
    SLINK_CH6 = tx_data;
292
    return 0;
293
  }
294
  return 1;
295
}
296
 
297
 
298
/**********************************************************************//**
299
 * Write data to TX stream link 7 (non-blocking)
300
 *
301
 * @param[in] tx_data Data to send to link.
302
 * @return 0 if data was send, 1 if link is still busy.
303
 **************************************************************************/
304
int neorv32_slink_tx7_nonblocking(uint32_t tx_data) {
305
 
306 62 zero_gravi
  if (SLINK_STATUS & (1 << SLINK_STATUS_TX7_FREE)) {
307 61 zero_gravi
    SLINK_CH7 = tx_data;
308
    return 0;
309
  }
310
  return 1;
311
}
312
 
313
 
314
/**********************************************************************//**
315
 * Read data from RX stream link 0 (non-blocking)
316
 *
317
 * @param[in,out] rx_data Pointer to return read data. Only valid if function return value = 0.
318
 * @return 0 if data was received, 1 if there is no data to fetch.
319
 **************************************************************************/
320
int neorv32_slink_rx0_nonblocking(uint32_t *rx_data) {
321
 
322 62 zero_gravi
  if (SLINK_STATUS & (1 << SLINK_STATUS_RX0_AVAIL)) {
323 61 zero_gravi
    *rx_data = SLINK_CH0;
324
    return 0;
325
  }
326
  return 1;
327
}
328
 
329
 
330
/**********************************************************************//**
331
 * Read data from RX stream link 1 (non-blocking)
332
 *
333
 * @param[in,out] rx_data Pointer to return read data. Only valid if function return value = 0.
334
 * @return 0 if data was received, 1 if there is no data to fetch.
335
 **************************************************************************/
336
int neorv32_slink_rx1_nonblocking(uint32_t *rx_data) {
337
 
338 62 zero_gravi
  if (SLINK_STATUS & (1 << SLINK_STATUS_RX1_AVAIL)) {
339 61 zero_gravi
    *rx_data = SLINK_CH1;
340
    return 0;
341
  }
342
  return 1;
343
}
344
 
345
 
346
/**********************************************************************//**
347
 * Read data from RX stream link 2 (non-blocking)
348
 *
349
 * @param[in,out] rx_data Pointer to return read data. Only valid if function return value = 0.
350
 * @return 0 if data was received, 1 if there is no data to fetch.
351
 **************************************************************************/
352
int neorv32_slink_rx2_nonblocking(uint32_t *rx_data) {
353
 
354 62 zero_gravi
  if (SLINK_STATUS & (1 << SLINK_STATUS_RX2_AVAIL)) {
355 61 zero_gravi
    *rx_data = SLINK_CH2;
356
    return 0;
357
  }
358
  return 1;
359
}
360
 
361
 
362
/**********************************************************************//**
363
 * Read data from RX stream link 3 (non-blocking)
364
 *
365
 * @param[in,out] rx_data Pointer to return read data. Only valid if function return value = 0.
366
 * @return 0 if data was received, 1 if there is no data to fetch.
367
 **************************************************************************/
368
int neorv32_slink_rx3_nonblocking(uint32_t *rx_data) {
369
 
370 62 zero_gravi
  if (SLINK_STATUS & (1 << SLINK_STATUS_RX3_AVAIL)) {
371 61 zero_gravi
    *rx_data = SLINK_CH3;
372
    return 0;
373
  }
374
  return 1;
375
}
376
 
377
 
378
/**********************************************************************//**
379
 * Read data from RX stream link 4 (non-blocking)
380
 *
381
 * @param[in,out] rx_data Pointer to return read data. Only valid if function return value = 0.
382
 * @return 0 if data was received, 1 if there is no data to fetch.
383
 **************************************************************************/
384
int neorv32_slink_rx4_nonblocking(uint32_t *rx_data) {
385
 
386 62 zero_gravi
  if (SLINK_STATUS & (1 << SLINK_STATUS_RX4_AVAIL)) {
387 61 zero_gravi
    *rx_data = SLINK_CH4;
388
    return 0;
389
  }
390
  return 1;
391
}
392
 
393
 
394
/**********************************************************************//**
395
 * Read data from RX stream link 5 (non-blocking)
396
 *
397
 * @param[in,out] rx_data Pointer to return read data. Only valid if function return value = 0.
398
 * @return 0 if data was received, 1 if there is no data to fetch.
399
 **************************************************************************/
400
int neorv32_slink_rx5_nonblocking(uint32_t *rx_data) {
401
 
402 62 zero_gravi
  if (SLINK_STATUS & (1 << SLINK_STATUS_RX5_AVAIL)) {
403 61 zero_gravi
    *rx_data = SLINK_CH5;
404
    return 0;
405
  }
406
  return 1;
407
}
408
 
409
 
410
/**********************************************************************//**
411
 * Read data from RX stream link 6 (non-blocking)
412
 *
413
 * @param[in,out] rx_data Pointer to return read data. Only valid if function return value = 0.
414
 * @return 0 if data was received, 1 if there is no data to fetch.
415
 **************************************************************************/
416
int neorv32_slink_rx6_nonblocking(uint32_t *rx_data) {
417
 
418 62 zero_gravi
  if (SLINK_STATUS & (1 << SLINK_STATUS_RX6_AVAIL)) {
419 61 zero_gravi
    *rx_data = SLINK_CH6;
420
    return 0;
421
  }
422
  return 1;
423
}
424
 
425
 
426
/**********************************************************************//**
427
 * Read data from RX stream link 7 (non-blocking)
428
 *
429
 * @param[in,out] rx_data Pointer to return read data. Only valid if function return value = 0.
430
 * @return 0 if data was received, 1 if there is no data to fetch.
431
 **************************************************************************/
432
int neorv32_slink_rx7_nonblocking(uint32_t *rx_data) {
433
 
434 62 zero_gravi
  if (SLINK_STATUS & (1 << SLINK_STATUS_RX7_AVAIL)) {
435 61 zero_gravi
    *rx_data = SLINK_CH7;
436
    return 0;
437
  }
438
  return 1;
439
}

powered by: WebSVN 2.1.0

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