[45666bc7] | 1 | /* |
---|
[332484b5] | 2 | * This routine initailizes the periodic interrupt timer on |
---|
| 3 | * the Motorola 68332. |
---|
[45666bc7] | 4 | */ |
---|
| 5 | |
---|
| 6 | /* |
---|
| 7 | * COPYRIGHT (c) 1989-2014. |
---|
[332484b5] | 8 | * On-Line Applications Research Corporation (OAR). |
---|
| 9 | * |
---|
| 10 | * The license and distribution terms for this file may be |
---|
| 11 | * found in the file LICENSE in this distribution or at |
---|
[c499856] | 12 | * http://www.rtems.org/license/LICENSE. |
---|
[332484b5] | 13 | */ |
---|
| 14 | |
---|
| 15 | #include <stdlib.h> |
---|
| 16 | #include <bsp.h> |
---|
| 17 | #include <mrm332.h> |
---|
[337475b2] | 18 | #include <rtems/clockdrv.h> |
---|
[51995b69] | 19 | #include <rtems/m68k/sim.h> |
---|
[332484b5] | 20 | |
---|
| 21 | #define CLOCK_VECTOR MRM_PIV |
---|
| 22 | |
---|
[45666bc7] | 23 | uint32_t Clock_isrs; /* ISRs until next tick */ |
---|
| 24 | volatile uint32_t Clock_driver_ticks; /* ticks since initialization */ |
---|
| 25 | static rtems_isr_entry Old_ticker; |
---|
[332484b5] | 26 | |
---|
[a6b2080] | 27 | static void Clock_exit( void ); |
---|
[6128a4a] | 28 | |
---|
[45666bc7] | 29 | static rtems_isr Clock_isr(rtems_vector_number vector) |
---|
[332484b5] | 30 | { |
---|
| 31 | Clock_driver_ticks += 1; |
---|
| 32 | |
---|
| 33 | if ( Clock_isrs == 1 ) { |
---|
| 34 | rtems_clock_tick(); |
---|
[12bd47e] | 35 | Clock_isrs = rtems_configuration_get_microseconds_per_tick() / 1000; |
---|
[332484b5] | 36 | } |
---|
| 37 | else |
---|
| 38 | Clock_isrs -= 1; |
---|
| 39 | } |
---|
| 40 | |
---|
[45666bc7] | 41 | static void Install_clock(rtems_isr_entry clock_isr) |
---|
[332484b5] | 42 | { |
---|
| 43 | Clock_driver_ticks = 0; |
---|
[12bd47e] | 44 | Clock_isrs = rtems_configuration_get_microseconds_per_tick() / 1000; |
---|
[332484b5] | 45 | |
---|
| 46 | Old_ticker = (rtems_isr_entry) set_vector( clock_isr, CLOCK_VECTOR, 1 ); |
---|
| 47 | |
---|
| 48 | /* enable 1mS interrupts */ |
---|
| 49 | *PITR = (unsigned short int)( SAM(0x09,0,PITM) );/* load counter */ |
---|
| 50 | *PICR = (unsigned short int) /* enable interrupt */ |
---|
| 51 | ( SAM(ISRL_PIT,8,PIRQL) | SAM(CLOCK_VECTOR,0,PIV) ); |
---|
[6128a4a] | 52 | |
---|
[332484b5] | 53 | atexit( Clock_exit ); |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | void Clock_exit( void ) |
---|
| 57 | { |
---|
| 58 | /* shutdown the periodic interrupt */ |
---|
| 59 | *PICR = (unsigned short int) |
---|
| 60 | ( SAM(0,8,PIRQL) | SAM(CLOCK_VECTOR,0,PIV) ); |
---|
| 61 | /* ^^ zero disables interrupt */ |
---|
| 62 | |
---|
| 63 | /* do not restore old vector */ |
---|
| 64 | } |
---|
| 65 | |
---|
[bb99cd0d] | 66 | void _Clock_Initialize( void ) |
---|
[332484b5] | 67 | { |
---|
| 68 | Install_clock( Clock_isr ); |
---|
| 69 | } |
---|