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

4.104.114.84.95
Last change on this file since b5bb3d6 was b5bb3d6, checked in by Joel Sherrill <joel.sherrill@…>, on Jul 6, 1998 at 2:52:30 PM

Update from Geoffroy Montel (g_montel@…) to get in sync with termios
and eliminate warnings.

  • 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         extern void _Debug_ISR_Handler_Console(void);
195
196         sc = rtems_interrupt_catch (InterruptHandler,
197                                     TIMER1_VECTOR,
198                                     &old_handler);
199
200         /* uncomment this if you want to pass control to your own ISR handler
201            it may be usefull to do so to check for performances with an oscilloscope */
202         /*
203         {
204          proc_ptr ignored;
205          _CPU_ISR_install_raw_handler( TIMER1_VECTOR, _Debug_ISR_Handler_Console, &ignored );
206         }
207         */
208        }
209       } /* fifo full mode on a uart */
210
211       /* install routines */
212       Restart_Check_A_Timer = Fifo_Full_on_A ? __Restart_Check_Timer : __do_nothing;
213       Restart_Fifo_Full_A_Timer = Fifo_Full_on_A ? __Restart_Fifo_Full_Timer : __do_nothing;
214       Restart_Check_B_Timer = Fifo_Full_on_B ? __Restart_Check_Timer : __do_nothing;
215       Restart_Fifo_Full_B_Timer = Fifo_Full_on_B ? __Restart_Fifo_Full_Timer : __do_nothing;
216       /* start checking timer */
217       Restart_Check_A_Timer();
218       Restart_Check_B_Timer();
219}
220
221/******************************************************
222  Name: Timer_initialize
223  Input parameters: -
224  Output parameters: -
225  Description: init Timer for timing test suites
226 *****************************************************/
227void Timer_initialize (void)
228{
229        /* Disable the timer */
230        TCR2 &= ~m340_SWR;
231
232        /* Reset the interrupts */
233        TSR2 &= ~(m340_TO | m340_TG | m340_TC);
234
235        /* Init the stop bit for normal operation, ignore FREEZE, user privileges,
236           set interrupt arbitration */
237        TMCR1 = TIMER2_INTERRUPT_ARBITRATION;
238
239        /* interrupt priority level and interrupt vector */
240        TIR1 = TIMER2_VECTOR | (TIMER2_IRQ_LEVEL << 8);
241
242        /* Init the stop bit for normal operation, ignore FREEZE, user privileges,
243           set interrupt arbitration */
244        TMCR2 = TIMER2_INTERRUPT_ARBITRATION;
245
246        /* Preload register 1 */
247        WPREL21 = 0xFFFF;
248
249        /* Input Capture/Output Compare (ICOC) */
250        TCR2 = m340_SWR | m340_ICOC | m340_PSE | m340_Divide_by_16 | m340_CPE;
251}
252
253/******************************************************
254  Name: Read_timer
255  Input parameters: -
256  Output parameters: -
257  Description: Return timer value in microsecond units
258 *****************************************************/
259int
260Read_timer (void)
261{
262 /* there's CLOCK_SPEED / 16 micro seconds between two timer register decrement */
263 return (((0xFFFF - TCNTR2) * CLOCK_SPEED) / 16);
264}
265
266/******************************************************
267  Name: Empty_function
268  Input parameters: -
269  Output parameters: -
270  Description: Empty function call used in loops to
271               measure basic cost of looping
272               in Timing Test Suite.
273 *****************************************************/
274rtems_status_code
275Empty_function (void)
276{
277        return RTEMS_SUCCESSFUL;
278}
279
280/******************************************************
281  Name: Set_find_average_overhead
282  Input parameters: -
283  Output parameters: -
284  Description: -
285 *****************************************************/
286void
287Set_find_average_overhead(rtems_boolean find_flag)
288{
289}
Note: See TracBrowser for help on using the repository browser.