dev: character device abstraction

Introduce a character device obj type.  This type will act as a wrapper
for more concrete character device types, such as UART or USB CDC.  It
implements a generic read/write interface, without hardware-specific
configuration methods (such as setting baud rate).

The goal with this type is to replace the resource system.  printf() and
friends would write to character devices, which could be UART, USB, etc.

Change-Id: I48ac5ecaf8a586a1e281dc5f15ca9d4f1f65c387
dev: resource char_device implementation

To ease the transition to character devices, implement a character
device layer on top of the resource system.  Eventually, all uses of
resources can be replaced with character devices based on concrete
peripheral objs, but for now, this allows the transition to begin while
some resources are still in use.

Update read()/write()/swrite() to use the char_device internally.
Currently, this is very inefficient, as it requires a malloc() on each
call.  The next step is to make read()/write()/swrite() take
char_devices directly, rather than building them each time.

Additionally, resource_write() never makes use of the resource's
swriter() method, so USB output is noticably slower.

Change-Id: Ieeccc553f3bd13b33077c4f6779729eea36b19d9
dev: replace resource descriptors with char_device pointers

Replace the rd_t resource descriptors as the fundamental IO endpoint
with character devices.  read()/write()/fprintf()/etc now take a
struct char_device * as the first argument instead of an rd_t.

This continues the replacement of resources by making resources no
longer required, though currently all character devices boil down to a
resource.

With this change, the resource table is removed from tasks.  stdin,
stdout, and stderr each get a dedicated pointer in the task struct
(which the stdin, etc macros point to) and are inherited by child tasks,
but other resources are not.

An initializer sets up character device instances for the default
resources in the "current task" structure before task switching begins.
These are then copied into all new tasks.

buf_stream and shared_mem both also use resources.  Since the resource
table no longer exists, they must directly return the struct resource.
The resource must then be converted into a character device before being
used with the standard IO functions.

Change-Id: I4914f9c132b590ca0487baff712815192fdcccc0
dev: remove superfluous resource.h includes

Change-Id: I6f5ad9a0d99828ecaaf8afa13248ad5db10b92ad
dev: implement buf_stream as a char_device

Switch buf_stream from a resource implementation to a direct character
device implementation.  This allows buf_streams to be used directly
wherever a character device is taken, without requiring conversion to a
character device.

Change-Id: I24ba77f232d60b7f8ebdf3057797cc223ca89b0c
stm32f4: remove old register base functions

I2C and SPI are fully device-tree based now, so hardcoded register base
addresses are not necessary.

Change-Id: Iff8209bba579a378ee821a5cb95fa58de1df418f
stm32f4: peripheral bus and clock lookup

Provide RCC functions for looking up which bus a peripheral is on, and
what the clock speed of the bus is.  This allows drivers to adjust their
own clock settings based on the bus clock.

Change-Id: Ibcd3bd8bd36068d9c32d4062d268ae564f096b8b
dev: uart class

Define a class for describing UART peripherals.  This class will be
convertable to a character device, but additionally provides baud rate
get/set methods.

Change-Id: I1ad1c5b5afa0e250a4094a46976ac75dd64256cd
stm32f4: uart class

Implement the UART class for the STM32F4.  This enables the use of UARTs
besides UART1.  Note that UART1 is still used for standard resources, so
it should not be used through this class until that use is removed.

The UART peripheral clock speed is still hard-coded, so it likely will
incorrectly set the baud rate for some UART peripherals.

Change-Id: I10fe87ec7e0f70b7f8352dcd2dba3f5350de425a
shell: basic uart read shell app

Add a uart shell app, which connects to the specified uart, sets the
baud rate, and prints all characters read from the device.

Change-Id: I224431ac65f392b840b3c691d14e1dbe90aa8e7a
fdt: walk stringlist

Provide a helper function for iterating through an FDT stringlist.  The
function performs the basic checks necessary to make sure that it is
returning an in-bounds string.

Change-Id: I74bca13beac48009c176db83638012ba705421c7
stm32f4: DMA obj driver

Provide an abstract interface to STM32F4 DMA streams and channels using
an obj interface.

Each peripheral's DMA interface is described in the device tree, and
this information can be used to reserve the peripheral's DMA stream and
channel.

Once reserved, the DMA can be configured and transactions begun.

Change-Id: If9dfb75ea0ee7a8301bf4d69975f68652978ffff
stm32f4: use DMA in UART driver

Significantly improve performance by using DMA for RX and TX.  A
circular DMA stream buffers received bytes, and a one-shot TX stream
outputs messages as they are written.

Change-Id: I59b4b1fb8889ea706af4187ca29c91250f2f1d47
TEMP: 2-way UART shell app

Send characters on stdin to the UART as well as printing them.

Since stdin currently does not have a non-blocking getc(), write a
rudimentary one for USB.

Change-Id: I264a33a902871800cacd353b7079ffca609ae31d
dev: non-blocking char device methods

Switch the char device read() and write() methods to non-blocking
versions.  This will make working with multiple char devices
simulateously simpler, as callers won't get stuck waiting for data.

Several direct users of read() and write(), notably swrite(), fputs(),
fputc(), and fgetc() are updated to themselves block until all data is
read/written.

Resources converted to char devices will still block.  This cannot be
avoided, as the underlying implementations are blocking.  This will
become a non-issue onces resources are removed.

Change-Id: I98a194f2146cdc0963aa72b0187272c19afbbb78
dev: cast to char

Implement a generic char_device_cast() function, which takes an obj of
indeterminate type, and returns a char_device which utilizes the base
obj.  This makes it possible to get a device from device_get(), cast it
to a char_device, and use it generically.  This is provided by
char_device_get().

This is implemented with a linker list of "conversion" functions.  These
functions take an obj of definite type and return a char_device for
them.  char_device_cast() simply looks for a conversion function
matching the type of the obj passed.

Additionally, the reference behavior of character devices is better
defined.  They must have their own reference, meaning that casting
functions should perform an obj_get() on the base obj.  If the base obj
is no longer needed, it should be obj_put() after being cast.

Change-Id: I27f2af5a50dc1cde0af737839a01cfaa93985b72
dev: uart char_device conversion

Provide a very simple char_device conversion function for UART objs.
The char_device methods maps directly onto UART methods, so calls are
simply passed through.

Change-Id: I671fc013db2c50ca24db3b8d2a1e3f2425fa83c7
dev: initialize IO directly from character devices

Instead of setting up default resources for stdin/stdout/stderr,
directly perform char_device_get() for default devices, specified with
Kconfig.

If the default devices cannot be acquired, the system will panic.

Change-Id: I31d9c2c7b88783f4739ec3e913e1a972928b7bc4
sched: move task io setup to sched

Setting up task IO involves copying stdin/stdout/stderr from the current
task, which has nothing to do with resources, some move it out of
resources into sched.

Change-Id: I534d4fb19f7cc48da6675dfa691a3ce762f8ffd1
dev: implement shared_mem as char_device

Rework the shared_mem implementation as a char_device, rather than a
resource.  The functionality remains identical, though I call the
utility of allowing reads beyond the write counter into question.

Change-Id: If91e33d294c854cfc0b9dd6c80a218af58e1ed7c