mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-28 02:35:28 +00:00
This adds a new pair of interfaces called producer and consumer which are simpler (in that they don't hold onto the underlying queue) than the stream interfaces. This makes it easier to share a single queue between the endpoints that will manipulate it. It was not possible to share a queue between two objects that implemented the in_stream and out_stream interfaces. This also adds a pair of adaptors that can convert a producer or consumer into a stream of the correct type. These adaptors will be used for existing code once the usb-stream and usart drivers are converted over to use the producer/consumer interfaces instead of the stream interfaces. Signed-off-by: Anton Staaf <robotboy@chromium.org> BRANCH=None BUG=None TEST=make buildall -j Change-Id: I42b4b1ac15cca28e1adc6d3cea315f15e17a0b4d Reviewed-on: https://chromium-review.googlesource.com/250941 Trybot-Ready: Anton Staaf <robotboy@chromium.org> Tested-by: Anton Staaf <robotboy@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org> Commit-Queue: Anton Staaf <robotboy@chromium.org>
81 lines
2.3 KiB
C
81 lines
2.3 KiB
C
/* Copyright (c) 2015 The Chromium OS Authors. All rights reserved.
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
#ifndef INCLUDE_STREAM_ADAPTOR_H
|
|
#define INCLUDE_STREAM_ADAPTOR_H
|
|
|
|
/* STM32 USART driver for Chrome EC */
|
|
|
|
#include "common.h"
|
|
#include "in_stream.h"
|
|
#include "out_stream.h"
|
|
#include "consumer.h"
|
|
#include "producer.h"
|
|
|
|
/*
|
|
* +..........+ +..........+------+...........+
|
|
* . .<------------->. | | .
|
|
* . Producer . +---------+ . Consumer | ISFP | In Stream .
|
|
* . .->| Queue |->. | | .
|
|
* +..........+ +---------+ +..........+------+...........+
|
|
*/
|
|
|
|
struct in_stream_from_producer {
|
|
struct consumer consumer;
|
|
struct in_stream in;
|
|
};
|
|
|
|
/*
|
|
*
|
|
*/
|
|
extern struct in_stream_ops const in_stream_from_producer_in_stream_ops;
|
|
extern struct consumer_ops const in_stream_from_producer_consumer_ops;
|
|
|
|
#define IN_STREAM_FROM_PRODUCER(NAME, PRODUCER, QUEUE, READY) \
|
|
struct in_stream_from_producer const NAME = { \
|
|
.consumer = { \
|
|
.producer = &PRODUCER, \
|
|
.queue = &QUEUE, \
|
|
.ops = &in_stream_from_producer_consumer_ops, \
|
|
}, \
|
|
.in = { \
|
|
.ready = READY, \
|
|
.ops = &in_stream_from_producer_in_stream_ops, \
|
|
}, \
|
|
};
|
|
|
|
/*
|
|
* +..........+ +..........+------+............+
|
|
* . .<------------->. | | .
|
|
* . Consumer . +---------+ . Producer | OSFC | Out Stream .
|
|
* . .<-| Queue |<-. | | .
|
|
* +..........+ +---------+ +..........+------+............+
|
|
*/
|
|
|
|
struct out_stream_from_consumer {
|
|
struct producer producer;
|
|
struct out_stream out;
|
|
};
|
|
|
|
/*
|
|
*
|
|
*/
|
|
extern struct out_stream_ops const out_stream_from_consumer_out_stream_ops;
|
|
extern struct producer_ops const out_stream_from_consumer_producer_ops;
|
|
|
|
#define OUT_STREAM_FROM_CONSUMER(NAME, CONSUMER, QUEUE, READY) \
|
|
struct out_stream_from_consumer const NAME = { \
|
|
.producer = { \
|
|
.consumer = &CONSUMER, \
|
|
.queue = &QUEUE, \
|
|
.ops = &out_stream_from_consumer_producer_ops, \
|
|
}, \
|
|
.out = { \
|
|
.ready = READY, \
|
|
.ops = &out_stream_from_consumer_out_stream_ops, \
|
|
}, \
|
|
};
|
|
|
|
#endif /* INCLUDE_STREAM_ADAPTOR_H */
|