1 | /* |
---|
2 | * This routine initailizes the periodic interrupt timer on |
---|
3 | * the Motorola 68332. |
---|
4 | */ |
---|
5 | |
---|
6 | /* |
---|
7 | * COPYRIGHT (c) 1989-2014. |
---|
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 |
---|
12 | * http://www.rtems.org/license/LICENSE. |
---|
13 | */ |
---|
14 | |
---|
15 | #include <stdlib.h> |
---|
16 | #include <bsp.h> |
---|
17 | #include <mrm332.h> |
---|
18 | #include <rtems/clockdrv.h> |
---|
19 | #include <rtems/m68k/sim.h> |
---|
20 | |
---|
21 | #define CLOCK_VECTOR MRM_PIV |
---|
22 | |
---|
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; |
---|
26 | |
---|
27 | static void Clock_exit( void ); |
---|
28 | |
---|
29 | static rtems_isr Clock_isr(rtems_vector_number vector) |
---|
30 | { |
---|
31 | Clock_driver_ticks += 1; |
---|
32 | |
---|
33 | if ( Clock_isrs == 1 ) { |
---|
34 | rtems_clock_tick(); |
---|
35 | Clock_isrs = rtems_configuration_get_microseconds_per_tick() / 1000; |
---|
36 | } |
---|
37 | else |
---|
38 | Clock_isrs -= 1; |
---|
39 | } |
---|
40 | |
---|
41 | static void Install_clock(rtems_isr_entry clock_isr) |
---|
42 | { |
---|
43 | Clock_driver_ticks = 0; |
---|
44 | Clock_isrs = rtems_configuration_get_microseconds_per_tick() / 1000; |
---|
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) ); |
---|
52 | |
---|
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 | |
---|
66 | rtems_device_driver Clock_initialize( |
---|
67 | rtems_device_major_number major, |
---|
68 | rtems_device_minor_number minor, |
---|
69 | void *pargp |
---|
70 | ) |
---|
71 | { |
---|
72 | Install_clock( Clock_isr ); |
---|
73 | |
---|
74 | return RTEMS_SUCCESSFUL; |
---|
75 | } |
---|