Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
Software for White Rabbit PTP Core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
32
Issues
32
List
Board
Labels
Milestones
Merge Requests
4
Merge Requests
4
CI / CD
CI / CD
Pipelines
Schedules
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
Software for White Rabbit PTP Core
Commits
6f97e9a2
Commit
6f97e9a2
authored
Mar 01, 2017
by
Federico Vaga
Committed by
Adam Wujek
Jun 20, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
liblinux: vuart implemntation
Signed-off-by:
Federico Vaga
<
federico.vaga@cern.ch
>
parent
e1527a28
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
7 deletions
+62
-7
Makefile
liblinux/Makefile
+1
-1
libwhiterabbit.h
liblinux/libwhiterabbit.h
+2
-2
vuart.c
liblinux/vuart.c
+59
-4
No files found.
liblinux/Makefile
View file @
6f97e9a2
...
...
@@ -6,7 +6,7 @@
LIB
=
libwhiterabbit.a
LOBJ
:=
vuart.o
CFLAGS
=
-Wall
-ggdb
-O2
-fPIC
-
I
./
CFLAGS
=
-Wall
-ggdb
-O2
-fPIC
-
Werror
-I
./
-I
../include
LDFLAGS
=
-L
.
-lwhiterabbit
%
:
%.c $(LIB)
...
...
liblinux/libwhiterabbit.h
View file @
6f97e9a2
...
...
@@ -7,8 +7,8 @@
struct
wr_vuart
{
int
fd
;
unsigned
int
offset
;
vo
id
*
vuart_mmap
;
void
*
mmap
;
vo
latile
struct
UART_WB
*
base
;
};
/**
...
...
liblinux/vuart.c
View file @
6f97e9a2
...
...
@@ -3,11 +3,18 @@
*/
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <hw/wb_uart.h>
#include "libwhiterabbit.h"
#define MAX_SIZE 0x100000
/**
* It opens a White Rabbit Virtual UART
* @parma[in] resource_path path to the resource file which can be mmapped
...
...
@@ -21,17 +28,44 @@
*/
struct
wr_vuart
*
wr_vuart_open
(
char
*
resource_path
,
unsigned
int
offset
)
{
struct
wr_vuart
*
vuart
;
vuart
=
malloc
(
sizeof
(
struct
wr_vuart
));
if
(
!
vuart
)
goto
out_alloc
;
vuart
->
fd
=
open
(
resource_path
,
O_RDWR
|
O_SYNC
);
if
(
vuart
->
fd
<=
0
)
goto
out_open
;
vuart
->
mmap
=
mmap
(
NULL
,
MAX_SIZE
&
~
(
getpagesize
()
-
1
),
PROT_READ
|
PROT_WRITE
,
MAP_SHARED
,
vuart
->
fd
,
0
);
if
((
long
)
vuart
->
mmap
==
-
1
)
goto
out_mmap
;
vuart
->
base
=
vuart
->
mmap
+
offset
;
return
vuart
;
out_mmap:
close
(
vuart
->
fd
);
out_open:
free
(
vuart
);
out_alloc:
return
NULL
;
}
/**
* It releases the resources allocated by wr_vuart_open(). The vuart will
* not be available anymore
* not be available anymore
and the token will be invalidated
* @param[in,out] vuart token from wr_vuart_open()
*/
void
wr_vuart_close
(
struct
wr_vuart
*
vuart
)
{
close
(
vuart
->
fd
);
free
(
vuart
);
}
...
...
@@ -45,7 +79,17 @@ void wr_vuart_close(struct wr_vuart *vuart)
*/
size_t
wr_vuart_read
(
struct
wr_vuart
*
vuart
,
char
*
buf
,
size_t
size
)
{
return
0
;
size_t
s
=
size
,
n_rx
=
0
;
int
c
;
while
(
s
--
)
{
c
=
wr_vuart_rx
(
vuart
);
if
(
c
<
0
)
return
n_rx
;
*
buf
++
=
c
;
n_rx
++
;
}
return
n_rx
;
}
...
...
@@ -59,7 +103,13 @@ size_t wr_vuart_read(struct wr_vuart *vuart, char *buf, size_t size)
*/
size_t
wr_vuart_write
(
struct
wr_vuart
*
vuart
,
char
*
buf
,
size_t
size
)
{
return
0
;
size_t
s
=
size
;
while
(
s
--
)
wr_vuart_tx
(
vuart
,
*
buf
++
);
return
size
;
}
...
...
@@ -71,7 +121,9 @@ size_t wr_vuart_write(struct wr_vuart *vuart, char *buf, size_t size)
*/
int
wr_vuart_rx
(
struct
wr_vuart
*
vuart
)
{
return
0
;
int
rdr
=
vuart
->
base
->
RDR
;
return
(
rdr
&
UART_HOST_RDR_RDY
)
?
UART_HOST_RDR_DATA_R
(
rdr
)
:
-
1
;
}
...
...
@@ -81,4 +133,7 @@ int wr_vuart_rx(struct wr_vuart *vuart)
*/
void
wr_vuart_tx
(
struct
wr_vuart
*
vuart
,
int
data
)
{
while
(
vuart
->
base
->
SR
&
UART_SR_RX_RDY
)
;
vuart
->
base
->
HOST_TDR
=
UART_HOST_TDR_DATA_W
(
data
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment