Merge pull request #898 from dl8dtl/macos-nonstandard-baudrates
Macos nonstandard baudrates closes #266
This commit is contained in:
commit
99f191a0ca
|
@ -28,6 +28,7 @@
|
||||||
#include "ac_cfg.h"
|
#include "ac_cfg.h"
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -42,6 +43,10 @@
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
# include <IOKit/serial/ioss.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "avrdude.h"
|
#include "avrdude.h"
|
||||||
#include "libavrdude.h"
|
#include "libavrdude.h"
|
||||||
|
|
||||||
|
@ -78,10 +83,12 @@ static struct baud_mapping baud_lookup_table [] = {
|
||||||
static struct termios original_termios;
|
static struct termios original_termios;
|
||||||
static int saved_original_termios;
|
static int saved_original_termios;
|
||||||
|
|
||||||
static speed_t serial_baud_lookup(long baud)
|
static speed_t serial_baud_lookup(long baud, bool *nonstandard)
|
||||||
{
|
{
|
||||||
struct baud_mapping *map = baud_lookup_table;
|
struct baud_mapping *map = baud_lookup_table;
|
||||||
|
|
||||||
|
*nonstandard = false;
|
||||||
|
|
||||||
while (map->baud) {
|
while (map->baud) {
|
||||||
if (map->baud == baud)
|
if (map->baud == baud)
|
||||||
return map->speed;
|
return map->speed;
|
||||||
|
@ -92,9 +99,11 @@ static speed_t serial_baud_lookup(long baud)
|
||||||
* If a non-standard BAUD rate is used, issue
|
* If a non-standard BAUD rate is used, issue
|
||||||
* a warning (if we are verbose) and return the raw rate
|
* a warning (if we are verbose) and return the raw rate
|
||||||
*/
|
*/
|
||||||
avrdude_message(MSG_NOTICE, "%s: serial_baud_lookup(): Using non-standard baud rate: %ld",
|
avrdude_message(MSG_NOTICE, "%s: serial_baud_lookup(): Using non-standard baud rate: %ld\n",
|
||||||
progname, baud);
|
progname, baud);
|
||||||
|
|
||||||
|
*nonstandard = true;
|
||||||
|
|
||||||
return baud;
|
return baud;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +111,8 @@ static int ser_setparams(union filedescriptor *fd, long baud, unsigned long cfla
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
struct termios termios;
|
struct termios termios;
|
||||||
speed_t speed = serial_baud_lookup (baud);
|
bool nonstandard;
|
||||||
|
speed_t speed = serial_baud_lookup (baud, &nonstandard);
|
||||||
|
|
||||||
if (!isatty(fd->ifd))
|
if (!isatty(fd->ifd))
|
||||||
return -ENOTTY;
|
return -ENOTTY;
|
||||||
|
@ -146,8 +156,16 @@ static int ser_setparams(union filedescriptor *fd, long baud, unsigned long cfla
|
||||||
termios.c_iflag &= ~PARMRK;
|
termios.c_iflag &= ~PARMRK;
|
||||||
#endif /* PARMRK */
|
#endif /* PARMRK */
|
||||||
|
|
||||||
|
// MacOS doesn't handle nonstandard baudrate values in
|
||||||
|
// normal tcsetattr(), sigh.
|
||||||
|
#ifdef __APPLE__
|
||||||
|
if (!nonstandard) {
|
||||||
|
#endif
|
||||||
cfsetospeed(&termios, speed);
|
cfsetospeed(&termios, speed);
|
||||||
cfsetispeed(&termios, speed);
|
cfsetispeed(&termios, speed);
|
||||||
|
#ifdef __APPLE__
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
termios.c_cflag &= ~CSIZE;
|
termios.c_cflag &= ~CSIZE;
|
||||||
if (cflags & SERIAL_CS8) {
|
if (cflags & SERIAL_CS8) {
|
||||||
|
@ -204,6 +222,17 @@ static int ser_setparams(union filedescriptor *fd, long baud, unsigned long cfla
|
||||||
return -errno;
|
return -errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
// handle nonstandard speed values the MacOS way
|
||||||
|
if (nonstandard) {
|
||||||
|
if (ioctl(fd->ifd, IOSSIOSPEED, &speed) < 0) {
|
||||||
|
avrdude_message(MSG_INFO, "%s: ser_setparams(): ioctrl(IOSSIOSPEED) failed\n",
|
||||||
|
progname);
|
||||||
|
return -errno;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif // __APPLE__
|
||||||
|
|
||||||
tcflush(fd->ifd, TCIFLUSH);
|
tcflush(fd->ifd, TCIFLUSH);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -564,3 +593,4 @@ struct serial_device serial_serdev =
|
||||||
struct serial_device *serdev = &serial_serdev;
|
struct serial_device *serdev = &serial_serdev;
|
||||||
|
|
||||||
#endif /* WIN32 */
|
#endif /* WIN32 */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue