Mark3 Realtime Kernel
streamer.h
Go to the documentation of this file.
1 /*===========================================================================
2  _____ _____ _____ _____
3  ___| _|__ __|_ |__ __|__ |__ __| __ |__ ______
4 | \ / | || \ || | || |/ / ||___ |
5 | \/ | || \ || \ || \ ||___ |
6 |__/\__/|__|_||__|\__\ __||__|\__\ __||__|\__\ __||______|
7  |_____| |_____| |_____| |_____|
8 
9 --[Mark3 Realtime Platform]--------------------------------------------------
10 
11 Copyright (c) 2012 - 2019 m0slevin, all rights reserved.
12 See license.txt for more information
13 =========================================================================== */
20 #include "kerneltypes.h"
21 #include "mark3.h"
22 
23 #pragma once
24 
25 namespace Mark3
26 {
27 //---------------------------------------------------------------------------
35 class Streamer
36 {
37 public:
46  void Init(uint8_t* pau8Buffer_, uint16_t u16Size_);
47 
56  bool Read(uint8_t* pu8Data_);
57 
67  uint16_t Read(uint8_t* pu8Data_, uint16_t u16Len_);
68 
77  bool Write(uint8_t u8Data_);
78 
87  uint16_t Write(const uint8_t* pu8Data_, uint16_t u16Len_);
88 
109  bool Claim(uint8_t** pu8Addr_);
110 
120  void Lock(uint8_t* pu8LockAddr_);
121 
128  void Unlock(void);
129 
134  uint16_t GetAvailable(void) { return m_u16Size; }
139  bool CanRead(void);
140 
145  bool CanWrite(void);
146 
151  bool IsEmpty(void);
152 
153 private:
154  uint8_t* m_pau8Buffer;
155  uint8_t* m_pu8LockAddr;
156 
157  uint16_t m_u16Size;
158  uint16_t m_u16Avail;
159  uint16_t m_u16Head;
160  uint16_t m_u16Tail;
161 };
162 } // namespace Mark3
Basic data type primatives used throughout the OS.
void Init(uint8_t *pau8Buffer_, uint16_t u16Size_)
Init. Initialize the Streamer object prior to its use, providing a blob of memory for the object to m...
Definition: streamer.cpp:27
uint8_t * m_pau8Buffer
Pointer to the buffer managed in this object.
Definition: streamer.h:154
void Unlock(void)
Unlock. Reset the lock pointer in the object, allowing a consumer to read any previously unavailable ...
Definition: streamer.cpp:257
bool Write(uint8_t u8Data_)
Write. Write a byte of data into the stream.
Definition: streamer.cpp:120
uint16_t m_u16Size
Size of the stream's circular buffer (in bytes)
Definition: streamer.h:157
uint16_t m_u16Avail
Number of bytes free in the stream.
Definition: streamer.h:158
bool Claim(uint8_t **pu8Addr_)
Claim. Claim a byte of data for writing, without actually writing into it. When the writer is ready t...
Definition: streamer.cpp:224
Definition: atomic.cpp:23
uint16_t GetAvailable(void)
GetAvailable.
Definition: streamer.h:134
uint16_t m_u16Tail
Current tail index (read from) of the stream.
Definition: streamer.h:160
Single include file given to users of the Mark3 Kernel API.
bool Read(uint8_t *pu8Data_)
Read. Read a byte of data from the stream, if available.
Definition: streamer.cpp:38
uint16_t m_u16Head
Current head index (write to) of the stream.
Definition: streamer.h:159
uint8_t * m_pu8LockAddr
Address of the lock point in the stream.
Definition: streamer.h:155
bool IsEmpty(void)
IsEmpty.
Definition: streamer.cpp:264
void Lock(uint8_t *pu8LockAddr_)
Lock. When the lock is set, a client can neither read from, or write to the buffer at the index speci...
Definition: streamer.cpp:250
bool CanRead(void)
CanRead.
Definition: streamer.cpp:200
bool CanWrite(void)
CanWrite.
Definition: streamer.cpp:211
The Streamer class. This class implements a circular byte-buffer with thread and interrupt safe metho...
Definition: streamer.h:35