Skip to content

Commit

Permalink
0.2.3 - Add FullDuplexBuffer interface
Browse files Browse the repository at this point in the history
  • Loading branch information
vkottler committed Oct 26, 2023
1 parent ff62911 commit 2e29830
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 16 deletions.
3 changes: 3 additions & 0 deletions .vimrc
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<!--
=====================================
generator=datazen
version=3.1.2
hash=b09ffed8f96323afef69e5805e0d454f
version=3.1.4
hash=385f949b204867518742861977180695
=====================================
-->

# coral ([0.2.2](https://github.com/vkottler/coral/releases/tag/0.2.2))
# coral ([0.2.3](https://github.com/vkottler/coral/releases/tag/0.2.3))

[![codecov](https://codecov.io/gh/vkottler/coral/branch/master/graph/badge.svg)](https://codecov.io/gh/vkottler/coral)
![Build Status](https://github.com/vkottler/coral/actions/workflows/yambs-project.yml/badge.svg)
Expand Down
2 changes: 1 addition & 1 deletion local/configs/project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ description: Core C++ project utilities.
version:
major: 0
minor: 2
patch: 2
patch: 3
20 changes: 20 additions & 0 deletions src/apps/buffer/SampleFdBuffer.h
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;
}
};
13 changes: 13 additions & 0 deletions src/apps/buffer/common.h
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;
16 changes: 16 additions & 0 deletions src/apps/buffer/test_full_duplex_buffer.cc
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;
}
9 changes: 1 addition & 8 deletions src/apps/buffer/test_pc_buffer.cc
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
/* toolchain */
#include <cassert>
#include <iostream>
#include <limits>
#include <sstream>
#include <stdio.h>

/* internal */
#include "../../buffer/PcBuffer.h"

static constexpr std::size_t depth = 1024;
using element_t = char;

using namespace Coral;
#include "common.h"

using Buffer = PcBuffer<depth, element_t>;

Expand Down
57 changes: 57 additions & 0 deletions src/buffer/FullDuplexBuffer.h
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
6 changes: 3 additions & 3 deletions yambs.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# =====================================
# generator=datazen
# version=3.1.2
# hash=0be48a27b528ad11ed38b581f40b9443
# version=3.1.4
# hash=cd30ca828c268bf5b3847d3052de73df
# =====================================
---
project:
name: coral

github: {owner: &self vkottler}
version: {major: 0, minor: 2, patch: 2}
version: {major: 0, minor: 2, patch: 3}
variants:
clang:
suffix: &clang_version "-15"
Expand Down

0 comments on commit 2e29830

Please sign in to comment.