pankore | 6a3c36c | 2022-07-28 00:56:06 +0800 | [diff] [blame] | 1 | /* |
| 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> |
pankore | ce307eb | 2023-05-11 01:52:22 +0800 | [diff] [blame] | 25 | #include <platform/CHIPDeviceLayer.h> |
pankore | 6a3c36c | 2022-07-28 00:56:06 +0800 | [diff] [blame] | 26 | |
| 27 | #include <stdio.h> |
| 28 | #include <string.h> |
| 29 | |
pankore | ce307eb | 2023-05-11 01:52:22 +0800 | [diff] [blame] | 30 | extern QueueHandle_t shell_queue; |
pankore | 6a3c36c | 2022-07-28 00:56:06 +0800 | [diff] [blame] | 31 | |
| 32 | namespace chip { |
| 33 | namespace Shell { |
| 34 | namespace { |
| 35 | |
pankore | 6a3c36c | 2022-07-28 00:56:06 +0800 | [diff] [blame] | 36 | int streamer_ameba_init(streamer_t * streamer) |
| 37 | { |
pankore | ce307eb | 2023-05-11 01:52:22 +0800 | [diff] [blame] | 38 | // freertos queue should be initialized in ameba sdk |
| 39 | if (shell_queue == NULL) |
| 40 | { |
| 41 | // queue not initialized |
| 42 | return -1; |
| 43 | } |
| 44 | |
pankore | 6a3c36c | 2022-07-28 00:56:06 +0800 | [diff] [blame] | 45 | return 0; |
| 46 | } |
| 47 | |
| 48 | ssize_t streamer_ameba_read(streamer_t * streamer, char * buffer, size_t length) |
| 49 | { |
pankore | ce307eb | 2023-05-11 01:52:22 +0800 | [diff] [blame] | 50 | BaseType_t lineReceived = xQueueReceive(shell_queue, buffer, pdMS_TO_TICKS(10)); |
| 51 | if (lineReceived == pdTRUE) |
pankore | 6a3c36c | 2022-07-28 00:56:06 +0800 | [diff] [blame] | 52 | { |
pankore | ce307eb | 2023-05-11 01:52:22 +0800 | [diff] [blame] | 53 | return length; |
pankore | 6a3c36c | 2022-07-28 00:56:06 +0800 | [diff] [blame] | 54 | } |
pankore | ce307eb | 2023-05-11 01:52:22 +0800 | [diff] [blame] | 55 | |
| 56 | return 0; |
pankore | 6a3c36c | 2022-07-28 00:56:06 +0800 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | ssize_t streamer_ameba_write(streamer_t * streamer, const char * buffer, size_t length) |
| 60 | { |
| 61 | (void) streamer; |
pankore | ce307eb | 2023-05-11 01:52:22 +0800 | [diff] [blame] | 62 | printf("[shell] %s\r\n", buffer); |
| 63 | return length; |
pankore | 6a3c36c | 2022-07-28 00:56:06 +0800 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | static 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 | |
| 73 | streamer_t * streamer_get(void) |
| 74 | { |
| 75 | return &streamer_ameba; |
| 76 | } |
| 77 | |
| 78 | } // namespace Shell |
| 79 | } // namespace chip |