* General stuff for different baudrates:

- ubr argument to slip_arch_int

    - macros for calculating ubr

    - argument -Bbaudrate to tools tunslip and scat
This commit is contained in:
bg- 2007-02-02 13:26:48 +00:00
parent 2918e5ae20
commit 429d41defd
8 changed files with 121 additions and 76 deletions

View File

@ -29,7 +29,7 @@
*
* This file is part of the Contiki operating system.
*
* @(#)$Id: slip.h,v 1.3 2007/01/23 12:29:50 bg- Exp $
* @(#)$Id: slip.h,v 1.4 2007/02/02 13:26:48 bg- Exp $
*/
#ifndef __SLIP_H__
@ -75,7 +75,7 @@ extern u16_t slip_rubbish, slip_twopackets, slip_overflow, slip_ip_drop;
* These machine dependent functions and an interrupt service routine
* must be provided externally (slip_arch.c).
*/
void slip_arch_init(void);
void slip_arch_init(unsigned long ubr);
void slip_arch_writeb(unsigned char c);
#endif /* __SLIP_H__ */

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)$Id: slip_uart1.c,v 1.3 2006/12/01 15:07:49 bg- Exp $
* @(#)$Id: slip_uart1.c,v 1.4 2007/02/02 13:26:48 bg- Exp $
*/
/*
@ -82,47 +82,12 @@ putchar(int c)
return c;
}
#define RS232_19200 1
#define RS232_38400 2
#define RS232_57600 3
#define RS232_115200 3
#if 0
void
rs232_set_speed(unsigned char speed)
{
if(speed == RS232_19200) {
/* Set RS232 to 19200 */
UBR01 = 0x80; /* 2,457MHz/19200 = 128 -> 0x80 */
UBR11 = 0x00; /* */
UMCTL1 = 0x00; /* no modulation */
} else if(speed == RS232_38400) {
/* Set RS232 to 38400 */
UBR01 = 0x40; /* 2,457MHz/38400 = 64 -> 0x40 */
UBR11 = 0x00; /* */
UMCTL1 = 0x00; /* no modulation */
} else if(speed == RS232_57600) {
UBR01 = 0x2a; /* 2,457MHz/57600 = 42.7 -> 0x2A */
UBR11 = 0x00; /* */
UMCTL1 = 0x5b; /* */
} else if(speed == RS232_115200) {
UBR01 = 0x15; /* 2,457MHz/115200 = 21.4 -> 0x15 */
UBR11 = 0x00; /* */
UMCTL1 = 0x4a; /* */
} else {
rs232_set_speed(RS232_57600);
}
}
#endif
/**
* Initalize the RS232 port and the SLIP driver.
*
*/
void
slip_arch_init(void)
slip_arch_init(unsigned long ubr)
{
/* RS232 */
P3DIR &= ~0x80; /* Select P37 for input (UART1RX) */
@ -131,21 +96,32 @@ slip_arch_init(void)
UCTL1 = SWRST | CHAR; /* 8-bit character, UART mode */
/* U1RCTL &= ~URXEIE; /\* even erroneous characters trigger interrupts *\/ */
#if 0
U1RCTL &= ~URXEIE; /* even erroneous characters trigger interrupts */
#endif
UTCTL1 = SSEL1; /* UCLK = MCLK */
#ifdef TMOTE_SKY
/* rs232_set_speed(RS232_115200); */
UBR01 = 0x15;
UBR11 = 0x00;
UMCTL1 = 0x4a;
#else
/* rs232_set_speed(RS232_57600); */
UBR01 = 0x2a;
UBR11 = 0x00;
UMCTL1 = 0x5b;
#endif
UBR01 = ubr;
UBR11 = ubr >> 8; /* always zero */
/*
* UMCTL1 values calculated using
* http://mspgcc.sourceforge.net/baudrate.html and are not
* complete. Also the table assumes that F_CPU = 2,457,600 Hz.
*/
switch (ubr) {
case BAUD2UBR(115200):
UMCTL1 = 0x4a;
break;
case BAUD2UBR(57600):
UMCTL1 = 0x5b;
break;
case BAUD2UBR(19600):
UMCTL1 = 0x4a;
break;
default:
UMCTL1 = 0x00;
}
ME2 &= ~USPIE1; /* USART1 SPI module disable */
ME2 |= (UTXE1 | URXE1); /* Enable USART1 TXD/RXD */

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)$Id: client.c,v 1.3 2007/02/01 14:34:10 bg- Exp $
* @(#)$Id: client.c,v 1.4 2007/02/02 13:26:49 bg- Exp $
*/
/*
@ -105,9 +105,9 @@ main(int argc, char **argv)
clock_init();
leds_init();
leds_toggle(LEDS_ALL);
slip_arch_init(); /* Must come before first printf */
slip_arch_init(BAUD2UBR(115200)); /* Must come before first printf */
printf("Starting %s "
"($Id: client.c,v 1.3 2007/02/01 14:34:10 bg- Exp $)\n", __FILE__);
"($Id: client.c,v 1.4 2007/02/02 13:26:49 bg- Exp $)\n", __FILE__);
ds2411_init();
sensors_light_init();
cc2420_init();

