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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [arm/] [snds/] [current/] [src/] [snds100_misc.c] - Blame information for rev 856

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

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
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 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, jskov
44
//               Grant Edwards <grante@visi.com>
45
// Date:         2001-07-31
46
// Purpose:      HAL board support
47
// Description:  Implementations of HAL board interfaces
48
//
49
//####DESCRIPTIONEND####
50
//
51
//========================================================================*/
52
 
53
#include <pkgconf/hal.h>
54
 
55
#include <cyg/infra/cyg_type.h>         // base types
56
#include <cyg/infra/cyg_trac.h>         // tracing macros
57
#include <cyg/infra/cyg_ass.h>          // assertion macros
58
#include <cyg/infra/diag.h>             // diag_printf()
59
 
60
#include <cyg/hal/hal_io.h>             // IO macros
61
#include <cyg/hal/hal_arch.h>           // Register state info
62
#include <cyg/hal/hal_diag.h>
63
#include <cyg/hal/hal_cache.h>
64
#include <cyg/hal/hal_intr.h>           // necessary?
65
#include <cyg/hal/hal_if.h>             // calling interface
66
#include <cyg/hal/hal_misc.h>           // helper functions
67
#ifdef CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT
68
#include <cyg/hal/drv_api.h>            // HAL ISR support
69
#endif
70
 
71
#include "ks32c5000.h"
72
#include <cyg/hal/plf_io.h>
73
 
74
//======================================================================
75
// Use Timer0 for kernel clock
76
 
77
static cyg_uint32 _period;
78
 
79
#ifdef CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT
80
static cyg_interrupt abort_interrupt;
81
static cyg_handle_t  abort_interrupt_handle;
82
 
83
// This ISR is called only for the Abort button interrupt
84
static int
85
ks32c_abort_isr(cyg_vector_t vector, cyg_addrword_t data, HAL_SavedRegisters *regs)
86
{
87
    cyg_hal_user_break((CYG_ADDRWORD*)regs);
88
    cyg_drv_interrupt_acknowledge(CYGNUM_HAL_INTERRUPT_EXT0);
89
    return 0;  // No need to run DSR
90
}
91
#endif
92
 
93
void hal_clock_initialize(cyg_uint32 period)
94
{
95
    cyg_uint32 tmod;
96
 
97
    // Disable timer 0
98
    HAL_READ_UINT32(KS32C_TMOD, tmod);
99
    tmod &= ~(KS32C_TMOD_TE0);
100
    HAL_WRITE_UINT32(KS32C_TMOD, 0);
101
 
102
    tmod &= ~(KS32C_TMOD_TMD0 | KS32C_TMOD_TCLR0);
103
    tmod |= KS32C_TMOD_TE0;
104
 
105
    // Set counter
106
    HAL_WRITE_UINT32(KS32C_TDATA0, period);
107
 
108
    // And enable timer
109
    HAL_WRITE_UINT32(KS32C_TMOD, tmod);
110
 
111
    _period = period;
112
 
113
#ifdef CYGDBG_HAL_DEBUG_GDB_BREAK_SUPPORT
114
    cyg_drv_interrupt_create(CYGNUM_HAL_INTERRUPT_EXT0,
115
                             99,           // Priority
116
                             0,            // Data item passed to interrupt handler
117
                             ks32c_abort_isr,
118
                             0,
119
                             &abort_interrupt_handle,
120
                             &abort_interrupt);
121
    cyg_drv_interrupt_attach(abort_interrupt_handle);
122
    cyg_drv_interrupt_unmask(CYGNUM_HAL_INTERRUPT_EXT0);
123
#endif
124
}
125
 
126
void hal_clock_reset(cyg_uint32 vector, cyg_uint32 period)
127
{
128
    _period = period;
129
}
130
 
131
void hal_clock_read(cyg_uint32 *pvalue)
132
{
133
    cyg_uint32 value;
134
 
135
    HAL_READ_UINT32(KS32C_TCNT0, value);
136
    *pvalue = _period - value;
137
}
138
 
139
//======================================================================
140
// Interrupt controller stuff
141
 
142
extern volatile  tInterruptController ks32c5000_int;  // Interrupt controller registers
143
extern volatile  unsigned long EXTACON0;    // Extern access control reg
144
extern volatile  unsigned long EXTACON1;    // Extern access control reg
145
extern volatile  unsigned long IOPCON;      // I/O Port Control reg
146
extern volatile  unsigned long IOPMOD;
147
extern volatile  unsigned long SYSCON;
148
 
149
void hal_hardware_init(void)
150
{
151
    cyg_uint32 intmask, syscfg;
152
 
153
    // Set up eCos/ROM interfaces
154
    hal_if_init();
155
 
156
    // Enable cache
157
    HAL_READ_UINT32(KS32C_SYSCFG, syscfg);
158
    syscfg &= ~KS32C_SYSCFG_CM_MASK;
159
    syscfg |= KS32C_SYSCFG_CM_0R_8C|KS32C_SYSCFG_WE;
160
    HAL_WRITE_UINT32(KS32C_SYSCFG, syscfg);
161
    HAL_UCACHE_INVALIDATE_ALL();
162
    HAL_UCACHE_ENABLE();
163
 
164
    // Clear global interrupt mask bit
165
    HAL_READ_UINT32(KS32C_INTMSK, intmask);
166
    intmask &= ~KS32C_INTMSK_GLOBAL;
167
    HAL_WRITE_UINT32(KS32C_INTMSK, intmask);
168
}
169
 
