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
7
Merge Requests
7
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
d1e54838
Commit
d1e54838
authored
Nov 01, 2013
by
Grzegorz Daniluk
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'w1-eb'
parents
05a0472d
52fb757e
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
255 additions
and
465 deletions
+255
-465
Makefile
Makefile
+1
-1
w1-eeprom.c
dev/w1-eeprom.c
+9
-1
w1-hw.c
dev/w1-hw.c
+1
-1
w1.c
dev/w1.c
+12
-2
inttypes.h
include/std/inttypes.h
+0
-0
stdint.h
include/std/stdint.h
+0
-0
.gitignore
tools/.gitignore
+2
-0
Makefile
tools/Makefile
+19
-6
eb-w1-write.c
tools/eb-w1-write.c
+134
-0
eb-w1.c
tools/eb-w1.c
+75
-0
Makefile
tools/w1-host/Makefile
+0
-8
w1-eeprom.c
tools/w1-host/w1-eeprom.c
+0
-137
w1-temp.c
tools/w1-host/w1-temp.c
+0
-77
w1.c
tools/w1-host/w1.c
+0
-144
w1.h
tools/w1-host/w1.h
+0
-86
wrpc-w1-read.c
tools/wrpc-w1-read.c
+1
-1
wrpc-w1-write.c
tools/wrpc-w1-write.c
+1
-1
No files found.
Makefile
View file @
d1e54838
...
...
@@ -27,7 +27,7 @@ obj-y += wrc_main.o
$(CC)
-include
$(AUTOCONF)
-E
-P
$*
.ld.S
-o
$@
cflags-y
=
-ffreestanding
-include
$(AUTOCONF)
-Iinclude
-I
.
-Isoftpll
cflags-y
=
-ffreestanding
-include
$(AUTOCONF)
-Iinclude
/std
-Iinclude
-I
.
-Isoftpll
cflags-y
+=
-I
$(CURDIR)
/pp_printf
cflags-$(CONFIG_PTP_NOPOSIX)
+=
\
...
...
dev/w1-eeprom.c
View file @
d1e54838
...
...
@@ -4,9 +4,14 @@
*/
#include <stdlib.h>
#include <string.h>
#include <w1.h>
#ifndef EXTERNAL_W1
#include <wrc.h>
#include <shell.h>
#include <w1.h>
#else
#include <unistd.h>
#endif
#define LSB_ADDR(X) ((X) & 0xFF)
#define MSB_ADDR(X) (((X) & 0xFF00)>>8)
...
...
@@ -138,6 +143,7 @@ int w1_write_eeprom_bus(struct w1_bus *bus,
return
-
1
;
}
#ifndef EXTERNAL_W1
#define BLEN 32
/* A shell command, for testing write: "w1w <offset> <byte> [<byte> ...]" */
...
...
@@ -190,3 +196,5 @@ DEFINE_WRC_COMMAND(w1r) = {
.
name
=
"w1r"
,
.
exec
=
cmd_w1_r
,
};
#endif
dev/w1-hw.c
View file @
d1e54838
...
...
@@ -6,9 +6,9 @@
*
* Released according to the GNU GPL, version 2 or any later version.
*/
#include <wrc.h>
#include <string.h>
#include <w1.h>
#include <board.h>
#include <hw/sockit_owm_regs.h>
static
inline
uint32_t
__wait_cycle
(
void
*
base
)
...
...
dev/w1.c
View file @
d1e54838
...
...
@@ -2,11 +2,17 @@
* Onewire generic interface
* Alessandro Rubini, 2013 GNU GPL2 or later
*/
#include <wrc.h>
#include <string.h>
#include <shell.h>
#include <w1.h>
#ifndef EXTERNAL_W1
#include <wrc.h>
#include <shell.h>
#else
#include <unistd.h>
#define pp_printf(...) do {} while (0)
#endif
static
const
struct
w1_ops
*
ops
=
&
wrpc_w1_ops
;
/* local shorter name */
void
w1_write_byte
(
struct
w1_bus
*
bus
,
int
byte
)
...
...
@@ -146,6 +152,8 @@ void w1_match_rom(struct w1_dev *dev)
}
}
#ifndef EXTERNAL_W1
/* A shell command, for checking */
static
int
cmd_w1
(
const
char
*
args
[])
{
...
...
@@ -171,3 +179,5 @@ DEFINE_WRC_COMMAND(w1) = {
.
name
=
"w1"
,
.
exec
=
cmd_w1
,
};
#endif
include/inttypes.h
→
include/
std/
inttypes.h
View file @
d1e54838
File moved
include/stdint.h
→
include/std
/std
int.h
View file @
d1e54838
File moved
tools/.gitignore
View file @
d1e54838
...
...
@@ -4,3 +4,5 @@ genrammif
wrpc-uart-sw
wrpc-w1-read
wrpc-w1-write
eb-w1-write
sdb-wrpc.bin
tools/Makefile
View file @
d1e54838
CFLAGS
=
-Wall
-ggdb
EB
?=
no
SDBFS
?=
no
CFLAGS
=
-Wall
-ggdb
-DEXTERNAL_W1
-I
../include
LDFLAGS
=
-lutil
ALL
=
genraminit genramvhd genrammif wrpc-uart-sw
ALL
+=
wrpc-w1-read wrpc-w1-write
ifneq
($(EB),no)
ALL
+=
eb-w1-write
endif
ifneq
($(SDBFS),no)
ALL
+=
sdb-wrpc.bin
endif
AS
=
as
LD
=
ld
CC
=
gcc
...
...
@@ -18,14 +28,17 @@ all: $(ALL)
%
:
%.c
$(CC)
$(CFLAGS)
$<
$(LDFLAGS)
-o
$@
wrpc-w1-read
:
wrpc-w1-read.c
w1-host/libw1.a
wrpc-w1-read
:
wrpc-w1-read.c
../dev/w1.c ../dev/w1-eeprom.c ../dev/w1-hw.c
$(CC)
$(CFLAGS)
$^
$(LDFLAGS)
-o
$@
wrpc-w1-write
:
wrpc-w1-write.c
w1-host/libw1.a
wrpc-w1-write
:
wrpc-w1-write.c
../dev/w1.c ../dev/w1-eeprom.c ../dev/w1-hw.c
$(CC)
$(CFLAGS)
$^
$(LDFLAGS)
-o
$@
w1-host/libw1.a
:
$(MAKE)
-C
w1-host
eb-w1-write
:
eb-w1-write.c ../dev/w1.c ../dev/w1-eeprom.c eb-w1.c
$(CC)
$(CFLAGS)
-I
$(EB)
$^
$(LDFLAGS)
-o
$@
-L
$(EB)
-letherbone
sdb-wrpc.bin
:
sdbfs
$(SDBFS)
/gensdbfs
$<
$@
clean
:
rm
-f
$(ALL)
*
.o
*
~
$(MAKE)
-C
w1-host clean
tools/eb-w1-write.c
0 → 100644
View file @
d1e54838
/*
* This work is part of the White Rabbit project
*
* Copyright (C) 2013 CERN (www.cern.ch)
* Author: Wesley W. Terpstra <w.terpstra@gsi.de>
* Author: Alessandro Rubini <rubini@gnudd.com>
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
*
* Released according to the GNU GPL, version 2 or any later version.
*/
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <etherbone.h>
#include <w1.h>
#define W1_VENDOR 0xce42
/* CERN */
#define W1_DEVICE 0x779c5443
/* WR-Periph-1Wire */
char
*
prgname
;
int
verbose
;
eb_address_t
BASE_ONEWIRE
;
eb_device_t
device
;
extern
struct
w1_bus
wrpc_w1_bus
;
static
int
write_w1
(
int
w1base
,
int
w1len
)
{
struct
w1_dev
*
d
;
uint8_t
buf
[
w1len
];
int
i
;
w1_scan_bus
(
&
wrpc_w1_bus
);
if
(
verbose
)
{
/* code borrowed from dev/w1.c -- "w1" shell command */
for
(
i
=
0
;
i
<
W1_MAX_DEVICES
;
i
++
)
{
d
=
wrpc_w1_bus
.
devs
+
i
;
if
(
d
->
rom
)
fprintf
(
stderr
,
"device %i: %08x%08x
\n
"
,
i
,
(
int
)(
d
->
rom
>>
32
),
(
int
)
d
->
rom
);
}
}
if
(
verbose
)
{
fprintf
(
stderr
,
"Writing device offset %i (0x%x), len %i
\n
"
,
w1base
,
w1base
,
w1len
);
}
if
(
isatty
(
fileno
(
stdin
)))
fprintf
(
stderr
,
"Reading from stdin, please type the data
\n
"
);
i
=
fread
(
buf
,
1
,
w1len
,
stdin
);
if
(
i
!=
w1len
)
{
fprintf
(
stderr
,
"%s: read error (%i, expeted %i)
\n
"
,
prgname
,
i
,
w1len
);
return
1
;
}
i
=
w1_write_eeprom_bus
(
&
wrpc_w1_bus
,
w1base
,
buf
,
w1len
);
if
(
i
!=
w1len
)
{
fprintf
(
stderr
,
"Tried to write %i bytes, retval %i
\n
"
,
w1len
,
i
);
return
1
;
}
return
0
;
}
/*
* What follows is mostly generic, should be librarized in a way
*/
static
int
help
(
void
)
{
fprintf
(
stderr
,
"%s: Use:
\"
%s [-v] <device> <addr> <len>
\n
"
,
prgname
,
prgname
);
return
1
;
}
static
void
die
(
const
char
*
reason
,
eb_status_t
status
)
{
fprintf
(
stderr
,
"%s: %s: %s
\n
"
,
prgname
,
reason
,
eb_status
(
status
));
exit
(
1
);
}
int
main
(
int
argc
,
char
**
argv
)
{
int
c
;
eb_status_t
status
;
eb_socket_t
socket
;
struct
sdb_device
sdb
;
prgname
=
argv
[
0
];
while
((
c
=
getopt
(
argc
,
argv
,
"v"
))
!=
-
1
)
{
switch
(
c
)
{
case
'v'
:
verbose
++
;
break
;
default:
exit
(
help
());
}
}
if
(
optind
!=
argc
-
3
)
exit
(
help
());
if
((
status
=
eb_socket_open
(
EB_ABI_CODE
,
0
,
EB_DATAX
|
EB_ADDRX
,
&
socket
))
!=
EB_OK
)
die
(
"eb_socket_open"
,
status
);
if
((
status
=
eb_device_open
(
socket
,
argv
[
optind
],
EB_DATAX
|
EB_ADDRX
,
3
,
&
device
))
!=
EB_OK
)
die
(
argv
[
optind
],
status
);
/* Find the W1 device */
c
=
1
;
if
((
status
=
eb_sdb_find_by_identity
(
device
,
W1_VENDOR
,
W1_DEVICE
,
&
sdb
,
&
c
))
!=
EB_OK
)
die
(
"eb_sdb_find_by_identity"
,
status
);
if
(
c
!=
1
)
{
fprintf
(
stderr
,
"Found %d 1wire controllers on that device
\n
"
,
c
);
exit
(
1
);
}
BASE_ONEWIRE
=
sdb
.
sdb_component
.
addr_first
;
return
write_w1
(
atoi
(
argv
[
optind
+
1
]),
atoi
(
argv
[
optind
+
2
]));
}
tools/
w1-host/w1-hw
.c
→
tools/
eb-w1
.c
View file @
d1e54838
...
...
@@ -2,34 +2,41 @@
* This work is part of the White Rabbit project
*
* Copyright (C) 2013 CERN (www.cern.ch)
* Author: Alessandro Rubini <rubini@gnudd.com>
* Author: Wesley W. Terpstra <w.terpstra@gsi.de>
* Alessandro Rubini <rubini@gnudd.com>
*
* Released according to the GNU GPL, version 2 or any later version.
*/
#include <string.h>
#include "w1.h"
#include "../../include/hw/sockit_owm_regs.h"
#include <etherbone.h>
#include <w1.h>
#include <hw/sockit_owm_regs.h>
extern
void
*
BASE_ONEWIRE
;
extern
eb_address_t
BASE_ONEWIRE
;
extern
eb_device_t
device
;
static
inline
uint32_t
__wait_cycle
(
void
*
bas
e
)
static
inline
uint32_t
__wait_cycle
(
eb_device_t
devic
e
)
{
uint32_t
reg
;
eb_data_t
data
;
do
{
eb_device_read
(
device
,
BASE_ONEWIRE
,
EB_DATA32
|
EB_BIG_ENDIAN
,
&
data
,
0
,
0
);
}
while
(
data
&
SOCKIT_OWM_CTL_CYC_MSK
);
while
((
reg
=
IORD_SOCKIT_OWM_CTL
(
base
))
&
SOCKIT_OWM_CTL_CYC_MSK
)
;
return
reg
;
return
data
;
}
static
int
w1_reset
(
struct
w1_bus
*
bus
)
{
int
portnum
=
bus
->
detail
;
uint32_t
reg
;
IOWR_SOCKIT_OWM_CTL
(
BASE_ONEWIRE
,
(
portnum
<<
SOCKIT_OWM_CTL_SEL_OFST
)
eb_data_t
data
=
(
portnum
<<
SOCKIT_OWM_CTL_SEL_OFST
)
|
(
SOCKIT_OWM_CTL_CYC_MSK
)
|
(
SOCKIT_OWM_CTL_RST_MSK
));
reg
=
__wait_cycle
(
BASE_ONEWIRE
);
|
(
SOCKIT_OWM_CTL_RST_MSK
);
eb_device_write
(
device
,
BASE_ONEWIRE
,
EB_DATA32
|
EB_BIG_ENDIAN
,
data
,
0
,
0
);
reg
=
__wait_cycle
(
device
);
/* return presence-detect pulse (1 if true) */
return
(
reg
&
SOCKIT_OWM_CTL_DAT_MSK
)
?
0
:
1
;
}
...
...
@@ -39,21 +46,24 @@ static int w1_read_bit(struct w1_bus *bus)
int
portnum
=
bus
->
detail
;
uint32_t
reg
;
IOWR_SOCKIT_OWM_CTL
(
BASE_ONEWIRE
,
(
portnum
<<
SOCKIT_OWM_CTL_SEL_OFST
)
eb_data_t
data
=
(
portnum
<<
SOCKIT_OWM_CTL_SEL_OFST
)
|
(
SOCKIT_OWM_CTL_CYC_MSK
)
|
(
SOCKIT_OWM_CTL_DAT_MSK
));
reg
=
__wait_cycle
(
BASE_ONEWIRE
);
|
(
SOCKIT_OWM_CTL_DAT_MSK
);
eb_device_write
(
device
,
BASE_ONEWIRE
,
EB_DATA32
|
EB_BIG_ENDIAN
,
data
,
0
,
0
);
reg
=
__wait_cycle
(
device
);
return
(
reg
&
SOCKIT_OWM_CTL_DAT_MSK
)
?
1
:
0
;
}
static
void
w1_write_bit
(
struct
w1_bus
*
bus
,
int
bit
)
{
int
portnum
=
bus
->
detail
;
IOWR_SOCKIT_OWM_CTL
(
BASE_ONEWIRE
,
(
portnum
<<
SOCKIT_OWM_CTL_SEL_OFST
)
eb_data_t
data
=
(
portnum
<<
SOCKIT_OWM_CTL_SEL_OFST
)
|
(
SOCKIT_OWM_CTL_CYC_MSK
)
|
(
bit
?
SOCKIT_OWM_CTL_DAT_MSK
:
0
));
__wait_cycle
(
BASE_ONEWIRE
);
|
(
bit
?
SOCKIT_OWM_CTL_DAT_MSK
:
0
);
eb_device_write
(
device
,
BASE_ONEWIRE
,
EB_DATA32
|
EB_BIG_ENDIAN
,
data
,
0
,
0
);
__wait_cycle
(
device
);
}
struct
w1_ops
wrpc_w1_ops
=
{
...
...
tools/w1-host/Makefile
deleted
100644 → 0
View file @
05a0472d
all
:
libw1.a
libw1.a
:
w1.o w1-eeprom.o w1-hw.o w1-temp.o
ar r
$@
$^
clean
:
rm
-f
*
.o
*
.a
*
~
\ No newline at end of file
tools/w1-host/w1-eeprom.c
deleted
100644 → 0
View file @
05a0472d
/*
* Eeprom support (family 0x43)
* Cesar Prados, Alessandro Rubini, 2013. GNU GPL2 or later
*/
#include <stdlib.h>
#include <string.h>
#include "w1.h"
#define LSB_ADDR(X) ((X) & 0xFF)
#define MSB_ADDR(X) (((X) & 0xFF00)>>8)
static
int
w1_write_page
(
struct
w1_dev
*
dev
,
int
offset
,
const
uint8_t
*
buffer
,
int
blen
)
{
int
i
,
j
,
es
;
/* First, write scratchpad */
w1_match_rom
(
dev
);
w1_write_byte
(
dev
->
bus
,
W1_CMDR_W_SPAD
);
w1_write_byte
(
dev
->
bus
,
LSB_ADDR
(
offset
));
w1_write_byte
(
dev
->
bus
,
MSB_ADDR
(
offset
));
for
(
i
=
0
;
i
<
blen
;
i
++
)
w1_write_byte
(
dev
->
bus
,
buffer
[
i
]);
/* Then, read it back, and remember the return E/S */
w1_match_rom
(
dev
);
w1_write_byte
(
dev
->
bus
,
W1_CMDR_R_SPAD
);
if
(
w1_read_byte
(
dev
->
bus
)
!=
LSB_ADDR
(
offset
))
return
-
1
;
if
(
w1_read_byte
(
dev
->
bus
)
!=
MSB_ADDR
(
offset
))
return
-
2
;
es
=
w1_read_byte
(
dev
->
bus
);
for
(
i
=
0
;
i
<
blen
;
i
++
)
{
j
=
w1_read_byte
(
dev
->
bus
);
if
(
j
!=
buffer
[
i
])
return
-
3
;
}
/* Finally, "copy scratchpad" to actually write */
w1_match_rom
(
dev
);
w1_write_byte
(
dev
->
bus
,
W1_CMDR_C_SPAD
);
w1_write_byte
(
dev
->
bus
,
LSB_ADDR
(
offset
));
w1_write_byte
(
dev
->
bus
,
MSB_ADDR
(
offset
));
w1_write_byte
(
dev
->
bus
,
es
);
usleep
(
10000
);
/* 10ms, in theory */
/* Don't read back, as nothing useful is there (I get 0xf9, why?) */
return
blen
;
}
int
w1_write_eeprom
(
struct
w1_dev
*
dev
,
int
offset
,
const
uint8_t
*
buffer
,
int
blen
)
{
int
i
,
page
,
endpage
;
int
ret
=
0
;
/* Split the write into several page-local writes */
page
=
offset
/
32
;
endpage
=
(
offset
+
blen
-
1
)
/
32
;
/* Traling part of first page */
if
(
offset
%
32
)
{
if
(
endpage
!=
page
)
i
=
32
-
(
offset
%
32
);
else
i
=
blen
;
ret
+=
w1_write_page
(
dev
,
offset
,
buffer
,
i
);
if
(
ret
<
0
)
return
ret
;
buffer
+=
i
;
offset
+=
i
;
blen
-=
i
;
}
/* Whole pages and leading part of last page */
while
(
blen
>
0
)
{
i
=
blen
;
if
(
blen
>
32
)
i
=
32
;
i
=
w1_write_page
(
dev
,
offset
,
buffer
,
i
);
if
(
i
<
0
)
return
i
;
ret
+=
i
;
buffer
+=
32
;
offset
+=
32
;
blen
-=
32
;
}
return
ret
;
}
int
w1_read_eeprom
(
struct
w1_dev
*
dev
,
int
offset
,
uint8_t
*
buffer
,
int
blen
)
{
int
i
;
w1_match_rom
(
dev
);
w1_write_byte
(
dev
->
bus
,
W1_CMDR_R_MEMORY
);
w1_write_byte
(
dev
->
bus
,
LSB_ADDR
(
offset
));
w1_write_byte
(
dev
->
bus
,
MSB_ADDR
(
offset
));
/* There is no page-size limit in reading, just go on at will */
for
(
i
=
0
;
i
<
blen
;
i
++
)
buffer
[
i
]
=
w1_read_byte
(
dev
->
bus
);
return
blen
;
}
int
w1_read_eeprom_bus
(
struct
w1_bus
*
bus
,
int
offset
,
uint8_t
*
buffer
,
int
blen
)
{
int
i
,
class
;
for
(
i
=
0
;
i
<
W1_MAX_DEVICES
;
i
++
)
{
class
=
w1_class
(
bus
->
devs
+
i
);
if
(
class
==
0x43
)
return
w1_read_eeprom
(
bus
->
devs
+
i
,
offset
,
buffer
,
blen
);
}
/* not found */
return
-
1
;
}
int
w1_write_eeprom_bus
(
struct
w1_bus
*
bus
,
int
offset
,
const
uint8_t
*
buffer
,
int
blen
)
{
int
i
,
class
;
for
(
i
=
0
;
i
<
W1_MAX_DEVICES
;
i
++
)
{
class
=
w1_class
(
bus
->
devs
+
i
);
if
(
class
==
0x43
)
return
w1_write_eeprom
(
bus
->
devs
+
i
,
offset
,
buffer
,
blen
);
}
/* not found */
return
-
1
;
}
tools/w1-host/w1-temp.c
deleted
100644 → 0
View file @
05a0472d
/*
* Temperature input for DS18S20 (family 0x10)
* Alessandro Rubini, 2013 GNU GPL2 or later
*/
#include "w1.h"
int32_t
w1_read_temp
(
struct
w1_dev
*
dev
,
unsigned
long
flags
)
{
static
uint8_t
scratchpad
[
8
];
int
class
=
w1_class
(
dev
);
int32_t
res
;
int16_t
cval
;
int
i
;
/* The caller is expected to have checked the class. but still... */
switch
(
class
)
{
case
0x10
:
case
0x28
:
case
0x42
:
break
;
/* Supported, at least for temperature input */
default:
return
1
<<
31
;
/* very negative */
}
/* If so asked, jump over start-conversion and only collect result */
if
(
flags
&
W1_FLAG_COLLECT
)
goto
collect
;
w1_match_rom
(
dev
);
w1_write_byte
(
dev
->
bus
,
W1_CMDT_CONVERT
);
/* If so asked, don't wait for the conversion to be over */
if
(
flags
&
W1_FLAG_NOWAIT
)
return
0
;
while
(
wrpc_w1_ops
.
read_bit
(
dev
->
bus
)
==
0
)
;
collect:
w1_match_rom
(
dev
);
w1_write_byte
(
dev
->
bus
,
W1_CMDT_R_SPAD
);
for
(
i
=
0
;
i
<
sizeof
(
scratchpad
);
i
++
)
scratchpad
[
i
]
=
w1_read_byte
(
dev
->
bus
);
res
=
0
;
cval
=
scratchpad
[
1
]
<<
8
|
scratchpad
[
0
];
switch
(
class
)
{
case
0x10
:
/* 18S20: two bytes plus "count remain" value */
res
=
(
int32_t
)
cval
<<
15
;
/* 1 decimal points */
res
-=
0x4000
;
/* - 0.25 degrees */
res
|=
scratchpad
[
6
]
<<
12
;
/* 1/16th of degree each */
break
;
case
0x28
:
case
0x42
:
/* 18B20 and DS28EA00: only the two bytes */
res
=
(
int32_t
)
cval
<<
12
;
/* 4 decimal points */
break
;
}
return
res
;
}
int32_t
w1_read_temp_bus
(
struct
w1_bus
*
bus
,
unsigned
long
flags
)
{
int
i
,
class
;
for
(
i
=
0
;
i
<
W1_MAX_DEVICES
;
i
++
)
{
class
=
w1_class
(
bus
->
devs
+
i
);
switch
(
class
)
{
case
0x10
:
case
0x28
:
case
0x42
:
return
w1_read_temp
(
bus
->
devs
+
i
,
flags
);
default:
break
;
}
}
/* not found */
return
1
<<
31
;
}
tools/w1-host/w1.c
deleted
100644 → 0
View file @
05a0472d
/*
* Onewire generic interface
* Alessandro Rubini, 2013 GNU GPL2 or later
*/
#include <string.h>
#include "w1.h"
static
const
struct
w1_ops
*
ops
=
&
wrpc_w1_ops
;
/* local shorter name */
void
w1_write_byte
(
struct
w1_bus
*
bus
,
int
byte
)
{
int
i
;
for
(
i
=
1
;
i
<
0x100
;
i
<<=
1
)
ops
->
write_bit
(
bus
,
byte
&
i
?
1
:
0
);
}
int
w1_read_byte
(
struct
w1_bus
*
bus
)
{
int
i
,
res
=
0
;
for
(
i
=
1
;
i
<
0x100
;
i
<<=
1
)
res
|=
ops
->
read_bit
(
bus
)
?
i
:
0
;
usleep
(
100
);
/* inter-byte, for my eyes only */
return
res
;
}
/* scan_bus requires this di-bit helper */
enum
__bits
{
B_0
,
B_1
,
B_BOTH
};
/* return what we get, select it if unambiguous or the one passed */
static
enum
__bits
__get_dibit
(
struct
w1_bus
*
bus
,
int
select
)
{
int
a
,
b
;
a
=
ops
->
read_bit
(
bus
);
b
=
ops
->
read_bit
(
bus
);
if
(
a
!=
b
)
{
ops
->
write_bit
(
bus
,
a
);
return
a
?
B_1
:
B_0
;
}
ops
->
write_bit
(
bus
,
select
);
return
B_BOTH
;
}
/*
* This identifies one. Returns 0 if not found, -1 on error. The current mask
* is used to return the conflicts we found: on each conflict, we follow
* what's already in our id->rom, but remember it for later scans.
*/
static
int
__w1_scan_one
(
struct
w1_bus
*
bus
,
uint64_t
*
rom
,
uint64_t
*
cmask
)
{
uint64_t
mask
;
int
select
;
enum
__bits
b
;
if
(
ops
->
reset
(
bus
)
!=
1
)
return
-
1
;
w1_write_byte
(
bus
,
0xf0
);
/* search rom */
/*
* Send all bits we have (initially, zero).
* On a conflict, follow what we have in rom and possibly mark it.
*/
*
cmask
=
0
;
for
(
mask
=
1
;
mask
;
mask
<<=
1
)
{
select
=
*
rom
&
mask
;
b
=
__get_dibit
(
bus
,
select
);
switch
(
b
)
{
case
B_1
:
*
rom
|=
mask
;
case
B_0
:
break
;
case
B_BOTH
:
/* if we follow 1, it's resolved, else mark it */
if
(
!
select
)
*
cmask
|=
mask
;
break
;
}
}
return
0
;
}
int
w1_scan_bus
(
struct
w1_bus
*
bus
)
{
uint64_t
mask
;
uint64_t
cmask
;
/* current */
struct
w1_dev
*
d
;
int
i
;
memset
(
bus
->
devs
,
0
,
sizeof
(
bus
->
devs
));
if
(
!
ops
->
reset
)
return
0
;
/* no devices */
for
(
i
=
0
,
cmask
=
0
;
i
<
W1_MAX_DEVICES
;
i
++
)
{
d
=
bus
->
devs
+
i
;
d
->
bus
=
bus
;
if
(
i
)
{
/* Not first: scan conflicts and resolve last */
d
->
rom
=
bus
->
devs
[
i
-
1
].
rom
;
for
(
mask
=
(
1ULL
<<
63
);
mask
;
mask
>>=
1
)
{
/*
* Warning: lm32 compiter treats as signed!
*
* Even if mask is uint64_t, the shift in the
* for loop above is signed, so fix it.
* I prefer not to change the loop, as the
* code is in use elsewhere and I prefer to
* keep differences to a minimum
*/
if
(
mask
&
(
1ULL
<<
62
))
mask
=
(
1ULL
<<
62
);
if
(
cmask
&
mask
)
break
;
d
->
rom
&=
~
mask
;
}
if
(
!
mask
)
{
/* no conflicts to solve: done */
return
i
;
}
d
->
rom
|=
mask
;
/* we'll reply 1 next loop */
cmask
&=
~
mask
;
}
if
(
__w1_scan_one
(
bus
,
&
d
->
rom
,
&
cmask
))
{
/* error on this one */
return
i
;
}
}
return
i
;
}
void
w1_match_rom
(
struct
w1_dev
*
dev
)
{
int
i
;
ops
->
reset
(
dev
->
bus
);
w1_write_byte
(
dev
->
bus
,
W1_CMD_MATCH_ROM
);
/* match rom */
for
(
i
=
0
;
i
<
64
;
i
+=
8
)
{
w1_write_byte
(
dev
->
bus
,
(
int
)(
dev
->
rom
>>
i
)
);
}
}
tools/w1-host/w1.h
deleted
100644 → 0
View file @
05a0472d
/*
* Onewire generic interface
* Alessandro Rubini, 2013 GNU GPL2 or later
*/
#ifndef __BATHOS_W1_H__
#define __BATHOS_W1_H__
#include <stdint.h>
#define W1_MAX_DEVICES 8
/* we have no alloc */
struct
w1_dev
{
struct
w1_bus
*
bus
;
uint64_t
rom
;
};
static
inline
int
w1_class
(
struct
w1_dev
*
dev
)
{
return
dev
->
rom
&
0xff
;
}
struct
w1_bus
{
unsigned
long
detail
;
/* gpio bit or whatever (driver-specific) */
struct
w1_dev
devs
[
W1_MAX_DEVICES
];
};
/*
* The low-level driver is based on this set of operations. We expect to
* only have one set of such operations in each build. (i.e., no bus-specific
* operations, to keep the thing simple and small).
*/
struct
w1_ops
{
int
(
*
reset
)(
struct
w1_bus
*
bus
);
/* returns 1 on "present" */
int
(
*
read_bit
)(
struct
w1_bus
*
bus
);
void
(
*
write_bit
)(
struct
w1_bus
*
bus
,
int
bit
);
};
/* Library functions */
extern
int
w1_scan_bus
(
struct
w1_bus
*
bus
);
extern
void
w1_write_byte
(
struct
w1_bus
*
bus
,
int
byte
);
extern
int
w1_read_byte
(
struct
w1_bus
*
bus
);
extern
void
w1_match_rom
(
struct
w1_dev
*
dev
);
#define W1_CMD_SEARCH_ROM 0xf0
#define W1_CMD_READ_ROM 0x33
#define W1_CMD_MATCH_ROM 0x55
#define W1_CMD_SKIP_ROM 0xcc
#define W1_CMD_ASEARCH 0xec
/* commands for specific families */
#define W1_CMDT_CONVERT 0x44
#define W1_CMDT_W_SPAD 0x4e
#define W1_CMDT_R_SPAD 0xbe
#define W1_CMDT_CP_SPAD 0x48
#define W1_CMDT_RECALL 0xb8
#define W1_CMDT_R_PS 0xb4
/* EEPROM DS28EC20 */
#define W1_CMDR_W_SPAD 0x0f
#define W1_CMDR_R_SPAD 0xaa
#define W1_CMDR_C_SPAD 0x55
#define W1_CMDR_R_MEMORY 0xf0
#define W1_CMDR_EXT_R_MEMORY 0xa5
/* Temperature conversion takes time: by default wait, but allow flags */
#define W1_FLAG_NOWAIT 0x01
/* start conversion only*/
#define W1_FLAG_COLLECT 0x02
/* don't start, just get output */
/* These functions are dev-specific */
extern
int32_t
w1_read_temp
(
struct
w1_dev
*
dev
,
unsigned
long
flags
);
extern
int
w1_read_eeprom
(
struct
w1_dev
*
dev
,
int
offset
,
uint8_t
*
buffer
,
int
blen
);
extern
int
w1_write_eeprom
(
struct
w1_dev
*
dev
,
int
offset
,
const
uint8_t
*
buffer
,
int
blen
);
/* These are generic, using the first suitable device in the bus */
extern
int32_t
w1_read_temp_bus
(
struct
w1_bus
*
bus
,
unsigned
long
flags
);
extern
int
w1_read_eeprom_bus
(
struct
w1_bus
*
bus
,
int
offset
,
uint8_t
*
buffer
,
int
blen
);
extern
int
w1_write_eeprom_bus
(
struct
w1_bus
*
bus
,
int
offset
,
const
uint8_t
*
buffer
,
int
blen
);
extern
struct
w1_ops
wrpc_w1_ops
;
extern
struct
w1_bus
wrpc_w1_bus
;
#endif
/* __BATHOS_W1_H__ */
tools/wrpc-w1-read.c
View file @
d1e54838
...
...
@@ -20,7 +20,7 @@
#include <sys/stat.h>
#include <sys/mman.h>
#include
"w1-host/w1.h"
#include
<w1.h>
#define SPEC_W1_OFFSET 0x20600
/* from "sdb" on the shell, current gateware */
...
...
tools/wrpc-w1-write.c
View file @
d1e54838
...
...
@@ -20,7 +20,7 @@
#include <sys/stat.h>
#include <sys/mman.h>
#include
"w1-host/w1.h"
#include
<w1.h>
#define SPEC_W1_OFFSET 0x20600
/* from "sdb" on the shell, current gateware */
...
...
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