View File

@ -1,5 +1,5 @@
/* -*- C -*- */
/* @(#)$Id: contiki-conf.h,v 1.5 2007/01/24 16:31:40 bg- Exp $ */
/* @(#)$Id: contiki-conf.h,v 1.6 2007/02/02 13:26:49 bg- Exp $ */
#ifndef CONTIKI_CONF_H
#define CONTIKI_CONF_H
@ -26,9 +26,14 @@ void msp430_cpu_init(void); /* Rename to cpu_init() later! */
#define PROCESS_CONF_FASTPOLL 4
/* CPU target speed in Hz */
#define F_CPU 2457600uL
/* Our clock resolution, this is the same as Unix HZ. */
#define CLOCK_CONF_SECOND 64
#define BAUD2UBR(baud) ((F_CPU/baud))
#define UIP_CONF_DHCP_LIGHT
#define UIP_CONF_LLH_LEN 0
#define UIP_CONF_BUFFER_SIZE 116

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)$Id: dhclient.c,v 1.6 2007/02/01 14:34:32 bg- Exp $
* @(#)$Id: dhclient.c,v 1.7 2007/02/02 13:26:49 bg- Exp $
*/
/*
@ -101,9 +101,9 @@ main(int argc, char **argv)
clock_init();
leds_init();
leds_toggle(LEDS_ALL);
slip_arch_init(); /* Must come before first printf */
slip_arch_init(BAUD2UBR(115200)); /* Must come before first printf */
printf("Starting %s "
"($Id: dhclient.c,v 1.6 2007/02/01 14:34:32 bg- Exp $)\n", __FILE__);
"($Id: dhclient.c,v 1.7 2007/02/02 13:26:49 bg- Exp $)\n", __FILE__);
ds2411_init();
sensors_light_init();
cc2420_init();

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)$Id: gateway.c,v 1.5 2007/02/01 14:34:45 bg- Exp $
* @(#)$Id: gateway.c,v 1.6 2007/02/02 13:26:49 bg- Exp $
*/
/*
@ -123,9 +123,9 @@ main(int argc, char **argv)
clock_init();
leds_init();
leds_toggle(LEDS_ALL);
slip_arch_init(); /* Must come before first printf */
slip_arch_init(BAUD2UBR(115200)); /* Must come before first printf */
printf("Starting %s "
"($Id: gateway.c,v 1.5 2007/02/01 14:34:45 bg- Exp $)\n", __FILE__);
"($Id: gateway.c,v 1.6 2007/02/02 13:26:49 bg- Exp $)\n", __FILE__);
ds2411_init();
sensors_light_init();
cc2420_init();

View File

@ -26,7 +26,7 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: scat.c,v 1.4 2007/01/23 12:33:27 bg- Exp $
* $Id: scat.c,v 1.5 2007/02/02 13:26:49 bg- Exp $
*
*/
@ -57,16 +57,13 @@
#ifndef BAUDRATE
#define BAUDRATE B115200
//#define BAUDRATE B57600
//#define BAUDRATE B38400
//#define BAUDRATE B19200
#endif
speed_t b_rate = BAUDRATE;
void
stty_telos(int fd)
{
struct termios tty;
speed_t speed = BAUDRATE;
int i;
if(tcflush(fd, TCIOFLUSH) == -1) err(1, "tcflush");
@ -82,8 +79,8 @@ stty_telos(int fd)
tty.c_cflag &= ~HUPCL;
tty.c_cflag &= ~CLOCAL;
cfsetispeed(&tty, speed);
cfsetospeed(&tty, speed);
cfsetispeed(&tty, b_rate);
cfsetospeed(&tty, b_rate);
if(tcsetattr(fd, TCSAFLUSH, &tty) == -1) err(1, "tcsetattr");
@ -102,10 +99,51 @@ stty_telos(int fd)
int
main(int argc, char **argv)
{
int c;
int slipfd;
FILE *inslip;
const char *siodev;
int baudrate = -2;
while ((c = getopt(argc, argv, "B:")) != -1) {
switch (c) {
case 'B':
baudrate = atoi(optarg);
break;
case '?':
case 'h':
default:
err(1, "usage: scat [-B baudrate] device-file");
break;
}
}
argc -= (optind - 1);
argv += (optind - 1);
switch (baudrate) {
case -2:
break; /* Use default. */
case 9600:
b_rate = B9600;
break;
case 19200:
b_rate = B19200;
break;
case 38400:
b_rate = B38400;
break;
case 57600:
b_rate = B57600;
break;
case 115200:
b_rate = B115200;
break;
default:
err(1, "unknown baudrate %d", baudrate);
break;
}
if (argc != 2)
err(1, "usage: scat device-file");
siodev = argv[1];

View File

@ -28,7 +28,7 @@
*
* This file is part of the uIP TCP/IP stack.
*
* $Id: tunslip.c,v 1.9 2007/02/01 14:35:23 bg- Exp $
* $Id: tunslip.c,v 1.10 2007/02/02 13:26:49 bg- Exp $
*
*/
@ -689,16 +689,14 @@ tun_to_serial(int infd, int outfd)
#ifndef BAUDRATE
#define BAUDRATE B115200
//#define BAUDRATE B57600
//#define BAUDRATE B38400
//#define BAUDRATE B19200
#endif
speed_t b_rate = BAUDRATE;
void
stty_telos(int fd)
{
struct termios tty;
speed_t speed = BAUDRATE;
speed_t speed = b_rate;
int i;
if(tcflush(fd, TCIOFLUSH) == -1) err(1, "tcflush");
@ -866,11 +864,16 @@ main(int argc, char **argv)
const char *siodev = NULL;
const char *dhcp_server = NULL;
u_int16_t myport = BOOTPS, dhport = BOOTPS;
int baudrate = -2;
ip_id = getpid() * time(NULL);
while ((c = getopt(argc, argv, "D:hs:t:")) != -1) {
while ((c = getopt(argc, argv, "B:D:hs:t:")) != -1) {
switch (c) {
case 'B':
baudrate = atoi(optarg);
break;
case 'D':
dhcp_server = optarg;
break;
@ -892,7 +895,7 @@ main(int argc, char **argv)
case '?':
case 'h':
default:
err(1, "usage: tunslip [-s siodev] [-t tundev] [-D dhcp-server] ipaddress netmask [dhcp-server]");
err(1, "usage: tunslip [-B baudrate] [-s siodev] [-t tundev] [-D dhcp-server] ipaddress netmask [dhcp-server]");
break;
}
}
@ -906,6 +909,29 @@ main(int argc, char **argv)
circuit_addr = inet_addr(ipaddr);
netaddr = inet_addr(ipaddr) & inet_addr(netmask);
switch (baudrate) {
case -2:
break; /* Use default. */
case 9600:
b_rate = B9600;
break;
case 19200:
b_rate = B19200;
break;
case 38400:
b_rate = B38400;
break;
case 57600:
b_rate = B57600;
break;
case 115200:
b_rate = B115200;
break;
default:
err(1, "unknown baudrate %d", baudrate);
break;
}
/*
* Set up DHCP relay agent socket and find the address of this relay
* agent.