diff options
author | Mary Ruthven <mruthven@chromium.org> | 2016-03-30 10:27:58 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-04-07 13:00:39 -0700 |
commit | fa643a9fc754e6a5c18181ecb928fa9a5c12e7ae (patch) | |
tree | 25419df8ec4a379f9eb9fc1108422625299102ca /chip/g/blob.c | |
parent | 55032aa1236dc4f85485147f5927cfaf513def98 (diff) | |
download | chrome-ec-fa643a9fc754e6a5c18181ecb928fa9a5c12e7ae.tar.gz |
cr50: add support for creating multiple serial endpoints
CR50 will need three serial endpoints for the streaming AP and EC UART
and exporting its own console through USB. This change adds a macro to
create endpoints that can be recognized by the usb_serial driver.
BUG=chrome-os-partner:50702
BRANCH=none
TEST=Verify "/dev/google/Cr50*/serial/Blob" prints capital letters when
lower case letters are input.
Change-Id: Iddf2c957a00dc3cd5448a6a00de2cf61ef5dd84c
Signed-off-by: Mary Ruthven <mruthven@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/336441
Tested-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Diffstat (limited to 'chip/g/blob.c')
-rw-r--r-- | chip/g/blob.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/chip/g/blob.c b/chip/g/blob.c new file mode 100644 index 0000000000..fde66aac9a --- /dev/null +++ b/chip/g/blob.c @@ -0,0 +1,74 @@ +/* Copyright 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. + */ + +/* Handle an opaque blob of data */ + +#include "common.h" +#include "console.h" +#include "consumer.h" +#include "queue.h" +#include "queue_policies.h" +#include "producer.h" +#include "task.h" +#include "usb-stream.h" + +#define CPRINTS(format, args...) cprints(CC_USB, format, ## args) + +struct consumer const blob_consumer; +struct usb_stream_config const usb_blob; + +static struct queue const blob_to_usb = QUEUE_DIRECT(64, uint8_t, + null_producer, + usb_blob.consumer); +static struct queue const usb_to_blob = QUEUE_DIRECT(64, uint8_t, + usb_blob.producer, + blob_consumer); + +USB_STREAM_CONFIG(usb_blob, + USB_IFACE_BLOB, + USB_STR_BLOB_NAME, + USB_EP_BLOB, + USB_MAX_PACKET_SIZE, + USB_MAX_PACKET_SIZE, + usb_to_blob, + blob_to_usb) + +static void blob_written(struct consumer const *consumer, size_t count) +{ + int i; + uint8_t buf[USB_MAX_PACKET_SIZE]; + + count = QUEUE_REMOVE_UNITS(consumer->queue, buf, count); + + CPRINTS("Received: count=%d buf=((%s))", count, buf); + + /* + * Just to have something to test to begin with, we'll + * implement "tr a-zA-Z A-Za-z" and return the result. + */ + for (i = 0; i < count; i++) { + char tmp = buf[i]; + + if (tmp >= 'a' && tmp <= 'z') + buf[i] = tmp - ('a' - 'A'); + else if (tmp >= 'A' && tmp <= 'Z') + buf[i] = tmp + ('a' - 'A'); + } + + count = QUEUE_ADD_UNITS(&blob_to_usb, buf, count); + CPRINTS("Sending: count=%d buf=((%s))", count, buf); +} + +static void blob_flush(struct consumer const *consumer) +{ +} + +struct consumer const blob_consumer = { + .queue = &usb_to_blob, + .ops = &((struct consumer_ops const) { + .written = blob_written, + .flush = blob_flush, + }), +}; |