support lolo's board
authorFabrice Desclaux <serpilliere@droids-corp.org>
Tue, 27 Mar 2012 21:19:30 +0000 (23:19 +0200)
committerFabrice Desclaux <serpilliere@droids-corp.org>
Tue, 27 Mar 2012 21:19:30 +0000 (23:19 +0200)
serpi & zer0

DualVirtualSerial.c
autoconf.h
avr6.x [new file with mode: 0644]
cmdline.c
cmdline.h
main.c
makefile
uart_config.h

index f5f4053..df22741 100644 (file)
 #include "main.h"\r
 #include "cmdline.h"\r
 \r
 #include "main.h"\r
 #include "cmdline.h"\r
 \r
-volatile uint16_t global_ms;\r
-struct callout_manager cm;\r
-\r
-\r
 /** LUFA CDC Class driver interface configuration and state information. This structure is\r
  *  passed to all CDC Class driver functions, so that multiple instances of the same class\r
  *  within a device can be differentiated from one another. This is for the first CDC interface,\r
 /** LUFA CDC Class driver interface configuration and state information. This structure is\r
  *  passed to all CDC Class driver functions, so that multiple instances of the same class\r
  *  within a device can be differentiated from one another. This is for the first CDC interface,\r
@@ -113,90 +109,6 @@ USB_ClassInfo_CDC_Device_t VirtualSerial2_CDC_Interface =
        };\r
 \r
 \r
        };\r
 \r
 \r
-/* return time in milliseconds on unsigned 16 bits */\r
-static uint16_t get_time_ms(void)\r
-{\r
-       return global_ms;\r
-}\r
-\r
-static void do_led_blink(struct callout_manager *cm,\r
-                        struct callout *clt, void *dummy)\r
-{\r
-       static uint8_t a = 0;\r
-\r
-       if (a & 1)\r
-               LEDs_SetAllLEDs(0);\r
-       else\r
-               LEDs_SetAllLEDs(0xff);\r
-       a++;\r
-}\r
-\r
-static void increment_ms(void *dummy)\r
-{\r
-       global_ms++;\r
-}\r
-\r
-static void main_timer_interrupt(void)\r
-{\r
-       static uint8_t cpt = 0;\r
-       cpt++;\r
-       sei();\r
-       if ((cpt & 0x3) == 0)\r
-               scheduler_interrupt();\r
-}\r
-\r
-\r
-/** Main program entry point. This routine contains the overall program flow, including initial\r
- *  setup of all components and the main program loop.\r
- */\r
-int main(void)\r
-{\r
-       struct callout t1;\r
-       FILE *xbee_file;\r
-       int8_t err;\r
-       struct xbee_dev dev;\r
-\r
-       SetupHardware();\r
-\r
-       LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);\r
-\r
-       fdevopen(usbserial1_dev_send, usbserial1_dev_recv);\r
-       xbee_file = fdevopen(usbserial2_dev_send, usbserial2_dev_recv);\r
-       scheduler_init();\r
-       timer_init();\r
-       timer0_register_OV_intr(main_timer_interrupt);\r
-       sei();\r
-\r
-       scheduler_add_periodical_event_priority(increment_ms, NULL,\r
-                                               1000L / SCHEDULER_UNIT,\r
-                                               LED_PRIO);\r
-       cmdline_init();\r
-       callout_manager_init(&cm, get_time_ms);\r
-       callout_reset(&cm, &t1, 500, PERIODICAL, do_led_blink, NULL);\r
-\r
-       /* initialize libxbee */\r
-       err = xbee_init();\r
-       if (err < 0)\r
-               return -1;\r
-\r
-       xbee_dev = &dev;\r
-\r
-       /* open xbee device */\r
-       if (xbee_open(xbee_dev, xbee_file) < 0)\r
-               return -1;\r
-\r
-       /* register default channel with a callback */\r
-       if (xbee_register_channel(xbee_dev, XBEE_DEFAULT_CHANNEL,\r
-                                 xbee_rx, NULL) < 0) {\r
-               fprintf(stderr, "cannot register default channel\n");\r
-               return -1;\r
-       }\r
-\r
-       sei();\r
-       xbee_mainloop();\r
-       return 0;\r
-}\r
-\r
 /** Configures the board hardware and chip peripherals for the demo's functionality. */\r
 void SetupHardware(void)\r
 {\r
 /** Configures the board hardware and chip peripherals for the demo's functionality. */\r
 void SetupHardware(void)\r
 {\r
index 6bec9b5..feb99d1 100644 (file)
@@ -53,7 +53,7 @@
 #undef  CONFIG_MCU_ATMEGA2560
 #undef  CONFIG_MCU_ATMEGA256
 #define CONFIG_MCU_ATMEGAUSB1287
 #undef  CONFIG_MCU_ATMEGA2560
 #undef  CONFIG_MCU_ATMEGA256
 #define CONFIG_MCU_ATMEGAUSB1287
-#define CONFIG_QUARTZ (16000000)
+#define CONFIG_QUARTZ (8000000)
 
 /*
  * Generation options
 
 /*
  * Generation options
diff --git a/avr6.x b/avr6.x
new file mode 100644 (file)
index 0000000..3ad392f
--- /dev/null
+++ b/avr6.x
@@ -0,0 +1,269 @@
+/* Default linker script, for normal executables */
+OUTPUT_FORMAT("elf32-avr","elf32-avr","elf32-avr")
+OUTPUT_ARCH(avr:6)
+MEMORY
+{
+  text      (rx)   : ORIGIN = 0, LENGTH = 1024K
+  data      (rw!x) : ORIGIN = 0x800200, LENGTH = 0xfe00
+  eeprom    (rw!x) : ORIGIN = 0x810000, LENGTH = 64K
+  fuse      (rw!x) : ORIGIN = 0x820000, LENGTH = 1K
+  lock      (rw!x) : ORIGIN = 0x830000, LENGTH = 1K
+  signature (rw!x) : ORIGIN = 0x840000, LENGTH = 1K
+}
+SECTIONS
+{
+  /* Read-only sections, merged into text segment: */
+  .hash          : { *(.hash)          }
+  .dynsym        : { *(.dynsym)                }
+  .dynstr        : { *(.dynstr)                }
+  .gnu.version   : { *(.gnu.version)   }
+  .gnu.version_d   : { *(.gnu.version_d)       }
+  .gnu.version_r   : { *(.gnu.version_r)       }
+  .rel.init      : { *(.rel.init)              }
+  .rela.init     : { *(.rela.init)     }
+  .rel.text      :
+    {
+      *(.rel.text)
+      *(.rel.text.*)
+      *(.rel.gnu.linkonce.t*)
+    }
+  .rela.text     :
+    {
+      *(.rela.text)
+      *(.rela.text.*)
+      *(.rela.gnu.linkonce.t*)
+    }
+  .rel.fini      : { *(.rel.fini)              }
+  .rela.fini     : { *(.rela.fini)     }
+  .rel.rodata    :
+    {
+      *(.rel.rodata)
+      *(.rel.rodata.*)
+      *(.rel.gnu.linkonce.r*)
+    }
+  .rela.rodata   :
+    {
+      *(.rela.rodata)
+      *(.rela.rodata.*)
+      *(.rela.gnu.linkonce.r*)
+    }
+  .rel.data      :
+    {
+      *(.rel.data)
+      *(.rel.data.*)
+      *(.rel.gnu.linkonce.d*)
+    }
+  .rela.data     :
+    {
+      *(.rela.data)
+      *(.rela.data.*)
+      *(.rela.gnu.linkonce.d*)
+    }
+  .rel.ctors     : { *(.rel.ctors)     }
+  .rela.ctors    : { *(.rela.ctors)    }
+  .rel.dtors     : { *(.rel.dtors)     }
+  .rela.dtors    : { *(.rela.dtors)    }
+  .rel.got       : { *(.rel.got)               }
+  .rela.got      : { *(.rela.got)              }
+  .rel.bss       : { *(.rel.bss)               }
+  .rela.bss      : { *(.rela.bss)              }
+  .rel.plt       : { *(.rel.plt)               }
+  .rela.plt      : { *(.rela.plt)              }
+  /* Internal text space or external memory.  */
+  .text :
+  {
+    *(.vectors)
+    KEEP(*(.vectors))
+    . = 256 + ALIGN(256); /* placeholder for misc microb infos */
+    /* For data that needs to reside in the lower 64k of progmem.  */
+    *(.progmem.gcc*)
+    *(.progmem*)
+    . = ALIGN(2048);
+     __trampolines_start = . ;
+    /* The jump trampolines for the 16-bit limited relocs will reside here.  */
+    *(.trampolines)
+    *(.trampolines*)
+     __trampolines_end = . ;
+    /* For future tablejump instruction arrays for 3 byte pc devices.
+       We don't relax jump/call instructions within these sections.  */
+    *(.jumptables)
+    *(.jumptables*)
+    /* For code that needs to reside in the lower 128k progmem.  */
+    *(.lowtext)
+    *(.lowtext*)
+     __ctors_start = . ;
+     *(.ctors)
+     __ctors_end = . ;
+     __dtors_start = . ;
+     *(.dtors)
+     __dtors_end = . ;
+    KEEP(SORT(*)(.ctors))
+    KEEP(SORT(*)(.dtors))
+    /* From this point on, we don't bother about wether the insns are
+       below or above the 16 bits boundary.  */
+    *(.init0)  /* Start here after reset.  */
+    KEEP (*(.init0))
+    *(.init1)
+    KEEP (*(.init1))
+    *(.init2)  /* Clear __zero_reg__, set up stack pointer.  */
+    KEEP (*(.init2))
+    *(.init3)
+    KEEP (*(.init3))
+    *(.init4)  /* Initialize data and BSS.  */
+    KEEP (*(.init4))
+    *(.init5)
+    KEEP (*(.init5))
+    *(.init6)  /* C++ constructors.  */
+    KEEP (*(.init6))
+    *(.init7)
+    KEEP (*(.init7))
+    *(.init8)
+    KEEP (*(.init8))
+    *(.init9)  /* Call main().  */
+    KEEP (*(.init9))
+    *(.text.*) /* trucs de gcc ? */
+    . = ALIGN(2048);
+    /* some libc stuff */
+    strc*(.text)
+    mem*(.text)
+    printf*(.text)
+    vfprintf*(.text)
+    sprintf*(.text)
+    snprintf*(.text)
+    malloc*(.text)
+    free*(.text)
+    fdevopen*(.text)
+    fputc*(.text)
+    . = ALIGN(2048);
+    uart*(.text)
+    pwm*(.text)
+    parse*(.text)
+    rdline*(.text)
+    vt100*(.text)
+    scheduler*(.text)
+    control_system*(.text)
+    pid*(.text)
+    f08*(.text)
+    f16*(.text)
+    f32*(.text)
+    f64*(.text)
+    vect2*(.text)
+    quadramp*(.text)
+    blocking*(.text)
+    obstacle*(.text)
+    trajectory*(.text)
+    position*(.text)
+    adc*(.text)
+    robot*(.text)
+    error*(.text)
+    encoders*(.text)
+    time*(.text)
+    cirbuf*(.text)
+    i2c*(.text)
+    spi*(.text)
+    ax12*(.text)
+    . = ALIGN(2048);
+    *(.text)
+    . = ALIGN(2);
+    *(.fini9)  /* _exit() starts here.  */
+    KEEP (*(.fini9))
+    *(.fini8)
+    KEEP (*(.fini8))
+    *(.fini7)
+    KEEP (*(.fini7))
+    *(.fini6)  /* C++ destructors.  */
+    KEEP (*(.fini6))
+    *(.fini5)
+    KEEP (*(.fini5))
+    *(.fini4)
+    KEEP (*(.fini4))
+    *(.fini3)
+    KEEP (*(.fini3))
+    *(.fini2)
+    KEEP (*(.fini2))
+    *(.fini1)
+    KEEP (*(.fini1))
+    *(.fini0)  /* Infinite loop after program termination.  */
+    KEEP (*(.fini0))
+     _etext = . ;
+  }  > text
+  .data          : AT (ADDR (.text) + SIZEOF (.text))
+  {
+     PROVIDE (__data_start = .) ;
+    *(.data)
+    *(.data*)
+    *(.rodata)  /* We need to include .rodata here if gcc is used */
+    *(.rodata*) /* with -fdata-sections.  */
+    *(.gnu.linkonce.d*)
+    . = ALIGN(2);
+     _edata = . ;
+     PROVIDE (__data_end = .) ;
+  }  > data
+  .bss  SIZEOF(.data) + ADDR(.data) :
+  {
+     PROVIDE (__bss_start = .) ;
+    *(.bss)
+    *(.bss*)
+    *(COMMON)
+     PROVIDE (__bss_end = .) ;
+  }  > data
+   __data_load_start = LOADADDR(.data);
+   __data_load_end = __data_load_start + SIZEOF(.data);
+  /* Global data not cleared after reset.  */
+  .noinit  SIZEOF(.bss) + ADDR(.bss) :
+  {
+     PROVIDE (__noinit_start = .) ;
+    *(.noinit*)
+     PROVIDE (__noinit_end = .) ;
+     _end = . ;
+     PROVIDE (__heap_start = .) ;
+  }  > data
+  .eeprom  :
+  {
+    *(.eeprom*)
+     __eeprom_end = . ;
+  }  > eeprom
+  .fuse  :
+  {
+    KEEP(*(.fuse))
+    KEEP(*(.lfuse))
+    KEEP(*(.hfuse))
+    KEEP(*(.efuse))
+  }  > fuse
+  .lock  :
+  {
+    KEEP(*(.lock*))
+  }  > lock
+  .signature  :
+  {
+    KEEP(*(.signature*))
+  }  > signature
+  /* Stabs debugging sections.  */
+  .stab 0 : { *(.stab) }
+  .stabstr 0 : { *(.stabstr) }
+  .stab.excl 0 : { *(.stab.excl) }
+  .stab.exclstr 0 : { *(.stab.exclstr) }
+  .stab.index 0 : { *(.stab.index) }
+  .stab.indexstr 0 : { *(.stab.indexstr) }
+  .comment 0 : { *(.comment) }
+  /* DWARF debug sections.
+     Symbols in the DWARF debugging sections are relative to the beginning
+     of the section so we begin them at 0.  */
+  /* DWARF 1 */
+  .debug          0 : { *(.debug) }
+  .line           0 : { *(.line) }
+  /* GNU DWARF 1 extensions */
+  .debug_srcinfo  0 : { *(.debug_srcinfo) }
+  .debug_sfnames  0 : { *(.debug_sfnames) }
+  /* DWARF 1.1 and DWARF 2 */
+  .debug_aranges  0 : { *(.debug_aranges) }
+  .debug_pubnames 0 : { *(.debug_pubnames) }
+  /* DWARF 2 */
+  .debug_info     0 : { *(.debug_info) *(.gnu.linkonce.wi.*) }
+  .debug_abbrev   0 : { *(.debug_abbrev) }
+  .debug_line     0 : { *(.debug_line) }
+  .debug_frame    0 : { *(.debug_frame) }
+  .debug_str      0 : { *(.debug_str) }
+  .debug_loc      0 : { *(.debug_loc) }
+  .debug_macinfo  0 : { *(.debug_macinfo) }
+}
index 36d1f31..60dc9a6 100644 (file)
--- a/cmdline.c
+++ b/cmdline.c
 #include "main.h"
 #include "cmdline.h"
 
 #include "main.h"
 #include "cmdline.h"
 
-#include "DualVirtualSerial.h"
 
 
+#ifdef USE_USB
+#include "DualVirtualSerial.h"
+#endif
 
 
 
 
-/******** See in commands.c for the list of commands. */
 extern parse_pgm_ctx_t main_ctx[];
 
 extern parse_pgm_ctx_t main_ctx[];
 
-int usbserial1_dev_send(char c, FILE* f)
+int cmdline_dev_send(char c, FILE* f)
 {
 {
+#ifdef USE_USB
        CDC_Device_SendByte(&VirtualSerial1_CDC_Interface, (uint8_t)c);
        CDC_Device_SendByte(&VirtualSerial1_CDC_Interface, (uint8_t)c);
+#else
+       uart_send(CMDLINE_UART, c);
+#endif
        return 0;
 }
 
        return 0;
 }
 
-int usbserial1_dev_recv(FILE* f)
+int cmdline_dev_recv(FILE* f)
 {
        int16_t c;
 {
        int16_t c;
+#ifdef USE_USB
        /* non-blocking ! */
        c = CDC_Device_ReceiveByte(&VirtualSerial1_CDC_Interface);
        /* non-blocking ! */
        c = CDC_Device_ReceiveByte(&VirtualSerial1_CDC_Interface);
+#else
+       c = uart_recv_nowait(CMDLINE_UART);
+#endif
        if (c < 0)
                return _FDEV_EOF;
 
        if (c < 0)
                return _FDEV_EOF;
 
@@ -61,25 +70,32 @@ int usbserial1_dev_recv(FILE* f)
 }
 
 
 }
 
 
-int usbserial2_dev_send(char c, FILE* f)
+int xbee_dev_send(char c, FILE* f)
 {
 {
+#ifdef USE_USB
        CDC_Device_SendByte(&VirtualSerial2_CDC_Interface, (uint8_t)c);
        CDC_Device_SendByte(&VirtualSerial2_CDC_Interface, (uint8_t)c);
+#else
+       uart_send(XBEE_UART, c);
+#endif
        return 0;
 }
 
        return 0;
 }
 
-int usbserial2_dev_recv(FILE* f)
+int xbee_dev_recv(FILE* f)
 {
        int16_t c;
 
 {
        int16_t c;
 
+#ifdef USE_USB
        /* non-blocking ! */
        c = CDC_Device_ReceiveByte(&VirtualSerial2_CDC_Interface);
        /* non-blocking ! */
        c = CDC_Device_ReceiveByte(&VirtualSerial2_CDC_Interface);
+#else
+       c = uart_recv_nowait(XBEE_UART);
+#endif
        if (c < 0)
                return _FDEV_EOF;
 
        return c;
 }
 
        if (c < 0)
                return _FDEV_EOF;
 
        return c;
 }
 
-
 static void
 valid_buffer(const char *buf, uint8_t size)
 {
 static void
 valid_buffer(const char *buf, uint8_t size)
 {
@@ -104,7 +120,7 @@ complete_buffer(const char *buf, char *dstbuf, uint8_t dstsize,
 
 static void write_char(char c)
 {
 
 static void write_char(char c)
 {
-       usbserial1_dev_send(c, NULL);
+       cmdline_dev_send(c, NULL);
 }
 
 
 }
 
 
@@ -170,7 +186,7 @@ int cmdline_poll(void)
        int8_t ret, same = 0;
        int16_t c;
 
        int8_t ret, same = 0;
        int16_t c;
 
-       c = CDC_Device_ReceiveByte(&VirtualSerial1_CDC_Interface);
+       c = cmdline_dev_recv(NULL);
        if (c < 0)
                return -1;
 
        if (c < 0)
                return -1;
 
index 958660a..508d026 100644 (file)
--- a/cmdline.h
+++ b/cmdline.h
  */
 
 
  */
 
 
+#ifdef USE_USB
 #include "DualVirtualSerial.h"
 #include "DualVirtualSerial.h"
+#else
+#define CMDLINE_UART 0
+#define XBEE_UART 2
+#endif
 
 void cmdline_init(void);
 
 
 void cmdline_init(void);
 
@@ -34,24 +39,36 @@ void mylog(struct error * e, ...);
 /* poll cmdline */
 int cmdline_poll(void);
 
 /* poll cmdline */
 int cmdline_poll(void);
 
-int usbserial1_dev_send(char c, FILE* f);
-int usbserial1_dev_recv(FILE* f);
+int cmdline_dev_send(char c, FILE* f);
+int cmdline_dev_recv(FILE* f);
 
 
-int usbserial2_dev_send(char c, FILE* f);
-int usbserial2_dev_recv(FILE* f);
+int xbee_dev_send(char c, FILE* f);
+int xbee_dev_recv(FILE* f);
 
 static inline uint8_t cmdline_keypressed(void) {
 
 static inline uint8_t cmdline_keypressed(void) {
+#ifdef USE_USB
        return (CDC_Device_ReceiveByte(&VirtualSerial1_CDC_Interface) >= 0);
        return (CDC_Device_ReceiveByte(&VirtualSerial1_CDC_Interface) >= 0);
+#else
+       return (uart_recv_nowait(CMDLINE_UART) != -1);
+#endif
 }
 
 static inline int16_t cmdline_getchar(void) {
 }
 
 static inline int16_t cmdline_getchar(void) {
+#ifdef USE_USB
        return CDC_Device_ReceiveByte(&VirtualSerial1_CDC_Interface);
        return CDC_Device_ReceiveByte(&VirtualSerial1_CDC_Interface);
+#else
+       return uart_recv_nowait(CMDLINE_UART);
+#endif
 }
 
 static inline uint8_t cmdline_getchar_wait(void) {
 }
 
 static inline uint8_t cmdline_getchar_wait(void) {
+#ifdef USE_USB
        int16_t c;
        do {
                c = CDC_Device_ReceiveByte(&VirtualSerial1_CDC_Interface);
        } while (c < 0);
        return c;
        int16_t c;
        do {
                c = CDC_Device_ReceiveByte(&VirtualSerial1_CDC_Interface);
        } while (c < 0);
        return c;
+#else
+       return uart_recv(CMDLINE_UART);
+#endif
 }
 }
diff --git a/main.c b/main.c
index d5c3f5a..2bcb3ec 100644 (file)
--- a/main.c
+++ b/main.c
@@ -60,6 +60,8 @@
 #include "main.h"
 
 struct xbeeboard xbeeboard;
 #include "main.h"
 
 struct xbeeboard xbeeboard;
+volatile uint16_t global_ms;
+struct callout_manager cm;
 
 #define TIMEOUT_MS 1000
 
 
 #define TIMEOUT_MS 1000
 
@@ -497,7 +499,7 @@ void xbee_unload_timeout(struct xbee_ctx *ctx)
 
 void bootloader(void)
 {
 
 void bootloader(void)
 {
-#define BOOTLOADER_ADDR 0x1e000
+#define BOOTLOADER_ADDR 0x1f800
        if (pgm_read_byte_far(BOOTLOADER_ADDR) == 0xff) {
                printf_P(PSTR("Bootloader is not present\r\n"));
                return;
        if (pgm_read_byte_far(BOOTLOADER_ADDR) == 0xff) {
                printf_P(PSTR("Bootloader is not present\r\n"));
                return;
@@ -526,13 +528,12 @@ void xbee_mainloop(void)
                        int16_t c;
 
                        /* from xbee to cmdline */
                        int16_t c;
 
                        /* from xbee to cmdline */
-                       c = CDC_Device_ReceiveByte(&VirtualSerial2_CDC_Interface);
+                       c = xbee_dev_recv(NULL);
                        if (c >= 0)
                        if (c >= 0)
-                               CDC_Device_SendByte(&VirtualSerial1_CDC_Interface,
-                                                   (uint8_t)c);
+                               cmdline_dev_send((uint8_t)c, NULL);
 
                        /* from cmdline to xbee */
 
                        /* from cmdline to xbee */
-                       c = CDC_Device_ReceiveByte(&VirtualSerial1_CDC_Interface);
+                       c = cmdline_dev_recv(NULL);
                        if (c == 4) { /* CTRL-d */
                                xbee_raw = 0;
                                rdline_newline(&xbeeboard.rdl,
                        if (c == 4) { /* CTRL-d */
                                xbee_raw = 0;
                                rdline_newline(&xbeeboard.rdl,
@@ -540,11 +541,10 @@ void xbee_mainloop(void)
                        }
                        else if (c >= 0) {
                                /* send to xbee */
                        }
                        else if (c >= 0) {
                                /* send to xbee */
-                               CDC_Device_SendByte(&VirtualSerial2_CDC_Interface,
-                                                   (uint8_t)c);
+                               xbee_dev_send((uint8_t)c, NULL);
+
                                /* echo on cmdline */
                                /* echo on cmdline */
-                               CDC_Device_SendByte(&VirtualSerial1_CDC_Interface,
-                                                   (uint8_t)c);
+                               cmdline_dev_send((uint8_t)c, NULL);
                        }
                }
                else {
                        }
                }
                else {
@@ -553,8 +553,104 @@ void xbee_mainloop(void)
                        xbee_proto_rx(xbee_dev);
                }
 
                        xbee_proto_rx(xbee_dev);
                }
 
+#ifdef USE_USB
                CDC_Device_USBTask(&VirtualSerial1_CDC_Interface);
                CDC_Device_USBTask(&VirtualSerial2_CDC_Interface);
                USB_USBTask();
                CDC_Device_USBTask(&VirtualSerial1_CDC_Interface);
                CDC_Device_USBTask(&VirtualSerial2_CDC_Interface);
                USB_USBTask();
+#endif
        }
 }
        }
 }
+
+/* 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;
+
+#ifdef USE_USB
+       if (a & 1)
+               LEDs_SetAllLEDs(0);
+       else
+               LEDs_SetAllLEDs(0xff);
+#else
+       /* XXX */
+#endif
+       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;
+
+#ifdef USE_USB
+       SetupHardware();
+
+       LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
+#else
+       uart_init();
+#endif
+
+       fdevopen(cmdline_dev_send, cmdline_dev_recv);
+       xbee_file = fdevopen(xbee_dev_send, xbee_dev_recv);
+       scheduler_init();
+       timer_init();
+       timer0_register_OV_intr(main_timer_interrupt);
+
+       scheduler_add_periodical_event_priority(increment_ms, NULL,
+                                               1000L / SCHEDULER_UNIT,
+                                               LED_PRIO);
+       cmdline_init();
+#ifndef USE_USB
+       /* in usb mode, it's done in usb callback */
+       rdline_newline(&xbeeboard.rdl, xbeeboard.prompt);
+#endif
+       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;
+}
index 5360008..51feddd 100644 (file)
--- a/makefile
+++ b/makefile
 \r
 \r
 # MCU name\r
 \r
 \r
 # MCU name\r
+ifneq ($(USE_USB),)\r
 MCU = at90usb1287\r
 MCU = at90usb1287\r
-\r
+else\r
+MCU = atmega2560\r
+endif\r
 \r
 # Target architecture (see library "Board Types" documentation).\r
 ARCH = AVR8\r
 \r
 # Target architecture (see library "Board Types" documentation).\r
 ARCH = AVR8\r
@@ -131,13 +134,17 @@ LUFA_OPTS += -D USE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENAB
 # Create the LUFA source path variables by including the LUFA root makefile\r
 include $(LUFA_PATH)/LUFA/makefile\r
 \r
 # Create the LUFA source path variables by including the LUFA root makefile\r
 include $(LUFA_PATH)/LUFA/makefile\r
 \r
-\r
-# List C source files here. (C dependencies are automatically generated.)\r
+ifneq ($(USE_USB),)\r
 SRC = \\r
        $(TARGET).c \\r
        Descriptors.c \\r
        $(LUFA_SRC_USB) \\r
        $(LUFA_SRC_USBCLASS) \\r
 SRC = \\r
        $(TARGET).c \\r
        Descriptors.c \\r
        $(LUFA_SRC_USB) \\r
        $(LUFA_SRC_USBCLASS) \\r
+       DualVirtualSerial.c\r
+endif\r
+\r
+# List C source files here. (C dependencies are automatically generated.)\r
+SRC += \\r
        cirbuf_add_buf_head.c \\r
        cirbuf_add_buf_tail.c \\r
        cirbuf_add_head.c \\r
        cirbuf_add_buf_head.c \\r
        cirbuf_add_buf_tail.c \\r
        cirbuf_add_head.c \\r
@@ -152,11 +159,8 @@ SRC = \
        cirbuf_get_buf_tail.c \\r
        cirbuf_get_head.c \\r
        cirbuf_get_tail.c \\r
        cirbuf_get_buf_tail.c \\r
        cirbuf_get_head.c \\r
        cirbuf_get_tail.c \\r
-       cmdline.c \\r
        commands.c \\r
        commands_gen.c \\r
        commands.c \\r
        commands_gen.c \\r
-       Descriptors.c \\r
-       DualVirtualSerial.c \\r
        main.c \\r
        rc_proto.c \\r
        parse.c \\r
        main.c \\r
        rc_proto.c \\r
        parse.c \\r
@@ -231,7 +235,8 @@ SRC = \
        parse_neighbor.c \\r
        parse_atcmd.c \\r
        parse_monitor.c \\r
        parse_neighbor.c \\r
        parse_atcmd.c \\r
        parse_monitor.c \\r
-       time.c\r
+       time.c \\r
+       cmdline.c\r
 \r
 # List C++ source files here. (C dependencies are automatically generated.)\r
 CPPSRC =\r
 \r
 # List C++ source files here. (C dependencies are automatically generated.)\r
 CPPSRC =\r
@@ -327,6 +332,9 @@ CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
 CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))\r
 CFLAGS += $(CSTANDARD)\r
 CFLAGS += -std=gnu99\r
 CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))\r
 CFLAGS += $(CSTANDARD)\r
 CFLAGS += -std=gnu99\r
