-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
0.2.3 - Add FullDuplexBuffer interface
- Loading branch information
Showing
10 changed files
with
118 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
let gcc_suffix = '-12' | ||
let clang_suffix = '-15' | ||
|
||
let g:ale_c_clangformat_executable = 'clang-format' . clang_suffix | ||
|
||
let g:ale_c_cc_executable = 'gcc' . gcc_suffix | ||
let g:ale_cpp_cc_executable = 'g++' . gcc_suffix |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule config
updated
6 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,4 @@ description: Core C++ project utilities. | |
version: | ||
major: 0 | ||
minor: 2 | ||
patch: 2 | ||
patch: 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#pragma once | ||
|
||
#include "common.h" | ||
|
||
class SampleFdBuffer | ||
: public FullDuplexBuffer<SampleFdBuffer, depth, depth, element_t> | ||
{ | ||
public: | ||
inline void service_tx_impl(TxBuffer *buf) | ||
{ | ||
(void)buf; | ||
std::cout << "Serviced TX." << std::endl; | ||
} | ||
|
||
inline void service_rx_impl(RxBuffer *buf) | ||
{ | ||
(void)buf; | ||
std::cout << "Serviced RX." << std::endl; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#pragma once | ||
|
||
/* toolchain */ | ||
#include <iostream> | ||
#include <sstream> | ||
|
||
/* internal */ | ||
#include "../../buffer/FullDuplexBuffer.h" | ||
|
||
static constexpr std::size_t depth = 1024; | ||
using element_t = char; | ||
|
||
using namespace Coral; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* internal */ | ||
#include "SampleFdBuffer.h" | ||
|
||
int main(void) | ||
{ | ||
SampleFdBuffer buffer(true); | ||
|
||
/* Feed TX buffer. */ | ||
std::stringstream("Hello, world! (tx)\n") >> buffer.tx; | ||
|
||
/* Feed RX buffer. */ | ||
std::stringstream("Hello, world! (rx)\n") >> buffer.rx; | ||
std::cout << buffer.rx; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#pragma once | ||
|
||
/* internal */ | ||
#include "PcBuffer.h" | ||
|
||
namespace Coral | ||
{ | ||
|
||
template <class T, size_t tx_depth, size_t rx_depth, | ||
typename element_t = std::byte> | ||
class FullDuplexBuffer | ||
{ | ||
public: | ||
using TxBuffer = PcBuffer<tx_depth, element_t>; | ||
using RxBuffer = PcBuffer<rx_depth, element_t>; | ||
|
||
FullDuplexBuffer(bool _auto_service = false) | ||
: tx(_auto_service), rx(_auto_service) | ||
{ | ||
/* | ||
* Attempt to service the writing end whenever data is ready to be | ||
* written. | ||
*/ | ||
tx.set_data_available([this](TxBuffer *buf) { service_tx(buf); }); | ||
|
||
/* | ||
* Attempt to service the reading end whenever the read buffer has | ||
* space. | ||
*/ | ||
rx.set_space_available([this](RxBuffer *buf) { service_rx(buf); }); | ||
} | ||
|
||
/* | ||
* A method that can be polled at runtime if it's useful for hardware | ||
* resources to be interacted with regularly. | ||
*/ | ||
inline void dispatch(void) | ||
{ | ||
service_tx(&tx); | ||
service_rx(&rx); | ||
} | ||
|
||
inline void service_tx(TxBuffer *buf) | ||
{ | ||
static_cast<T *>(this)->service_tx_impl(buf); | ||
} | ||
|
||
inline void service_rx(RxBuffer *buf) | ||
{ | ||
static_cast<T *>(this)->service_rx_impl(buf); | ||
} | ||
|
||
TxBuffer tx; | ||
RxBuffer rx; | ||
}; | ||
|
||
} // namespace Coral |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters