Allow simultaneous use of RS232 and USB serial ports
This commit is contained in:
parent
d8711d32a3
commit
258e3cc93a
5 changed files with 55 additions and 25 deletions
|
@ -28,7 +28,7 @@
|
||||||
*
|
*
|
||||||
* This file is part of the Contiki operating system.
|
* This file is part of the Contiki operating system.
|
||||||
*
|
*
|
||||||
* @(#)$Id: rs232.c,v 1.6 2010/03/15 18:52:55 dak664 Exp $
|
* @(#)$Id: rs232.c,v 1.7 2010/10/27 14:51:20 dak664 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -48,6 +48,10 @@
|
||||||
#define RS232_PRINTF_BUFFER_LENGTH 64
|
#define RS232_PRINTF_BUFFER_LENGTH 64
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef ADD_CARRAGE_RETURNS_TO_SERIAL_OUTPUT
|
||||||
|
#define ADD_CARRAGE_RETURNS_TO_SERIAL_OUTPUT 1
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined (__AVR_ATmega128__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega1281__)
|
#if defined (__AVR_ATmega128__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega1281__)
|
||||||
typedef struct {
|
typedef struct {
|
||||||
volatile uint8_t * UDR;
|
volatile uint8_t * UDR;
|
||||||
|
@ -200,7 +204,12 @@ void
|
||||||
rs232_print(uint8_t port, char *buf)
|
rs232_print(uint8_t port, char *buf)
|
||||||
{
|
{
|
||||||
while(*buf) {
|
while(*buf) {
|
||||||
|
#if ADD_CARRAGE_RETURNS_TO_SERIAL_OUTPUT
|
||||||
|
if(*buf=='\n') rs232_send(port, '\r');
|
||||||
|
if(*buf=='\r') buf++; else rs232_send(port, *buf++);
|
||||||
|
#else
|
||||||
rs232_send(port, *buf++);
|
rs232_send(port, *buf++);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
@ -245,7 +254,12 @@ static FILE rs232_stdout = FDEV_SETUP_STREAM(rs232_stdout_putchar,
|
||||||
|
|
||||||
int rs232_stdout_putchar(char c, FILE *stream)
|
int rs232_stdout_putchar(char c, FILE *stream)
|
||||||
{
|
{
|
||||||
|
#if ADD_CARRAGE_RETURNS_TO_SERIAL_OUTPUT
|
||||||
|
if(c=='\n') rs232_send(stdout_rs232_port, '\r');
|
||||||
|
if(c!='\r') rs232_send (stdout_rs232_port, c);
|
||||||
|
#else
|
||||||
rs232_send (stdout_rs232_port, c);
|
rs232_send (stdout_rs232_port, c);
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
|
@ -143,7 +143,7 @@ Bool usb_user_read_request(U8 type, U8 request)
|
||||||
break;
|
break;
|
||||||
#endif /* USB_CONF_STORAGE */
|
#endif /* USB_CONF_STORAGE */
|
||||||
|
|
||||||
#if USB_CONF_CDC
|
#if USB_CONF_SERIAL
|
||||||
/* We don't have a real serial port - so these aren't applicable. We
|
/* We don't have a real serial port - so these aren't applicable. We
|
||||||
advertise that we support nothing, so shouldn't get them anyway */
|
advertise that we support nothing, so shouldn't get them anyway */
|
||||||
case GET_LINE_CODING:
|
case GET_LINE_CODING:
|
||||||
|
@ -176,7 +176,7 @@ Bool usb_user_read_request(U8 type, U8 request)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#endif /* USB_CONF_CDC */
|
#endif /* USB_CONF_SERIAL */
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -362,7 +362,7 @@ void usb_user_endpoint_init(U8 conf_nb)
|
||||||
Led0_on();
|
Led0_on();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if USB_CONF_CDC
|
#if USB_CONF_SERIAL
|
||||||
/******************** Virtual Serial Port ************************/
|
/******************** Virtual Serial Port ************************/
|
||||||
|
|
||||||
extern S_line_coding line_coding;
|
extern S_line_coding line_coding;
|
||||||
|
@ -429,7 +429,7 @@ void cdc_set_control_line_state (void)
|
||||||
uart_usb_set_control_line_state(controlLineState);
|
uart_usb_set_control_line_state(controlLineState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* USB_CONF_CDC */
|
#endif /* USB_CONF_SERIAL */
|
||||||
|
|
||||||
Bool usb_user_set_alt_interface(U8 interface, U8 alt_setting) {
|
Bool usb_user_set_alt_interface(U8 interface, U8 alt_setting) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
|
@ -61,9 +61,7 @@
|
||||||
#else
|
#else
|
||||||
#include "radio.h"
|
#include "radio.h"
|
||||||
#endif
|
#endif
|
||||||
#if USB_CONF_RS232
|
|
||||||
#include "dev/rs232.h"
|
|
||||||
#endif
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "dev/watchdog.h"
|
#include "dev/watchdog.h"
|
||||||
|
@ -130,12 +128,16 @@ PROCESS_THREAD(cdc_process, ev, data_proc)
|
||||||
{
|
{
|
||||||
PROCESS_BEGIN();
|
PROCESS_BEGIN();
|
||||||
|
|
||||||
|
#if USB_CONF_RS232
|
||||||
|
static FILE *rs232_stdout,*usb_stdout;
|
||||||
|
rs232_stdout=stdout;
|
||||||
|
#endif
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
// turn off LED's if necessary
|
// turn off LED's if necessary
|
||||||
if (led3_timer) led3_timer--;
|
if (led3_timer) led3_timer--;
|
||||||
else Led3_off();
|
else Led3_off();
|
||||||
|
|
||||||
|
|
||||||
if(Is_device_enumerated()) {
|
if(Is_device_enumerated()) {
|
||||||
// If the configuration is different than the last time we checked...
|
// If the configuration is different than the last time we checked...
|
||||||
if((uart_usb_get_control_line_state()&1)!=previous_uart_usb_control_line_state) {
|
if((uart_usb_get_control_line_state()&1)!=previous_uart_usb_control_line_state) {
|
||||||
|
@ -150,6 +152,7 @@ PROCESS_THREAD(cdc_process, ev, data_proc)
|
||||||
} else {
|
} else {
|
||||||
stdout = previous_stdout;
|
stdout = previous_stdout;
|
||||||
}
|
}
|
||||||
|
usb_stdout=stdout;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Flush buffer if timeout
|
//Flush buffer if timeout
|
||||||
|
@ -160,14 +163,19 @@ PROCESS_THREAD(cdc_process, ev, data_proc)
|
||||||
timer++;
|
timer++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if USB_CONF_RS232
|
||||||
|
stdout=usb_stdout;
|
||||||
|
#endif
|
||||||
while (uart_usb_test_hit()){
|
while (uart_usb_test_hit()){
|
||||||
menu_process(uart_usb_getchar()); // See what they want
|
menu_process(uart_usb_getchar()); // See what they want
|
||||||
}
|
}
|
||||||
|
#if USB_CONF_RS232
|
||||||
|
stdout=rs232_stdout;
|
||||||
|
#endif
|
||||||
}//if (Is_device_enumerated())
|
}//if (Is_device_enumerated())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (USB_CONFIG_HAS_DEBUG_PORT(usb_configuration_nb)) {
|
if (USB_CONFIG_HAS_DEBUG_PORT(usb_configuration_nb)) {
|
||||||
etimer_set(&et, CLOCK_SECOND/80);
|
etimer_set(&et, CLOCK_SECOND/80);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -190,13 +190,22 @@ extern void mac_log_802_15_4_rx(const uint8_t* buffer, size_t total_len);
|
||||||
* it will attempt to use it and give "device can not start" error.
|
* it will attempt to use it and give "device can not start" error.
|
||||||
* This doesn't seem to hurt anything but can potentially damage the OS!
|
* This doesn't seem to hurt anything but can potentially damage the OS!
|
||||||
*/
|
*/
|
||||||
//#define USB_CONF_MACINTOSH 1
|
#define USB_CONF_MACINTOSH 0
|
||||||
|
|
||||||
|
/* Set USB_CONF_SERIAL to enable the USB serial port that allows control of the
|
||||||
|
* run-time configuration (COMx on Windows, ttyACMx on Linux, tty.usbx on Mac)
|
||||||
|
* Debug printfs will go to this port unless USB_CONF_RS232 is set.
|
||||||
|
*/
|
||||||
|
#define USB_CONF_SERIAL 1
|
||||||
|
|
||||||
|
/* RS232 debugs have less effect on network timing and are less likely
|
||||||
|
* to be dropped due to buffer overflow. Only tx is implemented at present.
|
||||||
|
* The tx pad is the middle one behind the jackdaw leds.
|
||||||
|
*/
|
||||||
|
#define USB_CONF_RS232 1
|
||||||
|
|
||||||
/* Disable mass storage enumeration for more program space */
|
/* Disable mass storage enumeration for more program space */
|
||||||
/* TODO: Mass storage is currently broken */
|
//#define USB_CONF_STORAGE 1 /* TODO: Mass storage is currently broken */
|
||||||
//#define USB_CONF_STORAGE 1
|
|
||||||
/* Use either USB CDC or RS232 for stdout (or neither) */
|
|
||||||
#define USB_CONF_CDC 1
|
|
||||||
//#define USB_CONF_RS232 1
|
|
||||||
|
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
//#pragma mark RIME Settings
|
//#pragma mark RIME Settings
|
||||||
|
|
|
@ -64,11 +64,11 @@
|
||||||
#include "contiki-lib.h"
|
#include "contiki-lib.h"
|
||||||
#include "contiki-raven.h"
|
#include "contiki-raven.h"
|
||||||
|
|
||||||
/* Set ANNOUNCE to send boot messages to USB or serial port */
|
/* Set ANNOUNCE to send boot messages to USB or RS232 serial port */
|
||||||
#define ANNOUNCE 1
|
#define ANNOUNCE 1
|
||||||
|
|
||||||
#include "usb_task.h"
|
#include "usb_task.h"
|
||||||
#if USB_CONF_CDC
|
#if USB_CONF_SERIAL
|
||||||
#include "cdc_task.h"
|
#include "cdc_task.h"
|
||||||
#endif
|
#endif
|
||||||
#if USB_CONF_RS232
|
#if USB_CONF_RS232
|
||||||
|
@ -305,7 +305,7 @@ static void initialize(void) {
|
||||||
/* Clock */
|
/* Clock */
|
||||||
clock_init();
|
clock_init();
|
||||||
|
|
||||||
#if USB_CONF_RS232
|
#if USB_CONF_RS232
|
||||||
/* Use rs232 port for serial out (tx, rx, gnd are the three pads behind jackdaw leds */
|
/* Use rs232 port for serial out (tx, rx, gnd are the three pads behind jackdaw leds */
|
||||||
rs232_init(RS232_PORT_0, USART_BAUD_57600,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
|
rs232_init(RS232_PORT_0, USART_BAUD_57600,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8);
|
||||||
/* Redirect stdout to second port */
|
/* Redirect stdout to second port */
|
||||||
|
@ -425,7 +425,7 @@ static void initialize(void) {
|
||||||
|
|
||||||
/* Setup USB */
|
/* Setup USB */
|
||||||
process_start(&usb_process, NULL);
|
process_start(&usb_process, NULL);
|
||||||
#if USB_CONF_CDC
|
#if USB_CONF_SERIAL
|
||||||
process_start(&cdc_process, NULL);
|
process_start(&cdc_process, NULL);
|
||||||
#endif
|
#endif
|
||||||
process_start(&usb_eth_process, NULL);
|
process_start(&usb_eth_process, NULL);
|
||||||
|
@ -434,7 +434,7 @@ static void initialize(void) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ANNOUNCE
|
#if ANNOUNCE
|
||||||
#if USB_CONF_CDC
|
#if USB_CONF_SERIAL&&!USB_CONF_RS232
|
||||||
{unsigned short i;
|
{unsigned short i;
|
||||||
printf_P(PSTR("\n\n\n********BOOTING CONTIKI*********\n\r"));
|
printf_P(PSTR("\n\n\n********BOOTING CONTIKI*********\n\r"));
|
||||||
/* Allow USB CDC to keep up with printfs */
|
/* Allow USB CDC to keep up with printfs */
|
||||||
|
@ -453,10 +453,9 @@ static void initialize(void) {
|
||||||
#endif /* RF230BB */
|
#endif /* RF230BB */
|
||||||
printf_P(PSTR("System online.\n\r"));
|
printf_P(PSTR("System online.\n\r"));
|
||||||
}
|
}
|
||||||
#endif /* USB_CONF_CDC */
|
#elif USB_CONF_RS232
|
||||||
#if USB_CONF_RS232
|
|
||||||
printf_P(PSTR("System online.\n"));
|
printf_P(PSTR("System online.\n"));
|
||||||
#endif /* USB_CONF_RS232 */
|
#endif
|
||||||
#endif /* ANNOUNCE */
|
#endif /* ANNOUNCE */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue