X-Git-Url: http://git.droids-corp.org/?p=protos%2Fxbee-avr.git;a=blobdiff_plain;f=DualVirtualSerial.c;h=df22741ac5b84f95a8c469d7ddf42032a535b4e2;hp=f5f405304c5d8e7f556fffaca20f7c385e0fecff;hb=0e1c93804369af27043c82ccc778c42bf54a9bd4;hpb=1a0d8b2d8fb17cf4b2c845c52b22dc932efa080b diff --git a/DualVirtualSerial.c b/DualVirtualSerial.c index f5f4053..df22741 100644 --- a/DualVirtualSerial.c +++ b/DualVirtualSerial.c @@ -58,10 +58,6 @@ #include "main.h" #include "cmdline.h" -volatile uint16_t global_ms; -struct callout_manager cm; - - /** LUFA CDC Class driver interface configuration and state information. This structure is * passed to all CDC Class driver functions, so that multiple instances of the same class * within a device can be differentiated from one another. This is for the first CDC interface, @@ -113,90 +109,6 @@ USB_ClassInfo_CDC_Device_t VirtualSerial2_CDC_Interface = }; -/* return time in milliseconds on unsigned 16 bits */ -static uint16_t get_time_ms(void) -{ - return global_ms; -} - -static void do_led_blink(struct callout_manager *cm, - struct callout *clt, void *dummy) -{ - static uint8_t a = 0; - - if (a & 1) - LEDs_SetAllLEDs(0); - else - LEDs_SetAllLEDs(0xff); - a++; -} - -static void increment_ms(void *dummy) -{ - global_ms++; -} - -static void main_timer_interrupt(void) -{ - static uint8_t cpt = 0; - cpt++; - sei(); - if ((cpt & 0x3) == 0) - scheduler_interrupt(); -} - - -/** Main program entry point. This routine contains the overall program flow, including initial - * setup of all components and the main program loop. - */ -int main(void) -{ - struct callout t1; - FILE *xbee_file; - int8_t err; - struct xbee_dev dev; - - SetupHardware(); - - LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); - - fdevopen(usbserial1_dev_send, usbserial1_dev_recv); - xbee_file = fdevopen(usbserial2_dev_send, usbserial2_dev_recv); - scheduler_init(); - timer_init(); - timer0_register_OV_intr(main_timer_interrupt); - sei(); - - scheduler_add_periodical_event_priority(increment_ms, NULL, - 1000L / SCHEDULER_UNIT, - LED_PRIO); - cmdline_init(); - callout_manager_init(&cm, get_time_ms); - callout_reset(&cm, &t1, 500, PERIODICAL, do_led_blink, NULL); - - /* initialize libxbee */ - err = xbee_init(); - if (err < 0) - return -1; - - xbee_dev = &dev; - - /* open xbee device */ - if (xbee_open(xbee_dev, xbee_file) < 0) - return -1; - - /* register default channel with a callback */ - if (xbee_register_channel(xbee_dev, XBEE_DEFAULT_CHANNEL, - xbee_rx, NULL) < 0) { - fprintf(stderr, "cannot register default channel\n"); - return -1; - } - - sei(); - xbee_mainloop(); - return 0; -} - /** Configures the board hardware and chip peripherals for the demo's functionality. */ void SetupHardware(void) {