1 |
786 |
skrzyp |
/*=============================================================================
|
2 |
|
|
//
|
3 |
|
|
// mcfxxxx.c
|
4 |
|
|
//
|
5 |
|
|
// ColdFire MCFxxxx miscellaneous support
|
6 |
|
|
//
|
7 |
|
|
//=============================================================================
|
8 |
|
|
// ####ECOSGPLCOPYRIGHTBEGIN####
|
9 |
|
|
// -------------------------------------------
|
10 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
11 |
|
|
// Copyright (C) 2008 Free Software Foundation, Inc.
|
12 |
|
|
//
|
13 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
14 |
|
|
// the terms of the GNU General Public License as published by the Free
|
15 |
|
|
// Software Foundation; either version 2 or (at your option) any later
|
16 |
|
|
// version.
|
17 |
|
|
//
|
18 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
19 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
20 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
21 |
|
|
// for more details.
|
22 |
|
|
//
|
23 |
|
|
// You should have received a copy of the GNU General Public License
|
24 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
25 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
26 |
|
|
//
|
27 |
|
|
// As a special exception, if other files instantiate templates or use
|
28 |
|
|
// macros or inline functions from this file, or you compile this file
|
29 |
|
|
// and link it with other works to produce a work based on this file,
|
30 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
31 |
|
|
// the GNU General Public License. However the source code for this file
|
32 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
33 |
|
|
// General Public License v2.
|
34 |
|
|
//
|
35 |
|
|
// This exception does not invalidate any other reasons why a work based
|
36 |
|
|
// on this file might be covered by the GNU General Public License.
|
37 |
|
|
// -------------------------------------------
|
38 |
|
|
// ####ECOSGPLCOPYRIGHTEND####
|
39 |
|
|
//=============================================================================
|
40 |
|
|
//#####DESCRIPTIONBEGIN####
|
41 |
|
|
//
|
42 |
|
|
// Author(s): bartv
|
43 |
|
|
// Date: 2008-01-14
|
44 |
|
|
//
|
45 |
|
|
//####DESCRIPTIONEND####
|
46 |
|
|
//===========================================================================*/
|
47 |
|
|
|
48 |
|
|
#include <pkgconf/system.h>
|
49 |
|
|
#include <pkgconf/hal.h>
|
50 |
|
|
#include <pkgconf/hal_m68k_mcfxxxx.h>
|
51 |
|
|
|
52 |
|
|
#include <cyg/infra/cyg_type.h>
|
53 |
|
|
#include <cyg/hal/hal_arch.h>
|
54 |
|
|
#include <cyg/hal/hal_intr.h>
|
55 |
|
|
#include <cyg/hal/hal_io.h>
|
56 |
|
|
#include <cyg/hal/hal_if.h>
|
57 |
|
|
#include <cyg/hal/hal_misc.h>
|
58 |
|
|
#include <cyg/hal/hal_diag.h>
|
59 |
|
|
#include <cyg/hal/drv_api.h>
|
60 |
|
|
|
61 |
|
|
#ifdef CYGINT_HAL_M68K_MCFxxxx_SOFTWARE_PROFILE_TIMER
|
62 |
|
|
// ----------------------------------------------------------------------------
|
63 |
|
|
// Profiling support. This requires a hardware timer set to interrupt
|
64 |
|
|
// at a rate determined by application code. The interrupt handler
|
65 |
|
|
// should call __profile_hit() with a single argument, the interrupted
|
66 |
|
|
// PC. One of the PIT timers, determined by the processor or platform
|
67 |
|
|
// HAL is used to implement the profiling timer.
|
68 |
|
|
//
|
69 |
|
|
// Usually this would involve installing an ISR. However there is no
|
70 |
|
|
// easy way for an ISR to get hold of the interrupted PC. In some
|
71 |
|
|
// configurations the save state will be stored in hal_saved_interrupt_state,
|
72 |
|
|
// but not always. It might be possible to extract the PC from the stack,
|
73 |
|
|
// but that gets messy if a separate interrupt stack is used and would be
|
74 |
|
|
// vulnerable to changes in the architectural VSR. Instead a custom VSR
|
75 |
|
|
// is installed.
|
76 |
|
|
|
77 |
|
|
extern void hal_mcfxxxx_profile_vsr(void);
|
78 |
|
|
|
79 |
|
|
# include <cyg/profile/profile.h>
|
80 |
|
|
|
81 |
|
|
int
|
82 |
|
|
hal_enable_profile_timer(int resolution)
|
83 |
|
|
{
|
84 |
|
|
cyg_uint16 ticks;
|
85 |
|
|
|
86 |
|
|
// Make sure the clock is not running but is otherwise initialized.
|
87 |
|
|
HAL_WRITE_UINT16(HAL_MCFxxxx_PROFILE_TIMER_BASE + HAL_MCFxxxx_PITx_PCSR,
|
88 |
|
|
HAL_MCFxxxx_PITx_PCSR_PRE_64 | HAL_MCFxxxx_PITx_PCSR_OVW |
|
89 |
|
|
HAL_MCFxxxx_PITx_PCSR_PIE | HAL_MCFxxxx_PITx_PCSR_PIF |
|
90 |
|
|
HAL_MCFxxxx_PITx_PCSR_RLD);
|
91 |
|
|
|
92 |
|
|
// The resolution is a time interval in microseconds. The actual
|
93 |
|
|
// cpu clock frequency is determined by the platform. This is divided
|
94 |
|
|
// by 64, which means it may not be possible to get the exact resolution.
|
95 |
|
|
ticks = ((resolution * CYGHWR_HAL_SYSTEM_CLOCK_MHZ) / 64) - 1;
|
96 |
|
|
HAL_WRITE_UINT16(HAL_MCFxxxx_PROFILE_TIMER_BASE + HAL_MCFxxxx_PITx_PMR, ticks);
|
97 |
|
|
|
98 |
|
|
// Convert back to microseconds. This may actually increase rounding
|
99 |
|
|
// errors for some arguments and platforms, but the result should
|
100 |
|
|
// still be accurate enough for practical purposes.
|
101 |
|
|
resolution = ((ticks + 1) * 64) / CYGHWR_HAL_SYSTEM_CLOCK_MHZ;
|
102 |
|
|
|
103 |
|
|
// Set up the interrupt handler. This is usually a high-priority
|
104 |
|
|
// interrupt so that we can get profiling information for other
|
105 |
|
|
// interrupt sources.
|
106 |
|
|
#ifdef HAL_VSR_SET
|
107 |
|
|
HAL_VSR_SET(HAL_MCFxxxx_PROFILE_TIMER_VECTOR, &hal_mcfxxxx_profile_vsr, (cyg_uint32)0);
|
108 |
|
|
#endif
|
109 |
|
|
HAL_INTERRUPT_SET_LEVEL(HAL_MCFxxxx_PROFILE_TIMER_ISR, CYGNUM_HAL_M68K_MCFxxxx_SOFTWARE_PROFILE_TIMER_ISR_PRIORITY);
|
110 |
|
|
HAL_INTERRUPT_UNMASK(HAL_MCFxxxx_PROFILE_TIMER_ISR);
|
111 |
|
|
|
112 |
|
|
// Now start the timer running.
|
113 |
|
|
HAL_WRITE_UINT16(HAL_MCFxxxx_PROFILE_TIMER_BASE + HAL_MCFxxxx_PITx_PCSR,
|
114 |
|
|
HAL_MCFxxxx_PITx_PCSR_PRE_64 | HAL_MCFxxxx_PITx_PCSR_OVW |
|
115 |
|
|
HAL_MCFxxxx_PITx_PCSR_PIE | HAL_MCFxxxx_PITx_PCSR_PIF |
|
116 |
|
|
HAL_MCFxxxx_PITx_PCSR_RLD | HAL_MCFxxxx_PITx_PCSR_EN);
|
117 |
|
|
|
118 |
|
|
// Return the actual resolution.
|
119 |
|
|
return resolution;
|
120 |
|
|
}
|
121 |
|
|
|
122 |
|
|
#endif // Profiling timer
|
123 |
|
|
|
124 |
|
|
/* End of mcfxxxx.c */
|