blob: d553331e2fcbd9d11f3d8b1fb64963847fcbf541 [file] [log] [blame]
pankore6a3c36c2022-07-28 00:56:06 +08001/*
2 *
3 * Copyright (c) 2020 Project CHIP Authors
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/**
19 * @file
20 * Source implementation of an input / output stream for zehpyr targets.
21 */
22
23#include <lib/shell/Engine.h>
24#include <lib/shell/streamer.h>
pankorece307eb2023-05-11 01:52:22 +080025#include <platform/CHIPDeviceLayer.h>
pankore6a3c36c2022-07-28 00:56:06 +080026
27#include <stdio.h>
28#include <string.h>
29
pankorece307eb2023-05-11 01:52:22 +080030extern QueueHandle_t shell_queue;
pankore6a3c36c2022-07-28 00:56:06 +080031
32namespace chip {
33namespace Shell {
34namespace {
35
pankore6a3c36c2022-07-28 00:56:06 +080036int streamer_ameba_init(streamer_t * streamer)
37{
pankorece307eb2023-05-11 01:52:22 +080038 // freertos queue should be initialized in ameba sdk
39 if (shell_queue == NULL)
40 {
41 // queue not initialized
42 return -1;
43 }
44
pankore6a3c36c2022-07-28 00:56:06 +080045 return 0;
46}
47
48ssize_t streamer_ameba_read(streamer_t * streamer, char * buffer, size_t length)
49{
pankorece307eb2023-05-11 01:52:22 +080050 BaseType_t lineReceived = xQueueReceive(shell_queue, buffer, pdMS_TO_TICKS(10));
51 if (lineReceived == pdTRUE)
pankore6a3c36c2022-07-28 00:56:06 +080052 {
pankorece307eb2023-05-11 01:52:22 +080053 return length;
pankore6a3c36c2022-07-28 00:56:06 +080054 }
pankorece307eb2023-05-11 01:52:22 +080055
56 return 0;
pankore6a3c36c2022-07-28 00:56:06 +080057}
58
59ssize_t streamer_ameba_write(streamer_t * streamer, const char * buffer, size_t length)
60{
61 (void) streamer;
pankorece307eb2023-05-11 01:52:22 +080062 printf("[shell] %s\r\n", buffer);
63 return length;
pankore6a3c36c2022-07-28 00:56:06 +080064}
65
66static streamer_t streamer_ameba = {
67 .init_cb = streamer_ameba_init,
68 .read_cb = streamer_ameba_read,
69 .write_cb = streamer_ameba_write,
70};
71} // namespace
72
73streamer_t * streamer_get(void)
74{
75 return &streamer_ameba;
76}
77
78} // namespace Shell
79} // namespace chip