170
 
171
// This routine is called to respond to a hardware interrupt (IRQ).  It
172
// should interrogate the hardware and return the IRQ vector number.
173
 
174
int hal_IRQ_handler(void)
175
{
176
    // Do hardware-level IRQ handling
177
    cyg_uint32 irq_status;
178
    HAL_READ_UINT32(KS32C_INTOFFSET_IRQ, irq_status);
179
    irq_status = irq_status / 4;
180
    if (CYGNUM_HAL_ISR_MAX >= irq_status)
181
        return irq_status;
182
    // It's a bit bogus to test for FIQs after IRQs, but we use the
183
    // latter more, so don't impose the overhead of checking for FIQs
184
    HAL_READ_UINT32(KS32C_INTOFFSET_FIQ, irq_status);
185
    irq_status = irq_status / 4;
186
    if (CYGNUM_HAL_ISR_MAX >= irq_status)
187
        return irq_status;
188
    return CYGNUM_HAL_INTERRUPT_NONE;
189
}
190
 
191
 
192
//
193
// Interrupt control
194
//
195
 
196
void hal_interrupt_mask(int vector)
197
{
198
    cyg_uint32 mask, old_mask;
199
    HAL_READ_UINT32(KS32C_INTMSK, mask);
200
    old_mask = mask;
201
    mask |= (1<<vector);
202
    HAL_WRITE_UINT32(KS32C_INTMSK, mask);
203
}
204
 
205
void hal_interrupt_unmask(int vector)
206
{
207
    cyg_uint32 mask, old_mask;
208
    HAL_READ_UINT32(KS32C_INTMSK, mask);
209
    old_mask = mask;
210
    mask &= ~(1<<vector);
211
    HAL_WRITE_UINT32(KS32C_INTMSK, mask);
212
}
213
 
214
void hal_interrupt_acknowledge(int vector)
215
{
216
    HAL_WRITE_UINT32(KS32C_INTPND, (1<<vector));
217
}
218
 
219
void hal_interrupt_configure(int vector, int level, int up)
220
{
221
}
222
 
223
void hal_interrupt_set_level(int vector, int level)
224
{
225
}
226
 
227
void hal_show_IRQ(int vector, int data, int handler)
228
{
229
}
230
 
231
// -------------------------------------------------------------------------
232
//
233
// Delay for some number of micro-seconds
234
//
235
void hal_delay_us(cyg_int32 usecs)
236
{
237
    cyg_uint32 count;
238
    cyg_uint32 ticks = ((CYGNUM_HAL_RTC_PERIOD*CYGNUM_HAL_RTC_DENOMINATOR)/1000000) * usecs;
239
    cyg_uint32 tmod;
240
 
241
    // Disable timer 1
242
    HAL_READ_UINT32(KS32C_TMOD, tmod);
243
    tmod &= ~(KS32C_TMOD_TE1);
244
    HAL_WRITE_UINT32(KS32C_TMOD, tmod);
245
 
246
    tmod &= ~(KS32C_TMOD_TMD1 | KS32C_TMOD_TCLR1);
247
    tmod |= KS32C_TMOD_TE1;
248
 
249
    // Clear pending flag
250
    HAL_WRITE_UINT32(KS32C_INTPND, (1 << CYGNUM_HAL_INTERRUPT_TIMER1));
251
 
252
    // Set counter
253
    HAL_WRITE_UINT32(KS32C_TDATA1, ticks);
254
 
255
    // And enable timer
256
    HAL_WRITE_UINT32(KS32C_TMOD, tmod);
257
 
258
    // Wait for timer to underflow. Can't test the timer completion
259
    // bit without actually enabling the interrupt. So instead watch
260
    // the counter.
261
    ticks /= 2;                         // wait for this threshold
262
 
263
    // Wait till timer counts below threshold
264
    do {
265
        HAL_READ_UINT32(KS32C_TCNT1, count);
266
    } while (count >= ticks);
267
    // then wait for it to be reloaded
268
    do {
269
        HAL_READ_UINT32(KS32C_TCNT1, count);
270
    } while (count < ticks);
271
 
272
    // Then disable timer 1 again
273
    tmod &= ~KS32C_TMOD_TE1;
274
    HAL_WRITE_UINT32(KS32C_TMOD, tmod);
275
}
276
 
277
// No way to reset board
278
 
279
void hal_reset(void)
280
{
281
  CYG_INTERRUPT_STATE old;
282
  HAL_DISABLE_INTERRUPTS(old);
283
  while (1)
284
    ;
285
}

powered by: WebSVN 2.1.0

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