[311dfa6] | 1 | /* |
---|
| 2 | * RTEMS for Nintendo DS clock driver. |
---|
| 3 | * |
---|
| 4 | * Copyright (c) 2008 by Matthieu Bucchianeri <mbucchia@gmail.com> |
---|
| 5 | * |
---|
| 6 | * The license and distribution terms for this file may be |
---|
| 7 | * found in the file LICENSE in this distribution or at |
---|
| 8 | * |
---|
| 9 | * http://www.rtems.com/license/LICENSE |
---|
| 10 | * |
---|
| 11 | * $Id$ |
---|
| 12 | */ |
---|
| 13 | |
---|
| 14 | #include <rtems.h> |
---|
| 15 | #include <bsp.h> |
---|
[c193baad] | 16 | #include <rtems/irq.h> |
---|
[311dfa6] | 17 | #include <nds.h> |
---|
| 18 | |
---|
| 19 | #define CLOCK_VECTOR IRQ_TIMER0 |
---|
| 20 | |
---|
| 21 | /* |
---|
[6a118f18] | 22 | * forward declaration for clock isr in clockdrv_shell.h |
---|
[311dfa6] | 23 | */ |
---|
| 24 | |
---|
| 25 | rtems_isr Clock_isr (rtems_vector_number vector); |
---|
| 26 | |
---|
| 27 | /* |
---|
| 28 | * isr registration variables. |
---|
| 29 | */ |
---|
| 30 | |
---|
| 31 | static rtems_irq_connect_data clock_isr_data = { |
---|
| 32 | IRQ_TIMER0, |
---|
| 33 | (rtems_irq_hdl) Clock_isr, |
---|
| 34 | NULL, |
---|
| 35 | NULL, |
---|
| 36 | NULL, |
---|
[c193baad] | 37 | NULL |
---|
[311dfa6] | 38 | }; |
---|
| 39 | |
---|
| 40 | void update_touchscreen (void); |
---|
| 41 | |
---|
| 42 | /* |
---|
| 43 | * function called on every ticks. |
---|
| 44 | * NOTE: replaced by macro to avoid empty function call. |
---|
| 45 | */ |
---|
| 46 | |
---|
| 47 | #define Clock_driver_support_at_tick() \ |
---|
| 48 | update_touchscreen(); |
---|
| 49 | |
---|
| 50 | /* |
---|
| 51 | * install isr for clock driver. |
---|
| 52 | */ |
---|
| 53 | |
---|
[c193baad] | 54 | #define Clock_driver_support_install_isr( _new, _old ) \ |
---|
| 55 | do { \ |
---|
| 56 | _old = NULL; \ |
---|
| 57 | BSP_install_rtems_irq_handler(&clock_isr_data); \ |
---|
| 58 | } while (0) |
---|
[311dfa6] | 59 | /* |
---|
| 60 | * disable clock. |
---|
| 61 | */ |
---|
| 62 | |
---|
| 63 | void |
---|
| 64 | Clock_driver_support_shutdown_hardware (void) |
---|
| 65 | { |
---|
| 66 | BSP_remove_rtems_irq_handler (&clock_isr_data); |
---|
| 67 | TIMER_CR (0) &= ~(TIMER_ENABLE); |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | /* |
---|
| 71 | * initialize clock on timer 0. |
---|
| 72 | */ |
---|
| 73 | |
---|
| 74 | void |
---|
| 75 | Clock_driver_support_initialize_hardware (void) |
---|
| 76 | { |
---|
| 77 | uint32_t freq = |
---|
| 78 | 1000 / (rtems_configuration_get_microseconds_per_tick () / 1000); |
---|
| 79 | |
---|
| 80 | printk ("[+] clock started\n"); |
---|
| 81 | TIMER_CR (0) = TIMER_ENABLE | TIMER_IRQ_REQ | TIMER_DIV_64; |
---|
| 82 | printk ("[#] setting clock to %u hz\n", freq); |
---|
| 83 | TIMER_DATA (0) = TIMER_FREQ_64 ((uint16_t) freq); |
---|
| 84 | } |
---|
| 85 | |
---|
[6a118f18] | 86 | #include "../../../shared/clockdrv_shell.h" |
---|