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.
|
||||
*
|
||||
* @(#)$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>
|
||||
|
@ -48,6 +48,10 @@
|
|||
#define RS232_PRINTF_BUFFER_LENGTH 64
|
||||
#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__)
|
||||
typedef struct {
|
||||
volatile uint8_t * UDR;
|
||||
|
@ -200,7 +204,12 @@ void
|
|||
rs232_print(uint8_t port, char *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++);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -245,7 +254,12 @@ static FILE rs232_stdout = FDEV_SETUP_STREAM(rs232_stdout_putchar,
|
|||
|
||||
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);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
|
|
@ -143,7 +143,7 @@ Bool usb_user_read_request(U8 type, U8 request)
|
|||
break;
|
||||
#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
|
||||
advertise that we support nothing, so shouldn't get them anyway */
|
||||
case GET_LINE_CODING:
|
||||
|
@ -176,7 +176,7 @@ Bool usb_user_read_request(U8 type, U8 request)
|
|||
return FALSE;
|
||||
}
|
||||
break;
|
||||
#endif /* USB_CONF_CDC */
|
||||
#endif /* USB_CONF_SERIAL */
|
||||
default:
|
||||
break;
|
||||
|
||||
|
@ -362,7 +362,7 @@ void usb_user_endpoint_init(U8 conf_nb)
|
|||
Led0_on();
|
||||
}
|
||||
|
||||
#if USB_CONF_CDC
|
||||
#if USB_CONF_SERIAL
|
||||
/******************** Virtual Serial Port ************************/
|
||||
|
||||
extern S_line_coding line_coding;
|
||||
|
@ -429,7 +429,7 @@ void cdc_set_control_line_state (void)
|
|||
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) {
|
||||
return FALSE;
|
||||
|
|
|
@ -61,9 +61,7 @@
|
|||
#else
|
||||
#include "radio.h"
|
||||
#endif
|
||||
#if USB_CONF_RS232
|
||||
#include "dev/rs232.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "dev/watchdog.h"
|
||||
|
@ -130,12 +128,16 @@ PROCESS_THREAD(cdc_process, ev, data_proc)
|
|||
{
|
||||
PROCESS_BEGIN();
|
||||
|
||||
#if USB_CONF_RS232
|
||||
static FILE *rs232_stdout,*usb_stdout;
|
||||
rs232_stdout=stdout;
|
||||
#endif
|
||||
|
||||
while(1) {
|
||||
// turn off LED's if necessary
|
||||
if (led3_timer) led3_timer--;
|
||||
else Led3_off();
|
||||
|
||||
|
||||
if(Is_device_enumerated()) {
|
||||
// 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) {
|
||||
|
@ -150,6 +152,7 @@ PROCESS_THREAD(cdc_process, ev, data_proc)
|
|||
} else {
|
||||
stdout = previous_stdout;
|
||||
}
|
||||
usb_stdout=stdout;
|
||||
}
|
||||
|
||||
//Flush buffer if timeout
|
||||
|
@ -160,14 +163,19 @@ PROCESS_THREAD(cdc_process, ev, data_proc)
|
|||
timer++;
|
||||
}
|
||||
|
||||
#if USB_CONF_RS232
|
||||
stdout=usb_stdout;
|
||||
#endif
|
||||
while (uart_usb_test_hit()){
|
||||
menu_process(uart_usb_getchar()); // See what they want
|
||||
}
|
||||
|
||||
|
||||
#if USB_CONF_RS232
|
||||
stdout=rs232_stdout;
|
||||
#endif
|
||||
}//if (Is_device_enumerated())
|
||||
|
||||
|
||||
|
||||
if (USB_CONFIG_HAS_DEBUG_PORT(usb_configuration_nb)) {
|
||||
etimer_set(&et, CLOCK_SECOND/80);
|
||||
} 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.
|
||||
* 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 */
|
||||
/* 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
|
||||
//#define USB_CONF_STORAGE 1 /* TODO: Mass storage is currently broken */
|
||||
|
||||
/* ************************************************************************** */
|
||||
//#pragma mark RIME Settings
|
||||
|
|
|
@ -64,11 +64,11 @@
|
|||
#include "contiki-lib.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
|
||||
|
||||
#include "usb_task.h"
|
||||
#if USB_CONF_CDC
|
||||
#if USB_CONF_SERIAL
|
||||
#include "cdc_task.h"
|
||||
#endif
|
||||
#if USB_CONF_RS232
|
||||
|
@ -425,7 +425,7 @@ static void initialize(void) {
|
|||
|
||||
/* Setup USB */
|
||||
process_start(&usb_process, NULL);
|
||||
#if USB_CONF_CDC
|
||||
#if USB_CONF_SERIAL
|
||||
process_start(&cdc_process, NULL);
|
||||
#endif
|
||||
process_start(&usb_eth_process, NULL);
|
||||
|
@ -434,7 +434,7 @@ static void initialize(void) {
|
|||
#endif
|
||||
|
||||
#if ANNOUNCE
|
||||
#if USB_CONF_CDC
|
||||
#if USB_CONF_SERIAL&&!USB_CONF_RS232
|
||||
{unsigned short i;
|
||||
printf_P(PSTR("\n\n\n********BOOTING CONTIKI*********\n\r"));
|
||||
/* Allow USB CDC to keep up with printfs */
|
||||
|
@ -453,10 +453,9 @@ static void initialize(void) {
|
|||
#endif /* RF230BB */
|
||||
printf_P(PSTR("System online.\n\r"));
|
||||
}
|
||||
#endif /* USB_CONF_CDC */
|
||||
#if USB_CONF_RS232
|
||||
#elif USB_CONF_RS232
|
||||
printf_P(PSTR("System online.\n"));
|
||||
#endif /* USB_CONF_RS232 */
|
||||
#endif
|
||||
#endif /* ANNOUNCE */
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue