From 2bbf074f39cf53f17e84a49d078073bbd45d90a7 Mon Sep 17 00:00:00 2001 From: ksb Date: Sat, 1 Sep 2007 10:06:05 +0000 Subject: [PATCH] Added a gateway application the routes between SLIP on USB and the radio. --- platform/stepper-robot/gateway/Makefile | 11 +++ platform/stepper-robot/gateway/gateway.c | 105 +++++++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 platform/stepper-robot/gateway/Makefile create mode 100644 platform/stepper-robot/gateway/gateway.c diff --git a/platform/stepper-robot/gateway/Makefile b/platform/stepper-robot/gateway/Makefile new file mode 100644 index 000000000..fd867a7b4 --- /dev/null +++ b/platform/stepper-robot/gateway/Makefile @@ -0,0 +1,11 @@ +CONTIKI=../../../../contiki-2.x/ +TARGET=stepper-robot + +MCK=23961600 +XSLTPROC=xsltproc + +CONTIKI_TARGET_MAIN=contiki-main.c + +all: gateway + +include $(CONTIKI)/Makefile.include diff --git a/platform/stepper-robot/gateway/gateway.c b/platform/stepper-robot/gateway/gateway.c new file mode 100644 index 000000000..36b4b5c80 --- /dev/null +++ b/platform/stepper-robot/gateway/gateway.c @@ -0,0 +1,105 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +/* SLIP interface */ + +extern struct uip_fw_netif cc2420if; + +static struct uip_fw_netif slipif = +{UIP_FW_NETIF(0,0,0,0, 255,255,255,255, slip_send)}; + +/* USB buffers */ +static unsigned char input_buffer[128]; +static unsigned char output_buffer[128]; +static unsigned char interrupt_buffer[16]; + +#define DEV_TO_HOST 0x81 +#define HOST_TO_DEV 0x02 + +void +slip_arch_init(unsigned long ubr) +{ +} + +void +slip_arch_writeb(unsigned char c) +{ + while(usb_send_data(DEV_TO_HOST, &c, 1) != 1); +} + + +PROCESS(gateway_process, "Gateway process"); + + +PROCESS_THREAD(gateway_process, ev , data) +{ + static struct etimer timer; + PROCESS_BEGIN(); + usb_set_user_process(process_current); + usb_setup(); + usb_cdc_acm_setup(); + + uip_fw_default(&slipif); + uip_fw_register(&cc2420if); + + process_start(&slip_process, NULL); + + while(ev != PROCESS_EVENT_EXIT) { + PROCESS_WAIT_EVENT(); + if (ev == PROCESS_EVENT_TIMER) { + leds_toggle(LEDS_YELLOW); + etimer_restart(&timer); + } else if (ev == PROCESS_EVENT_MSG) { + const struct usb_user_msg * const msg = data; + switch(msg->type) { + case USB_USER_MSG_TYPE_CONFIG: + printf("User config\n"); + if (msg->data.config != 0) { + usb_setup_bulk_endpoint(DEV_TO_HOST, + input_buffer, sizeof(input_buffer)); + usb_setup_bulk_endpoint(HOST_TO_DEV, + output_buffer, sizeof(output_buffer)); + usb_setup_interrupt_endpoint(0x83,interrupt_buffer, + sizeof(interrupt_buffer)); + etimer_set(&timer, CLOCK_SECOND); + } else { + etimer_stop(&timer); + usb_disable_endpoint(DEV_TO_HOST); + usb_disable_endpoint(HOST_TO_DEV); + usb_disable_endpoint(0x83); + + } + break; + case USB_USER_MSG_TYPE_EP_OUT(2): + { + unsigned int len = msg->data.length; + /* printf("Received %d:\n", len); */ + { + unsigned char ch; + unsigned int xfer; + while((xfer = usb_recv_data(HOST_TO_DEV, &ch, 1)) > 0) { + /* printf(" %02x",ch); */ + if (slip_input_byte(ch)) break; + } + /* printf("\n"); */ + } + } + break; + } + + } + } + printf("USB test process exited\n"); + PROCESS_END(); +} + +AUTOSTART_PROCESSES(&gateway_process);