2012-11-10 17:06:01 +01:00
|
|
|
/****************************************************************************
|
2018-05-29 21:21:26 +02:00
|
|
|
* libs/libc/termios/lib_tcsetattr.c
|
2012-11-10 17:06:01 +01:00
|
|
|
*
|
2021-03-02 15:54:21 +01: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 17:06:01 +01:00
|
|
|
*
|
2021-03-02 15:54:21 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2012-11-10 17:06:01 +01:00
|
|
|
*
|
2021-03-02 15:54:21 +01: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 17:06:01 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
|
|
|
#include <termios.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <nuttx/serial/tioctl.h>
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: tcsetattr
|
|
|
|
*
|
2018-02-01 19:03:55 +01:00
|
|
|
* Description:
|
2012-11-10 17:06:01 +01:00
|
|
|
* The tcsetattr() function sets the parameters associated with the
|
|
|
|
* terminal referred to by the open file descriptor 'fd' from the termios
|
|
|
|
* structure referenced by 'termiop' as follows:
|
|
|
|
*
|
|
|
|
* If 'options' is TCSANOW, the change will occur immediately.
|
|
|
|
*
|
|
|
|
* If 'options' is TCSADRAIN, the change will occur after all output
|
2021-03-02 14:33:27 +01:00
|
|
|
* written to 'fd' is transmitted. This function should be used when
|
|
|
|
* changing parameters that affect output.
|
2012-11-10 17:06:01 +01:00
|
|
|
*
|
|
|
|
* If 'options' is TCSAFLUSH, the change will occur after all
|
|
|
|
* output written to 'fd' is transmitted, and all input so far received but
|
|
|
|
* not read will be discarded before the change is made.
|
|
|
|
*
|
|
|
|
* The tcsetattr() function will return successfully if it was able to
|
|
|
|
* perform any of the requested actions, even if some of the requested
|
|
|
|
* actions could not be performed. It will set all the attributes that
|
|
|
|
* implementation supports as requested and leave all the attributes not
|
|
|
|
* supported by the implementation unchanged. If no part of the request
|
|
|
|
* can be honoured, it will return -1 and set errno to EINVAL.
|
|
|
|
*
|
|
|
|
* The effect of tcsetattr() is undefined if the value of the termios
|
|
|
|
* structure pointed to by 'termiop' was not derived from the result of
|
|
|
|
* a call to tcgetattr() on 'fd'; an application should modify only fields
|
|
|
|
* and flags defined by this specification between the call to tcgetattr()
|
|
|
|
* and tcsetattr(), leaving all other fields and flags unmodified.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
*
|
|
|
|
* Upon successful completion, 0 is returned. Otherwise, -1 is returned
|
|
|
|
* and errno is set to indicate the error. The following errors may be
|
|
|
|
* reported:
|
|
|
|
*
|
2014-04-13 22:32:20 +02:00
|
|
|
* - EBADF: The 'fd' argument is not a valid file descriptor.
|
|
|
|
* - EINTR: A signal interrupted tcsetattr().
|
2012-11-10 17:06:01 +01:00
|
|
|
* - EINVAL: The 'options' argument is not a supported value, or
|
|
|
|
* an attempt was made to change an attribute represented in the
|
2014-04-13 22:32:20 +02:00
|
|
|
* termios structure to an unsupported value.
|
|
|
|
* - ENOTTY: The file associated with 'fd' is not a terminal.
|
2012-11-10 17:06:01 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int tcsetattr(int fd, int options, FAR const struct termios *termiosp)
|
|
|
|
{
|
2021-05-07 09:39:08 +02:00
|
|
|
if (options != TCSANOW)
|
2012-11-10 17:06:01 +01:00
|
|
|
{
|
2021-05-07 09:39:08 +02:00
|
|
|
tcdrain(fd);
|
2012-11-10 17:06:01 +01:00
|
|
|
}
|
2014-10-30 19:23:15 +01:00
|
|
|
|
2021-05-07 09:39:08 +02:00
|
|
|
if (options == TCSAFLUSH)
|
|
|
|
{
|
|
|
|
tcflush(fd, TCIFLUSH);
|
|
|
|
}
|
|
|
|
|
2021-12-16 19:58:49 +01:00
|
|
|
return ioctl(fd, TCSETS, (unsigned long)(uintptr_t)termiosp);
|
2012-11-10 17:06:01 +01:00
|
|
|
}
|