OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [arm/] [snds/] [v2_0/] [src/] [snds100_misc.c] - Blame information for rev 27

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
//==========================================================================
2
//
3
//      snds100_misc.c
4
//
5
//      HAL misc board support code for Samsung SNDS100
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 Red Hat, 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 version.
16
//
17
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
19
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20
// for more details.
21
//
22
// You should have received a copy of the GNU General Public License along
23
// with eCos; if not, write to the Free Software Foundation, Inc.,
24
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25
//
26
// As a special exception, if other files instantiate templates or use macros
27
// or inline functions from this file, or you compile this file and link it
28
// with other works to produce a work based on this file, this file does not
29
// by itself cause the resulting work to be covered by the GNU General Public
30
// License. However the source code for this file must still be made available
31
// in accordance with section (3) of the GNU General Public License.
32
//
33
// This exception does not invalidate any other reasons why a work based on
34
// this file might be covered by the GNU General Public License.
35
//
36
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37
// at http://sources.redhat.com/ecos/ecos-license/
38
// -------------------------------------------
39
//####ECOSGPLCOPYRIGHTEND####
40
//==========================================================================
41
//#####DESCRIPTIONBEGIN####
42
//
43
// Author(s):    gthomas
44
// Contributors: gthomas, jskov
45
//               Grant Edwards <grante@visi.com>
46
// Date:         2001-07-31
47
// Purpose:      HAL board support
48
// Description:  Implementations of HAL board interfaces
49
//
50
//####DESCRIPTIONEND####
51
//
52
//========================================================================*/
53
 
54
#include <pkgconf/hal.h>
55
 
56
#include <cyg/infra/cyg_type.h>         // base types
57
#include <cyg/infra/cyg_trac.h>         // tracing macros
58
#include <cyg/infra/cyg_ass.h>          // assertion macros
59
#include <cyg/infra/diag.h>             // diag_printf()
60
 
61
#include <cyg/hal/hal_io.h>             // IO macros
62
#include <cyg/hal/hal_arch.h>           // Register state info
63
#include <cyg/hal/hal_diag.h>
64
#include <cyg/hal/hal_cache.h>
65
#include <cyg/hal/hal_intr.h>           // necessary?
66
#include <cyg/hal/hal_if.h>             // calling interface
67
#include <cyg/hal/hal_misc.h>           // helper functions
68
#ifdef CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT
69
#include <cyg/hal/drv_api.h>            // HAL ISR support
70
#endif
71
 
72
#include "ks32c5000.h"
73
#include <cyg/hal/plf_io.h>
74
 
75
//======================================================================
76
// Use Timer0 for kernel clock
77
 
78
static cyg_uint32 _period;
79
 
80
#ifdef CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT
81
static cyg_interrupt abort_interrupt;
82
static cyg_handle_t  abort_interrupt_handle;
83
 
84
// This ISR is called only for the Abort button interrupt
85
static int
86
ks32c_abort_isr(cyg_vector_t vector, cyg_addrword_t data, HAL_SavedRegisters *regs)
87
{
88
    cyg_hal_user_break((CYG_ADDRWORD*)regs);
89
    cyg_drv_interrupt_acknowledge(CYGNUM_HAL_INTERRUPT_EXT0);
90
    return 0;  // No need to run DSR
91
}
92
#endif
93
 
94
void hal_clock_initialize(cyg_uint32 period)
95
{
96
    cyg_uint32 tmod;
97
 
98
    // Disable timer 0
99
    HAL_READ_UINT32(KS32C_TMOD, tmod);
100
    tmod &= ~(KS32C_TMOD_TE0);
101
    HAL_WRITE_UINT32(KS32C_TMOD, 0);
102
 
103
    tmod &= ~(KS32C_TMOD_TMD0 | KS32C_TMOD_TCLR0);
104
    tmod |= KS32C_TMOD_TE0;
105
 
106
    // Set counter
107
    HAL_WRITE_UINT32(KS32C_TDATA0, period);
108
 
109
    // And enable timer
110
    HAL_WRITE_UINT32(KS32C_TMOD, tmod);
111
 
112
    _period = period;
113
 
114
#ifdef CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT
115
    cyg_drv_interrupt_create(CYGNUM_HAL_INTERRUPT_EXT0,
116
                             99,           // Priority
117
                             0,            // Data item passed to interrupt handler
118
                             ks32c_abort_isr,
119
                             0,
120
                             &abort_interrupt_handle,
121
                             &abort_interrupt);
122
    cyg_drv_interrupt_attach(abort_interrupt_handle);
123
    cyg_drv_interrupt_unmask(CYGNUM_HAL_INTERRUPT_EXT0);
124
#endif
125
}
126
 
127
void hal_clock_reset(cyg_uint32 vector, cyg_uint32 period)
128
{
129
    _period = period;
130
}
131
 
132
void hal_clock_read(cyg_uint32 *pvalue)
133
{
134
    cyg_uint32 value;
135
 
136
    HAL_READ_UINT32(KS32C_TCNT0, value);
137
    *pvalue = _period - value;
138
}
139
 
140
//======================================================================
141
// Interrupt controller stuff
142
 
143
extern volatile  tInterruptController ks32c5000_int;  // Interrupt controller registers
144
extern volatile  unsigned long EXTACON0;    // Extern access control reg
145
extern volatile  unsigned long EXTACON1;    // Extern access control reg
146
extern volatile  unsigned long IOPCON;      // I/O Port Control reg
147
extern volatile  unsigned long IOPMOD;
148
extern volatile  unsigned long SYSCON;
149
 
