source: rtems/c/src/lib/libbsp/m68k/gen68340/timer/timer.c @ 132f194

4.104.114.84.95
Last change on this file since 132f194 was 132f194, checked in by Joel Sherrill <joel.sherrill@…>, on Jul 1, 1998 at 10:03:20 PM

Initial submission of gen68340 BSP (should run on a 68349) from
Geoffroy Montel <g_montel@…>.

  • Property mode set to 100644
File size: 8.7 KB
Line 
1/*
2 * Timer_init()
3 *
4 * ATTENTION: AS MC68349 has no built-in Timer, the following code doesn't work
5 *            in a MC68349. You can't use FIFO full mode for the moment, but
6 *            it should be easy to fix this by using an external timer
7 *
8 * Use TIMER 1 for TIMEOUT when using FIFO FULL mode in UART driver
9 * Use TIMER 2 for timing test suites
10 *
11 * Geoffroy Montel
12 * France Telecom - CNET/DSM/TAM/CAT
13 * 4, rue du Clos Courtel
14 * 35512 CESSON-SEVIGNE
15 * FRANCE
16 *
17 * e-mail: g_montel@yahoo.com
18 *
19 *  $Id$
20 */
21
22/*
23 *
24 *  Input parameters:  NONE
25 *
26 *  Output parameters:  NONE
27 *
28 *  NOTE: It is important that the timer start/stop overhead be
29 *        determined when porting or modifying this code.
30 *
31 *  COPYRIGHT (c) 1989-1998.
32 *  On-Line Applications Research Corporation (OAR).
33 *  Copyright assigned to U.S. Government, 1994.
34 *
35 *  The license and distribution terms for this file may be
36 *  found in the file LICENSE in this distribution or at
37 *  http://www.OARcorp.com/rtems/license.html.
38 */
39
40#include <rtems.h>
41#include <bsp.h>
42#include <m340uart.h>
43#include <m340timer.h>
44#include <m68340.h>
45
46#define TIMER1_VECTOR 122
47#define TIMER1_IRQ_LEVEL 5
48#define TIMER1_INTERRUPT_ARBITRATION 5
49
50#define TIMER2_VECTOR 123
51#define TIMER2_IRQ_LEVEL 4
52#define TIMER2_INTERRUPT_ARBITRATION 4
53
54#define CLOCK_SPEED 25          /* in Mhz */
55
56#define max(a,b) (((a)>(b)) ? (a) : (b))
57
58void (*Restart_Fifo_Full_A_Timer)();
59void (*Restart_Check_A_Timer)();
60void (*Restart_Fifo_Full_B_Timer)();
61void (*Restart_Check_B_Timer)();
62
63int preload = 0;
64
65/******************************************************
66  Name: __Restart_Fifo_Full_Timer
67  Input parameters: -
68  Output parameters: -
69  Description: when a character is received, sets
70               the TIMER to raise an interrupt at
71               TIMEOUT.
72               It's necessary to prevent from not
73               getting n-1 characters (with n the
74               Uart Fifo size)
75 *****************************************************/
76void __Restart_Fifo_Full_Timer (void)
77{
78 TSR1 |= m340_TO;
79 TCR1 &= ~m340_CPE;
80 WPREL11 = preload;
81 TCR1 |= m340_CPE;
82}
83
84/******************************************************
85  Name: __Restart_Fifo_Full_Timer
86  Input parameters: -
87  Output parameters: -
88  Description: when no character has been received
89               recently, check now and then if whether
90               a there's a character in the FIFO
91 *****************************************************/
92void __Restart_Check_Timer (void)
93{
94 TSR1 |= m340_TO;
95 TCR1 &= ~m340_CPE;
96 WPREL11 = 0xFFFF;
97 TCR1 |= m340_CPE;
98}
99
100/******************************************************
101  Name: __do_nothing
102  Input parameters: -
103  Output parameters: -
104  Description: we always restart the fifo full timer
105               with a call to Restart_*_Timer
106               if we do not use FIFO full, Restart_*_Timer
107               are set to do __do_nothing
108 *****************************************************/
109void __do_nothing (void)
110{
111}
112
113#define Fifo_Full_on_A (m340_uart_config[UART_CHANNEL_A].rx_mode==UART_FIFO_FULL && m340_uart_config[UART_CHANNEL_A].enable && m340_uart_config[UART_CHANNEL_A].mode==UART_INTERRUPTS)
114#define Fifo_Full_on_B (m340_uart_config[UART_CHANNEL_B].rx_mode==UART_FIFO_FULL && m340_uart_config[UART_CHANNEL_B].enable && m340_uart_config[UART_CHANNEL_B].mode==UART_INTERRUPTS)
115
116/******************************************************
117  Name: Fifo_Full_Timer_initialize
118  Input parameters: -
119  Output parameters: -
120  Description: initialize Timer 1 for FIFO full mode
121 *****************************************************/
122void Fifo_Full_Timer_initialize (void)
123{
124   float max_baud_rate;
125   int prescaler_output_tap = -1;
126   int nb_of_clock_ticks = 0;
127
128   /*
129    *  USE TIMER 1 for UART FIFO FULL mode
130    */
131
132   if ( Fifo_Full_on_A || Fifo_Full_on_B )     
133      {
134        /* Disable the timer */
135        TCR1 &= ~m340_SWR;
136
137        /* Reset the interrupts */
138        TSR1 &= ~(m340_TO | m340_TG | m340_TC);
139
140        /* Init the stop bit for normal operation, ignore FREEZE, user privileges,
141           set interrupt arbitration */
142        TMCR1 = TIMER1_INTERRUPT_ARBITRATION;
143
144        /* interrupt priority level and interrupt vector */
145        TIR1 = TIMER1_VECTOR | (TIMER1_IRQ_LEVEL << 8);
146
147        /* compute prescaler */
148        if ( Fifo_Full_on_A && Fifo_Full_on_B)
149                max_baud_rate = max(m340_uart_config[UART_CHANNEL_A].rx_baudrate, m340_uart_config[UART_CHANNEL_B].rx_baudrate);       
150        else if ( Fifo_Full_on_A )     
151                max_baud_rate = m340_uart_config[UART_CHANNEL_A].rx_baudrate;
152             else max_baud_rate = m340_uart_config[UART_CHANNEL_B].rx_baudrate;
153
154        /* find out config */
155        nb_of_clock_ticks = (10/max_baud_rate)*(CLOCK_SPEED*1000000)*1.2;
156        if (nb_of_clock_ticks < 0xFFFF) {
157           preload = nb_of_clock_ticks;
158           prescaler_output_tap = -1;   
159        } else if (nb_of_clock_ticks/2 < 0xFFFF) {
160           preload = nb_of_clock_ticks/2;
161           prescaler_output_tap = m340_Divide_by_2;
162        } else if (nb_of_clock_ticks/4 < 0xFFFF) {
163           preload = nb_of_clock_ticks/4;
164           prescaler_output_tap = m340_Divide_by_4;
165        } else if (nb_of_clock_ticks/8 < 0xFFFF) {
166           preload = nb_of_clock_ticks/8;
167           prescaler_output_tap = m340_Divide_by_16;
168        } else if (nb_of_clock_ticks/16 < 0xFFFF) {
169           preload = nb_of_clock_ticks/16;
170           prescaler_output_tap = m340_Divide_by_16;
171        } else if (nb_of_clock_ticks/32 < 0xFFFF) {
172           preload = nb_of_clock_ticks/32;
173           prescaler_output_tap = m340_Divide_by_32;
174        } else if (nb_of_clock_ticks/64 < 0xFFFF) {
175           preload = nb_of_clock_ticks/64;
176           prescaler_output_tap = m340_Divide_by_64;
177        } else if (nb_of_clock_ticks/128 < 0xFFFF) {
178           preload = nb_of_clock_ticks/128;
179           prescaler_output_tap = m340_Divide_by_128;
180        } else if (nb_of_clock_ticks/256 < 0xFFFF) {
181           preload = nb_of_clock_ticks/256;
182           prescaler_output_tap = m340_Divide_by_256;
183        } 
184
185        /* Input Capture/Output Compare (ICOC) */
186        TCR1 = m340_SWR | m340_TO_Enabled | m340_ICOC;
187        if (prescaler_output_tap!=-1) TCR1 |= prescaler_output_tap | m340_PSE;
188
189        /* install interrupt vector */
190        {
191         rtems_isr_entry old_handler;
192         rtems_status_code sc;
193
194         proc_ptr ignored;
195         extern void _Debug_ISR_Handler_Console(void);
196
197         sc = rtems_interrupt_catch (InterruptHandler,
198                                     TIMER1_VECTOR,
199                                     &old_handler);
200
201         /* uncomment this if you want to pass control to your own ISR handler
202            it may be usefull to do so to check for performances with an oscilloscope */
203         /*
204         _CPU_ISR_install_raw_handler( TIMER1_VECTOR, _Debug_ISR_Handler_Console, &ignored );
205         */
206        }
207       } /* fifo full mode on a uart */
208
209       /* install routines */
210       Restart_Check_A_Timer = Fifo_Full_on_A ? __Restart_Check_Timer : __do_nothing;
211       Restart_Fifo_Full_A_Timer = Fifo_Full_on_A ? __Restart_Fifo_Full_Timer : __do_nothing;
212       Restart_Check_B_Timer = Fifo_Full_on_B ? __Restart_Check_Timer : __do_nothing;
213       Restart_Fifo_Full_B_Timer = Fifo_Full_on_B ? __Restart_Fifo_Full_Timer : __do_nothing;
214       /* start checking timer */
215       Restart_Check_A_Timer();
216       Restart_Check_B_Timer();
217}
218
219/******************************************************
220  Name: Timer_initialize
221  Input parameters: -
222  Output parameters: -
223  Description: init Timer for timing test suites
224 *****************************************************/
225void Timer_initialize (void)
226{
227        /* Disable the timer */
228        TCR2 &= ~m340_SWR;
229
230        /* Reset the interrupts */
231        TSR2 &= ~(m340_TO | m340_TG | m340_TC);
232
233        /* Init the stop bit for normal operation, ignore FREEZE, user privileges,
234           set interrupt arbitration */
235        TMCR1 = TIMER2_INTERRUPT_ARBITRATION;
236
237        /* interrupt priority level and interrupt vector */
238        TIR1 = TIMER2_VECTOR | (TIMER2_IRQ_LEVEL << 8);
239
240        /* Init the stop bit for normal operation, ignore FREEZE, user privileges,
241           set interrupt arbitration */
242        TMCR2 = TIMER2_INTERRUPT_ARBITRATION;
243
244        /* Preload register 1 */
245        WPREL21 = 0xFFFF;
246
247        /* Input Capture/Output Compare (ICOC) */
248        TCR2 = m340_SWR | m340_ICOC | m340_PSE | m340_Divide_by_16 | m340_CPE;
249}
250
251/******************************************************
252  Name: Read_timer
253  Input parameters: -
254  Output parameters: -
255  Description: Return timer value in microsecond units
256 *****************************************************/
257int
258Read_timer (void)
259{
260 /* there's CLOCK_SPEED / 16 micro seconds between two timer register decrement */
261 return (((0xFFFF - TCNTR2) * CLOCK_SPEED) / 16);
262}
263
264/******************************************************
265  Name: Empty_function
266  Input parameters: -
267  Output parameters: -
268  Description: Empty function call used in loops to
269               measure basic cost of looping
270               in Timing Test Suite.
271 *****************************************************/
272rtems_status_code
273Empty_function (void)
274{
275        return RTEMS_SUCCESSFUL;
276}
277
278/******************************************************
279  Name: Set_find_average_overhead
280  Input parameters: -
281  Output parameters: -
282  Description: -
283 *****************************************************/
284void
285Set_find_average_overhead(rtems_boolean find_flag)
286{
287}
Note: See TracBrowser for help on using the repository browser.