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
28
Issues
28
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
196cba51
Commit
196cba51
authored
Jul 04, 2012
by
Wesley W. Terpstra
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix power problems with the 1wire.
Add more optional debug statements.
parent
b20e998e
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
82 additions
and
18 deletions
+82
-18
persistent_mac.c
dev/persistent_mac.c
+20
-11
cmd_mac.c
shell/cmd_mac.c
+42
-0
eep43.c
sockitowm/eep43.c
+17
-3
owlnk.c
sockitowm/owlnk.c
+2
-4
wrc_main.c
wrc_main.c
+1
-0
No files found.
dev/persistent_mac.c
View file @
196cba51
...
...
@@ -12,26 +12,33 @@ int get_persistent_mac(unsigned char* mac)
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 */
#if DEBUG_PMAC
mprintf
(
"Found %d onewire devices
\n
"
,
devices
);
#endif
out
=
-
1
;
for
(
i
=
0
;
i
<
devices
;
++
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
/* If there is a temperature sensor, use it for the low three MAC values */
if
(
FamilySN
[
i
][
0
]
==
0x28
||
FamilySN
[
i
][
0
]
==
0x42
)
{
mac
[
3
]
=
FamilySN
[
i
][
3
];
mac
[
4
]
=
FamilySN
[
i
][
2
];
mac
[
5
]
=
FamilySN
[
i
][
1
];
out
=
0
;
#ifdef DEBUG_PMAC
mprintf
(
"Using temperature sensor ID: %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
]);
#if DEBUG_PMAC
mprintf
(
"Using temperature ID for MAC
\n
"
);
#endif
}
...
...
@@ -41,19 +48,17 @@ int get_persistent_mac(unsigned char* mac)
if
(
ReadMem43
(
portnum
,
FamilySN
[
i
],
EEPROM_MAC_PAGE
,
&
read_buffer
)
==
TRUE
)
{
if
(
read_buffer
[
0
]
==
0
&&
read_buffer
[
1
]
==
0
&&
read_buffer
[
2
]
==
0
)
{
/* Skip the EEPROM since it has not been programmed! */
#ifdef DEBUG_PMAC
mprintf
(
"EEPROM %x:%x:%x:%x:%x:%x:%x:%x has not been programmed with a MAC
\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
]);
#if DEBUG_PMAC
mprintf
(
"EEPROM has not been programmed with a MAC
\n
"
);
#endif
}
else
{
memcpy
(
mac
,
read_buffer
,
6
);
out
=
0
;
#if
def
DEBUG_PMAC
#if DEBUG_PMAC
mprintf
(
"Using EEPROM page: %x:%x:%x:%x:%x:%x
\n
"
,
mac
[
0
],
mac
[
1
],
mac
[
2
],
mac
[
3
],
mac
[
4
],
mac
[
5
]);
}
#endif
}
}
}
}
...
...
@@ -77,6 +82,10 @@ int set_persistent_mac(unsigned char* mac)
memset
(
write_buffer
,
0
,
sizeof
(
write_buffer
));
memcpy
(
write_buffer
,
mac
,
6
);
#if DEBUG_PMAC
mprintf
(
"Writing to EEPROM
\n
"
);
#endif
/* Write the last EEPROM with the MAC */
owLevel
(
portnum
,
MODE_NORMAL
);
if
(
Write43
(
portnum
,
FamilySN
[
devices
-
1
],
EEPROM_MAC_PAGE
,
&
write_buffer
)
==
TRUE
)
...
...
shell/cmd_mac.c
0 → 100644
View file @
196cba51
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "softpll_ng.h"
#include "shell.h"
#include "../lib/ipv4.h"
static
decode_mac
(
const
char
*
str
,
unsigned
char
*
mac
)
{
int
i
,
x
;
/* Don't try to detect bad input; need small code */
for
(
i
=
0
;
i
<
6
;
++
i
)
{
str
=
fromhex
(
str
,
&
x
);
mac
[
i
]
=
x
;
if
(
*
str
==
':'
)
++
str
;
}
}
int
cmd_ip
(
const
char
*
args
[])
{
unsigned
char
mac
[
6
];
if
(
!
args
[
0
]
||
!
strcasecmp
(
args
[
0
],
"get"
))
{
/* get current MAC */
get_mac_addr
(
mac
);
}
else
if
(
!
strcasecmp
(
args
[
0
],
"getp"
))
{
/* get persistent MAC */
get_persistent_mac
(
mac
);
}
else
if
(
!
strcasecmp
(
args
[
0
],
"set"
)
&&
args
[
1
])
{
decode_mac
(
args
[
1
],
mac
);
set_mac_addr
(
mac
);
}
else
if
(
!
strcasecmp
(
args
[
0
],
"setp"
)
&&
args
[
1
])
{
decode_mac
(
args
[
1
],
mac
);
set_persistent_mac
(
mac
);
}
else
{
return
-
EINVAL
;
}
mprintf
(
"MAC-address: %x:%x:%x:%x:%x:%x
\n
"
,
mac
[
0
],
mac
[
1
],
mac
[
2
],
mac
[
3
],
mac
[
4
],
mac
[
5
]);
}
sockitowm/eep43.c
View file @
196cba51
...
...
@@ -6,6 +6,8 @@
#define READ_MEM_CMD 0xf0
#define E_READ_MEM_CMD 0xa5
//#define DEBUG_EEP43 1
int
Write43
(
int
portnum
,
uchar
*
SerialNum
,
int
page
,
uchar
*
page_buffer
)
{
uchar
rt
=
FALSE
;
...
...
@@ -16,7 +18,9 @@ int Write43(int portnum, uchar *SerialNum, int page, uchar *page_buffer)
if
(
owAccess
(
portnum
))
{
#if DEBUG_EEP43
mprintf
(
" Writing Scratchpad...
\n
"
);
#endif
if
(
!
owWriteBytePower
(
portnum
,
WRITE_SCRATCH_CMD
))
return
FALSE
;
setcrc16
(
portnum
,
0
);
...
...
@@ -33,8 +37,8 @@ int Write43(int portnum, uchar *SerialNum, int page, uchar *page_buffer)
for
(
i
=
0
;
i
<
32
;
i
++
)
//write 32 data bytes to scratchpad
{
owLevel
(
portnum
,
MODE_NORMAL
);
owWriteBytePower
(
portnum
,
i
);
lastcrc16
=
docrc16
(
portnum
,
i
);
owWriteBytePower
(
portnum
,
page_buffer
[
i
]
);
lastcrc16
=
docrc16
(
portnum
,
page_buffer
[
i
]
);
// mprintf(" CRC16: %x\n", lastcrc16);
}
...
...
@@ -43,7 +47,9 @@ int Write43(int portnum, uchar *SerialNum, int page, uchar *page_buffer)
owLevel
(
portnum
,
MODE_NORMAL
);
lastcrc16
=
docrc16
(
portnum
,(
ushort
)
owReadBytePower
(
portnum
));
}
#if DEBUG_EEP43
mprintf
(
" CRC16: %x
\n
"
,
lastcrc16
);
#endif
if
(
lastcrc16
==
0xb001
)
{
//copy to mem
...
...
@@ -54,6 +60,7 @@ int Write43(int portnum, uchar *SerialNum, int page, uchar *page_buffer)
}
}
owLevel
(
portnum
,
MODE_NORMAL
);
return
rt
;
}
...
...
@@ -77,7 +84,7 @@ int Copy2Mem43(int portnum, uchar *SerialNum)
owLevel
(
portnum
,
MODE_NORMAL
);
owWriteBytePower
(
portnum
,
0x1f
);
//write E/S
msDelay
(
5
00
);
usleep
(
5000
00
);
owLevel
(
portnum
,
MODE_NORMAL
);
...
...
@@ -87,6 +94,7 @@ int Copy2Mem43(int portnum, uchar *SerialNum)
rt
=
TRUE
;
}
owLevel
(
portnum
,
MODE_NORMAL
);
return
rt
;
}
...
...
@@ -107,7 +115,9 @@ int ReadScratch43(int portnum, uchar *SerialNum, uchar *page_buffer)
if
(
owAccess
(
portnum
))
{
#if DEBUG_EEP43
mprintf
(
" Reading Scratchpad...
\n
"
);
#endif
if
(
!
owWriteBytePower
(
portnum
,
READ_SCRATCH_CMD
))
return
FALSE
;
...
...
@@ -130,7 +140,9 @@ int ReadScratch43(int portnum, uchar *SerialNum, uchar *page_buffer)
read_data
=
owReadBytePower
(
portnum
);
lastcrc16
=
docrc16
(
portnum
,
read_data
);
#if DEBUG_EEP43
mprintf
(
"E/S: 0x%x
\n
"
,
read_data
);
#endif
for
(
i
=
0
;
i
<
32
;
i
++
)
{
owLevel
(
portnum
,
MODE_NORMAL
);
...
...
@@ -151,6 +163,7 @@ int ReadScratch43(int portnum, uchar *SerialNum, uchar *page_buffer)
rt
=
TRUE
;
}
owLevel
(
portnum
,
MODE_NORMAL
);
return
rt
;
}
...
...
@@ -202,5 +215,6 @@ int ReadMem43(int portnum, uchar *SerialNum, int page, uchar *page_buffer)
rt
=
TRUE
;
}
owLevel
(
portnum
,
MODE_NORMAL
);
return
rt
;
}
sockitowm/owlnk.c
View file @
196cba51
...
...
@@ -45,10 +45,8 @@
//#define S_PWR 0
#define S_IEN 0
#define S_OVD_E 1
//#define CLK_DIV_NOR CPU_CLOCK/357 //clock divider for normal mode
//#define CLK_DIV_OVD CPU_CLOCK/1008 //clock divider for overdrive mode
#define CLK_DIV_NOR 624
#define CLK_DIV_OVD 124
#define CLK_DIV_NOR (CPU_CLOCK/200000-1) //clock divider for normal mode
#define CLK_DIV_OVD (CPU_CLOCK/1000000-1) //clock divider for overdrive mode
// exportable link-level functions
SMALLINT
owTouchReset
(
int
);
...
...
wrc_main.c
View file @
196cba51
...
...
@@ -37,6 +37,7 @@ void wrc_initialize()
uart_init
();
mprintf
(
"WR Core: starting up...
\n
"
);
timer_init
(
1
);
owInit
();
mac_addr
[
0
]
=
0x08
;
//
mac_addr
[
1
]
=
0x00
;
// CERN OUI
...
...
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