source: rtems/c/src/lib/libbsp/mips/rbtx4938/clock/clockdrv.c @ 0c0181d

4.115
Last change on this file since 0c0181d was 0c0181d, checked in by Jennifer Averett <jennifer.averett@…>, on 04/04/12 at 13:39:46

PR 1993 - Convert MIPS to PIC IRQ model

  • Property mode set to 100644
File size: 4.0 KB
Line 
1/**
2 *  @file
3 * 
4 *  Instantiate the clock driver shell.
5 */
6
7/*
8 *  COPYRIGHT (c) 1989-2012.
9 *  On-Line Applications Research Corporation (OAR).
10 *
11 *  The license and distribution terms for this file may be
12 *  found in the file LICENSE in this distribution or at
13 *  http://www.rtems.com/license/LICENSE.
14 *
15 *  $Id$
16 */
17
18#include <rtems.h>
19#include <bsp/irq.h>
20#include <bsp.h>
21
22#include <stdio.h>
23#include <stdlib.h>
24
25#include "yamon_api.h"
26
27
28/* #define CLOCK_DRIVER_USE_FAST_IDLE */
29
30#define CLOCK_VECTOR TX4938_IRQ_TMR0
31
32#define TX4938_TIMER_INTERVAL_MODE 1
33
34#define TX4938_TIMER_MODE TX4938_TIMER_INTERVAL_MODE
35
36#if (TX4938_TIMER_MODE == TX4938_TIMER_INTERVAL_MODE)
37#define TX4938_TIMER_INTERRUPT_FLAG TIIS
38#define Clock_driver_support_initialize_hardware() \
39          Initialize_timer0_in_interval_mode()
40#else
41#error "Build Error: unsupported timer mode"
42#endif
43
44void new_brk_esr(void);
45
46t_yamon_retfunc esr_retfunc = 0;
47t_yamon_ref original_brk_esr = 0;
48t_yamon_ref original_tmr0_isr = 0;
49
50void new_brk_esr(void)
51{
52        if (original_tmr0_isr)
53        {
54                YAMON_FUNC_DEREGISTER_IC_ISR( original_tmr0_isr );
55                original_tmr0_isr = 0;
56        }
57        if (esr_retfunc)
58                esr_retfunc();
59}
60
61
62#define Clock_driver_support_install_isr( _new, _old ) \
63  do { \
64    rtems_interrupt_handler_install( \
65      CLOCK_VECTOR, \
66      "clock", \
67      0, \
68      _new, \
69      NULL \
70    ); \
71    YAMON_FUNC_REGISTER_IC_ISR(17,(t_yamon_isr)_new,0,&original_tmr0_isr); /* Call Yamon to enable interrupt */ \
72  } while(0)
73
74
75#define Clock_driver_support_at_tick() \
76  do { \
77        uint32_t interrupt_flag; \
78        do { \
79                int loop_count; \
80                TX4938_REG_WRITE( TX4938_REG_BASE, TX4938_TIMER0_BASE + TX4938_TIMER_TISR, 0x0 ); /* Clear timer 0 interrupt */ \
81                loop_count = 0; \
82                do { /* Wait until interrupt flag is cleared (this prevents re-entering interrupt) */ \
83                        /* Read back interrupt status register and isolate interval timer flag */ \
84                        interrupt_flag = TX4938_REG_READ( TX4938_REG_BASE, TX4938_TIMER0_BASE + TX4938_TIMER_TISR ) & TX4938_TIMER_INTERRUPT_FLAG; \
85                } while (interrupt_flag && (++loop_count < 10)); /* Loop while timer interrupt bit is set, or loop count is lees than 10 */ \
86        } while(interrupt_flag); \
87  } while(0)
88
89
90/* Setup timer in interval mode to generate peiodic interrupts */
91#define Initialize_timer0_in_interval_mode() \
92  do { \
93        uint32_t temp; \
94    TX4938_REG_WRITE( TX4938_REG_BASE, TX4938_TIMER0_BASE + TX4938_TIMER_TCR, 0x0 ); /* Disable timer */ \
95    TX4938_REG_WRITE( TX4938_REG_BASE, TX4938_TIMER0_BASE + TX4938_TIMER_CCDR, 0x0 ); /* Set register for divide by 2 clock */ \
96    TX4938_REG_WRITE( TX4938_REG_BASE, TX4938_TIMER0_BASE + TX4938_TIMER_ITMR, TIMER_CLEAR_ENABLE_MASK ); /* Set interval timer mode register */ \
97    TX4938_REG_WRITE( TX4938_REG_BASE, TX4938_TIMER0_BASE + TX4938_TIMER_CPRA, 0x3d090 ); /* Set tmier period ,10.0 msec (25 MHz timer clock) */ \
98    TX4938_REG_WRITE( TX4938_REG_BASE, TX4938_TIMER0_BASE + TX4938_TIMER_TCR, 0xC0 ); /* Enable timer in interval mode */ \
99    temp = TX4938_REG_READ( TX4938_REG_BASE, TX4938_TIMER0_BASE + TX4938_TIMER_ITMR ); /* Enable interval timer interrupts */ \
100    temp |= TIMER_INT_ENABLE_MASK; \
101    TX4938_REG_WRITE( TX4938_REG_BASE, TX4938_TIMER0_BASE + TX4938_TIMER_ITMR, temp ); \
102  } while(0)
103
104
105
106#define Clock_driver_support_shutdown_hardware() \
107  do { \
108        uint32_t temp; \
109    temp = TX4938_REG_READ( TX4938_REG_BASE, TX4938_TIMER0_BASE + TX4938_TIMER_ITMR ); /* Disable interval timer interrupt */ \
110    temp &= ~TIMER_INT_ENABLE_MASK; \
111    TX4938_REG_WRITE( TX4938_REG_BASE, TX4938_TIMER0_BASE + TX4938_TIMER_ITMR, temp ); \
112    temp = TX4938_REG_READ( TX4938_REG_BASE, TX4938_TIMER0_BASE + TX4938_TIMER_PGMR ); /* Disable pulse generator interrupt */ \
113    temp &= ~(TPIAE | TPIBE); \
114    TX4938_REG_WRITE( TX4938_REG_BASE, TX4938_TIMER0_BASE + TX4938_TIMER_PGMR, temp ); \
115    TX4938_REG_WRITE( TX4938_REG_BASE, TX4938_TIMER0_BASE + TX4938_TIMER_TCR, 0x0 ); /* Disable timer */ \
116  } while(0)
117
118
119#include "../../../shared/clockdrv_shell.h"
Note: See TracBrowser for help on using the repository browser.