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
29
Issues
29
List
Board
Labels
Milestones
Merge Requests
5
Merge Requests
5
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
21040be6
Commit
21040be6
authored
Jul 11, 2012
by
Grzegorz Daniluk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
onewire: make those onewire functions more general and add temperature reading wrapper function
parent
a309deee
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
60 additions
and
33 deletions
+60
-33
onewire.c
dev/onewire.c
+47
-27
onewire.h
include/onewire.h
+7
-2
cmd_mac.c
shell/cmd_mac.c
+3
-2
wrc_main.c
wrc_main.c
+3
-2
No files found.
dev/onewire.c
View file @
21040be6
#include "
persistent_mac
.h"
#include "
onewire
.h"
#include "../sockitowm/ownet.h"
#include "../sockitowm/findtype.h"
#define MAX_DEV1WIRE 8
#define DEBUG_PMAC 0
/* 0 = success, -1 = error */
int
get_persistent_mac
(
unsigned
char
*
mac
)
uint8_t
FamilySN
[
MAX_DEV1WIRE
][
8
];
uint8_t
devsnum
;
uint8_t
found_msk
;
void
own_scanbus
(
uint8_t
portnum
)
{
unsigned
char
FamilySN
[
MAX_DEV1WIRE
][
8
];
unsigned
char
read_buffer
[
32
];
unsigned
char
portnum
=
ONEWIRE_PORT
;
int
i
,
devices
,
out
;
// Find the device(s)
devices
=
0
;
devices
+=
FindDevices
(
portnum
,
&
FamilySN
[
devices
],
0x28
,
MAX_DEV1WIRE
-
devices
);
/* Temperature 28 sensor (SPEC) */
devices
+=
FindDevices
(
portnum
,
&
FamilySN
[
devices
],
0x42
,
MAX_DEV1WIRE
-
devices
);
/* Temperature 42 sensor (SCU) */
devices
+=
FindDevices
(
portnum
,
&
FamilySN
[
devices
],
0x43
,
MAX_DEV1WIRE
-
devices
);
/* EEPROM */
found_msk
=
0
;
devsnum
=
0
;
devsnum
+=
FindDevices
(
portnum
,
&
FamilySN
[
devsnum
],
0x28
,
MAX_DEV1WIRE
-
devsnum
);
/* Temperature 28 sensor (SPEC) */
if
(
devsnum
>
0
)
found_msk
|=
FOUND_DS18B20
;
devsnum
+=
FindDevices
(
portnum
,
&
FamilySN
[
devsnum
],
0x42
,
MAX_DEV1WIRE
-
devsnum
);
/* Temperature 42 sensor (SCU) */
devsnum
+=
FindDevices
(
portnum
,
&
FamilySN
[
devsnum
],
0x43
,
MAX_DEV1WIRE
-
devsnum
);
/* EEPROM */
#if DEBUG_PMAC
mprintf
(
"Found %d onewire devices
\n
"
,
dev
ices
);
mprintf
(
"Found %d onewire devices
\n
"
,
dev
snum
);
#endif
}
int16_t
own_readtemp
(
uint8_t
portnum
,
int16_t
*
temp
,
int16_t
*
t_frac
)
{
if
(
!
(
found_msk
&
FOUND_DS18B20
))
return
-
1
;
if
(
ReadTemperature28
(
portnum
,
FamilySN
[
0
],
temp
))
{
*
t_frac
=
5000
*
(
!!
(
*
temp
&
0x08
))
+
2500
*
(
!!
(
*
temp
&
0x04
))
+
1250
*
(
!!
(
*
temp
&
0x02
))
+
625
*
(
!!
(
*
temp
&
0x01
));
*
t_frac
=
*
t_frac
/
100
+
(
*
t_frac
%
100
)
/
50
;
*
temp
>>=
4
;
return
0
;
}
return
-
1
;
}
/* 0 = success, -1 = error */
int8_t
get_persistent_mac
(
uint8_t
portnum
,
uint8_t
*
mac
)
{
uint8_t
read_buffer
[
32
];
uint8_t
i
;
int8_t
out
;
out
=
-
1
;
if
(
devsnum
==
0
)
return
out
;
for
(
i
=
0
;
i
<
dev
ices
;
++
i
)
{
#if DEBUG_PMAC
for
(
i
=
0
;
i
<
dev
snum
;
++
i
)
{
//
#if DEBUG_PMAC
mprintf
(
"Found device: %x:%x:%x:%x:%x:%x:%x:%x
\n
"
,
FamilySN
[
i
][
7
],
FamilySN
[
i
][
6
],
FamilySN
[
i
][
5
],
FamilySN
[
i
][
4
],
FamilySN
[
i
][
3
],
FamilySN
[
i
][
2
],
FamilySN
[
i
][
1
],
FamilySN
[
i
][
0
]);
#endif
//
#endif
/* If there is a temperature sensor, use it for the low three MAC values */
if
(
FamilySN
[
i
][
0
]
==
0x28
||
FamilySN
[
i
][
0
]
==
0x42
)
{
...
...
@@ -67,17 +91,13 @@ int get_persistent_mac(unsigned char* mac)
}
/* 0 = success, -1 = error */
int
set_persistent_mac
(
unsigned
char
*
mac
)
int
8_t
set_persistent_mac
(
uint8_t
portnum
,
uint8_t
*
mac
)
{
unsigned
char
FamilySN
[
MAX_DEV1WIRE
][
8
];
unsigned
char
write_buffer
[
32
];
unsigned
char
portnum
=
ONEWIRE_PORT
;
int
i
,
devices
;
uint8_t
FamilySN
[
1
][
8
];
uint8_t
write_buffer
[
32
];
// Find the device(s)
devices
=
FindDevices
(
portnum
,
&
FamilySN
[
0
],
0x43
,
MAX_DEV1WIRE
);
/* EEPROM */
if
(
devices
==
0
)
return
-
1
;
// Find the device (only the first one, we won't write MAC to all EEPROMs out there, right?)
if
(
FindDevices
(
portnum
,
&
FamilySN
[
0
],
0x43
,
1
)
==
0
)
return
-
1
;
memset
(
write_buffer
,
0
,
sizeof
(
write_buffer
));
memcpy
(
write_buffer
,
mac
,
6
);
...
...
@@ -88,7 +108,7 @@ int set_persistent_mac(unsigned char* mac)
/* Write the last EEPROM with the MAC */
owLevel
(
portnum
,
MODE_NORMAL
);
if
(
Write43
(
portnum
,
FamilySN
[
devices
-
1
],
EEPROM_MAC_PAGE
,
&
write_buffer
)
==
TRUE
)
if
(
Write43
(
portnum
,
FamilySN
[
0
],
EEPROM_MAC_PAGE
,
&
write_buffer
)
==
TRUE
)
return
0
;
return
-
1
;
...
...
include/onewire.h
View file @
21040be6
...
...
@@ -3,9 +3,14 @@
#define ONEWIRE_PORT 0
#define EEPROM_MAC_PAGE 0
#define MAX_DEV1WIRE 8
#define FOUND_DS18B20 0x01
void
own_scanbus
(
uint8_t
portnum
);
int16_t
own_readtemp
(
uint8_t
portnum
,
int16_t
*
temp
,
int16_t
*
t_frac
);
/* 0 = success, -1 = error */
int
get_persistent_mac
(
unsigned
char
*
mac
);
int
set_persistent_mac
(
unsigned
char
*
mac
);
int
8_t
get_persistent_mac
(
uint8_t
portnum
,
uint8_t
*
mac
);
int
8_t
set_persistent_mac
(
uint8_t
portnum
,
uint8_t
*
mac
);
#endif
shell/cmd_mac.c
View file @
21040be6
...
...
@@ -4,6 +4,7 @@
#include "softpll_ng.h"
#include "shell.h"
#include "onewire.h"
#include "../lib/ipv4.h"
static
decode_mac
(
const
char
*
str
,
unsigned
char
*
mac
)
{
...
...
@@ -27,14 +28,14 @@ int cmd_mac(const char *args[])
}
else
if
(
!
strcasecmp
(
args
[
0
],
"getp"
))
{
/* get persistent MAC */
get_mac_addr
(
mac
);
get_persistent_mac
(
mac
);
get_persistent_mac
(
ONEWIRE_PORT
,
mac
);
}
else
if
(
!
strcasecmp
(
args
[
0
],
"set"
)
&&
args
[
1
])
{
decode_mac
(
args
[
1
],
mac
);
set_mac_addr
(
mac
);
pfilter_init_default
();
}
else
if
(
!
strcasecmp
(
args
[
0
],
"setp"
)
&&
args
[
1
])
{
decode_mac
(
args
[
1
],
mac
);
set_persistent_mac
(
mac
);
set_persistent_mac
(
ONEWIRE_PORT
,
mac
);
}
else
{
return
-
EINVAL
;
}
...
...
wrc_main.c
View file @
21040be6
...
...
@@ -13,7 +13,7 @@
#include "i2c.h"
//#include "eeprom.h"
#include "softpll_ng.h"
#include "
persistent_mac
.h"
#include "
onewire
.h"
#include "lib/ipv4.h"
#include "wrc_ptp.h"
...
...
@@ -50,7 +50,8 @@ void wrc_initialize()
mac_addr
[
4
]
=
0xAD
;
mac_addr
[
5
]
=
0x42
;
if
(
get_persistent_mac
(
mac_addr
)
==
-
1
)
{
own_scanbus
(
ONEWIRE_PORT
);
if
(
get_persistent_mac
(
ONEWIRE_PORT
,
mac_addr
)
==
-
1
)
{
mprintf
(
"Unable to determine MAC address
\n
"
);
}
...
...
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