150
void hal_hardware_init(void)
151
{
152
    cyg_uint32 intmask, syscfg;
153
 
154
    // Set up eCos/ROM interfaces
155
    hal_if_init();
156
 
157
    // Enable cache
158
    HAL_READ_UINT32(KS32C_SYSCFG, syscfg);
159
    syscfg &= ~KS32C_SYSCFG_CM_MASK;
160
    syscfg |= KS32C_SYSCFG_CM_0R_8C|KS32C_SYSCFG_WE;
161
    HAL_WRITE_UINT32(KS32C_SYSCFG, syscfg);
162
    HAL_UCACHE_INVALIDATE_ALL();
163
    HAL_UCACHE_ENABLE();
164
 
165
    // Clear global interrupt mask bit
166
    HAL_READ_UINT32(KS32C_INTMSK, intmask);
167
    intmask &= ~KS32C_INTMSK_GLOBAL;
168
    HAL_WRITE_UINT32(KS32C_INTMSK, intmask);
169
}
170
 
171
 
172
// This routine is called to respond to a hardware interrupt (IRQ).  It
173
// should interrogate the hardware and return the IRQ vector number.
174
 
175
int hal_IRQ_handler(void)
176
{
177
    // Do hardware-level IRQ handling
178
    cyg_uint32 irq_status;
179
    HAL_READ_UINT32(KS32C_INTOFFSET_IRQ, irq_status);
180
    irq_status = irq_status / 4;
181
    if (CYGNUM_HAL_ISR_MAX >= irq_status)
182
        return irq_status;
183
    // It's a bit bogus to test for FIQs after IRQs, but we use the
184
    // latter more, so don't impose the overhead of checking for FIQs
185
    HAL_READ_UINT32(KS32C_INTOFFSET_FIQ, irq_status);
186
    irq_status = irq_status / 4;
187
    if (CYGNUM_HAL_ISR_MAX >= irq_status)
188
        return irq_status;
189
    return CYGNUM_HAL_INTERRUPT_NONE;
190
}
191
 
192
 
193
//
194
// Interrupt control
195
//
196
 
197
void hal_interrupt_mask(int vector)
198
{
199
    cyg_uint32 mask, old_mask;
200
    HAL_READ_UINT32(KS32C_INTMSK, mask);
201
    old_mask = mask;
202
    mask |= (1<<vector);
203
    HAL_WRITE_UINT32(KS32C_INTMSK, mask);
204
}
205
 
206
void hal_interrupt_unmask(int vector)
207
{
208
    cyg_uint32 mask, old_mask;
209
    HAL_READ_UINT32(KS32C_INTMSK, mask);
210
    old_mask = mask;
211
    mask &= ~(1<<vector);
212
    HAL_WRITE_UINT32(KS32C_INTMSK, mask);
213
}
214
 
215
void hal_interrupt_acknowledge(int vector)
216
{
217
    HAL_WRITE_UINT32(KS32C_INTPND, (1<<vector));
218
}
219
 
220
void hal_interrupt_configure(int vector, int level, int up)
221
{
222
}
223
 
224
void hal_interrupt_set_level(int vector, int level)
225
{
226
}
227
 
228
void hal_show_IRQ(int vector, int data, int handler)
229
{
230
}
231
 
232
// -------------------------------------------------------------------------
233
//
234
// Delay for some number of micro-seconds
235
//
236
void hal_delay_us(cyg_int32 usecs)
237
{
238
    cyg_uint32 count;
239
    cyg_uint32 ticks = ((CYGNUM_HAL_RTC_PERIOD*CYGNUM_HAL_RTC_DENOMINATOR)/1000000) * usecs;
240
    cyg_uint32 tmod;
241
 
242
    // Disable timer 1
243
    HAL_READ_UINT32(KS32C_TMOD, tmod);
244
    tmod &= ~(KS32C_TMOD_TE1);
245
    HAL_WRITE_UINT32(KS32C_TMOD, tmod);
246
 
247
    tmod &= ~(KS32C_TMOD_TMD1 | KS32C_TMOD_TCLR1);
248
    tmod |= KS32C_TMOD_TE1;
249
 
250
    // Clear pending flag
251
    HAL_WRITE_UINT32(KS32C_INTPND, (1 << CYGNUM_HAL_INTERRUPT_TIMER1));
252
 
253
    // Set counter
254
    HAL_WRITE_UINT32(KS32C_TDATA1, ticks);
255
 
256
    // And enable timer
257
    HAL_WRITE_UINT32(KS32C_TMOD, tmod);
258
 
259
    // Wait for timer to underflow. Can't test the timer completion
260
    // bit without actually enabling the interrupt. So instead watch
261
    // the counter.
262
    ticks /= 2;                         // wait for this threshold
263
 
264
    // Wait till timer counts below threshold
265
    do {
266
        HAL_READ_UINT32(KS32C_TCNT1, count);
267
    } while (count >= ticks);
268
    // then wait for it to be reloaded
269
    do {
270
        HAL_READ_UINT32(KS32C_TCNT1, count);
271
    } while (count < ticks);
272
 
273
    // Then disable timer 1 again
274
    tmod &= ~KS32C_TMOD_TE1;
275
    HAL_WRITE_UINT32(KS32C_TMOD, tmod);
276
}
277
 
278
// No way to reset board
279
 
280
void hal_reset(void)
281
{
282
  CYG_INTERRUPT_STATE old;
283
  HAL_DISABLE_INTERRUPTS(old);
284
  while (1)
285
    ;
286
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.