summaryrefslogtreecommitdiff
path: root/nuttx/lib
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-07-23 15:37:13 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-07-23 15:37:13 +0000
commit6355e50a2289d7d764ac9de87ddd1528c510bd8f (patch)
treebdace79b95ff390c7c1b0ccdd005816be2c83e6c /nuttx/lib
parent92ee042ea3f2cd97bcca3f1d752ec68dac919d85 (diff)
downloadpx4-nuttx-6355e50a2289d7d764ac9de87ddd1528c510bd8f.tar.gz
px4-nuttx-6355e50a2289d7d764ac9de87ddd1528c510bd8f.tar.bz2
px4-nuttx-6355e50a2289d7d764ac9de87ddd1528c510bd8f.zip
Baud definitions (B9600 for example) are again encoded; Now supports the BOTHER settings which allows specifying the baud via c_ispeed and c_ospeed termios fields
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4970 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/lib')
-rw-r--r--nuttx/lib/termios/lib_cfgetispeed.c15
-rw-r--r--nuttx/lib/termios/lib_cfgetospeed.c15
-rw-r--r--nuttx/lib/termios/lib_cfsetispeed.c18
-rw-r--r--nuttx/lib/termios/lib_cfsetospeed.c18
4 files changed, 30 insertions, 36 deletions
diff --git a/nuttx/lib/termios/lib_cfgetispeed.c b/nuttx/lib/termios/lib_cfgetispeed.c
index d7ca5f5a5..d52b83774 100644
--- a/nuttx/lib/termios/lib_cfgetispeed.c
+++ b/nuttx/lib/termios/lib_cfgetispeed.c
@@ -70,24 +70,21 @@
* This function shall return exactly the value in the termios data
* structure, without interpretation.
*
- * NON STANDARD BEHAVIOR. In Nuttx, the speed_t is defined to be uint32_t
- * and the baud encodings of termios.h are the actual baud values
- * themselves. Therefore, any baud value can be provided as the speed
- * argument here. However, if you do so, your code will *NOT* be portable
- * to other environments where speed_t is smaller and where the termios.h
- * baud values are encoded! To avoid portability issues, use the baud
- * definitions in termios.h!
+ * NOTE 1: NuttX does not not control input/output baud rates independently
+ * Hense, this function is *identical* to cfgetospeed.
+ * NOTE 2: If this function returns BOTHER and the more flexible input
+ * speed can be obtained from the Linux-like c_ispeed field.
*
* Input Parameters:
* termiosp - The termiosp argument is a pointer to a termios structure.
*
* Returned Value:
- * Baud value in the termios structure (not verified).
+ * Encoded baud value from the termios structure.
*
****************************************************************************/
speed_t cfgetispeed(const struct termios *termios_p)
{
DEBUGASSERT(termios_p);
- return termios_p->c_ispeed;
+ return (termios_p->c_cflag & (CBAUD | CBAUDEX));
}
diff --git a/nuttx/lib/termios/lib_cfgetospeed.c b/nuttx/lib/termios/lib_cfgetospeed.c
index 89b4d619c..904353332 100644
--- a/nuttx/lib/termios/lib_cfgetospeed.c
+++ b/nuttx/lib/termios/lib_cfgetospeed.c
@@ -70,24 +70,21 @@
* This function shall return exactly the value in the termios data
* structure, without interpretation.
*
- * NON STANDARD BEHAVIOR. In Nuttx, the speed_t is defined to be uint32_t
- * and the baud encodings of termios.h are the actual baud values
- * themselves. Therefore, any baud value can be provided as the speed
- * argument here. However, if you do so, your code will *NOT* be portable
- * to other environments where speed_t is smaller and where the termios.h
- * baud values are encoded! To avoid portability issues, use the baud
- * definitions in termios.h!
+ * NOTE 1: NuttX does not not control input/output baud rates independently
+ * Hense, this function is *identical* to cfgetispeed.
+ * NOTE 2: If this function returns BOTHER and the more flexible input
+ * speed can be obtained from the Linux-like c_ospeed field.
*
* Input Parameters:
* termiosp - The termiosp argument is a pointer to a termios structure.
*
* Returned Value:
- * Baud value in the termios structure (not verified).
+ * Encoded baud value from the termios structure.
*
****************************************************************************/
speed_t cfgetospeed(const struct termios *termios_p)
{
DEBUGASSERT(termios_p);
- return termios_p->c_ospeed;
+ return (termios_p->c_cflag & (CBAUD | CBAUDEX));
}
diff --git a/nuttx/lib/termios/lib_cfsetispeed.c b/nuttx/lib/termios/lib_cfsetispeed.c
index 20a05e501..2aefee083 100644
--- a/nuttx/lib/termios/lib_cfsetispeed.c
+++ b/nuttx/lib/termios/lib_cfsetispeed.c
@@ -71,26 +71,26 @@
* There is no effect on the baud rates set in the hardware until a
* subsequent successful call to tcsetattr() on the same termios structure.
*
- * NON STANDARD BEHAVIOR. In Nuttx, the speed_t is defined to be uint32_t
- * and the baud encodings of termios.h are the actual baud values
- * themselves. Therefore, any baud value can be provided as the speed
- * argument here. However, if you do so, your code will *NOT* be portable
- * to other environments where speed_t is smaller and where the termios.h
- * baud values are encoded! To avoid portability issues, use the baud
- * definitions in termios.h!
+ * NOTE 1: NuttX does not not control input/output baud rates independently
+ * Hense, this function is *identical* to cfsetospeed.
+ * NOTE 2: If the specia value BOTHER is used, then the actual input baud
+ * must also be provided in the (non-standard) c_ispeed field.
*
* Input Parameters:
* termiosp - The termiosp argument is a pointer to a termios structure.
* speed - The new input speed
*
* Returned Value:
- * Baud is not checked... OK is always returned.
+ * Baud is not checked... OK is always returned (this is non-standard
+ * behavior).
*
****************************************************************************/
int cfsetispeed(struct termios *termios_p, speed_t speed)
{
DEBUGASSERT(termios_p);
- termios_p->c_ispeed = speed;
+ speed &= (CBAUD | CBAUDEX);
+ termios_p->c_cflag &= ~(CBAUD | CBAUDEX);
+ termios_p->c_cflag |= speed;
return OK;
}
diff --git a/nuttx/lib/termios/lib_cfsetospeed.c b/nuttx/lib/termios/lib_cfsetospeed.c
index 4a30699e9..cbf8e341b 100644
--- a/nuttx/lib/termios/lib_cfsetospeed.c
+++ b/nuttx/lib/termios/lib_cfsetospeed.c
@@ -71,26 +71,26 @@
* There is no effect on the baud rates set in the hardware until a
* subsequent successful call to tcsetattr() on the same termios structure.
*
- * NON STANDARD BEHAVIOR. In Nuttx, the speed_t is defined to be uint32_t
- * and the baud encodings of termios.h are the actual baud values
- * themselves. Therefore, any baud value can be provided as the speed
- * argument here. However, if you do so, your code will *NOT* be portable
- * to other environments where speed_t is smaller and where the termios.h
- * baud values are encoded! To avoid portability issues, use the baud
- * definitions in termios.h!
+ * NOTE 1: NuttX does not not control input/output baud rates independently
+ * Hense, this function is *identical* to cfsetispeed.
+ * NOTE 2: If the specia value BOTHER is used, then the actual input baud
+ * must also be provided in the (non-standard) c_ospeed field.
*
* Input Parameters:
* termiosp - The termiosp argument is a pointer to a termios structure.
* speed - The new output speed
*
* Returned Value:
- * Baud is not checked... OK is always returned.
+ * Baud is not checked... OK is always returned (this is non-standard
+ * behavior).
*
****************************************************************************/
int cfsetospeed(struct termios *termios_p, speed_t speed)
{
DEBUGASSERT(termios_p);
- termios_p->c_ospeed = speed;
+ speed &= (CBAUD | CBAUDEX);
+ termios_p->c_cflag &= ~(CBAUD | CBAUDEX);
+ termios_p->c_cflag |= speed;
return OK;
}