cpu/arm/k60: Implement newlib syscalls.

All newlib syscalls are somewhat implemented now. File IO is split into
device IO and actual file IO based on fd number. File IO is mapped to
CFS functions, device IO is mapped using a platform device operations
table. stdin, stdout, stderr is currently mapped to UART1.

See also: http://neptune.billgatliff.com/newlib.html

Signed-off-by: Joakim Gebart <joakim.gebart@eistec.se>
cpu/arm/k60: isatty: Set ENOTTY.

Set errno = ENOTTY when isatty is called with a non-tty fd.

Signed-off-by: Joakim Gebart <joakim.gebart@eistec.se>
cpu/arm/k60: Rework _open_r flags handling.

Just to make sure the case where flags = O_WRONLY|O_RDONLY works the
same as O_RDWR.

Signed-off-by: Joakim Gebart <joakim.gebart@eistec.se>
cpu/arm/k60: Add checks for invalid fd.

Add checks for fd less than zero in newlib syscalls for files, prevents
bugs where devoptab[-1] etc may be attempted to be read as if they are
valid device operation entries.

Signed-off-by: Joakim Gebart <joakim.gebart@eistec.se>
cpu/arm/k60: Refactor UART driver.

Major refactoring of UART driver:
 - Replaced UART_Type *uart_dev with unsigned int uart_num. No CPU
   specific pointers needed to call the UART functions.
 - Added support for automatically determining the current module clock
   frequency during uart_init().
 - Added uart_num parameter to uart_enable_rx_interrupt() and
   uart_set_rx_callback().
 - Support for RX interrupts on UARTs 0-5 (untested)
 - Support for TX buffering on all UARTs 0-5 (untested)
 - Some const-correctness fixes in UART driver API.
 - SLIP connection is using POSIX file API for handling writes. The
   SLIP driver is not yet completely decoupled from UART module, but a
   long term goal is to allow choosing between UART and other methods
   of opening a point to point link, for example USB-CDC, by simply
   modifying a #define in contiki-conf.h.
 - Removed dead printf_putc in contiki-main.c.
 - Added default buffer size UART_CONF_DEFAULT_TXBUFSIZE.
 - Added explanation for UART1_CONF_TXBUFSIZE.
 - Added #if UARTx_CONF_ENABLE preprocessor checks for each UART module
   ISR and TX buffer definition.
core/net/ip/slipdev: Remove unnecessary cast.

Remove unnecessary cast to char * and makes a warning go away. Gave
a warning previously:

    ../../../core/net/ip/slipdev.c:106:11: warning: assigning to
          'uint8_t *' (aka 'unsigned char *') from 'char *' converts
          between pointers to integer types with different sign
          [-Wpointer-sign]
          ptr = (char *)uip_appdata;
              ^ ~~~~~~~~~~~~~~~~~~~

Signed-off-by: Joakim Gebart <joakim.gebart@eistec.se>
core/sys/rtimer.h, rtimer.c: support multiple timers; allow cancellation

This rewrite of rtimers introduces the following changes:

- more than one rtimer can be used concurrently

  Some operations are O(n) for the number of active rtimers, so
  their number should still not be excessive.

- when setting an rtimer, the handler is guaranteed to be called
  exactly once. Before, it could also happen that it was never
  called or that it was only called with a very large delay,
  depending on the underlying architecture support.

- rtimers can be cancelled with rtimer_cancel. Cancellation means
  that the handler function will not be invoked after rtimer_cancel
  returns. The rtimer structure may still be used internally and
  must not be overwritten or deallocated.
core/sys/rtimer.c (next_timer_locked): we need to reschedule if the timer was cancelled

If the timer about to expire was cancelled, we don't call any timer
handler and we therefore always have to schedule the next timer.
This bug was reported by Joakim Eriksson.
core/sys/rtimer.c (set_locked): correct setting of rtimer->ptr
core/sys/rtimer.h, rtimer.c: support setting rtimers from interrupts (draft)

Underlying interrupt model:
- non-interrupt code can be interrupted by a timer interrupt or any
  other interrupt,
- a timer interrupt can be interrupted by a non-timer interrupt,
- non-timer interrupts cannot be interrupted by something else,
- any interrupt can call rtimer_set and rtimer_cancel,
- timer interrupts can also call rtimer_run_next.

Code is only lightly tested. May still harbour bugs.
cpu/arm/k60: Implement clock via rtimer API.

 - Change rtimer to use LPTMR (support STOP modes while rtimer is active)
 - Change clock module to use rtimer (instead of LPTMR hardware)
 - Reduce rtimer_clock_t to 32 bits (was a hassle to handle 64 bit)
 - Reduce RTIMER_SECOND to 32768 (was F_BUS == 48000000)

LPTMR is only 16 bit and can not be used to schedule things more than
2 seconds into the future without reducing precision or implementing a
software counter.

Signed-off-by: Joakim Gebart <joakim.gebart@eistec.se>
cpu/arm/k60: rtimer fixes.

 - Handle the RTIMER_PERIOD overflow correctly.
 - Handle timers set beyond the reach of the LPTMR.

Signed-off-by: Joakim Gebart <joakim.gebart@eistec.se>
cpu/arm/k60: rtimer stability

 - Follow guideline for CMR accesses by disabling the timer beforehand.
 - Handle timer wrap around in a different way.
 - Remove call to rtimer_run_next in order to avoid some race condition
   with the ISR that seem to cause random deadlocks when more than one
   timer is active and a timer is deferred.

Signed-off-by: Joakim Gebart <joakim.gebart@eistec.se>