source: SVN/cambria/redboot/packages/hal/common/current/include/drv_api.h @ 1

Last change on this file since 1 was 1, checked in by Tim Harvey, 2 years ago

restored latest version of files from server backup

Signed-off-by: Tim Harvey <tharvey@…>

File size: 10.3 KB
Line 
1#ifndef CYGONCE_HAL_DRV_API_H
2#define CYGONCE_HAL_DRV_API_H
3
4/*==========================================================================
5//
6//      drv_api.h
7//
8//      Native API for Kernel
9//
10//==========================================================================
11//####ECOSGPLCOPYRIGHTBEGIN####
12// -------------------------------------------
13// This file is part of eCos, the Embedded Configurable Operating System.
14// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
15//
16// eCos is free software; you can redistribute it and/or modify it under
17// the terms of the GNU General Public License as published by the Free
18// Software Foundation; either version 2 or (at your option) any later version.
19//
20// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
21// WARRANTY; without even the implied warranty of MERCHANTABILITY or
22// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
23// for more details.
24//
25// You should have received a copy of the GNU General Public License along
26// with eCos; if not, write to the Free Software Foundation, Inc.,
27// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
28//
29// As a special exception, if other files instantiate templates or use macros
30// or inline functions from this file, or you compile this file and link it
31// with other works to produce a work based on this file, this file does not
32// by itself cause the resulting work to be covered by the GNU General Public
33// License. However the source code for this file must still be made available
34// in accordance with section (3) of the GNU General Public License.
35//
36// This exception does not invalidate any other reasons why a work based on
37// this file might be covered by the GNU General Public License.
38//
39// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
40// at http://sources.redhat.com/ecos/ecos-license/
41// -------------------------------------------
42//####ECOSGPLCOPYRIGHTEND####
43//==========================================================================
44//#####DESCRIPTIONBEGIN####
45//
46// Author(s):   nickg
47// Date:        1999-02-24
48// Purpose:     Driver API
49// Description: This file defines the API used by device drivers to access
50//              system services. When the kernel is present it maps directly
51//              to the Kernel C API. When the kernel is absent, it is provided
52//              by a set of HAL functions.
53//             
54// Usage:       #include <cyg/kernel/kapi.h>
55//
56//####DESCRIPTIONEND####
57//
58//========================================================================*/
59
60#include <pkgconf/hal.h>
61#include <cyg/infra/cyg_type.h>
62
63#ifdef CYGPKG_KERNEL
64
65/*------------------------------------------------------------------------*/
66/* Kernel co-resident version of API                                      */
67
68#include <pkgconf/kernel.h>
69
70#ifndef CYGFUN_KERNEL_API_C
71#error Driver API requres Kernel API to be present
72#endif
73
74#include <cyg/kernel/kapi.h>
75
76#define cyg_drv_isr_lock                    cyg_interrupt_disable
77#define cyg_drv_isr_unlock                  cyg_interrupt_enable
78                                     
79#define cyg_drv_dsr_lock                    cyg_scheduler_lock
80#define cyg_drv_dsr_unlock                  cyg_scheduler_unlock
81                                     
82#define cyg_drv_mutex_t                     cyg_mutex_t
83#define cyg_drv_mutex_init                  cyg_mutex_init
84#define cyg_drv_mutex_destroy               cyg_mutex_destroy
85#define cyg_drv_mutex_lock                  cyg_mutex_lock
86#define cyg_drv_mutex_trylock               cyg_mutex_trylock
87#define cyg_drv_mutex_unlock                cyg_mutex_unlock
88#define cyg_drv_mutex_release               cyg_mutex_release
89                                     
90#define cyg_drv_cond_t                      cyg_cond_t
91#define cyg_drv_cond_init                   cyg_cond_init
92#define cyg_drv_cond_destroy                cyg_cond_destroy
93#define cyg_drv_cond_wait                   cyg_cond_wait
94#define cyg_drv_cond_signal                 cyg_cond_signal
95#define cyg_drv_cond_broadcast              cyg_cond_broadcast
96                                     
97#define cyg_drv_interrupt_create            cyg_interrupt_create
98#define cyg_drv_interrupt_delete            cyg_interrupt_delete
99#define cyg_drv_interrupt_attach            cyg_interrupt_attach
100#define cyg_drv_interrupt_detach            cyg_interrupt_detach
101#define cyg_drv_interrupt_mask              cyg_interrupt_mask
102#define cyg_drv_interrupt_unmask            cyg_interrupt_unmask
103#define cyg_drv_interrupt_mask_intunsafe    cyg_interrupt_mask_intunsafe
104#define cyg_drv_interrupt_unmask_intunsafe  cyg_interrupt_unmask_intunsafe
105#define cyg_drv_interrupt_acknowledge       cyg_interrupt_acknowledge
106#define cyg_drv_interrupt_configure         cyg_interrupt_configure
107#define cyg_drv_interrupt_level             cyg_interrupt_level
108#define cyg_drv_interrupt_set_cpu           cyg_interrupt_set_cpu
109#define cyg_drv_interrupt_get_cpu           cyg_interrupt_get_cpu
110                                         
111#define cyg_drv_spinlock_t                  cyg_spinlock_t
112#define cyg_drv_spinlock_init               cyg_spinlock_init
113#define cyg_drv_spinlock_spin               cyg_spinlock_spin
114#define cyg_drv_spinlock_clear              cyg_spinlock_clear
115#define cyg_drv_spinlock_try                cyg_spinlock_try
116#define cyg_drv_spinlock_test               cyg_spinlock_test
117#define cyg_drv_spinlock_spin_intsave       cyg_spinlock_spin_intsave
118#define cyg_drv_spinlock_clear_intsave      cyg_spinlock_clear_intsave
119
120#else /* CYGPKG_KERNEL */
121
122/*------------------------------------------------------------------------*/
123/* Non-kernel version of API                                              */
124                                         
125typedef CYG_ADDRWORD cyg_addrword_t;        /* May hold pointer or word   */
126typedef cyg_addrword_t cyg_handle_t;        /* Object handle              */
127typedef cyg_uint32   cyg_priority_t;        /* type for priorities        */
128typedef cyg_uint32   cyg_vector_t;          /* Interrupt vector id        */
129typedef cyg_uint32   cyg_cpu_t;             /* CPU id                     */
130typedef int          cyg_bool_t;           
131typedef cyg_int32    cyg_code_t;            /* type for various codes     */
132
133typedef cyg_uint32 cyg_ISR_t( cyg_vector_t vector, cyg_addrword_t data);
134typedef void cyg_DSR_t(cyg_vector_t vector,
135                       cyg_ucount32 count,
136                       cyg_addrword_t data);
137
138
139externC void cyg_drv_isr_lock(void);
140externC void cyg_drv_isr_unlock(void);
141
142externC void cyg_drv_dsr_lock(void);
143externC void cyg_drv_dsr_unlock(void);
144
145typedef struct
146{
147    cyg_atomic          lock;
148} cyg_drv_mutex_t;
149
150externC void cyg_drv_mutex_init( cyg_drv_mutex_t *mutex );
151externC void cyg_drv_mutex_destroy( cyg_drv_mutex_t *mutex );
152externC cyg_bool_t cyg_drv_mutex_lock( cyg_drv_mutex_t *mutex );
153externC cyg_bool_t cyg_drv_mutex_trylock( cyg_drv_mutex_t *mutex );
154externC void cyg_drv_mutex_unlock( cyg_drv_mutex_t *mutex );
155externC void cyg_drv_mutex_release( cyg_drv_mutex_t *mutex );
156
157typedef struct
158{
159    cyg_atomic          wait;
160    cyg_drv_mutex_t       *mutex;
161} cyg_drv_cond_t;
162
163externC void cyg_drv_cond_init( cyg_drv_cond_t  *cond, cyg_drv_mutex_t *mutex );
164externC void cyg_drv_cond_destroy( cyg_drv_cond_t  *cond );
165externC cyg_bool_t cyg_drv_cond_wait( cyg_drv_cond_t *cond );
166externC void cyg_drv_cond_signal( cyg_drv_cond_t *cond );
167externC void cyg_drv_cond_broadcast( cyg_drv_cond_t *cond );
168
169typedef struct cyg_interrupt
170{
171    cyg_vector_t        vector;
172    cyg_priority_t      priority;
173    cyg_ISR_t           *isr;
174    cyg_DSR_t           *dsr;
175    CYG_ADDRWORD        data;
176
177    struct cyg_interrupt* volatile next_dsr;
178    volatile cyg_int32             dsr_count;
179   
180#ifdef CYGIMP_HAL_COMMON_INTERRUPTS_CHAIN
181    struct cyg_interrupt *next;
182#endif
183
184} cyg_interrupt;
185
186externC void cyg_drv_interrupt_create(
187                     cyg_vector_t        vector,
188                     cyg_priority_t      priority,
189                     cyg_addrword_t      data,
190                     cyg_ISR_t           *isr,
191                     cyg_DSR_t           *dsr,
192                     cyg_handle_t        *handle,
193                     cyg_interrupt       *intr
194                     );
195externC void cyg_drv_interrupt_delete( cyg_handle_t interrupt );
196externC void cyg_drv_interrupt_attach( cyg_handle_t interrupt );
197externC void cyg_drv_interrupt_detach( cyg_handle_t interrupt );
198
199externC void cyg_drv_interrupt_mask( cyg_vector_t vector );
200externC void cyg_drv_interrupt_mask_intunsafe( cyg_vector_t vector );
201externC void cyg_drv_interrupt_unmask( cyg_vector_t vector );
202externC void cyg_drv_interrupt_unmask_intunsafe( cyg_vector_t vector );
203externC void cyg_drv_interrupt_acknowledge( cyg_vector_t vector );
204externC void cyg_drv_interrupt_configure(
205                     cyg_vector_t        vector,
206                     cyg_bool_t          level,
207                     cyg_bool_t          up
208                     );
209externC void cyg_drv_interrupt_level( cyg_vector_t vector, cyg_priority_t level );
210externC void cyg_drv_interrupt_set_cpu( cyg_vector_t vector, cyg_cpu_t cpu );
211externC cyg_cpu_t cyg_drv_interrupt_get_cpu( cyg_vector_t vector );
212
213
214enum cyg_ISR_results
215{
216    CYG_ISR_HANDLED  = 1,               /* Interrupt was handled             */
217    CYG_ISR_CALL_DSR = 2                /* Schedule DSR                      */
218};
219
220
221typedef struct
222{
223    cyg_atomic          lock;
224} cyg_drv_spinlock_t;
225
226void cyg_drv_spinlock_init(
227    cyg_drv_spinlock_t  *lock,          /* spinlock to initialize            */
228    cyg_bool_t          locked          /* init locked or unlocked           */
229);
230
231void cyg_drv_spinlock_destroy( cyg_drv_spinlock_t *lock );
232
233void cyg_drv_spinlock_spin( cyg_drv_spinlock_t *lock );
234
235void cyg_drv_spinlock_clear( cyg_drv_spinlock_t *lock );
236
237cyg_bool_t cyg_drv_spinlock_try( cyg_drv_spinlock_t *lock );
238
239cyg_bool_t cyg_drv_spinlock_test( cyg_drv_spinlock_t *lock );
240
241void cyg_drv_spinlock_spin_intsave( cyg_drv_spinlock_t *lock,
242                                    cyg_addrword_t *istate );
243
244void cyg_drv_spinlock_clear_intsave( cyg_drv_spinlock_t *lock,
245                                     cyg_addrword_t istate );
246
247#endif /* CYGPKG_KERNEL */
248
249/*------------------------------------------------------------------------*/
250/* EOF drv_api.h                                                          */
251#endif // CYGONCE_HAL_DRV_API_H
Note: See TracBrowser for help on using the repository browser.