Skip to content

Commit 66fb32f

Browse files
committed
LPC178x emac changed read to return non owning std::span
1 parent 18b3b86 commit 66fb32f

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

targets/core/nxp/lpc178x/emac.hpp

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ namespace klib::core::lpc178x::io {
366366
*
367367
* @param config
368368
*/
369-
static void configure(const klib::io::ethernet::link_config config) {
369+
static void configure(const klib::io::ethernet::link_config& config) {
370370
// configure the modes we received from the phy
371371
if (config.full_duplex) {
372372
// enable full duplex on the MAC
@@ -408,33 +408,26 @@ namespace klib::core::lpc178x::io {
408408
}
409409

410410
/**
411-
* @brief Reads data into the provided buffer
411+
* @brief Get a non owning span to the raw buffer we received
412412
*
413-
* @param rx
414-
* @return uint32_t
413+
* @return const std::span<const uint8_t>
415414
*/
416-
static uint32_t read(const std::span<uint16_t> rx, const uint32_t offset) {
415+
static const std::span<const uint8_t> read() {
417416
// get the consume index
418417
const uint32_t index = Emac::port->RXCONSUMEINDEX;
419418

420419
// get the amount of bytes we received in this buffer
421-
const uint32_t length = (klib::min(
422-
static_cast<uint32_t>(
423-
(reinterpret_cast<receive_status*>(Emac::port->RXSTATUS)[index].info) & 0x7ff
424-
),
425-
rx.size_bytes()
420+
const uint32_t length = (static_cast<uint32_t>(
421+
(reinterpret_cast<receive_status*>(Emac::port->RXSTATUS)[index].info) & 0x7ff
426422
));
427423

428424
// get the pointer to the buffer
429425
const uint8_t* buffer = (
430426
reinterpret_cast<descriptor*>(Emac::port->RXDESCRIPTOR)[index].packet
431427
);
432428

433-
// copy all the data from the buffer into the user provided buffer
434-
std::copy_n(buffer + offset, length, reinterpret_cast<uint8_t*>(rx.data()));
435-
436429
// return the full length of the packet
437-
return length;
430+
return {buffer, length};
438431
}
439432

440433
/**

0 commit comments

Comments
 (0)