1 |
786 |
skrzyp |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// mpc8xxx_timer.c
|
4 |
|
|
//
|
5 |
|
|
// PowerPC MPC8xxx timer tests
|
6 |
|
|
//
|
7 |
|
|
//==========================================================================
|
8 |
|
|
// ####ECOSGPLCOPYRIGHTBEGIN####
|
9 |
|
|
// -------------------------------------------
|
10 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
11 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 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): gthomas
|
43 |
|
|
// Contributors: gthomas
|
44 |
|
|
// Date: 2003-11-19
|
45 |
|
|
//####DESCRIPTIONEND####
|
46 |
|
|
|
47 |
|
|
#include <pkgconf/hal.h>
|
48 |
|
|
|
49 |
|
|
#include <cyg/infra/cyg_type.h>
|
50 |
|
|
#include <cyg/infra/cyg_ass.h>
|
51 |
|
|
#include <cyg/infra/testcase.h>
|
52 |
|
|
#include <cyg/infra/diag.h>
|
53 |
|
|
#include <cyg/hal/hal_arch.h>
|
54 |
|
|
#include <cyg/hal/mpc8xxx.h>
|
55 |
|
|
|
56 |
|
|
#ifdef CYGPKG_KERNEL
|
57 |
|
|
#include <cyg/kernel/kapi.h>
|
58 |
|
|
|
59 |
|
|
#define STACK_SIZE CYGNUM_HAL_STACK_SIZE_MINIMUM
|
60 |
|
|
static char main_thread_stack[STACK_SIZE];
|
61 |
|
|
static cyg_thread main_thread_thread_data;
|
62 |
|
|
static cyg_handle_t main_thread_thread_handle;
|
63 |
|
|
|
64 |
|
|
static cyg_vector_t interrupt; // Interrupt vector used by controller
|
65 |
|
|
static cyg_handle_t interrupt_handle;
|
66 |
|
|
static cyg_interrupt interrupt_object;
|
67 |
|
|
|
68 |
|
|
static volatile intr_count;
|
69 |
|
|
|
70 |
|
|
static void
|
71 |
|
|
main_thread(cyg_addrword_t param)
|
72 |
|
|
{
|
73 |
|
|
int tries = 0;
|
74 |
|
|
int old_intr_count;
|
75 |
|
|
int hits = 0;
|
76 |
|
|
|
77 |
|
|
while (++tries <= 10) {
|
78 |
|
|
old_intr_count = intr_count;
|
79 |
|
|
cyg_thread_delay(100);
|
80 |
|
|
diag_printf("tick - count = %d\n", intr_count);
|
81 |
|
|
if (intr_count != old_intr_count) hits++;
|
82 |
|
|
}
|
83 |
|
|
if (hits == (tries-1)) {
|
84 |
|
|
CYG_TEST_PASS("mpc8xxx_timer OK");
|
85 |
|
|
} else {
|
86 |
|
|
diag_printf("tries = %d, hits = %d\n", tries, hits);
|
87 |
|
|
CYG_TEST_FAIL("mpc8xxx_timer unreliable");
|
88 |
|
|
}
|
89 |
|
|
CYG_TEST_EXIT("mpc8xxx_timer");
|
90 |
|
|
}
|
91 |
|
|
|
92 |
|
|
// This ISR is called when the timer interrupt occurs
|
93 |
|
|
static int
|
94 |
|
|
timer_isr(cyg_vector_t vector, cyg_addrword_t data, HAL_SavedRegisters *regs)
|
95 |
|
|
{
|
96 |
|
|
cyg_interrupt_mask(interrupt);
|
97 |
|
|
return (CYG_ISR_HANDLED|CYG_ISR_CALL_DSR); // Run the DSR
|
98 |
|
|
}
|
99 |
|
|
|
100 |
|
|
// This DSR is called when the timer interrupt occurs
|
101 |
|
|
static void
|
102 |
|
|
timer_dsr(cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t data)
|
103 |
|
|
{
|
104 |
|
|
intr_count++;
|
105 |
|
|
IMM->cpm_timers_ter[0] = 0xFF; // Clears interrupt condition
|
106 |
|
|
cyg_interrupt_acknowledge(interrupt);
|
107 |
|
|
cyg_interrupt_unmask(interrupt);
|
108 |
|
|
}
|
109 |
|
|
|
110 |
|
|
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
|
111 |
|
|
externC void cyg_hal_invoke_constructors();
|
112 |
|
|
#endif
|
113 |
|
|
|
114 |
|
|
externC void
|
115 |
|
|
cyg_user_start( void )
|
116 |
|
|
{
|
117 |
|
|
#ifdef CYGSEM_HAL_STOP_CONSTRUCTORS_ON_FLAG
|
118 |
|
|
cyg_hal_invoke_constructors();
|
119 |
|
|
#endif
|
120 |
|
|
CYG_TEST_INIT();
|
121 |
|
|
CYG_TEST_INFO("cyg_user_start()");
|
122 |
|
|
cyg_thread_create(1, // Priority
|
123 |
|
|
main_thread , // entry
|
124 |
|
|
(cyg_addrword_t)0, // entry parameter
|
125 |
|
|
"CS8900 int", // Name
|
126 |
|
|
&main_thread_stack[0], // Stack
|
127 |
|
|
STACK_SIZE, // Size
|
128 |
|
|
&main_thread_thread_handle, // Handle
|
129 |
|
|
&main_thread_thread_data // Thread data structure
|
130 |
|
|
);
|
131 |
|
|
cyg_thread_resume(main_thread_thread_handle); // Start it
|
132 |
|
|
|
133 |
|
|
interrupt = CYGNUM_HAL_INTERRUPT_TIMER1;
|
134 |
|
|
cyg_interrupt_create(interrupt,
|
135 |
|
|
0, // Priority - what goes here?
|
136 |
|
|
(cyg_addrword_t)0, // Data item passed to interrupt handler
|
137 |
|
|
(cyg_ISR_t *)timer_isr,
|
138 |
|
|
(cyg_DSR_t *)timer_dsr,
|
139 |
|
|
&interrupt_handle,
|
140 |
|
|
&interrupt_object);
|
141 |
|
|
cyg_interrupt_attach(interrupt_handle);
|
142 |
|
|
cyg_interrupt_acknowledge(interrupt);
|
143 |
|
|
cyg_interrupt_unmask(interrupt);
|
144 |
|
|
|
145 |
|
|
// Set up timer1
|
146 |
|
|
IMM->cpm_timers_tmr1 = _TC_TMR_ORI | _TC_TMR_ICLK_BUS16 | (0x10<<8);
|
147 |
|
|
IMM->cpm_timers_trr1 = 0x2000; // Reference value
|
148 |
|
|
IMM->cpm_timers_tcn1 = 0;
|
149 |
|
|
IMM->cpm_timers_ter[0] = 0xFF;
|
150 |
|
|
IMM->cpm_timers_tgcr1 = _TC_TGCR_RST1; // Reset & enable timer1
|
151 |
|
|
|
152 |
|
|
cyg_scheduler_start();
|
153 |
|
|
CYG_TEST_PASS("mpc8xxx_timer");
|
154 |
|
|
}
|
155 |
|
|
|
156 |
|
|
// -------------------------------------------------------------------------
|
157 |
|
|
|
158 |
|
|
#else // ! CYGPKG_KERNEL
|
159 |
|
|
#define N_A_MSG "no kernel"
|
160 |
|
|
#endif // CYGPKG_KERNEL
|
161 |
|
|
|
162 |
|
|
#ifdef N_A_MSG
|
163 |
|
|
externC void
|
164 |
|
|
cyg_start( void )
|
165 |
|
|
{
|
166 |
|
|
CYG_TEST_INIT();
|
167 |
|
|
CYG_TEST_NA( N_A_MSG );
|
168 |
|
|
}
|
169 |
|
|
#endif // N_A_MSG defined ie. we are N/A.
|