SatCat5
message_buffer.h
1 // Copyright 2024-2025 The Aerospace Corporation.
3 // This file is a part of SatCat5, licensed under CERN-OHL-W v2 or later.
5 // PacketBuffer to MessageBuffer adapter.
6 
7 #pragma once
8 
9 extern "C" {
10  #include <FreeRTOS.h>
11  #include <message_buffer.h>
12  #include <semphr.h>
13 };
14 
15 #include <satcat5/eth_switch.h>
16 #include <satcat5/io_readable.h>
17 #include <satcat5/io_writeable.h>
18 #include <satcat5/pkt_buffer.h>
19 
20 namespace satcat5 {
21  namespace freertos {
23  class MessageCopy final : public satcat5::io::EventListener {
24  public:
27  MessageBufferHandle_t* msg_buff_handle,
28  SemaphoreHandle_t* msg_buff_semphr
29  );
30  ~MessageCopy() SATCAT5_OPTIONAL_DTOR;
31  protected:
32  // Override io::EventListener handlers.
33  void data_rcvd(satcat5::io::Readable* src) override;
34  void data_unlink(satcat5::io::Readable* src) override;
35 
36  // Pointers to source, message buffer, and semaphore.
37  satcat5::io::Readable* m_src;
38  MessageBufferHandle_t* const m_handle;
39  SemaphoreHandle_t* const m_mutex;
40  };
41 
48  public:
52  u8* txbuff, unsigned txbytes,
53  MessageBufferHandle_t* msg_buff_handle,
54  SemaphoreHandle_t* msg_buff_semphr);
55 
56  private:
57  // Working buffer accumulates each packet.
59 
60  // Copy complete packets to the FreeRTOS buffer.
62  };
63 
70  public:
73  MessageBufferHandle_t* msg_buff_handle,
74  SemaphoreHandle_t* msg_buff_semphr);
75 
76  protected:
77  // Copy complete packets to the FreeRTOS buffer.
79  };
80  } // namespace freertos
81 } // namespace satcat5
A shared-memory Ethernet switch based on the MultiBuffer class.
Definition: eth_switch.h:93
Generic packetized I/O interface for use with SwitchCore.
Definition: eth_switch.h:245
PacketBuffer to MessageBuffer adapter.
MessageBuffer(u8 *txbuff, unsigned txbytes, MessageBufferHandle_t *msg_buff_handle, SemaphoreHandle_t *msg_buff_semphr)
Constructor requires a working buffer, plus handles for the FreeRTOS MessageBuffer and Semaphore.
SwitchPort to FreeRTOS MessageBuffer adapter.
Copy data from a Readable source to a FreeRTOS MessageBuffer.
void data_rcvd(satcat5::io::Readable *src) override
The data_rcvd() callback is polled whenever data is available.
void data_unlink(satcat5::io::Readable *src) override
Unlink this EventListener from the designated source, because the designated Readable object is being...
Event-handler interface for newly received data.
Definition: io_readable.h:43
The PacketBuffer class is a wrapper for a circular buffer, with optional logic to support retention o...
Definition: pkt_buffer.h:66
Abstract API for reading byte-streams and packets.
Definition: io_readable.h:68
Wrapper class for forwarding writes to another object.
Definition: io_writeable.h:218
Software-defined Ethernet switch.
"Readable" I/O interface core definitions
"Writeable" I/O interface core definitions