Recent Changes - Search:

edit SideBar

Compilation

This page is about compiling the Duktape Host for TockOS

See also Duktape2 Initial Compilation

abort()

/Users/cxh/src/hail/tock/userland/libtock/build/cortex-m4/libtock.a(sys.o): In function `abort':
/Users/cxh/src/hail/tock/userland/libtock/sys.c:56: multiple definition of `abort'

/Users/cxh/src/hail/tock/userland/newlib/libc.a(lib_a-abort.o):/home/alevy/hack/helena/tock/userland/newlib/newlib-2.2.0.20150423-out/arm-none-eabi/armv6-m/newlib/libc/stdlib/../../../../../../newlib-2.2.0.20150423/newlib/libc/stdlib/abort.c:55: first defined here

The solution was to edit duktape/Makefile and add -DDUK_OPT_SEGFAULT_ON_PANIC to TINY_EDUK_FLAGS.

_gettimeofday()

/Users/cxh/src/hail/tock/userland/newlib/libc.a(lib_a-gettimeofdayr.o): In function `_gettimeofday_r':
/home/alevy/hack/helena/tock/userland/newlib/newlib-2.2.0.20150423-out/arm-none-eabi/armv6-m/newlib/libc/reent/../../../../../../\
newlib-2.2.0.20150423/newlib/libc/reent/gettimeofdayr.c:71: undefined reference to `_gettimeofday'

collect2: error: ld returned 1 exit status
make: *** [/Users/cxh/src/hail/tock/userland/examples/duktape/build/cortex-m4/app.elf] Error 1

c_eventloop.c calls gettimeofday() and usleep(), which we can ifdef out temporarily:

/* Get Javascript compatible 'now' timestamp (millisecs since 1970). */
static double get_now(void) {
        struct timeval tv;
        int rc;

#ifdef __ARM_EABI__
        // FIXME: Need gettimeofday(), see {$ACCESSORS_HOME}/wiki/Main/DuktapeEclipseARMCortexM4#TimerSetup    
        return 0.0;
#else
        rc = gettimeofday(&tv, NULL);
        if (rc != 0) {
                /* Should never happen, so return whatever. */
                return 0.0;
        }
        return ((double) tv.tv_sec) * 1000.0 + ((double) tv.tv_usec) / 1000.0;
#endif

}
...

// Accessors: Use usleep() here instead of poll().                                                                                
                //printf("timeout -> %d \n", timeout);                                                                            
#ifndef __ARM_EABI__
                // FIXME: Need usleep()                                                                                          
                usleep(timeout*1000);
#endif
                //rc = poll(poll_list, poll_count, timeout);                                                                      
                rc = 0;

However, even with the above, we still get a message about _gettimeofday.

We need to define a _gettimeofday() function?

Adding the following to c_eventloop.c:

#ifdef __ARM_EABI__
int _gettimeofday(struct timeval *tp, void *tzp) {
  return 0;
}
#endif

solves the problem

  LD        /Users/cxh/src/hail/tock/userland/examples/duktape/build/cortex-m4/app.elf
 BIN        /Users/cxh/src/hail/tock/userland/examples/duktape/build/cortex-m4/app.bin
   Compiling byteorder v0.4.2
   Compiling getopts v0.2.14
   Compiling elf v0.0.6 (https://github.com/cole14/rust-elf#7398e3e0)
   Compiling elf2tbf v0.1.0 (file:///Users/cxh/src/hail/tock/userland/tools/elf2tbf)
    Finished debug [unoptimized + debuginfo] target(s) in 2.73 secs
     Running `/Users/cxh/src/hail/tock/userland/tools/elf2tbf/target/debug/elf2tbf -o /Users/cxh/src/hail/tock/userland/examples/\
duktape/build/cortex-m4/app.bin /Users/cxh/src/hail/tock/userland/examples/duktape/build/cortex-m4/app.elf`
   text    data     bss     dec     hex filename
 308136    3401     272  311809   4c201 /Users/cxh/src/hail/tock/userland/examples/duktape/build/cortex-m4/app.elf
bash-3.2$

Next step, see Duktape Eclipse ARM Cortex M4 -> Timer Setup for a possible gettimeofday() solution.

Or, see https://github.com/helena-project/tock/blob/master/userland/libtock/timer.h for timer_read(), so we now have:

#ifdef __ARM_EABI__
#include "timer.h" // TockOS specific, see https://github.com/helena-project/tock/blob/master/userland/libtock/timer.h            
int _gettimeofday(struct timeval *tp, void *tzp) {
  return timer_read();
}
#endif

usleep()

Now that it compiles, we can go back and fix some of the FIXMEs.

usleep() was not found:

/Users/cxh/src/hail/tock/userland/examples/duktape/c_eventloop.c:388: undefined reference to `usleep'

Happily, https://github.com/helena-project/tock/blob/master/userland/examples/blink_sync/main.c defines

/* Delay for for the given microseconds (approximately).
 *
 * For a 16 MHz CPU, 1us == 16 instructions (assuming each instruction takes
 * one cycle). */

static void busy_delay_us(int duration) {
  // The inner loop instructions are: 14 NOPs + 1 SUBS/ADDS + 1 CMP
  while (duration-- != 0) {
    __asm volatile (
      "nop\n"
      "nop\n"
      "nop\n"
      "nop\n"
      "nop\n"
      "nop\n"
      "nop\n"
      "nop\n"
      "nop\n"
      "nop\n"
      "nop\n"
      "nop\n"
      "nop\n"
      "nop\n"
    );
  }
}

So, we can use that for microsecond delays.

Or, we can use the TockOS Timer: https://github.com/helena-project/tock/blob/master/userland/libtock/timer.h

See Duktape2 Initial Compilation

Edit - History - Print - Recent Changes - Search
Page last modified on January 22, 2017, at 02:15 PM