34 void Mailbox::Init(
void* pvBuffer_, uint16_t u16BufferSize_, uint16_t u16ElementSize_)
43 m_u16Count = (u16BufferSize_ / u16ElementSize_);
64 auto* pclNew = AutoAlloc::NewObject<Mailbox, AutoAllocType::MailBox>();
74 AutoAlloc::DestroyObject<Mailbox, AutoAllocType::MailBox>(pclNew);
78 pclNew->Init(pvBuffer, u16BufferSize_, u16ElementSize_);
93 return Receive_i(pvData_,
false, u32TimeoutMS_);
107 return Receive_i(pvData_,
true, u32TimeoutMS_);
114 return Send_i(pvData_,
false, 0);
121 return Send_i(pvData_,
true, 0);
128 return Send_i(pvData_,
false, u32TimeoutMS_);
135 return Send_i(pvData_,
true, u32TimeoutMS_);
143 void* pvDst =
nullptr;
174 }
else if (0u != u32TimeoutMS_) {
200 auto* pvSrc = (
const void*){};
uint16_t m_u16Count
Count of items in the mailbox.
void * GetHeadPointer(void)
GetHeadPointer Return a pointer to the current head of the mailbox's internal circular buffer...
void * GetTailPointer(void)
GetTailPointer Return a pointer to the current tail of the mailbox's internal circular buffer...
void MoveHeadForward(void)
MoveHeadForward Move the head index forward one element.
void Init(void *pvBuffer_, uint16_t u16BufferSize_, uint16_t u16ElementSize_)
Init Initialize the mailbox object prior to its use. This must be called before any calls can be made...
void CopyData(const void *src_, void *dst_, uint16_t len_)
CopyData Perform a direct byte-copy from a source to a destination object.
void MoveHeadBackward(void)
MoveHeadBackward Move the head index backward one element.
void Receive(void *pvData_)
Receive Read one envelope from the head of the mailbox. If the mailbox is currently empty...
bool Receive_i(void *pvData_, bool bTail_, uint32_t u32WaitTimeMS_)
Receive_i Internal method which implements all Read() methods in the class.
Semaphore m_clSendSem
Binary semaphore for send-blocked threads.
bool SendTail(void *pvData_)
SendTail Send an envelope to the mailbox. This safely copies the data contents of the datastructure t...
void MoveTailForward(void)
MoveTailForward Move the tail index forward one element.
Single include file given to users of the Mark3 Kernel API.
uint16_t m_u16Tail
Current tail index.
volatile uint16_t m_u16Free
Current number of free slots in the mailbox.
Semaphore m_clRecvSem
Counting semaphore used to synchronize threads on the object.
uint16_t m_u16Head
Current head index.
void MoveTailBackward(void)
MoveTailBackward Move the tail index backward one element.
The CriticalGuard class. This class provides an implemention of RAII for critical sections...
void Pend()
Decrement the semaphore count. If the count is zero, the calling Thread will block until the semaphor...
The Mailbox class. This class implements an IPC mechnism based on sending/receiving envelopes contain...
static void * NewRawData(size_t sSize_)
NewRawData Attempt to allocate a blob of raw data from the heap.
bool Post()
Increment the semaphore count. If the semaphore count is zero at the time this is called...
bool Send_i(const void *pvData_, bool bTail_, uint32_t u32TimeoutMS_)
Send_i Internal method which implements all Send() methods in the class.
#define PANIC_ACTIVE_MAILBOX_DESCOPED
void Init(uint16_t u16InitVal_, uint16_t u16MaxVal_)
Initialize a semaphore before use. Must be called before attempting post/pend operations on the objec...
const void * m_pvBuffer
Pointer to the data-buffer managed by this mailbox.
bool Send(void *pvData_)
Send Send an envelope to the mailbox. This safely copies the data contents of the datastructure to th...
uint16_t m_u16ElementSize
Size of the objects tracked in this mailbox.
void ReceiveTail(void *pvData_)
ReceiveTail Read one envelope from the tail of the mailbox. If the mailbox is currently empty...
static void Panic(uint16_t u16Cause_)
Panic Cause the kernel to enter its panic state.
static bool SetScheduler(bool bEnable_)
SetScheduler Set the active state of the scheduler. When the scheduler is disabled, the next thread is never set; the currently running thread will run forever until the scheduler is enabled again. Care must be taken to ensure that we don't end up trying to block while the scheduler is disabled, otherwise the system ends up in an unusable state.