Ticket #22867: patch-ser_posix.c.diff

File patch-ser_posix.c.diff, 1.3 KB (added by ranauei@…, 15 years ago)
  • ser_posix.c

    old new  
    1818 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1919 */
    2020
    21 /* $Id: ser_posix.c 826 2009-07-02 10:31:13Z joerg_wunsch $ */
     21/* $Id: ser_posix.c 845 2009-10-10 01:41:40Z mludvig $ */
    2222
    2323/*
    2424 * Posix serial interface for avrdude.
     
    3232#include <stdlib.h>
    3333#include <string.h>
    3434#include <errno.h>
     35#include <sys/ioctl.h>
    3536#include <sys/types.h>
    3637#include <sys/time.h>
    3738#include <sys/socket.h>
     
    210211  fdp->ifd = fd;
    211212}
    212213
     214
     215static int ser_set_dtr_rts(union filedescriptor *fdp, int is_on)
     216{
     217  unsigned int  ctl;
     218  int           r;
     219
     220  r = ioctl(fdp->ifd, TIOCMGET, &ctl);
     221  if (r < 0) {
     222    perror("ioctl(\"TIOCMGET\")");
     223    return -1;
     224  }
     225
     226  if (is_on) {
     227    /* Clear DTR and RTS */
     228    ctl &= ~(TIOCM_DTR | TIOCM_RTS);
     229  }
     230  else {
     231    /* Set DTR and RTS */
     232    ctl |= (TIOCM_DTR | TIOCM_RTS);
     233  }
     234
     235  r = ioctl(fdp->ifd, TIOCMSET, &ctl);
     236  if (r < 0) {
     237    perror("ioctl(\"TIOCMSET\")");
     238    return -1;
     239  }
     240
     241  return 0;
     242}
     243
    213244static void ser_open(char * port, long baud, union filedescriptor *fdp)
    214245{
    215246  int rc;
     
    455486  .send = ser_send,
    456487  .recv = ser_recv,
    457488  .drain = ser_drain,
     489  .set_dtr_rts = ser_set_dtr_rts,
    458490  .flags = SERDEV_FL_CANSETSPEED,
    459491};
    460492