irq: cleaned up some of the IRQ core code.

The IRQ core had some bad functions which would easily lead to errors.
Removed those functions and made the work for users easier by requiring
only a call to irq_request to install a new hardware interrupt handler.

Signed-off-by: Michel Megens <dev@michelmegens.net>
irq: handle: added an implementation to irq_handle

irq_handle is the base of the portable IRQ subsystem. This function gets
called by the IRQ chip and is responsible for calling the correct
handler, hidden somewhere else in the system.

Signed-off-by: Michel Megens <dev@michelmegens.net>
irq: handle: implemented hardware irq handles.

Added an implementation for hardware IRQ's. When a hardware IRQ is
triggered, the chip handler is called first. This handler is usually
irq_handle from kernel/irq/handle.c. This handle will then check if the
IRQ is enabled and valid. If all is good it will determine if its a SOFT
IRQ or HARD IRQ. Hard IRQs are handled instantly, in IRQ context, while
soft IRQs are handled at the next schedule call right before a context
switch in process context.

An IRQ can also have a thread associated with it, which can be woken up
when the IRQ has been handled by the driver. The driver should return
IRQ_WAKE_OWNER to do so.

Signed-off-by: Michel Megens <dev@michelmegens.net>
irq: handle: removed a handle for slow soft IRQs.

The software (threaded) IRQs are handled (read: requested to be handled)
in the hard IRQ handle. In otherwords, there is no need for this
function to exist, therefore I cut it out and removed it.

Signed-off-by: Michel Megens <dev@michelmegens.net>
atomic: added atomic types and API funcs.

Added the types:

	* atomic_t;
	* atomic64_t;

The atomic_t type is an integer type with the length `signed int'. The
atomic64_t type is defined as an `int64_t' type and is for that reason
ALWAYS 64 bits long. Usage of the latter should be reduced for data
space reasons only.

The currently implemented atomic API functions:

	* atomic_inc & atomic64_inc
	* atomic_get & atomic64_get

The get functions return their respective types mentioned above.

Signed-off-by: Michel Megens <dev@michelmegens.net>
avr: atomic: reimplemented the atomic operations

Reimplemented most atomic operations so they rely on the most basic
version of themselves. For example, atomic_inc is basically an
atomic_add with 1.

New functions implemented:

	* atomic_add
	* atomic_sub
	* atomic_dec

Functions which have been rewritten:

	* atomic_inc

Signed-off-by: Michel Megens <dev@michelmegens.net>
time: added timer and clocksource structures.

The timer structure is the frontend structure for a timer. It defines
how often it fires, and what to do when it fires. You can compare this
structure to the pointers on the clock. Behind the clock there's an
engine which defines how fast these pointers are being moved. It is
basically the driver of the clock. In ETA/OS there is a specific
structure to define this mechanism: the clocksource.

Signed-off-by: Michel Megens <dev@michelmegens.net>
timer: source: added a basic clock source.

Implmented the basics of the clock source data structure. The clock
source data structure has:

	* a name
	* a way to turn it on
	* a way to turn it off
	* a list of all timers registered for that specific source.

Signed-off-by: Michel Megens <dev@michelmegens.net>
irq: threaded: added an init for threaded IRQs

Threaded IRQs can now also be initialized by irq_request (after the
scheduler has seen birth, ofcourse) by passing the flag
IRQ_THREADED_MASK to the flags argument (together with other flags,
ofcourse).

Signed-off-by: Michel Megens <dev@michelmegens.net>
dev: core: added a name parameter to device create

The name is a major field of the device structure, since its a unique
identifier where other applications or drivers can search for to obtain
a pointer to the device for operation.

Signed-off-by: Michel Megens <dev@michelmegens.net>
dev: core: rewritten device create

device_create has been rewritten to a new template. Device create will,
from now on take a name, a private data pointer and a pointer to the
appropriate file operations.

device_initialize is the cousin of device create, but it doesn't
allocate a new device. It takes one which is already allocated in its
parameters and initializes it.

Signed-off-by: Michel Megens <dev@michelmegens.net>
Merge branch 'master' into dev-core

* Lib fixes
* Testing environment
dev: core: fixed some listing bugs

Fixed some bugs in the dev-core related to the linking into the dev_root
list head. This list head was not being initialized, resulting in errors
while inserting new nodes in it. Therefore a static initializer has been
added to <etaos/list.h> to initialize global list_head structures.

Further:
	* Added an error code parameter to simul_avr_exit
	* Added flag checking in the memory allocator. Nodes which are
	  not flagged as allocated cannot be free'd.
	* Devtest: added a test for the device core.

Signed-off-by: Michel Megens <dev@michelmegens.net>
Merge branch 'master' into time

Signed-off-by: Michel Megens <dev@michelmegens.net>
time: timer: added basic timer API

Added a basic API for timers. Creating (i.e. starting) and stopping
timers. Timers are driven by a clocksource and 1 clock source can drive
multiple timers.

Timers are listed on the clocksource in a sorted linked list. Timers are
listed with increasing tick intervals so if you have the timers with the
following ticks:

timer 1 -> tick every 200ms
timer 2 -> tick every 100ms
timer 3 -> tick every 300ms

Then the timers will be listed on the source as:

timer 2 - timer 1 - timer 3

Signed-off-by: Michel Megens <dev@michelmegens.net>
usr: tests: added a test for kernl/time/*

Added a time test to test the generic timer API. It currently tests the
insertion and deletion of timers.

Signed-off-by: Michel Megens <dev@michelmegens.net>
time: timer: added a clocksource processor.

The clocksources processor is the engine behind the timers. It updates
the ticks on the timers, and if expired, calls the timer handle if one
is present.

Signed-off-by: Michel Megens <dev@michelmegens.net>
avr: timer: added the AVR system clock source.

The AVR system clock source is going to run the main systems which need
timing for AVR based systems. Virtual timers, scheduler run queue's are
some examples which will be using this source. It is basically the feed
for the system tick.

Signed-off-by: Michel Megens <dev@michelmegens.net>
timer: tick: added systick IRQ

The systick IRQ is responsible for updating the clocksource's tick from
the timer interrupt. The only responsibility it has is updating the `tc'
field in the clocksource data structure.

Signed-off-by: Michel Megens <dev@michelmegens.net>
avr: timer: implemented the avr sys-clk init.

The AVR system clock is run of the AVR core timer 0, which is an 8 bit
HR timer. The timer is configured to interrupt on overflow, which occurs
at each time the timer hits 125 or 250 (depending on the CPU frequency). The
timer only works for CPU's running on either 8MHz or 16Mhz:

 8Mhz/64/125 = 1000Hz
16Mhz/64/250 = 1000Hz

Signed-off-by: Michel Megens <dev@michelmegens.net>