Tool/software: Linux
can any one tell me the configuration for HSUART of termios??.I configured TX,RX,RTS and CTS but still it's not working.
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Tool/software: Linux
can any one tell me the configuration for HSUART of termios??.I configured TX,RX,RTS and CTS but still it's not working.
/*******************************************************************************
* @file : Zigbee_application.c
* @brief : Topic :
* This program test for the zigbee application.
* @author : Venu (venu.kovelamudi@vvdntech.com)
* @Copyright : (c) 2017 , VVDN Technologies Pvt. Ltd.
* Permission is hereby granted to everyone in VVDN Technologies
* to use the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish,
* distribute, distribute with modifications.
********************************************************************************/
/* Header files declarations */
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
/**
* @funtion : main
* @brief : This program sets the configuration of HSUART between MSM8909
* and QCA4024. To get the data and send the commands depending on the
* user prospective.
**/
int main(int argc, char **argv)
{
/* structure indicates HSUART configurations */
struct termios tio, stdio, old_stdio;
int tty_fd = 0, BAUDRATE = 0;
unsigned char chp = '\0', cht = '\0';
if (argc != 3) {
printf("Error:Inavalid arguments\n");
printf("Usage:./a.out /dev/ttyHS0 B115200\n");
return EXIT_FAILURE;
}
/* Get the previous configurations of the terminal */
tcgetattr(STDOUT_FILENO, &old_stdio);
/* Clear the structure data for terminal*/
memset(&stdio, 0, sizeof(stdio));
/* input modes */
stdio.c_iflag = 0;
/* output modes */
stdio.c_oflag = 0;
/* control modes */
stdio.c_cflag = 0;
/* local modes */
stdio.c_lflag = 0;
/* Minimum number of characters for noncanonical read (MIN). */
stdio.c_cc[VMIN] = 1;
/* Timeout in deciseconds for noncanonical read (TIME). */
stdio.c_cc[VTIME] = 0;
/* TCSANOW -> The change occurs immediately. */
/* TCSAFLUSH -> The change occurs after all output written to fd has been transmitted.
This option should be used when changing parameters that affect output. */
/* Sets the new attributes for terminal */
tcsetattr(STDOUT_FILENO, TCSANOW, &stdio);
tcsetattr(STDOUT_FILENO, TCSAFLUSH, &stdio);
/* make the reads non-blocking */
fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK);
/* Clear the structure data for HSUART*/
memset(&tio, 0, sizeof(tio));
tio.c_iflag = 0;
tio.c_oflag = 0;
/* 8n1, see termios.h for more information */
tio.c_cflag = CS8 | CREAD | CLOCAL | CRTSCTS;
tio.c_lflag = 0;
tio.c_cc[VMIN] = 1;
tio.c_cc[VTIME] = 5;
/* Open the HSUART port for read and write */
if((tty_fd = open(argv[1], O_RDWR | O_NOCTTY | O_NONBLOCK)) == -1){
printf("Error while opening\n");
return EXIT_FAILURE;
}
BAUDRATE = atoi(argv[2]);
/* If the input baud rate is set to zero, the input baud rate will be equal to the output baud rate. */
cfsetospeed(&tio, BAUDRATE);
/* sets the input baud rate */
cfsetispeed(&tio, BAUDRATE);
/* Sets the new attributes for HSUART */
tcsetattr(tty_fd, TCSANOW, &tio);
while (cht != 'e' && cht != 'E') {
/* Read the data from the HSUART */
if (read(tty_fd, &chp, 1) > 0){
printf("p%c\n", chp);
/* if new data is available on the serial port, print it out */
write(STDOUT_FILENO, &chp, 1);
}
/* Read the data from the terminal */
if (read(STDIN_FILENO, &cht, 1) > 0){
printf("u%c\n", cht);
/* if new data is available on the console, send it to serial port */
write(tty_fd, &cht, 1);
}
}
/* Close the file discriptor */
close(tty_fd);
/* Sets the old attributes for terminal */
tcsetattr(STDOUT_FILENO, TCSANOW, &old_stdio);
return EXIT_SUCCESS;
}