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
30
Issues
30
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
98aac55c
Commit
98aac55c
authored
Jun 12, 2012
by
Tomasz Wlostowski
Browse files
Options
Browse Files
Download
Plain Diff
merged wrpc-w-shell
parents
a788f220
70efc7d4
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
134 additions
and
91 deletions
+134
-91
.gitignore
.gitignore
+0
-1
.gitmodules
.gitmodules
+3
-0
minic.c
dev/minic.c
+101
-71
minic_regs.h
include/hw/minic_regs.h
+22
-18
ptp-noposix
ptp-noposix
+1
-0
revision.c
revision.c
+2
-0
wrc_main.c
wrc_main.c
+5
-1
No files found.
.gitignore
View file @
98aac55c
...
...
@@ -8,4 +8,3 @@ tools/vuart_console
tools/genraminit
wrc_disasm.S
wrc.ram
ptp-noposix
\ No newline at end of file
.gitmodules
0 → 100644
View file @
98aac55c
[submodule "ptp-noposix"]
path = ptp-noposix
url = git://gnudd.com/ptp-noposix.git
dev/minic.c
View file @
98aac55c
#include <stdio.h>
#include <string.h>
#include "types.h"
#include "board.h"
...
...
@@ -27,8 +28,6 @@
#define TX_DESC_HAS_OWN_MAC (1<<28)
#define RX_OOB_SIZE 6
#define REFCLK_FREQ 125000000
#define ETH_HEADER_SIZE 14
...
...
@@ -69,30 +68,65 @@ static inline uint32_t minic_readl(uint32_t reg)
return
*
(
volatile
uint32_t
*
)(
BASE_MINIC
+
reg
);
}
static
void
minic_new_rx_buffer
(
)
static
uint8_t
*
minic_rx_memcpy
(
uint8_t
*
dst
,
uint8_t
*
src
,
uint32_t
size
)
{
minic
.
rx_head
=
minic
.
rx_base
;
uint32_t
part
;
//if src is outside the circular buffer, bring it back to the beginning
src
=
(
uint8_t
*
)
((
uint32_t
)
minic
.
rx_base
+
((
uint32_t
)
src
-
(
uint32_t
)
minic
.
rx_base
)
%
minic
.
rx_size
);
if
((
uint32_t
)
src
+
size
<=
(
uint32_t
)
minic
.
rx_base
+
minic
.
rx_size
)
return
memcpy
(
dst
,
src
,
size
);
part
=
(
uint32_t
)
minic
.
rx_base
+
minic
.
rx_size
-
(
uint32_t
)
src
;
memcpy
(
dst
,
src
,
part
);
memcpy
((
void
*
)
(
dst
+
part
),
(
void
*
)
minic
.
rx_base
,
size
-
part
);
return
dst
;
}
static
uint8_t
*
minic_rx_memset
(
uint8_t
*
mem
,
uint8_t
c
,
uint32_t
size
)
{
uint32_t
part
;
uint8_t
*
src
;
//if src is outside the circular buffer, bring it back to the beginning
src
=
(
uint8_t
*
)
((
uint32_t
)
minic
.
rx_base
+
((
uint32_t
)
mem
-
(
uint32_t
)
minic
.
rx_base
)
%
minic
.
rx_size
);
if
((
uint32_t
)
src
+
size
<=
(
uint32_t
)
minic
.
rx_base
+
minic
.
rx_size
)
return
memset
(
src
,
c
,
size
);
part
=
(
uint32_t
)
minic
.
rx_base
+
minic
.
rx_size
-
(
uint32_t
)
src
;
memset
(
src
,
c
,
part
);
memset
((
void
*
)
minic
.
rx_base
,
c
,
size
-
part
);
return
src
;
}
static
void
minic_new_rx_buffer
()
{
minic_writel
(
MINIC_REG_MCR
,
0
);
minic
.
rx_head
=
minic
.
rx_base
;
minic_rx_memset
((
uint8_t
*
)
minic
.
rx_base
,
0x00
,
minic
.
rx_size
);
memset
((
void
*
)
minic
.
rx_base
,
0x0
,
minic
.
rx_size
);
minic_writel
(
MINIC_REG_RX_ADDR
,
(
uint32_t
)
minic
.
rx_base
);
minic_writel
(
MINIC_REG_RX_AVAIL
,
(
minic
.
rx_size
-
MINIC_MTU
)
>>
2
);
// TRACE_DEV("Sizeof: %d Size : %d Avail: %d\n", minic.rx_size, (minic.rx_size - MINIC_MTU) >> 2);
minic_writel
(
MINIC_REG_RX_SIZE
,
minic
.
rx_size
>>
2
);
//new buffer allocated, clear any old RX interrupts
minic_writel
(
MINIC_REG_EIC_ISR
,
MINIC_EIC_ISR_RX
);
minic_writel
(
MINIC_REG_MCR
,
MINIC_MCR_RX_EN
);
}
//mprintf("Base : %x Avail: %d\n", minic_readl(MINIC_REG_RX_ADDR), minic_readl(MINIC_REG_RX_AVAIL));
static
void
minic_rxbuf_free
(
uint32_t
words
)
{
minic_rx_memset
((
uint8_t
*
)
minic
.
rx_head
,
0x00
,
words
<<
2
);
minic_writel
(
MINIC_REG_RX_AVAIL
,
words
);
}
static
void
minic_new_tx_buffer
()
{
minic
.
tx_head
=
minic
.
tx_base
;
minic
.
tx_avail
=
(
minic
.
tx_size
-
MINIC_MTU
)
>>
2
;
minic
.
tx_avail
=
minic
.
tx_size
>>
2
;
minic_writel
(
MINIC_REG_TX_ADDR
,
(
uint32_t
)
minic
.
tx_base
);
}
void
minic_init
()
{
uint32_t
lo
,
hi
;
...
...
@@ -132,7 +166,7 @@ int minic_poll_rx()
isr
=
minic_readl
(
MINIC_REG_EIC_ISR
);
return
(
isr
&
MINIC_EIC_ISR_RX
)
?
1
:
0
;
//>>1;
return
(
isr
&
MINIC_EIC_ISR_RX
)
?
1
:
0
;
}
int
minic_rx_frame
(
uint8_t
*
hdr
,
uint8_t
*
payload
,
uint32_t
buf_size
,
struct
hw_timestamp
*
hwts
)
...
...
@@ -140,27 +174,25 @@ int minic_rx_frame(uint8_t *hdr, uint8_t *payload, uint32_t buf_size, struct hw_
uint32_t
payload_size
,
num_words
;
uint32_t
desc_hdr
;
uint32_t
raw_ts
;
uint32_t
rx_addr_cur
;
uint32_t
rx_addr_cur
,
cur_avail
;
int
n_recvd
;
// mprintf("erxf\n");
if
(
!
(
minic_readl
(
MINIC_REG_EIC_ISR
)
&
MINIC_EIC_ISR_RX
))
return
0
;
//TRACE_DEV("minic: got sthx \n");
//TRACE_DEV("minic: got sthx \n");
desc_hdr
=
*
minic
.
rx_head
;
if
(
!
RX_DESC_VALID
(
desc_hdr
))
/* invalid descriptor? Weird, the RX_ADDR seems to be saying something different. Ignore the packet and purge the RX buffer. */
{
mprintf
(
"invalid descriptor
\n
"
);
minic_new_rx_buffer
();
return
0
;
}
payload_size
=
RX_DESC_SIZE
(
desc_hdr
);
num_words
=
((
payload_size
+
3
)
>>
2
)
+
1
;
// mprintf("Payload: %d\n", payload_size);
/* valid packet */
if
(
!
RX_DESC_ERROR
(
desc_hdr
))
...
...
@@ -175,15 +207,13 @@ int minic_rx_frame(uint8_t *hdr, uint8_t *payload, uint32_t buf_size, struct hw_
payload_size
-=
RX_OOB_SIZE
;
memcpy
(
&
raw_ts
,
(
uint8_t
*
)
minic
.
rx_head
+
payload_size
+
6
,
4
);
/* fixme: ugly way of doing unaligned read */
memcpy
(
&
dhdr
,
(
uint8_t
*
)
minic
.
rx_head
+
payload_size
+
4
,
2
);
minic_rx_memcpy
((
uint8_t
*
)
&
raw_ts
,
(
uint8_t
*
)
minic
.
rx_head
+
payload_size
+
6
,
4
);
/* fixme: ugly way of doing unaligned read */
minic_rx_memcpy
((
uint8_t
*
)
&
dhdr
,
(
uint8_t
*
)
minic
.
rx_head
+
payload_size
+
4
,
2
);
EXPLODE_WR_TIMESTAMP
(
raw_ts
,
counter_r
,
counter_f
);
pps_gen_get_time
(
&
sec
,
&
counter_ppsg
);
counter_ppsg
/=
(
REF_CLOCK_PERIOD_PS
/
1000
);
if
(
counter_r
>
3
*
REF_CLOCK_FREQ_HZ
/
4
&&
counter_ppsg
<
REF_CLOCK_FREQ_HZ
/
4
)
if
(
counter_r
>
3
*
REF_CLOCK_FREQ_HZ
/
4
&&
counter_ppsg
<
250000000
)
sec
--
;
hwts
->
sec
=
sec
&
0x7fffffff
;
...
...
@@ -195,25 +225,26 @@ int minic_rx_frame(uint8_t *hdr, uint8_t *payload, uint32_t buf_size, struct hw_
else
hwts
->
ahead
=
0
;
hwts
->
nsec
=
counter_r
*
8
;
hwts
->
nsec
=
counter_r
*
(
REF_CLOCK_PERIOD_PS
/
1000
)
;
hwts
->
valid
=
(
dhdr
&
RXOOB_TS_INCORRECT
)
?
0
:
1
;
}
n_recvd
=
(
buf_size
<
payload_size
?
buf_size
:
payload_size
);
minic
.
rx_count
++
;
memcpy
(
hdr
,
(
void
*
)
minic
.
rx_head
+
4
,
ETH_HEADER_SIZE
);
memcpy
(
payload
,
(
void
*
)
minic
.
rx_head
+
4
+
ETH_HEADER_SIZE
,
n_recvd
-
ETH_HEADER_SIZE
);
minic_rx_
memcpy
(
hdr
,
(
void
*
)
minic
.
rx_head
+
4
,
ETH_HEADER_SIZE
);
minic_rx_
memcpy
(
payload
,
(
void
*
)
minic
.
rx_head
+
4
+
ETH_HEADER_SIZE
,
n_recvd
-
ETH_HEADER_SIZE
);
minic
.
rx_head
+=
num_words
;
}
else
{
minic
.
rx_head
+=
num_words
;
n_recvd
=
-
1
;
}
minic_rxbuf_free
(
num_words
);
minic
.
rx_head
=
(
uint32_t
*
)
((
uint32_t
)
minic
.
rx_base
+
((
uint32_t
)
minic
.
rx_head
+
(
num_words
<<
2
)
-
(
uint32_t
)
minic
.
rx_base
)
%
minic
.
rx_size
);
rx_addr_cur
=
minic_readl
(
MINIC_REG_RX_ADDR
)
&
0xffff
;
cur_avail
=
minic_readl
(
MINIC_REG_RX_AVAIL
)
;
if
(
rx_addr_cur
<
(
uint32_t
)
minic
.
rx_head
)
/* nothing new in the buffer? */
/*empty buffer->no more received packets, or packet reception in progress but not done*/
if
(
cur_avail
==
(
minic
.
rx_size
>>
2
)
||
!
RX_DESC_VALID
(
*
minic
.
rx_head
))
{
if
(
minic_readl
(
MINIC_REG_MCR
)
&
MINIC_MCR_RX_FULL
)
minic_new_rx_buffer
();
...
...
@@ -221,7 +252,6 @@ int minic_rx_frame(uint8_t *hdr, uint8_t *payload, uint32_t buf_size, struct hw_
minic_writel
(
MINIC_REG_EIC_ISR
,
MINIC_EIC_ISR_RX
);
}
// TRACE_DEV("minic: num_rx %d\n", n_recvd);
return
n_recvd
;
}
...
...
@@ -236,7 +266,7 @@ int minic_tx_frame(uint8_t *hdr, uint8_t *payload, uint32_t size, struct hw_time
// TRACE_DEV("minic_tx_frame: head %x size %d\n", minic.tx_head, size);
memset
(
minic
.
tx_head
,
0x0
,
size
+
16
);
memset
(
(
void
*
)
minic
.
tx_head
,
0x0
,
size
+
16
);
memset
((
void
*
)
minic
.
tx_head
+
4
,
0
,
size
<
60
?
60
:
size
);
memcpy
((
void
*
)
minic
.
tx_head
+
4
,
hdr
,
ETH_HEADER_SIZE
);
memcpy
((
void
*
)
minic
.
tx_head
+
4
+
ETH_HEADER_SIZE
,
payload
,
size
-
ETH_HEADER_SIZE
);
...
...
@@ -278,10 +308,11 @@ int minic_tx_frame(uint8_t *hdr, uint8_t *payload, uint32_t size, struct hw_time
{
TRACE_DEV
(
"minic_tx_frame: unmatched fid %d vs %d
\n
"
,
fid
,
tx_oob_val
);
}
EXPLODE_WR_TIMESTAMP
(
raw_ts
,
counter_r
,
counter_f
);
pps_gen_get_time
(
&
sec
,
&
nsec
);
if
(
counter_r
>
3
*
REF_CLOCK_FREQ_HZ
/
4
&&
nsec
<
REF_CLOCK_FREQ_HZ
/
4
)
if
(
counter_r
>
3
*
REF_CLOCK_FREQ_HZ
/
4
&&
nsec
<
250000000
)
sec
--
;
hwts
->
valid
=
ts_valid
;
...
...
@@ -291,7 +322,6 @@ int minic_tx_frame(uint8_t *hdr, uint8_t *payload, uint32_t size, struct hw_time
// TRACE_DEV("minic_tx_frame [%d bytes] TS: %d.%d valid %d\n", size, hwts->utc, hwts->nsec, hwts->valid);
minic
.
tx_count
++
;
}
tx_oob_val
++
;
...
...
include/hw/minic_regs.h
View file @
98aac55c
...
...
@@ -3,7 +3,7 @@
* File : minic_regs.h
* Author : auto-generated by wbgen2 from mini_nic.wb
* Created :
Wed Nov 2 02:18:19 2011
* Created :
Tue May 29 15:57:15 2012
* Standard : ANSI C
THIS FILE WAS GENERATED BY wbgen2 FROM SOURCE FILE mini_nic.wb
...
...
@@ -63,6 +63,8 @@
/* definitions for register: RX buffer size register */
/* definitions for register: RX buffer available words register */
/* definitions for register: TX timestamp register 0 */
/* definitions for field: Timestamp valid in reg: TX timestamp register 0 */
...
...
@@ -163,21 +165,23 @@
/* [0x8]: REG RX DMA Address */
#define MINIC_REG_RX_ADDR 0x00000008
/* [0xc]: REG RX buffer size register */
#define MINIC_REG_RX_AVAIL 0x0000000c
/* [0x10]: REG TX timestamp register 0 */
#define MINIC_REG_TSR0 0x00000010
/* [0x14]: REG TX timestamp register 1 */
#define MINIC_REG_TSR1 0x00000014
/* [0x18]: REG Debug register */
#define MINIC_REG_DBGR 0x00000018
/* [0x1c]: REG Memory protection reg */
#define MINIC_REG_MPROT 0x0000001c
/* [0x20]: REG Interrupt disable register */
#define MINIC_REG_EIC_IDR 0x00000020
/* [0x24]: REG Interrupt enable register */
#define MINIC_REG_EIC_IER 0x00000024
/* [0x28]: REG Interrupt mask register */
#define MINIC_REG_EIC_IMR 0x00000028
/* [0x2c]: REG Interrupt status register */
#define MINIC_REG_EIC_ISR 0x0000002c
#define MINIC_REG_RX_SIZE 0x0000000c
/* [0x10]: REG RX buffer available words register */
#define MINIC_REG_RX_AVAIL 0x00000010
/* [0x14]: REG TX timestamp register 0 */
#define MINIC_REG_TSR0 0x00000014
/* [0x18]: REG TX timestamp register 1 */
#define MINIC_REG_TSR1 0x00000018
/* [0x1c]: REG Debug register */
#define MINIC_REG_DBGR 0x0000001c
/* [0x20]: REG Memory protection reg */
#define MINIC_REG_MPROT 0x00000020
/* [0x40]: REG Interrupt disable register */
#define MINIC_REG_EIC_IDR 0x00000040
/* [0x44]: REG Interrupt enable register */
#define MINIC_REG_EIC_IER 0x00000044
/* [0x48]: REG Interrupt mask register */
#define MINIC_REG_EIC_IMR 0x00000048
/* [0x4c]: REG Interrupt status register */
#define MINIC_REG_EIC_ISR 0x0000004c
#endif
ptp-noposix
@
d9f2709b
Subproject commit d9f2709b65d95b9e079a32f285e9ea31a28d8bb4
revision.c
0 → 100644
View file @
98aac55c
const
char
*
build_revision
=
"c651ae0a9432441127943f4b8188396a022db919"
;
const
char
*
build_date
=
__DATE__
" "
__TIME__
;
wrc_main.c
View file @
98aac55c
...
...
@@ -19,10 +19,14 @@
///////////////////////////////////
//Calibration data (from EEPROM if available)
#ifdef WRPC_MASTER
int32_t
sfp_alpha
=
-
73622176
;
//default value if could not read EEPROM
#else
int32_t
sfp_alpha
=
73622176
;
//default value if could not read EEPROM
#endif
int32_t
sfp_deltaTx
=
0
;
int32_t
sfp_deltaRx
=
0
;
uint32_t
cal_phase_transition
=
7000
;
uint32_t
cal_phase_transition
=
595
;
//
7000;
///////////////////////////////////
#include "ptp-noposix/libptpnetif/ptpd_netif.h"
...
...
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