File indexing completed on 2025-05-11 08:23:59
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042 #include <rtems.h>
0043 #include <rtems/clockdrv.h>
0044 #include <rtems/libio.h>
0045 #include <libcpu/irq.h>
0046
0047 #include <stdlib.h> /* for atexit() */
0048 #include <mpc5xx.h>
0049
0050 volatile uint32_t Clock_driver_ticks;
0051 extern int BSP_connect_clock_handler(rtems_isr_entry);
0052 extern int BSP_disconnect_clock_handler(void);
0053 extern uint32_t bsp_clicks_per_usec;
0054
0055
0056
0057
0058 rtems_isr Clock_isr(rtems_vector_number vector)
0059 {
0060 usiu.piscrk = USIU_UNLOCK_KEY;
0061 usiu.piscr |= USIU_PISCR_PS;
0062 usiu.piscrk = 0;
0063
0064 Clock_driver_ticks++;
0065 rtems_clock_tick();
0066 }
0067
0068 void clockOn(void* unused)
0069 {
0070 unsigned desiredLevel;
0071 uint32_t pit_value;
0072
0073
0074 pit_value = (rtems_configuration_get_microseconds_per_tick() *
0075 bsp_clicks_per_usec) - 1 ;
0076
0077 if (pit_value > 0xffff) {
0078 rtems_fatal_error_occurred(-1);
0079 }
0080 usiu.sccrk = USIU_UNLOCK_KEY;
0081 usiu.sccr &= ~USIU_SCCR_RTDIV;
0082 usiu.sccrk = 0;
0083
0084 usiu.pitck = USIU_UNLOCK_KEY;
0085 usiu.pitc = pit_value;
0086 usiu.pitck = 0;
0087
0088
0089
0090 desiredLevel = CPU_irq_level_from_symbolic_name(CPU_PERIODIC_TIMER);
0091
0092 usiu.piscrk = USIU_UNLOCK_KEY;
0093 usiu.piscr = USIU_PISCR_PIRQ(desiredLevel)
0094 | USIU_PISCR_PS
0095 | USIU_PISCR_PIE
0096 | USIU_PISCR_PITF
0097 | USIU_PISCR_PTE;
0098 usiu.piscrk = 0;
0099 }
0100
0101 void clockOff(void* unused)
0102 {
0103
0104 usiu.piscrk = USIU_UNLOCK_KEY;
0105 usiu.piscr &= ~(USIU_PISCR_PTE | USIU_PISCR_PIE);
0106 usiu.piscrk = 0;
0107 }
0108
0109 int clockIsOn(void* unused)
0110 {
0111 if (usiu.piscr & USIU_PISCR_PIE)
0112 return 1;
0113 return 0;
0114 }
0115
0116
0117
0118
0119
0120 static void Clock_exit(void)
0121 {
0122 (void) BSP_disconnect_clock_handler ();
0123 }
0124
0125 static void Install_clock(rtems_isr_entry clock_isr)
0126 {
0127 Clock_driver_ticks = 0;
0128
0129 BSP_connect_clock_handler (clock_isr);
0130 atexit(Clock_exit);
0131 }
0132
0133 void _Clock_Initialize( void )
0134 {
0135 Install_clock( Clock_isr );
0136 }