libpynq
(release 5EWC0-2023 version 0.2.6 of 2023-10-24 17:28)
Loading...
Searching...
No Matches
uio.c
Go to the documentation of this file.
1
/******************************************************************************
2
* Copyright (c) 2016, Xilinx, Inc.
3
* All rights reserved.
4
*
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions are met:
7
*
8
* 1. Redistributions of source code must retain the above copyright notice,
9
* this list of conditions and the following disclaimer.
10
*
11
* 2. Redistributions in binary form must reproduce the above copyright
12
* notice, this list of conditions and the following disclaimer in the
13
* documentation and/or other materials provided with the distribution.
14
*
15
* 3. Neither the name of the copyright holder nor the names of its
16
* contributors may be used to endorse or promote products derived from
17
* this software without specific prior written permission.
18
*
19
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26
* OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
*
31
*****************************************************************************/
32
/******************************************************************************
33
*
34
*
35
* @file uio.c
36
*
37
* Functions to interact with linux UIO. No safe checks here, so users must
38
* know what they are doing.
39
*
40
* <pre>
41
* MODIFICATION HISTORY:
42
*
43
* Ver Who Date Changes
44
* ----- --- ------- -----------------------------------------------
45
* 1.00a yrq 12/05/17 Initial release
46
*
47
* </pre>
48
*
49
*****************************************************************************/
50
51
#include "
uio.h
"
52
#include <fcntl.h>
53
#include <stdio.h>
54
#include <stdlib.h>
55
#include <string.h>
56
#include <sys/mman.h>
57
#include <unistd.h>
58
59
/******************************************************************************
60
* Function to set the UIO device.
61
* @param uio_index is the uio index in /dev list.
62
* @param length is the length of the MMAP in bytes.
63
* @return A pointer pointing to the MMAP of the UIO.
64
*****************************************************************************/
65
void
*
setUIO
(
int
uio_index,
int
length) {
66
char
uio_buf[32];
67
int
uio_fd;
68
void
*uio_ptr;
69
70
sprintf(uio_buf,
"/dev/uio%d"
, uio_index);
71
uio_fd = open(uio_buf, O_RDWR);
72
if
(uio_fd < 1) {
73
printf(
"Invalid UIO device file: %s.\n"
, uio_buf);
74
}
75
// mmap the UIO devices
76
uio_ptr = mmap(NULL, length, PROT_READ | PROT_WRITE, MAP_SHARED, uio_fd, 0);
77
return
uio_ptr;
78
}
79
80
/******************************************************************************
81
* Function to set the UIO device.
82
* @param uio_ptr is the uio pointer to be freed.
83
* @param length is the length of the MMAP.
84
* @return 0 on success; -1 otherwise.
85
*****************************************************************************/
86
int
unsetUIO
(
void
*uio_ptr,
int
length) {
return
munmap(uio_ptr, length); }
setUIO
void * setUIO(int uio_index, int length)
Definition
uio.c:65
unsetUIO
int unsetUIO(void *uio_ptr, int length)
Definition
uio.c:86
uio.h
library
uio.c
Generated on Tue Oct 24 2023 17:28:18 for libpynq by
1.9.8