Skip to content

Commit c55a011

Browse files
authored
Merge pull request #510 from tlevora/fix-eth-desring-alignment
Fix eth::DesRing alignment
2 parents d13db0c + 2ff9d72 commit c55a011

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/ethernet/eth.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,12 @@ use self::emac_consts::*;
6969
/// Note that Copy and Clone are derived to support initialising an
7070
/// array of TDes, but you may not move a TDes after its address has
7171
/// been given to the ETH_DMA engine.
72+
///
73+
/// Both order and alignment is required by the ETH peripheral. The repr(C)
74+
/// ensures that alignment of the members is 4 with no padding on the target
75+
/// platform.
7276
#[derive(Copy, Clone)]
73-
#[repr(C, packed)]
77+
#[repr(C)]
7478
struct TDes {
7579
tdes0: u32,
7680
tdes1: u32,
@@ -94,7 +98,6 @@ impl TDes {
9498
}
9599

96100
/// Store a ring of TDes and associated buffers
97-
#[repr(C, packed)]
98101
struct TDesRing<const TD: usize> {
99102
td: [TDes; TD],
100103
tbuf: [[u32; ETH_BUF_SIZE / 4]; TD],
@@ -187,7 +190,7 @@ impl<const TD: usize> TDesRing<TD> {
187190
self.td[x].tdes2 = (length as u32) & EMAC_TDES2_B1L;
188191

189192
// Create a raw pointer in place without an intermediate reference. Use
190-
// this to return a slice from the packed buffer
193+
// this to return a slice from the buffer
191194
let addr = ptr::addr_of_mut!(self.tbuf[x]) as *mut _;
192195
core::slice::from_raw_parts_mut(addr, len)
193196
}
@@ -203,8 +206,12 @@ impl<const TD: usize> TDesRing<TD> {
203206
/// Note that Copy and Clone are derived to support initialising an
204207
/// array of RDes, but you may not move a RDes after its address has
205208
/// been given to the ETH_DMA engine.
209+
///
210+
/// Both order and alignment is required by the ETH peripheral. The repr(C)
211+
/// ensures that alignment of the members is 4 with no padding on the target
212+
/// platform.
206213
#[derive(Copy, Clone)]
207-
#[repr(C, packed)]
214+
#[repr(C)]
208215
struct RDes {
209216
rdes0: u32,
210217
rdes1: u32,
@@ -239,7 +246,6 @@ impl RDes {
239246
}
240247

241248
/// Store a ring of RDes and associated buffers
242-
#[repr(C, packed)]
243249
struct RDesRing<const RD: usize> {
244250
rd: [RDes; RD],
245251
rbuf: [[u32; ETH_BUF_SIZE / 4]; RD],

0 commit comments

Comments
 (0)