aboutsummaryrefslogtreecommitdiffstats
path: root/sdk/dev/speed.c
blob: f9fee56af06e53dc9b9c996f7ec3cf84f212a752 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
 * Specify serial communications speed.
 * $Id$
 * Copyright (c) 1997 by Tycho Softworks.
 * For conditions of distribution and reuse see product license.
 */

#include <dev/tty.h>
#ifndef	TERMIOS_H_MISSING
#include <termios.h>
#endif

int	setspeed(stty_t tios, ulong speed)
{

#ifdef	B38400
	int	rate = B38400;
#else
	int	rate = B19200;
#endif

	switch(speed)
	{
	case 110:
		rate = B110;
		break;
	case 300:
		rate = B300;
		break;
	case 600:
		rate = B600;
		break;
	case 1200:
		rate = B1200;
		break;
	case 2400:
		rate = B2400;
		break;
	case 4800:
		rate = B4800;
		break;
	case 9600:
		rate = B9600;
		break;
	case 19200:
		rate = B19200;
		break;
#ifdef	B38400
	case 38400:
		rate = B38400;
		break;
#endif
#ifdef	B57600
	case 57600:
		rate = B57600;
		break;
#endif
#ifdef	B115200
	case 115200:
		rate = B115200;
		break;
#endif
	}

#ifndef	TERMIOS_H_MISSING
	cfsetospeed(tios, rate);
	cfsetispeed(tios, rate);
#endif
	return rate;
}