@@ -149,6 +149,21 @@ namespace klib::core::lpc178x::io {
149149 return true ;
150150 }
151151
152+ /* *
153+ * @brief Helper to increment the tx producer after writing
154+ * to the buffer of the description
155+ *
156+ * @param index
157+ */
158+ static void increment_tx_producer (const uint32_t index) {
159+ // move to the next index after writing
160+ const auto max = (Emac::port->TXDESCRIPTORNUMBER + 1 );
161+ const auto next = index + 1 ;
162+
163+ // limit the index to the max indexes we have
164+ Emac::port->TXPRODUCEINDEX = next % max;
165+ }
166+
152167 public:
153168 /* *
154169 * @brief Init the lpc178x emac peripheral.
@@ -452,7 +467,7 @@ namespace klib::core::lpc178x::io {
452467 * @param tx
453468 * @return result
454469 */
455- static bool write (const std::span<uint16_t > tx) {
470+ static bool write (const std::span<uint8_t > tx) {
456471 // get the produce index
457472 const uint32_t index = Emac::port->TXPRODUCEINDEX ;
458473
@@ -462,17 +477,44 @@ namespace klib::core::lpc178x::io {
462477 );
463478
464479 // write the data to the buffer
465- std::copy_n (tx.data (), tx.size (), reinterpret_cast <uint16_t *>(desc.packet ));
480+ std::copy_n (tx.data (), tx.size (), reinterpret_cast <uint8_t *>(desc.packet ));
466481
467482 // write the size to the control
468483 desc.control = (0x1 << 30 ) | tx.size_bytes ();
469484
470- // move to the next index after writing
471- const auto max = (Emac::port->TXDESCRIPTORNUMBER + 1 );
472- const auto next = index + 1 ;
485+ // increment the tx pruducer after writing
486+ increment_tx_producer (index);
473487
474- // limit the index to the max indexes we have
475- Emac::port->TXPRODUCEINDEX = next % max;
488+ return true ;
489+ }
490+
491+ /* *
492+ * @brief Write into a tx buffer
493+ *
494+ * @param tx
495+ * @return result
496+ */
497+ static bool write (const multispan<const uint8_t >& tx) {
498+ // get the produce index
499+ const uint32_t index = Emac::port->TXPRODUCEINDEX ;
500+
501+ // get a reference to the descriptor
502+ descriptor& desc = (
503+ reinterpret_cast <descriptor*>(Emac::port->TXDESCRIPTOR )[index]
504+ );
505+
506+ // write the data to the buffer. For the multispan we need
507+ // to fall back to a for loop as the array subscripting
508+ // operator is overloaded as it can be non contiguous
509+ for (uint32_t i = 0 ; i < tx.size_bytes (); i++) {
510+ desc.packet [i] = tx[i];
511+ }
512+
513+ // write the size to the control
514+ desc.control = (0x1 << 30 ) | tx.size_bytes ();
515+
516+ // increment the tx pruducer after writing
517+ increment_tx_producer (index);
476518
477519 return true ;
478520 }
0 commit comments