source: rtems/c/src/lib/libbsp/arm/gba/clock/clockdrv.c @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 2.7 KB
Line 
1/**
2 *  @file clockdrv.c
3 *
4 *  Game Boy Advance Clock driver.
5 */
6
7/*
8 *  RTEMS GBA BSP
9 *
10 *  Copyright (c) 2004  Markku Puro <markku.puro@kopteri.net>
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.org/license/LICENSE.
15 */
16
17#include <rtems.h>
18#include <bsp.h>
19#include <bsp/irq.h>
20#include <gba.h>
21#include <assert.h>
22
23
24void Clock_isr(void * arg);
25
26#define Clock_driver_support_at_tick()
27
28#define Clock_driver_support_install_isr( _new, _old )  \
29  do {                                                  \
30    rtems_status_code status = RTEMS_SUCCESSFUL;        \
31    status = rtems_interrupt_handler_install(           \
32        BSP_IRQ_TIMER3,                                 \
33        "Clock",                                        \
34        RTEMS_INTERRUPT_UNIQUE,                         \
35        Clock_isr,                                      \
36        NULL                                            \
37    );                                                  \
38    assert(status == RTEMS_SUCCESSFUL);                 \
39    _old = NULL;                                        \
40  } while(0)
41
42#define Clock_driver_support_shutdown_hardware()        \
43  do {                                                  \
44    rtems_status_code status = RTEMS_SUCCESSFUL;        \
45    status = rtems_interrupt_handler_remove(            \
46        BSP_IRQ_TIMER3,                                 \
47        Clock_isr,                                      \
48        NULL                                            \
49    );                                                  \
50    assert(status == RTEMS_SUCCESSFUL);                 \
51  } while (0)
52
53
54/*
55 * Calculate Tick Times
56 *    1 / 16.78Mhz  => 59.595 ns
57 *   64 / 16.78Mhz  =>  3.814 us
58 *  256 / 16.78Mhz  => 15.256 us
59 * 1024 / 16.78Mhz  => 61.025 us
60 */
61#define  __TimTickTime_us   ((1000000L/__ClockFrequency)*__TimPreScaler)
62#define  __TimTickTime_ns   ((1000000000L/__ClockFrequency)*__TimPreScaler)
63
64#if (__TimPreScaler==1)
65 #define GBA_TMCNT_PS    0x0000
66#elif (__TimPreScaler==64)
67 #define GBA_TMCNT_PS    0x0001
68#elif (__TimPreScaler==256)
69 #define GBA_TMCNT_PS    0x0002
70#elif (__TimPreScaler==1024)
71 #define GBA_TMCNT_PS    0x0003
72#else
73 #define GBA_TMCNT_PS    0x0003
74#endif
75
76/**
77 *  @brief This function set up the clock hardware
78 *
79 *  @param  None
80 *  @return None
81 */
82void Clock_driver_support_initialize_hardware(void)
83{
84  int tmreload = ((rtems_configuration_get_microseconds_per_tick()*1000)/__TimTickTime_ns);
85
86  if (tmreload>0xFFFF) tmreload = 0xFFFF;
87  GBA_REG_TM3CNT = (GBA_TMCNT_PS);
88  GBA_REG_TM3D   = (0x0000-tmreload);
89  GBA_REG_TM3CNT = (0x00c0|GBA_TMCNT_PS);
90}
91
92#include "../../../shared/clockdrv_shell.h"
Note: See TracBrowser for help on using the repository browser.