2012-11-10 16:06:01 +00:00
|
|
|
/****************************************************************************
|
2021-12-13 21:28:23 +08:00
|
|
|
* libs/libc/stream/lib_lowoutstream.c
|
2012-11-10 16:06:01 +00:00
|
|
|
*
|
2024-09-25 14:05:00 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*
|
2021-04-02 09:22:52 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
|
* License. You may obtain a copy of the License at
|
2012-11-10 16:06:01 +00:00
|
|
|
*
|
2021-04-02 09:22:52 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2012-11-10 16:06:01 +00:00
|
|
|
*
|
2021-04-02 09:22:52 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
|
* under the License.
|
2012-11-10 16:06:01 +00:00
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Included Files
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_ARCH_LOWPUTC
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <nuttx/arch.h>
|
|
|
|
|
|
2015-12-29 17:31:17 -06:00
|
|
|
#include "libc.h"
|
2012-11-10 16:06:01 +00:00
|
|
|
|
2023-12-21 22:19:19 +08:00
|
|
|
/****************************************************************************
|
|
|
|
|
* Private Functions Prototypes
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static void lowoutstream_putc(FAR struct lib_outstream_s *self, int ch);
|
2024-11-09 17:10:17 +08:00
|
|
|
static ssize_t lowoutstream_puts(FAR struct lib_outstream_s *self,
|
|
|
|
|
FAR const void *buf, size_t len);
|
2023-12-21 22:19:19 +08:00
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Public Data
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
struct lib_outstream_s g_lowoutstream =
|
|
|
|
|
{
|
|
|
|
|
0,
|
|
|
|
|
lowoutstream_putc,
|
|
|
|
|
lowoutstream_puts,
|
|
|
|
|
lib_noflush
|
|
|
|
|
};
|
|
|
|
|
|
2012-11-10 16:06:01 +00:00
|
|
|
/****************************************************************************
|
|
|
|
|
* Private Functions
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: lowoutstream_putc
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2023-09-10 12:32:34 -07:00
|
|
|
static void lowoutstream_putc(FAR struct lib_outstream_s *self, int ch)
|
2012-11-10 16:06:01 +00:00
|
|
|
{
|
2023-09-10 12:32:34 -07:00
|
|
|
DEBUGASSERT(self);
|
2012-11-10 16:06:01 +00:00
|
|
|
|
2025-02-13 11:56:33 +08:00
|
|
|
up_lowputc(ch);
|
driver/serial: remove return value of up_putc()
modify the prototype of up_putc(): remove the return value
The architecture code does not care about the return value of up_putc(), so removing it saves two statements:
Before: After:
de4c: e52de004 push {lr} @ (str lr, [sp, #-4]!) | de4c: e52de004 push {lr} @ (str lr, [sp, #-4]!)
de50: e24dd014 sub sp, sp, #20 | de50: e24dd014 sub sp, sp, #20
de54: e58d0004 str r0, [sp, #4] | de54: e58d0004 str r0, [sp, #4]
de58: e30030f8 movw r3, #248 @ 0xf8 | de58: e30030f8 movw r3, #248 @ 0xf8
de5c: e3423000 movt r3, #8192 @ 0x2000 | de5c: e3423000 movt r3, #8192 @ 0x2000
de60: e58d300c str r3, [sp, #12] | de60: e58d300c str r3, [sp, #12]
de64: e59d1004 ldr r1, [sp, #4] | de64: e59d1004 ldr r1, [sp, #4]
de68: e59d000c ldr r0, [sp, #12] | de68: e59d000c ldr r0, [sp, #12]
de6c: ebfffe66 bl d80c <pl011_putc> | de6c: ebfffe66 bl d80c <pl011_putc>
de70: e59d3004 ldr r3, [sp, #4] | de70: e28dd014 add sp, sp, #20
de74: e1a00003 mov r0, r3 | de74: e49df004 pop {pc} @ (ldr pc, [sp], #4)
de78: e28dd014 add sp, sp, #20 |
de7c: e49df004 pop {pc} @ (ldr pc, [sp], #4) |
Signed-off-by: chao an <anchao@lixiang.com>
2024-10-25 17:58:49 +08:00
|
|
|
|
|
|
|
|
if (ch != EOF)
|
2012-11-10 16:06:01 +00:00
|
|
|
{
|
2023-09-10 12:32:34 -07:00
|
|
|
self->nput++;
|
2012-11-10 16:06:01 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-24 11:37:35 +08:00
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: lowoutstream_puts
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2024-11-09 17:10:17 +08:00
|
|
|
static ssize_t lowoutstream_puts(FAR struct lib_outstream_s *self,
|
|
|
|
|
FAR const void *buf, size_t len)
|
2023-02-24 11:37:35 +08:00
|
|
|
{
|
2025-02-13 11:56:33 +08:00
|
|
|
FAR const char *str = (FAR const char *)buf;
|
|
|
|
|
size_t idx = 0;
|
2023-09-10 12:32:34 -07:00
|
|
|
DEBUGASSERT(self);
|
2023-02-24 11:37:35 +08:00
|
|
|
|
2025-02-13 11:56:33 +08:00
|
|
|
while (str[idx] != 0 && idx < len)
|
|
|
|
|
{
|
|
|
|
|
lowoutstream_putc(self, str[idx]);
|
|
|
|
|
idx++;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-24 11:37:35 +08:00
|
|
|
return len;
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-10 16:06:01 +00:00
|
|
|
/****************************************************************************
|
|
|
|
|
* Public Functions
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: lib_lowoutstream
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* Initializes a stream for use with low-level, architecture-specific I/O.
|
|
|
|
|
*
|
2018-02-01 10:00:02 -06:00
|
|
|
* Input Parameters:
|
2016-05-18 12:49:07 -06:00
|
|
|
* stream - User allocated, uninitialized instance of struct
|
|
|
|
|
* lib_lowoutstream_s to be initialized.
|
2012-11-10 16:06:01 +00:00
|
|
|
*
|
|
|
|
|
* Returned Value:
|
|
|
|
|
* None (User allocated instance initialized).
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void lib_lowoutstream(FAR struct lib_outstream_s *stream)
|
|
|
|
|
{
|
2022-12-04 17:35:13 +08:00
|
|
|
stream->putc = lowoutstream_putc;
|
2023-02-24 11:37:35 +08:00
|
|
|
stream->puts = lowoutstream_puts;
|
2012-11-10 16:06:01 +00:00
|
|
|
stream->flush = lib_noflush;
|
|
|
|
|
stream->nput = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif /* CONFIG_ARCH_LOWPUTC */
|