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
31
Issues
31
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
fbda64cf
Commit
fbda64cf
authored
May 31, 2012
by
Grzegorz Daniluk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
greg-testing: minic rx circular buffer
parent
92eee579
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
112 additions
and
75 deletions
+112
-75
minic.c
dev/minic.c
+89
-56
minic_regs.h
include/hw/minic_regs.h
+22
-18
wrc_main.c
wrc_main.c
+1
-1
No files found.
dev/minic.c
View file @
fbda64cf
...
...
@@ -73,24 +73,47 @@ static void minic_new_rx_buffer()
{
minic
.
rx_head
=
minic
.
rx_base
;
mprintf
(
"minic: new rx buffer
\n
"
);
minic_writel
(
MINIC_REG_MCR
,
0
);
minic_writel
(
MINIC_REG_RX_ADDR
,
(
uint32_t
)
minic
.
rx_base
);
minic_writel
(
MINIC_REG_RX_
AVAIL
,
(
minic
.
rx_size
-
MINIC_MTU
)
>>
2
);
minic_writel
(
MINIC_REG_RX_
SIZE
,
minic
.
rx_size
>>
2
);
//
(minic.rx_size - MINIC_MTU) >> 2);
// TRACE_DEV("Sizeof: %d Size : %d Avail: %d\n", minic.rx_size, (minic.rx_size - MINIC_MTU) >> 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_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.tx_size - MINIC_MTU) >> 2;
minic_writel
(
MINIC_REG_TX_ADDR
,
(
uint32_t
)
minic
.
tx_base
);
}
static
uint8_t
*
minic_rx_memcpy
(
uint8_t
*
dst
,
uint8_t
*
src
,
uint32_t
size
)
{
uint32_t
part
;
//if src is outside the circular buffer, bring it back to the beginning
src
=
(
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
(
dst
+
part
,
minic
.
rx_base
,
size
-
part
);
return
dst
;
}
void
minic_init
()
...
...
@@ -140,27 +163,31 @@ 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");
// 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
;
//mprintf("%s: rx_base = %x\n", __FUNCTION__, (uint32_t)minic.rx_base>>2);
//mprintf("%s: rx_head= %x\n", __FUNCTION__, (uint32_t)minic.rx_head>>2);
//mprintf("%s: rx_size=%x\n", __FUNCTION__, (uint32_t)minic.rx_size>>2);
//mprintf("%s: rx_end = %x\n", __FUNCTION__, (((uint32_t)minic.rx_base)>>2) + (minic.rx_size>>2));
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
))
...
...
@@ -174,8 +201,8 @@ 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
(
&
raw_ts
,
(
uint8_t
*
)
minic
.
rx_head
+
payload_size
+
6
,
4
);
/* fixme: ugly way of doing unaligned read */
minic_rx_
memcpy
(
&
dhdr
,
(
uint8_t
*
)
minic
.
rx_head
+
payload_size
+
4
,
2
);
EXPLODE_WR_TIMESTAMP
(
raw_ts
,
counter_r
,
counter_f
);
pps_gen_get_time
(
&
utc
,
&
counter_ppsg
);
...
...
@@ -199,26 +226,32 @@ int minic_rx_frame(uint8_t *hdr, uint8_t *payload, uint32_t buf_size, struct hw_
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
;
//mprintf(" packet OK\n")
;
}
else
{
minic
.
rx_head
+=
num_words
;
//mprintf(" error in packet\n");
n_recvd
=
-
1
;
}
minic_rxbuf_free
(
num_words
);
minic
.
rx_head
=
(
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
;
//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? */
//mprintf("minic: cur_avail=%d, minic.rx_size=%d\n", cur_avail, minic.rx_size>>2);
if
(
cur_avail
==
(
minic
.
rx_size
>>
2
)
)
/*empty buffer->no more received packets*/
{
//mprintf("minic: nothing new in the buffer\n");
if
(
minic_readl
(
MINIC_REG_MCR
)
&
MINIC_MCR_RX_FULL
)
minic_new_rx_buffer
();
minic_writel
(
MINIC_REG_EIC_ISR
,
MINIC_EIC_ISR_RX
);
}
// TRACE_DEV("minic: num_rx %d\n", n_recvd);
// TRACE_DEV("minic: num_rx %d\n", n_recvd);
return
n_recvd
;
}
...
...
include/hw/minic_regs.h
View file @
fbda64cf
...
...
@@ -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
wrc_main.c
View file @
fbda64cf
...
...
@@ -73,7 +73,7 @@ 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