+ifneq ($(USE_USB),)\r
+CFLAGS += -DUSE_USB\r
+endif\r
 \r
 \r
 #---------------- Compiler Options C++ ----------------\r
 \r
 \r
 #---------------- Compiler Options C++ ----------------\r
@@ -428,8 +436,9 @@ LDFLAGS += -Wl,--gc-sections
 LDFLAGS += $(EXTMEMOPTS)\r
 LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))\r
 LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)\r
 LDFLAGS += $(EXTMEMOPTS)\r
 LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))\r
 LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)\r
-#LDFLAGS += -T linker_script.x\r
-\r
+ifeq ($(USE_USB),)\r
+LDFLAGS = -T avr6.x\r
+endif\r
 \r
 \r
 #---------------- Programming Options (avrdude) ----------------\r
 \r
 \r
 #---------------- Programming Options (avrdude) ----------------\r
@@ -694,6 +703,7 @@ extcoff: $(TARGET).elf
 %.hex: %.elf\r
        @echo\r
        @echo $(MSG_FLASH) $@\r
 %.hex: %.elf\r
        @echo\r
        @echo $(MSG_FLASH) $@\r
+       $(OBJCOPY) -O binary -R .eeprom -R .fuse -R .lock $< $(TARGET).bin\r
        $(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock $< $@\r
 \r
 %.eep: %.elf\r
        $(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock $< $@\r
 \r
 %.eep: %.elf\r
index 8795a7e..f8b2f09 100644 (file)
 #define UART_CONFIG_H\r
 \r
 /*\r
 #define UART_CONFIG_H\r
 \r
 /*\r
- * UART1 definitions\r
+ * UART0 definitions\r
  */\r
 \r
  */\r
 \r
-/* compile uart1 fonctions, undefine it to pass compilation */\r
-#define UART1_COMPILE\r
+/* compile uart0 fonctions, undefine it to pass compilation */\r
+#define UART0_COMPILE\r
 \r
 \r
-/* enable uart1 if == 1, disable if == 0 */\r
-#define UART1_ENABLED  1\r
+/* enable uart0 if == 1, disable if == 0 */\r
+#define UART0_ENABLED  1\r
 \r
 \r
-/* enable uart1 interrupts if == 1, disable if == 0 */\r
-#define UART1_INTERRUPT_ENABLED  1\r
+/* enable uart0 interrupts if == 1, disable if == 0 */\r
+#define UART0_INTERRUPT_ENABLED  1\r
 \r
 \r
-#define UART1_BAUDRATE 57600\r
+#define UART0_BAUDRATE 57600\r
 \r
 /*\r
  * if you enable this, the maximum baudrate you can reach is\r
  * higher, but the precision is lower.\r
  */\r
 \r
 /*\r
  * if you enable this, the maximum baudrate you can reach is\r
  * higher, but the precision is lower.\r
  */\r
-#define UART1_USE_DOUBLE_SPEED 1\r
+#define UART0_USE_DOUBLE_SPEED 1\r
 \r
 \r
-#define UART1_RX_FIFO_SIZE 64\r
-#define UART1_TX_FIFO_SIZE 127\r
-#define UART1_NBITS 8\r
+#define UART0_RX_FIFO_SIZE 64\r
+#define UART0_TX_FIFO_SIZE 127\r
+#define UART0_NBITS 8\r
 \r
 \r
-#define UART1_PARITY UART_PARTITY_NONE\r
+#define UART0_PARITY UART_PARTITY_NONE\r
 \r
 \r
-#define UART1_STOP_BIT UART_STOP_BITS_1\r
+#define UART0_STOP_BIT UART_STOP_BITS_1\r
+\r
+/* .... same for uart 1, 2, 3 ... */\r
+\r
+/*\r
+ * UART2 definitions\r
+ */\r
+\r
+/* compile uart2 fonctions, undefine it to pass compilation */\r
+#define UART2_COMPILE\r
+\r
+/* enable uart2 if == 1, disable if == 0 */\r
+#define UART2_ENABLED  1\r
+\r
+/* enable uart2 interrupts if == 1, disable if == 0 */\r
+#define UART2_INTERRUPT_ENABLED  1\r
+\r
+#define UART2_BAUDRATE 9600\r
+\r
+/*\r
+ * if you enable this, the maximum baudrate you can reach is\r
+ * higher, but the precision is lower.\r
+ */\r
+#define UART2_USE_DOUBLE_SPEED 1\r
+\r
+#define UART2_RX_FIFO_SIZE 64\r
+#define UART2_TX_FIFO_SIZE 127\r
+#define UART2_NBITS 8\r
+\r
+#define UART2_PARITY UART_PARTITY_NONE\r
+\r
+#define UART2_STOP_BIT UART_STOP_BITS_1\r
 \r
 /* .... same for uart 1, 2, 3 ... */\r
 \r
 \r
 /* .... same for uart 1, 2, 3 ... */\r
 \r